1 端口模块
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,
};
2 网桥模块
struct datapath { //网桥结构体
struct rcu_head rcu; //RCU调整延迟破坏
struct list_head list_node; //网桥hash链表元素,里面只有next和prev前驱后继指针
/* Flow table. */
struct flow_table __rcu *table; //哈希流表,里边包含了哈希桶的地址指针。该hash表受_rcu保护
/* Switch ports. */
struct hlist_head *ports; //一个网桥有多个端口,这些端口都是用哈希链表来链接的
/* Stats. */
struct dp_stats_percpu __percpu *stats_percpu;
#ifdef CONFIG_NET_NS
/* Network namespace ref. */
struct net *net;
#endif
};
3 流表模块flowstruct sw_flow_key { //隧道相关变量
struct ovs_key_ipv4_tunnel tun_key; /* Encapsulating tunnel key. */
struct { //包的优先级
u32 priority; /* Packet QoS priority. */
u32 skb_mark; /* SKB mark. */
u16 in_port; /* Input switch port (or DP_MAX_PORTS). */
} phy;
struct {
u8 src[ETH_ALEN]; /* Ethernet source address. */
u8 dst[ETH_ALEN]; /* Ethernet destination address. */
__be16 tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
__be16 type; /* Ethernet frame type. */
} eth;
struct {
u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */
u8 tos; /* IP ToS. */
u8 ttl; /* IP TTL/hop limit. */
u8 frag; /* One of OVS_FRAG_TYPE_*. */
} ip;
union {
struct {
struct {
__be32 src; /* IP source address. */
__be32 dst; /* IP destination address. */
} addr;
union {
struct {
__be16 src; /* TCP/UDP/SCTP source port. */
__be16 dst; /* TCP/UDP/SCTP destination port. */
} tp;
struct {
u8 sha[ETH_ALEN]; /* ARP source hardware address. */
u8 tha[ETH_ALEN]; /* ARP target hardware address. */
} arp;
};
} ipv4;
struct {
struct {
struct in6_addr src; /* IPv6 source address. */
struct in6_addr dst; /* IPv6 destination address. */
} addr;
__be32 label; /* IPv6 flow label. */
struct {
__be16 src; /* TCP/UDP/SCTP source port. */
__be16 dst; /* TCP/UDP/SCTP destination port. */
} tp;
struct {
struct in6_addr target; /* ND target address. */
u8 sll[ETH_ALEN]; /* ND source link layer address. */
u8 tll[ETH_ALEN]; /* ND target link layer address. */
} nd;
} ipv6;
};