SlideShare a Scribd company logo
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Network Management
2© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
W's of Networking
Introduction to Sockets
Addressing at the Layers
Programming the Sockets
Client-Server Concepts
3© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
W's of Networking
Communication is the Key
User Space & User Space
Signals, IPC, Shared Address Space
Kernel Space & User Space
System Calls, Signals
Kernel Space & Kernel Space
Kernel Communication & Synchronization Mechanisms
Hardware Space & Kernel Space
Interrupts, Device Access Mechanisms
What's common in all of these?
All within the same system
Networking extends a hand outside the system
4© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Stack & Sockets
Physical
Data Link
Network
Transport
Session
Presentation
Application
Stream
Socket
Interface
Datagram
Socket
Interface
Raw
Socket
Interface
IP
Application Program
7 Layers
TCP UDP
Interface Layer (Ethernet, SLIP, loopback, etc)
Media
5© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System I
Inter System Communication
User Space
...Process Process
Socket Interface
Kernel Space
Hardware Space
System II
User Space
...Process Process
Socket Interface
Kernel Space
Hardware Space
Network Link
D
6© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Examples
Network Daemons (Servers) with default socket numbers
ftpd (Port 21)
sshd (Port 22)
telnetd (Port 23)
smtp (Port 25)
httpd (Port 80)
Network Applications (Clients)
ftp
ssh
telnet
Mail Clients (pine, mutt, ...)
Web Browsers (firefox, ...)
7© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Dependence
Wire Transmission – Bit-wise
MSB first
System Data – Word-wise
Which end first?
Depends on the Processor
Two prevalent Endians
Little Endian (x86 systems, PPC, ...)
Big Endian (Sun systems, PPC, ...)
8© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Little Endian
00101000 01111100 00101110 00101010 Data
MS Byte LS Byte
Memory
A
A+1
A+2
A+3
00101010
00101110
01111100
00101000
9© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Big Endian
00101000 01111100 00101110 00101010
00101010
00101110
01111100
00101000
Memory
Data
MS Byte LS Byte
A
A+1
A+2
A+3
10© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Trivial functions
uint16_t htons(uint16_t host_short);
uint16_t ntohs(uint16_t network_short);
uint32_t htonl(uint32_t host_long);
uint32_t ntohl(uint32_t network_long);
Header: <arpa/inet.h>
11© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Addressing at Layers
Physical
Data Link
Network
Transport
Session
Presentation
Application
IP
TCP UDP
Application Program
Physical Networks
Physical Address
(MAC Address)
IP Address
Port Address
(Socket Address)
User-specific
12© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Socket Address
Basic Structure (16 bytes)
struct sockaddr
{
sa_family_t sa_family; // Protocol Family
char sa_data[14]; // Protocol Address
}
typedef unsigned short sa_family_t;
13© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Socket Address ...
With Internet Address
struct sockaddr_in
{
sa_family_t sin_family; // Protocol Family
in_port_t sin_port; // Port Number / Socket Address
struct in_addr sin_addr; // IP Protocol Address
unsigned char sin_zero[8]; // Pad to sizeof(struct sockaddr)
}
typedef uint16_t in_port_t;
struct in_addr { in_addr_t s_addr; }
typedef uint32_t in_addr_t;
14© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Socket Programming Usage
Socket Creation: socket()
Attaching with an address: bind()
Preparing for accepting connections: listen()
Waiting for & Accepting connections: accept()
Setting up the connection: connect()
Sending data: send(), sendto(), sendmsg()
Receiving data: recv(), recvfrom(), recvmsg()
Cleaning up: close()
Example Pairs
Connection-oriented (TCP based): sock_server.c, sock_client.c
Connection-less (UDP based): sock_dgram_*.c
15© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Creating a socket
fd = socket(family, type, protocol);
Family
AF_UNIX / AF_LOCAL, AF_INET, AF_INET6, ...
Type
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ...
Can be or'ed with SOCK_NONBLOCK, SOCK_CLOEXEC
Protocol
Typically one per family. So, pass zero
Returns
file descriptor of the new socket on success
-1 on error (and sets errno)
16© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Attaching an address
Done by a server
status = bind(fd, addresssp, addrlen);
fd: File descriptor returned by socket()
addressp: Pointer to address structure
addrlen: Size of address structure
Returns
0 on success
-1 on error (and sets errno)
17© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Preparing for connections
Done by a server for transport connections
status = listen(fd, qlen);
fd: File descriptor returned by socket()
qlen
Length of the pending connection queue
Returns
0 on success
-1 on error (and sets errno)
18© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Accepting new connections
Done by a server for connection based sockets
newfd = accept(fd, addresssp, addrlen);
fd: File descriptor returned by socket()
addressp (Could be NULL)
Pointer to structure of address of the connected peer
addrlen: Value-result address structure size
Blocking call (by default), waiting for new connections
Returns
File descriptor of the new accepted socket connection
-1 on error (and sets errno)
19© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Connecting to server
Done by a client for connection based sockets
status = connect(fd, addresssp, addrlen);
fd
File descriptor returned by socket() to be connected
addressp
Pointer to structure of address to connect to
addrlen: Size of address structure
Returns
0 on success
-1 on error (and sets errno)
20© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Connection Establishment
Server Application
socket()
bind()
listen()
accept()
Physical Layer
Transport / Network
Layer
Client Application
socket()
connect()
Transport / Network
Layer
21© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Sending Data
Could be done by both server and client
sent = send(fd, buf, len, flags);
fd: File descriptor of the connected socket
buf: Buffer of Data to be sent
len: Length of the data to be sent
flags: MSG_DONTWAIT, MSG_NOSIGNAL, ...
Returns
Bytes of data sent on success
-1 on error (and sets errno)
Other APIs: write(), sendto(), sendmsg()
22© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Receiving Data
Could be done by both server and client
received = recv(fd, buf, len, flags);
fd: File descriptor of the connected socket
buf: Buffer to receive Data into
len: Length of the Buffer
flags: MSG_DONTWAIT, MSG_PEEK, MSG_WAITALL, ...
Returns
Bytes of data received on success
-1 on error (and sets errno)
Other APIs: read(), recvfrom(), recvmsg()
23© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Closing sockets
To be done by both server and client
On all the not-needed socket file descriptors
Unless they were opened with SOCK_CLOEXEC
Terminates both directions of data transfer
Reading and Writing
Cleans up all the socket related resources
shutdown(fd, how);
fd: File descriptor of the socket to be closed
how: SHUT_RD, SHUT_WR, SHUT_RDWR
Returns
0 on success
-1 on error (and sets errno)
Other API: close()
24© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Non-blocking Options
Typical blocking system calls
accept()
send*(), write()
recv*(), read()
Achieving non-blocking behaviour
Non-blocking: Socket opened with SOCK_NONBLOCK
Multiplexing: Use select() or poll() or epoll() on socket fd
Signal driven: Set socket to deliver SIGIO on activity
Using FIOSETOWN cmd of fcntl, Or
Using SIOCSPGRP cmd of ioctl
25© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Call 'select'
Header File: <sys/select.h>
int select(
int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout
);
File Descriptor Set APIs
void FD_ZERO(fd_set *set);
void FD_SET(int fd, fd_set *set);
void FD_CLR(int fd, fd_set *set);
int FD_ISSET(int fd, fd_set *set);
Select Usage Example: pipe_window.c → pipe_window0, pipe_window1
Server-Client Pair: sock_server_select.c, sock_client.c
26© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Call 'poll'
Header File: <poll.h>
int poll(
struct pollfd *array_fds, nfds_t nfds,
struct timespec *timeout
);
struct pollfd
int fd;
short events /* requested events */
short revents /* returned events */
Events: POLLIN, POLLOUT, POLLPRI
Additional returned Events: POLLERR, POLLHUP, POLLNVAL
27© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Socket related Information
cat /proc/sys/net/core/
rmem_default: Default receive buffer size
rmem_max: Maximum receive buffer size
wmem_default: Default send buffer size
wmem_max: Maximum send buffer size
…
man 7 socket
28© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Client-Server Concepts
Types of Connections
Control connections
Data connections
Types of Servers
Iterative servers (Single Process)
Concurrent servers (Multi-Process)
29© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Iterative Servers
Client Server Client
Ephemeral Port Well-known Port
Example: sock_server_select.c(, sock_client.c)
30© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Concurrent Servers
Client Server Client
Child
Server
Ephemeral Port Well-known Port
Example: sock_server_concurrent.c(, sock_client.c)
Child
Server
31© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Miscellaneous Examples
Named (AF_UNIX / AF_LOCAL) Sockets
named_socket_server.c
named_socket_client.c
Multicast Operations
mcast_recv.c
mcast_send.c
32© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
W's of Networking
Introduction to Sockets
Networking with 'Endian'
Addressing at the Layers
Programming the Sockets
Client-Server Concepts
33© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

What's hot

IP addressing seminar ppt
IP addressing seminar pptIP addressing seminar ppt
IP addressing seminar ppt
Smriti Rastogi
 
Network Security Terminologies
Network Security TerminologiesNetwork Security Terminologies
Network Security Terminologies
university of education,Lahore
 
Security and Linux Security
Security and Linux SecuritySecurity and Linux Security
Security and Linux Security
Rizky Ariestiyansyah
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
Kernel TLV
 
Telnet & SSH
Telnet & SSHTelnet & SSH
Telnet & SSH
NetProtocol Xpert
 
Network operating system
Network operating systemNetwork operating system
Network operating system
John Carlo Catacutan
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Operating system security
Operating system securityOperating system security
Operating system security
Ramesh Ogania
 
Server configuration
Server configurationServer configuration
Server configuration
Aisha Talat
 
Linux security
Linux securityLinux security
Linux security
trilokchandra prakash
 
Storage Management in Linux OS.ppt
Storage Management in Linux OS.pptStorage Management in Linux OS.ppt
Storage Management in Linux OS.ppt
Rakesh Kadu
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and Permissions
Ahmed El-Arabawy
 
System and network administration network services
System and network administration network servicesSystem and network administration network services
System and network administration network services
Uc Man
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
Emertxe Information Technologies Pvt Ltd
 
Linux commands
Linux commandsLinux commands
Linux commands
penetration Tester
 
Install and configure linux
Install and configure linuxInstall and configure linux
Install and configure linux
Vicent Selfa
 
Linux User Management
Linux User ManagementLinux User Management
Linux User Management
Gaurav Mishra
 
CS6004 Cyber Forensics
CS6004 Cyber ForensicsCS6004 Cyber Forensics
CS6004 Cyber Forensics
Kathirvel Ayyaswamy
 
Windows Network concepts
Windows Network conceptsWindows Network concepts
Windows Network concepts
Duressa Teshome
 
Presentation on samba server
Presentation on samba serverPresentation on samba server
Presentation on samba server
Veeral Bhateja
 

What's hot (20)

IP addressing seminar ppt
IP addressing seminar pptIP addressing seminar ppt
IP addressing seminar ppt
 
Network Security Terminologies
Network Security TerminologiesNetwork Security Terminologies
Network Security Terminologies
 
Security and Linux Security
Security and Linux SecuritySecurity and Linux Security
Security and Linux Security
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
 
Telnet & SSH
Telnet & SSHTelnet & SSH
Telnet & SSH
 
Network operating system
Network operating systemNetwork operating system
Network operating system
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Operating system security
Operating system securityOperating system security
Operating system security
 
Server configuration
Server configurationServer configuration
Server configuration
 
Linux security
Linux securityLinux security
Linux security
 
Storage Management in Linux OS.ppt
Storage Management in Linux OS.pptStorage Management in Linux OS.ppt
Storage Management in Linux OS.ppt
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and Permissions
 
System and network administration network services
System and network administration network servicesSystem and network administration network services
System and network administration network services
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Install and configure linux
Install and configure linuxInstall and configure linux
Install and configure linux
 
Linux User Management
Linux User ManagementLinux User Management
Linux User Management
 
CS6004 Cyber Forensics
CS6004 Cyber ForensicsCS6004 Cyber Forensics
CS6004 Cyber Forensics
 
Windows Network concepts
Windows Network conceptsWindows Network concepts
Windows Network concepts
 
Presentation on samba server
Presentation on samba serverPresentation on samba server
Presentation on samba server
 

Viewers also liked

Embedded C
Embedded CEmbedded C
Embedded C
Anil Kumar Pugalia
 
Threads
ThreadsThreads
References
ReferencesReferences
References
Anil Kumar Pugalia
 
Interrupts
InterruptsInterrupts
Interrupts
Anil Kumar Pugalia
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingAnil Kumar Pugalia
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
Anil Kumar Pugalia
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversAnil Kumar Pugalia
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISPAnil Kumar Pugalia
 
Bootloaders
BootloadersBootloaders
Bootloaders
Anil Kumar Pugalia
 

Viewers also liked (20)

System Calls
System CallsSystem Calls
System Calls
 
Timers
TimersTimers
Timers
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Signals
SignalsSignals
Signals
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
References
ReferencesReferences
References
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 

Similar to Linux Network Management

Sockets
Sockets Sockets
Sockets
Gopaiah Sanaka
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
Mohammad Reza Kamalifard
 
lab04.pdf
lab04.pdflab04.pdf
lab04.pdf
SaidiCalala
 
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23
Techvilla
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Socketselliando dias
 
Basics of sockets
Basics of socketsBasics of sockets
Basics of sockets
AviNash ChaVhan
 
Sockets intro
Sockets introSockets intro
Sockets intro
AviNash ChaVhan
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
Peter R. Egli
 
Sockets
Sockets Sockets
Sockets
babu4b4u
 
sockets
socketssockets
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 
Socket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdfSocket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdf
PraveenKumar187040
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
Avinash Varma Kalidindi
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
EloAcubaOgardo
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
EloOgardo
 
03 sockets
03 sockets03 sockets
03 sockets
Pavan Illa
 
Socket programming
Socket programming Socket programming
Socket programming
Rajivarnan (Rajiv)
 
sockets_intro.ppt
sockets_intro.pptsockets_intro.ppt
sockets_intro.ppt
AnilGupta681764
 

Similar to Linux Network Management (20)

Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Sockets
Sockets Sockets
Sockets
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
 
lab04.pdf
lab04.pdflab04.pdf
lab04.pdf
 
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Sockets
 
Basics of sockets
Basics of socketsBasics of sockets
Basics of sockets
 
Np unit2
Np unit2Np unit2
Np unit2
 
Sockets intro
Sockets introSockets intro
Sockets intro
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Sockets
Sockets Sockets
Sockets
 
sockets
socketssockets
sockets
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Socket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdfSocket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdf
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
 
03 sockets
03 sockets03 sockets
03 sockets
 
Socket programming
Socket programming Socket programming
Socket programming
 
sockets_intro.ppt
sockets_intro.pptsockets_intro.ppt
sockets_intro.ppt
 

More from Anil Kumar Pugalia

File System Modules
File System ModulesFile System Modules
File System Modules
Anil Kumar Pugalia
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
Anil Kumar Pugalia
 
Processes
ProcessesProcesses
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
Anil Kumar Pugalia
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
Anil Kumar Pugalia
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
Anil Kumar Pugalia
 

More from Anil Kumar Pugalia (17)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Power of vi
Power of viPower of vi
Power of vi
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Processes
ProcessesProcesses
Processes
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 

Recently uploaded

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Linux Network Management

  • 1. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux Network Management
  • 2. 2© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? W's of Networking Introduction to Sockets Addressing at the Layers Programming the Sockets Client-Server Concepts
  • 3. 3© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. W's of Networking Communication is the Key User Space & User Space Signals, IPC, Shared Address Space Kernel Space & User Space System Calls, Signals Kernel Space & Kernel Space Kernel Communication & Synchronization Mechanisms Hardware Space & Kernel Space Interrupts, Device Access Mechanisms What's common in all of these? All within the same system Networking extends a hand outside the system
  • 4. 4© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Stack & Sockets Physical Data Link Network Transport Session Presentation Application Stream Socket Interface Datagram Socket Interface Raw Socket Interface IP Application Program 7 Layers TCP UDP Interface Layer (Ethernet, SLIP, loopback, etc) Media
  • 5. 5© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System I Inter System Communication User Space ...Process Process Socket Interface Kernel Space Hardware Space System II User Space ...Process Process Socket Interface Kernel Space Hardware Space Network Link D
  • 6. 6© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Examples Network Daemons (Servers) with default socket numbers ftpd (Port 21) sshd (Port 22) telnetd (Port 23) smtp (Port 25) httpd (Port 80) Network Applications (Clients) ftp ssh telnet Mail Clients (pine, mutt, ...) Web Browsers (firefox, ...)
  • 7. 7© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Dependence Wire Transmission – Bit-wise MSB first System Data – Word-wise Which end first? Depends on the Processor Two prevalent Endians Little Endian (x86 systems, PPC, ...) Big Endian (Sun systems, PPC, ...)
  • 8. 8© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Little Endian 00101000 01111100 00101110 00101010 Data MS Byte LS Byte Memory A A+1 A+2 A+3 00101010 00101110 01111100 00101000
  • 9. 9© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Big Endian 00101000 01111100 00101110 00101010 00101010 00101110 01111100 00101000 Memory Data MS Byte LS Byte A A+1 A+2 A+3
  • 10. 10© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Trivial functions uint16_t htons(uint16_t host_short); uint16_t ntohs(uint16_t network_short); uint32_t htonl(uint32_t host_long); uint32_t ntohl(uint32_t network_long); Header: <arpa/inet.h>
  • 11. 11© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Addressing at Layers Physical Data Link Network Transport Session Presentation Application IP TCP UDP Application Program Physical Networks Physical Address (MAC Address) IP Address Port Address (Socket Address) User-specific
  • 12. 12© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Socket Address Basic Structure (16 bytes) struct sockaddr { sa_family_t sa_family; // Protocol Family char sa_data[14]; // Protocol Address } typedef unsigned short sa_family_t;
  • 13. 13© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Socket Address ... With Internet Address struct sockaddr_in { sa_family_t sin_family; // Protocol Family in_port_t sin_port; // Port Number / Socket Address struct in_addr sin_addr; // IP Protocol Address unsigned char sin_zero[8]; // Pad to sizeof(struct sockaddr) } typedef uint16_t in_port_t; struct in_addr { in_addr_t s_addr; } typedef uint32_t in_addr_t;
  • 14. 14© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Socket Programming Usage Socket Creation: socket() Attaching with an address: bind() Preparing for accepting connections: listen() Waiting for & Accepting connections: accept() Setting up the connection: connect() Sending data: send(), sendto(), sendmsg() Receiving data: recv(), recvfrom(), recvmsg() Cleaning up: close() Example Pairs Connection-oriented (TCP based): sock_server.c, sock_client.c Connection-less (UDP based): sock_dgram_*.c
  • 15. 15© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Creating a socket fd = socket(family, type, protocol); Family AF_UNIX / AF_LOCAL, AF_INET, AF_INET6, ... Type SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ... Can be or'ed with SOCK_NONBLOCK, SOCK_CLOEXEC Protocol Typically one per family. So, pass zero Returns file descriptor of the new socket on success -1 on error (and sets errno)
  • 16. 16© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Attaching an address Done by a server status = bind(fd, addresssp, addrlen); fd: File descriptor returned by socket() addressp: Pointer to address structure addrlen: Size of address structure Returns 0 on success -1 on error (and sets errno)
  • 17. 17© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Preparing for connections Done by a server for transport connections status = listen(fd, qlen); fd: File descriptor returned by socket() qlen Length of the pending connection queue Returns 0 on success -1 on error (and sets errno)
  • 18. 18© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Accepting new connections Done by a server for connection based sockets newfd = accept(fd, addresssp, addrlen); fd: File descriptor returned by socket() addressp (Could be NULL) Pointer to structure of address of the connected peer addrlen: Value-result address structure size Blocking call (by default), waiting for new connections Returns File descriptor of the new accepted socket connection -1 on error (and sets errno)
  • 19. 19© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Connecting to server Done by a client for connection based sockets status = connect(fd, addresssp, addrlen); fd File descriptor returned by socket() to be connected addressp Pointer to structure of address to connect to addrlen: Size of address structure Returns 0 on success -1 on error (and sets errno)
  • 20. 20© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Connection Establishment Server Application socket() bind() listen() accept() Physical Layer Transport / Network Layer Client Application socket() connect() Transport / Network Layer
  • 21. 21© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Sending Data Could be done by both server and client sent = send(fd, buf, len, flags); fd: File descriptor of the connected socket buf: Buffer of Data to be sent len: Length of the data to be sent flags: MSG_DONTWAIT, MSG_NOSIGNAL, ... Returns Bytes of data sent on success -1 on error (and sets errno) Other APIs: write(), sendto(), sendmsg()
  • 22. 22© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Receiving Data Could be done by both server and client received = recv(fd, buf, len, flags); fd: File descriptor of the connected socket buf: Buffer to receive Data into len: Length of the Buffer flags: MSG_DONTWAIT, MSG_PEEK, MSG_WAITALL, ... Returns Bytes of data received on success -1 on error (and sets errno) Other APIs: read(), recvfrom(), recvmsg()
  • 23. 23© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Closing sockets To be done by both server and client On all the not-needed socket file descriptors Unless they were opened with SOCK_CLOEXEC Terminates both directions of data transfer Reading and Writing Cleans up all the socket related resources shutdown(fd, how); fd: File descriptor of the socket to be closed how: SHUT_RD, SHUT_WR, SHUT_RDWR Returns 0 on success -1 on error (and sets errno) Other API: close()
  • 24. 24© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Non-blocking Options Typical blocking system calls accept() send*(), write() recv*(), read() Achieving non-blocking behaviour Non-blocking: Socket opened with SOCK_NONBLOCK Multiplexing: Use select() or poll() or epoll() on socket fd Signal driven: Set socket to deliver SIGIO on activity Using FIOSETOWN cmd of fcntl, Or Using SIOCSPGRP cmd of ioctl
  • 25. 25© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Call 'select' Header File: <sys/select.h> int select( int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout ); File Descriptor Set APIs void FD_ZERO(fd_set *set); void FD_SET(int fd, fd_set *set); void FD_CLR(int fd, fd_set *set); int FD_ISSET(int fd, fd_set *set); Select Usage Example: pipe_window.c → pipe_window0, pipe_window1 Server-Client Pair: sock_server_select.c, sock_client.c
  • 26. 26© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Call 'poll' Header File: <poll.h> int poll( struct pollfd *array_fds, nfds_t nfds, struct timespec *timeout ); struct pollfd int fd; short events /* requested events */ short revents /* returned events */ Events: POLLIN, POLLOUT, POLLPRI Additional returned Events: POLLERR, POLLHUP, POLLNVAL
  • 27. 27© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Socket related Information cat /proc/sys/net/core/ rmem_default: Default receive buffer size rmem_max: Maximum receive buffer size wmem_default: Default send buffer size wmem_max: Maximum send buffer size … man 7 socket
  • 28. 28© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Client-Server Concepts Types of Connections Control connections Data connections Types of Servers Iterative servers (Single Process) Concurrent servers (Multi-Process)
  • 29. 29© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Iterative Servers Client Server Client Ephemeral Port Well-known Port Example: sock_server_select.c(, sock_client.c)
  • 30. 30© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Concurrent Servers Client Server Client Child Server Ephemeral Port Well-known Port Example: sock_server_concurrent.c(, sock_client.c) Child Server
  • 31. 31© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Miscellaneous Examples Named (AF_UNIX / AF_LOCAL) Sockets named_socket_server.c named_socket_client.c Multicast Operations mcast_recv.c mcast_send.c
  • 32. 32© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? W's of Networking Introduction to Sockets Networking with 'Endian' Addressing at the Layers Programming the Sockets Client-Server Concepts
  • 33. 33© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?