0001
0002
0003
0004
0005
0006
0007 #ifndef _VXLAN_PRIVATE_H
0008 #define _VXLAN_PRIVATE_H
0009
0010 #include <linux/rhashtable.h>
0011
0012 extern unsigned int vxlan_net_id;
0013 extern const u8 all_zeros_mac[ETH_ALEN + 2];
0014 extern const struct rhashtable_params vxlan_vni_rht_params;
0015
0016 #define PORT_HASH_BITS 8
0017 #define PORT_HASH_SIZE (1 << PORT_HASH_BITS)
0018
0019
0020 struct vxlan_net {
0021 struct list_head vxlan_list;
0022 struct hlist_head sock_list[PORT_HASH_SIZE];
0023 spinlock_t sock_lock;
0024 struct notifier_block nexthop_notifier_block;
0025 };
0026
0027
0028 struct vxlan_fdb {
0029 struct hlist_node hlist;
0030 struct rcu_head rcu;
0031 unsigned long updated;
0032 unsigned long used;
0033 struct list_head remotes;
0034 u8 eth_addr[ETH_ALEN];
0035 u16 state;
0036 __be32 vni;
0037 u16 flags;
0038 struct list_head nh_list;
0039 struct nexthop __rcu *nh;
0040 struct vxlan_dev __rcu *vdev;
0041 };
0042
0043 #define NTF_VXLAN_ADDED_BY_USER 0x100
0044
0045
0046 static inline struct hlist_head *vni_head(struct vxlan_sock *vs, __be32 vni)
0047 {
0048 return &vs->vni_list[hash_32((__force u32)vni, VNI_HASH_BITS)];
0049 }
0050
0051
0052 static inline struct hlist_head *vs_head(struct net *net, __be16 port)
0053 {
0054 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
0055
0056 return &vn->sock_list[hash_32(ntohs(port), PORT_HASH_BITS)];
0057 }
0058
0059
0060
0061
0062 static inline struct vxlan_rdst *first_remote_rcu(struct vxlan_fdb *fdb)
0063 {
0064 if (rcu_access_pointer(fdb->nh))
0065 return NULL;
0066 return list_entry_rcu(fdb->remotes.next, struct vxlan_rdst, list);
0067 }
0068
0069 static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb)
0070 {
0071 if (rcu_access_pointer(fdb->nh))
0072 return NULL;
0073 return list_first_entry(&fdb->remotes, struct vxlan_rdst, list);
0074 }
0075
0076 #if IS_ENABLED(CONFIG_IPV6)
0077 static inline
0078 bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
0079 {
0080 if (a->sa.sa_family != b->sa.sa_family)
0081 return false;
0082 if (a->sa.sa_family == AF_INET6)
0083 return ipv6_addr_equal(&a->sin6.sin6_addr, &b->sin6.sin6_addr);
0084 else
0085 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
0086 }
0087
0088 #else
0089
0090 static inline
0091 bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
0092 {
0093 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
0094 }
0095
0096 #endif
0097
0098 static inline struct vxlan_vni_node *
0099 vxlan_vnifilter_lookup(struct vxlan_dev *vxlan, __be32 vni)
0100 {
0101 struct vxlan_vni_group *vg;
0102
0103 vg = rcu_dereference_rtnl(vxlan->vnigrp);
0104 if (!vg)
0105 return NULL;
0106
0107 return rhashtable_lookup_fast(&vg->vni_hash, &vni,
0108 vxlan_vni_rht_params);
0109 }
0110
0111
0112 int vxlan_fdb_create(struct vxlan_dev *vxlan,
0113 const u8 *mac, union vxlan_addr *ip,
0114 __u16 state, __be16 port, __be32 src_vni,
0115 __be32 vni, __u32 ifindex, __u16 ndm_flags,
0116 u32 nhid, struct vxlan_fdb **fdb,
0117 struct netlink_ext_ack *extack);
0118 int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
0119 const unsigned char *addr, union vxlan_addr ip,
0120 __be16 port, __be32 src_vni, __be32 vni,
0121 u32 ifindex, bool swdev_notify);
0122 u32 eth_vni_hash(const unsigned char *addr, __be32 vni);
0123 u32 fdb_head_index(struct vxlan_dev *vxlan, const u8 *mac, __be32 vni);
0124 int vxlan_fdb_update(struct vxlan_dev *vxlan,
0125 const u8 *mac, union vxlan_addr *ip,
0126 __u16 state, __u16 flags,
0127 __be16 port, __be32 src_vni, __be32 vni,
0128 __u32 ifindex, __u16 ndm_flags, u32 nhid,
0129 bool swdev_notify, struct netlink_ext_ack *extack);
0130 int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan,
0131 struct vxlan_config *conf, __be32 vni);
0132
0133
0134 int vxlan_vnigroup_init(struct vxlan_dev *vxlan);
0135 void vxlan_vnigroup_uninit(struct vxlan_dev *vxlan);
0136
0137 void vxlan_vnifilter_init(void);
0138 void vxlan_vnifilter_uninit(void);
0139 void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni,
0140 struct vxlan_vni_node *vninode,
0141 int type, unsigned int len);
0142
0143 void vxlan_vs_add_vnigrp(struct vxlan_dev *vxlan,
0144 struct vxlan_sock *vs,
0145 bool ipv6);
0146 void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan);
0147 int vxlan_vnilist_update_group(struct vxlan_dev *vxlan,
0148 union vxlan_addr *old_remote_ip,
0149 union vxlan_addr *new_remote_ip,
0150 struct netlink_ext_ack *extack);
0151
0152
0153
0154 int vxlan_multicast_join(struct vxlan_dev *vxlan);
0155 int vxlan_multicast_leave(struct vxlan_dev *vxlan);
0156 bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev,
0157 __be32 vni, union vxlan_addr *rip, int rifindex);
0158 int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip,
0159 int rifindex);
0160 int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip,
0161 int rifindex);
0162 #endif