Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

skbuff: add a basic intro doc

Add basic skb documentation. It's mostly an intro to the subsequent
patches - it would looks strange if we documented advanced topics
without covering the basics in any way.

Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+65
+25
Documentation/networking/skbuff.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + struct sk_buff 4 + ============== 5 + 6 + :c:type:`sk_buff` is the main networking structure representing 7 + a packet. 8 + 9 + Basic sk_buff geometry 10 + ---------------------- 11 + 12 + .. kernel-doc:: include/linux/skbuff.h 13 + :doc: Basic sk_buff geometry 14 + 15 + Shared skbs and skb clones 16 + -------------------------- 17 + 18 + :c:member:`sk_buff.users` is a simple refcount allowing multiple entities 19 + to keep a struct sk_buff alive. skbs with a ``sk_buff.users != 1`` are referred 20 + to as shared skbs (see skb_shared()). 21 + 22 + skb_clone() allows for fast duplication of skbs. None of the data buffers 23 + get copied, but caller gets a new metadata struct (struct sk_buff). 24 + &skb_shared_info.refcount indicates the number of skbs pointing at the same 25 + packet data (i.e. clones).
+40
include/linux/skbuff.h
··· 801 801 #endif 802 802 803 803 /** 804 + * DOC: Basic sk_buff geometry 805 + * 806 + * struct sk_buff itself is a metadata structure and does not hold any packet 807 + * data. All the data is held in associated buffers. 808 + * 809 + * &sk_buff.head points to the main "head" buffer. The head buffer is divided 810 + * into two parts: 811 + * 812 + * - data buffer, containing headers and sometimes payload; 813 + * this is the part of the skb operated on by the common helpers 814 + * such as skb_put() or skb_pull(); 815 + * - shared info (struct skb_shared_info) which holds an array of pointers 816 + * to read-only data in the (page, offset, length) format. 817 + * 818 + * Optionally &skb_shared_info.frag_list may point to another skb. 819 + * 820 + * Basic diagram may look like this:: 821 + * 822 + * --------------- 823 + * | sk_buff | 824 + * --------------- 825 + * ,--------------------------- + head 826 + * / ,----------------- + data 827 + * / / ,----------- + tail 828 + * | | | , + end 829 + * | | | | 830 + * v v v v 831 + * ----------------------------------------------- 832 + * | headroom | data | tailroom | skb_shared_info | 833 + * ----------------------------------------------- 834 + * + [page frag] 835 + * + [page frag] 836 + * + [page frag] 837 + * + [page frag] --------- 838 + * + frag_list --> | sk_buff | 839 + * --------- 840 + * 841 + */ 842 + 843 + /** 804 844 * struct sk_buff - socket buffer 805 845 * @next: Next buffer in list 806 846 * @prev: Previous buffer in list