struct vport {
struct rcu_head rcu; //一种锁机制
struct datapath *dp; //网桥结构体指针,表示该端口属于哪个网桥的
u32 upcall_portid; //Netlink端口收到的数据包时使用的端口id
u16 port_no; //端口号,唯一标识该端口
// 因为一个网桥上有多个端口,而这些端口都是用哈希链表来存储的。
//所以这些是链表元素(里边没有数据,只有next和prev前驱后继指针,数据部分就是vport结构体中的其他成员)
struct hlist_node hash_node;
struct hlist_node dp_hash_node; //网桥的hash链表元素
const struct vport_ops *ops; //这是端口结构体的操作函数指针结构体,结构体里边存放了很多操作函数的函数指针
struct pcpu_tstats __percpu *percpu_stats; //vport 只想每个cpu的统计数据使用和维护
spinlock_t stats_lock; //自旋锁,防止异步操作,保护下面的两个成员
struct vport_err_stats err_stats; //错误状态支出错误vport使用和维护的统计数字
struct ovs_vport_stats offset_stats; //添加到实际统计数据,部分原因是为了兼容
};
/**
* struct vport_parms - parameters for creating a new vport
*
* @name: New vport's name.
* @type: New vport's type.
* @options: %OVS_VPORT_ATTR_OPTIONS attribute from Netlink message, %NULL if
* none was supplied.
* @dp: New vport's datapath.
* @port_no: New vport's port number.
*/
struct vport_parms { //端口参数,当创建一个新的vport端口时要传入的参数
const char *name; //新端口的名字
enum ovs_vport_type type; //新端口的类型,类型不止一种,所以使用枚举型
struct nlattr *options;
/* For ovs_vport_alloc(). */
struct datapath *dp; //新的端口是属于哪个网桥的
u16 port_no; //新端口的端口号
u32 upcall_portid; //和Netlink通信时使用的端口id
};
/**
* struct vport_ops - definition of a type of virtual port
*
* @type: %OVS_VPORT_TYPE_* value for this type of virtual port.
* @create: Create a new vport configured as specified. On success returns
* a new vport allocated with ovs_vport_alloc(), otherwise an ERR_PTR() value.
* @destroy: Destroys a vport. Must call vport_free() on the vport but not
* before an RCU grace period has elapsed.
* @set_options: Modify the configuration of an existing vport. May be %NULL
* if modification is not supported.
* @get_options: Appends vport-specific attributes for the configuration of an
* existing vport to a &struct sk_buff. May be %NULL for a vport that does not
* have any configuration.
* @get_name: Get the device's name.
* @send: Send a packet on the device. Returns the length of the packet sent,
* zero for dropped packets or negative for error.
*/
//这是端口vport操作函数的函数指针结构体,是操作函数的集合,里面存放了所有有关vport操作函数的函数指针
struct vport_ops {
enum ovs_vport_type type; //端口的类型
/* Called with ovs_mutex. */
struct vport *(*create)(const struct vport_parms *); //根据指定的参数配置创建一个新的vport,成功返回新端口指针
void (*destroy)(struct vport *); //销毁端口函数
int (*set_options)(struct vport *, struct nlattr *); //得到和设置option成员函数
int (*get_options)(const struct vport *, struct sk_buff *);
/* Called with rcu_read_lock or ovs_mutex. */
const char *(*get_name)(const struct vport *);
int (*send)(struct vport *, struct sk_buff *);
};
// 端口vport的类型枚举类型存储
enum vport_err_type {
VPORT_E_RX_DROPPED,
VPORT_E_RX_ERROR,
VPORT_E_TX_DROPPED,
VPORT_E_TX_ERROR,
};