sk_buff Structure
The structure has changed many times in the history of the kernel,both to add new options and to reorganize existing fields into a cleaner layout.Its fields can be classified roughly into the following categories:
- Layout
- General
- Feature-specific
- Management functions
Layout Fields
Interesting fields of sk_buff:
- struct sock *sk:This is a pointer to a sock data structure of the socket that owns this buffer.
- unsigned int len:This is the size of the block of data in the buffer.This length include both the data in the main buffer and the data in the fragments.
- unsigned int data_len:Unlike len,data_len accounts only for the size of the data in the fragments.
- unsigned int mac_len:This is the size of the MAC header
- atomic_t users:This is the reference count.
- unsigned int truesize:This field represent the total size of the buffer,including the sk_buff structure itself.
- unsigned char head,end,data,tail:head and end point to the beginning and end of the space allocated to the buffer,and data and tail point to the beginning and end of the actual data.
General Fields
- struct timeval stamp:This is usually meaningful only for a received packet.It is a timestamp that represents when a packet was received or when one is scheduled for transmission.
- struce net_device * dev:describes a network device.
- struct dst_entry dst:This is used by the routing subsystem.
- char cb[40]:This is a "control buffer",or storage for private information,maintained by each layer for internal use
- unsigned char clone:indicates that this structure is a clone of another sk_buff buffer.
- unsigned char pkt_type:This field classifies the type of frame based on its L2 destination address.
- unsigned short protocol:This is the protocol used at the next-higher layer from the perspective of the device driver at L2.
Feature-Specific Fields
The Linux kernel is modular.allowing you to select what to include and waht to leave out.Thus some fields are included in the sk_buff data structure only if the kernel is compiled with support for particular features such as firewalling or QoS
- struct nf_conntrack *nfct
- struct nf_bridge_info *nf_bridge;
- u8 nfctinfo
u8 nf_trace
These parameters are used by Netfilter
- u16 tc_index
u16 tc_verd
These parameters are used by the Traffic Control
struct sec_path *sp
This is used by the IPsec protocol suite to keep track of transformations
Management Functions
Before and After:(a)skb_put,(b)skb_push,(c)skb_pull,(d)skb_reserve
Allocating memory:alloc_skb and dev_alloc_skb
creating a single buffer involves two allocations of memory(one for the buffer and one for the sk_buff struct)
The skb_shared_info structure and the skb_shinfo function
skb_shared_info at the end of the data buffer that keeps additional information about the data block(Fragment).
Note that there is no field inside sk_buff structure pointing at the skb_shared_info data structure.To access that structure,functions need to use the skb_shinfo macro,which simply returns the end pointer.
List management functions
skb_queue_head_init: initializes an sk_buff_head with an empty queue of elements.
skb_queue_head,skb_queue_tail:Adds one buffer to the head or to the tail of a queue,respectively
skb_dequeue,skb_dequeue_tail:Dequeues an element from the head or from the tail.
skb_queue_purge:Empties a queue.
skb_queue_walk:Runs a loop on each element of a queue in turn.
sk_buff Structure的更多相关文章
- the Linux Kernel: Traffic Control, Shaping and QoS
−Table of Contents Journey to the Center of the Linux Kernel: Traffic Control, Shaping and QoS 1 Int ...
- TCP 接收窗口自动调节
https://technet.microsoft.com/zh-cn/magazine/2007.01.cableguy.aspx 欢迎来到 TechNet 杂志“网络专家”的第一部分.TechNe ...
- 【Linux 内核网络协议栈源码剖析】网络栈主要结构介绍(socket、sock、sk_buff,etc)
原文:http://blog.csdn.net/wenqian1991/article/details/46700177 通过前面的分析,可以发现,网络协议栈中的数据处理,都是基于各类结构体,所有有关 ...
- Linux 网卡驱动sk_buff内核源码随笔
这几天在调试有关网卡驱动的东西,有很多地方不清楚.有关网卡驱动部分主要有两个很重要的结构体:struct net_device 和struct sk_buff. 驱动大部分都是围绕这两个东西进行操作的 ...
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- Theano Graph Structure
Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...
- sk_buff封装和解封装网络数据包的过程详解
转自:http://www.2cto.com/os/201502/376226.html 可以说sk_buff结构体是Linux网络协议栈的核心中的核心,几乎所有的操作都是围绕sk_buff这个结构体 ...
随机推荐
- nginx中有关 root 和 alias的主要区别
举个例子给伙伴们区别就明显看出来了,例子如下: location /img/ { alias /var/www/image/; }注意:如果按照上述配置的话,则访问/img/目录里面的文件时,ning ...
- 浅谈Android 混淆和加固
混淆: 针对项目代码,代码混淆通常将代码中的各种元素(变量.函数.类名等)改为无意义的名字,使得阅读的人无法通过名称猜测其用途,增大反编译者的理解难度. 虽然代码混淆可以提高反编译的门槛,但是对开发者 ...
- Android 进度条按钮实现(ProgressButton)
有些App在点击下载按钮的时候,可以在按钮上显示进度,我们可以通过继承原生Button,重写onDraw来实现带进度条的按钮. Github:https://github.com/imcloudflo ...
- springboot 学习之路 7(静态页面自动生效问题)
目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...
- (python)数据结构---元组
一.描述 一个有序的元素组成的集合 元组是不可变的线性数据结构 二.元组的相关操作 1.元组元素的访问 索引不可超界,否则抛异常IndexError 支持正负索引 t = (2, 3) print(t ...
- mssql sqlserver SQL 位运算举例权限应用
摘要: 下文通过举例的方式讲述sqlserver中位运算的相关知识,如下所示: 实验环境:sqlserver 2008 R2 在sqlserver的权限设置,我们通常使用1.2.4.8.16.32.6 ...
- linux c 开发通用结构,框架
转自:http://www.maomao365.com/?p=673 了解其它语言的框架例:java Struts1.Struts2.Hibernate.Mybatis.Ibatis.Spring 等 ...
- 一、Tableau基础
有关函数的官方文档:https://onlinehelp.tableau.com/current/pro/desktop/zh-cn/functions_functions_string.htm 注意 ...
- python发展史
一:Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum)(龟叔).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹 打发时间,决心开发一个新的脚本解释程序, ...
- Linux 小知识翻译 - 「/proc 文件夹」
这次聊聊 「/proc 文件夹」. /proc 文件夹用来保管系统状态相关的文件的特殊文件夹,这个文件夹中有的文件只是内存上的虚拟文件. /proc 文件夹下有些文件可以反映各个进程的运行状态.所以说 ...