1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef VPORT_H
20#define VPORT_H 1
21
22#include <linux/if_tunnel.h>
23#include <linux/list.h>
24#include <linux/netlink.h>
25#include <linux/openvswitch.h>
26#include <linux/reciprocal_div.h>
27#include <linux/skbuff.h>
28#include <linux/spinlock.h>
29#include <linux/u64_stats_sync.h>
30
31#include "datapath.h"
32
33struct vport;
34struct vport_parms;
35
36
37
38int ovs_vport_init(void);
39void ovs_vport_exit(void);
40
41struct vport *ovs_vport_add(const struct vport_parms *);
42void ovs_vport_del(struct vport *);
43
44struct vport *ovs_vport_locate(const struct net *net, const char *name);
45
46void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *);
47
48int ovs_vport_set_options(struct vport *, struct nlattr *options);
49int ovs_vport_get_options(const struct vport *, struct sk_buff *);
50
51int ovs_vport_set_upcall_portids(struct vport *, const struct nlattr *pids);
52int ovs_vport_get_upcall_portids(const struct vport *, struct sk_buff *);
53u32 ovs_vport_find_upcall_portid(const struct vport *, struct sk_buff *);
54
55
56
57
58
59
60
61
62
63
64struct vport_portids {
65 struct reciprocal_value rn_ids;
66 struct rcu_head rcu;
67 u32 n_ids;
68 u32 ids[];
69};
70
71
72
73
74
75
76
77
78
79
80
81
82
83struct vport {
84 struct net_device *dev;
85 struct datapath *dp;
86 struct vport_portids __rcu *upcall_portids;
87 u16 port_no;
88
89 struct hlist_node hash_node;
90 struct hlist_node dp_hash_node;
91 const struct vport_ops *ops;
92
93 struct list_head detach_list;
94 struct rcu_head rcu;
95};
96
97
98
99
100
101
102
103
104
105
106
107struct vport_parms {
108 const char *name;
109 enum ovs_vport_type type;
110 struct nlattr *options;
111
112
113 struct datapath *dp;
114 u16 port_no;
115 struct nlattr *upcall_portids;
116};
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134struct vport_ops {
135 enum ovs_vport_type type;
136
137
138 struct vport *(*create)(const struct vport_parms *);
139 void (*destroy)(struct vport *);
140
141 int (*set_options)(struct vport *, struct nlattr *);
142 int (*get_options)(const struct vport *, struct sk_buff *);
143
144 netdev_tx_t (*send) (struct sk_buff *skb);
145 struct module *owner;
146 struct list_head list;
147};
148
149struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,
150 const struct vport_parms *);
151void ovs_vport_free(struct vport *);
152
153#define VPORT_ALIGN 8
154
155
156
157
158
159
160
161
162
163
164static inline void *vport_priv(const struct vport *vport)
165{
166 return (u8 *)(uintptr_t)vport + ALIGN(sizeof(struct vport), VPORT_ALIGN);
167}
168
169
170
171
172
173
174
175
176
177
178
179static inline struct vport *vport_from_priv(void *priv)
180{
181 return (struct vport *)((u8 *)priv - ALIGN(sizeof(struct vport), VPORT_ALIGN));
182}
183
184int ovs_vport_receive(struct vport *, struct sk_buff *,
185 const struct ip_tunnel_info *);
186
187static inline const char *ovs_vport_name(struct vport *vport)
188{
189 return vport->dev->name;
190}
191
192int __ovs_vport_ops_register(struct vport_ops *ops);
193#define ovs_vport_ops_register(ops) \
194 ({ \
195 (ops)->owner = THIS_MODULE; \
196 __ovs_vport_ops_register(ops); \
197 })
198
199void ovs_vport_ops_unregister(struct vport_ops *ops);
200void ovs_vport_send(struct vport *vport, struct sk_buff *skb, u8 mac_proto);
201
202#endif
203