treewide: fix white space errors
[project/netifd.git] / system-linux.c
index 2f15bf1..8a1173c 100644 (file)
@@ -52,7 +52,6 @@
 #define IFA_FLAGS (IFA_MULTICAST + 1)
 #endif
 
-
 #include <string.h>
 #include <fcntl.h>
 #include <glob.h>
@@ -140,7 +139,7 @@ create_socket(int protocol, int groups)
 
 static bool
 create_raw_event_socket(struct event_socket *ev, int protocol, int groups,
-                        uloop_fd_handler cb, int flags)
+                       uloop_fd_handler cb, int flags)
 {
        ev->sock = create_socket(protocol, groups);
        if (!ev->sock)
@@ -244,7 +243,7 @@ int system_init(void)
                return -1;
 
        if (!create_raw_event_socket(&hotplug_event, NETLINK_KOBJECT_UEVENT, 1,
-                                    handle_hotplug_event, 0))
+                                       handle_hotplug_event, 0))
                return -1;
 
        // Receive network link events form kernel
@@ -1177,10 +1176,10 @@ int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlande
        nlmsg_append(msg, &iim, sizeof(iim), 0);
        nla_put_string(msg, IFLA_IFNAME, vlandev->ifname);
        nla_put_u32(msg, IFLA_LINK, dev->ifindex);
-       
+
        if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO)))
                goto nla_put_failure;
-       
+
        nla_put_string(msg, IFLA_INFO_KIND, "vlan");
 
        if (!(data = nla_nest_start(msg, IFLA_INFO_DATA)))
@@ -1782,7 +1781,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
                .rtm_dst_len = route->mask,
                .rtm_src_len = route->sourcemask,
                .rtm_table = (table < 256) ? table : RT_TABLE_UNSPEC,
-               .rtm_protocol = (route->flags & DEVADDR_KERNEL) ? RTPROT_KERNEL : RTPROT_STATIC,
+               .rtm_protocol = (route->flags & DEVROUTE_PROTO) ? route->proto : RTPROT_STATIC,
                .rtm_scope = RT_SCOPE_NOWHERE,
                .rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST,
                .rtm_flags = (route->flags & DEVROUTE_ONLINK) ? RTNH_F_ONLINK : 0,
@@ -1900,6 +1899,45 @@ bool system_resolve_rt_type(const char *type, unsigned int *id)
        return system_rtn_aton(type, id);
 }
 
+bool system_resolve_rt_proto(const char *type, unsigned int *id)
+{
+       FILE *f;
+       char *e, buf[128];
+       unsigned int n, proto = 256;
+
+       if ((n = strtoul(type, &e, 0)) >= 0 && !*e && e != type)
+               proto = n;
+       else if (!strcmp(type, "unspec"))
+               proto = RTPROT_UNSPEC;
+       else if (!strcmp(type, "kernel"))
+               proto = RTPROT_KERNEL;
+       else if (!strcmp(type, "boot"))
+               proto = RTPROT_BOOT;
+       else if (!strcmp(type, "static"))
+               proto = RTPROT_STATIC;
+       else if ((f = fopen("/etc/iproute2/rt_protos", "r")) != NULL) {
+               while (fgets(buf, sizeof(buf) - 1, f) != NULL) {
+                       if ((e = strtok(buf, " \t\n")) == NULL || *e == '#')
+                               continue;
+
+                       n = strtoul(e, NULL, 10);
+                       e = strtok(NULL, " \t\n");
+
+                       if (e && !strcmp(e, type)) {
+                               proto = n;
+                               break;
+                       }
+               }
+               fclose(f);
+       }
+
+       if (proto > 255)
+               return false;
+
+       *id = proto;
+       return true;
+}
+
 bool system_resolve_rt_table(const char *name, unsigned int *id)
 {
        FILE *f;
@@ -2193,7 +2231,7 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
                        else
                                tos = 1;
                }
-        }
+       }
 
        if ((cur = tb[TUNNEL_ATTR_INFO]) && (blobmsg_type(cur) == BLOBMSG_TYPE_STRING)) {
                uint8_t icsum, ocsum, iseqno, oseqno;
@@ -2426,7 +2464,7 @@ static int system_add_proto_tunnel(const char *name, const uint8_t proto, const
        struct blob_attr *cur;
        bool set_df = true;
        struct ip_tunnel_parm p  = {
-               .link = link,
+               .link = link,
                .iph = {
                        .version = 4,
                        .ihl = 5,