1 Protocols                                               route(7P)
   2 
   3 
   4 
   5 NAME
   6      route - kernel packet forwarding database
   7 
   8 SYNOPSIS
   9      #include <sys/types.h>
  10      #include <sys/socket.h>
  11      #include <net/if.h>
  12      #include <net/route.h>
  13 
  14      int socket(PF_ROUTE, SOCK_RAW, int protocol);
  15 
  16 
  17 DESCRIPTION
  18      UNIX provides some packet  routing  facilities.  The  kernel
  19      maintains  a  routing information database, which is used in
  20      selecting the appropriate network interface  when  transmit-
  21      ting packets.
  22 
  23 
  24      A user process (or possibly multiple co-operating processes)
  25      maintains  this  database by sending messages over a special
  26      kind of socket. This supplants fixed size ioctl(2)'s  speci-
  27      fied in  routing(7P). Routing table changes may only be car-
  28      ried out by the superuser.
  29 
  30 
  31      The operating system may spontaneously emit routing messages
  32      in  response  to  external  events, such as receipt of a re-
  33      direct, or failure to locate a suitable route for a request.
  34      The message types are described in greater detail below.
  35 
  36 
  37      Routing database entries come in two flavors: entries for  a
  38      specific host, or entries for all hosts on a generic subnet-
  39      work (as specified by a bit mask and value under the  mask).
  40      The  effect  of wildcard or default route may be achieved by
  41      using a mask of all zeros, and  there  may  be  hierarchical
  42      routes.
  43 
  44 
  45      When the system is booted and addresses are assigned to  the
  46      network  interfaces, the internet protocol family installs a
  47      routing table entry for each interface when it is ready  for
  48      traffic.  Normally  the protocol specifies the route through
  49      each interface as a direct  connection  to  the  destination
  50      host  or  network.   If  the  route is direct, the transport
  51      layer of a protocol family usually requests  the  packet  be
  52      sent  to  the same host specified in the packet.  Otherwise,
  53      the interface is requested to  address  the  packet  to  the
  54      gateway  listed in the routing entry, that is, the packet is
  55      forwarded.
  56 
  57 
  58 
  59 
  60 SunOS 5.11          Last change: 25 July 2006                   1
  61 
  62 
  63 
  64 
  65 
  66 
  67 Protocols                                               route(7P)
  68 
  69 
  70 
  71      When routing a packet, the kernel attempts to find  the most
  72      specific  route  matching  the  destination.  If no entry is
  73      found, the destination is declared to be unreachable, and  a
  74      routing-miss message is generated if there are any listeners
  75      on the routing control socket (described  below).  If  there
  76      are  two  different mask and value-under-the-mask pairs that
  77      match, the more specific is the one with more  bits  in  the
  78      mask. A route to a host is regarded as being supplied with a
  79      mask of as many ones as there are bits in the destination.
  80 
  81 
  82      A wildcard routing entry is specified with a  zero  destina-
  83      tion  address  value,  and  a  mask  of all zeroes. Wildcard
  84      routes are used when the system fails to find  other  routes
  85      matching the destination. The combination of wildcard routes
  86      and routing redirects can provide  an  economical  mechanism
  87      for routing traffic.
  88 
  89 
  90      One opens the channel for passing routing  control  messages
  91      by using the socket call shown in the   section above. There
  92      can be more than one routing socket open per system.
  93 
  94 
  95      Messages are formed by a header followed by a  small  number
  96      of  sockaddrs,  whose  length depend on the address  family.
  97      sockaddrs are interpreted by position. An example of a  type
  98      of  message  with  three  addresses  might be a  CIDR prefix
  99      route: Destination, Netmask, and Gateway. The interpretation
 100      of which addresses are present is given by a bit mask within
 101      the header, and the sequence is least  significant  to  most
 102      significant bit within the vector.
 103 
 104 
 105      Any messages sent to the kernel are returned, and copies are
 106      sent  to  all interested listeners.  The kernel provides the
 107      process ID of the sender, and the sender may  use  an  addi-
 108      tional  sequence  field  to  distinguish between outstanding
 109      messages.  However, message replies may be lost when  kernel
 110      buffers are exhausted.
 111 
 112 
 113      The protocol parameter specifies which messages an  applica-
 114      tion  listening  on the routing socket is interested in see-
 115      ing, based on  the  the  address  family  of  the  sockaddrs
 116      present. Currently, you can specify AF_INET and AF_INET6  to
 117      filter the messages seen by the listener, or  alternatively,
 118      you  can specify AF_UNSPEC  to indicate that the listener is
 119      interested in all routing messages.
 120 
 121 
 122 
 123 
 124 
 125 
 126 SunOS 5.11          Last change: 25 July 2006                   2
 127 
 128 
 129 
 130 
 131 
 132 
 133 Protocols                                               route(7P)
 134 
 135 
 136 
 137      The kernel may reject certain messages,  and  will  indicate
 138      this  by  filling  in  the  rtm_errno field of the rt_msghdr
 139      struct (see below). The following codes may be returned:
 140 
 141      EEXIST     If requested to duplicate an existing entry
 142 
 143 
 144      ESRCH      If requested to delete a non-existent entry
 145 
 146 
 147      ENOBUFS    If  insufficient  resources  were  available   to
 148                 install a new route.
 149 
 150 
 151      EPERM      If the calling process does not have  appropriate
 152                 privileges to alter the routing table.
 153 
 154 
 155 
 156      In the current implementation,  all  routing  processes  run
 157      locally,  and the values for rtm_errno are available through
 158      the normal errno mechanism, even if the routing  reply  mes-
 159      sage is lost.
 160 
 161 
 162      A process may avoid the expense of reading  replies  to  its
 163      own  messages by issuing a setsockopt(3SOCKET) call indicat-
 164      ing that the SO_USELOOPBACK option at the  SOL_SOCKET  level
 165      is  to be turned off. A process may ignore all messages from
 166      the routing socket by doing a  shutdown(3SOCKET) system call
 167      for further input.
 168 
 169 
 170      If a route is in use when it is deleted, the  routing  entry
 171      is  marked  down and removed from the routing table, but the
 172      resources associated with it are  not  reclaimed  until  all
 173      references to it are released.
 174 
 175 
 176      The RTM_IFINFO, RTM_NEWADDR, and RTM_ADD messages associated
 177      with  interface  configuration  (setting the IFF_UP bit) are
 178      normally delayed until  after  Duplicate  Address  Detection
 179      completes.  Thus, applications that configure interfaces and
 180      wish to  wait until the interface is ready  can  wait  until
 181      RTM_IFINFO   is   returned   and  SIOCGLIFFLAGS  shows  that
 182      IFF_DUPLICATE is not set.
 183 
 184   Messages
 185      User processes can  obtain  information  about  the  routing
 186      entry to a specific destination by using a RTM_GET message.
 187 
 188 
 189 
 190 
 191 
 192 SunOS 5.11          Last change: 25 July 2006                   3
 193 
 194 
 195 
 196 
 197 
 198 
 199 Protocols                                               route(7P)
 200 
 201 
 202 
 203      Messages include:
 204 
 205        #define RTM_ADD      0x1   /* Add Route */
 206        #define RTM_DELETE   0x2   /* Delete Route */
 207        #define RTM_CHANGE   0x3   /* Change Metrics, Flags, or Gateway */
 208        #define RTM_GET      0x4   /* Report Information */
 209        #define RTM_LOSING   0x5   /* Kernel Suspects Partitioning */
 210        #define RTM_REDIRECT 0x6   /* Told to use different route */
 211        #define RTM_MISS     0x7   /* Lookup failed on this address */
 212        #define RTM_LOCK     0x8   /* fix specified metrics */
 213        #define RTM_OLDADD   0x9   /* caused by SIOCADDRT */
 214        #define RTM_OLDDEL   0xa   /* caused by SIOCDELRT */
 215        #define RTM_RESOLVE  0xb   /* request to resolve dst to LL addr */
 216        #define RTM_NEWADDR  0xc   /* address being added to iface */
 217        #define RTM_DELADDR  0xd   /* address being removed from iface */
 218        #define RTM_IFINFO   0xe   /* iface going up/down etc. */
 219 
 220 
 221 
 222      A message header consists of:
 223 
 224        struct rt_msghdr {
 225         ushort_t rtm_msglen;    /* to skip over non-understood messages */
 226         uchar_t  rtm_version;   /* future binary compatibility */
 227         uchar_t  rtm_type;      /* message type */
 228         ushort_t rtm_index;     /* index for associated ifp */
 229         pid_t   rtm_pid;        /* identify sender */
 230         int     rtm_addrs;      /* bitmask identifying sockaddrs in msg */
 231         int     rtm_seq;        /* for sender to identify action */
 232         int     rtm_errno;      /* why failed */
 233         int     rtm_flags;      /*  flags,  incl  kern  &  message, e.g., DONE */
 234         int     rtm_use;        /* from rtentry */
 235         uint_t  rtm_inits;      /* which values we are initializing */
 236 
 237        struct  rt_metrics rtm_rmx;   /* metrics themselves */
 238            };
 239 
 240 
 241 
 242      where
 243 
 244        struct rt_metrics {
 245         uint32_t rmx_locks;      /* Kernel must leave  these  values alone */
 246         uint32_t rmx_mtu;        /* MTU for this path */
 247         uint32_t rmx_hopcount;   /* max hops expected */
 248         uint32_t rmx_expire;     /* lifetime for route, e.g., redirect */
 249         uint32_t rmx_recvpipe;   /* inbound delay-bandwidth  product */
 250         uint32_t rmx_sendpipe;   /* outbound delay-bandwidth product */
 251         uint32_t rmx_ssthresh;   /* outbound gateway buffer limit */
 252         uint32_t rmx_rtt;        /* estimated round trip time */
 253         uint32_t rmx_rttvar;     /* estimated rtt variance */
 254         uint32_t rmx_pksent;     /* packets sent using this route */
 255 
 256 
 257 
 258 SunOS 5.11          Last change: 25 July 2006                   4
 259 
 260 
 261 
 262 
 263 
 264 
 265 Protocols                                               route(7P)
 266 
 267 
 268 
 269        };
 270 
 271        /* Flags include the values */
 272 
 273 
 274        #define RTF_UP         0x1     /* route usable */
 275        #define RTF_GATEWAY    0x2     /* destination is a gateway */
 276        #define RTF_HOST       0x4     /* host entry (net otherwise) */
 277        #define RTF_REJECT     0x8     /* host or net unreachable */
 278        #define RTF_DYNAMIC    0x10    /* created dynamically(by redirect) */
 279        #define RTF_MODIFIED   0x20    /* modified dynamically(by redirect) */
 280        #define RTF_DONE       0x40    /* message confirmed */
 281        #define RTF_MASK       0x80    /* subnet mask present */
 282        #define RTF_CLONING    0x100   /* generate new routes on use */
 283        #define RTF_XRESOLVE   0x200   /* external daemon resolves name */
 284        #define RTF_LLINFO     0x400   /* generated by ARP */
 285        #define RTF_STATIC     0x800   /* manually added */
 286        #define RTF_BLACKHOLE  0x1000  /* just discard pkts (during updates) */
 287        #define RTF_PRIVATE    0x2000  /* do not advertise this route */
 288        #define RTF_PROTO2     0x4000  /* protocol specific routing flag #2 */
 289        #define RTF_PROTO1     0x8000  /* protocol specific routing flag #1 */
 290 
 291        /* Specifiers for metric values in rmx_locks and rtm_inits are */
 292 
 293        #define RTV_MTU        0x1     /* init or lock _mtu */
 294        #define RTV_HOPCOUNT   0x2     /* init or lock _hopcount */
 295        #define RTV_EXPIRE     0x4     /* init or lock _expire */
 296        #define RTV_RPIPE      0x8     /* init or lock _recvpipe */
 297        #define RTV_SPIPE      0x10    /* init or lock _sendpipe */
 298        #define RTV_SSTHRESH   0x20    /* init or lock _ssthresh */
 299        #define RTV_RTT        0x40    /* init or lock _rtt */
 300        #define RTV_RTTVAR     0x80    /* init or lock _rttvar */
 301 
 302        /* Specifiers for which addresses are present in  the  messages are */
 303 
 304        #define RTA_DST        0x1     /* destination sockaddr present */
 305        #define RTA_GATEWAY    0x2     /* gateway sockaddr present */
 306        #define RTA_NETMASK    0x4     /* netmask sockaddr present */
 307        #define RTA_GENMASK    0x8     /* cloning mask sockaddr present */
 308        #define RTA_IFP        0x10    /* interface name sockaddr present */
 309        #define RTA_IFA        0x20    /* interface addr sockaddr present */
 310        #define RTA_AUTHOR     0x40    /* sockaddr for author of redirect */
 311        #define RTA_BRD        0x80    /* for NEWADDR, broadcast or p-p dest addr */
 312 
 313 
 314 SEE ALSO
 315      ioctl(2),      setsockopt(3SOCKET),       shutdown(3SOCKET),
 316      routing(7P)
 317 
 318 NOTES
 319      Some of the metrics may not be implemented and return  zero.
 320      The implemented metrics are set in rtm_inits.
 321 
 322 
 323 
 324 SunOS 5.11          Last change: 25 July 2006                   5
 325 
 326 
 327