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:

#define ETH_P_LOOP 0x0060/* Ethernet Loopback Packet * *
#define ETH_P_PUP 0x0200/* Xerox PUP Packet * *
#define ETH_P_PUPAT 0x0201/* Xerox PUP Addr Trans Packet * *
#define ETH_P_IP 0x0800/* Internet PROTOCOL Packet * *
#define ETH_P_X25 0x0805/* CCITT X.25 * *
#define ETH_P_ARP 0x0806/* Address Resolution Packet * *
#define ETH_P_BPQ 0x08ff/* G8BPQ ax.25 Ethernet Packet [not a officially registered ID] * *

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.