Page 296 - DCAP403_Operating System
P. 296

Unit 13: Case Study: Linux




          maintain hash tables which are used to lookup the addresses within incoming IP messages and   Notes
          direct them to the correct socket/sock pair. TCP is a connection oriented protocol and so there is
          more information involved in processing TCP packets than there is in processing UDP packets.
          UDP maintains a hash table of allocated UDP ports, the udp_hash table. This consists of pointers
          to sock data structures indexed by a hash function based on the port number. As the UDP hash
          table is much smaller than the number of permissible port numbers (udp_hash is only 128 or
          UDP_HTABLE_SIZE entries long) some entries in the table point to a chain of sock data structures
          linked together using each sock’s next pointer.
          TCP is much more complex as it maintains several hash tables. However, TCP does not actually
          add the binding sock data stucture into its hash tables during the bind operation, it merely checks
          that the port number requested is not currently being used. The sock data structure is added to
          TCP’s hash tables during the listen operation.

          Making a Connection on an INET BSD Socket

          Once a socket has been created and, provided it has not been used to listen for inbound connection
          requests, it can be used to make outbound connection requests. For connectionless protocols like
          UDP this socket operation does not do a whole lot but for connection orientated protocols like
          TCP it involves building a virtual circuit between two applications.

          An outbound connection can only be made on an INET BSD socket that is in the right state; that
          is to say one that does not already have a connection established and one that is not being used
          for listening for inbound connections. This means that the BSD socket data structure must be in
          state SS_UNCONNECTED. The UDP protocol does not establish virtual connections between
          applications, any messages sent are datagrams, one off messages that may or may not reach
          their destinations. It does, however, support the connect BSD socket operation. A connection
          operation on a UDP INET BSD socket simply sets up the addresses of the remote application; its
          IP address and its IP port number. Additionally it sets up a cache of the routing table entry so that
          UDP packets sent on this BSD socket do not need to check the routing database again (unless this
          route becomes invalid). The cached routing information is pointed at from the ip_route_cache
          pointer in the INET sock data structure. If no addressing information is given, this cached routing
          and IP addressing information will be automatically be used for messages sent using this BSD
          socket. UDP moves the sock’s state to TCP_ESTABLISHED.
          For a connect operation on a TCP BSD socket, TCP must build a TCP message containing
          the connection information and send it to IP destination given. The TCP message contains
          information about the connection, a unique starting message sequence number, the maximum
          sized message that can be managed by the initiating host, the transmit and receive window
          size and so on. Within TCP all messages are numbered and the initial sequence number is used

          as the  first message number. Linux chooses a reasonably random value to avoid malicious
          protocol attacks. Every message transmitted by one end of the TCP connection and successfully
          received by the other is acknowledged to say that it arrived successfully and uncorrupted.
          Unacknowledges messages will be retransmitted. The transmit and receive window size is the
          number of outstanding messages that there can be without an acknowledgement being sent. The
          maximum message size is based on the network device that is being used at the initiating end
          of the request. If the receiving end’s network device supports smaller maximum message sizes
          then the connection will use the minimum of the two. The application making the outbound TCP
          connection request must now wait for a response from the target application to accept or reject
          the connection request. As the TCP sock is now expecting incoming messages, it is added to the
          tcp_listening_hash so that incoming TCP messages can be directed to this sock data structure.
          TCP also starts timers so that the outbound connection request can be timed out if the target
          application does not respond to the request.






                                           LOVELY PROFESSIONAL UNIVERSITY                                   289
   291   292   293   294   295   296   297   298   299   300   301