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的更多相关文章

  1. 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 ...

  2. TCP 接收窗口自动调节

    https://technet.microsoft.com/zh-cn/magazine/2007.01.cableguy.aspx 欢迎来到 TechNet 杂志“网络专家”的第一部分.TechNe ...

  3. 【Linux 内核网络协议栈源码剖析】网络栈主要结构介绍(socket、sock、sk_buff,etc)

    原文:http://blog.csdn.net/wenqian1991/article/details/46700177 通过前面的分析,可以发现,网络协议栈中的数据处理,都是基于各类结构体,所有有关 ...

  4. Linux 网卡驱动sk_buff内核源码随笔

    这几天在调试有关网卡驱动的东西,有很多地方不清楚.有关网卡驱动部分主要有两个很重要的结构体:struct net_device 和struct sk_buff. 驱动大部分都是围绕这两个东西进行操作的 ...

  5. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  6. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  7. [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  8. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

  9. sk_buff封装和解封装网络数据包的过程详解

    转自:http://www.2cto.com/os/201502/376226.html 可以说sk_buff结构体是Linux网络协议栈的核心中的核心,几乎所有的操作都是围绕sk_buff这个结构体 ...

随机推荐

  1. vue2 设置网页title的问题

    好东东,没个标题看着多难受 看到1文章  http://blog.csdn.net/qishuixian/article/details/72912368 推荐使用 vue-wechat-title插 ...

  2. neutron 多租户隔离的实现以及子网间路由的实现

    1.一个network相当于一个二层网络,使用vxlan 隧道连通所有的CNA节点. 2.一个VPC下有多个network,也就是会分配多个vxlan隧道,这些子网间的路由是通过DVR实现的.DVR就 ...

  3. github上传流程图记录

    参考文章 http://blog.csdn.net/laozitianxia/article/details/50682100 首先你得先创建仓库 为仓库取一个名字,然后点击创建就会有一个仓库了, g ...

  4. python 正则表达式中反斜杠(\)的麻烦和陷阱

    这里是一点小心得:由于下面两个原因,在正则表达式中使用反斜杠就会产生了一个双重转换的问题. (1).python自身处理字符串时,反斜杠是用于转义字符 (2).正则表达式也使用反斜杠来转义字符     ...

  5. css的定义、用法、注释、命名规则、书写规范

    什么是css: css全名是层叠样式表(Cascading Style Sheets) CSS的作用:给html标签添加"样式",样式定义了如何显示 HTML 元素 标签是可以由自 ...

  6. mysql之数据备份与恢复

    本文内容: 复制文件法 利用mysqldump 利用select into outfile 其它(列举但不介绍) 首发日期:2018-04-19 有些时候,在备份之前要先做flush tables , ...

  7. java面试整理(会持续更新..)

    本人出道至今,经历了大大小小百余场战斗,,,下面整理的面试题有些有答案,有些没答案,那个谁说过:"要抱着怀疑的态度去编程,所以,即便有答案,也不一定正确,即便我本地正确,但是由于屏幕前的你和 ...

  8. 轻量简单好用的C++JSON库CJsonObject

    1. JSON概述 JSON: JavaScript 对象表示法( JavaScript Object Notation) .是一种轻量级的数据交换格式. 它基于ECMAScript的一个子集.许多编 ...

  9. 在Xshell 6开NumLock时按小键盘上的数字键并不能输入数字

    小键盘问题 在Xshell 6上用vi的时候,开NumLock时按小键盘上的数字键并不能输入数字,而是出现一个字母然后换行(实际上是命令模式上对应上下左右的键).解决方法 选项Terminal-> ...

  10. Windows Server 2016-增强IPAM

    Windows Server 2016网络功能可能没有像Docker容器或Nano Server那样得到关注,但是管理员应该了解新的域名系统服务器和IP地址管理功能如何帮助他们获得对网络环境的更多控制 ...