SKB - Linux Network Buffers

xiaoxiao2021-03-06  67

SKB - Linux Network Buffers

HARALD WELTE LAFORGE@gnumonks.org1.3, 2000/10/14 21:27:02

Short Description About The Linux Network Buffers (SKB's)

INTRODUCTION

At the time I wanted to know more about the Linux network stack, I always wanted a document like this to exist. But unfortunately I never found one. After I gained some basic knowledge about the Linux network stack internals, I wrote one.

I'm happy if this document is of any use for other people................

Please Let Me Know of any bugs in this document. It Should Reemble Kernel Revision 2.4.0-Test4

2. SKBUFF's

skbuffs are the buffers in which the linux kernel handles network packets. The packet is received by the network card, put into a skbuff and then passed to the network stack, which uses the skbuff all the time.

2.1 Struct SK_Buff

The struct SK_Buff Is Defined in As Follows:

NEXT

Next buffer in list

Prev

Previous Buffer in List

List

List we are on

SK

Socket We belong to

Stamp

TimeVal We Arrived AT

DEV

Device we are leaving by

RX_DEV

Device we arrived at

hide

TRANSPORT LAYER Header (TCP, UDP, ICMP, IGMP, SPX, RAW)

NH

NetWork Layer Header (IP, IPv6, ARP, IPX, RAW)

Mac

Link Layer HEADER

DST

FIXME:

CB

Control Buffer, Used INTERNALLY

Len

Length of actual data

CSum

CHECKSUM

Used

FIXME: Data Moved to User and Not MSG_PEEK

IS_clone

WE Are A Clone

cloned

Head May Be Cloned

PKT_TYPE

Packet class

IP_SUMMED

Driver Fed US IP CHECKSUM

Priority

Packet queuing priority

Users

User count

Protocol

Packet Protocol from Driver

Security

Security level of packet

TrueSize

Real size of the buffer

HEAD

Pointer to Head of buffer

Data

Data Head Pointer

TAIL

Tail pointerend

END POINTER

Destructor

Destructor function

NFMark

Netfilter Mark

NFCache

Netfilter Internal Caching Info

NFCT

Associated Connection, IF ANY

Tc_index

Traffic Control Index

2.2 SKB Support Functions

There Are A Bunch of Skb Support Functions Provided by The Sk_Buff Layer. I Briefly Describe The Most Important Ones in this section.

Allocation / Free / Copy / Clone and Expansion Functions

Struct SK_Buff * Alloc_skb (unsigned int size, int GFP_mask)

This Function Allocates A New Skb. This is provided by The Skb Layer To Initialize Some Privat Data And Do Memory Statistics. The Returned Buffer Has No Headroom and A Tailroom OF / SIZE / BYTES.

Void kfree_skb (struct SK_Buff * SKB)

Decrement the skb's usage count by one and free the skb if no references.

Struct SK_Buff * SKB_GET (STRUCT SK_BUFF * SKB)

Increments the SKB'S USAGE Count by One and Returns a Pointer To IT.

STRUCT SK_BUFF * SKB_CLONE (Struct SK_Buff * SKB, INT GFP_MASK)

This Function Clones A SKB. Both Copies Share The Packet Data But Have Their OWN STRUCT SK_BUF. The New Copy IS NOT OWNED by Any Socket, Reference Count Is 1.

STRUCT SK_BUFF * SKB_COPY (const struct SK_Buff * SKB, INT GFP_MASK)

Makes A Real Copy of the SKB, INCLUDING PACKET DATA. This is needed, if you wish to modify the packet data. Reference Count of the New SKB IS 1.

STRUCT SKB_COPY_EXPAND (Const Struct SK_Buff * SKB, INT New_HEADROOM, INT New_TAILROOM, INT GFP_MASK)

Make a Copy of the SKB, Including Packet Data. Additional The New Skb Has A Haedroom of / New_Headroom / Bytes Size and a Tailroom OF / New_TAILROOM / BYTES.

Anciliary Functions

INT SKB_CLONED (STRUCT SK_BUFF * SKB)

Is the SKB A Clone?

INT SKB_SHARED (STRUCT SK_BUFF * SKB)

Is this SKB Shared? (Is The Reference Count> 1)? Operations on Lists of Skb's

Struct SK_Buff * SKB_PEEK (STRUCT SK_BUFF_HEAD * LIST_)

Peek a SKB from Front of the List; Does Not Remove Skb from the list

Struct SK_Buff * SKB_PEEK_TAIL (Struct Sk_buff_head * list_)

Peek A SKB from Tail of The List; Does Not Remove Sk from the list

__U32 SKB_QUEUE_LEN (SK_BUFF_HEAD * LIST_)

Return the length of the given SKB LIST

Void SKB_QUEUE_HEAD (STRUCT SK_BUFF_HEAD * LIST_, STRUCT SK_BUFF * Newsk)

Enqueue a SKB At the Head of a Given List

Void SKB_QUE_TAIL (STRUCT SK_BUFF_HEAD * LIST_, STRUCT SK_BUFF * Newsk)

ENQUEUE A SKB AT The End of a Given List.

STRUCT SK_BUFF * SKB_DEQUEUE (struct SK_BUFF_HEAD * LIST_)

DEQUEUE A SKB from from the head of the given list.

Struct SK_BUFF * SBK_DEQUE_TAIL (STRUCT SK_BUFF_HEAD * LIST_)

Dequeue a SKB from the Tail of the Given List

Operations on SKB DATA

Unsigned char * SKB_PUT (Struct Sk_buff * SBK, INT LEN)

Extends The Data Area of ​​The Skb. If The Total Size Exceeds The Size of The SKB, The Kernel Will Panic. a Pointer To The First Byte Of New Data is Returned.

Unsigned char * SKB_PUSH (Struct Sk_buff * SKB, INT LEN)

Extends The Data Area of ​​The Skb. If The Total Size Exceeds The Size of The SKB, The Kernel Will Panic. a Pointer To The First Byte Of New Data is Returned.

Unsigned char * SKB_PULL (Struct Sk_buff * SKB, INT LEN)

Remove Data from The Start of a buffer, return the bytes to headroom. a PointR to the next data in the buffer is returned.

INT SKB_HEADROOM (Struct SK_Buff * SKB)

Return the Amount of Bytes of Free Space At the Head of SKB

INT SKB_TAILROOM (Struct Sk_buff * SKB)

Return The Amount of Bytes of Free Space At the end of skb

Struct SK_Buff * SKB_COW (Struct SK_Buff * SKB, INT Headroom If The Buffer Passed Lacks Sufficient Headroom Or Is A Clone It is Copied and Additional Headroom Made Available.

转载请注明原文地址:https://www.9cbs.com/read-110013.html

New Post(0)