• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Linux Network Management
 

Linux Network Management

on

  • 4,984 views

 

Statistics

Views

Total Views
4,984
Views on SlideShare
3,450
Embed Views
1,534

Actions

Likes
3
Downloads
0
Comments
3

7 Embeds 1,534

http://sysplay.in 776
http://profession.sarika-pugs.com 718
http://ivalmiki.com 18
http://www.sysplay.in 9
http://www.userspace.org 7
http://www.linkedin.com 4
https://www.linkedin.com 2
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

13 of 3 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • sir i am a trainer and i need to implement these device drivers. And i am enable to download the slides.can u mail me these to my emailid:
    rkb1128@gmail.com

    thank you sir...
    Are you sure you want to
    Your message goes here
    Processing…
  • Thanks
    Are you sure you want to
    Your message goes here
    Processing…
  • like
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Linux Network Management Linux Network Management Presentation Transcript

    • Linux Network Management © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
    • What to Expect?Ws of NetworkingIntroduction to SocketsAddressing at the LayersProgramming the SocketsClient-Server Concepts © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
    • Ws of NetworkingCommunication is the KeyUser Space & User Space Signals, IPC, Shared Address SpaceKernel Space & User Space System Calls, SignalsKernel Space & Kernel Space Kernel Communication & Synchronization MechanismsHardware Space & Kernel Space Interrupts, Device Access MechanismsWhats common in all of these? All within the same systemNetworking extends a hand outside the system © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
    • Network Stack & Sockets7 Layers Application Program Stream Datagram Socket Socket RawApplication Interface Interface SocketPresentation Interface Session TCP UDP Transport Network IP Data Link Interface Layer (Ethernet, SLIP, loopback, etc) Physical Media © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
    • Inter System Communication System I System II User Space User Space DProcess ... Process Process ... Process Socket Interface Socket Interface Kernel Space Kernel Space Hardware Space Hardware Space Network Link © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
    • ExamplesNetwork 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, ...) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
    • System DependenceWire Transmission – Bit-wise MSB firstSystem Data – Word-wise Which end first? Depends on the ProcessorTwo prevalent Endians Little Endian (x86 systems, PPC, ...) Big Endian (Sun systems, PPC, ...) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
    • Little EndianMS Byte LS Byte00101000 01111100 00101110 00101010 Data Memory 00101010 A 00101010 A+1 01111100 A+2 00101000 A+3 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
    • Big EndianMS Byte LS Byte00101000 01111100 00101110 00101010 Data Memory 00101000 A 01111100 A+1 00101110 A+2 00101010 A+3 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
    • Trivial functionsuint16_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> © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
    • Addressing at Layers Application Program User-specificApplicationPresentation Session Port Address TCP UDP (Socket Address) Transport Network IP IP Address Data Link Physical Physical Address Physical Networks (MAC Address) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
    • Socket AddressBasic Structure (16 bytes)struct sockaddr{ sa_family_t sa_family; // Protocol Family char sa_data[14]; // Protocol Address}typedef unsigned short sa_family_t; © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
    • Socket Address ...With Internet Addressstruct 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; © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
    • Socket Programming UsageSocket 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 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
    • Creating a socketfd = socket(family, type, protocol);Family AF_UNIX / AF_LOCAL, AF_INET, AF_INET6, ...Type SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ... Can be ored with SOCK_NONBLOCK, SOCK_CLOEXECProtocol Typically one per family. So, pass zeroReturns file descriptor of the new socket on success -1 on error (and sets errno) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
    • Attaching an addressDone by a serverstatus = bind(fd, addresssp, addrlen);fd: File descriptor returned by socket()addressp: Pointer to address structureaddrlen: Size of address structureReturns 0 on success -1 on error (and sets errno) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
    • Preparing for connectionsDone by a server for transport connectionsstatus = listen(fd, qlen);fd: File descriptor returned by socket()qlen Length of the pending connection queueReturns 0 on success -1 on error (and sets errno) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
    • Accepting new connectionsDone by a server for connection based socketsnewfd = accept(fd, addresssp, addrlen);fd: File descriptor returned by socket()addressp (Could be NULL) Pointer to structure of address of the connected peeraddrlen: Value-result address structure sizeBlocking call (by default), waiting for new connectionsReturns File descriptor of the new accepted socket connection -1 on error (and sets errno) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
    • Connecting to serverDone by a client for connection based socketsstatus = connect(fd, addresssp, addrlen);fd File descriptor returned by socket() to be connectedaddressp Pointer to structure of address to connect toaddrlen: Size of address structureReturns 0 on success -1 on error (and sets errno) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 19 All Rights Reserved.
    • Connection Establishment socket() socket() bind() connect()Server Application Client Application listen() accept()Transport / Network Transport / Network Layer Layer Physical Layer © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 20 All Rights Reserved.
    • Sending DataCould be done by both server and clientsent = send(fd, buf, len, flags);fd: File descriptor of the connected socketbuf: Buffer of Data to be sentlen: Length of the data to be sentflags: MSG_DONTWAIT, MSG_NOSIGNAL, ...Returns Bytes of data sent on success -1 on error (and sets errno)Other APIs: write(), sendto(), sendmsg() © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 21 All Rights Reserved.
    • Receiving DataCould be done by both server and clientreceived = recv(fd, buf, len, flags);fd: File descriptor of the connected socketbuf: Buffer to receive Data intolen: Length of the Bufferflags: MSG_DONTWAIT, MSG_PEEK, MSG_WAITALL, ...Returns Bytes of data received on success -1 on error (and sets errno)Other APIs: read(), recvfrom(), recvmsg() © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 22 All Rights Reserved.
    • Closing socketsTo be done by both server and client On all the not-needed socket file descriptors Unless they were opened with SOCK_CLOEXECTerminates both directions of data transfer Reading and WritingCleans up all the socket related resourcesshutdown(fd, how);fd: File descriptor of the socket to be closedhow: SHUT_RD, SHUT_WR, SHUT_RDWRReturns 0 on success -1 on error (and sets errno)Other API: close() © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 23 All Rights Reserved.
    • Non-blocking OptionsTypical 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 ioctlExamples Select Usage: pipe_window.c → pipe_window0, pipe_window1 Server-Client Pair: sock_server_select.c, sock_client.c © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 24 All Rights Reserved.
    • System Call selectHeader 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); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 25 All Rights Reserved.
    • System Call pollHeader 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, POLLPRIAdditional returned Events: POLLERR, POLLHUP, POLLNVAL © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 26 All Rights Reserved.
    • Socket related Informationcat /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 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 27 All Rights Reserved.
    • Client-Server ConceptsTypes of Connections Control connections Data connectionsTypes of Servers Iterative servers (Single Process) Concurrent servers (Multi-Process) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 28 All Rights Reserved.
    • Iterative ServersExample: sock_server_select.c Client Server Client Ephemeral Port Well-known Port © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 29 All Rights Reserved.
    • Concurrent ServersExample: sock_server_concurrent.c Child Child Client Server Server Server Client Ephemeral Port Well-known Port © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 30 All Rights Reserved.
    • Miscellaneous ExamplesNamed (AF_UNIX / AF_LOCAL) Sockets named_socket_server.c named_socket_client.cMulticast Operations mcast_recv.c mcast_send.c © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 31 All Rights Reserved.
    • What all have we learnt?Ws of NetworkingIntroduction to SocketsNetworking with EndianAddressing at the LayersProgramming the SocketsClient-Server Concepts © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 32 All Rights Reserved.
    • Any Queries?© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 33 All Rights Reserved.