X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv6.c;h=3128968b8629d2bc593038f509b072d617826b33;hp=c62a08f9a761f3c58ace52e24d4eb8287b98e47b;hb=5dad295c283a8ab8101d58ec3d8ead49a3a62a19;hpb=73850ae66e29b6cebf73a787a639f8400c6c94ab diff --git a/src/dhcpv6.c b/src/dhcpv6.c index c62a08f..3128968 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "odhcpd.h" #include "dhcpv6.h" @@ -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); @@ -228,7 +232,7 @@ static void handle_client_request(void *addr, void *data, size_t len, size_t dns_cnt = iface->dns_cnt; if ((dns_cnt == 0) && - odhcpd_get_preferred_interface_address(iface->ifindex, &dns_addr)) { + !odhcpd_get_interface_dns_addr(iface, &dns_addr)) { dns_addr_ptr = &dns_addr; dns_cnt = 1; } @@ -331,14 +335,15 @@ static void handle_client_request(void *addr, void *data, size_t len, iov[IOV_CERID].iov_len = sizeof(cerid); if (IN6_IS_ADDR_UNSPECIFIED(&cerid.addr)) { - struct odhcpd_ipaddr addrs[32]; - ssize_t len = odhcpd_get_interface_addresses(0, addrs, - ARRAY_SIZE(addrs)); + struct odhcpd_ipaddr *addrs; + ssize_t len = odhcpd_get_interface_addresses(0, &addrs); for (ssize_t i = 0; i < len; ++i) if (IN6_IS_ADDR_UNSPECIFIED(&cerid.addr) || memcmp(&addrs[i].addr, &cerid.addr, sizeof(cerid.addr)) < 0) cerid.addr = addrs[i].addr; + + free(addrs); } #endif } @@ -460,7 +465,7 @@ static void relay_server_response(uint8_t *data, size_t len) size_t rewrite_cnt = iface->dns_cnt; if (rewrite_cnt == 0) { - if (odhcpd_get_preferred_interface_address(iface->ifindex, &addr) < 1) + if (odhcpd_get_interface_dns_addr(iface, &addr)) return; // Unable to get interface address rewrite = &addr; @@ -517,17 +522,18 @@ static void relay_client_request(struct sockaddr_in6 *source, memcpy(&hdr.interface_id_data, &ifindex, sizeof(ifindex)); // Detect public IP of slave interface to use as link-address - struct odhcpd_ipaddr ip; - if (odhcpd_get_interface_addresses(iface->ifindex, &ip, 1) < 1) { + struct odhcpd_ipaddr *ip = NULL; + if (odhcpd_get_interface_addresses(iface->ifindex, &ip) < 1) { // No suitable address! Is the slave not configured yet? // Detect public IP of master interface and use it instead // This is WRONG and probably violates the RFC. However // otherwise we have a hen and egg problem because the // slave-interface cannot be auto-configured. - if (odhcpd_get_interface_addresses(master->ifindex, &ip, 1) < 1) + if (odhcpd_get_interface_addresses(master->ifindex, &ip) < 1) return; // Could not obtain a suitable address } - memcpy(&hdr.link_address, &ip.addr, sizeof(hdr.link_address)); + memcpy(&hdr.link_address, &ip[0].addr, sizeof(hdr.link_address)); + free(ip); struct sockaddr_in6 dhcpv6_servers = {AF_INET6, htons(DHCPV6_SERVER_PORT), 0, ALL_DHCPV6_SERVERS, 0};