xref: /csrg-svn/share/man/man4/route.4 (revision 63008)
1*63008Sbostic.\" Copyright (c) 1990, 1991, 1993
2*63008Sbostic.\"	The Regents of the University of California.  All rights reserved.
342485Ssklower.\"
442485Ssklower.\" %sccs.include.redist.man%
542485Ssklower.\"
6*63008Sbostic.\"     @(#)route.4	8.1 (Berkeley) 06/09/93
742485Ssklower.\"
847675Scael.Dd
947675Scael.Dt ROUTE 4
1047675Scael.Os
1147675Scael.Sh NAME
1247675Scael.Nm route
1347675Scael.Nd kernel packet forwarding database
1447675Scael.Sh SYNOPSIS
1547675Scael.Fd #include <sys/socket.h>
1647675Scael.Fd #include <net/if.h>
1747675Scael.Fd #include <net/route.h>
1847675Scael.Ft int
1947675Scael.Fn socket PF_ROUTE SOCK_RAW "int family"
2047675Scael.Sh DESCRIPTION
2147675Scael.Tn UNIX
2242485Ssklowerprovides some packet routing facilities.
2342485SsklowerThe kernel maintains a routing information database, which
2442485Sskloweris used in selecting the appropriate network interface when
2542485Ssklowertransmitting packets.
2647675Scael.Pp
2742485SsklowerA user process (or possibly multiple co-operating processes)
2842485Ssklowermaintains this database by sending messages over a special kind
2942485Ssklowerof socket.
3042485SsklowerThis supplants fixed size
3147675Scael.Xr ioctl 2 Ns 's
3242485Ssklowerused in earlier releases.
3342485SsklowerRouting table changes may only be carried out by the super user.
3447675Scael.Pp
3542485SsklowerThe operating system may spontaneously emit routing messages in response
3642485Ssklowerto external events, such as recipt of a re-direct, or failure to
3742485Ssklowerlocate a suitable route for a request.
3842485SsklowerThe message types are described in greater detail below.
3947675Scael.Pp
4042487SsklowerRouting database entries come in two flavors: for a specific
4142487Ssklowerhost, or for all hosts on a generic subnetwork (as specified
4242487Ssklowerby a bit mask and value under the mask.
4342487SsklowerThe effect of wildcard or default route may be achieved by using
4442487Ssklowera mask of all zeros, and there may be hierarchical routes.
4547675Scael.Pp
4642485SsklowerWhen the system is booted and addresses are assigned
4742485Ssklowerto the network interfaces, each protocol family
4842485Ssklowerinstalls a routing table entry for each interface when it is ready for traffic.
4942485SsklowerNormally the protocol specifies the route
5047675Scaelthrough each interface as a
5147675Scael.Dq direct
5247675Scaelconnection to the destination host
5342485Sskloweror network.  If the route is direct, the transport layer of
5442485Ssklowera protocol family usually requests the packet be sent to the
5542485Ssklowersame host specified in the packet.  Otherwise, the interface
5642485Sskloweris requested to address the packet to the gateway listed in the routing entry
5742485Ssklower(i.e. the packet is forwarded).
5847675Scael.Pp
5942485SsklowerWhen routing a packet,
6042485Ssklowerthe kernel will first attempt to find a route to the destination host.
6142485SsklowerFailing that, a search is made for a route to the network of the destination.
6247675ScaelFinally, any route to a default
6347675Scael.Pq Dq wildcard
6447675Scaelgateway is chosen.
6542485SsklowerIf no entry is found, the destination is declared to be unreachable,
6642485Ssklowerand a routing\-miss message is generated if there are any
6742485Ssklowerlisters on the routing control socket described below.
6847675Scael.Pp
6942485SsklowerA wildcard routing entry is specified with a zero
7042485Ssklowerdestination address value.  Wildcard routes are used
7142485Sskloweronly when the system fails to find a route to the
7242485Ssklowerdestination host and network.  The combination of wildcard
7342485Ssklowerroutes and routing redirects can provide an economical
7442485Ssklowermechanism for routing traffic.
7547675Scael.Pp
7642485SsklowerOne opens the channel for passing routing control messasges
7742485Ssklowerby using the socket call shown in the synopsis above:
7847675Scael.Pp
7947675ScaelThe
8047675Scael.Fa family
8147675Scaelparamter may be
8247675Scael.Dv AF_UNSPEC
8347675Scaelwhich will provide
8442485Ssklowerrouting information for all address families, or can be restricted
8542485Ssklowerto a specific address family by specifying which one is desired.
8642485SsklowerThere can be more than one routing socket open per system.
8747675Scael.Pp
8842485SsklowerMessages are formed by a header followed by a small
8942485Ssklowernumber of sockadders (now variable length particularly
9047675Scaelin the
9147675Scael.Tn ISO
9247675Scaelcase), interpreted by position, and delimited
9342485Ssklowerby the new length entry in the sockaddr.
9447675ScaelAn example of a message with four addresses might be an
9547675Scael.Tn ISO
9647675Scaelredirect:
9742485SsklowerDestination, Netmask, Gateway, and Author of the redirect.
9842485SsklowerThe interpretation of which address are present is given by a
9942485Ssklowerbit mask within the header, and the sequence is least significant
10042485Ssklowerto most significant bit within the vector.
10147675Scael.Pp
10242485SsklowerAny messages sent to the kernel are returned, and copies are sent
10342485Ssklowerto all interested listeners.  The kernel will provide the process
10442485Ssklowerid. for the sender, and the sender may use an additional sequence
10542485Ssklowerfield to distinguish between outstanding messages.  However,
10642485Ssklowermessage replies may be lost when kernel buffers are exhausted.
10747675Scael.Pp
10842485SsklowerThe kernel may reject certain messages, and will indicate this
10947675Scaelby filling in the
11047675Scael.Ar rtm_errno
11147675Scaelfield.
11247675ScaelThe routing code returns
11347675Scael.Dv EEXIST
11447675Scaelif
11547675Scaelrequested to duplicate an existing entry,
11647675Scael.Dv ESRCH
11747675Scaelif
11842485Ssklowerrequested to delete a non-existent entry,
11947675Scaelor
12047675Scael.Dv ENOBUFS
12147675Scaelif insufficient resources were available
12242485Ssklowerto install a new route.
12342485SsklowerIn the current implementation, all routing process run locally,
12447675Scaeland the values for
12547675Scael.Ar rtm_errno
12647675Scaelare available through the normal
12747675Scael.Em errno
12847675Scaelmechanism, even if the routing reply message is lost.
12947675Scael.Pp
13042485SsklowerA process may avoid the expense of reading replies to
13142485Ssklowerits own messages by issuing a
13247675Scael.Xr setsockopt 2
13347675Scaelcall indicating that the
13447675Scael.Dv SO_USELOOPBACK
13547675Scaeloption
13647675Scaelat the
13747675Scael.Dv SOL_SOCKET
13847675Scaellevel is to be turned off.
13942485SsklowerA process may ignore all messages from the routing socket
14042485Ssklowerby doing a
14147675Scael.Xr shutdown 2
14242485Ssklowersystem call for further input.
14347675Scael.Pp
14442485SsklowerIf a route is in use when it is deleted,
14542485Ssklowerthe routing entry will be marked down and removed from the routing table,
14642485Ssklowerbut the resources associated with it will not
14742485Ssklowerbe reclaimed until all references to it are released.
14842485SsklowerUser processes can obtain information about the routing
14947675Scaelentry to a specific destination by using a
15047675Scael.Dv RTM_GET
15147675Scaelmessage,
15242485Sskloweror by reading the
15347675Scael.Pa /dev/kmem
15442485Ssklowerdevice, or by issuing a
15547675Scael.Xr getkerninfo 2
15642485Ssklowersystem call.
15747675Scael.Pp
15842485SsklowerMessages include:
15947675Scael.Bd -literal
16047675Scael#define	RTM_ADD		0x1    /* Add Route */
16147675Scael#define	RTM_DELETE	0x2    /* Delete Route */
16247675Scael#define	RTM_CHANGE	0x3    /* Change Metrics, Flags, or Gateway */
16347675Scael#define	RTM_GET		0x4    /* Report Information */
16447675Scael#define	RTM_LOOSING	0x5    /* Kernel Suspects Partitioning */
16547675Scael#define	RTM_REDIRECT	0x6    /* Told to use different route */
16647675Scael#define	RTM_MISS	0x7    /* Lookup failed on this address */
16747675Scael#define	RTM_RESOLVE	0xb    /* request to resolve dst to LL addr */
16847675Scael.Ed
16947675Scael.Pp
17042485SsklowerA message header consists of:
17147675Scael.Bd -literal
17242485Ssklowerstruct rt_msghdr {
17347675Scael    u_short rmt_msglen;  /* to skip over non-understood messages */
17447675Scael    u_char  rtm_version; /* future binary compatability */
17547675Scael    u_char  rtm_type;    /* message type */
17647675Scael    u_short rmt_index;   /* index for associated ifp */
17747675Scael    pid_t   rmt_pid;     /* identify sender */
17847675Scael    int     rtm_addrs;   /* bitmask identifying sockaddrs in msg */
17947675Scael    int     rtm_seq;     /* for sender to identify action */
18047675Scael    int     rtm_errno;   /* why failed */
18147675Scael    int     rtm_flags;   /* flags, incl kern & message, e.g. DONE */
18247675Scael    int     rtm_use;     /* from rtentry */
18347675Scael    u_long  rtm_inits;   /* which values we are initializing */
18447675Scael    struct  rt_metrics rtm_rmx;	/* metrics themselves */
18542485Ssklower};
18647675Scael.Ed
18747675Scael.Pp
18842485Ssklowerwhere
18947675Scael.Bd -literal
19042485Ssklowerstruct rt_metrics {
19147675Scael    u_long rmx_locks;     /* Kernel must leave these values alone */
19247675Scael    u_long rmx_mtu;       /* MTU for this path */
19347675Scael    u_long rmx_hopcount;  /* max hops expected */
19447675Scael    u_long rmx_expire;    /* lifetime for route, e.g. redirect */
19547675Scael    u_long rmx_recvpipe;  /* inbound delay-bandwith product */
19647675Scael    u_long rmx_sendpipe;  /* outbound delay-bandwith product */
19747675Scael    u_long rmx_ssthresh;  /* outbound gateway buffer limit */
19847675Scael    u_long rmx_rtt;       /* estimated round trip time */
19947675Scael    u_long rmx_rttvar;    /* estimated rtt variance */
20042485Ssklower};
20147675Scael.Ed
20247675Scael.Pp
20342485SsklowerFlags include the values:
20447675Scael.Bd -literal
20547675Scael#define	RTF_UP        0x1    /* route useable */
20647675Scael#define	RTF_GATEWAY   0x2    /* destination is a gateway */
20747675Scael#define	RTF_HOST      0x4    /* host entry (net otherwise) */
20847675Scael#define	RTF_NORMAL    0x8    /* subnet mask is cannonical */
20947675Scael#define	RTF_DYNAMIC   0x10   /* created dynamically (by redirect) */
21047675Scael#define	RTF_MODIFIED  0x20   /* modified dynamically (by redirect) */
21147675Scael#define	RTF_DONE      0x40   /* message confirmed */
21247675Scael#define	RTF_MASK      0x80   /* subnet mask present */
21347675Scael.Ed
21447675Scael.Pp
21542485SsklowerSpecfiers for metric values in rmx_locks and rtm_inits are:
21647675Scael.Bd -literal
21747675Scael#define	RTV_SSTHRESH  0x1    /* init or lock _ssthresh */
21847675Scael#define	RTV_RPIPE     0x2    /* init or lock _recvpipe */
21947675Scael#define	RTV_SPIPE     0x4    /* init or lock _sendpipe */
22047675Scael#define	RTV_HOPCOUNT  0x8    /* init or lock _hopcount */
22147675Scael#define	RTV_RTT       0x10   /* init or lock _rtt */
22247675Scael#define	RTV_RTTVAR    0x20   /* init or lock _rttvar */
22347675Scael#define	RTV_MTU       0x40   /* init or lock _mtu */
22447675Scael.Ed
22547675Scael.Pp
22642485SsklowerSpecifiers for which addresses are present in the messages are:
22747675Scael.Bd -literal
22847675Scael#define RTA_DST       0x1    /* destination sockaddr present */
22947675Scael#define RTA_GATEWAY   0x2    /* gateway sockaddr present */
23047675Scael#define RTA_NETMASK   0x4    /* netmask sockaddr present */
23147675Scael#define RTA_GENMASK   0x8    /* cloning mask sockaddr present */
23247675Scael#define RTA_IFP       0x10   /* interface name sockaddr present */
23347675Scael#define RTA_IFA       0x20   /* interface addr sockaddr present */
23447675Scael#define RTA_AUTHOR    0x40   /* sockaddr for author of redirect */
23547675Scael.Ed
236