config: limit ra_mtu to 65535
[project/odhcpd.git] / src / dhcpv6.c
index f0a4938..ebb0c80 100644 (file)
@@ -18,6 +18,7 @@
 #include <stddef.h>
 #include <resolv.h>
 #include <sys/timerfd.h>
+#include <arpa/inet.h>
 
 #include "odhcpd.h"
 #include "dhcpv6.h"
@@ -51,7 +52,7 @@ int setup_dhcpv6_interface(struct interface *iface, bool enable)
        }
 
        // Configure multicast settings
-       if (enable && iface->dhcpv6 && !iface->master) {
+       if (enable && iface->dhcpv6) {
                int sock = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
                if (sock < 0) {
                        syslog(LOG_ERR, "Failed to create DHCPv6 server socket: %s",
@@ -89,6 +90,9 @@ int setup_dhcpv6_interface(struct interface *iface, bool enable)
                if (iface->dhcpv6 == RELAYD_SERVER)
                        setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &server, sizeof(server));
 
+               if (iface->dhcpv6 != RELAYD_RELAY || !iface->master)
+                       ndp_rqs_addr6_dump();
+
                iface->dhcpv6_event.uloop.fd = sock;
                iface->dhcpv6_event.handle_dgram = handle_dhcpv6;
                odhcpd_register(&iface->dhcpv6_event);
@@ -224,19 +228,19 @@ static void handle_client_request(void *addr, void *data, size_t len,
        } refresh = {htons(DHCPV6_OPT_INFO_REFRESH), htons(sizeof(uint32_t)),
                        htonl(600)};
 
-       struct odhcpd_ipaddr ipaddr;
-       struct in6_addr *dns_addr = iface->dns;
+       struct in6_addr dns_addr, *dns_addr_ptr = iface->dns;
        size_t dns_cnt = iface->dns_cnt;
 
-       if (dns_cnt == 0 && odhcpd_get_interface_addresses(iface->ifindex, &ipaddr, 1) == 1) {
-               dns_addr = &ipaddr.addr;
+       if ((dns_cnt == 0) &&
+               !odhcpd_get_interface_dns_addr(iface, &dns_addr)) {
+               dns_addr_ptr = &dns_addr;
                dns_cnt = 1;
        }
 
        struct {
                uint16_t type;
                uint16_t len;
-       } dns = {htons(DHCPV6_OPT_DNS_SERVERS), htons(dns_cnt * sizeof(*dns_addr))};
+       } dns = {htons(DHCPV6_OPT_DNS_SERVERS), htons(dns_cnt * sizeof(*dns_addr_ptr))};
 
 
 
@@ -274,7 +278,7 @@ static void handle_client_request(void *addr, void *data, size_t len,
                [IOV_DEST] = {&dest, (uint8_t*)&dest.clientid_type - (uint8_t*)&dest},
                [IOV_MAXRT] = {&maxrt, sizeof(maxrt)},
                [IOV_DNS] = {&dns, (dns_cnt) ? sizeof(dns) : 0},
-               [IOV_DNS_ADDR] = {dns_addr, dns_cnt * sizeof(*dns_addr)},
+               [IOV_DNS_ADDR] = {dns_addr_ptr, dns_cnt * sizeof(*dns_addr_ptr)},
                [IOV_SEARCH] = {&search, (search_len) ? sizeof(search) : 0},
                [IOV_SEARCH_DOMAIN] = {search_domain, search_len},
                [IOV_PDBUF] = {pdbuf, 0},
@@ -302,6 +306,9 @@ static void handle_client_request(void *addr, void *data, size_t len,
        } else if (opts[-4] == DHCPV6_MSG_INFORMATION_REQUEST) {
                iov[IOV_REFRESH].iov_base = &refresh;
                iov[IOV_REFRESH].iov_len = sizeof(refresh);
+
+               // Return inf max rt option in reply to information request
+               maxrt.type = htons(DHCPV6_OPT_INF_MAX_RT);
        }
 
        // Go through options and find what we need
@@ -330,7 +337,7 @@ static void handle_client_request(void *addr, void *data, size_t len,
                        if (IN6_IS_ADDR_UNSPECIFIED(&cerid.addr)) {
                                struct odhcpd_ipaddr addrs[32];
                                ssize_t len = odhcpd_get_interface_addresses(0, addrs,
-                                               sizeof(addrs) / sizeof(*addrs));
+                                               ARRAY_SIZE(addrs));
 
                                for (ssize_t i = 0; i < len; ++i)
                                        if (IN6_IS_ADDR_UNSPECIFIED(&cerid.addr)
@@ -452,15 +459,15 @@ static void relay_server_response(uint8_t *data, size_t len)
                if (is_authenticated)
                        return; // Impossible to rewrite
 
-               struct odhcpd_ipaddr ip;
                const struct in6_addr *rewrite = iface->dns;
+               struct in6_addr addr;
                size_t rewrite_cnt = iface->dns_cnt;
 
                if (rewrite_cnt == 0) {
-                       if (odhcpd_get_interface_addresses(iface->ifindex, &ip, 1) < 1)
+                       if (odhcpd_get_interface_dns_addr(iface, &addr))
                                return; // Unable to get interface address
 
-                       rewrite = &ip.addr;
+                       rewrite = &addr;
                        rewrite_cnt = 1;
                }
 
@@ -529,5 +536,5 @@ static void relay_client_request(struct sockaddr_in6 *source,
        struct sockaddr_in6 dhcpv6_servers = {AF_INET6,
                        htons(DHCPV6_SERVER_PORT), 0, ALL_DHCPV6_SERVERS, 0};
        struct iovec iov[2] = {{&hdr, sizeof(hdr)}, {(void*)data, len}};
-       odhcpd_send(iface->dhcpv6_event.uloop.fd, &dhcpv6_servers, iov, 2, master);
+       odhcpd_send(master->dhcpv6_event.uloop.fd, &dhcpv6_servers, iov, 2, master);
 }