blob: 43cd21e64a6b7a9ab92a8098a3c17df406a86e0b [file] [log] [blame]
Simon Kelley61744352013-01-31 14:34:40 +00001/* dnsmasq is Copyright (c) 2000-2013 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 Kelley832af0b2007-01-21 20:01:28 +000025/* linux 2.6.19 buggers up the headers, patch it up here. */
26#ifndef IFA_RTA
27# define IFA_RTA(r) \
28 ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
29
30# include <linux/if_addr.h>
31#endif
32
Simon Kelley28866e92011-02-14 20:19:14 +000033#ifndef NDA_RTA
34# define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
35#endif
36
Simon Kelleyc72daea2012-01-05 21:33:27 +000037
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010038static struct iovec iov;
Simon Kelley7622fc02009-06-04 20:32:05 +010039static u32 netlink_pid;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010040
Simon Kelley54dd3932012-06-20 11:23:38 +010041static int nl_async(struct nlmsghdr *h);
Simon Kelley87d346f2012-12-22 22:35:11 +000042static void nl_newaddress(time_t now);
Simon Kelleycdeda282006-03-16 20:16:06 +000043
Simon Kelley5aabfc72007-08-29 11:24:47 +010044void netlink_init(void)
Simon Kelley0a852542005-03-23 20:28:59 +000045{
46 struct sockaddr_nl addr;
Simon Kelley7622fc02009-06-04 20:32:05 +010047 socklen_t slen = sizeof(addr);
Simon Kelley0a852542005-03-23 20:28:59 +000048
49 addr.nl_family = AF_NETLINK;
50 addr.nl_pad = 0;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010051 addr.nl_pid = 0; /* autobind */
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010052 addr.nl_groups = RTMGRP_IPV4_ROUTE;
Simon Kelley54dd3932012-06-20 11:23:38 +010053 if (option_bool(OPT_CLEVERBIND))
Simon Kelley1f776932012-12-16 19:46:08 +000054 addr.nl_groups |= RTMGRP_IPV4_IFADDR;
Simon Kelley54dd3932012-06-20 11:23:38 +010055#ifdef HAVE_IPV6
56 addr.nl_groups |= RTMGRP_IPV6_ROUTE;
Simon Kelley1f776932012-12-16 19:46:08 +000057 if (option_bool(OPT_CLEVERBIND))
58 addr.nl_groups |= RTMGRP_IPV6_IFADDR;
59#endif
60#ifdef HAVE_DHCP6
61 if (daemon->doing_ra || daemon->doing_dhcp6)
Simon Kelley54dd3932012-06-20 11:23:38 +010062 addr.nl_groups |= RTMGRP_IPV6_IFADDR;
Simon Kelleycdeda282006-03-16 20:16:06 +000063#endif
Simon Kelley0a852542005-03-23 20:28:59 +000064
Simon Kelley309331f2006-04-22 15:05:01 +010065 /* May not be able to have permission to set multicast groups don't die in that case */
66 if ((daemon->netlinkfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) != -1)
67 {
68 if (bind(daemon->netlinkfd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
69 {
70 addr.nl_groups = 0;
71 if (errno != EPERM || bind(daemon->netlinkfd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
72 daemon->netlinkfd = -1;
73 }
74 }
75
Simon Kelley7622fc02009-06-04 20:32:05 +010076 if (daemon->netlinkfd == -1 ||
77 getsockname(daemon->netlinkfd, (struct sockaddr *)&addr, &slen) == 1)
Simon Kelley5aabfc72007-08-29 11:24:47 +010078 die(_("cannot create netlink socket: %s"), NULL, EC_MISC);
Simon Kelley7622fc02009-06-04 20:32:05 +010079
80 /* save pid assigned by bind() and retrieved by getsockname() */
81 netlink_pid = addr.nl_pid;
Simon Kelley5aabfc72007-08-29 11:24:47 +010082
Simon Kelley7622fc02009-06-04 20:32:05 +010083 iov.iov_len = 100;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010084 iov.iov_base = safe_malloc(iov.iov_len);
Simon Kelley0a852542005-03-23 20:28:59 +000085}
86
Simon Kelley5aabfc72007-08-29 11:24:47 +010087static ssize_t netlink_recv(void)
Simon Kelleycdeda282006-03-16 20:16:06 +000088{
89 struct msghdr msg;
Simon Kelley7622fc02009-06-04 20:32:05 +010090 struct sockaddr_nl nladdr;
Simon Kelleycdeda282006-03-16 20:16:06 +000091 ssize_t rc;
Simon Kelley0a852542005-03-23 20:28:59 +000092
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010093 while (1)
Simon Kelleycdeda282006-03-16 20:16:06 +000094 {
Simon Kelley7622fc02009-06-04 20:32:05 +010095 msg.msg_control = NULL;
96 msg.msg_controllen = 0;
97 msg.msg_name = &nladdr;
98 msg.msg_namelen = sizeof(nladdr);
99 msg.msg_iov = &iov;
100 msg.msg_iovlen = 1;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100101 msg.msg_flags = 0;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100102
Simon Kelley7622fc02009-06-04 20:32:05 +0100103 while ((rc = recvmsg(daemon->netlinkfd, &msg, MSG_PEEK | MSG_TRUNC)) == -1 && errno == EINTR);
104
105 /* make buffer big enough */
106 if (rc != -1 && (msg.msg_flags & MSG_TRUNC))
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100107 {
Simon Kelley7622fc02009-06-04 20:32:05 +0100108 /* Very new Linux kernels return the actual size needed, older ones always return truncated size */
109 if ((size_t)rc == iov.iov_len)
110 {
111 if (expand_buf(&iov, rc + 100))
112 continue;
113 }
114 else
115 expand_buf(&iov, rc);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100116 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100117
Simon Kelley7622fc02009-06-04 20:32:05 +0100118 /* read it for real */
119 msg.msg_flags = 0;
120 while ((rc = recvmsg(daemon->netlinkfd, &msg, 0)) == -1 && errno == EINTR);
121
122 /* Make sure this is from the kernel */
123 if (rc == -1 || nladdr.nl_pid == 0)
124 break;
125 }
126
127 /* discard stuff which is truncated at this point (expand_buf() may fail) */
128 if (msg.msg_flags & MSG_TRUNC)
129 {
130 rc = -1;
131 errno = ENOMEM;
132 }
Simon Kelleycdeda282006-03-16 20:16:06 +0000133
134 return rc;
135}
136
Simon Kelley28866e92011-02-14 20:19:14 +0000137
Simon Kelleyc72daea2012-01-05 21:33:27 +0000138/* family = AF_UNSPEC finds ARP table entries.
139 family = AF_LOCAL finds MAC addresses. */
Simon Kelley28866e92011-02-14 20:19:14 +0000140int iface_enumerate(int family, void *parm, int (*callback)())
Simon Kelley0a852542005-03-23 20:28:59 +0000141{
142 struct sockaddr_nl addr;
143 struct nlmsghdr *h;
Simon Kelleycdeda282006-03-16 20:16:06 +0000144 ssize_t len;
Simon Kelley0a852542005-03-23 20:28:59 +0000145 static unsigned int seq = 0;
Simon Kelley54dd3932012-06-20 11:23:38 +0100146 int callback_ok = 1, newaddr = 0;
Simon Kelley0a852542005-03-23 20:28:59 +0000147
148 struct {
149 struct nlmsghdr nlh;
150 struct rtgenmsg g;
151 } req;
152
Simon Kelley0a852542005-03-23 20:28:59 +0000153 addr.nl_family = AF_NETLINK;
154 addr.nl_pad = 0;
155 addr.nl_groups = 0;
156 addr.nl_pid = 0; /* address to kernel */
Simon Kelleyc72daea2012-01-05 21:33:27 +0000157
158 again:
159 if (family == AF_UNSPEC)
160 req.nlh.nlmsg_type = RTM_GETNEIGH;
161 else if (family == AF_LOCAL)
162 req.nlh.nlmsg_type = RTM_GETLINK;
163 else
164 req.nlh.nlmsg_type = RTM_GETADDR;
Simon Kelley0a852542005-03-23 20:28:59 +0000165
166 req.nlh.nlmsg_len = sizeof(req);
Simon Kelley7cebd202006-05-06 14:13:33 +0100167 req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST | NLM_F_ACK;
Simon Kelley0a852542005-03-23 20:28:59 +0000168 req.nlh.nlmsg_pid = 0;
169 req.nlh.nlmsg_seq = ++seq;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100170 req.g.rtgen_family = family;
Simon Kelley0a852542005-03-23 20:28:59 +0000171
172 /* Don't block in recvfrom if send fails */
173 while((len = sendto(daemon->netlinkfd, (void *)&req, sizeof(req), 0,
174 (struct sockaddr *)&addr, sizeof(addr))) == -1 && retry_send());
Simon Kelley0a852542005-03-23 20:28:59 +0000175
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100176 if (len == -1)
177 return 0;
178
179 while (1)
Simon Kelley0a852542005-03-23 20:28:59 +0000180 {
Simon Kelley5aabfc72007-08-29 11:24:47 +0100181 if ((len = netlink_recv()) == -1)
Simon Kelley7622fc02009-06-04 20:32:05 +0100182 {
183 if (errno == ENOBUFS)
184 {
185 sleep(1);
186 goto again;
187 }
188 return 0;
189 }
190
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100191 for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
Simon Kelley54dd3932012-06-20 11:23:38 +0100192 if (h->nlmsg_seq != seq || h->nlmsg_pid != netlink_pid || h->nlmsg_type == NLMSG_ERROR)
193 {
194 /* May be multicast arriving async */
Simon Kelley1f776932012-12-16 19:46:08 +0000195 if (nl_async(h))
Simon Kelley115ac3e2013-05-20 11:28:32 +0100196 {
197 newaddr = 1;
198 enumerate_interfaces(1); /* reset */
199 }
Simon Kelley54dd3932012-06-20 11:23:38 +0100200 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100201 else if (h->nlmsg_type == NLMSG_DONE)
Simon Kelley54dd3932012-06-20 11:23:38 +0100202 {
203 /* handle async new interface address arrivals, these have to be done
204 after we complete as we're not re-entrant */
205 if (newaddr)
Simon Kelley87d346f2012-12-22 22:35:11 +0000206 nl_newaddress(dnsmasq_time());
Simon Kelley8445f5d2012-12-17 21:54:08 +0000207
Simon Kelley54dd3932012-06-20 11:23:38 +0100208 return callback_ok;
209 }
Simon Kelleyc72daea2012-01-05 21:33:27 +0000210 else if (h->nlmsg_type == RTM_NEWADDR && family != AF_UNSPEC && family != AF_LOCAL)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100211 {
212 struct ifaddrmsg *ifa = NLMSG_DATA(h);
213 struct rtattr *rta = IFA_RTA(ifa);
214 unsigned int len1 = h->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));
215
Simon Kelley28866e92011-02-14 20:19:14 +0000216 if (ifa->ifa_family == family)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100217 {
Simon Kelley28866e92011-02-14 20:19:14 +0000218 if (ifa->ifa_family == AF_INET)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100219 {
Simon Kelley28866e92011-02-14 20:19:14 +0000220 struct in_addr netmask, addr, broadcast;
Simon Kelley3f2873d2013-05-14 11:28:47 +0100221 char *label = NULL;
222
Simon Kelley28866e92011-02-14 20:19:14 +0000223 netmask.s_addr = htonl(0xffffffff << (32 - ifa->ifa_prefixlen));
224 addr.s_addr = 0;
225 broadcast.s_addr = 0;
226
227 while (RTA_OK(rta, len1))
228 {
229 if (rta->rta_type == IFA_LOCAL)
230 addr = *((struct in_addr *)(rta+1));
231 else if (rta->rta_type == IFA_BROADCAST)
232 broadcast = *((struct in_addr *)(rta+1));
Simon Kelley3f2873d2013-05-14 11:28:47 +0100233 else if (rta->rta_type == IFA_LABEL)
234 label = RTA_DATA(rta);
Simon Kelley28866e92011-02-14 20:19:14 +0000235
236 rta = RTA_NEXT(rta, len1);
237 }
238
Simon Kelleye44ddca2012-02-18 17:08:50 +0000239 if (addr.s_addr && callback_ok)
Simon Kelley3f2873d2013-05-14 11:28:47 +0100240 if (!((*callback)(addr, ifa->ifa_index, label, netmask, broadcast, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000241 callback_ok = 0;
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100242 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100243#ifdef HAVE_IPV6
Simon Kelley28866e92011-02-14 20:19:14 +0000244 else if (ifa->ifa_family == AF_INET6)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100245 {
Simon Kelley28866e92011-02-14 20:19:14 +0000246 struct in6_addr *addrp = NULL;
Simon Kelley1f776932012-12-16 19:46:08 +0000247 u32 valid = 0, preferred = 0;
Simon Kelleybad7b872012-12-20 22:00:39 +0000248 int flags = 0;
249
Simon Kelley28866e92011-02-14 20:19:14 +0000250 while (RTA_OK(rta, len1))
251 {
252 if (rta->rta_type == IFA_ADDRESS)
253 addrp = ((struct in6_addr *)(rta+1));
Simon Kelley1f776932012-12-16 19:46:08 +0000254 else if (rta->rta_type == IFA_CACHEINFO)
255 {
256 struct ifa_cacheinfo *ifc = (struct ifa_cacheinfo *)(rta+1);
257 preferred = ifc->ifa_prefered;
258 valid = ifc->ifa_valid;
259 }
Simon Kelley28866e92011-02-14 20:19:14 +0000260 rta = RTA_NEXT(rta, len1);
261 }
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100262
Simon Kelleybad7b872012-12-20 22:00:39 +0000263 if (ifa->ifa_flags & IFA_F_TENTATIVE)
264 flags |= IFACE_TENTATIVE;
265
266 if (ifa->ifa_flags & IFA_F_DEPRECATED)
267 flags |= IFACE_DEPRECATED;
Vladislav Grishenko4568a6f2013-08-19 16:07:07 +0100268
269 if (ifa->ifa_flags & IFA_F_PERMANENT)
270 flags |= IFACE_PERMANENT;
Simon Kelleybad7b872012-12-20 22:00:39 +0000271
Simon Kelleye44ddca2012-02-18 17:08:50 +0000272 if (addrp && callback_ok)
Simon Kelley52b92f42012-01-22 16:05:15 +0000273 if (!((*callback)(addrp, (int)(ifa->ifa_prefixlen), (int)(ifa->ifa_scope),
Simon Kelleybad7b872012-12-20 22:00:39 +0000274 (int)(ifa->ifa_index), flags,
Simon Kelley1f776932012-12-16 19:46:08 +0000275 (int) preferred, (int)valid, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000276 callback_ok = 0;
Simon Kelley28866e92011-02-14 20:19:14 +0000277 }
278#endif
279 }
280 }
281 else if (h->nlmsg_type == RTM_NEWNEIGH && family == AF_UNSPEC)
282 {
283 struct ndmsg *neigh = NLMSG_DATA(h);
284 struct rtattr *rta = NDA_RTA(neigh);
285 unsigned int len1 = h->nlmsg_len - NLMSG_LENGTH(sizeof(*neigh));
286 size_t maclen = 0;
287 char *inaddr = NULL, *mac = NULL;
288
289 while (RTA_OK(rta, len1))
290 {
291 if (rta->rta_type == NDA_DST)
292 inaddr = (char *)(rta+1);
293 else if (rta->rta_type == NDA_LLADDR)
294 {
295 maclen = rta->rta_len - sizeof(struct rtattr);
296 mac = (char *)(rta+1);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100297 }
298
Simon Kelley28866e92011-02-14 20:19:14 +0000299 rta = RTA_NEXT(rta, len1);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100300 }
Simon Kelley28866e92011-02-14 20:19:14 +0000301
Simon Kelleye44ddca2012-02-18 17:08:50 +0000302 if (inaddr && mac && callback_ok)
Simon Kelley28866e92011-02-14 20:19:14 +0000303 if (!((*callback)(neigh->ndm_family, inaddr, mac, maclen, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000304 callback_ok = 0;
Simon Kelleyc72daea2012-01-05 21:33:27 +0000305 }
306#ifdef HAVE_DHCP6
307 else if (h->nlmsg_type == RTM_NEWLINK && family == AF_LOCAL)
308 {
309 struct ifinfomsg *link = NLMSG_DATA(h);
310 struct rtattr *rta = IFLA_RTA(link);
311 unsigned int len1 = h->nlmsg_len - NLMSG_LENGTH(sizeof(*link));
312 char *mac = NULL;
313 size_t maclen = 0;
314
315 while (RTA_OK(rta, len1))
316 {
317 if (rta->rta_type == IFLA_ADDRESS)
318 {
319 maclen = rta->rta_len - sizeof(struct rtattr);
320 mac = (char *)(rta+1);
321 }
322
323 rta = RTA_NEXT(rta, len1);
324 }
325
Simon Kelleye44ddca2012-02-18 17:08:50 +0000326 if (mac && callback_ok && !((link->ifi_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) &&
Simon Kelleyc5ad4e72012-02-24 16:06:20 +0000327 !((*callback)((int)link->ifi_index, (unsigned int)link->ifi_type, mac, maclen, parm)))
Simon Kelleye44ddca2012-02-18 17:08:50 +0000328 callback_ok = 0;
Simon Kelleyc72daea2012-01-05 21:33:27 +0000329 }
330#endif
Simon Kelley0a852542005-03-23 20:28:59 +0000331 }
Simon Kelley0a852542005-03-23 20:28:59 +0000332}
333
Simon Kelley1f776932012-12-16 19:46:08 +0000334void netlink_multicast(time_t now)
Simon Kelleycdeda282006-03-16 20:16:06 +0000335{
336 ssize_t len;
337 struct nlmsghdr *h;
Simon Kelley54dd3932012-06-20 11:23:38 +0100338 int flags, newaddr = 0;
Simon Kelley7622fc02009-06-04 20:32:05 +0100339
340 /* don't risk blocking reading netlink messages here. */
341 if ((flags = fcntl(daemon->netlinkfd, F_GETFL)) == -1 ||
342 fcntl(daemon->netlinkfd, F_SETFL, flags | O_NONBLOCK) == -1)
343 return;
Simon Kelleycdeda282006-03-16 20:16:06 +0000344
Simon Kelley5aabfc72007-08-29 11:24:47 +0100345 if ((len = netlink_recv()) != -1)
Simon Kelley54dd3932012-06-20 11:23:38 +0100346 for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
Simon Kelley1f776932012-12-16 19:46:08 +0000347 if (nl_async(h))
Simon Kelley54dd3932012-06-20 11:23:38 +0100348 newaddr = 1;
Simon Kelley7622fc02009-06-04 20:32:05 +0100349
Simon Kelley54dd3932012-06-20 11:23:38 +0100350 /* restore non-blocking status */
351 fcntl(daemon->netlinkfd, F_SETFL, flags);
Simon Kelley5d162f22012-12-20 14:55:46 +0000352
Simon Kelley54dd3932012-06-20 11:23:38 +0100353 if (newaddr)
Simon Kelley87d346f2012-12-22 22:35:11 +0000354 nl_newaddress(now);
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100355}
356
Simon Kelley54dd3932012-06-20 11:23:38 +0100357static int nl_async(struct nlmsghdr *h)
358{
359 if (h->nlmsg_type == NLMSG_ERROR)
360 {
361 struct nlmsgerr *err = NLMSG_DATA(h);
Simon Kelleydfb23b32012-09-18 21:44:47 +0100362 if (err->error != 0)
363 my_syslog(LOG_ERR, _("netlink returns error: %s"), strerror(-(err->error)));
Simon Kelley54dd3932012-06-20 11:23:38 +0100364 return 0;
365 }
366 else if (h->nlmsg_pid == 0 && h->nlmsg_type == RTM_NEWROUTE)
367 {
Simon Kelleye17b4b32012-06-28 21:44:30 +0100368 /* We arrange to receive netlink multicast messages whenever the network route is added.
369 If this happens and we still have a DNS packet in the buffer, we re-send it.
370 This helps on DoD links, where frequently the packet which triggers dialling is
371 a DNS query, which then gets lost. By re-sending, we can avoid the lookup
372 failing. */
373 struct rtmsg *rtm = NLMSG_DATA(h);
374
375 if (rtm->rtm_type == RTN_UNICAST && rtm->rtm_scope == RT_SCOPE_LINK)
376 {
377 /* Force re-reading resolv file right now, for luck. */
378 daemon->last_resolv = 0;
379
380 if (daemon->srv_save)
381 {
382 int fd;
383
384 if (daemon->srv_save->sfd)
385 fd = daemon->srv_save->sfd->fd;
386 else if (daemon->rfd_save && daemon->rfd_save->refcount != 0)
387 fd = daemon->rfd_save->fd;
388 else
389 return 0;
390
391 while(sendto(fd, daemon->packet, daemon->packet_len, 0,
392 &daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send());
393 }
394 }
Simon Kelley54dd3932012-06-20 11:23:38 +0100395 return 0;
396 }
Simon Kelley1f776932012-12-16 19:46:08 +0000397 else if (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR)
398 return 1; /* clever bind mode - rescan */
Simon Kelleye17b4b32012-06-28 21:44:30 +0100399
Simon Kelley54dd3932012-06-20 11:23:38 +0100400 return 0;
401}
Simon Kelley5d162f22012-12-20 14:55:46 +0000402
Simon Kelley87d346f2012-12-22 22:35:11 +0000403static void nl_newaddress(time_t now)
Simon Kelley5d162f22012-12-20 14:55:46 +0000404{
Simon Kelleyf0dd7f82012-12-22 22:31:58 +0000405 if (option_bool(OPT_CLEVERBIND) || daemon->doing_dhcp6 || daemon->doing_ra)
Simon Kelley115ac3e2013-05-20 11:28:32 +0100406 enumerate_interfaces(0);
Simon Kelleyf0dd7f82012-12-22 22:31:58 +0000407
Simon Kelley5d162f22012-12-20 14:55:46 +0000408 if (option_bool(OPT_CLEVERBIND))
Simon Kelleyf0dd7f82012-12-22 22:31:58 +0000409 create_bound_listeners(0);
Simon Kelley54dd3932012-06-20 11:23:38 +0100410
Simon Kelley5d162f22012-12-20 14:55:46 +0000411#ifdef HAVE_DHCP6
412 if (daemon->doing_dhcp6 || daemon->doing_ra)
413 {
Simon Kelley5d162f22012-12-20 14:55:46 +0000414 join_multicast(0);
Simon Kelleyf0dd7f82012-12-22 22:31:58 +0000415 dhcp_construct_contexts(now);
Simon Kelley5d162f22012-12-20 14:55:46 +0000416 }
417
418 if (daemon->doing_dhcp6)
419 lease_find_interfaces(now);
420#endif
421}
422
423
Simon Kelley0a852542005-03-23 20:28:59 +0000424#endif
425
426