bridge: fix setting pvid for updated vlans
[project/netifd.git] / device.h
index 7ad733eaf5cd1a64d10de5631d5ac9804023d0f3..db6dc3359138633d594f5673ce8ea42c475f94b8 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,14 @@ enum {
        DEV_ATTR_NEIGHGCSTALETIME,
        DEV_ATTR_SENDREDIRECTS,
        DEV_ATTR_NEIGHLOCKTIME,
+       DEV_ATTR_ISOLATE,
+       DEV_ATTR_IP6SEGMENTROUTING,
+       DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST,
+       DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST,
+       DEV_ATTR_DROP_GRATUITOUS_ARP,
+       DEV_ATTR_DROP_UNSOLICITED_NA,
+       DEV_ATTR_ARP_ACCEPT,
+       DEV_ATTR_AUTH,
        __DEV_ATTR_MAX,
 };
 
@@ -75,6 +83,7 @@ struct device_type {
                struct blob_attr *attr);
        void (*config_init)(struct device *);
        enum dev_change_type (*reload)(struct device *, struct blob_attr *);
+       void (*vlan_update)(struct device *);
        void (*dump_info)(struct device *, struct blob_buf *buf);
        void (*dump_stats)(struct device *, struct blob_buf *buf);
        int (*check_state)(struct device *);
@@ -92,8 +101,8 @@ 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),
+       DEV_OPT_DEFAULT_MACADDR         = (1 << 10),
+       DEV_OPT_AUTH                    = (1 << 11),
        DEV_OPT_MTU6                    = (1 << 12),
        DEV_OPT_DADTRANSMITS            = (1 << 13),
        DEV_OPT_MULTICAST_TO_UNICAST    = (1 << 14),
@@ -105,6 +114,13 @@ enum {
        DEV_OPT_MULTICAST_FAST_LEAVE    = (1 << 20),
        DEV_OPT_SENDREDIRECTS           = (1 << 21),
        DEV_OPT_NEIGHLOCKTIME           = (1 << 22),
+       DEV_OPT_ISOLATE                 = (1 << 23),
+       DEV_OPT_IP6SEGMENTROUTING       = (1 << 24),
+       DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST = (1 << 25),
+       DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST = (1 << 26),
+       DEV_OPT_DROP_GRATUITOUS_ARP     = (1 << 27),
+       DEV_OPT_DROP_UNSOLICITED_NA     = (1 << 28),
+       DEV_OPT_ARP_ACCEPT              = (1 << 29),
 };
 
 /* events broadcasted to all users of a device */
@@ -120,6 +136,7 @@ enum device_event {
        DEV_EVENT_UP,
        DEV_EVENT_DOWN,
 
+       DEV_EVENT_AUTH_UP,
        DEV_EVENT_LINK_UP,
        DEV_EVENT_LINK_DOWN,
 
@@ -163,8 +180,6 @@ struct device_settings {
        unsigned int neigh4gcstaletime;
        unsigned int neigh6gcstaletime;
        int neigh4locktime;
-       bool rps;
-       bool xps;
        unsigned int dadtransmits;
        bool multicast_to_unicast;
        unsigned int multicast_router;
@@ -173,6 +188,14 @@ struct device_settings {
        bool learning;
        bool unicast_flood;
        bool sendredirects;
+       bool ip6segmentrouting;
+       bool isolate;
+       bool drop_v4_unicast_in_l2_multicast;
+       bool drop_v6_unicast_in_l2_multicast;
+       bool drop_gratuitous_arp;
+       bool drop_unsolicited_na;
+       bool arp_accept;
+       bool auth;
 };
 
 /*
@@ -186,6 +209,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;
 
@@ -198,6 +224,7 @@ struct device {
        int active;
        /* DEV_EVENT_LINK_UP */
        bool link_active;
+       bool auth_status;
 
        bool external;
        bool disabled;
@@ -225,9 +252,33 @@ struct device {
 };
 
 struct device_hotplug_ops {
-       int (*prepare)(struct device *dev);
-       int (*add)(struct device *main, struct device *member);
-       int (*del)(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, struct blob_attr *vlan);
+};
+
+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;
+       bool pending;
 };
 
 extern const struct uci_blob_param_list device_attr_list;
@@ -237,10 +288,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 +304,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,13 +324,14 @@ 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);
 void alias_notify_device(const char *name, struct device *dev);
 struct device *device_alias_get(const char *name);
 
+void device_set_auth_status(struct device *dev, bool value);
+
 static inline void
 device_set_deferred(struct device *dev, bool value)
 {
@@ -292,4 +346,15 @@ device_set_disabled(struct device *dev, bool value)
        device_refresh_present(dev);
 }
 
+static inline bool
+device_link_active(struct device *dev)
+{
+       if (dev->settings.auth && !dev->auth_status)
+               return false;
+
+       return dev->link_active;
+}
+
+bool device_check_ip6segmentrouting(void);
+
 #endif