xref: /original-bsd/sys/net/route.h (revision e58c8952)
1 /*
2  * Copyright (c) 1980, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)route.h	8.3 (Berkeley) 04/19/94
8  */
9 
10 /*
11  * Kernel resident routing tables.
12  *
13  * The routing tables are initialized when interface addresses
14  * are set by making entries for all directly connected interfaces.
15  */
16 
17 /*
18  * A route consists of a destination address and a reference
19  * to a routing entry.  These are often held by protocols
20  * in their control blocks, e.g. inpcb.
21  */
22 struct route {
23 	struct	rtentry *ro_rt;
24 	struct	sockaddr ro_dst;
25 };
26 
27 /*
28  * These numbers are used by reliable protocols for determining
29  * retransmission behavior and are included in the routing structure.
30  */
31 struct rt_metrics {
32 	u_long	rmx_locks;	/* Kernel must leave these values alone */
33 	u_long	rmx_mtu;	/* MTU for this path */
34 	u_long	rmx_hopcount;	/* max hops expected */
35 	u_long	rmx_expire;	/* lifetime for route, e.g. redirect */
36 	u_long	rmx_recvpipe;	/* inbound delay-bandwith product */
37 	u_long	rmx_sendpipe;	/* outbound delay-bandwith product */
38 	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
39 	u_long	rmx_rtt;	/* estimated round trip time */
40 	u_long	rmx_rttvar;	/* estimated rtt variance */
41 	u_long	rmx_pksent;	/* packets sent using this route */
42 };
43 
44 /*
45  * rmx_rtt and rmx_rttvar are stored as microseconds;
46  * RTTTOPRHZ(rtt) converts to a value suitable for use
47  * by a protocol slowtimo counter.
48  */
49 #define	RTM_RTTUNIT	1000000	/* units for rtt, rttvar, as units per sec */
50 #define	RTTTOPRHZ(r)	((r) / (RTM_RTTUNIT / PR_SLOWHZ))
51 
52 /*
53  * We distinguish between routes to hosts and routes to networks,
54  * preferring the former if available.  For each route we infer
55  * the interface to use from the gateway address supplied when
56  * the route was entered.  Routes that forward packets through
57  * gateways are marked so that the output routines know to address the
58  * gateway rather than the ultimate destination.
59  */
60 #ifndef RNF_NORMAL
61 #include <net/radix.h>
62 #endif
63 struct rtentry {
64 	struct	radix_node rt_nodes[2];	/* tree glue, and other values */
65 #define	rt_key(r)	((struct sockaddr *)((r)->rt_nodes->rn_key))
66 #define	rt_mask(r)	((struct sockaddr *)((r)->rt_nodes->rn_mask))
67 	struct	sockaddr *rt_gateway;	/* value */
68 	short	rt_flags;		/* up/down?, host/net */
69 	short	rt_refcnt;		/* # held references */
70 	u_long	rt_use;			/* raw # packets forwarded */
71 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
72 	struct	ifaddr *rt_ifa;		/* the answer: interface to use */
73 	struct	sockaddr *rt_genmask;	/* for generation of cloned routes */
74 	caddr_t	rt_llinfo;		/* pointer to link level info cache */
75 	struct	rt_metrics rt_rmx;	/* metrics used by rx'ing protocols */
76 	struct	rtentry *rt_gwroute;	/* implied entry for gatewayed routes */
77 };
78 
79 /*
80  * Following structure necessary for 4.3 compatibility;
81  * We should eventually move it to a compat file.
82  */
83 struct ortentry {
84 	u_long	rt_hash;		/* to speed lookups */
85 	struct	sockaddr rt_dst;	/* key */
86 	struct	sockaddr rt_gateway;	/* value */
87 	short	rt_flags;		/* up/down?, host/net */
88 	short	rt_refcnt;		/* # held references */
89 	u_long	rt_use;			/* raw # packets forwarded */
90 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
91 };
92 
93 #define	RTF_UP		0x1		/* route usable */
94 #define	RTF_GATEWAY	0x2		/* destination is a gateway */
95 #define	RTF_HOST	0x4		/* host entry (net otherwise) */
96 #define	RTF_REJECT	0x8		/* host or net unreachable */
97 #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
98 #define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
99 #define RTF_DONE	0x40		/* message confirmed */
100 #define RTF_MASK	0x80		/* subnet mask present */
101 #define RTF_CLONING	0x100		/* generate new routes on use */
102 #define RTF_XRESOLVE	0x200		/* external daemon resolves name */
103 #define RTF_LLINFO	0x400		/* generated by ARP or ESIS */
104 #define RTF_STATIC	0x800		/* manually added */
105 #define RTF_BLACKHOLE	0x1000		/* just discard pkts (during updates) */
106 #define RTF_PROTO2	0x4000		/* protocol specific routing flag */
107 #define RTF_PROTO1	0x8000		/* protocol specific routing flag */
108 
109 
110 /*
111  * Routing statistics.
112  */
113 struct	rtstat {
114 	short	rts_badredirect;	/* bogus redirect calls */
115 	short	rts_dynamic;		/* routes created by redirects */
116 	short	rts_newgateway;		/* routes modified by redirects */
117 	short	rts_unreach;		/* lookups which failed */
118 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
119 };
120 /*
121  * Structures for routing messages.
122  */
123 struct rt_msghdr {
124 	u_short	rtm_msglen;	/* to skip over non-understood messages */
125 	u_char	rtm_version;	/* future binary compatibility */
126 	u_char	rtm_type;	/* message type */
127 	u_short	rtm_index;	/* index for associated ifp */
128 	int	rtm_flags;	/* flags, incl. kern & message, e.g. DONE */
129 	int	rtm_addrs;	/* bitmask identifying sockaddrs in msg */
130 	pid_t	rtm_pid;	/* identify sender */
131 	int	rtm_seq;	/* for sender to identify action */
132 	int	rtm_errno;	/* why failed */
133 	int	rtm_use;	/* from rtentry */
134 	u_long	rtm_inits;	/* which metrics we are initializing */
135 	struct	rt_metrics rtm_rmx; /* metrics themselves */
136 };
137 
138 #define RTM_VERSION	3	/* Up the ante and ignore older versions */
139 
140 #define RTM_ADD		0x1	/* Add Route */
141 #define RTM_DELETE	0x2	/* Delete Route */
142 #define RTM_CHANGE	0x3	/* Change Metrics or flags */
143 #define RTM_GET		0x4	/* Report Metrics */
144 #define RTM_LOSING	0x5	/* Kernel Suspects Partitioning */
145 #define RTM_REDIRECT	0x6	/* Told to use different route */
146 #define RTM_MISS	0x7	/* Lookup failed on this address */
147 #define RTM_LOCK	0x8	/* fix specified metrics */
148 #define RTM_OLDADD	0x9	/* caused by SIOCADDRT */
149 #define RTM_OLDDEL	0xa	/* caused by SIOCDELRT */
150 #define RTM_RESOLVE	0xb	/* req to resolve dst to LL addr */
151 #define RTM_NEWADDR	0xc	/* address being added to iface */
152 #define RTM_DELADDR	0xd	/* address being removed from iface */
153 #define RTM_IFINFO	0xe	/* iface going up/down etc. */
154 
155 #define RTV_MTU		0x1	/* init or lock _mtu */
156 #define RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
157 #define RTV_EXPIRE	0x4	/* init or lock _hopcount */
158 #define RTV_RPIPE	0x8	/* init or lock _recvpipe */
159 #define RTV_SPIPE	0x10	/* init or lock _sendpipe */
160 #define RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
161 #define RTV_RTT		0x40	/* init or lock _rtt */
162 #define RTV_RTTVAR	0x80	/* init or lock _rttvar */
163 
164 /*
165  * Bitmask values for rtm_addr.
166  */
167 #define RTA_DST		0x1	/* destination sockaddr present */
168 #define RTA_GATEWAY	0x2	/* gateway sockaddr present */
169 #define RTA_NETMASK	0x4	/* netmask sockaddr present */
170 #define RTA_GENMASK	0x8	/* cloning mask sockaddr present */
171 #define RTA_IFP		0x10	/* interface name sockaddr present */
172 #define RTA_IFA		0x20	/* interface addr sockaddr present */
173 #define RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
174 #define RTA_BRD		0x80	/* for NEWADDR, broadcast or p-p dest addr */
175 
176 /*
177  * Index offsets for sockaddr array for alternate internal encoding.
178  */
179 #define RTAX_DST	0	/* destination sockaddr present */
180 #define RTAX_GATEWAY	1	/* gateway sockaddr present */
181 #define RTAX_NETMASK	2	/* netmask sockaddr present */
182 #define RTAX_GENMASK	3	/* cloning mask sockaddr present */
183 #define RTAX_IFP	4	/* interface name sockaddr present */
184 #define RTAX_IFA	5	/* interface addr sockaddr present */
185 #define RTAX_AUTHOR	6	/* sockaddr for author of redirect */
186 #define RTAX_BRD	7	/* for NEWADDR, broadcast or p-p dest addr */
187 #define RTAX_MAX	8	/* size of array to allocate */
188 
189 struct rt_addrinfo {
190 	int	rti_addrs;
191 	struct	sockaddr *rti_info[RTAX_MAX];
192 };
193 
194 struct route_cb {
195 	int	ip_count;
196 	int	ns_count;
197 	int	iso_count;
198 	int	any_count;
199 };
200 
201 #ifdef KERNEL
202 #define	RTFREE(rt) \
203 	if ((rt)->rt_refcnt <= 1) \
204 		rtfree(rt); \
205 	else \
206 		(rt)->rt_refcnt--;
207 
208 struct	route_cb route_cb;
209 struct	rtstat	rtstat;
210 struct	radix_node_head *rt_tables[AF_MAX+1];
211 
212 void	 route_init __P((void));
213 int	 route_output __P((struct mbuf *, struct socket *));
214 int	 route_usrreq __P((struct socket *,
215 	    int, struct mbuf *, struct mbuf *, struct mbuf *));
216 void	 rt_ifmsg __P((struct ifnet *));
217 void	 rt_maskedcopy __P((struct sockaddr *,
218 	    struct sockaddr *, struct sockaddr *));
219 void	 rt_missmsg __P((int, struct rt_addrinfo *, int, int));
220 void	 rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *));
221 int	 rt_setgate __P((struct rtentry *,
222 	    struct sockaddr *, struct sockaddr *));
223 void	 rt_setmetrics __P((u_long, struct rt_metrics *, struct rt_metrics *));
224 void	 rtable_init __P((void **));
225 void	 rtalloc __P((struct route *));
226 struct rtentry *
227 	 rtalloc1 __P((struct sockaddr *, int));
228 void	 rtfree __P((struct rtentry *));
229 int	 rtinit __P((struct ifaddr *, int, int));
230 int	 rtioctl __P((int, caddr_t, struct proc *));
231 int	 rtredirect __P((struct sockaddr *, struct sockaddr *,
232 	    struct sockaddr *, int, struct sockaddr *, struct rtentry **));
233 int	 rtrequest __P((int, struct sockaddr *,
234 	    struct sockaddr *, struct sockaddr *, int, struct rtentry **));
235 #endif
236