OVS在处理每条流的时候,先根据每条流生产相应的key,然后根据key匹配相应的流表,根据流表中的action操作来处理每条流,本文对key的结构体进行分析,看看对于一条流会提出那些特征信息。对于key的描述在openvswitch源码中的flow.h文件中。
struct Sw_flow_key {U8 tun_opts[255]; U8 Tun_opts_len; struct Ip_tunnel_key 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). */} __packed PHY; /* Safe when right after ' Tun_key '. */U8 Mac_proto; /* MAC layer protocol (e.g. Ethernet). */U8 Tun_proto; /* Protocol of encapsulating Tunnel. */U32 Ovs_flow_hash; /* Datapath computed hash value. */U32 recirc_id; /* recirculation ID. */struct {U8 Src[eth_alen]; /* Ethernet Source address. */U8 Dst[eth_alen]; /* Ethernet Destination address. */struct Vlan_head VLAN; struct Vlan_head Cvlan; __BE16 type; /* Ethernet frame type. */} ETH; /* Filling a hole of bytes. */U8 Ct_state; U8 Ct_orig_proto; /* CT Original direction tuple IP * protocol. */Union {struct {__be32 top_lse;/* Top Label Stack entry */} MPLS; 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; }; U16 Ct_zone; /* Conntrack zone. */struct {__be16 src; /* TCP/UDP/SCTP Source port. */__BE16 DST; /* TCP/UDP/SCTP Destination port. */__BE16 flags; /* TCP flags. */} TP; Union {struct {struct {__be32 src;/* IP source address. */__BE32 DST; /* IP Destination address. */} addr; Union {struct {__be32 src; __BE32 DST; } Ct_orig; /* Conntrack original direction fields. */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. */Union {struct {struct in6_addr src; struct IN6_ADDR DST; } Ct_orig; /* Conntrack original direction fields. */struct {struct IN6_ADDR target;/* ND target address. */U8 Sll[e Th_alen]; /* ND Source link Layer address. */U8 Tll[eth_alen]; /* ND target link Layer address. */} nd; }; } IPv6; }; struct {/* Connection tracking fields NoT packed above. */struct {__be16 src;/* ct orig tuple tp src port. */__BE16 DST;/* CT orig tuple TP DST Port. */} ORIG_TP; U32 Mark; struct Ovs_key_ct_labels labels; } CT;};
struct ip_tunnel_key { __be64 tun_id; union { struct { __be32 src; __be32 dst; } ipv4; struct { struct in6_addr src; struct in6_addr dst; } ipv6; } u; __be16 tun_flags; u8 tos; /* TOS for IPv4, TC for IPv6 */ u8 ttl; /* TTL for IPv4, HL for IPv6 */ __be32 label; /* Flow Label for IPv6 */ __be16 tp_src; __be16 tp_dst;};
(39481745) [39481745]
Key parsing in the OvS