dhcpv4: add ubus_get_address4 ubus_get_mask4 function
[project/odhcpd.git] / src / router.c
index 0b15dac..f942d8f 100644 (file)
@@ -176,7 +176,7 @@ static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len)
 
        char line[512], ifname[16];
        bool found_default = false;
-       struct odhcpd_ipaddr p = {IN6ADDR_ANY_INIT, 0, 0, false, 0, 0, 0};
+       struct odhcpd_ipaddr p = {IN6ADDR_ANY_INIT, 0, 0, 0, 0};
        while (fgets(line, sizeof(line), fp_route)) {
                uint32_t rflags;
                if (sscanf(line, "00000000000000000000000000000000 00 "
@@ -209,9 +209,11 @@ static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len)
 // Router Advert server mode
 static uint64_t send_router_advert(struct interface *iface, const struct in6_addr *from)
 {
-       int mtu = odhcpd_get_interface_mtu(iface->ifname);
-       if (mtu < 0)
-               mtu = 1500;
+       int mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
+       int hlim = odhcpd_get_interface_config(iface->ifname, "hop_limit");
+
+       if (mtu < 1280)
+               mtu = 1280;
 
        struct {
                struct nd_router_advert h;
@@ -224,6 +226,9 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
                .mtu = {ND_OPT_MTU, 1, 0, htonl(mtu)},
        };
 
+       if (hlim > 0)
+               adv.h.nd_ra_curhoplimit = hlim;
+
        if (iface->dhcpv6)
                adv.h.nd_ra_flags_reserved = ND_RA_FLAG_OTHER;
 
@@ -262,7 +267,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
 
        for (ssize_t i = 0; i < ipcnt; ++i) {
                struct odhcpd_ipaddr *addr = &addrs[i];
-               if (addr->prefix > 96 || addr->has_class)
+               if (addr->prefix > 96)
                        continue; // Address not suitable
 
                if (addr->preferred > MaxPreferredTime)
@@ -537,7 +542,6 @@ static void forward_router_advertisement(uint8_t *data, size_t len)
        struct sockaddr_in6 all_nodes = {AF_INET6, 0, 0, ALL_IPV6_NODES, 0};
        struct iovec iov = {data, len};
 
-       struct odhcpd_ipaddr addr;
        struct interface *iface;
        list_for_each_entry(iface, &interfaces, head) {
                if (iface->ra != RELAYD_RELAY || iface->master)
@@ -550,13 +554,14 @@ static void forward_router_advertisement(uint8_t *data, size_t len)
                // If we have to rewrite DNS entries
                if (iface->always_rewrite_dns && dns_ptr && dns_count > 0) {
                        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, &addr, 1) < 1)
+                               if (odhcpd_get_preferred_interface_address(iface->ifindex, &addr) < 1)
                                        continue; // Unable to comply
 
-                               rewrite = &addr.addr;
+                               rewrite = &addr;
                                rewrite_cnt = 1;
                        }