SlideShare uma empresa Scribd logo
1 de 28
Creating a socket from user space is done by the socket()
system call:
int socket (int family, int type, int protocol);
On success, a file descriptor for the new socket is returned.
For open() system call (for files), we also get a file descriptor as
the return value.
Socket
Essentially, a socket is an abstraction for network communication, just
as a file is an abstraction for file system communication. Let’s consider
the basic network I/O functions for a Linux system. In general, an
application that performs net- work input and output needs to perform
the five basic functions described in open, close, read, write, and
control.
A family is a suite of protocols
Each family is a subdirectory of linux/net
E.g., linux/net/ipv4, linux/net/decnet, linux/net/packet
IPv4: PF_INET
IPv6: PF_INET6.
Packet sockets: PF_PACKET
Operate at the device driver layer.
pcap library for Linux uses PF_PACKET sockets
pcap library is in use by sniffers such as tcpdump.
Protocol Family == Address Family
PF_INET == AF_INET (in /include/linux/socket.h)
Socket(): Family
 SOCK_STREAM and SOCK_DGRAM are
the mostly used types.
 SOCK_STREAM for TCP, SCTP
 SOCK_DGRAM for UDP.
 SOCK_RAW for RAW sockets.
 There are cases where protocol can be either
SOCK_STREAM or SOCK_DGRAM; for
example, Unix domain socket (AF_UNIX).
Socket(): Type
Protocol is protocol number within a family.
Internet protocols are assigned by IANA
(Internet Assigned Number Authority)
http://www.iana.org/assignments/protocol-numbers/
For IPPROTO_TCP, it’s usually 0.
IPPROTO_TCP is 0, see: include/linux/in.h.
For SCTP:
protocol is IPPROTO_SCTP (132)
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
For UDP-Lite:
protocol is IPPROTO_UDPLITE (136)
Socket(): Protocol
/* Supported address families. */
#define AF_UNSPEC 0
#define AF_UNIX 1 /* Unix domain sockets */
#define AF_LOCAL 1 /* POSIX name for AF_UNIX */
#define AF_INET 2 /* Internet IP Protocol */
#define AF_AX25 3 /* Amateur Radio AX.25 */
#define AF_IPX 4 /* Novell IPX */
#define AF_APPLETALK 5 /* AppleTalk DDP */
#define AF_NETROM 6 /* Amateur Radio NET/ROM */
#define AF_BRIDGE 7 /* Multiprotocol bridge */
#define AF_ATMPVC 8 /* ATM PVCs */
#define AF_X25 9 /* Reserved for X.25 project */
#define AF_INET6 10 /* IP version 6 */
#define AF_ROSE 11 /* Amateur Radio X.25 PLP */
#define AF_DECnet 12 /* Reserved for DECnet project */
#define AF_NETBEUI 13 /* Reserved for 802.2LLC project*/
#define AF_SECURITY 14 /* Security callback pseudo AF */
#define AF_KEY 15 /* PF_KEY key management API */
..
#define AF_ISDN 34 /* mISDN sockets */
#define AF_PHONET 35 /* Phonet sockets */
#define AF_IEEE802154 36 /* IEEE802154 sockets */
#define AF_MAX 37 /* For now.. */
Address/Protocol Families
For every socket which is created by a user space application, there is a
corresponding struct socket and struct sock in the kernel.
struct socket: include/linux/net.h
Data common to the socket layer
Has only 8 members
Any variable “sock” always refers to a struct socket
struct sock : include/net/sock.h
Data common to the Network Protocol layer (i.e., AF_INET)
has more than 30 members, and is one of the biggest structures in the
networking stack.
Any variable “sk” always refers to a struct sock.
Socket Data Structures
socket()
bind()
listen()
accept()
read()
write()
close()
socket()
bind()
connect()
write()
read()
close()
The ‘server’ application
3-way handshake
data flow to server
data flow to client
4-way handshake
Diagram
CLIENT application
Socket Layer
User
Kernel
UDP
Hardware
Application
Ethernet
PF_INET
TCP
Network Device Layer
IPV4
SOCK_
STREAM
SOCK_
DGRAM SOCK
_RAW
PF_PACKET
SOCK
_RAW
SOCK_
DGRAM
PF_UNIX PF_IPX
….
….
Socket
Interface
Protocol
Layers
Token Ring PPP SLIP FDDI
Device
Layer
Socket Layer Architecture
In Linux, the three different
data structures each have the letters "sock" in them. The first is the socket buffer
defined in linux/include/linux/sk_buff.h. Socket buffers are structures to hold
packet data.
struct sk_buff *skb;:
In the Linux source code, socket buffers are often referred to by the variable skb.
struct socket *sock; :
The socket structure is the general structure that holds control and states
information for the socket layer.
struct sock *sk; :
It is a more complex structure used to keep state information about open
connections. It is accessed throughout the TCP/IP protocol but mostly within the
TCP protocol. It is usually referenced through a variable called sk.
SK_BUFFSK_BUFF
The Socket Buffer: sk_buff Structure
Most important data structure in the Linux networking code,
representing the headers for data that has been received or is
about to be transmit- ted. Defined in the <include/linux/skbuff.h>
include file.
struct sk_buff {
/* These two members must be first. */
struct sk_buff *next; //next buffer in list
struct sk_buff *prev; //previous buffer in list
struct sk_buff_head *list; //list we are on
struct sock *sk; //socket we belong to
struct timeval stamp; //timeval we arrived at
struct net_device *dev; //device we are leaving by
struct net_device *input_dev; //device we arrived at
struct net_device *real_dev;
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.
union {
struct tcphdr *th;
struct udphdr *uh;
struct icmphdr *icmph;
struct igmphdr *igmph;
struct iphdr *ipiph;
struct ipv6hdr*ipv6h;
unsigned char *raw;
} h; //transport layer header (tcp,udp,icmp,igmp,spx,raw)
union {
struct iphdr *iph;
struct ipv6hdr*ipv6h;
struct arphdr *arph;
unsigned char *raw;
} nh; //network layer header (ip,ipv6,arp,ipx,raw)
union {
unsigned char *raw;
} mac; //link layer header
struct dst_entry *dst;
struct sec_path *sp;
//FIXME:
char cb[40];
unsigned int len,
data_len,
mac_len,
csum;
unsigned char local_df,
cloned,
pkt_type,
ip_summed;
__u32 priority;
unsigned short protocol,
security;
void (*destructor)(struct sk_buff *skb);
#ifdef CONFIG_NETFILTER
unsigned long nfmark;
__u32 nfcache;
__u32 nfctinfo;
struct nf_conntrack *nfct;
//control buffer, used internally
// Length of actual data
//checksum
//head may be cloned
//packet class
//driver fed us ip checksum
//packet queuing priority
//packet protocol from driver
// security level of packet
//destructor function
#ifdef CONFIG_NETFILTER_DEBUG
unsigned int nf_debug;
#endif
#ifdef CONFIG_BRIDGE_NETFILTER
struct nf_bridge_info *nf_bridge;
#endif
#endif /* CONFIG_NETFILTER */
#if defined(CONFIG_HIPPI)
union {
__u32 ifield;
} private;
#endif
#ifdef CONFIG_NET_SCHED
__u32 tc_index; /* traffic control index */
#ifdef CONFIG_NET_CLS_ACT
__u32 tc_verd; /* traffic control verdict */
__u32 tc_classid; /* traffic control classid */
#endif
#endif
/* These elements must be at the end, see alloc_skb() for details.
*/
unsigned int truesize; //real size of the buffer
atomic_t users; //user count
unsigned char *head, // pointer to head of buffer
*data, //data head pointer
*tail, //tail pointer
*end; //end pointer
};
End of sk_buff structure
This one is tied together by next and prev fields in each sk_buff structure, the next field
pointing forward and the prev field pointing back-ward. But this list has another
requirement: each sk_buff structure must be able tofind the head of the whole list quickly.
To implement this requirement, an extrastructure of type sk_buff_head is inserted at the
beginning of the list, as a kind of dummy element. The sk_buff_head structure is:
struct sk_buff_head {
/* These two members must be first. */
struct sk_buff * next;
struct sk_buff * prev;
_ _u32 qlen;
spinlock_t lock;
};
NOTE: Data and tail point to the beginning and end of the actual data.
NOTE: The layer can then fill in the gap between head and data with a protocol header, or the gap
between tail and end with new data.
When a packet is received, the device driver updates this field with the pointer to
the data structure representing the receiving interface
static int vortex_rx(struct net_device *dev)
{
skb->dev = dev;
... ... ...
skb->protocol = eth_type_trans(skb, dev);
netif_rx(skb); /* Pass the packet to the higher layer */
... ... ...
}
When receiving a data packet, the function responsible for processing the layer n
header receives a buffer from layer n-1 with skb->data pointing to the beginning
of the layer n header.
before passing
the packet to the layer n+1 handler, updates skb->data to make it point to the
end of the layer n header, which is the beginning of the layer n+1 header.
skb support functions examples
1.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.
2.void kfree_skb(struct sk_buff *skb)
Decrement the skb's usage count by one and free the skb if no
references left.
3.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.
4.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.
5.unsigned char *skb_pull(struct sk_buff *skb, int len)
remove data from the start of a buffer, returning the bytes to headroom. A pointr to the
next data in the buffer is returned.
THE FLOW
1. When TCP is asked to transmit some data, it allocates a buffer following certain
criteria (TCP Maximum Segment Size (mss), support for scatter gather I/O, etc.).
2. TCP reserves (with skb_reserve) enough space at the head of the buffer to hold
all the headers of all layers (TCP, IP, link layer). The parameter MAX_TCP_HEADER is
the sum of all headers of all levels and is calculated taking into account the
worst-case scenarios: because the TCP layer does not know what type of inter-
face will be used for the transmission, it reserves the biggest possible header for
each layer. It even accounts for the possibility of multiple IP headers (because
you can have multiple IP headers when the kernel is compiled with support for
IP over IP).
3. The TCP payload is copied into the buffer. Note that Figure 2-8 is just an exam-
ple. The TCP payload could be organized differently; for example, it could be
stored as fragments. In Chapter 21, we will see what a fragmented buffer (also
commonly called a paged buffer) looks like.
4. The TCP layer adds its header.
5. The TCP layer hands the buffer to the IP layer, which adds its header as well.
6. The IP layer hands the IP packet to the neighboring layer, which adds the link
layer header.
SOCKETS
CLIENT-SERVER DATA
THANK YOU
By: Sourav Punoriyar
Contact: souravpunoriyar@gmail.com

Mais conteúdo relacionado

Mais procurados

Advanced REXX Programming Techniques
Advanced REXX Programming TechniquesAdvanced REXX Programming Techniques
Advanced REXX Programming TechniquesDan O'Dea
 
Container Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondContainer Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondKubeAcademy
 
Geep networking stack-linuxkernel
Geep networking stack-linuxkernelGeep networking stack-linuxkernel
Geep networking stack-linuxkernelKiran Divekar
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking WalkthroughThomas Graf
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingViller Hsiao
 
Linux Boot Process
Linux Boot ProcessLinux Boot Process
Linux Boot Processdarshhingu
 
Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...
Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...
Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...xKinAnx
 
クラウドオーケストレーション「OpenStack Heat」に迫る!
クラウドオーケストレーション「OpenStack Heat」に迫る!クラウドオーケストレーション「OpenStack Heat」に迫る!
クラウドオーケストレーション「OpenStack Heat」に迫る!Etsuji Nakai
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network InterfacesKernel TLV
 
Kernel_Crash_Dump_Analysis
Kernel_Crash_Dump_AnalysisKernel_Crash_Dump_Analysis
Kernel_Crash_Dump_AnalysisBuland Singh
 
Linux and H/W optimizations for MySQL
Linux and H/W optimizations for MySQLLinux and H/W optimizations for MySQL
Linux and H/W optimizations for MySQLYoshinori Matsunobu
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughThomas Graf
 
debugging openstack neutron /w openvswitch
debugging openstack neutron /w openvswitchdebugging openstack neutron /w openvswitch
debugging openstack neutron /w openvswitch어형 이
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernelAdrian Huang
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File SystemAdrian Huang
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringScyllaDB
 

Mais procurados (20)

eBPF maps 101
eBPF maps 101eBPF maps 101
eBPF maps 101
 
Advanced REXX Programming Techniques
Advanced REXX Programming TechniquesAdvanced REXX Programming Techniques
Advanced REXX Programming Techniques
 
Container Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondContainer Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyond
 
Geep networking stack-linuxkernel
Geep networking stack-linuxkernelGeep networking stack-linuxkernel
Geep networking stack-linuxkernel
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking Walkthrough
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracing
 
Linux Boot Process
Linux Boot ProcessLinux Boot Process
Linux Boot Process
 
Embedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile DevicesEmbedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile Devices
 
Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...
Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...
Ibm spectrum scale fundamentals workshop for americas part 4 spectrum scale_r...
 
クラウドオーケストレーション「OpenStack Heat」に迫る!
クラウドオーケストレーション「OpenStack Heat」に迫る!クラウドオーケストレーション「OpenStack Heat」に迫る!
クラウドオーケストレーション「OpenStack Heat」に迫る!
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network Interfaces
 
Kernel_Crash_Dump_Analysis
Kernel_Crash_Dump_AnalysisKernel_Crash_Dump_Analysis
Kernel_Crash_Dump_Analysis
 
Linux and H/W optimizations for MySQL
Linux and H/W optimizations for MySQLLinux and H/W optimizations for MySQL
Linux and H/W optimizations for MySQL
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
debugging openstack neutron /w openvswitch
debugging openstack neutron /w openvswitchdebugging openstack neutron /w openvswitch
debugging openstack neutron /w openvswitch
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
 

Destaque

Basic explanation to md5 implementation in C
Basic explanation to md5 implementation in CBasic explanation to md5 implementation in C
Basic explanation to md5 implementation in CSourav Punoriyar
 
Production process of my School Magazine
Production process of my School MagazineProduction process of my School Magazine
Production process of my School MagazineBenmorrell123
 
A review on Rich dad's "The Business School"
A review on Rich dad's "The Business School"A review on Rich dad's "The Business School"
A review on Rich dad's "The Business School"Deepika Bommu
 
Oranjerevolutie
OranjerevolutieOranjerevolutie
OranjerevolutieTomasgeens
 
Behind the lines
Behind the linesBehind the lines
Behind the linesRMM955
 
Aardbeving sumatra 28 maart 2005.ppt
Aardbeving sumatra 28 maart 2005.pptAardbeving sumatra 28 maart 2005.ppt
Aardbeving sumatra 28 maart 2005.pptstef jochems
 
Основи програмування
Основи програмуванняОснови програмування
Основи програмуванняHelenSm007
 
Spring summer preview 2015
Spring summer preview 2015Spring summer preview 2015
Spring summer preview 2015Melita Tompkins
 
Content product challenge
Content product challengeContent product challenge
Content product challengeJay Mount
 
Открытое внеклассное мероприятие "Золотая Осень"
Открытое внеклассное мероприятие "Золотая Осень"Открытое внеклассное мероприятие "Золотая Осень"
Открытое внеклассное мероприятие "Золотая Осень"mizieva
 
Welcome mtc sfe
Welcome mtc sfeWelcome mtc sfe
Welcome mtc sfeAhmad Ehab
 

Destaque (20)

Basic explanation to md5 implementation in C
Basic explanation to md5 implementation in CBasic explanation to md5 implementation in C
Basic explanation to md5 implementation in C
 
AREALIDEA,
AREALIDEA, AREALIDEA,
AREALIDEA,
 
Production process of my School Magazine
Production process of my School MagazineProduction process of my School Magazine
Production process of my School Magazine
 
A review on Rich dad's "The Business School"
A review on Rich dad's "The Business School"A review on Rich dad's "The Business School"
A review on Rich dad's "The Business School"
 
Samayer chhayapath
Samayer chhayapathSamayer chhayapath
Samayer chhayapath
 
anlisis de roger rabbit
anlisis de roger rabbitanlisis de roger rabbit
anlisis de roger rabbit
 
Media studies
Media studiesMedia studies
Media studies
 
Fmp 8000 manual
Fmp 8000 manualFmp 8000 manual
Fmp 8000 manual
 
Oranjerevolutie
OranjerevolutieOranjerevolutie
Oranjerevolutie
 
Behind the lines
Behind the linesBehind the lines
Behind the lines
 
Question 2
Question 2 Question 2
Question 2
 
Our pitch Fix
Our pitch FixOur pitch Fix
Our pitch Fix
 
Aardbeving sumatra 28 maart 2005.ppt
Aardbeving sumatra 28 maart 2005.pptAardbeving sumatra 28 maart 2005.ppt
Aardbeving sumatra 28 maart 2005.ppt
 
Основи програмування
Основи програмуванняОснови програмування
Основи програмування
 
kandeloos
kandelooskandeloos
kandeloos
 
Spring summer preview 2015
Spring summer preview 2015Spring summer preview 2015
Spring summer preview 2015
 
2pawer
2pawer2pawer
2pawer
 
Content product challenge
Content product challengeContent product challenge
Content product challenge
 
Открытое внеклассное мероприятие "Золотая Осень"
Открытое внеклассное мероприятие "Золотая Осень"Открытое внеклассное мероприятие "Золотая Осень"
Открытое внеклассное мероприятие "Золотая Осень"
 
Welcome mtc sfe
Welcome mtc sfeWelcome mtc sfe
Welcome mtc sfe
 

Semelhante a Sockets and Socket-Buffer

Introduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hackingIntroduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hackingSusant Sahani
 
CC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdfCC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdfsecunderbadtirumalgi
 
Berkeley Packet Filters
Berkeley Packet FiltersBerkeley Packet Filters
Berkeley Packet FiltersKernel TLV
 
DUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelDUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelAlexey Smirnov
 
Unix.system.calls
Unix.system.callsUnix.system.calls
Unix.system.callsGRajendra
 
1-Information sharing 2-Computation speedup3-Modularity4-.docx
1-Information sharing 2-Computation speedup3-Modularity4-.docx1-Information sharing 2-Computation speedup3-Modularity4-.docx
1-Information sharing 2-Computation speedup3-Modularity4-.docxSONU61709
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource KernelsSilvio Cesare
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerunidsecconf
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorialhughpearse
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device driversAlexandre Moreno
 
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...Anne Nicolas
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesYourHelper1
 
Apache Cassandra and Apche Spark
Apache Cassandra and Apche SparkApache Cassandra and Apche Spark
Apache Cassandra and Apche SparkAlex Thompson
 

Semelhante a Sockets and Socket-Buffer (20)

Introduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hackingIntroduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hacking
 
CC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdfCC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdf
 
Berkeley Packet Filters
Berkeley Packet FiltersBerkeley Packet Filters
Berkeley Packet Filters
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
Linux IO
Linux IOLinux IO
Linux IO
 
DUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelDUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into Kernel
 
Unix.system.calls
Unix.system.callsUnix.system.calls
Unix.system.calls
 
Socket programming
Socket programming Socket programming
Socket programming
 
netLec5.pdf
netLec5.pdfnetLec5.pdf
netLec5.pdf
 
1-Information sharing 2-Computation speedup3-Modularity4-.docx
1-Information sharing 2-Computation speedup3-Modularity4-.docx1-Information sharing 2-Computation speedup3-Modularity4-.docx
1-Information sharing 2-Computation speedup3-Modularity4-.docx
 
Linux
LinuxLinux
Linux
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
 
Computer Science Homework Help
Computer Science Homework HelpComputer Science Homework Help
Computer Science Homework Help
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerun
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorial
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
 
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging Techniques
 
Apache Cassandra and Apche Spark
Apache Cassandra and Apche SparkApache Cassandra and Apche Spark
Apache Cassandra and Apche Spark
 

Último

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Último (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 

Sockets and Socket-Buffer

  • 1. Creating a socket from user space is done by the socket() system call: int socket (int family, int type, int protocol); On success, a file descriptor for the new socket is returned. For open() system call (for files), we also get a file descriptor as the return value. Socket Essentially, a socket is an abstraction for network communication, just as a file is an abstraction for file system communication. Let’s consider the basic network I/O functions for a Linux system. In general, an application that performs net- work input and output needs to perform the five basic functions described in open, close, read, write, and control.
  • 2. A family is a suite of protocols Each family is a subdirectory of linux/net E.g., linux/net/ipv4, linux/net/decnet, linux/net/packet IPv4: PF_INET IPv6: PF_INET6. Packet sockets: PF_PACKET Operate at the device driver layer. pcap library for Linux uses PF_PACKET sockets pcap library is in use by sniffers such as tcpdump. Protocol Family == Address Family PF_INET == AF_INET (in /include/linux/socket.h) Socket(): Family
  • 3.  SOCK_STREAM and SOCK_DGRAM are the mostly used types.  SOCK_STREAM for TCP, SCTP  SOCK_DGRAM for UDP.  SOCK_RAW for RAW sockets.  There are cases where protocol can be either SOCK_STREAM or SOCK_DGRAM; for example, Unix domain socket (AF_UNIX). Socket(): Type
  • 4. Protocol is protocol number within a family. Internet protocols are assigned by IANA (Internet Assigned Number Authority) http://www.iana.org/assignments/protocol-numbers/ For IPPROTO_TCP, it’s usually 0. IPPROTO_TCP is 0, see: include/linux/in.h. For SCTP: protocol is IPPROTO_SCTP (132) sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); For UDP-Lite: protocol is IPPROTO_UDPLITE (136) Socket(): Protocol
  • 5. /* Supported address families. */ #define AF_UNSPEC 0 #define AF_UNIX 1 /* Unix domain sockets */ #define AF_LOCAL 1 /* POSIX name for AF_UNIX */ #define AF_INET 2 /* Internet IP Protocol */ #define AF_AX25 3 /* Amateur Radio AX.25 */ #define AF_IPX 4 /* Novell IPX */ #define AF_APPLETALK 5 /* AppleTalk DDP */ #define AF_NETROM 6 /* Amateur Radio NET/ROM */ #define AF_BRIDGE 7 /* Multiprotocol bridge */ #define AF_ATMPVC 8 /* ATM PVCs */ #define AF_X25 9 /* Reserved for X.25 project */ #define AF_INET6 10 /* IP version 6 */ #define AF_ROSE 11 /* Amateur Radio X.25 PLP */ #define AF_DECnet 12 /* Reserved for DECnet project */ #define AF_NETBEUI 13 /* Reserved for 802.2LLC project*/ #define AF_SECURITY 14 /* Security callback pseudo AF */ #define AF_KEY 15 /* PF_KEY key management API */ .. #define AF_ISDN 34 /* mISDN sockets */ #define AF_PHONET 35 /* Phonet sockets */ #define AF_IEEE802154 36 /* IEEE802154 sockets */ #define AF_MAX 37 /* For now.. */ Address/Protocol Families
  • 6. For every socket which is created by a user space application, there is a corresponding struct socket and struct sock in the kernel. struct socket: include/linux/net.h Data common to the socket layer Has only 8 members Any variable “sock” always refers to a struct socket struct sock : include/net/sock.h Data common to the Network Protocol layer (i.e., AF_INET) has more than 30 members, and is one of the biggest structures in the networking stack. Any variable “sk” always refers to a struct sock. Socket Data Structures
  • 7. socket() bind() listen() accept() read() write() close() socket() bind() connect() write() read() close() The ‘server’ application 3-way handshake data flow to server data flow to client 4-way handshake Diagram CLIENT application
  • 8. Socket Layer User Kernel UDP Hardware Application Ethernet PF_INET TCP Network Device Layer IPV4 SOCK_ STREAM SOCK_ DGRAM SOCK _RAW PF_PACKET SOCK _RAW SOCK_ DGRAM PF_UNIX PF_IPX …. …. Socket Interface Protocol Layers Token Ring PPP SLIP FDDI Device Layer Socket Layer Architecture
  • 9. In Linux, the three different data structures each have the letters "sock" in them. The first is the socket buffer defined in linux/include/linux/sk_buff.h. Socket buffers are structures to hold packet data. struct sk_buff *skb;: In the Linux source code, socket buffers are often referred to by the variable skb. struct socket *sock; : The socket structure is the general structure that holds control and states information for the socket layer. struct sock *sk; : It is a more complex structure used to keep state information about open connections. It is accessed throughout the TCP/IP protocol but mostly within the TCP protocol. It is usually referenced through a variable called sk. SK_BUFFSK_BUFF
  • 10. The Socket Buffer: sk_buff Structure Most important data structure in the Linux networking code, representing the headers for data that has been received or is about to be transmit- ted. Defined in the <include/linux/skbuff.h> include file. struct sk_buff { /* These two members must be first. */ struct sk_buff *next; //next buffer in list struct sk_buff *prev; //previous buffer in list struct sk_buff_head *list; //list we are on struct sock *sk; //socket we belong to struct timeval stamp; //timeval we arrived at struct net_device *dev; //device we are leaving by struct net_device *input_dev; //device we arrived at struct net_device *real_dev; 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.
  • 11. union { struct tcphdr *th; struct udphdr *uh; struct icmphdr *icmph; struct igmphdr *igmph; struct iphdr *ipiph; struct ipv6hdr*ipv6h; unsigned char *raw; } h; //transport layer header (tcp,udp,icmp,igmp,spx,raw) union { struct iphdr *iph; struct ipv6hdr*ipv6h; struct arphdr *arph; unsigned char *raw; } nh; //network layer header (ip,ipv6,arp,ipx,raw) union { unsigned char *raw; } mac; //link layer header struct dst_entry *dst; struct sec_path *sp; //FIXME:
  • 12. char cb[40]; unsigned int len, data_len, mac_len, csum; unsigned char local_df, cloned, pkt_type, ip_summed; __u32 priority; unsigned short protocol, security; void (*destructor)(struct sk_buff *skb); #ifdef CONFIG_NETFILTER unsigned long nfmark; __u32 nfcache; __u32 nfctinfo; struct nf_conntrack *nfct; //control buffer, used internally // Length of actual data //checksum //head may be cloned //packet class //driver fed us ip checksum //packet queuing priority //packet protocol from driver // security level of packet //destructor function
  • 13. #ifdef CONFIG_NETFILTER_DEBUG unsigned int nf_debug; #endif #ifdef CONFIG_BRIDGE_NETFILTER struct nf_bridge_info *nf_bridge; #endif #endif /* CONFIG_NETFILTER */ #if defined(CONFIG_HIPPI) union { __u32 ifield; } private; #endif #ifdef CONFIG_NET_SCHED __u32 tc_index; /* traffic control index */ #ifdef CONFIG_NET_CLS_ACT __u32 tc_verd; /* traffic control verdict */ __u32 tc_classid; /* traffic control classid */ #endif
  • 14. #endif /* These elements must be at the end, see alloc_skb() for details. */ unsigned int truesize; //real size of the buffer atomic_t users; //user count unsigned char *head, // pointer to head of buffer *data, //data head pointer *tail, //tail pointer *end; //end pointer }; End of sk_buff structure
  • 15.
  • 16. This one is tied together by next and prev fields in each sk_buff structure, the next field pointing forward and the prev field pointing back-ward. But this list has another requirement: each sk_buff structure must be able tofind the head of the whole list quickly. To implement this requirement, an extrastructure of type sk_buff_head is inserted at the beginning of the list, as a kind of dummy element. The sk_buff_head structure is: struct sk_buff_head { /* These two members must be first. */ struct sk_buff * next; struct sk_buff * prev; _ _u32 qlen; spinlock_t lock; }; NOTE: Data and tail point to the beginning and end of the actual data. NOTE: The layer can then fill in the gap between head and data with a protocol header, or the gap between tail and end with new data.
  • 17.
  • 18. When a packet is received, the device driver updates this field with the pointer to the data structure representing the receiving interface static int vortex_rx(struct net_device *dev) { skb->dev = dev; ... ... ... skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); /* Pass the packet to the higher layer */ ... ... ... } When receiving a data packet, the function responsible for processing the layer n header receives a buffer from layer n-1 with skb->data pointing to the beginning of the layer n header. before passing the packet to the layer n+1 handler, updates skb->data to make it point to the end of the layer n header, which is the beginning of the layer n+1 header.
  • 19.
  • 20. skb support functions examples 1.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. 2.void kfree_skb(struct sk_buff *skb) Decrement the skb's usage count by one and free the skb if no references left. 3.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. 4.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. 5.unsigned char *skb_pull(struct sk_buff *skb, int len) remove data from the start of a buffer, returning the bytes to headroom. A pointr to the next data in the buffer is returned.
  • 21.
  • 22.
  • 23.
  • 24. THE FLOW 1. When TCP is asked to transmit some data, it allocates a buffer following certain criteria (TCP Maximum Segment Size (mss), support for scatter gather I/O, etc.). 2. TCP reserves (with skb_reserve) enough space at the head of the buffer to hold all the headers of all layers (TCP, IP, link layer). The parameter MAX_TCP_HEADER is the sum of all headers of all levels and is calculated taking into account the worst-case scenarios: because the TCP layer does not know what type of inter- face will be used for the transmission, it reserves the biggest possible header for each layer. It even accounts for the possibility of multiple IP headers (because you can have multiple IP headers when the kernel is compiled with support for IP over IP). 3. The TCP payload is copied into the buffer. Note that Figure 2-8 is just an exam- ple. The TCP payload could be organized differently; for example, it could be stored as fragments. In Chapter 21, we will see what a fragmented buffer (also commonly called a paged buffer) looks like. 4. The TCP layer adds its header. 5. The TCP layer hands the buffer to the IP layer, which adds its header as well. 6. The IP layer hands the IP packet to the neighboring layer, which adds the link layer header.
  • 26.
  • 28. THANK YOU By: Sourav Punoriyar Contact: souravpunoriyar@gmail.com