Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vport.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2012 Nicira, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 2 of the GNU General Public
6  * License as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA
17  */
18 
19 #ifndef VPORT_H
20 #define VPORT_H 1
21 
22 #include <linux/list.h>
23 #include <linux/netlink.h>
24 #include <linux/openvswitch.h>
25 #include <linux/skbuff.h>
26 #include <linux/spinlock.h>
27 #include <linux/u64_stats_sync.h>
28 
29 #include "datapath.h"
30 
31 struct vport;
32 struct vport_parms;
33 
34 /* The following definitions are for users of the vport subsytem: */
35 
36 int ovs_vport_init(void);
37 void ovs_vport_exit(void);
38 
39 struct vport *ovs_vport_add(const struct vport_parms *);
40 void ovs_vport_del(struct vport *);
41 
42 struct vport *ovs_vport_locate(struct net *net, const char *name);
43 
44 void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *);
45 
46 int ovs_vport_set_options(struct vport *, struct nlattr *options);
47 int ovs_vport_get_options(const struct vport *, struct sk_buff *);
48 
49 int ovs_vport_send(struct vport *, struct sk_buff *);
50 
51 /* The following definitions are for implementers of vport devices: */
52 
59 };
60 
66 };
67 
82 struct vport {
83  struct rcu_head rcu;
85  struct datapath *dp;
87 
90  const struct vport_ops *ops;
91 
93 
96 };
97 
108 struct vport_parms {
109  const char *name;
111  struct nlattr *options;
112 
113  /* For ovs_vport_alloc(). */
114  struct datapath *dp;
117 };
118 
138 struct vport_ops {
140 
141  /* Called with RTNL lock. */
142  struct vport *(*create)(const struct vport_parms *);
143  void (*destroy)(struct vport *);
144 
145  int (*set_options)(struct vport *, struct nlattr *);
146  int (*get_options)(const struct vport *, struct sk_buff *);
147 
148  /* Called with rcu_read_lock or RTNL lock. */
149  const char *(*get_name)(const struct vport *);
150  void (*get_config)(const struct vport *, void *);
151  int (*get_ifindex)(const struct vport *);
152 
153  int (*send)(struct vport *, struct sk_buff *);
154 };
155 
161 };
162 
163 struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,
164  const struct vport_parms *);
165 void ovs_vport_free(struct vport *);
166 
167 #define VPORT_ALIGN 8
168 
178 static inline void *vport_priv(const struct vport *vport)
179 {
180  return (u8 *)vport + ALIGN(sizeof(struct vport), VPORT_ALIGN);
181 }
182 
193 static inline struct vport *vport_from_priv(const void *priv)
194 {
195  return (struct vport *)(priv - ALIGN(sizeof(struct vport), VPORT_ALIGN));
196 }
197 
198 void ovs_vport_receive(struct vport *, struct sk_buff *);
199 void ovs_vport_record_error(struct vport *, enum vport_err_type err_type);
200 
201 /* List of statically compiled vport implementations. Don't forget to also
202  * add yours to the list at the top of vport.c. */
203 extern const struct vport_ops ovs_netdev_vport_ops;
204 extern const struct vport_ops ovs_internal_vport_ops;
205 
206 #endif /* vport.h */