router: fix interface mtu read error
[project/odhcpd.git] / src / router.c
index 6e5111a..f08a7b0 100644 (file)
@@ -259,12 +259,18 @@ static uint16_t calc_ra_lifetime(struct interface *iface, uint32_t maxival)
 static uint64_t send_router_advert(struct interface *iface, const struct in6_addr *from)
 {
        time_t now = odhcpd_time();
-       int mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
-       int hlim = odhcpd_get_interface_config(iface->ifname, "hop_limit");
+       int mtu = iface->ra_mtu;
+       int hlim = iface->ra_hoplimit;
+
+       if (mtu == 0)
+               mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
 
        if (mtu < 1280)
                mtu = 1280;
 
+       if (hlim == 0)
+               hlim = odhcpd_get_interface_config(iface->ifname, "hop_limit");
+
        struct {
                struct nd_router_advert h;
                struct icmpv6_opt lladdr;
@@ -289,6 +295,10 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
                adv.h.nd_ra_flags_reserved |= ND_RA_PREF_LOW;
        else if (iface->route_preference > 0)
                adv.h.nd_ra_flags_reserved |= ND_RA_PREF_HIGH;
+
+       adv.h.nd_ra_reachable = htonl(iface->ra_reachabletime);
+       adv.h.nd_ra_retransmit = htonl(iface->ra_retranstime);
+
        odhcpd_get_mac(iface, adv.lladdr.data);
 
        // If not currently shutting down
@@ -319,7 +329,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
        struct in6_addr dns_pref, *dns_addr = &dns_pref;
        size_t dns_cnt = 1;
 
-       odhcpd_get_linklocal_interface_address(iface->ifindex, &dns_pref);
+       odhcpd_get_interface_dns_addr(iface, &dns_pref);
 
        for (ssize_t i = 0; i < ipcnt; ++i) {
                struct odhcpd_ipaddr *addr = &addrs[i];
@@ -617,7 +627,7 @@ static void forward_router_advertisement(uint8_t *data, size_t len)
                        size_t rewrite_cnt = iface->dns_cnt;
 
                        if (rewrite_cnt == 0) {
-                               if (odhcpd_get_linklocal_interface_address(iface->ifindex, &addr))
+                               if (odhcpd_get_interface_dns_addr(iface, &addr))
                                        continue; // Unable to comply
 
                                rewrite = &addr;