interface-ip: Remove ip loop policy rules as kernel issue is fixed
[project/netifd.git] / interface-ip.c
index 18dd2fa..6c152b6 100644 (file)
@@ -133,23 +133,6 @@ static int set_ip_source_policy(bool add, bool v6, unsigned int priority,
        return (add) ? system_add_iprule(&rule) : system_del_iprule(&rule);
 }
 
-static int set_ip_lo_policy(bool add, bool v6, struct interface *iface)
-{
-       struct iprule rule = {
-               .flags = IPRULE_IN | IPRULE_LOOKUP | IPRULE_PRIORITY,
-               .priority = IPRULE_PRIORITY_NW + iface->l3_dev.dev->ifindex,
-               .lookup = (v6) ? iface->ip6table : iface->ip4table,
-               .in_dev = "lo"
-       };
-
-       if (!rule.lookup)
-               return 0;
-
-       rule.flags |= (v6) ? IPRULE_INET6 : IPRULE_INET4;
-
-       return (add) ? system_add_iprule(&rule) : system_del_iprule(&rule);
-}
-
 static bool
 __find_ip_addr_target(struct interface_ip_settings *ip, union if_addr *a, bool v6)
 {
@@ -710,7 +693,9 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment,
        struct device *l3_downlink = iface->l3_dev.dev;
 
        struct device_addr addr;
+       struct device_route route;
        memset(&addr, 0, sizeof(addr));
+       memset(&route, 0, sizeof(route));
 
        if (IN6_IS_ADDR_UNSPECIFIED(&assignment->addr)) {
                addr.addr.in6 = prefix->addr;
@@ -722,15 +707,14 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment,
                addr.addr.in6 = assignment->addr;
 
        addr.mask = assignment->length;
-       addr.flags = DEVADDR_INET6;
+       addr.flags = DEVADDR_INET6 | DEVADDR_OFFLINK;
        addr.preferred_until = prefix->preferred_until;
        addr.valid_until = prefix->valid_until;
 
-       if (addr.mask < 64) {
-               addr.mask = 64;
-               system_del_address(l3_downlink, &addr);
-               addr.mask = assignment->length;
-       }
+       route.flags = DEVADDR_INET6;
+       route.mask = addr.mask < 64 ? 64 : addr.mask;
+       route.addr = addr.addr;
+       clear_if_addr(&route.addr, route.mask);
 
        if (!add && assignment->enabled) {
                time_t now = system_get_rtime();
@@ -738,8 +722,6 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment,
                if (!addr.valid_until || addr.valid_until - now > 7200)
                        addr.valid_until = now + 7200;
 
-               system_del_address(l3_downlink, &addr); // Work around dangling prefix routes
-
                if (prefix->iface) {
                        if (prefix->iface->ip6table)
                                set_ip_source_policy(false, true, IPRULE_PRIORITY_NW, &addr.addr,
@@ -749,16 +731,12 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment,
                                                        addr.mask, 0, iface, "unreachable");
                }
 
-               if (addr.mask < 64)
-                       addr.mask = 64;
-
-               interface_handle_subnet_route(iface, &addr, false);
+               system_del_route(l3_downlink, &route);
                system_add_address(l3_downlink, &addr);
 
                assignment->enabled = false;
        } else if (add && (iface->state == IFS_UP || iface->state == IFS_SETUP) &&
                        !system_add_address(l3_downlink, &addr)) {
-               interface_handle_subnet_route(iface, &addr, false);
 
                if (prefix->iface && !assignment->enabled) {
                        set_ip_source_policy(true, true, IPRULE_PRIORITY_REJECT, &addr.addr,
@@ -769,15 +747,14 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment,
                                                addr.mask, prefix->iface->ip6table, iface, NULL);
                }
 
-               if (addr.mask < 64)
-                       addr.mask = 64;
+               route.metric = iface->metric;
+               system_add_route(l3_downlink, &route);
 
-               interface_handle_subnet_route(iface, &addr, true);
+               if (uplink && uplink->l3_dev.dev && !(l3_downlink->settings.flags & DEV_OPT_MTU6)) {
+                       int mtu = system_update_ipv6_mtu(uplink->l3_dev.dev, 0);
+                       int mtu_old = system_update_ipv6_mtu(l3_downlink, 0);
 
-               if (uplink && uplink->l3_dev.dev) {
-                       int mtu = system_update_ipv6_mtu(
-                                       uplink->l3_dev.dev, 0);
-                       if (mtu > 0)
+                       if (mtu > 0 && mtu_old > mtu)
                                system_update_ipv6_mtu(l3_downlink, mtu);
                }
 
@@ -1264,13 +1241,9 @@ void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled)
                        if (!strcmp(a->name, ip->iface->name))
                                interface_set_prefix_address(a, c, ip->iface, enabled);
 
-       if (ip->iface && ip->iface->l3_dev.dev) {
-               set_ip_lo_policy(enabled, true, ip->iface);
-               set_ip_lo_policy(enabled, false, ip->iface);
-
+       if (ip->iface && ip->iface->l3_dev.dev)
                set_ip_source_policy(enabled, true, IPRULE_PRIORITY_REJECT + ip->iface->l3_dev.dev->ifindex,
                        NULL, 0, 0, ip->iface, "failed_policy");
-       }
 }
 
 void