aboutsummaryrefslogtreecommitdiffstats
path: root/library/MSLookup_mDNS_Templates.ttcn
blob: 3d4fafe7a2e8cb185ca1edd57e4f21eed9407894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

module MSLookup_mDNS_Templates {

import from DNS_Types all;
import from MSLookup_mDNS_Types all;

template MSLookup_mDNS ts_MSLookup_mDNS_query(integer id, charstring domain) := {
	dnsMessage := {
		header := {
			id := id,
			qr := DNS_QUERY,
			opCode := 0,
			aa := false,
			tc := false,
			rd := false,
			ra := false,
			z := '000'B,
			rCode := DNS_NO_ERROR,
			qdCount := 1,
			anCount := 0,
			nsCount := 0,
			arCount := 0
		},
		queries := {
			{
				qName := domain,
				qType := 255,
				qClass := DNS_IN
			}
		},
		answers := {},
		nameServerRecords := {},
		additionalRecords := {}
	},
	udpAddress := "239.192.23.42",
	udpPort := 4266
}

template MSLookup_mDNS tr_MSLookup_mDNS_query(charstring domain) := {
	dnsMessage := {
		header := {
			id := ?,
			qr := DNS_QUERY,
			opCode := 0,
			aa := false,
			tc := false,
			rd := false,
			ra := false,
			z := '000'B,
			rCode := DNS_NO_ERROR,
			qdCount := 1,
			anCount := 0,
			nsCount := 0,
			arCount := 0
		},
		queries := {
			{
				qName := domain,
				qType := 255,
				qClass := DNS_IN
			}
		},
		answers := {},
		nameServerRecords := {},
		additionalRecords := {}
	},
	udpAddress := ?,
	udpPort := ?
}

template MSLookup_mDNS ts_MSLookup_mDNS_result_IPv4(integer id, charstring domain, UInt32 ip_v4, integer port_v4) := {
	dnsMessage := {
		header := {
			id := id,
			qr := DNS_RESPONSE,
			opCode := DNS_OP_QUERY,
			aa := false,
			tc := false,
			rd := false,
			ra := false,
			z := '000'B,
			rCode := DNS_NO_ERROR,
			qdCount := 0,
			anCount := 3,
			nsCount := 0,
			arCount := 0
		},
		queries := {},
		answers := {
			{
				name := domain,
				rrType := DNS_TXT,
				rrClass := DNS_IN,
				ttl := '00000000'O,
				rdLength := 6,
				rData := {txt := {"age=0"}}
			},
			{
				name := domain,
				rrType := DNS_A,
				rrClass := DNS_IN,
				ttl := '00000000'O,
				rdLength := 4,
				rData := {a := ip_v4}
			},
			{
				name := domain,
				rrType := DNS_TXT,
				rrClass := DNS_IN,
				ttl := '00000000'O,
				rdLength := 1 + lengthof("port=" & int2str(port_v4)),
				rData := {txt := {"port=" & int2str(port_v4)}}
			}
		},
		nameServerRecords := {},
		additionalRecords := {}
	},
	udpAddress := "239.192.23.42",
	udpPort := 4266
}

template MSLookup_mDNS tr_MSLookup_mDNS_result_IPv4(integer id, charstring domain, UInt32 ip_v4, integer port_v4) := {
	dnsMessage := {
		header := {
			id := id,
			qr := DNS_RESPONSE,
			opCode := DNS_OP_QUERY,
			aa := false,
			tc := false,
			rd := false,
			ra := false,
			z := '000'B,
			rCode := DNS_NO_ERROR,
			qdCount := 0,
			anCount := 3,
			nsCount := 0,
			arCount := 0
		},
		queries := {},
		answers := {
			{
				name := domain,
				rrType := DNS_TXT,
				rrClass := DNS_IN,
				ttl := ?,
				rdLength := ?,
				rData := {txt := {pattern "age=*"}}
			},
			{
				name := domain,
				rrType := DNS_A,
				rrClass := DNS_IN,
				ttl := ?,
				rdLength := ?,
				rData := {a := ip_v4}
			},
			{
				name := domain,
				rrType := DNS_TXT,
				rrClass := DNS_IN,
				ttl := ?,
				rdLength := ?,
				rData := {txt := {"port=" & int2str(port_v4)}}
			}
		},
		nameServerRecords := {},
		additionalRecords := {}
	},
	udpAddress := ?,
	udpPort := ?
}

}