Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2007-2012 Nicira, Inc.
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 /* The following definitions are for users of the vport subsystem: */
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  * struct vport_portids - array of netlink portids of a vport.
0044  *                        must be protected by rcu.
0045  * @rn_ids: The reciprocal value of @n_ids.
0046  * @rcu: RCU callback head for deferred destruction.
0047  * @n_ids: Size of @ids array.
0048  * @ids: Array storing the Netlink socket pids to be used for packets received
0049  * on this port that miss the flow table.
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  * struct vport - one port within a datapath
0060  * @dev: Pointer to net_device.
0061  * @dev_tracker: refcount tracker for @dev reference
0062  * @dp: Datapath to which this port belongs.
0063  * @upcall_portids: RCU protected 'struct vport_portids'.
0064  * @port_no: Index into @dp's @ports array.
0065  * @hash_node: Element in @dev_table hash table in vport.c.
0066  * @dp_hash_node: Element in @datapath->ports hash table in datapath.c.
0067  * @ops: Class structure.
0068  * @detach_list: list used for detaching vport in net-exit call.
0069  * @rcu: RCU callback head for deferred destruction.
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  * struct vport_parms - parameters for creating a new vport
0088  *
0089  * @name: New vport's name.
0090  * @type: New vport's type.
0091  * @options: %OVS_VPORT_ATTR_OPTIONS attribute from Netlink message, %NULL if
0092  * none was supplied.
0093  * @dp: New vport's datapath.
0094  * @port_no: New vport's port number.
0095  */
0096 struct vport_parms {
0097     const char *name;
0098     enum ovs_vport_type type;
0099     struct nlattr *options;
0100 
0101     /* For ovs_vport_alloc(). */
0102     struct datapath *dp;
0103     u16 port_no;
0104     struct nlattr *upcall_portids;
0105 };
0106 
0107 /**
0108  * struct vport_ops - definition of a type of virtual port
0109  *
0110  * @type: %OVS_VPORT_TYPE_* value for this type of virtual port.
0111  * @create: Create a new vport configured as specified.  On success returns
0112  * a new vport allocated with ovs_vport_alloc(), otherwise an ERR_PTR() value.
0113  * @destroy: Destroys a vport.  Must call vport_free() on the vport but not
0114  * before an RCU grace period has elapsed.
0115  * @set_options: Modify the configuration of an existing vport.  May be %NULL
0116  * if modification is not supported.
0117  * @get_options: Appends vport-specific attributes for the configuration of an
0118  * existing vport to a &struct sk_buff.  May be %NULL for a vport that does not
0119  * have any configuration.
0120  * @send: Send a packet on the device.
0121  * zero for dropped packets or negative for error.
0122  */
0123 struct vport_ops {
0124     enum ovs_vport_type type;
0125 
0126     /* Called with ovs_mutex. */
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  *  vport_priv - access private data area of vport
0146  *
0147  * @vport: vport to access
0148  *
0149  * If a nonzero size was passed in priv_size of vport_alloc() a private data
0150  * area was allocated on creation.  This allows that area to be accessed and
0151  * used for any purpose needed by the vport implementer.
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  *  vport_from_priv - lookup vport from private data pointer
0160  *
0161  * @priv: Start of private data area.
0162  *
0163  * It is sometimes useful to translate from a pointer to the private data
0164  * area to the vport, such as in the case where the private data pointer is
0165  * the result of a hash table lookup.  @priv must point to the start of the
0166  * private data area.
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 /* vport.h */