linux network
DESCRIPTION
Linux Network cTRANSCRIPT
-
Introduction to Linux [email protected]
-
OutlineOSI and TCP/IP OverviewLinux Networking LayersBSD Socket InterfaceINET Socket InterfaceAn Example of Socket Programming
-
OSI OverviewOSI (Open Systems Interconnection)See Figures
-
TCP/IP Model OSI TCP/IPNot presentTCPIP
ApplicationPresentationSessionTransportNetworkData LinkPhysical
Application
TransportInternetHost-to-Network
7654321
-
TCP OverviewTCP (Transmission Control Protocol)Connection-OrientedReliable ProtocolUDP (User Datagram Protocol)ConnectionlessUnreliable Protocol
-
IP Overview32-bit Unique IP AddressNetwork Address Subnet AddressHost Address
140.112.28.XX140.112.30.XXGateway(Router)
-
IP Overview (cont.)IP Header
-
Ethernet Layer48-bit Unique Device AddressARP (Address Resolution Protocol)multicastmulticastmulticastmulticast
-
Linux Networking LayersSupport MechanismVarious Networking Inter-Process CommunicationA Special Kind of PipeSupport Several Address FamilySupport Several Socket Type
-
Addr FamilyDescriptionUNIXUnix domain socketsINETInternet address family support TCP(UDP)/IP AX25Amateur radio X25IPXNovell IPXAPPLETALKAppletalk DDPX25X25
-
Socket TypeDescriptionStreamReliable, Sequenced, Like TCPDatagramUnreliable, Not sequenced, Like UDPReliable Delivered MessagesLike datagram but reliableSequenced PacketLike Stream but fixed size packet
-
**BSD SocketsINET SocketsTCPUDPIPPPPSLIPEthernetARPUserKernelNetwork ApplicationsSocket InterfaceProtocol LayersNetwork Devices
-
Client/Server CommunicationClient1. Create a socket2. Bind an addr3. Listen the client4. Create a socketServer ConnectAcceptSendRecv
-
BSD Socket APISee An Example
-
BSD Initializationvoid __init proto_init(void)
-
The INET LayerBSD SocketA part of VFS inodeA socket can be operated just the same as a file by system call read(), write(), lseek()INET Layer use sock data structure to handle BSD socket
-
Creating a BSD SocketFor both client and serverint socket(int family, int type, int protocol)Ex. fd=Socket(AF_INET, SOCK_STREAM,0);
-
files_structcountclose_on_execopen_fsfd[0]fd[1]
fd[255]filef_modef_posf_flagsf_countf_ownerf_opf_inodef_versioninodesocksockettypeprotocoldata (sk)typeprotocolsocketSOCK_STREAMSOCK_STREAMAddress Familysocket operationsBSD SocketFile OperationslseekreadwriteselectioctlclosefasyncLinux BSD Socket Data Structure
-
Binding an AddressOnly for ServerInt bind(int sockfd, const struct sockaddr *address, size_t add_len)Port Number is optional for bindingsocket.socket_state = TCP_CLOSE;The bound socket cant be used for other communication
-
Binding an Address (cont.)The bound addr was saved in sock.rcv_saddrUDP maintains a hash table udp_hash to allocate UDP portTCP doesnt add the binding sock to hash table during binding operation
-
ListeningOnly for serverint listen(int sockfd, int queue_size)socket.socket_state = TCP_LISTEN;Add the sock to tcp_bound_hash and tcp_listening_hash
-
Listening (cont.)After receiving clients requestServer build a new sockClones the incoming sk_buff and queues it to the listening sock.receive_queue
-
ConnectingOnly for clientBefore connecting, socket.socket_state = SS_UNCONNECTED;Int connect(int csockfd, const struct sockaddr *address, size_t add_len)Add the sock to tcp_listening_hash waiting for servers response
-
AcceptingOnly for serverint accept(int sockfd, struct sockaddr *address, size_t *add_len)A new socket was cloned from the listening socket
-
Accepting (cont.)If there are no incoming connection to acceptNon-Blockingaccept operation failed and throw away the new socketBlockingaccept operation was added to the wait queue
-
sk_buffer structuretruesizelenPushPullPutTrim
nextprevdev
headdatatailend
Packet to be transmitted
-
ReferencesThe Linux Kernel, chapter 10Linux Kernel Internals, chapter 8Unix System Programming, chapter 10Computer Networks, chapter 1, 5, 6