blob: 049407075215df43ffc095a3d312794adbf5bdff [file] [log] [blame]
Simon Kelleyc8e8f5c2021-01-24 21:59:37 +00001/* dnsmasq is Copyright (c) 2000-2021 Simon Kelley
Simon Kelley0a852542005-03-23 20:28:59 +00002
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
Simon Kelley824af852008-02-12 20:43:05 +00005 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
7
Simon Kelley0a852542005-03-23 20:28:59 +00008 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
Simon Kelley824af852008-02-12 20:43:05 +000012
Simon Kelley73a08a22009-02-05 20:28:08 +000013 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
Simon Kelley0a852542005-03-23 20:28:59 +000015*/
16
Simon Kelley0a852542005-03-23 20:28:59 +000017#include "dnsmasq.h"
18
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010019#ifdef HAVE_LINUX_NETWORK
Simon Kelley0a852542005-03-23 20:28:59 +000020
Simon Kelley91dccd02005-03-31 17:48:32 +010021#include <linux/types.h>
Simon Kelley0a852542005-03-23 20:28:59 +000022#include <linux/netlink.h>
23#include <linux/rtnetlink.h>
24
Simon Kelley1627d572020-03-10 23:55:18 +000025/* Blergh. Radv does this, so that's our excuse. */
26#ifndef SOL_NETLINK
27#define SOL_NETLINK 270
28#endif
29
Simon Kelley0506a5e2020-03-19 21:56:45 +000030#ifndef NETLINK_NO_ENOBUFS
31#define NETLINK_NO_ENOBUFS 5
32#endif
Simon Kelley1627d572020-03-10 23:55:18 +000033
Simon Kelley832af0b2007-01-21 20:01:28 +000034/* linux 2.6.19 buggers up the headers, patch it up here. */
35#ifndef IFA_RTA
36# define IFA_RTA(r) \
37 ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
38
39# include <linux/if_addr.h>
40#endif
41
Simon Kelley28866e92011-02-14 20:19:14 +000042#ifndef NDA_RTA
43# define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
44#endif
45
Simon Kelleyc72daea2012-01-05 21:33:27 +000046
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010047static struct iovec iov;
Simon Kelley7622fc02009-06-04 20:32:05 +010048static u32 netlink_pid;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010049
Simon Kelleya0358e52014-06-07 13:38:48 +010050static void nl_async(struct nlmsghdr *h);
Simon Kelleycdeda282006-03-16 20:16:06 +000051
Simon Kelley913fa152020-04-19 23:16:52 +010052char *netlink_init(void)
Simon Kelley0a852542005-03-23 20:28:59 +000053{
54 struct sockaddr_nl addr;
Simon Kelley7622fc02009-06-04 20:32:05 +010055 socklen_t slen = sizeof(addr);
Simon Kelley1627d572020-03-10 23:55:18 +000056 int opt = 1;
Simon Kelley0a852542005-03-23 20:28:59 +000057
58 addr.nl_family = AF_NETLINK;
59 addr.nl_pad = 0;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010060 addr.nl_pid = 0; /* autobind */
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010061 addr.nl_groups = RTMGRP_IPV4_ROUTE;
Simon Kelley54dd3932012-06-20 11:23:38 +010062 if (option_bool(OPT_CLEVERBIND))
Simon Kelley1f776932012-12-16 19:46:08 +000063 addr.nl_groups |= RTMGRP_IPV4_IFADDR;
Simon Kelley54dd3932012-06-20 11:23:38 +010064 addr.nl_groups |= RTMGRP_IPV6_ROUTE;
Simon Kelley1f776932012-12-16 19:46:08 +000065 if (option_bool(OPT_CLEVERBIND))
66 addr.nl_groups |= RTMGRP_IPV6_IFADDR;
Simon Kelleyee875042018-10-23 22:10:17 +010067
Simon Kelley1f776932012-12-16 19:46:08 +000068#ifdef HAVE_DHCP6
69 if (daemon->doing_ra || daemon->doing_dhcp6)
Simon Kelley54dd3932012-06-20 11:23:38 +010070 addr.nl_groups |= RTMGRP_IPV6_IFADDR;
Simon Kelleycdeda282006-03-16 20:16:06 +000071#endif
Simon Kelley0a852542005-03-23 20:28:59 +000072
Simon Kelley309331f2006-04-22 15:05:01 +010073 /* May not be able to have permission to set multicast groups don't die in that case */
74 if ((daemon->netlinkfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) != -1)
75 {
76 if (bind(daemon->netlinkfd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
77 {
78 addr.nl_groups = 0;
79 if (errno != EPERM || bind(daemon->netlinkfd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
80 daemon->netlinkfd = -1;
81 }
82 }
83
Simon Kelley7622fc02009-06-04 20:32:05 +010084 if (daemon->netlinkfd == -1 ||
Reiter Wolfgang5eb9dde2017-01-08 17:39:06 +000085 getsockname(daemon->netlinkfd, (struct sockaddr *)&addr, &slen) == -1)
Simon Kelley5aabfc72007-08-29 11:24:47 +010086 die(_("cannot create netlink socket: %s"), NULL, EC_MISC);
Simon Kelley0506a5e2020-03-19 21:56:45 +000087
Simon Kelley913fa152020-04-19 23:16:52 +010088
Simon Kelley7622fc02009-06-04 20:32:05 +010089 /* save pid assigned by bind() and retrieved by getsockname() */
90 netlink_pid = addr.nl_pid;
Simon Kelley5aabfc72007-08-29 11:24:47 +010091
Simon Kelley7622fc02009-06-04 20:32:05 +010092 iov.iov_len = 100;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010093 iov.iov_base = safe_malloc(iov.iov_len);
Simon Kelley913fa152020-04-19 23:16:52 +010094
95 if (daemon->kernel_version >= KERNEL_VERSION(2,6,30) &&
96 setsockopt(daemon->netlinkfd, SOL_NETLINK, NETLINK_NO_ENOBUFS, &opt, sizeof(opt)) == -1)
97 return _("warning: failed to set NETLINK_NO_ENOBUFS on netlink socket");
98
99 return NULL;
Simon Kelley0a852542005-03-23 20:28:59 +0000100}
101
Simon Kelley5aabfc72007-08-29 11:24:47 +0100102static ssize_t netlink_recv(void)
Simon Kelleycdeda282006-03-16 20:16:06 +0000103{
104 struct msghdr msg;
Simon Kelley7622fc02009-06-04 20:32:05 +0100105 struct sockaddr_nl nladdr;
Simon Kelleycdeda282006-03-16 20:16:06 +0000106 ssize_t rc;
Simon Kelley0a852542005-03-23 20:28:59 +0000107
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100108 while (1)
Simon Kelleycdeda282006-03-16 20:16:06 +0000109 {
Simon Kelley7622fc02009-06-04 20:32:05 +0100110 msg.msg_control = NULL;
111 msg.msg_controllen = 0;
112 msg.msg_name = &nladdr;
113 msg.msg_namelen = sizeof(nladdr);
114 msg.msg_iov = &iov;
115 msg.msg_iovlen = 1;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100116 msg.msg_flags = 0;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100117
Simon Kelley7622fc02009-06-04 20:32:05 +0100118 while ((rc = recvmsg(daemon->netlinkfd, &msg, MSG_PEEK | MSG_TRUNC)) == -1 && errno == EINTR);
119
120 /* make buffer big enough */
121 if (rc != -1 && (msg.msg_flags & MSG_TRUNC))
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100122 {
Simon Kelley7622fc02009-06-04 20:32:05 +0100123 /* Very new Linux kernels return the actual size needed, older ones always return truncated size */
124 if ((size_t)rc == iov.iov_len)
125 {
126 if (expand_buf(&iov, rc + 100))
127 continue;
128 }
129 else
130 expand_buf(&iov, rc);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100131 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100132
Simon Kelley7622fc02009-06-04 20:32:05 +0100133 /* read it for real */
134 msg.msg_flags = 0;
135 while ((rc = recvmsg(daemon->netlinkfd, &msg, 0)) == -1 && errno == EINTR);
136
137 /* Make sure this is from the kernel */
138 if (rc == -1 || nladdr.nl_pid == 0)
139 break;
140 }
141
142 /* discard stuff which is truncated at this point (expand_buf() may fail) */
143 if (msg.msg_flags & MSG_TRUNC)
144 {
145 rc = -1;
146 errno = ENOMEM;
147 }
Simon Kelleycdeda282006-03-16 20:16:06 +0000148
149 return rc;
150}
151
Simon Kelley28866e92011-02-14 20:19:14 +0000152
Simon Kelleyc72daea2012-01-05 21:33:27 +0000153/* family = AF_UNSPEC finds ARP table entries.
154 family = AF_LOCAL finds MAC addresses. */
Simon Kelley28866e92011-02-14 20:19:14 +0000155int iface_enumerate(int family, void *parm, int (*callback)())
Simon Kelley0a852542005-03-23 20:28:59 +0000156{
157 struct sockaddr_nl addr;
158 struct nlmsghdr *h;
Simon Kelleycdeda282006-03-16 20:16:06 +0000159 ssize_t len;
Simon Kelley0a852542005-03-23 20:28:59 +0000160 static unsigned int seq = 0;
Simon Kelleya0358e52014-06-07 13:38:48 +0100161 int callback_ok = 1;
Simon Kelley0a852542005-03-23 20:28:59 +0000162
163 struct {
164 struct nlmsghdr nlh;
165 struct rtgenmsg g;
166 } req;
167
Petr Menšík47b45b22018-08-15 18:17:00 +0200168 memset(&req, 0, sizeof(req));
169 memset(&addr, 0, sizeof(addr));
170
Simon Kelley0a852542005-03-23 20:28:59 +0000171 addr.nl_family = AF_NETLINK;
Simon Kelleyc72daea2012-01-05 21:33:27 +0000172
173 again:
174 if (family == AF_UNSPEC)
175 req.nlh.nlmsg_type = RTM_GETNEIGH;
176 else if (family == AF_LOCAL)
177 req.nlh.nlmsg_type = RTM_GETLINK;
178 else
179 req.nlh.nlmsg_type = RTM_GETADDR;
Simon Kelley0a852542005-03-23 20:28:59 +0000180
181 req.nlh.nlmsg_len = sizeof(req);
Simon Kelley7cebd202006-05-06 14:13:33 +0100182 req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST | NLM_F_ACK;
Simon Kelley0a852542005-03-23 20:28:59 +0000183 req.nlh.nlmsg_pid = 0;
184 req.nlh.nlmsg_seq = ++seq;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100185 req.g.rtgen_family = family;
Simon Kelley0a852542005-03-23 20:28:59 +0000186
187 /* Don't block in recvfrom if send fails */
Simon Kelleyff841eb2015-03-11 21:36:30 +0000188 while(retry_send(sendto(daemon->netlinkfd, (void *)&req, sizeof(req), 0,
189 (struct sockaddr *)&addr, sizeof(addr))));
190
191 if (errno != 0)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100192 return 0;
193
194 while (1)
Simon Kelley0a852542005-03-23 20:28:59 +0000195 {
Simon Kelley5aabfc72007-08-29 11:24:47 +0100196 if ((len = netlink_recv()) == -1)
Simon Kelley7622fc02009-06-04 20:32:05 +0100197 {
198 if (errno == ENOBUFS)
199 {
200 sleep(1);
201 goto again;
202 }
203 return 0;
204 }
205
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100206 for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
Ivan Kokshaysky1d076672016-07-11 18:36:05 +0100207 if (h->nlmsg_pid != netlink_pid || h->nlmsg_type == NLMSG_ERROR)
Simon Kelley54dd3932012-06-20 11:23:38 +0100208 {
209 /* May be multicast arriving async */
Simon Kelleya0358e52014-06-07 13:38:48 +0100210 nl_async(h);
Simon Kelley54dd3932012-06-20 11:23:38 +0100211 }
Ivan Kokshaysky1d076672016-07-11 18:36:05 +0100212 else if (h->nlmsg_seq != seq)
213 {
214 /* May be part of incomplete response to previous request after
215 ENOBUFS. Drop it. */
216 continue;
217 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100218 else if (h->nlmsg_type == NLMSG_DONE)
Simon Kelleya0358e52014-06-07 13:38:48 +0100219 return callback_ok;
Simon Kelleyc72daea2012-01-05 21:33:27 +0000220 else if (h->nlmsg_type == RTM_NEWADDR && family != AF_UNSPEC && family != AF_LOCAL)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100221 {
222 struct ifaddrmsg *ifa = NLMSG_DATA(h);
223 struct rtattr *rta = IFA_RTA(ifa);
224 unsigned int len1 = h->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));
225
Simon Kelley28866e92011-02-14 20:19:14 +0000226 if (ifa->ifa_family == family)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100227 {
Simon Kelley28866e92011-02-14 20:19:14 +0000228 if (ifa->ifa_family == AF_INET)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100229 {
Simon Kelley28866e92011-02-14 20:19:14 +0000230 struct in_addr netmask, addr, broadcast;
Simon Kelley3f2873d2013-05-14 11:28:47 +0100231 char *label = NULL;
232
Richard Genoud10cfc0d2014-09-17 21:17:39 +0100233 netmask.s_addr = htonl(~(in_addr_t)0 << (32 - ifa->ifa_prefixlen));
234
Simon Kelley28866e92011-02-14 20:19:14 +0000235 addr.s_addr = 0;
236 broadcast.s_addr = 0;
237
238 while (RTA_OK(rta, len1))
239 {
240 if (rta->rta_type == IFA_LOCAL)
241 addr = *((struct in_addr *)(rta+1));
242 else if (rta->rta_type == IFA_BROADCAST)
243 broadcast = *((struct in_addr *)(rta+1));
Simon Kelley3f2873d2013-05-14 11:28:47 +0100244 else if (rta->rta_type == IFA_LABEL)
245 label = RTA_DATA(rta);
Simon Kelley28866e92011-02-14 20:19:14 +0000246
247 rta = RTA_NEXT(rta, len1);
248 }
249
Simon Kelleye44ddca2012-02-18 17:08:50 +0000250 if (addr.s_addr && callback_ok)
Simon Kelley3f2873d2013-05-14 11:28:47 +0100251 if (!((*callback)(addr, ifa->ifa_index, label, netmask, broadcast, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000252 callback_ok = 0;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100253 }
Simon Kelley28866e92011-02-14 20:19:14 +0000254 else if (ifa->ifa_family == AF_INET6)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100255 {
Simon Kelley28866e92011-02-14 20:19:14 +0000256 struct in6_addr *addrp = NULL;
Simon Kelley1f776932012-12-16 19:46:08 +0000257 u32 valid = 0, preferred = 0;
Simon Kelleybad7b872012-12-20 22:00:39 +0000258 int flags = 0;
259
Simon Kelley28866e92011-02-14 20:19:14 +0000260 while (RTA_OK(rta, len1))
261 {
262 if (rta->rta_type == IFA_ADDRESS)
263 addrp = ((struct in6_addr *)(rta+1));
Simon Kelley1f776932012-12-16 19:46:08 +0000264 else if (rta->rta_type == IFA_CACHEINFO)
265 {
266 struct ifa_cacheinfo *ifc = (struct ifa_cacheinfo *)(rta+1);
267 preferred = ifc->ifa_prefered;
268 valid = ifc->ifa_valid;
269 }
Simon Kelley28866e92011-02-14 20:19:14 +0000270 rta = RTA_NEXT(rta, len1);
271 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100272
Simon Kelleybad7b872012-12-20 22:00:39 +0000273 if (ifa->ifa_flags & IFA_F_TENTATIVE)
274 flags |= IFACE_TENTATIVE;
275
276 if (ifa->ifa_flags & IFA_F_DEPRECATED)
277 flags |= IFACE_DEPRECATED;
278
Jonas Gorski57ab36e2014-01-22 11:34:16 +0000279 if (!(ifa->ifa_flags & IFA_F_TEMPORARY))
280 flags |= IFACE_PERMANENT;
281
Simon Kelleye44ddca2012-02-18 17:08:50 +0000282 if (addrp && callback_ok)
Simon Kelley52b92f42012-01-22 16:05:15 +0000283 if (!((*callback)(addrp, (int)(ifa->ifa_prefixlen), (int)(ifa->ifa_scope),
Simon Kelleybad7b872012-12-20 22:00:39 +0000284 (int)(ifa->ifa_index), flags,
Simon Kelley1f776932012-12-16 19:46:08 +0000285 (int) preferred, (int)valid, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000286 callback_ok = 0;
Simon Kelley28866e92011-02-14 20:19:14 +0000287 }
Simon Kelley28866e92011-02-14 20:19:14 +0000288 }
289 }
290 else if (h->nlmsg_type == RTM_NEWNEIGH && family == AF_UNSPEC)
291 {
292 struct ndmsg *neigh = NLMSG_DATA(h);
293 struct rtattr *rta = NDA_RTA(neigh);
294 unsigned int len1 = h->nlmsg_len - NLMSG_LENGTH(sizeof(*neigh));
295 size_t maclen = 0;
296 char *inaddr = NULL, *mac = NULL;
297
298 while (RTA_OK(rta, len1))
299 {
300 if (rta->rta_type == NDA_DST)
301 inaddr = (char *)(rta+1);
302 else if (rta->rta_type == NDA_LLADDR)
303 {
304 maclen = rta->rta_len - sizeof(struct rtattr);
305 mac = (char *)(rta+1);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100306 }
307
Simon Kelley28866e92011-02-14 20:19:14 +0000308 rta = RTA_NEXT(rta, len1);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100309 }
Simon Kelley28866e92011-02-14 20:19:14 +0000310
Simon Kelleyfa14bec2015-12-20 17:12:16 +0000311 if (!(neigh->ndm_state & (NUD_NOARP | NUD_INCOMPLETE | NUD_FAILED)) &&
312 inaddr && mac && callback_ok)
Simon Kelley28866e92011-02-14 20:19:14 +0000313 if (!((*callback)(neigh->ndm_family, inaddr, mac, maclen, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000314 callback_ok = 0;
Simon Kelleyc72daea2012-01-05 21:33:27 +0000315 }
316#ifdef HAVE_DHCP6
317 else if (h->nlmsg_type == RTM_NEWLINK && family == AF_LOCAL)
318 {
319 struct ifinfomsg *link = NLMSG_DATA(h);
320 struct rtattr *rta = IFLA_RTA(link);
321 unsigned int len1 = h->nlmsg_len - NLMSG_LENGTH(sizeof(*link));
322 char *mac = NULL;
323 size_t maclen = 0;
324
325 while (RTA_OK(rta, len1))
326 {
327 if (rta->rta_type == IFLA_ADDRESS)
328 {
329 maclen = rta->rta_len - sizeof(struct rtattr);
330 mac = (char *)(rta+1);
331 }
332
333 rta = RTA_NEXT(rta, len1);
334 }
335
Simon Kelleye44ddca2012-02-18 17:08:50 +0000336 if (mac && callback_ok && !((link->ifi_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) &&
Simon Kelleyc5ad4e72012-02-24 16:06:20 +0000337 !((*callback)((int)link->ifi_index, (unsigned int)link->ifi_type, mac, maclen, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000338 callback_ok = 0;
Simon Kelleyc72daea2012-01-05 21:33:27 +0000339 }
340#endif
Simon Kelley0a852542005-03-23 20:28:59 +0000341 }
Simon Kelley0a852542005-03-23 20:28:59 +0000342}
343
Simon Kelleya0358e52014-06-07 13:38:48 +0100344void netlink_multicast(void)
Simon Kelleycdeda282006-03-16 20:16:06 +0000345{
346 ssize_t len;
347 struct nlmsghdr *h;
Simon Kelleya0358e52014-06-07 13:38:48 +0100348 int flags;
Simon Kelley7622fc02009-06-04 20:32:05 +0100349
350 /* don't risk blocking reading netlink messages here. */
351 if ((flags = fcntl(daemon->netlinkfd, F_GETFL)) == -1 ||
352 fcntl(daemon->netlinkfd, F_SETFL, flags | O_NONBLOCK) == -1)
353 return;
Simon Kelleycdeda282006-03-16 20:16:06 +0000354
Simon Kelley5aabfc72007-08-29 11:24:47 +0100355 if ((len = netlink_recv()) != -1)
Simon Kelley54dd3932012-06-20 11:23:38 +0100356 for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
Simon Kelleya0358e52014-06-07 13:38:48 +0100357 nl_async(h);
Simon Kelley7622fc02009-06-04 20:32:05 +0100358
Simon Kelley54dd3932012-06-20 11:23:38 +0100359 /* restore non-blocking status */
360 fcntl(daemon->netlinkfd, F_SETFL, flags);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100361}
362
Simon Kelleya0358e52014-06-07 13:38:48 +0100363static void nl_async(struct nlmsghdr *h)
Simon Kelley54dd3932012-06-20 11:23:38 +0100364{
365 if (h->nlmsg_type == NLMSG_ERROR)
366 {
367 struct nlmsgerr *err = NLMSG_DATA(h);
Simon Kelleydfb23b32012-09-18 21:44:47 +0100368 if (err->error != 0)
369 my_syslog(LOG_ERR, _("netlink returns error: %s"), strerror(-(err->error)));
Simon Kelley54dd3932012-06-20 11:23:38 +0100370 }
371 else if (h->nlmsg_pid == 0 && h->nlmsg_type == RTM_NEWROUTE)
372 {
Simon Kelleye17b4b32012-06-28 21:44:30 +0100373 /* We arrange to receive netlink multicast messages whenever the network route is added.
374 If this happens and we still have a DNS packet in the buffer, we re-send it.
375 This helps on DoD links, where frequently the packet which triggers dialling is
376 a DNS query, which then gets lost. By re-sending, we can avoid the lookup
377 failing. */
378 struct rtmsg *rtm = NLMSG_DATA(h);
379
Donald Sharpb2ed6912020-03-02 11:23:36 -0500380 if (rtm->rtm_type == RTN_UNICAST && rtm->rtm_scope == RT_SCOPE_LINK &&
381 (rtm->rtm_table == RT_TABLE_MAIN ||
382 rtm->rtm_table == RT_TABLE_LOCAL))
Simon Kelley47a95162014-07-08 22:22:02 +0100383 queue_event(EVENT_NEWROUTE);
Simon Kelley54dd3932012-06-20 11:23:38 +0100384 }
Simon Kelley1f776932012-12-16 19:46:08 +0000385 else if (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR)
Simon Kelley47a95162014-07-08 22:22:02 +0100386 queue_event(EVENT_NEWADDR);
Simon Kelley54dd3932012-06-20 11:23:38 +0100387}
Simon Kelley0a852542005-03-23 20:28:59 +0000388#endif
389
390