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 流表模塊flow
struct 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;
};