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