SlideShare une entreprise Scribd logo
1  sur  68
Divye Kapoor
PracheerAgarwal
Swagat Konchada
 It is the software layer in the kernel that provides a
uniform filesystem interface to userspace programs
 It provides an abstraction within the kernel that allows
for transparent working with a variety of filesystems.
 Thus it allows many different filesystem
implementations to coexist freely
 Each socket is implemented as a “file” mounted on
the sockfs filesystem.
 file->private points to the socket information.
 Inodes provide a method to access the actual
data blocks allocated to a file. For sockets, they
provide buffer space which can be used to hold
socket specific data.
 struct inode
 Every file is represented in the kernel as an
object of the file structure. It requires an inode
provided to it.
 struct file
Struct operations {
int (*read)(int, char *, int);
void (*destroy_inode)(inode *);
void (*dirty_inode) (struct inode *);
int (*write_inode) (struct inode *, int);
void (*drop_inode) (struct inode *);
void (*delete_inode) (struct inode *);
};
Sizeof(operations) = sizeof(function ptr)*6
Divye Kapoor
User Space
Socket, bind, listen, connect, send, recv, write, read etc.
Socket Functions (Kernel)
sys_socket, sys_bind, sys_listen, sys_connect etc. in socket.c
TCP/IP Layer Functions
inet_create, tcp_v4_connect, tcp_sendmsg, tcp_recvmsg
Ethernet Device Layer
dev_hard_start_xmit
Sys_socket()
Sock_create() Sock_map_fd()
Allocate a socket object
(internally an inode
Associated with a file object)
Locate the family requested and
call the create function for that
family
Inet_create()
Lower layer initialization
Sock_alloc_fd()
Allocate a file descriptor
Sock_attach_fd()
Fd_install()
Sys_connect()
Sockfd_lookup_light()
Returns the socket object
associated with the given fd
Move_addr_to_kernel()
For userspace sockaddr *
Sock->ops->connect()
Lower layer call
Tcp_v4_connect()
Socket layer functions
are elided.
Defined in <include/linux/skbuff.h>
 used by every network layer (except the physical layer)
 fields of the structure change as it is passed from one layer to another
 i.e., fields are layer dependent.
struct sk_buff {
... ... ...
#ifdef CONFIG_NET_SCHED
_ _u32 tc_index;
#ifdef CONFIG_NET_CLS_ACT
_ _u32 tc_verd;
_ _u32 tc_classid;
#endif
#endif
}
sk_buff is peppered with C preprocessor #ifdef directives.
CONFIG_NET_SCHED symbol should be defined at compile time for the
structure to have the element tc_index.
enabled with some version of make config by an administrator.
 The kernel maintains all sk_buff structures in a doubly linked list.
struct sk_buff_head {/* only the head of the list */
/*These two members must be first. */
struct sk_buff * next;
struct sk_buff * prev;
_ _u32 qlen;
spinlock_t lock;/* atomicity in accessing a sk_buff list. */
};
 Layout
 General
 Feature-specific
 Management functions
 struct sock * sk
sock data structure of the socket that owns this buffer
 unsigned int len
includes both the data in the main buffer (i.e., the one pointed to by head)
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 truesize
skb->truesize = size + sizeof(struct sk_buff);
 atomic_t users
reference count, or the number of entities using this sk_buff buffer
atomic_inc and atomic_dec
 struct sock * sk
sock data structure of the socket that owns this buffer
 unsigned int len
includes both the data in the main buffer (i.e., the one pointed to by
head) 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 truesize
skb->truesize = size + sizeof(struct sk_buff);
 atomic_t users
reference count, or the number of entities using this sk_buff buffer
atomic_inc and atomic_dec
 struct sock * sk
sock data structure of the socket that owns this buffer
 unsigned int len
includes both the data in the main buffer (i.e., the one pointed to by head)
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 truesize
skb->truesize = size + sizeof(struct sk_buff);
 atomic_t users
reference count, or the number of entities using this sk_buff buffer
atomic_inc and atomic_dec
 struct sock * sk
sock data structure of the socket that owns this buffer
 unsigned int len
includes both the data in the main buffer (i.e., the one pointed to by head)
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 truesize
skb->truesize = size + sizeof(struct sk_buff);
 atomic_t users
reference count, or the number of entities using this sk_buff buffer
atomic_inc and atomic_dec
 struct sock * sk
sock data structure of the socket that owns this buffer
 unsigned int len
includes both the data in the main buffer (i.e., the one pointed to by head)
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 truesize
skb->truesize = size + sizeof(struct sk_buff);
 atomic_t users
reference count, or the number of entities using this sk_buff buffer
atomic_inc() and atomic_dec()
• unsigned char *head
• sk_buff_data_t end
• unsigned char *data
• sk_buff_data_t tail
struct net_device *dev
 represents the receiving interface or the to be transmitted device(or
interface) corresponding to the packet.
 usually represents the virtual device’s(representation of all devices
grouped) net_device structure.
 Pointers to protocol headers.
 sk_buff_data_t transport_header;
 sk_buff_data_t network_header;
 sk_buff_data_t mac_header;
updation of data is done using the *_header pointers
 char cb[40]
 This is a "control buffer," or storage for private information, maintained
by each layer for internal use.
struct tcp_skb_cb {
... ... ... _ _u32 seq; /* Starting sequence number */
_ _u32 end_seq; /* SEQ + FIN + SYN + datalen*/
_ _u32 when; /* used to compute rtt's */
_ _u8 flags; /*TCP header flags. */
... ... ...
};
Defined in <include/linux/skbuff.h> & <net/core/skbuff.c>
skb_put(struct sk_buff *, usingned int len)
skb_push(struct sk_buff *skb, unsigned int len)
skb_pull(struct sk_buff *skb, unsigned int len)
skb_reserve(struct sk_buff *skb, int len)
Each of the above four memory management functions return the data ptr.
defined in <net/core/skbuff.c>
struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
int fclone, int node)
…
size = SKB_DATA_ALIGN(size);
data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
…
struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
unsigned int length, gfp_t gfp_mask)
The buffer allocation function meant for use by device drivers
Executed in interrupt mode
Freeing memory: kfree_skb and dev_kfree_skb
Release buffer back to the buffer-pool.
Buffer released only when skb_users counter is 1. If not, the counter is
decremented.
Socket layer functions
are elided.
 Defined in <include/linux/netdevice.h>
 stores all information specifically regarding a network device
 one such structure for each device, both real ones (such as Ethernet
NICs) and virtual ones
 Network devices can be classified into types such as Ethernet cards and
Token Ring cards
 Each type may come in several models.
 Model specific parameters are initialized by device driver software.
 Parameters common for different models are initiated by kernel.
struct net_device{
char name[IFNAMSIZ];
int ifindex;
/* device name hash chain, ex: eth0 */
struct hlist_node name_hlist;
unsigned long mem_end;/* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned int irq; /* device IRQ number*/
unsigned char if_port; /* Selectable AUI,TP,..*/
unsigned char dma; /* DMA channel */
…
struct net_device{
char name[IFNAMSIZ];
int ifindex;
/* device name hash chain, ex: eth0 */
struct hlist_node name_hlist;
unsigned long mem_end; /* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned int irq; /* device IRQ number*/
unsigned char if_port; /* Selectable AUI,TP,..*/
unsigned char dma; /* DMA channel */
…
struct net_device{
char name[IFNAMSIZ];
int ifindex;
/* device name hash chain, ex: eth0 */
struct hlist_node name_hlist;
unsigned long mem_end;/* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned int irq; /* device IRQ number*/
unsigned char if_port; /* Selectable AUI,TP,..*/
unsigned char dma; /* DMA channel
*/
struct net_device{
char name[IFNAMSIZ];
/* device name hash chain, ex: eth0 */
struct hlist_node name_hlist;
unsigned long mem_end;/* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned int irq; /* device IRQ number*/
unsigned char if_port; /* Selectable AUI,TP,..*/
unsigned char dma; /* DMA channel */
unsigned short flags; /* interface flags (a la BSD) */
…
struct net_device{
char name[IFNAMSIZ];
/* device name hash chain, ex: eth0 */
struct hlist_node name_hlist;
unsigned long mem_end;/* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned int irq; /* device IRQ number*/
unsigned char if_port; /* Selectable AUI,TP,..*/
unsigned char dma; /* DMA channel */
unsigned short flags; /* interface flags (a la BSD)*/
…
struct net_device{
char name[IFNAMSIZ];
/* device name hash chain, ex: eth0 */
struct hlist_node name_hlist;
unsigned long mem_end;/* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned int irq; /* device IRQ number*/
unsigned char if_port; /* Selectable AUI,TP,..*/
unsigned char dma; /* DMA channel */
unsigned short flags; /* interface flags (a la BSD)*/
/* ex : IFF_UP || IFF_RUNNING || IFF_MULTICAST */
struct net_device{
…
unsigned mtu; /* interface MTU value */
unsigned short type; /* interface hardware type */
unsigned short hard_header_len; /* hardware hdr length */
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware address length */
unsigned char broadcast[MAX_ADDR_LEN];
unsigned int promiscuity;
…
struct net_device{
…
unsigned mtu; /* interface MTU value */
unsigned short type; /* interface hardware type*/
unsigned short hard_header_len; /* hardware hdr length */
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware address length */
unsigned char broadcast[MAX_ADDR_LEN];
unsigned int promiscuity;
…
struct net_device{
…
unsigned mtu; /* interface MTU value */
unsigned short type; /* interface hardware type */
unsigned short hard_header_len;/* hardware hdr length */
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware address length */
unsigned char broadcast[MAX_ADDR_LEN];
unsigned int promiscuity;
…
struct net_device{
…
unsigned mtu; /* interface MTU value */
unsigned short type; /* interface hardware type */
unsigned short hard_header_len; /* hardware hdr length */
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware address length*/
unsigned char broadcast[MAX_ADDR_LEN];
unsigned int promiscuity;
…
struct net_device{
…
unsigned mtu; /* interface MTU value */
unsigned short type; /* interface hardware type */
unsigned short hard_header_len; /* hardware hdr length */
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware address length */
unsigned char broadcast[MAX_ADDR_LEN];
unsigned int promiscuity;
…
struct net_device{
…
unsigned mtu; /* interface MTU value */
unsigned short type; /* interface hardware type */
unsigned short hard_header_len; /* hardware hdr length */
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware address length */
unsigned char broadcast[MAX_ADDR_LEN];
unsigned int promiscuity;
…
struct net_device{
…
struct net_device *next;
struct hlist_node name_hlist;
struct hlist_node index_hlist;
We don’t process the packet in the interrupt subroutine.
Netif_rx() – raise the net Rx softIRQ.
Net_rx_action() is called - start processing the packet
 Processing of packet starts with the protocol switching section
Netif_receive_skb() is called to process the packet and find out the next protocol layer.
Protocol family of the packet is extracted from the link layer header.
ip_rcv() is an entry point for IP packets processing.
Checks if the packet we have is destined for some other host (using PACKET_OTHERHOST)
Check the checksum of the packet by calling ip_fast_csum()
Call ip_route_input() , this routine checks kernel routing table rt_hash_table.
If packet needs to be forwarded input routine is ip_forward()
Otherwise ip_local_deliver()
ip_send() is called to check if the packet needs to be fragmented
If yes , fragment the packet by calling ip_fragment()
Packet output path – ip_finish_output()
ip_local_deliver() – packets need to delivered locally
ip_defrag()
Protocol identifier field skb->np.iph->protocol (in IP header).
ForTCP, we find the receive handler as tcp_v4_rcv() (entry point for theTCP layer)
_tcp_v4_lookup() – find the socket to which the packet belongs
Establised sockets are maintained in the hash table tcp_ehash.
Established socket not found – New connection request for any listening socket
Search for listening socket – tcp_v4_lookup_listener()
tcp_rcv_established()
Application read the data from the receive queue if it issues recv()
Kernel routine to read data fromTCP socket is tcp_recvmsg()
The TCP/IP Stack in the Linux Kernel

Contenu connexe

Tendances

Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic ControlSUSE Labs Taipei
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsDivye Kapoor
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracingViller Hsiao
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDKKernel TLV
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux KernelKernel TLV
 
DPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet ProcessingDPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet ProcessingMichelle Holley
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver艾鍗科技
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Andriy Berestovskyy
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPThomas Graf
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stackAnne Nicolas
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingMichelle Holley
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmicsDenys Haryachyy
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and moreBrendan Gregg
 

Tendances (20)

Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
 
DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracing
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
DPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet ProcessingDPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet Processing
 
Dpdk performance
Dpdk performanceDpdk performance
Dpdk performance
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stack
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 

Similaire à The TCP/IP Stack in the Linux Kernel

Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesYourHelper1
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014Kevin Lo
 
Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11Russell Childs
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenPostgresOpen
 
Introduction to Kernel Programming
Introduction to Kernel ProgrammingIntroduction to Kernel Programming
Introduction to Kernel ProgrammingAhmed Mekkawy
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bChereCheek752
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and DriversKernel TLV
 
LAS16-300: Mini Conference 2 Cortex-M Software - Device Configuration
LAS16-300: Mini Conference 2 Cortex-M Software - Device ConfigurationLAS16-300: Mini Conference 2 Cortex-M Software - Device Configuration
LAS16-300: Mini Conference 2 Cortex-M Software - Device ConfigurationLinaro
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 
Unix.system.calls
Unix.system.callsUnix.system.calls
Unix.system.callsGRajendra
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelVitaly Nikolenko
 
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
 
Unit 3
Unit  3Unit  3
Unit 3siddr
 

Similaire à The TCP/IP Stack in the Linux Kernel (20)

Sockets and Socket-Buffer
Sockets and Socket-BufferSockets and Socket-Buffer
Sockets and Socket-Buffer
 
Linux
LinuxLinux
Linux
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging Techniques
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
 
Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Introduction to Kernel Programming
Introduction to Kernel ProgrammingIntroduction to Kernel Programming
Introduction to Kernel Programming
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
Sysprog 16
Sysprog 16Sysprog 16
Sysprog 16
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
LAS16-300: Mini Conference 2 Cortex-M Software - Device Configuration
LAS16-300: Mini Conference 2 Cortex-M Software - Device ConfigurationLAS16-300: Mini Conference 2 Cortex-M Software - Device Configuration
LAS16-300: Mini Conference 2 Cortex-M Software - Device Configuration
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
Unix.system.calls
Unix.system.callsUnix.system.calls
Unix.system.calls
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
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...
 
Unit 3
Unit  3Unit  3
Unit 3
 

Dernier

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Dernier (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

The TCP/IP Stack in the Linux Kernel

  • 2.
  • 3.  It is the software layer in the kernel that provides a uniform filesystem interface to userspace programs  It provides an abstraction within the kernel that allows for transparent working with a variety of filesystems.  Thus it allows many different filesystem implementations to coexist freely  Each socket is implemented as a “file” mounted on the sockfs filesystem.  file->private points to the socket information.
  • 4.  Inodes provide a method to access the actual data blocks allocated to a file. For sockets, they provide buffer space which can be used to hold socket specific data.  struct inode  Every file is represented in the kernel as an object of the file structure. It requires an inode provided to it.  struct file
  • 5. Struct operations { int (*read)(int, char *, int); void (*destroy_inode)(inode *); void (*dirty_inode) (struct inode *); int (*write_inode) (struct inode *, int); void (*drop_inode) (struct inode *); void (*delete_inode) (struct inode *); }; Sizeof(operations) = sizeof(function ptr)*6
  • 7. User Space Socket, bind, listen, connect, send, recv, write, read etc. Socket Functions (Kernel) sys_socket, sys_bind, sys_listen, sys_connect etc. in socket.c TCP/IP Layer Functions inet_create, tcp_v4_connect, tcp_sendmsg, tcp_recvmsg Ethernet Device Layer dev_hard_start_xmit
  • 8. Sys_socket() Sock_create() Sock_map_fd() Allocate a socket object (internally an inode Associated with a file object) Locate the family requested and call the create function for that family Inet_create() Lower layer initialization Sock_alloc_fd() Allocate a file descriptor Sock_attach_fd() Fd_install()
  • 9. Sys_connect() Sockfd_lookup_light() Returns the socket object associated with the given fd Move_addr_to_kernel() For userspace sockaddr * Sock->ops->connect() Lower layer call Tcp_v4_connect()
  • 10.
  • 11.
  • 12.
  • 14.
  • 15. Defined in <include/linux/skbuff.h>  used by every network layer (except the physical layer)  fields of the structure change as it is passed from one layer to another  i.e., fields are layer dependent.
  • 16. struct sk_buff { ... ... ... #ifdef CONFIG_NET_SCHED _ _u32 tc_index; #ifdef CONFIG_NET_CLS_ACT _ _u32 tc_verd; _ _u32 tc_classid; #endif #endif } sk_buff is peppered with C preprocessor #ifdef directives. CONFIG_NET_SCHED symbol should be defined at compile time for the structure to have the element tc_index. enabled with some version of make config by an administrator.
  • 17.  The kernel maintains all sk_buff structures in a doubly linked list. struct sk_buff_head {/* only the head of the list */ /*These two members must be first. */ struct sk_buff * next; struct sk_buff * prev; _ _u32 qlen; spinlock_t lock;/* atomicity in accessing a sk_buff list. */ };
  • 18.  Layout  General  Feature-specific  Management functions
  • 19.  struct sock * sk sock data structure of the socket that owns this buffer  unsigned int len includes both the data in the main buffer (i.e., the one pointed to by head) 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 truesize skb->truesize = size + sizeof(struct sk_buff);  atomic_t users reference count, or the number of entities using this sk_buff buffer atomic_inc and atomic_dec
  • 20.  struct sock * sk sock data structure of the socket that owns this buffer  unsigned int len includes both the data in the main buffer (i.e., the one pointed to by head) 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 truesize skb->truesize = size + sizeof(struct sk_buff);  atomic_t users reference count, or the number of entities using this sk_buff buffer atomic_inc and atomic_dec
  • 21.  struct sock * sk sock data structure of the socket that owns this buffer  unsigned int len includes both the data in the main buffer (i.e., the one pointed to by head) 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 truesize skb->truesize = size + sizeof(struct sk_buff);  atomic_t users reference count, or the number of entities using this sk_buff buffer atomic_inc and atomic_dec
  • 22.  struct sock * sk sock data structure of the socket that owns this buffer  unsigned int len includes both the data in the main buffer (i.e., the one pointed to by head) 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 truesize skb->truesize = size + sizeof(struct sk_buff);  atomic_t users reference count, or the number of entities using this sk_buff buffer atomic_inc and atomic_dec
  • 23.  struct sock * sk sock data structure of the socket that owns this buffer  unsigned int len includes both the data in the main buffer (i.e., the one pointed to by head) 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 truesize skb->truesize = size + sizeof(struct sk_buff);  atomic_t users reference count, or the number of entities using this sk_buff buffer atomic_inc() and atomic_dec()
  • 24. • unsigned char *head • sk_buff_data_t end • unsigned char *data • sk_buff_data_t tail
  • 25. struct net_device *dev  represents the receiving interface or the to be transmitted device(or interface) corresponding to the packet.  usually represents the virtual device’s(representation of all devices grouped) net_device structure.  Pointers to protocol headers.  sk_buff_data_t transport_header;  sk_buff_data_t network_header;  sk_buff_data_t mac_header;
  • 26. updation of data is done using the *_header pointers
  • 27.  char cb[40]  This is a "control buffer," or storage for private information, maintained by each layer for internal use. struct tcp_skb_cb { ... ... ... _ _u32 seq; /* Starting sequence number */ _ _u32 end_seq; /* SEQ + FIN + SYN + datalen*/ _ _u32 when; /* used to compute rtt's */ _ _u8 flags; /*TCP header flags. */ ... ... ... };
  • 28. Defined in <include/linux/skbuff.h> & <net/core/skbuff.c> skb_put(struct sk_buff *, usingned int len)
  • 29. skb_push(struct sk_buff *skb, unsigned int len)
  • 30. skb_pull(struct sk_buff *skb, unsigned int len)
  • 31. skb_reserve(struct sk_buff *skb, int len) Each of the above four memory management functions return the data ptr.
  • 32. defined in <net/core/skbuff.c> struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, int fclone, int node) … size = SKB_DATA_ALIGN(size); data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask); …
  • 33. struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int length, gfp_t gfp_mask) The buffer allocation function meant for use by device drivers Executed in interrupt mode Freeing memory: kfree_skb and dev_kfree_skb Release buffer back to the buffer-pool. Buffer released only when skb_users counter is 1. If not, the counter is decremented.
  • 34.
  • 35.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.  Defined in <include/linux/netdevice.h>  stores all information specifically regarding a network device  one such structure for each device, both real ones (such as Ethernet NICs) and virtual ones  Network devices can be classified into types such as Ethernet cards and Token Ring cards  Each type may come in several models.  Model specific parameters are initialized by device driver software.  Parameters common for different models are initiated by kernel.
  • 47. struct net_device{ char name[IFNAMSIZ]; int ifindex; /* device name hash chain, ex: eth0 */ struct hlist_node name_hlist; unsigned long mem_end;/* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number*/ unsigned char if_port; /* Selectable AUI,TP,..*/ unsigned char dma; /* DMA channel */ …
  • 48. struct net_device{ char name[IFNAMSIZ]; int ifindex; /* device name hash chain, ex: eth0 */ struct hlist_node name_hlist; unsigned long mem_end; /* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number*/ unsigned char if_port; /* Selectable AUI,TP,..*/ unsigned char dma; /* DMA channel */ …
  • 49. struct net_device{ char name[IFNAMSIZ]; int ifindex; /* device name hash chain, ex: eth0 */ struct hlist_node name_hlist; unsigned long mem_end;/* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number*/ unsigned char if_port; /* Selectable AUI,TP,..*/ unsigned char dma; /* DMA channel */
  • 50. struct net_device{ char name[IFNAMSIZ]; /* device name hash chain, ex: eth0 */ struct hlist_node name_hlist; unsigned long mem_end;/* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number*/ unsigned char if_port; /* Selectable AUI,TP,..*/ unsigned char dma; /* DMA channel */ unsigned short flags; /* interface flags (a la BSD) */ …
  • 51. struct net_device{ char name[IFNAMSIZ]; /* device name hash chain, ex: eth0 */ struct hlist_node name_hlist; unsigned long mem_end;/* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number*/ unsigned char if_port; /* Selectable AUI,TP,..*/ unsigned char dma; /* DMA channel */ unsigned short flags; /* interface flags (a la BSD)*/ …
  • 52. struct net_device{ char name[IFNAMSIZ]; /* device name hash chain, ex: eth0 */ struct hlist_node name_hlist; unsigned long mem_end;/* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number*/ unsigned char if_port; /* Selectable AUI,TP,..*/ unsigned char dma; /* DMA channel */ unsigned short flags; /* interface flags (a la BSD)*/ /* ex : IFF_UP || IFF_RUNNING || IFF_MULTICAST */
  • 53. struct net_device{ … unsigned mtu; /* interface MTU value */ unsigned short type; /* interface hardware type */ unsigned short hard_header_len; /* hardware hdr length */ unsigned char dev_addr[MAX_ADDR_LEN]; unsigned char addr_len; /* hardware address length */ unsigned char broadcast[MAX_ADDR_LEN]; unsigned int promiscuity; …
  • 54. struct net_device{ … unsigned mtu; /* interface MTU value */ unsigned short type; /* interface hardware type*/ unsigned short hard_header_len; /* hardware hdr length */ unsigned char dev_addr[MAX_ADDR_LEN]; unsigned char addr_len; /* hardware address length */ unsigned char broadcast[MAX_ADDR_LEN]; unsigned int promiscuity; …
  • 55. struct net_device{ … unsigned mtu; /* interface MTU value */ unsigned short type; /* interface hardware type */ unsigned short hard_header_len;/* hardware hdr length */ unsigned char dev_addr[MAX_ADDR_LEN]; unsigned char addr_len; /* hardware address length */ unsigned char broadcast[MAX_ADDR_LEN]; unsigned int promiscuity; …
  • 56. struct net_device{ … unsigned mtu; /* interface MTU value */ unsigned short type; /* interface hardware type */ unsigned short hard_header_len; /* hardware hdr length */ unsigned char dev_addr[MAX_ADDR_LEN]; unsigned char addr_len; /* hardware address length*/ unsigned char broadcast[MAX_ADDR_LEN]; unsigned int promiscuity; …
  • 57. struct net_device{ … unsigned mtu; /* interface MTU value */ unsigned short type; /* interface hardware type */ unsigned short hard_header_len; /* hardware hdr length */ unsigned char dev_addr[MAX_ADDR_LEN]; unsigned char addr_len; /* hardware address length */ unsigned char broadcast[MAX_ADDR_LEN]; unsigned int promiscuity; …
  • 58. struct net_device{ … unsigned mtu; /* interface MTU value */ unsigned short type; /* interface hardware type */ unsigned short hard_header_len; /* hardware hdr length */ unsigned char dev_addr[MAX_ADDR_LEN]; unsigned char addr_len; /* hardware address length */ unsigned char broadcast[MAX_ADDR_LEN]; unsigned int promiscuity; …
  • 59. struct net_device{ … struct net_device *next; struct hlist_node name_hlist; struct hlist_node index_hlist;
  • 60.
  • 61. We don’t process the packet in the interrupt subroutine. Netif_rx() – raise the net Rx softIRQ. Net_rx_action() is called - start processing the packet  Processing of packet starts with the protocol switching section
  • 62. Netif_receive_skb() is called to process the packet and find out the next protocol layer. Protocol family of the packet is extracted from the link layer header.
  • 63. ip_rcv() is an entry point for IP packets processing. Checks if the packet we have is destined for some other host (using PACKET_OTHERHOST) Check the checksum of the packet by calling ip_fast_csum()
  • 64. Call ip_route_input() , this routine checks kernel routing table rt_hash_table. If packet needs to be forwarded input routine is ip_forward() Otherwise ip_local_deliver() ip_send() is called to check if the packet needs to be fragmented If yes , fragment the packet by calling ip_fragment() Packet output path – ip_finish_output() ip_local_deliver() – packets need to delivered locally
  • 65. ip_defrag() Protocol identifier field skb->np.iph->protocol (in IP header). ForTCP, we find the receive handler as tcp_v4_rcv() (entry point for theTCP layer)
  • 66. _tcp_v4_lookup() – find the socket to which the packet belongs Establised sockets are maintained in the hash table tcp_ehash. Established socket not found – New connection request for any listening socket Search for listening socket – tcp_v4_lookup_listener() tcp_rcv_established()
  • 67. Application read the data from the receive queue if it issues recv() Kernel routine to read data fromTCP socket is tcp_recvmsg()

Notes de l'éditeur

  1. Req_irq and free_irq
  2. Req_irq and free_irq
  3. Req_irq and free_irq
  4. Req_irq and free_irq