proto-shell: retry setup if the proto handler script quits without changing the state...
[project/netifd.git] / system-linux.c
index e45fc69..a6734a4 100644 (file)
 #define RTN_FAILED_POLICY 12
 #endif
 
+#ifndef RT_TABLE_PRELOCAL
+#define RT_TABLE_PRELOCAL 128
+#endif
+
 #include <string.h>
 #include <fcntl.h>
 #include <glob.h>
@@ -370,7 +374,6 @@ static int system_get_neigh6reachabletime(struct device *dev, char *buf, const s
 static int cb_rtnl_event(struct nl_msg *msg, void *arg)
 {
        struct nlmsghdr *nh = nlmsg_hdr(msg);
-       struct ifinfomsg *ifi = NLMSG_DATA(nh);
        struct nlattr *nla[__IFLA_MAX];
        int link_state = 0;
        char buf[10];
@@ -378,7 +381,7 @@ static int cb_rtnl_event(struct nl_msg *msg, void *arg)
        if (nh->nlmsg_type != RTM_NEWLINK)
                goto out;
 
-       nlmsg_parse(nh, sizeof(*ifi), nla, __IFLA_MAX - 1, NULL);
+       nlmsg_parse(nh, sizeof(struct ifinfomsg), nla, __IFLA_MAX - 1, NULL);
        if (!nla[IFLA_IFNAME])
                goto out;
 
@@ -1638,6 +1641,8 @@ bool system_resolve_rt_table(const char *name, unsigned int *id)
                table = RT_TABLE_MAIN;
        else if (!strcmp(name, "local"))
                table = RT_TABLE_LOCAL;
+       else if (!strcmp(name, "prelocal"))
+               table = RT_TABLE_PRELOCAL;
 
        /* try to look up name in /etc/iproute2/rt_tables */
        else if ((f = fopen("/etc/iproute2/rt_tables", "r")) != NULL)
@@ -1798,7 +1803,11 @@ int system_flush_iprules(void)
 
        rule.flags = IPRULE_INET4 | IPRULE_PRIORITY | IPRULE_LOOKUP;
 
-       rule.priority = 128;
+       rule.priority = 0;
+       rule.lookup = RT_TABLE_PRELOCAL;
+       rv |= system_iprule(&rule, RTM_NEWRULE);
+
+       rule.priority = 1;
        rule.lookup = RT_TABLE_LOCAL;
        rv |= system_iprule(&rule, RTM_NEWRULE);
 
@@ -1813,7 +1822,11 @@ int system_flush_iprules(void)
 
        rule.flags = IPRULE_INET6 | IPRULE_PRIORITY | IPRULE_LOOKUP;
 
-       rule.priority = 128;
+       rule.priority = 0;
+       rule.lookup = RT_TABLE_PRELOCAL;
+       rv |= system_iprule(&rule, RTM_NEWRULE);
+
+       rule.priority = 1;
        rule.lookup = RT_TABLE_LOCAL;
        rv |= system_iprule(&rule, RTM_NEWRULE);