netifd-device: add support for promisc setting
authorMartin Hundebøll <martin@hundeboll.net>
Mon, 15 Sep 2014 09:57:50 +0000 (11:57 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 17 Sep 2014 11:38:06 +0000 (13:38 +0200)
Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
device.c
device.h
system-linux.c

index 26b020f..b29d73b 100644 (file)
--- a/device.c
+++ b/device.c
@@ -38,6 +38,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
        [DEV_ATTR_TXQUEUELEN] = { .name = "txqueuelen", .type = BLOBMSG_TYPE_INT32 },
        [DEV_ATTR_ENABLED] = { .name = "enabled", .type = BLOBMSG_TYPE_BOOL },
        [DEV_ATTR_IPV6] = { .name = "ipv6", .type = BLOBMSG_TYPE_BOOL },
+       [DEV_ATTR_PROMISC] = { .name = "promisc", .type = BLOBMSG_TYPE_BOOL },
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -144,6 +145,7 @@ device_merge_settings(struct device *dev, struct device_settings *n)
                (s->flags & DEV_OPT_MACADDR ? s->macaddr : os->macaddr),
                sizeof(n->macaddr));
        n->ipv6 = s->flags & DEV_OPT_IPV6 ? s->ipv6 : os->ipv6;
+       n->promisc = s->flags & DEV_OPT_PROMISC ? s->promisc : os->promisc;
        n->flags = s->flags | os->flags;
 }
 
@@ -182,6 +184,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
                s->flags |= DEV_OPT_IPV6;
        }
 
+       if ((cur = tb[DEV_ATTR_PROMISC])) {
+               s->promisc = blobmsg_get_bool(cur);
+               s->flags |= DEV_OPT_PROMISC;
+       }
+
        device_set_disabled(dev, disabled);
 }
 
@@ -717,6 +724,8 @@ device_dump_status(struct blob_buf *b, struct device *dev)
                        blobmsg_add_u32(b, "txqueuelen", st.txqueuelen);
                if (st.flags & DEV_OPT_IPV6)
                        blobmsg_add_u8(b, "ipv6", st.ipv6);
+               if (st.flags & DEV_OPT_PROMISC)
+                       blobmsg_add_u8(b, "promisc", st.promisc);
        }
 
        s = blobmsg_open_table(b, "statistics");
index 01a68bc..08a3055 100644 (file)
--- a/device.h
+++ b/device.h
@@ -32,6 +32,7 @@ enum {
        DEV_ATTR_TXQUEUELEN,
        DEV_ATTR_ENABLED,
        DEV_ATTR_IPV6,
+       DEV_ATTR_PROMISC,
        __DEV_ATTR_MAX,
 };
 
@@ -62,6 +63,7 @@ enum {
        DEV_OPT_MACADDR         = (1 << 1),
        DEV_OPT_TXQUEUELEN      = (1 << 2),
        DEV_OPT_IPV6            = (1 << 3),
+       DEV_OPT_PROMISC         = (1 << 4),
 };
 
 /* events broadcasted to all users of a device */
@@ -108,6 +110,7 @@ struct device_settings {
        unsigned int txqueuelen;
        uint8_t macaddr[6];
        bool ipv6;
+       bool promisc;
 };
 
 /*
index 2a281cc..c4d89be 100644 (file)
@@ -943,6 +943,11 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
                s->ipv6 = !strtoul(buf, NULL, 0);
                s->flags |= DEV_OPT_IPV6;
        }
+
+       if (ioctl(sock_ioctl, SIOCGIFFLAGS, &ifr) == 0) {
+               s->promisc = ifr.ifr_flags & IFF_PROMISC;
+               s->flags |= DEV_OPT_PROMISC;
+       }
 }
 
 void
@@ -973,6 +978,11 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
        }
        if (s->flags & DEV_OPT_IPV6 & apply_mask)
                system_set_disable_ipv6(dev, s->ipv6 ? "0" : "1");
+       if (s->flags & DEV_OPT_PROMISC & apply_mask) {
+               if (system_if_flags(dev->ifname, s->promisc ? IFF_PROMISC : 0,
+                                   !s->promisc ? IFF_PROMISC : 0) < 0)
+                       s->flags &= ~DEV_OPT_PROMISC;
+       }
 }
 
 int system_if_up(struct device *dev)