0001
0002
0003
0004
0005
0006 #ifndef VPORT_H
0007 #define VPORT_H 1
0008
0009 #include <linux/if_tunnel.h>
0010 #include <linux/list.h>
0011 #include <linux/netlink.h>
0012 #include <linux/openvswitch.h>
0013 #include <linux/reciprocal_div.h>
0014 #include <linux/skbuff.h>
0015 #include <linux/spinlock.h>
0016 #include <linux/u64_stats_sync.h>
0017
0018 #include "datapath.h"
0019
0020 struct vport;
0021 struct vport_parms;
0022
0023
0024
0025 int ovs_vport_init(void);
0026 void ovs_vport_exit(void);
0027
0028 struct vport *ovs_vport_add(const struct vport_parms *);
0029 void ovs_vport_del(struct vport *);
0030
0031 struct vport *ovs_vport_locate(const struct net *net, const char *name);
0032
0033 void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *);
0034
0035 int ovs_vport_set_options(struct vport *, struct nlattr *options);
0036 int ovs_vport_get_options(const struct vport *, struct sk_buff *);
0037
0038 int ovs_vport_set_upcall_portids(struct vport *, const struct nlattr *pids);
0039 int ovs_vport_get_upcall_portids(const struct vport *, struct sk_buff *);
0040 u32 ovs_vport_find_upcall_portid(const struct vport *, struct sk_buff *);
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 struct vport_portids {
0052 struct reciprocal_value rn_ids;
0053 struct rcu_head rcu;
0054 u32 n_ids;
0055 u32 ids[];
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 struct vport {
0072 struct net_device *dev;
0073 netdevice_tracker dev_tracker;
0074 struct datapath *dp;
0075 struct vport_portids __rcu *upcall_portids;
0076 u16 port_no;
0077
0078 struct hlist_node hash_node;
0079 struct hlist_node dp_hash_node;
0080 const struct vport_ops *ops;
0081
0082 struct list_head detach_list;
0083 struct rcu_head rcu;
0084 };
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 struct vport_parms {
0097 const char *name;
0098 enum ovs_vport_type type;
0099 struct nlattr *options;
0100
0101
0102 struct datapath *dp;
0103 u16 port_no;
0104 struct nlattr *upcall_portids;
0105 };
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 struct vport_ops {
0124 enum ovs_vport_type type;
0125
0126
0127 struct vport *(*create)(const struct vport_parms *);
0128 void (*destroy)(struct vport *);
0129
0130 int (*set_options)(struct vport *, struct nlattr *);
0131 int (*get_options)(const struct vport *, struct sk_buff *);
0132
0133 netdev_tx_t (*send) (struct sk_buff *skb);
0134 struct module *owner;
0135 struct list_head list;
0136 };
0137
0138 struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,
0139 const struct vport_parms *);
0140 void ovs_vport_free(struct vport *);
0141
0142 #define VPORT_ALIGN 8
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 static inline void *vport_priv(const struct vport *vport)
0154 {
0155 return (u8 *)(uintptr_t)vport + ALIGN(sizeof(struct vport), VPORT_ALIGN);
0156 }
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 static inline struct vport *vport_from_priv(void *priv)
0169 {
0170 return (struct vport *)((u8 *)priv - ALIGN(sizeof(struct vport), VPORT_ALIGN));
0171 }
0172
0173 int ovs_vport_receive(struct vport *, struct sk_buff *,
0174 const struct ip_tunnel_info *);
0175
0176 static inline const char *ovs_vport_name(struct vport *vport)
0177 {
0178 return vport->dev->name;
0179 }
0180
0181 int __ovs_vport_ops_register(struct vport_ops *ops);
0182 #define ovs_vport_ops_register(ops) \
0183 ({ \
0184 (ops)->owner = THIS_MODULE; \
0185 __ovs_vport_ops_register(ops); \
0186 })
0187
0188 void ovs_vport_ops_unregister(struct vport_ops *ops);
0189 void ovs_vport_send(struct vport *vport, struct sk_buff *skb, u8 mac_proto);
0190
0191 #endif