Why is the sk_buff-> protocol stored in network order?

Since the fields are sk_buffprocessed locally, it makes sense to store it in the host order. Fields like these sk_buff->vlan_tciare in host order. Is there any reason to store certain fields sk_buff->protocol, sk_buff->vlan_protoin the network / big endian format?

+4
source share
1 answer

According to http://vger.kernel.org/~davem/skb.html , the protocol sk_buffIS field is used by the network:

unsigned short        protocol,

"protocol" , "eth_type_trans()". "ETH_P_ *", "linux/if_ether.h". ethernet- ethernet, , . Ethernet , .

, skbuff.h , protocol :

340 /** 
341  *      struct sk_buff - socket buffer
369  *      @protocol: Packet protocol from driver
391  *      @vlan_proto: vlan encapsulation protocol
392  *      @vlan_tci: vlan tag control information

, protocol Ethernet- "TYPE" (ethertype, network endian) http://en.wikipedia.org/wiki/Ethernet_frame:

Ethernet . .     Ethertype (Ethernet II) 2

"".

vlan_proto - protocol ethernet, 0x8100, 802.1Q tagging (http://en.wikipedia.org/wiki/EtherType "VLAN-tagged frame (IEEE 802.1Q)" ). ( VLAN) protocol. , vlan_proto , / .

TCI ( vlan_tci) 802.1q, 2 (). vlan_untag() net/8021q/vlan_core.c:

118 struct sk_buff *vlan_untag(struct sk_buff *skb)
119 {
120         struct vlan_hdr *vhdr;
121         u16 vlan_tci;

135         vhdr = (struct vlan_hdr *) skb->data;
136         vlan_tci = ntohs(vhdr->h_vlan_TCI);
137         __vlan_hwaccel_put_tag(skb, skb->protocol, vlan_tci);

, TCI. TCI (3 ), DEI (1 ) VID (12 ). VLAN_TAG_PRESENT, vlan_tci, __vlan_hwaccel_put_tag

TCI , vlan_insert_tag() linux/if_vlan.h:

277  * Inserts the VLAN tag into @skb as part of the payload
278  * Returns a VLAN tagged skb. If a new skb is created, @skb is freed.

285 static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
286                                               __be16 vlan_proto, u16 vlan_tci)
287 {

300         /* first, the ethernet type */
301         veth->h_vlan_proto = vlan_proto;
302 
303         /* now, the TCI */
304         veth->h_vlan_TCI = htons(vlan_tci);
+4

Source: https://habr.com/ru/post/1539800/


All Articles