xref: /csrg-svn/sys/net/route.h (revision 40788)
123164Smckusick /*
229070Smckusick  * Copyright (c) 1980, 1986 Regents of the University of California.
333183Sbostic  * All rights reserved.
423164Smckusick  *
533183Sbostic  * Redistribution and use in source and binary forms are permitted
634844Sbostic  * provided that the above copyright notice and this paragraph are
734844Sbostic  * duplicated in all such forms and that any documentation,
834844Sbostic  * advertising materials, and other materials related to such
934844Sbostic  * distribution and use acknowledge that the software was developed
1034844Sbostic  * by the University of California, Berkeley.  The name of the
1134844Sbostic  * University may not be used to endorse or promote products derived
1234844Sbostic  * from this software without specific prior written permission.
1334844Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434844Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534844Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633183Sbostic  *
17*40788Ssklower  *	@(#)route.h	7.8 (Berkeley) 04/05/90
1823164Smckusick  */
196332Ssam 
206332Ssam /*
216412Ssam  * Kernel resident routing tables.
226412Ssam  *
2324776Skarels  * The routing tables are initialized when interface addresses
2424776Skarels  * are set by making entries for all directly connected interfaces.
256332Ssam  */
266332Ssam 
277156Swnj /*
287156Swnj  * A route consists of a destination address and a reference
297156Swnj  * to a routing entry.  These are often held by protocols
307156Swnj  * in their control blocks, e.g. inpcb.
317156Swnj  */
326332Ssam struct route {
336332Ssam 	struct	rtentry *ro_rt;
346332Ssam 	struct	sockaddr ro_dst;
356332Ssam };
366332Ssam 
376332Ssam /*
38*40788Ssklower  * These numbers are used by reliable protocols for determining
39*40788Ssklower  * retransmission behavior and are included in the routing structure.
40*40788Ssklower  */
41*40788Ssklower struct rt_metrics {
42*40788Ssklower 	u_long	rmx_locks;	/* Kernel must leave these values alone */
43*40788Ssklower 	u_long	rmx_mtu;	/* MTU for this path */
44*40788Ssklower 	u_long	rmx_hopcount;	/* max hops expected */
45*40788Ssklower 	u_long	rmx_expire;	/* lifetime for route, e.g. redirect */
46*40788Ssklower 	u_long	rmx_recvpipe;	/* inbound delay-bandwith product */
47*40788Ssklower 	u_long	rmx_sendpipe;	/* outbound delay-bandwith product */
48*40788Ssklower 	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
49*40788Ssklower 	u_long	rmx_rtt;	/* estimated round trip time */
50*40788Ssklower 	u_long	rmx_rttvar;	/* estimated rtt variance */
51*40788Ssklower };
52*40788Ssklower 
53*40788Ssklower /*
547156Swnj  * We distinguish between routes to hosts and routes to networks,
557156Swnj  * preferring the former if available.  For each route we infer
567156Swnj  * the interface to use from the gateway address supplied when
577156Swnj  * the route was entered.  Routes that forward packets through
587156Swnj  * gateways are marked so that the output routines know to address the
597156Swnj  * gateway rather than the ultimate destination.
606332Ssam  */
6136354Ssklower #include "radix.h"
627156Swnj struct rtentry {
6336354Ssklower 	struct	radix_node rt_nodes[2];	/* tree glue, and other values */
6436354Ssklower #define	rt_key(r)	((struct sockaddr *)((r)->rt_nodes->rn_key))
6536354Ssklower #define	rt_mask(r)	((struct sockaddr *)((r)->rt_nodes->rn_mask))
6636354Ssklower 	struct	sockaddr *rt_gateway;	/* value */
6736354Ssklower 	short	rt_flags;		/* up/down?, host/net */
6836354Ssklower 	short	rt_refcnt;		/* # held references */
6936354Ssklower 	u_long	rt_use;			/* raw # packets forwarded */
7036354Ssklower 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
7137472Ssklower 	struct	ifaddr *rt_ifa;		/* the answer: interface to use */
7240445Ssklower 	struct	sockaddr *rt_genmask;	/* for generation of cloned routes */
7340445Ssklower 	caddr_t	rt_llinfo;		/* pointer to link level info cache */
74*40788Ssklower 	struct	rt_metrics rt_rmx;	/* metrics used by rx'ing protocols */
7536354Ssklower };
7636354Ssklower 
7736354Ssklower /*
7836354Ssklower  * Following structure necessary for 4.3 compatibility;
7936354Ssklower  * We should eventually move it to a compat file.
8036354Ssklower  */
8136354Ssklower struct ortentry {
827156Swnj 	u_long	rt_hash;		/* to speed lookups */
837156Swnj 	struct	sockaddr rt_dst;	/* key */
847156Swnj 	struct	sockaddr rt_gateway;	/* value */
857156Swnj 	short	rt_flags;		/* up/down?, host/net */
867156Swnj 	short	rt_refcnt;		/* # held references */
877156Swnj 	u_long	rt_use;			/* raw # packets forwarded */
887156Swnj 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
897156Swnj };
907156Swnj 
916339Ssam #define	RTF_UP		0x1		/* route useable */
927156Swnj #define	RTF_GATEWAY	0x2		/* destination is a gateway */
936377Ssam #define	RTF_HOST	0x4		/* host entry (net otherwise) */
9424776Skarels #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
9530396Skarels #define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
9636354Ssklower #define RTF_DONE	0x40		/* message confirmed */
9736354Ssklower #define RTF_MASK	0x80		/* subnet mask present */
9840445Ssklower #define RTF_CLONING	0x100		/* generate new routes on use */
9940445Ssklower #define RTF_XRESOLVE	0x200		/* external daemon resolves name */
1006332Ssam 
10136354Ssklower 
10212832Ssam /*
10312832Ssam  * Routing statistics.
10412832Ssam  */
10512832Ssam struct	rtstat {
10612832Ssam 	short	rts_badredirect;	/* bogus redirect calls */
10712832Ssam 	short	rts_dynamic;		/* routes created by redirects */
10812832Ssam 	short	rts_newgateway;		/* routes modified by redirects */
10912832Ssam 	short	rts_unreach;		/* lookups which failed */
11012832Ssam 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
11112832Ssam };
11236354Ssklower /*
11336354Ssklower  * Structures for routing messages.
11436354Ssklower  */
11536354Ssklower struct rt_msghdr {
11636354Ssklower 	u_short	rtm_msglen;	/* to skip over non-understood messages */
11736354Ssklower 	u_char	rtm_version;	/* future binary compatability */
11836354Ssklower 	u_char	rtm_type;	/* message type */
119*40788Ssklower 	u_short	rtm_index;	/* index for associated ifp */
12036354Ssklower 	pid_t	rtm_pid;	/* identify sender */
121*40788Ssklower 	int	rtm_addrs;	/* bitmask identifying sockaddrs in msg */
12236354Ssklower 	int	rtm_seq;	/* for sender to identify action */
12336354Ssklower 	int	rtm_errno;	/* why failed */
12436354Ssklower 	int	rtm_flags;	/* flags, incl. kern & message, e.g. DONE */
125*40788Ssklower 	int	rtm_use;	/* from rtentry */
126*40788Ssklower 	u_long	rtm_inits;	/* which metrics we are initializing */
127*40788Ssklower 	struct	rt_metrics rtm_rmx; /* metrics themselves */
12836354Ssklower };
12936354Ssklower 
13036354Ssklower struct route_cb {
13136354Ssklower 	int	ip_count;
13236354Ssklower 	int	ns_count;
13336354Ssklower 	int	iso_count;
13436354Ssklower 	int	any_count;
13536354Ssklower };
136*40788Ssklower #define RTM_VERSION	2	/* Up the ante and ignore older versions */
13736354Ssklower 
13836354Ssklower #define RTM_ADD		0x1	/* Add Route */
13936354Ssklower #define RTM_DELETE	0x2	/* Delete Route */
14036354Ssklower #define RTM_CHANGE	0x3	/* Change Metrics or flags */
14136354Ssklower #define RTM_GET		0x4	/* Report Metrics */
14236354Ssklower #define RTM_LOSING	0x5	/* Kernel Suspects Partitioning */
14336354Ssklower #define RTM_REDIRECT	0x6	/* Told to use different route */
14436354Ssklower #define RTM_MISS	0x7	/* Lookup failed on this address */
14536354Ssklower #define RTM_LOCK	0x8	/* fix specified metrics */
14636354Ssklower #define RTM_OLDADD	0x9	/* caused by SIOCADDRT */
14736354Ssklower #define RTM_OLDDEL	0xa	/* caused by SIOCDELRT */
14840445Ssklower #define RTM_RESOLVE	0xb	/* req to resolve dst to LL addr */
14936354Ssklower 
15036354Ssklower #define RTV_MTU		0x1	/* init or lock _mtu */
15136354Ssklower #define RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
15236354Ssklower #define RTV_EXPIRE	0x4	/* init or lock _hopcount */
15336354Ssklower #define RTV_RPIPE	0x8	/* init or lock _recvpipe */
15436354Ssklower #define RTV_SPIPE	0x10	/* init or lock _sendpipe */
15536354Ssklower #define RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
15636354Ssklower #define RTV_RTT		0x40	/* init or lock _rtt */
15736354Ssklower #define RTV_RTTVAR	0x80	/* init or lock _rttvar */
15836354Ssklower 
159*40788Ssklower #define RTA_DST		0x1	/* destination sockaddr present */
160*40788Ssklower #define RTA_GATEWAY	0x2	/* gateway sockaddr present */
161*40788Ssklower #define RTA_NETMASK	0x4	/* netmask sockaddr present */
162*40788Ssklower #define RTA_GENMASK	0x8	/* cloning mask sockaddr present */
163*40788Ssklower #define RTA_IFP		0x10	/* interface name sockaddr present */
164*40788Ssklower #define RTA_IFA		0x20	/* interface addr sockaddr present */
165*40788Ssklower #define RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
166*40788Ssklower 
16712832Ssam #ifdef KERNEL
16836354Ssklower struct route_cb route_cb;
16936354Ssklower #endif
17036354Ssklower 
17136354Ssklower #ifdef KERNEL
1726412Ssam #define	RTFREE(rt) \
17340445Ssklower 	if ((rt)->rt_refcnt <= 1) \
1746412Ssam 		rtfree(rt); \
1756412Ssam 	else \
1766412Ssam 		(rt)->rt_refcnt--;
17712832Ssam 
17817067Skarels #ifdef	GATEWAY
17917067Skarels #define	RTHASHSIZ	64
18017067Skarels #else
18116554Skarels #define	RTHASHSIZ	8
18217067Skarels #endif
18316554Skarels #if	(RTHASHSIZ & (RTHASHSIZ - 1)) == 0
18416554Skarels #define RTHASHMOD(h)	((h) & (RTHASHSIZ - 1))
18516554Skarels #else
18616554Skarels #define RTHASHMOD(h)	((h) % RTHASHSIZ)
18716554Skarels #endif
18812832Ssam struct	mbuf *rthost[RTHASHSIZ];
18912832Ssam struct	mbuf *rtnet[RTHASHSIZ];
19012832Ssam struct	rtstat	rtstat;
19136354Ssklower struct	rtentry *rtalloc1();
19212832Ssam #endif
193