Linux Network protocol stack (d)--Link layer (2) __linux
Source: Internet
Author: User
2. Agreement related
2.1, the 3rd layer of the Protocol management
In the Linux kernel, there are 3-tier protocols for two different purposes:
(1) The Ptype_all Management protocol is used primarily for analysis purposes, and it receives all packets arriving at Layer 3rd protocol.
(2) Ptype_base manages the normal 3-layer protocol, receiving only packets with the correct protocol identifier, such as the 0x0800 of the Internet.
Notice the difference between the Sb_buff and the Net_device in several fields:
Sb_buff:
Unsigned short protocol
High-level protocols seen from the perspective of the two-tier device, typical protocols include Ip,ipv6 and ARP, complete with a list of include/linux/if_ether.h.
unsigned char Pkt_type
The type of frame, and possible values are defined in include/linux/if_packet.h.
Net_device:
unsigned short type
Device type (Ethernet, Frame Relay, etc.). There is a complete list of types in Include/linux/if_arp.h.
2.2. Protocol Processing function Registration
When the protocol is registered, the kernel invokes Dev_add_pack to add a corresponding PACKET_TYPE data structure:
Include/linux/netdevice.h
struct Packet_type {
unsigned short type; /* This is really htons (Ether_type). */
struct Net_device * DEV; /* NULL is wildcarded here/*
Int (* func) (struct Sk_buff *, struct net_device *,
struct Packet_type *);
void * AF_PACKET_PRIV;
struct List_head list;
};
Type: The protocol type, which can take some of the following values. Look at the types of protocols defined in If_ether.h:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.