36f6ae79bf6813438760fe5e1305aae592f2b211
[project/odhcpd.git] / src / router.c
1 /**
2  * Copyright (C) 2012-2013 Steven Barth <steven@midlink.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License v2 as published by
6  * the Free Software Foundation.
7  *
8  * 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.
12  *
13  */
14
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <signal.h>
18 #include <resolv.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <stdbool.h>
23 #include <net/route.h>
24
25 #include "router.h"
26 #include "odhcpd.h"
27
28
29 static void forward_router_solicitation(const struct interface *iface);
30 static void forward_router_advertisement(uint8_t *data, size_t len);
31
32 static void handle_icmpv6(void *addr, void *data, size_t len,
33                 struct interface *iface, void *dest);
34 static void trigger_router_advert(struct uloop_timeout *event);
35 static void sigusr1_refresh(int signal);
36
37 static struct odhcpd_event router_event = {{.fd = -1}, handle_icmpv6};
38
39 static FILE *fp_route = NULL;
40 #define RA_IOV_LEN 6
41
42
43 int init_router(void)
44 {
45         // Open ICMPv6 socket
46         int sock = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
47         if (sock < 0 && errno != EAFNOSUPPORT) {
48                 syslog(LOG_ERR, "Failed to open RAW-socket: %s", strerror(errno));
49                 return -1;
50         }
51
52         // Let the kernel compute our checksums
53         int val = 2;
54         setsockopt(sock, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val));
55
56         // This is required by RFC 4861
57         val = 255;
58         setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val));
59         setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val));
60
61         // We need to know the source interface
62         val = 1;
63         setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val));
64         setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &val, sizeof(val));
65
66         // Don't loop back
67         val = 0;
68         setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val));
69
70         // Filter ICMPv6 package types
71         struct icmp6_filter filt;
72         ICMP6_FILTER_SETBLOCKALL(&filt);
73         ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
74         ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt);
75         setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, sizeof(filt));
76
77         // Register socket
78         router_event.uloop.fd = sock;
79         odhcpd_register(&router_event);
80
81         if (!(fp_route = fopen("/proc/net/ipv6_route", "r")))
82                 syslog(LOG_ERR, "Failed to open routing table: %s",
83                                 strerror(errno));
84
85         signal(SIGUSR1, sigusr1_refresh);
86         return 0;
87 }
88
89
90 int setup_router_interface(struct interface *iface, bool enable)
91 {
92         if (!fp_route || router_event.uloop.fd < 0)
93                 return -1;
94
95         struct ipv6_mreq all_nodes = {ALL_IPV6_NODES, iface->ifindex};
96         struct ipv6_mreq all_routers = {ALL_IPV6_ROUTERS, iface->ifindex};
97
98         uloop_timeout_cancel(&iface->timer_rs);
99         iface->timer_rs.cb = NULL;
100
101         setsockopt(router_event.uloop.fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP,
102                         &all_nodes, sizeof(all_nodes));
103         setsockopt(router_event.uloop.fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP,
104                         &all_routers, sizeof(all_routers));
105
106         if (!enable) {
107                 if (iface->ra)
108                         trigger_router_advert(&iface->timer_rs);
109         } else {
110                 void *mreq = &all_routers;
111
112                 if (iface->ra == RELAYD_RELAY && iface->master) {
113                         mreq = &all_nodes;
114                         forward_router_solicitation(iface);
115                 } else if (iface->ra == RELAYD_SERVER && !iface->master) {
116                         iface->timer_rs.cb = trigger_router_advert;
117                         uloop_timeout_set(&iface->timer_rs, 1000);
118                 }
119
120                 if (iface->ra == RELAYD_RELAY || (iface->ra == RELAYD_SERVER && !iface->master))
121                         setsockopt(router_event.uloop.fd, IPPROTO_IPV6,
122                                         IPV6_ADD_MEMBERSHIP, mreq, sizeof(all_nodes));
123         }
124         return 0;
125 }
126
127
128 // Signal handler to resend all RDs
129 static void sigusr1_refresh(_unused int signal)
130 {
131         struct interface *iface;
132         list_for_each_entry(iface, &interfaces, head)
133                 if (iface->ra == RELAYD_SERVER && !iface->master)
134                         uloop_timeout_set(&iface->timer_rs, 1000);
135 }
136
137 static bool router_icmpv6_valid(struct sockaddr_in6 *source, uint8_t *data, size_t len)
138 {
139         struct icmp6_hdr *hdr = (struct icmp6_hdr *)data;
140         struct icmpv6_opt *opt, *end = (struct icmpv6_opt*)&data[len];
141
142         /* Hoplimit is already checked in odhcpd_receive_packets */
143         if (len < sizeof(*hdr) || hdr->icmp6_code)
144                 return false;
145
146         switch (hdr->icmp6_type) {
147         case ND_ROUTER_ADVERT:
148                 if (!IN6_IS_ADDR_LINKLOCAL(&source->sin6_addr))
149                         return false;
150
151                 opt = (struct icmpv6_opt *)((struct nd_router_advert *)data + 1);
152                 break;
153
154         case ND_ROUTER_SOLICIT:
155                 opt = (struct icmpv6_opt *)((struct nd_router_solicit *)data + 1);
156                 break;
157
158         default:
159                 return false;
160         }
161
162         icmpv6_for_each_option(opt, opt, end)
163                 if (opt->type == ND_OPT_SOURCE_LINKADDR &&
164                                 IN6_IS_ADDR_UNSPECIFIED(&source->sin6_addr) &&
165                                 hdr->icmp6_type == ND_ROUTER_SOLICIT)
166                         return false;
167
168         // Check all options parsed successfully
169         return opt == end;
170 }
171
172
173 // Detect whether a default route exists, also find the source prefixes
174 static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len)
175 {
176         rewind(fp_route);
177
178         char line[512], ifname[16];
179         bool found_default = false;
180         struct odhcpd_ipaddr p = {IN6ADDR_ANY_INIT, 0, 0, 0, 0};
181         while (fgets(line, sizeof(line), fp_route)) {
182                 uint32_t rflags;
183                 if (sscanf(line, "00000000000000000000000000000000 00 "
184                                 "%*s %*s %*s %*s %*s %*s %*s %15s", ifname) &&
185                                 strcmp(ifname, "lo")) {
186                         found_default = true;
187                 } else if (sscanf(line, "%8" SCNx32 "%8" SCNx32 "%*8" SCNx32 "%*8" SCNx32 " %hhx %*s "
188                                 "%*s 00000000000000000000000000000000 %*s %*s %*s %" SCNx32 " lo",
189                                 &p.addr.s6_addr32[0], &p.addr.s6_addr32[1], &p.prefix, &rflags) &&
190                                 p.prefix > 0 && (rflags & RTF_NONEXTHOP) && (rflags & RTF_REJECT)) {
191                         // Find source prefixes by scanning through unreachable-routes
192                         p.addr.s6_addr32[0] = htonl(p.addr.s6_addr32[0]);
193                         p.addr.s6_addr32[1] = htonl(p.addr.s6_addr32[1]);
194
195                         for (ssize_t i = 0; i < len; ++i) {
196                                 if (n[i].prefix <= 64 && n[i].prefix >= p.prefix &&
197                                                 !odhcpd_bmemcmp(&p.addr, &n[i].addr, p.prefix)) {
198                                         n[i].dprefix = p.prefix;
199                                         break;
200                                 }
201                         }
202
203                 }
204         }
205
206         return found_default;
207 }
208
209 // Router Advert server mode
210 static uint64_t send_router_advert(struct interface *iface, const struct in6_addr *from)
211 {
212         time_t now = odhcpd_time();
213         int mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
214         int hlim = odhcpd_get_interface_config(iface->ifname, "hop_limit");
215
216         if (mtu < 1280)
217                 mtu = 1280;
218
219         struct {
220                 struct nd_router_advert h;
221                 struct icmpv6_opt lladdr;
222                 struct nd_opt_mtu mtu;
223                 struct nd_opt_prefix_info prefix[sizeof(iface->ia_addr) / sizeof(*iface->ia_addr)];
224         } adv = {
225                 .h = {{.icmp6_type = ND_ROUTER_ADVERT, .icmp6_code = 0}, 0, 0},
226                 .lladdr = {ND_OPT_SOURCE_LINKADDR, 1, {0}},
227                 .mtu = {ND_OPT_MTU, 1, 0, htonl(mtu)},
228         };
229
230         if (hlim > 0)
231                 adv.h.nd_ra_curhoplimit = hlim;
232
233         if (iface->dhcpv6)
234                 adv.h.nd_ra_flags_reserved = ND_RA_FLAG_OTHER;
235
236         if (iface->managed >= RELAYD_MANAGED_MFLAG)
237                 adv.h.nd_ra_flags_reserved |= ND_RA_FLAG_MANAGED;
238
239         if (iface->route_preference < 0)
240                 adv.h.nd_ra_flags_reserved |= ND_RA_PREF_LOW;
241         else if (iface->route_preference > 0)
242                 adv.h.nd_ra_flags_reserved |= ND_RA_PREF_HIGH;
243         odhcpd_get_mac(iface, adv.lladdr.data);
244
245         // If not currently shutting down
246         struct odhcpd_ipaddr *addrs = NULL;
247         ssize_t ipcnt = 0;
248         int64_t minvalid = INT64_MAX;
249         int64_t maxvalid = 0;
250
251         // If not shutdown
252         if (iface->timer_rs.cb) {
253                 addrs = iface->ia_addr;
254                 ipcnt = iface->ia_addr_len;
255
256                 // Check default route
257                 if (parse_routes(addrs, ipcnt))
258                         adv.h.nd_ra_router_lifetime = htons(1);
259                 if (iface->default_router > 1)
260                         adv.h.nd_ra_router_lifetime = htons(iface->default_router);
261         }
262
263         // Construct Prefix Information options
264         size_t cnt = 0;
265
266         struct in6_addr dns_pref = IN6ADDR_ANY_INIT, *dns_addr = &dns_pref;
267         uint32_t dns_time = 0;
268         size_t dns_cnt = 1;
269
270         for (ssize_t i = 0; i < ipcnt; ++i) {
271                 struct odhcpd_ipaddr *addr = &addrs[i];
272                 if (addr->prefix > 96 || addr->valid <= now)
273                         continue; // Address not suitable
274
275                 struct nd_opt_prefix_info *p = NULL;
276                 for (size_t i = 0; i < cnt; ++i) {
277                         if (addr->prefix == adv.prefix[i].nd_opt_pi_prefix_len &&
278                                         !odhcpd_bmemcmp(&adv.prefix[i].nd_opt_pi_prefix,
279                                         &addr->addr, addr->prefix))
280                                 p = &adv.prefix[i];
281                 }
282
283                 if (!p) {
284                         if (cnt >= ARRAY_SIZE(adv.prefix))
285                                 break;
286
287                         p = &adv.prefix[cnt++];
288                 }
289
290                 if (addr->preferred > now &&
291                                 minvalid > 1000LL * (addr->valid - now))
292                         minvalid = 1000LL * (addr->valid - now);
293
294                 if (maxvalid < 1000LL * (addr->valid - now))
295                         maxvalid = 1000LL * (addr->valid - now);
296
297                 if (((addr->addr.s6_addr[0] & 0xfe) != 0xfc || iface->default_router)
298                                 && ntohs(adv.h.nd_ra_router_lifetime) < addr->valid - now)
299                         adv.h.nd_ra_router_lifetime = htons(addr->valid - now);
300
301                 odhcpd_bmemcpy(&p->nd_opt_pi_prefix, &addr->addr,
302                                 (iface->ra_advrouter) ? 128 : addr->prefix);
303                 p->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
304                 p->nd_opt_pi_len = 4;
305                 p->nd_opt_pi_prefix_len = (addr->prefix < 64) ? 64 : addr->prefix;
306                 p->nd_opt_pi_flags_reserved = 0;
307                 if (!iface->ra_not_onlink)
308                         p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_ONLINK;
309                 if (iface->managed < RELAYD_MANAGED_NO_AFLAG && addr->prefix <= 64)
310                         p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO;
311                 if (iface->ra_advrouter)
312                         p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR;
313                 p->nd_opt_pi_valid_time = htonl(addr->valid - now);
314                 if (addr->preferred > now)
315                         p->nd_opt_pi_preferred_time = htonl(addr->preferred - now);
316
317
318                 if (addr->preferred - now > dns_time) {
319                         dns_time = addr->preferred - now;
320                         dns_pref = addr->addr;
321                 }
322         }
323
324         if (!iface->default_router && ntohs(adv.h.nd_ra_router_lifetime) == 1) {
325                 syslog(LOG_WARNING, "A default route is present but there is no public prefix "
326                                 "on %s thus we don't announce a default route!", iface->ifname);
327                 adv.h.nd_ra_router_lifetime = 0;
328         }
329
330         // DNS Recursive DNS
331         if (iface->dns_cnt > 0) {
332                 dns_addr = iface->dns;
333                 dns_cnt = iface->dns_cnt;
334                 dns_time = 0;
335         }
336
337         if (!dns_addr || IN6_IS_ADDR_UNSPECIFIED(dns_addr))
338                 dns_cnt = 0;
339
340         struct {
341                 uint8_t type;
342                 uint8_t len;
343                 uint8_t pad;
344                 uint8_t pad2;
345                 uint32_t lifetime;
346         } dns = {ND_OPT_RECURSIVE_DNS, (1 + (2 * dns_cnt)), 0, 0, htonl(dns_time)};
347
348
349
350         // DNS Search options
351         uint8_t search_buf[256], *search_domain = iface->search;
352         size_t search_len = iface->search_len, search_padded = 0;
353
354         if (!search_domain && !res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
355                 int len = dn_comp(_res.dnsrch[0], search_buf,
356                                 sizeof(search_buf), NULL, NULL);
357                 if (len > 0) {
358                         search_domain = search_buf;
359                         search_len = len;
360                 }
361         }
362
363         if (search_len > 0)
364                 search_padded = ((search_len + 7) & (~7)) + 8;
365
366         struct {
367                 uint8_t type;
368                 uint8_t len;
369                 uint8_t pad;
370                 uint8_t pad2;
371                 uint32_t lifetime;
372                 uint8_t name[];
373         } *search = alloca(sizeof(*search) + search_padded);
374
375         search->type = ND_OPT_DNS_SEARCH;
376         search->len = search_len ? ((sizeof(*search) + search_padded) / 8) : 0;
377         search->pad = 0;
378         search->pad2 = 0;
379         memcpy(search->name, search_domain, search_len);
380         memset(&search->name[search_len], 0, search_padded - search_len);
381
382
383         size_t routes_cnt = 0;
384         struct {
385                 uint8_t type;
386                 uint8_t len;
387                 uint8_t prefix;
388                 uint8_t flags;
389                 uint32_t lifetime;
390                 uint32_t addr[4];
391         } routes[RELAYD_MAX_PREFIXES];
392
393         for (ssize_t i = 0; i < ipcnt; ++i) {
394                 struct odhcpd_ipaddr *addr = &addrs[i];
395                 if (addr->dprefix > 64 || addr->dprefix == 0 || addr->valid <= now ||
396                                 (addr->dprefix == 64 && addr->prefix == 64)) {
397                         continue; // Address not suitable
398                 } else if (addr->dprefix > 32) {
399                         addr->addr.s6_addr32[1] &= htonl(~((1U << (64 - addr->dprefix)) - 1));
400                 } else if (addr->dprefix <= 32) {
401                         addr->addr.s6_addr32[0] &= htonl(~((1U << (32 - addr->dprefix)) - 1));
402                         addr->addr.s6_addr32[1] = 0;
403                 }
404
405                 routes[routes_cnt].type = ND_OPT_ROUTE_INFO;
406                 routes[routes_cnt].len = sizeof(*routes) / 8;
407                 routes[routes_cnt].prefix = addr->dprefix;
408                 routes[routes_cnt].flags = 0;
409                 if (iface->route_preference < 0)
410                         routes[routes_cnt].flags |= ND_RA_PREF_LOW;
411                 else if (iface->route_preference > 0)
412                         routes[routes_cnt].flags |= ND_RA_PREF_HIGH;
413                 routes[routes_cnt].lifetime = htonl(addr->valid - now);
414                 routes[routes_cnt].addr[0] = addr->addr.s6_addr32[0];
415                 routes[routes_cnt].addr[1] = addr->addr.s6_addr32[1];
416                 routes[routes_cnt].addr[2] = 0;
417                 routes[routes_cnt].addr[3] = 0;
418
419                 ++routes_cnt;
420         }
421
422         // Calculate periodic transmit
423         int msecs = 0;
424         uint32_t maxival = iface->ra_maxinterval * 1000;
425         uint32_t minival;
426
427         if (maxival < 4000 || maxival > MaxRtrAdvInterval * 1000)
428                 maxival = MaxRtrAdvInterval * 1000;
429
430         if (maxival > minvalid / 3) {
431                 maxival = minvalid / 3;
432
433                 if (maxival < 4000)
434                         maxival = 4000;
435         }
436
437         minival = (maxival * 3) / 4;
438
439         search->lifetime = htonl(maxvalid / 1000);
440
441         if (!dns.lifetime)
442                 dns.lifetime = search->lifetime;
443
444         odhcpd_urandom(&msecs, sizeof(msecs));
445         msecs = (labs(msecs) % (maxival - minival)) + minival;
446
447         struct icmpv6_opt adv_interval = {
448                 .type = ND_OPT_RTR_ADV_INTERVAL,
449                 .len = 1,
450                 .data = {0, 0, maxival >> 24, maxival >> 16, maxival >> 8, maxival}
451         };
452
453         struct iovec iov[RA_IOV_LEN] = {
454                         {&adv, (uint8_t*)&adv.prefix[cnt] - (uint8_t*)&adv},
455                         {&routes, routes_cnt * sizeof(*routes)},
456                         {&dns, (dns_cnt) ? sizeof(dns) : 0},
457                         {dns_addr, dns_cnt * sizeof(*dns_addr)},
458                         {search, search->len * 8},
459                         {&adv_interval, adv_interval.len * 8}};
460         struct sockaddr_in6 dest = {AF_INET6, 0, 0, ALL_IPV6_NODES, 0};
461
462         if (from && !IN6_IS_ADDR_UNSPECIFIED(from))
463                 dest.sin6_addr = *from;
464
465         odhcpd_send(router_event.uloop.fd,
466                         &dest, iov, ARRAY_SIZE(iov), iface);
467
468         return msecs;
469 }
470
471
472 static void trigger_router_advert(struct uloop_timeout *event)
473 {
474         struct interface *iface = container_of(event, struct interface, timer_rs);
475         int msecs = send_router_advert(iface, NULL);
476
477         // Rearm timer if not shut down
478         if (event->cb)
479                 uloop_timeout_set(event, msecs);
480 }
481
482
483 // Event handler for incoming ICMPv6 packets
484 static void handle_icmpv6(void *addr, void *data, size_t len,
485                 struct interface *iface, _unused void *dest)
486 {
487         struct icmp6_hdr *hdr = data;
488         struct sockaddr_in6 *from = addr;
489
490         if (!router_icmpv6_valid(addr, data, len))
491                 return;
492
493         if ((iface->ra == RELAYD_SERVER && !iface->master)) { // Server mode
494                 if (hdr->icmp6_type == ND_ROUTER_SOLICIT)
495                         send_router_advert(iface, &from->sin6_addr);
496         } else if (iface->ra == RELAYD_RELAY) { // Relay mode
497                 if (hdr->icmp6_type == ND_ROUTER_ADVERT && iface->master)
498                         forward_router_advertisement(data, len);
499                 else if (hdr->icmp6_type == ND_ROUTER_SOLICIT && !iface->master)
500                         forward_router_solicitation(odhcpd_get_master_interface());
501         }
502 }
503
504
505 // Forward router solicitation
506 static void forward_router_solicitation(const struct interface *iface)
507 {
508         if (!iface)
509                 return;
510
511         struct icmp6_hdr rs = {ND_ROUTER_SOLICIT, 0, 0, {{0}}};
512         struct iovec iov = {&rs, sizeof(rs)};
513         struct sockaddr_in6 all_routers =
514                 {AF_INET6, 0, 0, ALL_IPV6_ROUTERS, iface->ifindex};
515
516         syslog(LOG_NOTICE, "Sending RS to %s", iface->ifname);
517         odhcpd_send(router_event.uloop.fd, &all_routers, &iov, 1, iface);
518 }
519
520
521 // Handler for incoming router solicitations on slave interfaces
522 static void forward_router_advertisement(uint8_t *data, size_t len)
523 {
524         struct nd_router_advert *adv = (struct nd_router_advert *)data;
525
526         // Rewrite options
527         uint8_t *end = data + len;
528         uint8_t *mac_ptr = NULL;
529         struct in6_addr *dns_ptr = NULL;
530         size_t dns_count = 0;
531
532         struct icmpv6_opt *opt;
533         icmpv6_for_each_option(opt, &adv[1], end) {
534                 if (opt->type == ND_OPT_SOURCE_LINKADDR) {
535                         // Store address of source MAC-address
536                         mac_ptr = opt->data;
537                 } else if (opt->type == ND_OPT_RECURSIVE_DNS && opt->len > 1) {
538                         // Check if we have to rewrite DNS
539                         dns_ptr = (struct in6_addr*)&opt->data[6];
540                         dns_count = (opt->len - 1) / 2;
541                 }
542         }
543
544         syslog(LOG_NOTICE, "Got a RA");
545
546         // Indicate a proxy, however we don't follow the rest of RFC 4389 yet
547         adv->nd_ra_flags_reserved |= ND_RA_FLAG_PROXY;
548
549         // Forward advertisement to all slave interfaces
550         struct sockaddr_in6 all_nodes = {AF_INET6, 0, 0, ALL_IPV6_NODES, 0};
551         struct iovec iov = {data, len};
552
553         struct interface *iface;
554         list_for_each_entry(iface, &interfaces, head) {
555                 if (iface->ra != RELAYD_RELAY || iface->master)
556                         continue;
557
558                 // Fixup source hardware address option
559                 if (mac_ptr)
560                         odhcpd_get_mac(iface, mac_ptr);
561
562                 // If we have to rewrite DNS entries
563                 if (iface->always_rewrite_dns && dns_ptr && dns_count > 0) {
564                         const struct in6_addr *rewrite = iface->dns;
565                         struct in6_addr addr;
566                         size_t rewrite_cnt = iface->dns_cnt;
567
568                         if (rewrite_cnt == 0) {
569                                 if (odhcpd_get_preferred_interface_address(iface->ifindex, &addr) < 1)
570                                         continue; // Unable to comply
571
572                                 rewrite = &addr;
573                                 rewrite_cnt = 1;
574                         }
575
576                         // Copy over any other addresses
577                         for (size_t i = 0; i < dns_count; ++i) {
578                                 size_t j = (i < rewrite_cnt) ? i : rewrite_cnt - 1;
579                                 dns_ptr[i] = rewrite[j];
580                         }
581                 }
582
583                 odhcpd_send(router_event.uloop.fd, &all_nodes, &iov, 1, iface);
584         }
585 }