【正文】
of the packet by 2 bytes. Drivers should do this with: ? skb_reserve(NET_IP_ALIGN)。 spinlock_t lock。 Buffer Management COMS W6998 Spring 2022 Erich Nahum Outline ? Intro to socket buffers ? The sk_buff data structure ? APIs for creating, releasing, and duplicating socket buffers. ? APIs for manipulating parameters within the sk_buff structure ? APIs for managing the socket buffer queue. Socket Buffers (1) ? We need to manipulate packets through the stack ? This manipulation involves efficiently: ? Adding protocol headers/trailers down the stack. ? Removing protocol headers/trailers up the stack. ? Concatenating/separating data. ? Each protocol should have convenient access to header fields. ? To do all this the kernel provides the sk_buff structure. ? Created when an application passes data to a socket or when a packet arrives at the work adaptor (dev_alloc_skb() is invoked). ? Packet headers of each layer are ? Inserted in front of the payload on send ? Removed from front of payload on receive ? The packet is (hopefully) copied only twice: 1. Once from the user address space to the kernel address space via an explicit copy 2. Once when the packet is passed to or from the work adaptor (usually via DMA) Socket Buffers (2) Outline ? Intro to socket buffers ? The sk_buff data structure ? APIs for creating, releasing, and duplicating socket buffers. ? APIs for manipulating parameters within the sk_buff structure ? APIs for managing the socket buffer queue. next prev sk_buff transport_header work_header mac_header ...lots.. head data tail Packetdata dataref: 1 UDPData UDPHeader IPHeader MACHeader _device sk_buff sk_buff_head struct sock sk tstamp dev nr_frags ...of.. ...stuff.. end truesize users skb_shared_info ... destructor_arg ``headroom‘‘ ``tailroom‘‘ Structure of sk_buff head sk_buff data tail end tailroom Packet data size ... ... head = data = tail end = tail + size len = 0 sk_buff after alloc_skb(size) head sk_buff data tail end headroom Packet data len ... ... tailroom size data += len tail += len sk_buff after skb_reserve(len) head sk_buff data tail end headroom Packet