|
@@ -0,0 +1,562 @@
|
|
1
|
+diff --git a/.gitignore b/.gitignore
|
|
2
|
+new file mode 100644
|
|
3
|
+index 0000000..920cdfc
|
|
4
|
+--- /dev/null
|
|
5
|
++++ b/.gitignore
|
|
6
|
+@@ -0,0 +1,4 @@
|
|
7
|
++Clients/build
|
|
8
|
++mDNSPosix/build
|
|
9
|
++mDNSPosix/objects
|
|
10
|
++
|
|
11
|
+diff --git a/mDNSPosix/PosixDaemon.c b/mDNSPosix/PosixDaemon.c
|
|
12
|
+index 88b3292..e86a6c7 100644
|
|
13
|
+--- a/mDNSPosix/PosixDaemon.c
|
|
14
|
++++ b/mDNSPosix/PosixDaemon.c
|
|
15
|
+@@ -37,6 +37,11 @@
|
|
16
|
+ #include <fcntl.h>
|
|
17
|
+ #include <pwd.h>
|
|
18
|
+ #include <sys/types.h>
|
|
19
|
++#ifdef __linux__
|
|
20
|
++#include <sys/capability.h> /* !!! We require libcap-dev for this. Oh well. */
|
|
21
|
++/* prctl is required to enable inheriting of capabilities across setuid */
|
|
22
|
++#include <sys/prctl.h>
|
|
23
|
++#endif /* __linux__ */
|
|
24
|
+
|
|
25
|
+ #if __APPLE__
|
|
26
|
+ #undef daemon
|
|
27
|
+@@ -184,16 +189,50 @@ int main(int argc, char **argv)
|
|
28
|
+
|
|
29
|
+ Reconfigure(&mDNSStorage);
|
|
30
|
+
|
|
31
|
++#ifdef __linux__
|
|
32
|
++ /*
|
|
33
|
++ * SO_BINDTODEVICE is privileged operation; however, we can get
|
|
34
|
++ * around it using capabilities instead of remaining root.
|
|
35
|
++ */
|
|
36
|
++ if (mStatus_NoError == err)
|
|
37
|
++ {
|
|
38
|
++ if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0)
|
|
39
|
++ perror("prctl PR_SET_KEEPCAPS");
|
|
40
|
++ }
|
|
41
|
++#endif /* __linux__ */
|
|
42
|
++
|
|
43
|
+ // Now that we're finished with anything privileged, switch over to running as "nobody"
|
|
44
|
+ if (mStatus_NoError == err)
|
|
45
|
+ {
|
|
46
|
+ const struct passwd *pw = getpwnam("nobody");
|
|
47
|
+ if (pw != NULL)
|
|
48
|
++ {
|
|
49
|
+ setuid(pw->pw_uid);
|
|
50
|
++#ifdef __linux__
|
|
51
|
++ struct __user_cap_header_struct ch;
|
|
52
|
++ struct __user_cap_data_struct cd[_LINUX_CAPABILITY_U32S_3];
|
|
53
|
++
|
|
54
|
++ memset(&ch, 0, sizeof(ch));
|
|
55
|
++ ch.version = _LINUX_CAPABILITY_VERSION_3;
|
|
56
|
++ ch.pid = getpid();
|
|
57
|
++ memset(&cd[0], 0, sizeof(cd));
|
|
58
|
++ /* CAP_NET_RAW is required to use SO_BINDTODEVICE */
|
|
59
|
++ int caps = CAP_TO_MASK(CAP_NET_RAW);
|
|
60
|
++ cd[0].permitted = caps;
|
|
61
|
++ cd[0].effective = caps;
|
|
62
|
++ if (capset(&ch, &cd[0]) < 0)
|
|
63
|
++ perror("capset");
|
|
64
|
++#endif /* __linux__ */
|
|
65
|
++ }
|
|
66
|
+ else
|
|
67
|
+ LogMsg("WARNING: mdnsd continuing as root because user \"nobody\" does not exist");
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
++#ifdef __linux__
|
|
71
|
++ if (mStatus_NoError == err)
|
|
72
|
++ err = mDNSPlatformPosixRefreshInterfaceList(&mDNSStorage);
|
|
73
|
++#endif /* __linux__ */
|
|
74
|
++
|
|
75
|
+ if (mStatus_NoError == err)
|
|
76
|
+ err = MainLoop(&mDNSStorage);
|
|
77
|
+
|
|
78
|
+diff --git a/mDNSPosix/Responder.c b/mDNSPosix/Responder.c
|
|
79
|
+index 3996b7b..e58d8eb 100755
|
|
80
|
+--- a/mDNSPosix/Responder.c
|
|
81
|
++++ b/mDNSPosix/Responder.c
|
|
82
|
+@@ -603,7 +603,8 @@ static mStatus RegisterServicesInFile(const char *filePath)
|
|
83
|
+ status = mStatus_UnknownErr;
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+- assert(0 == fclose(fp));
|
|
87
|
++ int rv = fclose(fp);
|
|
88
|
++ assert(0 == rv);
|
|
89
|
+
|
|
90
|
+ return status;
|
|
91
|
+ }
|
|
92
|
+diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
|
|
93
|
+index 953bf64..4e481ea 100755
|
|
94
|
+--- a/mDNSPosix/mDNSPosix.c
|
|
95
|
++++ b/mDNSPosix/mDNSPosix.c
|
|
96
|
+@@ -136,7 +136,7 @@ mDNSlocal void SockAddrTomDNSAddr(const struct sockaddr *const sa, mDNSAddr *ipA
|
|
97
|
+
|
|
98
|
+ // mDNS core calls this routine when it needs to send a packet.
|
|
99
|
+ mDNSexport mStatus mDNSPlatformSendUDP(const mDNS *const m, const void *const msg, const mDNSu8 *const end,
|
|
100
|
+- mDNSInterfaceID InterfaceID, UDPSocket *src, const mDNSAddr *dst,
|
|
101
|
++ mDNSInterfaceID InterfaceID, UDPSocket *src, const mDNSAddr *dst,
|
|
102
|
+ mDNSIPPort dstPort, mDNSBool useBackgroundTrafficClass)
|
|
103
|
+ {
|
|
104
|
+ int err = 0;
|
|
105
|
+@@ -574,9 +574,17 @@ mDNSlocal void FreePosixNetworkInterface(PosixNetworkInterface *intf)
|
|
106
|
+ {
|
|
107
|
+ assert(intf != NULL);
|
|
108
|
+ if (intf->intfName != NULL) free((void *)intf->intfName);
|
|
109
|
+- if (intf->multicastSocket4 != -1) assert(close(intf->multicastSocket4) == 0);
|
|
110
|
++ if (intf->multicastSocket4 != -1)
|
|
111
|
++ {
|
|
112
|
++ int rv = close(intf->multicastSocket4);
|
|
113
|
++ assert(rv == 0);
|
|
114
|
++ }
|
|
115
|
+ #if HAVE_IPV6
|
|
116
|
+- if (intf->multicastSocket6 != -1) assert(close(intf->multicastSocket6) == 0);
|
|
117
|
++ if (intf->multicastSocket6 != -1)
|
|
118
|
++ {
|
|
119
|
++ int rv = close(intf->multicastSocket6);
|
|
120
|
++ assert(rv == 0);
|
|
121
|
++ }
|
|
122
|
+ #endif
|
|
123
|
+ free(intf);
|
|
124
|
+ }
|
|
125
|
+@@ -703,6 +711,29 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
|
|
126
|
+ if (err < 0) { err = errno; perror("setsockopt - IP_MULTICAST_TTL"); }
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
++#ifdef __linux__
|
|
130
|
++#ifdef SO_BINDTODEVICE
|
|
131
|
++ if (err == 0 && interfaceIndex)
|
|
132
|
++ {
|
|
133
|
++ char ifname[IFNAMSIZ];
|
|
134
|
++ if (if_indextoname(interfaceIndex, ifname))
|
|
135
|
++ {
|
|
136
|
++ err = setsockopt(*sktPtr, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname));
|
|
137
|
++ if (err < 0)
|
|
138
|
++ {
|
|
139
|
++ err = errno;
|
|
140
|
++ perror("setsockopt - SO_BINDTODEVICE");
|
|
141
|
++ }
|
|
142
|
++ }
|
|
143
|
++ else
|
|
144
|
++ {
|
|
145
|
++ err = errno;
|
|
146
|
++ perror("if_indextoname");
|
|
147
|
++ }
|
|
148
|
++ }
|
|
149
|
++#endif /* SO_BINDTODEVICE */
|
|
150
|
++#endif /* __linux__ */
|
|
151
|
++
|
|
152
|
+ // And start listening for packets
|
|
153
|
+ if (err == 0)
|
|
154
|
+ {
|
|
155
|
+@@ -784,6 +815,29 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
|
|
156
|
+ if (err < 0) { err = errno; perror("setsockopt - IPV6_MULTICAST_HOPS"); }
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
++#ifdef __linux__
|
|
160
|
++#ifdef SO_BINDTODEVICE
|
|
161
|
++ if (err == 0 && interfaceIndex)
|
|
162
|
++ {
|
|
163
|
++ char ifname[IFNAMSIZ];
|
|
164
|
++ if (if_indextoname(interfaceIndex, ifname))
|
|
165
|
++ {
|
|
166
|
++ err = setsockopt(*sktPtr, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname));
|
|
167
|
++ if (err < 0)
|
|
168
|
++ {
|
|
169
|
++ err = errno;
|
|
170
|
++ perror("setsockopt - SO_BINDTODEVICE");
|
|
171
|
++ }
|
|
172
|
++ }
|
|
173
|
++ else
|
|
174
|
++ {
|
|
175
|
++ err = errno;
|
|
176
|
++ perror("if_indextoname");
|
|
177
|
++ }
|
|
178
|
++ }
|
|
179
|
++#endif /* SO_BINDTODEVICE */
|
|
180
|
++#endif /* __linux__ */
|
|
181
|
++
|
|
182
|
+ // And start listening for packets
|
|
183
|
+ if (err == 0)
|
|
184
|
+ {
|
|
185
|
+@@ -815,7 +869,12 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ // Clean up
|
|
189
|
+- if (err != 0 && *sktPtr != -1) { assert(close(*sktPtr) == 0); *sktPtr = -1; }
|
|
190
|
++ if (err != 0 && *sktPtr != -1)
|
|
191
|
++ {
|
|
192
|
++ int rv = close(*sktPtr);
|
|
193
|
++ assert(rv == 0);
|
|
194
|
++ *sktPtr = -1;
|
|
195
|
++ }
|
|
196
|
+ assert((err == 0) == (*sktPtr != -1));
|
|
197
|
+ return err;
|
|
198
|
+ }
|
|
199
|
+@@ -994,7 +1053,7 @@ mDNSlocal mStatus OpenIfNotifySocket(int *pFD)
|
|
200
|
+ /* Subscribe the socket to Link & IP addr notifications. */
|
|
201
|
+ mDNSPlatformMemZero(&snl, sizeof snl);
|
|
202
|
+ snl.nl_family = AF_NETLINK;
|
|
203
|
+- snl.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
|
|
204
|
++ snl.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR;
|
|
205
|
+ ret = bind(sock, (struct sockaddr *) &snl, sizeof snl);
|
|
206
|
+ if (0 == ret)
|
|
207
|
+ *pFD = sock;
|
|
208
|
+@@ -1072,11 +1131,18 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd)
|
|
209
|
+ PrintNetLinkMsg(pNLMsg);
|
|
210
|
+ #endif
|
|
211
|
+
|
|
212
|
++ // this result isn't used anywhere as a number, just as
|
|
213
|
++ // non-zero - however, I have seen devices with more than 32
|
|
214
|
++ // interfaces at some point..
|
|
215
|
++ // (on Linux, every tunnel increases index for example)
|
|
216
|
++
|
|
217
|
+ // Process the NetLink message
|
|
218
|
+ if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK)
|
|
219
|
+- result |= 1 << ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index;
|
|
220
|
++ result |= 1;
|
|
221
|
++ // << ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index;
|
|
222
|
+ else if (pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR)
|
|
223
|
+- result |= 1 << ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index;
|
|
224
|
++ result |= 1;
|
|
225
|
++ // << ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index;
|
|
226
|
+
|
|
227
|
+ // Advance pNLMsg to the next message in the buffer
|
|
228
|
+ if ((pNLMsg->nlmsg_flags & NLM_F_MULTI) != 0 && pNLMsg->nlmsg_type != NLMSG_DONE)
|
|
229
|
+@@ -1247,8 +1313,12 @@ mDNSexport mStatus mDNSPlatformInit(mDNS *const m)
|
|
230
|
+ if (err == mStatus_NoError) err = SetupSocket(&sa, zeroIPPort, 0, &m->p->unicastSocket6);
|
|
231
|
+ #endif
|
|
232
|
+
|
|
233
|
++ // In Linux case, we can't set up sockets with different owner -
|
|
234
|
++ // it blows up SO_REUSEPORT. So we do this step bit later.
|
|
235
|
++#ifndef __linux__
|
|
236
|
+ // Tell mDNS core about the network interfaces on this machine.
|
|
237
|
+ if (err == mStatus_NoError) err = SetupInterfaceList(m);
|
|
238
|
++#endif /* !__linux__ */
|
|
239
|
+
|
|
240
|
+ // Tell mDNS core about DNS Servers
|
|
241
|
+ mDNS_Lock(m);
|
|
242
|
+@@ -1281,9 +1351,17 @@ mDNSexport void mDNSPlatformClose(mDNS *const m)
|
|
243
|
+ {
|
|
244
|
+ assert(m != NULL);
|
|
245
|
+ ClearInterfaceList(m);
|
|
246
|
+- if (m->p->unicastSocket4 != -1) assert(close(m->p->unicastSocket4) == 0);
|
|
247
|
++ if (m->p->unicastSocket4 != -1)
|
|
248
|
++ {
|
|
249
|
++ int rv = close(m->p->unicastSocket4);
|
|
250
|
++ assert(rv == 0);
|
|
251
|
++ }
|
|
252
|
+ #if HAVE_IPV6
|
|
253
|
+- if (m->p->unicastSocket6 != -1) assert(close(m->p->unicastSocket6) == 0);
|
|
254
|
++ if (m->p->unicastSocket6 != -1)
|
|
255
|
++ {
|
|
256
|
++ int rv = close(m->p->unicastSocket6);
|
|
257
|
++ assert(rv == 0);
|
|
258
|
++ }
|
|
259
|
+ #endif
|
|
260
|
+ }
|
|
261
|
+
|
|
262
|
+@@ -1533,14 +1611,14 @@ mDNSexport mStatus mDNSPlatformClearSPSMACAddr(void)
|
|
263
|
+ mDNSexport mDNSu16 mDNSPlatformGetUDPPort(UDPSocket *sock)
|
|
264
|
+ {
|
|
265
|
+ (void) sock; // unused
|
|
266
|
+-
|
|
267
|
++
|
|
268
|
+ return (mDNSu16)-1;
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ mDNSexport mDNSBool mDNSPlatformInterfaceIsD2D(mDNSInterfaceID InterfaceID)
|
|
272
|
+ {
|
|
273
|
+ (void) InterfaceID; // unused
|
|
274
|
+-
|
|
275
|
++
|
|
276
|
+ return mDNSfalse;
|
|
277
|
+ }
|
|
278
|
+
|
|
279
|
+diff --git a/mDNSPosix/mDNSUNP.c b/mDNSPosix/mDNSUNP.c
|
|
280
|
+index b392fc7..9f85e0e 100755
|
|
281
|
+--- a/mDNSPosix/mDNSUNP.c
|
|
282
|
++++ b/mDNSPosix/mDNSUNP.c
|
|
283
|
+@@ -61,154 +61,86 @@
|
|
284
|
+ #endif
|
|
285
|
+
|
|
286
|
+ #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
|
|
287
|
+-#include <netdb.h>
|
|
288
|
+-#include <arpa/inet.h>
|
|
289
|
+-
|
|
290
|
+-/* Converts a prefix length to IPv6 network mask */
|
|
291
|
+-void plen_to_mask(int plen, char *addr) {
|
|
292
|
+- int i;
|
|
293
|
+- int colons=7; /* Number of colons in IPv6 address */
|
|
294
|
+- int bits_in_block=16; /* Bits per IPv6 block */
|
|
295
|
+- for(i=0; i<=colons; i++) {
|
|
296
|
+- int block, ones=0xffff, ones_in_block;
|
|
297
|
+- if (plen>bits_in_block) ones_in_block=bits_in_block;
|
|
298
|
+- else ones_in_block=plen;
|
|
299
|
+- block = ones & (ones << (bits_in_block-ones_in_block));
|
|
300
|
+- i==0 ? sprintf(addr, "%x", block) : sprintf(addr, "%s:%x", addr, block);
|
|
301
|
+- plen -= ones_in_block;
|
|
302
|
+- }
|
|
303
|
+-}
|
|
304
|
++#include <sys/types.h>
|
|
305
|
++#include <ifaddrs.h>
|
|
306
|
++
|
|
307
|
+
|
|
308
|
+-/* Gets IPv6 interface information from the /proc filesystem in linux*/
|
|
309
|
+-struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases)
|
|
310
|
++/* Correct way to deal with this is just to use getifaddrs (glibc
|
|
311
|
++ * 2.3.3+ and various BSDs, but BSDs are 'slightly different' just to
|
|
312
|
++ * make life interesting). We assume Linux getifaddrs is available,
|
|
313
|
++ * and if not, please upgrade. */
|
|
314
|
++struct ifi_info *get_ifi_info_linuxv6(int doaliases)
|
|
315
|
+ {
|
|
316
|
+- struct ifi_info *ifi, *ifihead, **ifipnext, *ifipold, **ifiptr;
|
|
317
|
+- FILE *fp;
|
|
318
|
+- char addr[8][5];
|
|
319
|
+- int flags, myflags, index, plen, scope;
|
|
320
|
+- char ifname[9], lastname[IFNAMSIZ];
|
|
321
|
+- char addr6[32+7+1]; /* don't forget the seven ':' */
|
|
322
|
+- struct addrinfo hints, *res0;
|
|
323
|
+- struct sockaddr_in6 *sin6;
|
|
324
|
+- struct in6_addr *addrptr;
|
|
325
|
+- int err;
|
|
326
|
+- int sockfd = -1;
|
|
327
|
+- struct ifreq ifr;
|
|
328
|
+-
|
|
329
|
+- res0=NULL;
|
|
330
|
+- ifihead = NULL;
|
|
331
|
+- ifipnext = &ifihead;
|
|
332
|
+- lastname[0] = 0;
|
|
333
|
++ struct ifaddrs *ifap, *ifa;
|
|
334
|
++ struct ifi_info *ifi = NULL, *head = NULL;
|
|
335
|
+
|
|
336
|
+- if ((fp = fopen(PROC_IFINET6_PATH, "r")) != NULL) {
|
|
337
|
+- sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
|
|
338
|
+- if (sockfd < 0) {
|
|
339
|
+- goto gotError;
|
|
340
|
++ /* doaliases seems always true in the calls in current code */
|
|
341
|
++ assert(doaliases);
|
|
342
|
++
|
|
343
|
++ if (getifaddrs(&ifap) < 0)
|
|
344
|
++ {
|
|
345
|
++ return NULL;
|
|
346
|
++ }
|
|
347
|
++ for (ifa = ifap ; ifa ; ifa = ifa->ifa_next)
|
|
348
|
++ {
|
|
349
|
++ /* Care only about IPv6 addresses on non-point-to-point links. */
|
|
350
|
++ if (!ifa->ifa_addr
|
|
351
|
++ || ifa->ifa_addr->sa_family != AF_INET6)
|
|
352
|
++ continue;
|
|
353
|
++ ifi = calloc(1, sizeof(*ifi));
|
|
354
|
++ if (!ifi)
|
|
355
|
++ break;
|
|
356
|
++ strncpy(ifi->ifi_name, ifa->ifa_name, IFI_NAME);
|
|
357
|
++ /* We ignore ifi_{haddr,hlen}, everyone else does too */
|
|
358
|
++ ifi->ifi_flags = ifa->ifa_flags;
|
|
359
|
++ /* We ignore ifi_myflags; IFI_ALIAS isn't used anywhere */
|
|
360
|
++ ifi->ifi_index = if_nametoindex(ifa->ifa_name);
|
|
361
|
++ if (!(ifi->ifi_addr = malloc(sizeof(struct sockaddr_in6))))
|
|
362
|
++ break;
|
|
363
|
++ memcpy(ifi->ifi_addr, ifa->ifa_addr, sizeof(struct sockaddr_in6));
|
|
364
|
++
|
|
365
|
++ if (ifa->ifa_netmask)
|
|
366
|
++ {
|
|
367
|
++ if (!(ifi->ifi_netmask = malloc(sizeof(struct sockaddr_in6))))
|
|
368
|
++ break;
|
|
369
|
++ memcpy(ifi->ifi_netmask, ifa->ifa_netmask,
|
|
370
|
++ sizeof(struct sockaddr_in6));
|
|
371
|
+ }
|
|
372
|
+- while (fscanf(fp,
|
|
373
|
+- "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %8s\n",
|
|
374
|
+- addr[0],addr[1],addr[2],addr[3],
|
|
375
|
+- addr[4],addr[5],addr[6],addr[7],
|
|
376
|
+- &index, &plen, &scope, &flags, ifname) != EOF) {
|
|
377
|
+-
|
|
378
|
+- myflags = 0;
|
|
379
|
+- if (strncmp(lastname, ifname, IFNAMSIZ) == 0) {
|
|
380
|
+- if (doaliases == 0)
|
|
381
|
+- continue; /* already processed this interface */
|
|
382
|
+- myflags = IFI_ALIAS;
|
|
383
|
+- }
|
|
384
|
+- memcpy(lastname, ifname, IFNAMSIZ);
|
|
385
|
+- ifi = (struct ifi_info*)calloc(1, sizeof(struct ifi_info));
|
|
386
|
+- if (ifi == NULL) {
|
|
387
|
+- goto gotError;
|
|
388
|
+- }
|
|
389
|
+
|
|
390
|
+- ifipold = *ifipnext; /* need this later */
|
|
391
|
+- ifiptr = ifipnext;
|
|
392
|
+- *ifipnext = ifi; /* prev points to this new one */
|
|
393
|
+- ifipnext = &ifi->ifi_next; /* pointer to next one goes here */
|
|
394
|
+-
|
|
395
|
+- sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
|
|
396
|
+- addr[0],addr[1],addr[2],addr[3],
|
|
397
|
+- addr[4],addr[5],addr[6],addr[7]);
|
|
398
|
+-
|
|
399
|
+- /* Add address of the interface */
|
|
400
|
+- memset(&hints, 0, sizeof(hints));
|
|
401
|
+- hints.ai_family = AF_INET6;
|
|
402
|
+- hints.ai_flags = AI_NUMERICHOST;
|
|
403
|
+- err = getaddrinfo(addr6, NULL, &hints, &res0);
|
|
404
|
+- if (err) {
|
|
405
|
+- goto gotError;
|
|
406
|
+- }
|
|
407
|
+- ifi->ifi_addr = calloc(1, sizeof(struct sockaddr_in6));
|
|
408
|
+- if (ifi->ifi_addr == NULL) {
|
|
409
|
+- goto gotError;
|
|
410
|
+- }
|
|
411
|
+- memcpy(ifi->ifi_addr, res0->ai_addr, sizeof(struct sockaddr_in6));
|
|
412
|
++ if (!(ifi->ifi_addr = malloc(sizeof(struct sockaddr_in6))))
|
|
413
|
++ break;
|
|
414
|
++ memcpy(ifi->ifi_addr, ifa->ifa_addr, sizeof(struct sockaddr_in6));
|
|
415
|
+
|
|
416
|
+- /* Add netmask of the interface */
|
|
417
|
+- char ipv6addr[INET6_ADDRSTRLEN];
|
|
418
|
+- plen_to_mask(plen, ipv6addr);
|
|
419
|
+- ifi->ifi_netmask = calloc(1, sizeof(struct sockaddr_in6));
|
|
420
|
+- if (ifi->ifi_addr == NULL) {
|
|
421
|
+- goto gotError;
|
|
422
|
+- }
|
|
423
|
+- sin6=calloc(1, sizeof(struct sockaddr_in6));
|
|
424
|
+- addrptr=calloc(1, sizeof(struct in6_addr));
|
|
425
|
+- inet_pton(family, ipv6addr, addrptr);
|
|
426
|
+- sin6->sin6_family=family;
|
|
427
|
+- sin6->sin6_addr=*addrptr;
|
|
428
|
+- sin6->sin6_scope_id=scope;
|
|
429
|
+- memcpy(ifi->ifi_netmask, sin6, sizeof(struct sockaddr_in6));
|
|
430
|
+- free(sin6);
|
|
431
|
+-
|
|
432
|
+-
|
|
433
|
+- /* Add interface name */
|
|
434
|
+- memcpy(ifi->ifi_name, ifname, IFI_NAME);
|
|
435
|
+-
|
|
436
|
+- /* Add interface index */
|
|
437
|
+- ifi->ifi_index = index;
|
|
438
|
+-
|
|
439
|
+- /* Add interface flags*/
|
|
440
|
+- memcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
|
441
|
+- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
|
|
442
|
+- if (errno == EADDRNOTAVAIL) {
|
|
443
|
+- /*
|
|
444
|
+- * If the main interface is configured with no IP address but
|
|
445
|
+- * an alias interface exists with an IP address, you get
|
|
446
|
+- * EADDRNOTAVAIL for the main interface
|
|
447
|
+- */
|
|
448
|
+- free(ifi->ifi_addr);
|
|
449
|
+- free(ifi);
|
|
450
|
+- ifipnext = ifiptr;
|
|
451
|
+- *ifipnext = ifipold;
|
|
452
|
+- continue;
|
|
453
|
+- } else {
|
|
454
|
+- goto gotError;
|
|
455
|
+- }
|
|
456
|
+- }
|
|
457
|
+- ifi->ifi_flags = ifr.ifr_flags;
|
|
458
|
+- freeaddrinfo(res0);
|
|
459
|
+- res0=NULL;
|
|
460
|
+- }
|
|
461
|
+- }
|
|
462
|
+- goto done;
|
|
463
|
+
|
|
464
|
+-gotError:
|
|
465
|
+- if (ifihead != NULL) {
|
|
466
|
+- free_ifi_info(ifihead);
|
|
467
|
+- ifihead = NULL;
|
|
468
|
+- }
|
|
469
|
+- if (res0 != NULL) {
|
|
470
|
+- freeaddrinfo(res0);
|
|
471
|
+- res0=NULL;
|
|
472
|
+- }
|
|
473
|
+-done:
|
|
474
|
+- if (sockfd != -1) {
|
|
475
|
+- assert(close(sockfd) == 0);
|
|
476
|
++ if (ifa->ifa_flags & IFF_POINTOPOINT && ifa->ifa_dstaddr)
|
|
477
|
++ {
|
|
478
|
++ if (!(ifi->ifi_dstaddr = malloc(sizeof(struct sockaddr_in6))))
|
|
479
|
++ break;
|
|
480
|
++ memcpy(ifi->ifi_dstaddr, ifa->ifa_dstaddr,
|
|
481
|
++ sizeof(struct sockaddr_in6));
|
|
482
|
++ }
|
|
483
|
++ else if (ifa->ifa_broadaddr)
|
|
484
|
++ {
|
|
485
|
++ if (!(ifi->ifi_brdaddr = malloc(sizeof(struct sockaddr_in6))))
|
|
486
|
++ break;
|
|
487
|
++ memcpy(ifi->ifi_brdaddr, ifa->ifa_broadaddr,
|
|
488
|
++ sizeof(struct sockaddr_in6));
|
|
489
|
++ }
|
|
490
|
++ ifi->ifi_next = head;
|
|
491
|
++ head = ifi;
|
|
492
|
++ ifi = NULL;
|
|
493
|
++ };
|
|
494
|
++ if (ifi)
|
|
495
|
++ {
|
|
496
|
++ /* An error occurred. Let's bail out. */
|
|
497
|
++ ifi->ifi_next = head;
|
|
498
|
++ free_ifi_info(head);
|
|
499
|
++ return NULL;
|
|
500
|
+ }
|
|
501
|
+- return(ifihead); /* pointer to first structure in linked list */
|
|
502
|
++ freeifaddrs(ifap);
|
|
503
|
++ return head;
|
|
504
|
+ }
|
|
505
|
++
|
|
506
|
+ #endif // defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
|
|
507
|
+
|
|
508
|
+ struct ifi_info *get_ifi_info(int family, int doaliases)
|
|
509
|
+@@ -229,7 +161,7 @@ struct ifi_info *get_ifi_info(int family, int doaliases)
|
|
510
|
+ #endif
|
|
511
|
+
|
|
512
|
+ #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
|
|
513
|
+- if (family == AF_INET6) return get_ifi_info_linuxv6(family, doaliases);
|
|
514
|
++ if (family == AF_INET6) return get_ifi_info_linuxv6(doaliases);
|
|
515
|
+ #endif
|
|
516
|
+
|
|
517
|
+ sockfd = -1;
|
|
518
|
+diff --git a/mDNSPosix/mDNSUNP.h b/mDNSPosix/mDNSUNP.h
|
|
519
|
+index cc81b7d..e710087 100755
|
|
520
|
+--- a/mDNSPosix/mDNSUNP.h
|
|
521
|
++++ b/mDNSPosix/mDNSUNP.h
|
|
522
|
+@@ -97,8 +97,7 @@ struct ifi_info {
|
|
523
|
+ };
|
|
524
|
+
|
|
525
|
+ #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
|
|
526
|
+-#define PROC_IFINET6_PATH "/proc/net/if_inet6"
|
|
527
|
+-extern struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases);
|
|
528
|
++extern struct ifi_info *get_ifi_info_linuxv6(int doaliases);
|
|
529
|
+ #endif
|
|
530
|
+
|
|
531
|
+ #if defined(AF_INET6) && HAVE_IPV6
|
|
532
|
+diff --git a/mDNSShared/dnsextd_parser.y b/mDNSShared/dnsextd_parser.y
|
|
533
|
+index 18c5990..d4b63ce 100644
|
|
534
|
+--- a/mDNSShared/dnsextd_parser.y
|
|
535
|
++++ b/mDNSShared/dnsextd_parser.y
|
|
536
|
+@@ -15,6 +15,8 @@
|
|
537
|
+ * limitations under the License.
|
|
538
|
+ */
|
|
539
|
+
|
|
540
|
++%parse-param { void *context }
|
|
541
|
++
|
|
542
|
+ %{
|
|
543
|
+ #include <stdio.h>
|
|
544
|
+ #include <stdlib.h>
|
|
545
|
+@@ -23,7 +25,7 @@
|
|
546
|
+ #include "DebugServices.h"
|
|
547
|
+ #include "dnsextd.h"
|
|
548
|
+
|
|
549
|
+-void yyerror( const char* error );
|
|
550
|
++void yyerror( void *context, const char* error );
|
|
551
|
+ int yylex(void);
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+@@ -378,7 +380,7 @@ int yywrap(void);
|
|
555
|
+
|
|
556
|
+ extern int yylineno;
|
|
557
|
+
|
|
558
|
+-void yyerror( const char *str )
|
|
559
|
++void yyerror( void *context, const char *str )
|
|
560
|
+ {
|
|
561
|
+ fprintf( stderr,"%s:%d: error: %s\n", g_filename, yylineno, str );
|
|
562
|
+ }
|