[PATCH net-next 18/22] vxlan: Factor out device configuration
This factors out the device configuration out of the RTNL newlink API which allows for in-kernel creation of VXLAN net_devices. Signed-off-by: Thomas Graf tg...@suug.ch --- drivers/net/vxlan.c | 332 include/net/vxlan.h | 59 ++ 2 files changed, 236 insertions(+), 155 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index 2587ac8..30e1f21 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -55,10 +55,6 @@ #define PORT_HASH_BITS 8 #define PORT_HASH_SIZE (1PORT_HASH_BITS) -#define VNI_HASH_BITS 10 -#define VNI_HASH_SIZE (1VNI_HASH_BITS) -#define FDB_HASH_BITS 8 -#define FDB_HASH_SIZE (1FDB_HASH_BITS) #define FDB_AGE_DEFAULT 300 /* 5 min */ #define FDB_AGE_INTERVAL (10 * HZ) /* rescan interval */ @@ -75,6 +71,7 @@ module_param(log_ecn_error, bool, 0644); MODULE_PARM_DESC(log_ecn_error, Log packets received with corrupted ECN); static int vxlan_net_id; +static struct rtnl_link_ops vxlan_link_ops; static const u8 all_zeros_mac[ETH_ALEN]; @@ -85,21 +82,6 @@ struct vxlan_net { spinlock_tsock_lock; }; -union vxlan_addr { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr sa; -}; - -struct vxlan_rdst { - union vxlan_addr remote_ip; - __be16 remote_port; - u32 remote_vni; - u32 remote_ifindex; - struct list_head list; - struct rcu_head rcu; -}; - /* Forwarding table entry */ struct vxlan_fdb { struct hlist_node hlist;/* linked list of entries */ @@ -112,31 +94,6 @@ struct vxlan_fdb { u8flags;/* see ndm_flags */ }; -/* Pseudo network device */ -struct vxlan_dev { - struct hlist_node hlist;/* vni hash table */ - struct list_head next; /* vxlan's per namespace list */ - struct vxlan_sock *vn_sock; /* listening socket */ - struct net_device *dev; - struct net*net; /* netns for packet i/o */ - struct vxlan_rdst default_dst; /* default destination */ - union vxlan_addr saddr;/* source address */ - __be16dst_port; - __u16 port_min; /* source port range */ - __u16 port_max; - __u8 tos; /* TOS override */ - __u8 ttl; - u32 flags;/* VXLAN_F_* in vxlan.h */ - - unsigned long age_interval; - struct timer_list age_timer; - spinlock_thash_lock; - unsigned int addrcnt; - unsigned int addrmax; - - struct hlist_head fdb_head[FDB_HASH_SIZE]; -}; - /* salt for hash table */ static u32 vxlan_salt __read_mostly; static struct workqueue_struct *vxlan_wq; @@ -352,7 +309,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, if (send_ip vxlan_nla_put_addr(skb, NDA_DST, rdst-remote_ip)) goto nla_put_failure; - if (rdst-remote_port rdst-remote_port != vxlan-dst_port + if (rdst-remote_port rdst-remote_port != vxlan-cfg.dst_port nla_put_be16(skb, NDA_PORT, rdst-remote_port)) goto nla_put_failure; if (rdst-remote_vni != vxlan-default_dst.remote_vni @@ -756,7 +713,8 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan, if (!(flags NLM_F_CREATE)) return -ENOENT; - if (vxlan-addrmax vxlan-addrcnt = vxlan-addrmax) + if (vxlan-cfg.addrmax + vxlan-addrcnt = vxlan-cfg.addrmax) return -ENOSPC; /* Disallow replace to add a multicast entry */ @@ -842,7 +800,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, return -EINVAL; *port = nla_get_be16(tb[NDA_PORT]); } else { - *port = vxlan-dst_port; + *port = vxlan-cfg.dst_port; } if (tb[NDA_VNI]) { @@ -1028,7 +986,7 @@ static bool vxlan_snoop(struct net_device *dev, vxlan_fdb_create(vxlan, src_mac, src_ip, NUD_REACHABLE, NLM_F_EXCL|NLM_F_CREATE, -vxlan-dst_port, +vxlan-cfg.dst_port, vxlan-default_dst.remote_vni, 0, NTF_SELF); spin_unlock(vxlan-hash_lock); @@ -1957,7 +1915,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, info = skb_tunnel_info(skb, AF_INET); if (rdst) { - dst_port = rdst-remote_port ? rdst-remote_port : vxlan-dst_port; + dst_port = rdst-remote_port ?
[PATCH net-next 18/22] vxlan: Factor out device configuration
This factors out the device configuration out of the RTNL newlink API which allows for in-kernel creation of VXLAN net_devices. Signed-off-by: Thomas Graf tg...@suug.ch --- drivers/net/vxlan.c | 332 include/net/vxlan.h | 59 ++ 2 files changed, 236 insertions(+), 155 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index 23378db..5ae6c0c 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -55,10 +55,6 @@ #define PORT_HASH_BITS 8 #define PORT_HASH_SIZE (1PORT_HASH_BITS) -#define VNI_HASH_BITS 10 -#define VNI_HASH_SIZE (1VNI_HASH_BITS) -#define FDB_HASH_BITS 8 -#define FDB_HASH_SIZE (1FDB_HASH_BITS) #define FDB_AGE_DEFAULT 300 /* 5 min */ #define FDB_AGE_INTERVAL (10 * HZ) /* rescan interval */ @@ -75,6 +71,7 @@ module_param(log_ecn_error, bool, 0644); MODULE_PARM_DESC(log_ecn_error, Log packets received with corrupted ECN); static int vxlan_net_id; +static struct rtnl_link_ops vxlan_link_ops; static const u8 all_zeros_mac[ETH_ALEN]; @@ -85,21 +82,6 @@ struct vxlan_net { spinlock_tsock_lock; }; -union vxlan_addr { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr sa; -}; - -struct vxlan_rdst { - union vxlan_addr remote_ip; - __be16 remote_port; - u32 remote_vni; - u32 remote_ifindex; - struct list_head list; - struct rcu_head rcu; -}; - /* Forwarding table entry */ struct vxlan_fdb { struct hlist_node hlist;/* linked list of entries */ @@ -112,31 +94,6 @@ struct vxlan_fdb { u8eth_addr[ETH_ALEN]; }; -/* Pseudo network device */ -struct vxlan_dev { - struct hlist_node hlist;/* vni hash table */ - struct list_head next; /* vxlan's per namespace list */ - struct vxlan_sock *vn_sock; /* listening socket */ - struct net_device *dev; - struct net*net; /* netns for packet i/o */ - struct vxlan_rdst default_dst; /* default destination */ - union vxlan_addr saddr;/* source address */ - __be16dst_port; - __u16 port_min; /* source port range */ - __u16 port_max; - __u8 tos; /* TOS override */ - __u8 ttl; - u32 flags;/* VXLAN_F_* in vxlan.h */ - - unsigned long age_interval; - struct timer_list age_timer; - spinlock_thash_lock; - unsigned int addrcnt; - unsigned int addrmax; - - struct hlist_head fdb_head[FDB_HASH_SIZE]; -}; - /* salt for hash table */ static u32 vxlan_salt __read_mostly; static struct workqueue_struct *vxlan_wq; @@ -352,7 +309,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, if (send_ip vxlan_nla_put_addr(skb, NDA_DST, rdst-remote_ip)) goto nla_put_failure; - if (rdst-remote_port rdst-remote_port != vxlan-dst_port + if (rdst-remote_port rdst-remote_port != vxlan-cfg.dst_port nla_put_be16(skb, NDA_PORT, rdst-remote_port)) goto nla_put_failure; if (rdst-remote_vni != vxlan-default_dst.remote_vni @@ -756,7 +713,8 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan, if (!(flags NLM_F_CREATE)) return -ENOENT; - if (vxlan-addrmax vxlan-addrcnt = vxlan-addrmax) + if (vxlan-cfg.addrmax + vxlan-addrcnt = vxlan-cfg.addrmax) return -ENOSPC; /* Disallow replace to add a multicast entry */ @@ -842,7 +800,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, return -EINVAL; *port = nla_get_be16(tb[NDA_PORT]); } else { - *port = vxlan-dst_port; + *port = vxlan-cfg.dst_port; } if (tb[NDA_VNI]) { @@ -1028,7 +986,7 @@ static bool vxlan_snoop(struct net_device *dev, vxlan_fdb_create(vxlan, src_mac, src_ip, NUD_REACHABLE, NLM_F_EXCL|NLM_F_CREATE, -vxlan-dst_port, +vxlan-cfg.dst_port, vxlan-default_dst.remote_vni, 0, NTF_SELF); spin_unlock(vxlan-hash_lock); @@ -1957,7 +1915,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, info = skb_tunnel_info(skb, AF_INET); if (rdst) { - dst_port = rdst-remote_port ? rdst-remote_port : vxlan-dst_port; + dst_port = rdst-remote_port ? rdst-remote_port :