2 * Copyright (C) 2012-2013 Steven Barth <steven@midlink.org>
3 * Copyright (C) 2018 Hans Dedecker <dedeckeh@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License v2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
21 #include <sys/timerfd.h>
22 #include <arpa/inet.h>
24 #include <libubox/utils.h>
30 static void relay_client_request(struct sockaddr_in6
*source
,
31 const void *data
, size_t len
, struct interface
*iface
);
32 static void relay_server_response(uint8_t *data
, size_t len
);
34 static void handle_dhcpv6(void *addr
, void *data
, size_t len
,
35 struct interface
*iface
, void *dest
);
36 static void handle_client_request(void *addr
, void *data
, size_t len
,
37 struct interface
*iface
, void *dest_addr
);
40 /* Create socket and register events */
43 return dhcpv6_ia_init();
46 int dhcpv6_setup_interface(struct interface
*iface
, bool enable
)
50 if (iface
->dhcpv6_event
.uloop
.fd
> 0) {
51 uloop_fd_delete(&iface
->dhcpv6_event
.uloop
);
52 close(iface
->dhcpv6_event
.uloop
.fd
);
53 iface
->dhcpv6_event
.uloop
.fd
= -1;
56 /* Configure multicast settings */
57 if (enable
&& iface
->dhcpv6
) {
58 struct sockaddr_in6 bind_addr
= {AF_INET6
, htons(DHCPV6_SERVER_PORT
),
59 0, IN6ADDR_ANY_INIT
, 0};
60 struct ipv6_mreq mreq
;
63 iface
->dhcpv6_event
.uloop
.fd
= socket(AF_INET6
, SOCK_DGRAM
| SOCK_CLOEXEC
, IPPROTO_UDP
);
64 if (iface
->dhcpv6_event
.uloop
.fd
< 0) {
65 syslog(LOG_ERR
, "socket(AF_INET6): %m");
70 /* Basic IPv6 configuration */
71 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, SOL_SOCKET
, SO_BINDTODEVICE
,
72 iface
->ifname
, strlen(iface
->ifname
)) < 0) {
73 syslog(LOG_ERR
, "setsockopt(SO_BINDTODEVICE): %m");
78 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, IPPROTO_IPV6
, IPV6_V6ONLY
,
79 &val
, sizeof(val
)) < 0) {
80 syslog(LOG_ERR
, "setsockopt(IPV6_V6ONLY): %m");
85 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, SOL_SOCKET
, SO_REUSEADDR
,
86 &val
, sizeof(val
)) < 0) {
87 syslog(LOG_ERR
, "setsockopt(SO_REUSEADDR): %m");
92 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, IPPROTO_IPV6
, IPV6_RECVPKTINFO
,
93 &val
, sizeof(val
)) < 0) {
94 syslog(LOG_ERR
, "setsockopt(IPV6_RECVPKTINFO): %m");
99 val
= DHCPV6_HOP_COUNT_LIMIT
;
100 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, IPPROTO_IPV6
, IPV6_MULTICAST_HOPS
,
101 &val
, sizeof(val
)) < 0) {
102 syslog(LOG_ERR
, "setsockopt(IPV6_MULTICAST_HOPS): %m");
108 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, IPPROTO_IPV6
, IPV6_MULTICAST_LOOP
,
109 &val
, sizeof(val
)) < 0) {
110 syslog(LOG_ERR
, "setsockopt(IPV6_MULTICAST_LOOP): %m");
115 if (bind(iface
->dhcpv6_event
.uloop
.fd
, (struct sockaddr
*)&bind_addr
,
116 sizeof(bind_addr
)) < 0) {
117 syslog(LOG_ERR
, "bind(): %m");
122 memset(&mreq
, 0, sizeof(mreq
));
123 inet_pton(AF_INET6
, ALL_DHCPV6_RELAYS
, &mreq
.ipv6mr_multiaddr
);
124 mreq
.ipv6mr_interface
= iface
->ifindex
;
126 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, IPPROTO_IPV6
, IPV6_ADD_MEMBERSHIP
,
127 &mreq
, sizeof(mreq
)) < 0) {
128 syslog(LOG_ERR
, "setsockopt(IPV6_ADD_MEMBERSHIP): %m");
133 if (iface
->dhcpv6
== MODE_SERVER
) {
134 memset(&mreq
, 0, sizeof(mreq
));
135 inet_pton(AF_INET6
, ALL_DHCPV6_SERVERS
, &mreq
.ipv6mr_multiaddr
);
136 mreq
.ipv6mr_interface
= iface
->ifindex
;
138 if (setsockopt(iface
->dhcpv6_event
.uloop
.fd
, IPPROTO_IPV6
, IPV6_ADD_MEMBERSHIP
,
139 &mreq
, sizeof(mreq
)) < 0) {
140 syslog(LOG_ERR
, "setsockopt(IPV6_ADD_MEMBERSHIP): %m");
146 iface
->dhcpv6_event
.handle_dgram
= handle_dhcpv6
;
147 odhcpd_register(&iface
->dhcpv6_event
);
150 ret
= dhcpv6_setup_ia_interface(iface
, enable
);
153 if (ret
< 0 && iface
->dhcpv6_event
.uloop
.fd
> 0) {
154 close(iface
->dhcpv6_event
.uloop
.fd
);
155 iface
->dhcpv6_event
.uloop
.fd
= -1;
165 #define IOV_STAT IOV_MAXRT
171 #define IOV_REFRESH IOV_PDBUF
178 static void handle_nested_message(uint8_t *data
, size_t len
,
179 uint8_t **opts
, uint8_t **end
, struct iovec iov
[IOV_TOTAL
])
181 struct dhcpv6_relay_header
*hdr
= (struct dhcpv6_relay_header
*)data
;
182 if (iov
[IOV_NESTED
].iov_base
== NULL
) {
183 iov
[IOV_NESTED
].iov_base
= data
;
184 iov
[IOV_NESTED
].iov_len
= len
;
187 if (len
< sizeof(struct dhcpv6_client_header
))
190 if (hdr
->msg_type
!= DHCPV6_MSG_RELAY_FORW
) {
191 iov
[IOV_NESTED
].iov_len
= data
- (uint8_t*)iov
[IOV_NESTED
].iov_base
;
192 struct dhcpv6_client_header
*hdr
= (void*)data
;
193 *opts
= (uint8_t*)&hdr
[1];
198 uint16_t otype
, olen
;
200 dhcpv6_for_each_option(hdr
->options
, data
+ len
, otype
, olen
, odata
) {
201 if (otype
== DHCPV6_OPT_RELAY_MSG
) {
202 iov
[IOV_RELAY_MSG
].iov_base
= odata
+ olen
;
203 iov
[IOV_RELAY_MSG
].iov_len
= (((uint8_t*)iov
[IOV_NESTED
].iov_base
) +
204 iov
[IOV_NESTED
].iov_len
) - (odata
+ olen
);
205 handle_nested_message(odata
, olen
, opts
, end
, iov
);
212 static void update_nested_message(uint8_t *data
, size_t len
, ssize_t pdiff
)
214 struct dhcpv6_relay_header
*hdr
= (struct dhcpv6_relay_header
*)data
;
215 if (hdr
->msg_type
!= DHCPV6_MSG_RELAY_FORW
)
218 hdr
->msg_type
= DHCPV6_MSG_RELAY_REPL
;
220 uint16_t otype
, olen
;
222 dhcpv6_for_each_option(hdr
->options
, data
+ len
, otype
, olen
, odata
) {
223 if (otype
== DHCPV6_OPT_RELAY_MSG
) {
225 odata
[-2] = (olen
>> 8) & 0xff;
226 odata
[-1] = olen
& 0xff;
227 update_nested_message(odata
, olen
- pdiff
, pdiff
);
233 /* Simple DHCPv6-server for information requests */
234 static void handle_client_request(void *addr
, void *data
, size_t len
,
235 struct interface
*iface
, void *dest_addr
)
237 struct dhcpv6_client_header
*hdr
= data
;
239 if (len
< sizeof(*hdr
))
242 syslog(LOG_NOTICE
, "Got DHCPv6 request on %s", iface
->name
);
244 /* Construct reply message */
245 struct __attribute__((packed
)) {
248 uint16_t serverid_type
;
249 uint16_t serverid_length
;
251 uint16_t hardware_type
;
253 uint16_t clientid_type
;
254 uint16_t clientid_length
;
255 uint8_t clientid_buf
[130];
257 .msg_type
= DHCPV6_MSG_REPLY
,
258 .serverid_type
= htons(DHCPV6_OPT_SERVERID
),
259 .serverid_length
= htons(10),
260 .duid_type
= htons(3),
261 .hardware_type
= htons(1),
262 .clientid_type
= htons(DHCPV6_OPT_CLIENTID
),
265 odhcpd_get_mac(iface
, dest
.mac
);
267 struct __attribute__((packed
)) {
271 } maxrt
= {htons(DHCPV6_OPT_SOL_MAX_RT
), htons(sizeof(maxrt
) - 4),
274 struct __attribute__((packed
)) {
278 } stat
= {htons(DHCPV6_OPT_STATUS
), htons(sizeof(stat
) - 4),
279 htons(DHCPV6_STATUS_USEMULTICAST
)};
281 struct __attribute__((packed
)) {
285 } refresh
= {htons(DHCPV6_OPT_INFO_REFRESH
), htons(sizeof(uint32_t)),
288 struct in6_addr dns_addr
, *dns_addr_ptr
= iface
->dns
;
289 size_t dns_cnt
= iface
->dns_cnt
;
291 if ((dns_cnt
== 0) &&
292 !odhcpd_get_interface_dns_addr(iface
, &dns_addr
)) {
293 dns_addr_ptr
= &dns_addr
;
300 } dns
= {htons(DHCPV6_OPT_DNS_SERVERS
), htons(dns_cnt
* sizeof(*dns_addr_ptr
))};
304 /* DNS Search options */
305 uint8_t search_buf
[256], *search_domain
= iface
->search
;
306 size_t search_len
= iface
->search_len
;
308 if (!search_domain
&& !res_init() && _res
.dnsrch
[0] && _res
.dnsrch
[0][0]) {
309 int len
= dn_comp(_res
.dnsrch
[0], search_buf
,
310 sizeof(search_buf
), NULL
, NULL
);
312 search_domain
= search_buf
;
320 } search
= {htons(DHCPV6_OPT_DNS_DOMAIN
), htons(search_len
)};
323 struct dhcpv6_cer_id cerid
= {
325 .type
= htons(EXT_CER_ID
),
328 .addr
= iface
->dhcpv6_pd_cer
,
333 struct iovec iov
[IOV_TOTAL
] = {
334 [IOV_NESTED
] = {NULL
, 0},
335 [IOV_DEST
] = {&dest
, (uint8_t*)&dest
.clientid_type
- (uint8_t*)&dest
},
336 [IOV_MAXRT
] = {&maxrt
, sizeof(maxrt
)},
337 [IOV_DNS
] = {&dns
, (dns_cnt
) ? sizeof(dns
) : 0},
338 [IOV_DNS_ADDR
] = {dns_addr_ptr
, dns_cnt
* sizeof(*dns_addr_ptr
)},
339 [IOV_SEARCH
] = {&search
, (search_len
) ? sizeof(search
) : 0},
340 [IOV_SEARCH_DOMAIN
] = {search_domain
, search_len
},
341 [IOV_PDBUF
] = {pdbuf
, 0},
342 [IOV_CERID
] = {&cerid
, 0},
343 [IOV_DHCPV6_RAW
] = {iface
->dhcpv6_raw
, iface
->dhcpv6_raw_len
},
344 [IOV_RELAY_MSG
] = {NULL
, 0}
347 uint8_t *opts
= (uint8_t*)&hdr
[1], *opts_end
= (uint8_t*)data
+ len
;
348 if (hdr
->msg_type
== DHCPV6_MSG_RELAY_FORW
)
349 handle_nested_message(data
, len
, &opts
, &opts_end
, iov
);
351 memcpy(dest
.tr_id
, &opts
[-3], sizeof(dest
.tr_id
));
353 if (opts
[-4] == DHCPV6_MSG_ADVERTISE
|| opts
[-4] == DHCPV6_MSG_REPLY
|| opts
[-4] == DHCPV6_MSG_RELAY_REPL
)
356 if (!IN6_IS_ADDR_MULTICAST((struct in6_addr
*)dest_addr
) && iov
[IOV_NESTED
].iov_len
== 0 &&
357 (opts
[-4] == DHCPV6_MSG_SOLICIT
|| opts
[-4] == DHCPV6_MSG_CONFIRM
||
358 opts
[-4] == DHCPV6_MSG_REBIND
|| opts
[-4] == DHCPV6_MSG_INFORMATION_REQUEST
))
361 if (opts
[-4] == DHCPV6_MSG_SOLICIT
) {
362 dest
.msg_type
= DHCPV6_MSG_ADVERTISE
;
363 } else if (opts
[-4] == DHCPV6_MSG_INFORMATION_REQUEST
) {
364 iov
[IOV_REFRESH
].iov_base
= &refresh
;
365 iov
[IOV_REFRESH
].iov_len
= sizeof(refresh
);
367 /* Return inf max rt option in reply to information request */
368 maxrt
.type
= htons(DHCPV6_OPT_INF_MAX_RT
);
371 /* Go through options and find what we need */
372 uint16_t otype
, olen
;
374 dhcpv6_for_each_option(opts
, opts_end
, otype
, olen
, odata
) {
375 if (otype
== DHCPV6_OPT_CLIENTID
&& olen
<= 130) {
376 dest
.clientid_length
= htons(olen
);
377 memcpy(dest
.clientid_buf
, odata
, olen
);
378 iov
[IOV_DEST
].iov_len
+= 4 + olen
;
379 } else if (otype
== DHCPV6_OPT_SERVERID
) {
380 if (olen
!= ntohs(dest
.serverid_length
) ||
381 memcmp(odata
, &dest
.duid_type
, olen
))
382 return; /* Not for us */
383 } else if (iface
->filter_class
&& otype
== DHCPV6_OPT_USER_CLASS
) {
384 uint8_t *c
= odata
, *cend
= &odata
[olen
];
385 for (; &c
[2] <= cend
&& &c
[2 + (c
[0] << 8) + c
[1]] <= cend
; c
= &c
[2 + (c
[0] << 8) + c
[1]]) {
386 size_t elen
= strlen(iface
->filter_class
);
387 if (((((size_t)c
[0]) << 8) | c
[1]) == elen
&& !memcmp(&c
[2], iface
->filter_class
, elen
))
388 return; /* Ignore from homenet */
390 } else if (otype
== DHCPV6_OPT_IA_PD
) {
392 iov
[IOV_CERID
].iov_len
= sizeof(cerid
);
394 if (IN6_IS_ADDR_UNSPECIFIED(&cerid
.addr
)) {
395 struct odhcpd_ipaddr
*addrs
;
396 ssize_t len
= netlink_get_interface_addrs(0, true, &addrs
);
398 for (ssize_t i
= 0; i
< len
; ++i
)
399 if (IN6_IS_ADDR_UNSPECIFIED(&cerid
.addr
)
400 || memcmp(&addrs
[i
].addr
, &cerid
.addr
, sizeof(cerid
.addr
)) < 0)
401 cerid
.addr
= addrs
[i
].addr
.in6
;
409 if (!IN6_IS_ADDR_MULTICAST((struct in6_addr
*)dest_addr
) && iov
[IOV_NESTED
].iov_len
== 0 &&
410 (opts
[-4] == DHCPV6_MSG_REQUEST
|| opts
[-4] == DHCPV6_MSG_RENEW
||
411 opts
[-4] == DHCPV6_MSG_RELEASE
|| opts
[-4] == DHCPV6_MSG_DECLINE
)) {
412 iov
[IOV_STAT
].iov_base
= &stat
;
413 iov
[IOV_STAT
].iov_len
= sizeof(stat
);
415 for (ssize_t i
= IOV_STAT
+ 1; i
< IOV_TOTAL
; ++i
)
418 odhcpd_send(iface
->dhcpv6_event
.uloop
.fd
, addr
, iov
, ARRAY_SIZE(iov
), iface
);
422 if (opts
[-4] != DHCPV6_MSG_INFORMATION_REQUEST
) {
423 ssize_t ialen
= dhcpv6_handle_ia(pdbuf
, sizeof(pdbuf
), iface
, addr
, &opts
[-4], opts_end
);
424 iov
[IOV_PDBUF
].iov_len
= ialen
;
425 if (ialen
< 0 || (ialen
== 0 && (opts
[-4] == DHCPV6_MSG_REBIND
|| opts
[-4] == DHCPV6_MSG_CONFIRM
)))
429 if (iov
[IOV_NESTED
].iov_len
> 0) /* Update length */
430 update_nested_message(data
, len
, iov
[IOV_DEST
].iov_len
+ iov
[IOV_MAXRT
].iov_len
+
431 iov
[IOV_DNS
].iov_len
+ iov
[IOV_DNS_ADDR
].iov_len
+
432 iov
[IOV_SEARCH
].iov_len
+ iov
[IOV_SEARCH_DOMAIN
].iov_len
+
433 iov
[IOV_PDBUF
].iov_len
+ iov
[IOV_CERID
].iov_len
+
434 iov
[IOV_DHCPV6_RAW
].iov_len
- (4 + opts_end
- opts
));
436 odhcpd_send(iface
->dhcpv6_event
.uloop
.fd
, addr
, iov
, ARRAY_SIZE(iov
), iface
);
440 /* Central DHCPv6-relay handler */
441 static void handle_dhcpv6(void *addr
, void *data
, size_t len
,
442 struct interface
*iface
, void *dest_addr
)
444 if (iface
->dhcpv6
== MODE_SERVER
) {
445 handle_client_request(addr
, data
, len
, iface
, dest_addr
);
446 } else if (iface
->dhcpv6
== MODE_RELAY
) {
448 relay_server_response(data
, len
);
450 relay_client_request(addr
, data
, len
, iface
);
455 /* Relay server response (regular relay server handling) */
456 static void relay_server_response(uint8_t *data
, size_t len
)
458 /* Information we need to gather */
459 uint8_t *payload_data
= NULL
;
460 size_t payload_len
= 0;
461 int32_t ifaceidx
= 0;
462 struct sockaddr_in6 target
= {AF_INET6
, htons(DHCPV6_CLIENT_PORT
),
463 0, IN6ADDR_ANY_INIT
, 0};
465 syslog(LOG_NOTICE
, "Got a DHCPv6-reply");
468 uint8_t *odata
, *end
= data
+ len
;
470 /* Relay DHCPv6 reply from server to client */
471 struct dhcpv6_relay_header
*h
= (void*)data
;
472 if (len
< sizeof(*h
) || h
->msg_type
!= DHCPV6_MSG_RELAY_REPL
)
475 memcpy(&target
.sin6_addr
, &h
->peer_address
,
476 sizeof(struct in6_addr
));
478 /* Go through options and find what we need */
479 dhcpv6_for_each_option(h
->options
, end
, otype
, olen
, odata
) {
480 if (otype
== DHCPV6_OPT_INTERFACE_ID
481 && olen
== sizeof(ifaceidx
)) {
482 memcpy(&ifaceidx
, odata
, sizeof(ifaceidx
));
483 } else if (otype
== DHCPV6_OPT_RELAY_MSG
) {
484 payload_data
= odata
;
489 /* Invalid interface-id or basic payload */
490 struct interface
*iface
= odhcpd_get_interface_by_index(ifaceidx
);
491 if (!iface
|| iface
->master
|| !payload_data
|| payload_len
< 4)
494 bool is_authenticated
= false;
495 struct in6_addr
*dns_ptr
= NULL
;
496 size_t dns_count
= 0;
498 /* If the payload is relay-reply we have to send to the server port */
499 if (payload_data
[0] == DHCPV6_MSG_RELAY_REPL
) {
500 target
.sin6_port
= htons(DHCPV6_SERVER_PORT
);
501 } else { /* Go through the payload data */
502 struct dhcpv6_client_header
*h
= (void*)payload_data
;
503 end
= payload_data
+ payload_len
;
505 dhcpv6_for_each_option(&h
[1], end
, otype
, olen
, odata
) {
506 if (otype
== DHCPV6_OPT_DNS_SERVERS
&& olen
>= 16) {
507 dns_ptr
= (struct in6_addr
*)odata
;
508 dns_count
= olen
/ 16;
509 } else if (otype
== DHCPV6_OPT_AUTH
) {
510 is_authenticated
= true;
515 /* Rewrite DNS servers if requested */
516 if (iface
->always_rewrite_dns
&& dns_ptr
&& dns_count
> 0) {
517 if (is_authenticated
)
518 return; /* Impossible to rewrite */
520 const struct in6_addr
*rewrite
= iface
->dns
;
521 struct in6_addr addr
;
522 size_t rewrite_cnt
= iface
->dns_cnt
;
524 if (rewrite_cnt
== 0) {
525 if (odhcpd_get_interface_dns_addr(iface
, &addr
))
526 return; // Unable to get interface address
532 /* Copy over any other addresses */
533 for (size_t i
= 0; i
< dns_count
; ++i
) {
534 size_t j
= (i
< rewrite_cnt
) ? i
: rewrite_cnt
- 1;
535 memcpy(&dns_ptr
[i
], &rewrite
[j
], sizeof(*rewrite
));
539 struct iovec iov
= {payload_data
, payload_len
};
540 odhcpd_send(iface
->dhcpv6_event
.uloop
.fd
, &target
, &iov
, 1, iface
);
543 static struct odhcpd_ipaddr
*relay_link_address(struct interface
*iface
)
545 struct odhcpd_ipaddr
*addr
= NULL
;
546 time_t now
= odhcpd_time();
548 for (size_t i
= 0; i
< iface
->addr6_len
; i
++) {
549 if (iface
->addr6
[i
].valid
<= (uint32_t)now
)
552 if (iface
->addr6
[i
].preferred
> (uint32_t)now
) {
553 addr
= &iface
->addr6
[i
];
557 if (!addr
|| (iface
->addr6
[i
].valid
> addr
->valid
))
558 addr
= &iface
->addr6
[i
];
564 /* Relay client request (regular DHCPv6-relay) */
565 static void relay_client_request(struct sockaddr_in6
*source
,
566 const void *data
, size_t len
, struct interface
*iface
)
568 struct interface
*master
= odhcpd_get_master_interface();
569 const struct dhcpv6_relay_header
*h
= data
;
570 struct sockaddr_in6 s
;
572 if (!master
|| master
->dhcpv6
!= MODE_RELAY
||
573 h
->msg_type
== DHCPV6_MSG_RELAY_REPL
||
574 h
->msg_type
== DHCPV6_MSG_RECONFIGURE
||
575 h
->msg_type
== DHCPV6_MSG_REPLY
||
576 h
->msg_type
== DHCPV6_MSG_ADVERTISE
)
577 return; /* Invalid message types for client */
579 syslog(LOG_NOTICE
, "Got a DHCPv6-request");
581 /* Construct our forwarding envelope */
582 struct dhcpv6_relay_forward_envelope hdr
= {
583 .msg_type
= DHCPV6_MSG_RELAY_FORW
,
585 .interface_id_type
= htons(DHCPV6_OPT_INTERFACE_ID
),
586 .interface_id_len
= htons(sizeof(uint32_t)),
587 .relay_message_type
= htons(DHCPV6_OPT_RELAY_MSG
),
588 .relay_message_len
= htons(len
),
591 if (h
->msg_type
== DHCPV6_MSG_RELAY_FORW
) { /* handle relay-forward */
592 if (h
->hop_count
>= DHCPV6_HOP_COUNT_LIMIT
)
593 return; // Invalid hop count
595 hdr
.hop_count
= h
->hop_count
+ 1;
598 /* use memcpy here as the destination fields are unaligned */
599 uint32_t ifindex
= iface
->ifindex
;
600 memcpy(&hdr
.peer_address
, &source
->sin6_addr
, sizeof(struct in6_addr
));
601 memcpy(&hdr
.interface_id_data
, &ifindex
, sizeof(ifindex
));
603 /* Detect public IP of slave interface to use as link-address */
604 struct odhcpd_ipaddr
*ip
= relay_link_address(iface
);
606 /* No suitable address! Is the slave not configured yet?
607 * Detect public IP of master interface and use it instead
608 * This is WRONG and probably violates the RFC. However
609 * otherwise we have a hen and egg problem because the
610 * slave-interface cannot be auto-configured. */
611 ip
= relay_link_address(master
);
613 return; /* Could not obtain a suitable address */
616 memcpy(&hdr
.link_address
, &ip
->addr
.in6
, sizeof(hdr
.link_address
));
618 memset(&s
, 0, sizeof(s
));
619 s
.sin6_family
= AF_INET6
;
620 s
.sin6_port
= htons(DHCPV6_SERVER_PORT
);
621 inet_pton(AF_INET6
, ALL_DHCPV6_SERVERS
, &s
.sin6_addr
);
623 struct iovec iov
[2] = {{&hdr
, sizeof(hdr
)}, {(void*)data
, len
}};
624 odhcpd_send(master
->dhcpv6_event
.uloop
.fd
, &s
, iov
, 2, master
);