diff options
12 files changed, 945 insertions, 0 deletions
diff --git a/meta-networking/recipes-protocols/mdns/files/0001-Create-subroutine-for-cleaning-recent-interfaces.patch b/meta-networking/recipes-protocols/mdns/files/0001-Create-subroutine-for-cleaning-recent-interfaces.patch new file mode 100644 index 0000000000..692c344db9 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0001-Create-subroutine-for-cleaning-recent-interfaces.patch | |||
@@ -0,0 +1,60 @@ | |||
1 | From 89ea6ac4a8840e8c2be0140a9805c6522c6c5280 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Wed, 28 Jun 2017 17:30:00 -0500 | ||
4 | Subject: [PATCH 01/11] Create subroutine for cleaning recent interfaces | ||
5 | |||
6 | Moves functionality for cleaning the list of recent | ||
7 | interfaces into its own subroutine. | ||
8 | |||
9 | Upstream-Status: Submitted [dts@apple.com] | ||
10 | |||
11 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
12 | --- | ||
13 | mDNSPosix/mDNSPosix.c | 24 ++++++++++++++---------- | ||
14 | 1 file changed, 14 insertions(+), 10 deletions(-) | ||
15 | |||
16 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
17 | index 0e10bd5..ffc9696 100644 | ||
18 | --- a/mDNSPosix/mDNSPosix.c | ||
19 | +++ b/mDNSPosix/mDNSPosix.c | ||
20 | @@ -856,6 +856,19 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf | ||
21 | return err; | ||
22 | } | ||
23 | |||
24 | +// Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute | ||
25 | +mDNSlocal void CleanRecentInterfaces(void) | ||
26 | +{ | ||
27 | + PosixNetworkInterface **ri = &gRecentInterfaces; | ||
28 | + const mDNSs32 utc = mDNSPlatformUTC(); | ||
29 | + while (*ri) | ||
30 | + { | ||
31 | + PosixNetworkInterface *pi = *ri; | ||
32 | + if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next; | ||
33 | + else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); } | ||
34 | + } | ||
35 | +} | ||
36 | + | ||
37 | // Creates a PosixNetworkInterface for the interface whose IP address is | ||
38 | // intfAddr and whose name is intfName and registers it with mDNS core. | ||
39 | mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex) | ||
40 | @@ -1010,16 +1023,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m) | ||
41 | |||
42 | // Clean up. | ||
43 | if (intfList != NULL) free_ifi_info(intfList); | ||
44 | - | ||
45 | - // Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute | ||
46 | - PosixNetworkInterface **ri = &gRecentInterfaces; | ||
47 | - const mDNSs32 utc = mDNSPlatformUTC(); | ||
48 | - while (*ri) | ||
49 | - { | ||
50 | - PosixNetworkInterface *pi = *ri; | ||
51 | - if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next; | ||
52 | - else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); } | ||
53 | - } | ||
54 | + CleanRecentInterfaces(); | ||
55 | |||
56 | return err; | ||
57 | } | ||
58 | -- | ||
59 | 2.17.1 | ||
60 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0002-Create-subroutine-for-tearing-down-an-interface.patch b/meta-networking/recipes-protocols/mdns/files/0002-Create-subroutine-for-tearing-down-an-interface.patch new file mode 100644 index 0000000000..21ba318499 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0002-Create-subroutine-for-tearing-down-an-interface.patch | |||
@@ -0,0 +1,58 @@ | |||
1 | From a2148df99ddcd122247f95c4cbcce5c4118581a1 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Wed, 28 Jun 2017 17:30:00 -0500 | ||
4 | Subject: [PATCH 02/11] Create subroutine for tearing down an interface | ||
5 | |||
6 | Creates a subroutine for tearing down an interface. | ||
7 | |||
8 | Upstream-Status: Submitted [dts@apple.com] | ||
9 | |||
10 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
11 | --- | ||
12 | mDNSPosix/mDNSPosix.c | 22 ++++++++++++++++------ | ||
13 | 1 file changed, 16 insertions(+), 6 deletions(-) | ||
14 | |||
15 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
16 | index ffc9696..5e5b2cd 100644 | ||
17 | --- a/mDNSPosix/mDNSPosix.c | ||
18 | +++ b/mDNSPosix/mDNSPosix.c | ||
19 | @@ -591,6 +591,19 @@ mDNSlocal void FreePosixNetworkInterface(PosixNetworkInterface *intf) | ||
20 | gRecentInterfaces = intf; | ||
21 | } | ||
22 | |||
23 | +mDNSlocal void TearDownInterface(mDNS *const m, PosixNetworkInterface *intf) | ||
24 | +{ | ||
25 | + mDNS_DeregisterInterface(m, &intf->coreIntf, NormalActivation); | ||
26 | + if (gMDNSPlatformPosixVerboseLevel > 0) fprintf(stderr, "Deregistered interface %s\n", intf->intfName); | ||
27 | + FreePosixNetworkInterface(intf); | ||
28 | + | ||
29 | + num_registered_interfaces--; | ||
30 | + if (num_registered_interfaces == 0) { | ||
31 | + num_pkts_accepted = 0; | ||
32 | + num_pkts_rejected = 0; | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | // Grab the first interface, deregister it, free it, and repeat until done. | ||
37 | mDNSlocal void ClearInterfaceList(mDNS *const m) | ||
38 | { | ||
39 | @@ -599,13 +612,10 @@ mDNSlocal void ClearInterfaceList(mDNS *const m) | ||
40 | while (m->HostInterfaces) | ||
41 | { | ||
42 | PosixNetworkInterface *intf = (PosixNetworkInterface*)(m->HostInterfaces); | ||
43 | - mDNS_DeregisterInterface(m, &intf->coreIntf, NormalActivation); | ||
44 | - if (gMDNSPlatformPosixVerboseLevel > 0) fprintf(stderr, "Deregistered interface %s\n", intf->intfName); | ||
45 | - FreePosixNetworkInterface(intf); | ||
46 | + TearDownInterface(m, intf); | ||
47 | } | ||
48 | - num_registered_interfaces = 0; | ||
49 | - num_pkts_accepted = 0; | ||
50 | - num_pkts_rejected = 0; | ||
51 | + | ||
52 | + assert(num_registered_interfaces == 0); | ||
53 | } | ||
54 | |||
55 | // Sets up a send/receive socket. | ||
56 | -- | ||
57 | 2.17.1 | ||
58 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0003-Track-interface-socket-family.patch b/meta-networking/recipes-protocols/mdns/files/0003-Track-interface-socket-family.patch new file mode 100644 index 0000000000..8c0e6bf397 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0003-Track-interface-socket-family.patch | |||
@@ -0,0 +1,50 @@ | |||
1 | From 71a7c728ae0d8143b66aa40decca74ebaa9aa2ce Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Wed, 28 Jun 2017 17:30:00 -0500 | ||
4 | Subject: [PATCH 03/11] Track interface socket family | ||
5 | |||
6 | Tracks the socket family associated with the interface. | ||
7 | |||
8 | Upstream-Status: Submitted [dts@apple.com] | ||
9 | |||
10 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
11 | --- | ||
12 | mDNSPosix/mDNSPosix.c | 1 + | ||
13 | mDNSPosix/mDNSPosix.h | 2 ++ | ||
14 | 2 files changed, 3 insertions(+) | ||
15 | |||
16 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
17 | index 5e5b2cd..8fe22be 100644 | ||
18 | --- a/mDNSPosix/mDNSPosix.c | ||
19 | +++ b/mDNSPosix/mDNSPosix.c | ||
20 | @@ -918,6 +918,7 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct | ||
21 | // Set up the extra fields in PosixNetworkInterface. | ||
22 | assert(intf->intfName != NULL); // intf->intfName already set up above | ||
23 | intf->index = intfIndex; | ||
24 | + intf->sa_family = intfAddr->sa_family; | ||
25 | intf->multicastSocket4 = -1; | ||
26 | #if HAVE_IPV6 | ||
27 | intf->multicastSocket6 = -1; | ||
28 | diff --git a/mDNSPosix/mDNSPosix.h b/mDNSPosix/mDNSPosix.h | ||
29 | index ca60d80..f77c185 100644 | ||
30 | --- a/mDNSPosix/mDNSPosix.h | ||
31 | +++ b/mDNSPosix/mDNSPosix.h | ||
32 | @@ -19,6 +19,7 @@ | ||
33 | #define __mDNSPlatformPosix_h | ||
34 | |||
35 | #include <signal.h> | ||
36 | +#include <sys/socket.h> | ||
37 | #include <sys/time.h> | ||
38 | |||
39 | #ifdef __cplusplus | ||
40 | @@ -40,6 +41,7 @@ struct PosixNetworkInterface | ||
41 | const char * intfName; | ||
42 | PosixNetworkInterface * aliasIntf; | ||
43 | int index; | ||
44 | + sa_family_t sa_family; | ||
45 | int multicastSocket4; | ||
46 | #if HAVE_IPV6 | ||
47 | int multicastSocket6; | ||
48 | -- | ||
49 | 2.17.1 | ||
50 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0004-Use-list-for-changed-interfaces.patch b/meta-networking/recipes-protocols/mdns/files/0004-Use-list-for-changed-interfaces.patch new file mode 100644 index 0000000000..05ad49b9f9 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0004-Use-list-for-changed-interfaces.patch | |||
@@ -0,0 +1,177 @@ | |||
1 | From e1f483510a1011e37540fdee8f3bc36111fa45a0 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Thu, 13 Jul 2017 09:00:00 -0500 | ||
4 | Subject: [PATCH 04/11] Use list for changed interfaces | ||
5 | |||
6 | Uses a linked list to store the index of changed network interfaces | ||
7 | instead of a bitfield. This allows for network interfaces with an | ||
8 | index greater than 31 (an index of 36 was seen on Android). | ||
9 | |||
10 | Upstream-Status: Submitted [dts@apple.com] | ||
11 | |||
12 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
13 | --- | ||
14 | mDNSPosix/mDNSPosix.c | 67 +++++++++++++++++++++++++++++++++---------- | ||
15 | 1 file changed, 52 insertions(+), 15 deletions(-) | ||
16 | |||
17 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
18 | index 8fe22be..699855a 100644 | ||
19 | --- a/mDNSPosix/mDNSPosix.c | ||
20 | +++ b/mDNSPosix/mDNSPosix.c | ||
21 | @@ -75,6 +75,14 @@ struct IfChangeRec | ||
22 | }; | ||
23 | typedef struct IfChangeRec IfChangeRec; | ||
24 | |||
25 | +// Used to build a list of network interface indices | ||
26 | +struct NetworkInterfaceIndex | ||
27 | +{ | ||
28 | + int if_index; | ||
29 | + struct NetworkInterfaceIndex *Next; | ||
30 | +}; | ||
31 | +typedef struct NetworkInterfaceIndex NetworkInterfaceIndex; | ||
32 | + | ||
33 | // Note that static data is initialized to zero in (modern) C. | ||
34 | static fd_set gEventFDs; | ||
35 | static int gMaxFD; // largest fd in gEventFDs | ||
36 | @@ -1071,6 +1079,32 @@ mDNSlocal mStatus OpenIfNotifySocket(int *pFD) | ||
37 | return err; | ||
38 | } | ||
39 | |||
40 | +mDNSlocal mDNSBool ListContainsInterfaceIndex(GenLinkedList *list, int if_index) | ||
41 | +{ | ||
42 | + NetworkInterfaceIndex *item; | ||
43 | + | ||
44 | + for (item = (NetworkInterfaceIndex*)list->Head; item != NULL; item = item->Next) | ||
45 | + { | ||
46 | + if (if_index == item->if_index) return mDNStrue; | ||
47 | + } | ||
48 | + | ||
49 | + return mDNSfalse; | ||
50 | +} | ||
51 | + | ||
52 | +mDNSlocal void AddInterfaceIndexToList(GenLinkedList *list, int if_index) | ||
53 | +{ | ||
54 | + NetworkInterfaceIndex *item; | ||
55 | + | ||
56 | + if (ListContainsInterfaceIndex(list, if_index)) return; | ||
57 | + | ||
58 | + item = malloc(sizeof *item); | ||
59 | + if (item == NULL) return; | ||
60 | + | ||
61 | + item->if_index = if_index; | ||
62 | + item->Next = NULL; | ||
63 | + AddToTail(list, item); | ||
64 | +} | ||
65 | + | ||
66 | #if MDNS_DEBUGMSGS | ||
67 | mDNSlocal void PrintNetLinkMsg(const struct nlmsghdr *pNLMsg) | ||
68 | { | ||
69 | @@ -1098,14 +1132,13 @@ mDNSlocal void PrintNetLinkMsg(const struct nlmsghdr *pNLMsg) | ||
70 | } | ||
71 | #endif | ||
72 | |||
73 | -mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) | ||
74 | +mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *changedInterfaces) | ||
75 | // Read through the messages on sd and if any indicate that any interface records should | ||
76 | // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. | ||
77 | { | ||
78 | ssize_t readCount; | ||
79 | char buff[4096]; | ||
80 | struct nlmsghdr *pNLMsg = (struct nlmsghdr*) buff; | ||
81 | - mDNSu32 result = 0; | ||
82 | |||
83 | // The structure here is more complex than it really ought to be because, | ||
84 | // unfortunately, there's no good way to size a buffer in advance large | ||
85 | @@ -1141,9 +1174,9 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) | ||
86 | |||
87 | // Process the NetLink message | ||
88 | if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK) | ||
89 | - result |= 1 << ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index; | ||
90 | + AddInterfaceIndexToList(changedInterfaces, ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index); | ||
91 | else if (pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) | ||
92 | - result |= 1 << ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index; | ||
93 | + AddInterfaceIndexToList(changedInterfaces, ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index); | ||
94 | |||
95 | // Advance pNLMsg to the next message in the buffer | ||
96 | if ((pNLMsg->nlmsg_flags & NLM_F_MULTI) != 0 && pNLMsg->nlmsg_type != NLMSG_DONE) | ||
97 | @@ -1154,8 +1187,6 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) | ||
98 | else | ||
99 | break; // all done! | ||
100 | } | ||
101 | - | ||
102 | - return result; | ||
103 | } | ||
104 | |||
105 | #else // USES_NETLINK | ||
106 | @@ -1187,14 +1218,13 @@ mDNSlocal void PrintRoutingSocketMsg(const struct ifa_msghdr *pRSMsg) | ||
107 | } | ||
108 | #endif | ||
109 | |||
110 | -mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) | ||
111 | +mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *changedInterfaces) | ||
112 | // Read through the messages on sd and if any indicate that any interface records should | ||
113 | // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. | ||
114 | { | ||
115 | ssize_t readCount; | ||
116 | char buff[4096]; | ||
117 | struct ifa_msghdr *pRSMsg = (struct ifa_msghdr*) buff; | ||
118 | - mDNSu32 result = 0; | ||
119 | |||
120 | readCount = read(sd, buff, sizeof buff); | ||
121 | if (readCount < (ssize_t) sizeof(struct ifa_msghdr)) | ||
122 | @@ -1209,12 +1239,10 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) | ||
123 | pRSMsg->ifam_type == RTM_IFINFO) | ||
124 | { | ||
125 | if (pRSMsg->ifam_type == RTM_IFINFO) | ||
126 | - result |= 1 << ((struct if_msghdr*) pRSMsg)->ifm_index; | ||
127 | + AddInterfaceIndexToList(changedInterfaces, ((struct if_msghdr*) pRSMsg)->ifm_index); | ||
128 | else | ||
129 | - result |= 1 << pRSMsg->ifam_index; | ||
130 | + AddInterfaceIndexToList(changedInterfaces, pRSMsg->ifam_index); | ||
131 | } | ||
132 | - | ||
133 | - return result; | ||
134 | } | ||
135 | |||
136 | #endif // USES_NETLINK | ||
137 | @@ -1224,7 +1252,8 @@ mDNSlocal void InterfaceChangeCallback(int fd, short filter, void *context) | ||
138 | { | ||
139 | IfChangeRec *pChgRec = (IfChangeRec*) context; | ||
140 | fd_set readFDs; | ||
141 | - mDNSu32 changedInterfaces = 0; | ||
142 | + GenLinkedList changedInterfaces; | ||
143 | + NetworkInterfaceIndex *changedInterface; | ||
144 | struct timeval zeroTimeout = { 0, 0 }; | ||
145 | |||
146 | (void)fd; // Unused | ||
147 | @@ -1233,17 +1262,25 @@ mDNSlocal void InterfaceChangeCallback(int fd, short filter, void *context) | ||
148 | FD_ZERO(&readFDs); | ||
149 | FD_SET(pChgRec->NotifySD, &readFDs); | ||
150 | |||
151 | + InitLinkedList(&changedInterfaces, offsetof(NetworkInterfaceIndex, Next)); | ||
152 | + | ||
153 | do | ||
154 | { | ||
155 | - changedInterfaces |= ProcessRoutingNotification(pChgRec->NotifySD); | ||
156 | + ProcessRoutingNotification(pChgRec->NotifySD, &changedInterfaces); | ||
157 | } | ||
158 | while (0 < select(pChgRec->NotifySD + 1, &readFDs, (fd_set*) NULL, (fd_set*) NULL, &zeroTimeout)); | ||
159 | |||
160 | // Currently we rebuild the entire interface list whenever any interface change is | ||
161 | // detected. If this ever proves to be a performance issue in a multi-homed | ||
162 | // configuration, more care should be paid to changedInterfaces. | ||
163 | - if (changedInterfaces) | ||
164 | + if (changedInterfaces.Head != NULL) | ||
165 | mDNSPlatformPosixRefreshInterfaceList(pChgRec->mDNS); | ||
166 | + | ||
167 | + while ((changedInterface = (NetworkInterfaceIndex*)changedInterfaces.Head) != NULL) | ||
168 | + { | ||
169 | + RemoveFromList(&changedInterfaces, changedInterface); | ||
170 | + free(changedInterface); | ||
171 | + } | ||
172 | } | ||
173 | |||
174 | // Register with either a Routing Socket or RtNetLink to listen for interface changes. | ||
175 | -- | ||
176 | 2.17.1 | ||
177 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0005-Handle-noisy-netlink-sockets.patch b/meta-networking/recipes-protocols/mdns/files/0005-Handle-noisy-netlink-sockets.patch new file mode 100644 index 0000000000..f2b171e55b --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0005-Handle-noisy-netlink-sockets.patch | |||
@@ -0,0 +1,212 @@ | |||
1 | From 92025cab86619f548bf3eb816a1804ef40507ca7 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Mon, 24 Jul 2017 09:38:55 -0500 | ||
4 | Subject: [PATCH 05/11] Handle noisy netlink sockets | ||
5 | |||
6 | The POSIX implementation currently clears all network interfaces | ||
7 | when netlink indicates that there has been a change. This causes | ||
8 | the following problems: | ||
9 | |||
10 | 1) Applications are informed that all of the services they are | ||
11 | tracking have been removed. | ||
12 | 2) Increases network load because the client must re-query for | ||
13 | all records it is interested in. | ||
14 | |||
15 | This changes netlink notification handling by: | ||
16 | |||
17 | 1) Always comparing with the latest interface list returned | ||
18 | by the OS. | ||
19 | 2) Confirming that the interface has been changed in a way | ||
20 | that we care about. | ||
21 | |||
22 | Upstream-Status: Submitted [dts@apple.com] | ||
23 | |||
24 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
25 | --- | ||
26 | mDNSPosix/mDNSPosix.c | 143 +++++++++++++++++++++++++++++++++++++++--- | ||
27 | 1 file changed, 133 insertions(+), 10 deletions(-) | ||
28 | |||
29 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
30 | index 699855a..59a8b8c 100644 | ||
31 | --- a/mDNSPosix/mDNSPosix.c | ||
32 | +++ b/mDNSPosix/mDNSPosix.c | ||
33 | @@ -1247,14 +1247,38 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change | ||
34 | |||
35 | #endif // USES_NETLINK | ||
36 | |||
37 | +// Test whether the given PosixNetworkInterface matches the given struct ifi_info | ||
38 | +mDNSlocal mDNSBool InterfacesMatch(PosixNetworkInterface *intf, struct ifi_info *ifi) | ||
39 | +{ | ||
40 | + mDNSBool match = mDNSfalse; | ||
41 | + mDNSAddr ip, mask; | ||
42 | + | ||
43 | + if((intf->index == ifi->ifi_index) && | ||
44 | + (intf->sa_family == ifi->ifi_addr->sa_family) && | ||
45 | + (strcmp(intf->coreIntf.ifname, ifi->ifi_name) == 0)) | ||
46 | + { | ||
47 | + SockAddrTomDNSAddr(ifi->ifi_addr, &ip, NULL); | ||
48 | + SockAddrTomDNSAddr(ifi->ifi_netmask, &mask, NULL); | ||
49 | + | ||
50 | + match = mDNSSameAddress(&intf->coreIntf.ip, &ip) && | ||
51 | + mDNSSameAddress(&intf->coreIntf.mask, &mask); | ||
52 | + } | ||
53 | + | ||
54 | + return match; | ||
55 | +} | ||
56 | + | ||
57 | // Called when data appears on interface change notification socket | ||
58 | mDNSlocal void InterfaceChangeCallback(int fd, short filter, void *context) | ||
59 | { | ||
60 | IfChangeRec *pChgRec = (IfChangeRec*) context; | ||
61 | + mDNS *m = pChgRec->mDNS; | ||
62 | fd_set readFDs; | ||
63 | GenLinkedList changedInterfaces; | ||
64 | NetworkInterfaceIndex *changedInterface; | ||
65 | struct timeval zeroTimeout = { 0, 0 }; | ||
66 | + struct ifi_info *ifi_list, **ifi, *ifi_free, *ifi_loop4 = NULL; | ||
67 | + PosixNetworkInterface *intf, *intfNext; | ||
68 | + mDNSBool found, foundav4; | ||
69 | |||
70 | (void)fd; // Unused | ||
71 | (void)filter; // Unused | ||
72 | @@ -1270,12 +1294,115 @@ mDNSlocal void InterfaceChangeCallback(int fd, short filter, void *context) | ||
73 | } | ||
74 | while (0 < select(pChgRec->NotifySD + 1, &readFDs, (fd_set*) NULL, (fd_set*) NULL, &zeroTimeout)); | ||
75 | |||
76 | - // Currently we rebuild the entire interface list whenever any interface change is | ||
77 | - // detected. If this ever proves to be a performance issue in a multi-homed | ||
78 | - // configuration, more care should be paid to changedInterfaces. | ||
79 | - if (changedInterfaces.Head != NULL) | ||
80 | - mDNSPlatformPosixRefreshInterfaceList(pChgRec->mDNS); | ||
81 | + CleanRecentInterfaces(); | ||
82 | + | ||
83 | + if (changedInterfaces.Head == NULL) goto cleanup; | ||
84 | + | ||
85 | + ifi_list = get_ifi_info(AF_INET, mDNStrue); | ||
86 | + if (ifi_list == NULL) goto cleanup; | ||
87 | + | ||
88 | +#if HAVE_IPV6 | ||
89 | + /* Link the IPv6 list to the end of the IPv4 list */ | ||
90 | + ifi = &ifi_list; | ||
91 | + while (*ifi != NULL) ifi = &(*ifi)->ifi_next; | ||
92 | + *ifi = get_ifi_info(AF_INET6, mDNStrue); | ||
93 | +#endif | ||
94 | + | ||
95 | + for (intf = (PosixNetworkInterface*)(m->HostInterfaces); intf != NULL; intf = intfNext) | ||
96 | + { | ||
97 | + intfNext = (PosixNetworkInterface*)(intf->coreIntf.next); | ||
98 | + | ||
99 | + // Loopback interface(s) are handled later | ||
100 | + if (intf->coreIntf.Loopback) continue; | ||
101 | + | ||
102 | + found = mDNSfalse; | ||
103 | + for (ifi = &ifi_list; *ifi != NULL; ifi = &(*ifi)->ifi_next) | ||
104 | + { | ||
105 | + if (InterfacesMatch(intf, *ifi)) | ||
106 | + { | ||
107 | + found = mDNStrue; | ||
108 | + | ||
109 | + // Removes unchanged from ifi_list | ||
110 | + ifi_free = *ifi; | ||
111 | + *ifi = (*ifi)->ifi_next; | ||
112 | + ifi_free->ifi_next = NULL; | ||
113 | + free_ifi_info(ifi_free); | ||
114 | + | ||
115 | + break; | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + // Removes changed and old interfaces from m->HostInterfaces | ||
120 | + if (!found) TearDownInterface(m, intf); | ||
121 | + } | ||
122 | + | ||
123 | + // Add new and changed interfaces in ifi_list | ||
124 | + // Save off loopback interface in case it is needed later | ||
125 | + for (ifi = &ifi_list; *ifi != NULL; ifi = &(*ifi)->ifi_next) | ||
126 | + { | ||
127 | + if ((ifi_loop4 == NULL) && | ||
128 | + ((*ifi)->ifi_addr->sa_family == AF_INET) && | ||
129 | + ((*ifi)->ifi_flags & IFF_UP) && | ||
130 | + ((*ifi)->ifi_flags & IFF_LOOPBACK)) | ||
131 | + { | ||
132 | + ifi_loop4 = *ifi; | ||
133 | + continue; | ||
134 | + } | ||
135 | + | ||
136 | + if ( (((*ifi)->ifi_addr->sa_family == AF_INET) | ||
137 | +#if HAVE_IPV6 | ||
138 | + || ((*ifi)->ifi_addr->sa_family == AF_INET6) | ||
139 | +#endif | ||
140 | + ) && ((*ifi)->ifi_flags & IFF_UP) | ||
141 | + && !((*ifi)->ifi_flags & IFF_POINTOPOINT) | ||
142 | + && !((*ifi)->ifi_flags & IFF_LOOPBACK)) | ||
143 | + { | ||
144 | + SetupOneInterface(m, *ifi); | ||
145 | + } | ||
146 | + } | ||
147 | + | ||
148 | + // Determine if there is at least one non-loopback IPv4 interface. This is to work around issues | ||
149 | + // with multicast loopback on IPv6 interfaces -- see corresponding logic in SetupInterfaceList(). | ||
150 | + foundav4 = mDNSfalse; | ||
151 | + for (intf = (PosixNetworkInterface*)(m->HostInterfaces); intf != NULL; intf = (PosixNetworkInterface*)(intf->coreIntf.next)) | ||
152 | + { | ||
153 | + if (intf->sa_family == AF_INET && !intf->coreIntf.Loopback) | ||
154 | + { | ||
155 | + foundav4 = mDNStrue; | ||
156 | + break; | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
160 | + if (foundav4) | ||
161 | + { | ||
162 | + for (intf = (PosixNetworkInterface*)(m->HostInterfaces); intf != NULL; intf = intfNext) | ||
163 | + { | ||
164 | + intfNext = (PosixNetworkInterface*)(intf->coreIntf.next); | ||
165 | + if (intf->coreIntf.Loopback) TearDownInterface(m, intf); | ||
166 | + } | ||
167 | + } | ||
168 | + else | ||
169 | + { | ||
170 | + found = mDNSfalse; | ||
171 | + | ||
172 | + for (intf = (PosixNetworkInterface*)(m->HostInterfaces); intf != NULL; intf = (PosixNetworkInterface*)(intf->coreIntf.next)) | ||
173 | + { | ||
174 | + if (intf->coreIntf.Loopback) | ||
175 | + { | ||
176 | + found = mDNStrue; | ||
177 | + break; | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | + if (!found && (ifi_loop4 != NULL)) | ||
182 | + { | ||
183 | + SetupOneInterface(m, ifi_loop4); | ||
184 | + } | ||
185 | + } | ||
186 | + | ||
187 | + if (ifi_list != NULL) free_ifi_info(ifi_list); | ||
188 | |||
189 | +cleanup: | ||
190 | while ((changedInterface = (NetworkInterfaceIndex*)changedInterfaces.Head) != NULL) | ||
191 | { | ||
192 | RemoveFromList(&changedInterfaces, changedInterface); | ||
193 | @@ -1400,15 +1527,11 @@ mDNSexport void mDNSPlatformClose(mDNS *const m) | ||
194 | #endif | ||
195 | } | ||
196 | |||
197 | -// This is used internally by InterfaceChangeCallback. | ||
198 | -// It's also exported so that the Standalone Responder (mDNSResponderPosix) | ||
199 | +// This is exported so that the Standalone Responder (mDNSResponderPosix) | ||
200 | // can call it in response to a SIGHUP (mainly for debugging purposes). | ||
201 | mDNSexport mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m) | ||
202 | { | ||
203 | int err; | ||
204 | - // This is a pretty heavyweight way to process interface changes -- | ||
205 | - // destroying the entire interface list and then making fresh one from scratch. | ||
206 | - // We should make it like the OS X version, which leaves unchanged interfaces alone. | ||
207 | ClearInterfaceList(m); | ||
208 | err = SetupInterfaceList(m); | ||
209 | return PosixErrorToStatus(err); | ||
210 | -- | ||
211 | 2.17.1 | ||
212 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0006-Remove-unneeded-function.patch b/meta-networking/recipes-protocols/mdns/files/0006-Remove-unneeded-function.patch new file mode 100644 index 0000000000..b461a60df7 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0006-Remove-unneeded-function.patch | |||
@@ -0,0 +1,51 @@ | |||
1 | From 157d67f152777754c059ced7511352102f23ffae Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Mon, 24 Jul 2017 09:39:18 -0500 | ||
4 | Subject: [PATCH 06/11] Remove unneeded function | ||
5 | |||
6 | Removes a function we no longer need by integrating it into the only | ||
7 | function that calls it. This was originally separated so that we could | ||
8 | only process network interfaces that netlink indicated had been changed, | ||
9 | this has since been extended to test for all network intefaces. | ||
10 | |||
11 | Upstream-Status: Submitted [dts@apple.com] | ||
12 | |||
13 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
14 | --- | ||
15 | mDNSPosix/mDNSPosix.c | 13 ++----------- | ||
16 | 1 file changed, 2 insertions(+), 11 deletions(-) | ||
17 | |||
18 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
19 | index 59a8b8c..3fc5451 100644 | ||
20 | --- a/mDNSPosix/mDNSPosix.c | ||
21 | +++ b/mDNSPosix/mDNSPosix.c | ||
22 | @@ -1079,24 +1079,15 @@ mDNSlocal mStatus OpenIfNotifySocket(int *pFD) | ||
23 | return err; | ||
24 | } | ||
25 | |||
26 | -mDNSlocal mDNSBool ListContainsInterfaceIndex(GenLinkedList *list, int if_index) | ||
27 | +mDNSlocal void AddInterfaceIndexToList(GenLinkedList *list, int if_index) | ||
28 | { | ||
29 | NetworkInterfaceIndex *item; | ||
30 | |||
31 | for (item = (NetworkInterfaceIndex*)list->Head; item != NULL; item = item->Next) | ||
32 | { | ||
33 | - if (if_index == item->if_index) return mDNStrue; | ||
34 | + if (if_index == item->if_index) return; | ||
35 | } | ||
36 | |||
37 | - return mDNSfalse; | ||
38 | -} | ||
39 | - | ||
40 | -mDNSlocal void AddInterfaceIndexToList(GenLinkedList *list, int if_index) | ||
41 | -{ | ||
42 | - NetworkInterfaceIndex *item; | ||
43 | - | ||
44 | - if (ListContainsInterfaceIndex(list, if_index)) return; | ||
45 | - | ||
46 | item = malloc(sizeof *item); | ||
47 | if (item == NULL) return; | ||
48 | |||
49 | -- | ||
50 | 2.17.1 | ||
51 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0007-Indicate-loopback-interface-to-mDNS-core.patch b/meta-networking/recipes-protocols/mdns/files/0007-Indicate-loopback-interface-to-mDNS-core.patch new file mode 100644 index 0000000000..86201c650d --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0007-Indicate-loopback-interface-to-mDNS-core.patch | |||
@@ -0,0 +1,129 @@ | |||
1 | From 07a9401d84804d7f0181aa4fb0f13a54b2a1c9a8 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Tue, 1 Aug 2017 17:06:01 -0500 | ||
4 | Subject: [PATCH 07/11] Indicate loopback interface to mDNS core | ||
5 | |||
6 | Tells the mDNS core if an interface is a loopback interface, | ||
7 | similar to AddInterfaceToList() in the MacOS implementation. | ||
8 | Also reorganizes SetupOneInterface() to use a const struct | ||
9 | rather than growing its parameter list again. | ||
10 | |||
11 | Upstream-Status: Submitted [dts@apple.com] | ||
12 | |||
13 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
14 | --- | ||
15 | mDNSPosix/mDNSPosix.c | 37 ++++++++++++++++++------------------- | ||
16 | 1 file changed, 18 insertions(+), 19 deletions(-) | ||
17 | |||
18 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
19 | index 3fc5451..798ab10 100644 | ||
20 | --- a/mDNSPosix/mDNSPosix.c | ||
21 | +++ b/mDNSPosix/mDNSPosix.c | ||
22 | @@ -889,16 +889,14 @@ mDNSlocal void CleanRecentInterfaces(void) | ||
23 | |||
24 | // Creates a PosixNetworkInterface for the interface whose IP address is | ||
25 | // intfAddr and whose name is intfName and registers it with mDNS core. | ||
26 | -mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex) | ||
27 | +mDNSlocal int SetupOneInterface(mDNS *const m, struct ifi_info *const ifi) | ||
28 | { | ||
29 | int err = 0; | ||
30 | PosixNetworkInterface *intf; | ||
31 | PosixNetworkInterface *alias = NULL; | ||
32 | |||
33 | assert(m != NULL); | ||
34 | - assert(intfAddr != NULL); | ||
35 | - assert(intfName != NULL); | ||
36 | - assert(intfMask != NULL); | ||
37 | + assert(ifi != NULL); | ||
38 | |||
39 | // Allocate the interface structure itself. | ||
40 | intf = (PosixNetworkInterface*)calloc(1, sizeof(*intf)); | ||
41 | @@ -907,26 +905,27 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct | ||
42 | // And make a copy of the intfName. | ||
43 | if (err == 0) | ||
44 | { | ||
45 | - intf->intfName = strdup(intfName); | ||
46 | + intf->intfName = strdup(ifi->ifi_name); | ||
47 | if (intf->intfName == NULL) { assert(0); err = ENOMEM; } | ||
48 | } | ||
49 | |||
50 | if (err == 0) | ||
51 | { | ||
52 | // Set up the fields required by the mDNS core. | ||
53 | - SockAddrTomDNSAddr(intfAddr, &intf->coreIntf.ip, NULL); | ||
54 | - SockAddrTomDNSAddr(intfMask, &intf->coreIntf.mask, NULL); | ||
55 | + SockAddrTomDNSAddr(ifi->ifi_addr, &intf->coreIntf.ip, NULL); | ||
56 | + SockAddrTomDNSAddr(ifi->ifi_netmask, &intf->coreIntf.mask, NULL); | ||
57 | |||
58 | //LogMsg("SetupOneInterface: %#a %#a", &intf->coreIntf.ip, &intf->coreIntf.mask); | ||
59 | - strncpy(intf->coreIntf.ifname, intfName, sizeof(intf->coreIntf.ifname)); | ||
60 | + strncpy(intf->coreIntf.ifname, ifi->ifi_name, sizeof(intf->coreIntf.ifname)); | ||
61 | intf->coreIntf.ifname[sizeof(intf->coreIntf.ifname)-1] = 0; | ||
62 | intf->coreIntf.Advertise = m->AdvertiseLocalAddresses; | ||
63 | intf->coreIntf.McastTxRx = mDNStrue; | ||
64 | + intf->coreIntf.Loopback = ((ifi->ifi_flags & IFF_LOOPBACK) != 0) ? mDNStrue : mDNSfalse; | ||
65 | |||
66 | // Set up the extra fields in PosixNetworkInterface. | ||
67 | assert(intf->intfName != NULL); // intf->intfName already set up above | ||
68 | - intf->index = intfIndex; | ||
69 | - intf->sa_family = intfAddr->sa_family; | ||
70 | + intf->index = ifi->ifi_index; | ||
71 | + intf->sa_family = ifi->ifi_addr->sa_family; | ||
72 | intf->multicastSocket4 = -1; | ||
73 | #if HAVE_IPV6 | ||
74 | intf->multicastSocket6 = -1; | ||
75 | @@ -936,17 +935,17 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct | ||
76 | intf->coreIntf.InterfaceID = (mDNSInterfaceID)alias; | ||
77 | |||
78 | if (alias != intf) | ||
79 | - debugf("SetupOneInterface: %s %#a is an alias of %#a", intfName, &intf->coreIntf.ip, &alias->coreIntf.ip); | ||
80 | + debugf("SetupOneInterface: %s %#a is an alias of %#a", ifi->ifi_name, &intf->coreIntf.ip, &alias->coreIntf.ip); | ||
81 | } | ||
82 | |||
83 | // Set up the multicast socket | ||
84 | if (err == 0) | ||
85 | { | ||
86 | - if (alias->multicastSocket4 == -1 && intfAddr->sa_family == AF_INET) | ||
87 | - err = SetupSocket(intfAddr, MulticastDNSPort, intf->index, &alias->multicastSocket4); | ||
88 | + if (alias->multicastSocket4 == -1 && ifi->ifi_addr->sa_family == AF_INET) | ||
89 | + err = SetupSocket(ifi->ifi_addr, MulticastDNSPort, intf->index, &alias->multicastSocket4); | ||
90 | #if HAVE_IPV6 | ||
91 | - else if (alias->multicastSocket6 == -1 && intfAddr->sa_family == AF_INET6) | ||
92 | - err = SetupSocket(intfAddr, MulticastDNSPort, intf->index, &alias->multicastSocket6); | ||
93 | + else if (alias->multicastSocket6 == -1 && ifi->ifi_addr->sa_family == AF_INET6) | ||
94 | + err = SetupSocket(ifi->ifi_addr, MulticastDNSPort, intf->index, &alias->multicastSocket6); | ||
95 | #endif | ||
96 | } | ||
97 | |||
98 | @@ -973,8 +972,8 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | - // Use intfName instead of intf->intfName in the next line to avoid dereferencing NULL. | ||
103 | - debugf("SetupOneInterface: %s %#a failed to register %d", intfName, &intf->coreIntf.ip, err); | ||
104 | + // Use ifi->ifi_name instead of intf->intfName in the next line to avoid dereferencing NULL. | ||
105 | + debugf("SetupOneInterface: %s %#a failed to register %d", ifi->ifi_name, &intf->coreIntf.ip, err); | ||
106 | if (intf) { FreePosixNetworkInterface(intf); intf = NULL; } | ||
107 | } | ||
108 | |||
109 | @@ -1023,7 +1022,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m) | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | - if (SetupOneInterface(m, i->ifi_addr, i->ifi_netmask, i->ifi_name, i->ifi_index) == 0) | ||
114 | + if (SetupOneInterface(m, i) == 0) | ||
115 | if (i->ifi_addr->sa_family == AF_INET) | ||
116 | foundav4 = mDNStrue; | ||
117 | } | ||
118 | @@ -1037,7 +1036,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m) | ||
119 | // In the interim, we skip loopback interface only if we found at least one v4 interface to use | ||
120 | // if ((m->HostInterfaces == NULL) && (firstLoopback != NULL)) | ||
121 | if (!foundav4 && firstLoopback) | ||
122 | - (void) SetupOneInterface(m, firstLoopback->ifi_addr, firstLoopback->ifi_netmask, firstLoopback->ifi_name, firstLoopback->ifi_index); | ||
123 | + (void) SetupOneInterface(m, firstLoopback); | ||
124 | } | ||
125 | |||
126 | // Clean up. | ||
127 | -- | ||
128 | 2.17.1 | ||
129 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0008-Mark-deleted-interfaces-as-being-changed.patch b/meta-networking/recipes-protocols/mdns/files/0008-Mark-deleted-interfaces-as-being-changed.patch new file mode 100644 index 0000000000..fdc5105cb9 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0008-Mark-deleted-interfaces-as-being-changed.patch | |||
@@ -0,0 +1,39 @@ | |||
1 | From 0fcc0f210f3a9310a1963de640b384ce866410fd Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Wed, 9 Aug 2017 09:16:58 -0500 | ||
4 | Subject: [PATCH 08/11] Mark deleted interfaces as being changed | ||
5 | |||
6 | Netlink notification handling ignores messages for deleted links, | ||
7 | RTM_DELLINK. It does handle RTM_GETLINK. According to libnl docu- | ||
8 | mentation (http://www.infradead.org/~tgr/libnl/doc/route.html) | ||
9 | RTM_DELLINK can be sent by the kernel, but RTM_GETLINK cannot. | ||
10 | There was likely a mixup in the original implementation, so this | ||
11 | change replaces handling for RTM_GETLINK with RTM_DELLINK. | ||
12 | |||
13 | Testing and Verification Instructions: | ||
14 | 1. Use ip-link to add and remove a VLAN interface and verify | ||
15 | that mDNSResponder handles the deleted link. | ||
16 | |||
17 | Upstream-Status: Submitted [dts@apple.com] | ||
18 | |||
19 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
20 | --- | ||
21 | mDNSPosix/mDNSPosix.c | 2 +- | ||
22 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
23 | |||
24 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
25 | index 798ab10..a8a57df 100644 | ||
26 | --- a/mDNSPosix/mDNSPosix.c | ||
27 | +++ b/mDNSPosix/mDNSPosix.c | ||
28 | @@ -1163,7 +1163,7 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change | ||
29 | #endif | ||
30 | |||
31 | // Process the NetLink message | ||
32 | - if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK) | ||
33 | + if (pNLMsg->nlmsg_type == RTM_DELLINK || pNLMsg->nlmsg_type == RTM_NEWLINK) | ||
34 | AddInterfaceIndexToList(changedInterfaces, ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index); | ||
35 | else if (pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) | ||
36 | AddInterfaceIndexToList(changedInterfaces, ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index); | ||
37 | -- | ||
38 | 2.17.1 | ||
39 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0009-Fix-possible-NULL-dereference.patch b/meta-networking/recipes-protocols/mdns/files/0009-Fix-possible-NULL-dereference.patch new file mode 100644 index 0000000000..362d69768e --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0009-Fix-possible-NULL-dereference.patch | |||
@@ -0,0 +1,45 @@ | |||
1 | From 38cff19781f81586926b02f0fd1cb36c040395e0 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Thu, 10 Aug 2017 08:21:53 -0500 | ||
4 | Subject: [PATCH 09/11] Fix possible NULL dereference | ||
5 | |||
6 | Fixes a possible NULL dereference if memory for | ||
7 | the PosixNetworkInterface could not be allocated. | ||
8 | Other logic seems to prevent dereferencing this | ||
9 | variable if NULL, but this instance seems to have | ||
10 | been overlooked. | ||
11 | |||
12 | Upstream-Status: Submitted [dts@apple.com] | ||
13 | |||
14 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
15 | --- | ||
16 | mDNSPosix/mDNSPosix.c | 11 +++++++---- | ||
17 | 1 file changed, 7 insertions(+), 4 deletions(-) | ||
18 | |||
19 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
20 | index a8a57df..3243ed4 100644 | ||
21 | --- a/mDNSPosix/mDNSPosix.c | ||
22 | +++ b/mDNSPosix/mDNSPosix.c | ||
23 | @@ -951,12 +951,15 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct ifi_info *const ifi) | ||
24 | |||
25 | // If interface is a direct link, address record will be marked as kDNSRecordTypeKnownUnique | ||
26 | // and skip the probe phase of the probe/announce packet sequence. | ||
27 | - intf->coreIntf.DirectLink = mDNSfalse; | ||
28 | + if (err == 0) | ||
29 | + { | ||
30 | + intf->coreIntf.DirectLink = mDNSfalse; | ||
31 | #ifdef DIRECTLINK_INTERFACE_NAME | ||
32 | - if (strcmp(intfName, STRINGIFY(DIRECTLINK_INTERFACE_NAME)) == 0) | ||
33 | - intf->coreIntf.DirectLink = mDNStrue; | ||
34 | + if (strcmp(intfName, STRINGIFY(DIRECTLINK_INTERFACE_NAME)) == 0) | ||
35 | + intf->coreIntf.DirectLink = mDNStrue; | ||
36 | #endif | ||
37 | - intf->coreIntf.SupportsUnicastMDNSResponse = mDNStrue; | ||
38 | + intf->coreIntf.SupportsUnicastMDNSResponse = mDNStrue; | ||
39 | + } | ||
40 | |||
41 | // The interface is all ready to go, let's register it with the mDNS core. | ||
42 | if (err == 0) | ||
43 | -- | ||
44 | 2.17.1 | ||
45 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0010-Handle-errors-from-socket-calls.patch b/meta-networking/recipes-protocols/mdns/files/0010-Handle-errors-from-socket-calls.patch new file mode 100644 index 0000000000..b9b0157276 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0010-Handle-errors-from-socket-calls.patch | |||
@@ -0,0 +1,62 @@ | |||
1 | From 382b3b924e43abd1bdc5792918161d0922666691 Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Thu, 10 Aug 2017 08:27:32 -0500 | ||
4 | Subject: [PATCH 10/11] Handle errors from socket calls | ||
5 | |||
6 | Adds handling for socket() or read() returning a | ||
7 | negative value (indicating an error has occurred). | ||
8 | |||
9 | Upstream-Status: Submitted [dts@apple.com] | ||
10 | |||
11 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
12 | --- | ||
13 | mDNSPosix/mDNSPosix.c | 12 +++++++++--- | ||
14 | 1 file changed, 9 insertions(+), 3 deletions(-) | ||
15 | |||
16 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
17 | index 3243ed4..84af26b 100644 | ||
18 | --- a/mDNSPosix/mDNSPosix.c | ||
19 | +++ b/mDNSPosix/mDNSPosix.c | ||
20 | @@ -1129,7 +1129,7 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change | ||
21 | // Read through the messages on sd and if any indicate that any interface records should | ||
22 | // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. | ||
23 | { | ||
24 | - ssize_t readCount; | ||
25 | + ssize_t readVal, readCount; | ||
26 | char buff[4096]; | ||
27 | struct nlmsghdr *pNLMsg = (struct nlmsghdr*) buff; | ||
28 | |||
29 | @@ -1138,7 +1138,10 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change | ||
30 | // enough to hold all pending data and so avoid message fragmentation. | ||
31 | // (Note that FIONREAD is not supported on AF_NETLINK.) | ||
32 | |||
33 | - readCount = read(sd, buff, sizeof buff); | ||
34 | + readVal = read(sd, buff, sizeof buff); | ||
35 | + if (readVal < 0) return; | ||
36 | + readCount = readVal; | ||
37 | + | ||
38 | while (1) | ||
39 | { | ||
40 | // Make sure we've got an entire nlmsghdr in the buffer, and payload, too. | ||
41 | @@ -1154,7 +1157,9 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change | ||
42 | pNLMsg = (struct nlmsghdr*) buff; | ||
43 | |||
44 | // read more data | ||
45 | - readCount += read(sd, buff + readCount, sizeof buff - readCount); | ||
46 | + readVal = read(sd, buff + readCount, sizeof buff - readCount); | ||
47 | + if (readVal < 0) return; | ||
48 | + readCount += readVal; | ||
49 | continue; // spin around and revalidate with new readCount | ||
50 | } | ||
51 | else | ||
52 | @@ -1429,6 +1434,7 @@ mDNSlocal mDNSBool mDNSPlatformInit_CanReceiveUnicast(void) | ||
53 | int err; | ||
54 | int s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | ||
55 | struct sockaddr_in s5353; | ||
56 | + if (s < 0) return mDNSfalse; | ||
57 | s5353.sin_family = AF_INET; | ||
58 | s5353.sin_port = MulticastDNSPort.NotAnInteger; | ||
59 | s5353.sin_addr.s_addr = 0; | ||
60 | -- | ||
61 | 2.17.1 | ||
62 | |||
diff --git a/meta-networking/recipes-protocols/mdns/files/0011-Change-a-dynamic-allocation-to-file-scope-variable.patch b/meta-networking/recipes-protocols/mdns/files/0011-Change-a-dynamic-allocation-to-file-scope-variable.patch new file mode 100644 index 0000000000..d64fb35db1 --- /dev/null +++ b/meta-networking/recipes-protocols/mdns/files/0011-Change-a-dynamic-allocation-to-file-scope-variable.patch | |||
@@ -0,0 +1,51 @@ | |||
1 | From 19de26db69408f02241e232b39224589a0f630df Mon Sep 17 00:00:00 2001 | ||
2 | From: Nate Karstens <nate.karstens@garmin.com> | ||
3 | Date: Thu, 10 Aug 2017 08:46:03 -0500 | ||
4 | Subject: [PATCH 11/11] Change a dynamic allocation to file-scope variable | ||
5 | |||
6 | Changes a variable from being dynamically-allocated to being | ||
7 | statically-allocated at the file scope. Addresses a Coverity | ||
8 | issue where it appeared that the memory was being leaked. | ||
9 | |||
10 | Upstream-Status: Submitted [dts@apple.com] | ||
11 | |||
12 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> | ||
13 | --- | ||
14 | mDNSPosix/mDNSPosix.c | 12 ++++-------- | ||
15 | 1 file changed, 4 insertions(+), 8 deletions(-) | ||
16 | |||
17 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c | ||
18 | index 84af26b..b7795ed 100644 | ||
19 | --- a/mDNSPosix/mDNSPosix.c | ||
20 | +++ b/mDNSPosix/mDNSPosix.c | ||
21 | @@ -91,6 +91,7 @@ static sigset_t gEventSignalSet; // Signals which event loop list | ||
22 | static sigset_t gEventSignals; // Signals which were received while inside loop | ||
23 | |||
24 | static PosixNetworkInterface *gRecentInterfaces; | ||
25 | +static IfChangeRec gChgRec; | ||
26 | |||
27 | // *************************************************************************** | ||
28 | // Globals (for debugging) | ||
29 | @@ -1412,16 +1413,11 @@ cleanup: | ||
30 | mDNSlocal mStatus WatchForInterfaceChange(mDNS *const m) | ||
31 | { | ||
32 | mStatus err; | ||
33 | - IfChangeRec *pChgRec; | ||
34 | |||
35 | - pChgRec = (IfChangeRec*) mDNSPlatformMemAllocate(sizeof *pChgRec); | ||
36 | - if (pChgRec == NULL) | ||
37 | - return mStatus_NoMemoryErr; | ||
38 | - | ||
39 | - pChgRec->mDNS = m; | ||
40 | - err = OpenIfNotifySocket(&pChgRec->NotifySD); | ||
41 | + gChgRec.mDNS = m; | ||
42 | + err = OpenIfNotifySocket(&gChgRec.NotifySD); | ||
43 | if (err == 0) | ||
44 | - err = mDNSPosixAddFDToEventLoop(pChgRec->NotifySD, InterfaceChangeCallback, pChgRec); | ||
45 | + err = mDNSPosixAddFDToEventLoop(gChgRec.NotifySD, InterfaceChangeCallback, &gChgRec); | ||
46 | |||
47 | return err; | ||
48 | } | ||
49 | -- | ||
50 | 2.17.1 | ||
51 | |||
diff --git a/meta-networking/recipes-protocols/mdns/mdns_878.260.1.bb b/meta-networking/recipes-protocols/mdns/mdns_878.260.1.bb index 0178945316..a5991bf73a 100644 --- a/meta-networking/recipes-protocols/mdns/mdns_878.260.1.bb +++ b/meta-networking/recipes-protocols/mdns/mdns_878.260.1.bb | |||
@@ -11,6 +11,17 @@ RPROVIDES_${PN} += "libdns_sd.so" | |||
11 | SRC_URI = "https://opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-${PV}.tar.gz \ | 11 | SRC_URI = "https://opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-${PV}.tar.gz \ |
12 | file://build.patch;patchdir=.. \ | 12 | file://build.patch;patchdir=.. \ |
13 | file://mdns.service \ | 13 | file://mdns.service \ |
14 | file://0001-Create-subroutine-for-cleaning-recent-interfaces.patch;patchdir=.. \ | ||
15 | file://0002-Create-subroutine-for-tearing-down-an-interface.patch;patchdir=.. \ | ||
16 | file://0003-Track-interface-socket-family.patch;patchdir=.. \ | ||
17 | file://0004-Use-list-for-changed-interfaces.patch;patchdir=.. \ | ||
18 | file://0005-Handle-noisy-netlink-sockets.patch;patchdir=.. \ | ||
19 | file://0006-Remove-unneeded-function.patch;patchdir=.. \ | ||
20 | file://0007-Indicate-loopback-interface-to-mDNS-core.patch;patchdir=.. \ | ||
21 | file://0008-Mark-deleted-interfaces-as-being-changed.patch;patchdir=.. \ | ||
22 | file://0009-Fix-possible-NULL-dereference.patch;patchdir=.. \ | ||
23 | file://0010-Handle-errors-from-socket-calls.patch;patchdir=.. \ | ||
24 | file://0011-Change-a-dynamic-allocation-to-file-scope-variable.patch;patchdir=.. \ | ||
14 | " | 25 | " |
15 | SRC_URI[md5sum] = "aeb92d838a4aa2402ef128ed501484eb" | 26 | SRC_URI[md5sum] = "aeb92d838a4aa2402ef128ed501484eb" |
16 | SRC_URI[sha256sum] = "3cc71582e8eee469c2de8ecae1d769e7f32b3468dfb7f2ca77f1dee1f30a7d1e" | 27 | SRC_URI[sha256sum] = "3cc71582e8eee469c2de8ecae1d769e7f32b3468dfb7f2ca77f1dee1f30a7d1e" |