vlandev: support bridge-vlan aliases in the vid config parameter
[project/netifd.git] / device.h
index 74d20d65cd11c740ec225e516b7f1ff4c15f928e..b2b18ab0cfa63c4069c4b495d33a29f5169e8bfb 100644 (file)
--- a/device.h
+++ b/device.h
 
 #include <libubox/avl.h>
 #include <libubox/safe_list.h>
+#include <libubox/kvlist.h>
 #include <netinet/in.h>
 
 struct device;
 struct device_type;
 struct device_user;
 struct device_hotplug_ops;
+struct bridge_vlan;
 struct interface;
 
 typedef int (*device_state_cb)(struct device *, bool up);
@@ -40,8 +42,6 @@ enum {
        DEV_ATTR_IGMPVERSION,
        DEV_ATTR_MLDVERSION,
        DEV_ATTR_NEIGHREACHABLETIME,
-       DEV_ATTR_RPS,
-       DEV_ATTR_XPS,
        DEV_ATTR_DADTRANSMITS,
        DEV_ATTR_MULTICAST_TO_UNICAST,
        DEV_ATTR_MULTICAST_ROUTER,
@@ -52,6 +52,7 @@ enum {
        DEV_ATTR_NEIGHGCSTALETIME,
        DEV_ATTR_SENDREDIRECTS,
        DEV_ATTR_NEIGHLOCKTIME,
+       DEV_ATTR_ISOLATE,
        __DEV_ATTR_MAX,
 };
 
@@ -92,8 +93,7 @@ enum {
        DEV_OPT_IGMPVERSION             = (1 << 7),
        DEV_OPT_MLDVERSION              = (1 << 8),
        DEV_OPT_NEIGHREACHABLETIME      = (1 << 9),
-       DEV_OPT_RPS                     = (1 << 10),
-       DEV_OPT_XPS                     = (1 << 11),
+       /* 2 bit hole */
        DEV_OPT_MTU6                    = (1 << 12),
        DEV_OPT_DADTRANSMITS            = (1 << 13),
        DEV_OPT_MULTICAST_TO_UNICAST    = (1 << 14),
@@ -105,6 +105,7 @@ enum {
        DEV_OPT_MULTICAST_FAST_LEAVE    = (1 << 20),
        DEV_OPT_SENDREDIRECTS           = (1 << 21),
        DEV_OPT_NEIGHLOCKTIME           = (1 << 22),
+       DEV_OPT_ISOLATE                 = (1 << 23),
 };
 
 /* events broadcasted to all users of a device */
@@ -162,9 +163,7 @@ struct device_settings {
        unsigned int neigh6reachabletime;
        unsigned int neigh4gcstaletime;
        unsigned int neigh6gcstaletime;
-       unsigned int neigh4locktime;
-       bool rps;
-       bool xps;
+       int neigh4locktime;
        unsigned int dadtransmits;
        bool multicast_to_unicast;
        unsigned int multicast_router;
@@ -173,6 +172,7 @@ struct device_settings {
        bool learning;
        bool unicast_flood;
        bool sendredirects;
+       bool isolate;
 };
 
 /*
@@ -186,6 +186,9 @@ struct device {
        struct safe_list users;
        struct safe_list aliases;
 
+       struct vlist_tree vlans;
+       struct kvlist vlan_aliases;
+
        char ifname[IFNAMSIZ + 1];
        int ifindex;
 
@@ -225,11 +228,34 @@ struct device {
 };
 
 struct device_hotplug_ops {
-       int (*prepare)(struct device *dev);
-       int (*add)(struct device *main, struct device *member);
+       int (*prepare)(struct device *dev, struct device **bridge_dev);
+       int (*add)(struct device *main, struct device *member, struct blob_attr *vlan);
        int (*del)(struct device *main, struct device *member);
 };
 
+enum bridge_vlan_flags {
+       BRVLAN_F_SELF =         (1 << 0),
+       BRVLAN_F_PVID =         (1 << 1),
+       BRVLAN_F_UNTAGGED =     (1 << 2),
+};
+
+struct bridge_vlan_port {
+       const char *ifname;
+       uint16_t flags;
+};
+
+struct bridge_vlan {
+       struct vlist_node node;
+
+       struct bridge_vlan_port *ports;
+       int n_ports;
+
+       struct list_head hotplug_ports;
+
+       uint16_t vid;
+       bool local;
+};
+
 extern const struct uci_blob_param_list device_attr_list;
 extern struct device_type simple_device_type;
 extern struct device_type tunnel_device_type;
@@ -237,10 +263,13 @@ extern struct device_type tunnel_device_type;
 void device_lock(void);
 void device_unlock(void);
 
+void device_vlan_update(bool done);
+
 int device_type_add(struct device_type *devtype);
 struct device_type *device_type_get(const char *tname);
 struct device *device_create(const char *name, struct device_type *type,
                             struct blob_attr *config);
+void device_merge_settings(struct device *dev, struct device_settings *n);
 void device_init_settings(struct device *dev, struct blob_attr **tb);
 void device_init_pending(void);
 
@@ -250,9 +279,8 @@ device_apply_config(struct device *dev, struct device_type *type,
 
 void device_reset_config(void);
 void device_reset_old(void);
-void device_set_default_ps(bool state);
 
-void device_init_virtual(struct device *dev, struct device_type *type, const char *name);
+int device_init_virtual(struct device *dev, struct device_type *type, const char *name);
 int device_init(struct device *dev, struct device_type *type, const char *ifname);
 void device_cleanup(struct device *dev);
 struct device *device_find(const char *name);
@@ -271,7 +299,6 @@ void device_release(struct device_user *dep);
 int device_check_state(struct device *dev);
 void device_dump_status(struct blob_buf *b, struct device *dev);
 
-void device_free(struct device *dev);
 void device_free_unused(struct device *dev);
 
 struct device *get_vlan_device_chain(const char *ifname, bool create);