Everything Penguin

Focusing on Linux-based Operating Systems
htDig Search:

Operating Systems
  • /pub/OS/Linux

  • Storage
  • File Systems
  • HPC
  • /pub/Storage

  • Networking
  • /pub/Networking

  • Network Services
  • /pub/NetworkServices

  • Security
  • /pub/Security
  • Keytool/OpenSSL

  • Clustering
  • HA
  • DRM

  • Development
  • Design
  • C/C++
  • Java
  • Perl
  • Python
  • Shell
  • Web / J2EE

  • Not Linux ?
  • BSD
  • HP-UX
  • Mac
  • Solaris
  • VM
  • Windows
  • /pub/OS

  • Other
  • /pub
  • /pub/3rdParty
  •  Parent Directory

    Packet Routing
    Brett Lee
    How does the OS determine where to route the packet?
    Short answer:
        It checks the routing table.
    Long answer:
    1.  First, the OS has to determine the destination IP address that is
        contained in the IP header.
    2.  Next, it checks the routes in its routing table and finds the
        longest match.  Routes are sorted from longest to shortest.
        * By longest, this means the greatest amount of network bits.
          - matching 25 bits has precidence over matching 24 bits.
    How does it check each route?
    Short answer:
        It does a bitwise "and".
    Long answer:
        Say you are a router with a packet to route and some possible routes.
          Sorts the routes by network length (longest first).
          Compare destination IP to networks using bitwise "AND".
            A bitwise AND reveals if the destination matches the network route bits.
          First match wins, and traffic sent to the gateway for that network.
        For example, a comparison could be:
          Destination =
          Network Route 1 = ( /24 ) == 11000000.10101000.00000001.00000000
          Network Route 2 = ( /16 ) == 11000000.10101000.00000000.00000000
 ^ =
          11000000.10101000.00000001.00000010 ^ 11000000.10101000.00000001.00000000 =
          11000000.10101000.00000001.00000010 ^
          11000000.10101000.00000001.00000000 =
          So, match on network, so send it to the gateway for that network.
    What if nothing matches?
      Send it out the default gateway.
    What if there is no default gateway?
      If acting as a router for other hosts:
        Send back an ICMP "Destination Unreachable"
      If acting as originating host for the traffic:
        Return an error to application.
      What kind of error?
        Hmmm.  If IP, maybe a socket() error?  If not IP, ???

    Other Sites

  • FAQ's
  • IETF
  • RFC Sourcebook

  • Linux
  • Linux - Intro
  • Linux Kernel
  • Linux Kernel (LKML)
  • Bash - Intro
  • Bash - Advanced
  • Command Line
  • System Administration
  • Network Administration
  • Man Pages (& more)
  • More Guides
  • Red Hat Manuals
  • HOWTO's

  • Reference/Tutorials
  • C++ @ cppreference
  • C++ @ cplusplus
  • CSS @ echoecho
  • DNS @ Zytrax
  • HTML @ W3 Schools
  • Java @ Sun
  • LDAP @ Zytrax
  • Linux @ YoLinux
  • MySQL
  • NetFilter
  • Network Protocols
  • OpenLDAP
  • Quagga
  • Samba
  • Unix Programming

  • This site contains many of my notes from research into different aspects of the Linux kernel as well as some of the software provided by GNU and others. Thouugh these notes are not fully comprehensive or even completetly accurate, they are part of my on-going attempt to better understand this complex field. And, they are your to use.

    Should you wish to report any errors or suggestions, please let me know.

    Should you wish to make a donation for anything you may have learned here, please direct that donation to the ASPCA, with my sincere thanks.

    Brett Lee
    Everything Penguin

    The code for this site, which is just a few CGI scripts, may be found on GitHub (https://github.com/userbrett/cgindex).

    For both data encryption and password protection, try Personal Data Security (https://www.trustpds.com).

    "We left all that stuff out. If there's an error, we have this routine called 'panic', and when its called, the machine crashes, and you holler down the hall, 'Hey, reboot it.'"

        - Dennis Ritchie on Unix (vs Multics)

    [ Powered by Red Hat Linux ] [ Powered by Apache Server] [ Powered by MySQL ]

    [ Statistics by AWStats ]