Sk_buff sort notes (2. operation functions) and sk_buff Functions

Source: Internet
Author: User

Sk_buff sort notes (2. operation functions) and sk_buff Functions

Previous Article: sk_buff notes (I. Data Structure) This article focuses on some operation functions provided by the kernel for the sk_buff structure.

First, let's talk about the four pointers in sk_buff:

The four pointers are head, data, tail, and end. These four pointers point to the data zone, where the protocol header and data are stored. The head and end pointers are the same for each data packet. They are also used to determine the size of the Data zone. At the beginning, the head, data, and tail pointers all point together and are changed only when protocol data is added.

Let's talk about the formation of the next package, first the data at the application layer, then add the layer-4 TCP protocol header (assuming the TCP packet) to the layer-4, and then send it to the layer-3; when layer-3 is used, layer-4 data is treated as a load, and a layer-3 IP protocol header is added before the load to the layer-2. Then, a frame header is added to the layer-2 to send the data. Therefore, these pointers play a key role in packet formation. Next, let's take a look at the size of the four pointers pointing to the address, which is also helpful for understanding the following operational functions.


The last sentence means that when a data packet is in the second layer (that is, the data Pointer Points to the second layer protocol header), a method to get the third layer protocol header pointer is provided. Of course, you can also directly use the built-in function to obtain the three-layer protocol header pointer (in fact, the function is also implemented using the above Code), here only to show the increase of data, is moving down. This facilitates the understanding of the following functions.

2. Several functions that operate the sk_buff pointer:

First, let's take a look at the next three spaces to facilitate the understanding of the functions below. The first is: headroom, which is the space between skb-> head and skb-> data. The second is data, which is the space between skb-> data and skb-> tail; the third is: tailroom, which is the space between skb-> tail and skb-> end. For example:


Next, let's talk about the pointer functions in the four operations sk_buff structure: (a) skb_put (), (B) skb_push (), (c) skb_pull (), and (d) skb_reserve (); these four functions are crucial when data packets are transmitted between layers.

Important.

(A) skb_put (): The data zone space is extended backward, the headroom space remains unchanged, the tailroom space is reduced, skb-> data Pointer remains unchanged, and skb-> tail pointer is moved down;

(B) skb_push (): expands the data zone forward, reduces the headroom space, and changes the tailroom space. skb-> tail pointer remains unchanged, and skb-> data pointer moves up;
(C) skb_pull (): reduces the data zone space, increases the headroom space, and keeps the tailroom space. The skb-> data pointer moves down, And the skb-> tail pointer remains unchanged;

(D) skb_reserve (): The data zone remains unchanged, the headroom space increases, and the tailroom space decreases. skb-> data and skb-> tail move down simultaneously;

You can also analyze the source code. When you look at the source code, you will find that many functions have the same name. For example, the skb_push () function has two: static inline unsigned char * _ skb_push (struct sk_buff * skb, unsigned int len); and unsigned char * skb_push (struct sk_buff * skb, unsigned int len ); the first function is the implementation of specific content (key function). The second function only checks validity of the first function.

Third, other simple operation functions:

GET/set a series of functions such as the protocol header pointer, such as: get the IP header pointer, unsigned char * skb_network_header (const struct sk_buff * skb ); other functions (skb memory application, skb cloning and replication, and skb queue operations) will be analyzed in detail later.



Delphi binary operation functions

Function GetNum (value: integer; num: integer): integer;
Var
S1, s2: string;
M: integer;
Begin
S1: = inttostr (value );
M: = strtoint (s1 );
While m <> 0 do begin
If m = (m div 2) * 2 then
S2: = '0' + s2
Else
S2: = '1' + s2;
M: = m div 2;
End;
Result: = strtoint (copy (s2, num, 1 ));
End;

Q # What library function is I nclude <linux/skbuffh> ??

Skbuff. h is the header file of the Linux kernel. It has nothing to do with library functions.
The most important part of skbuff. h is the Linux kernel network subsystem (protocol stack) used to represent the data structure of data packets-struct sk_buff, also known as skb and its related functions. This data structure is basically the core of the Linux network subsystem.

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.