Annotation of sys/net/route.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: route.h,v 1.46 2006/06/18 11:47:45 pascoe Exp $ */
2: /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
3:
4: /*
5: * Copyright (c) 1980, 1986, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. Neither the name of the University nor the names of its contributors
17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
32: * @(#)route.h 8.3 (Berkeley) 4/19/94
33: */
34:
35: #ifndef _NET_ROUTE_H_
36: #define _NET_ROUTE_H_
37:
38: #include <sys/queue.h>
39:
40: /*
41: * Kernel resident routing tables.
42: *
43: * The routing tables are initialized when interface addresses
44: * are set by making entries for all directly connected interfaces.
45: */
46:
47: /*
48: * A route consists of a destination address and a reference
49: * to a routing entry. These are often held by protocols
50: * in their control blocks, e.g. inpcb.
51: */
52: struct route {
53: struct rtentry *ro_rt;
54: struct sockaddr ro_dst;
55: };
56:
57: /*
58: * These numbers are used by reliable protocols for determining
59: * retransmission behavior and are included in the routing structure.
60: */
61: struct rt_kmetrics {
62: u_long rmx_locks; /* Kernel must leave these values alone */
63: u_long rmx_mtu; /* MTU for this path */
64: u_long rmx_expire; /* lifetime for route, e.g. redirect */
65: u_long rmx_pksent; /* packets sent using this route */
66: };
67:
68: /*
69: * Huge version for userland compatibility.
70: */
71: struct rt_metrics {
72: u_long rmx_locks; /* Kernel must leave these values alone */
73: u_long rmx_mtu; /* MTU for this path */
74: u_long rmx_hopcount; /* max hops expected */
75: u_long rmx_expire; /* lifetime for route, e.g. redirect */
76: u_long rmx_recvpipe; /* inbound delay-bandwidth product */
77: u_long rmx_sendpipe; /* outbound delay-bandwidth product */
78: u_long rmx_ssthresh; /* outbound gateway buffer limit (deprecated) */
79: u_long rmx_rtt; /* estimated round trip time (deprecated) */
80: u_long rmx_rttvar; /* estimated rtt variance (deprecated) */
81: u_long rmx_pksent; /* packets sent using this route */
82: };
83: /* XXX overloading some values that are no longer used. */
84: #define rmx_refcnt rmx_rttvar /* # held references only used by sysctl */
85: #define rmx_rt_tableid rmx_rtt /* routing table ID */
86:
87: /*
88: * rmx_rtt and rmx_rttvar are stored as microseconds;
89: * RTTTOPRHZ(rtt) converts to a value suitable for use
90: * by a protocol slowtimo counter.
91: */
92: #define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
93: #define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
94:
95: /*
96: * We distinguish between routes to hosts and routes to networks,
97: * preferring the former if available. For each route we infer
98: * the interface to use from the gateway address supplied when
99: * the route was entered. Routes that forward packets through
100: * gateways are marked so that the output routines know to address the
101: * gateway rather than the ultimate destination.
102: */
103: #ifndef RNF_NORMAL
104: #include <net/radix.h>
105: #include <net/radix_mpath.h>
106: #endif
107: struct rtentry {
108: struct radix_node rt_nodes[2]; /* tree glue, and other values */
109: #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key))
110: #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask))
111: struct sockaddr *rt_gateway; /* value */
112: u_int rt_flags; /* up/down?, host/net */
113: int rt_refcnt; /* # held references */
114: struct ifnet *rt_ifp; /* the answer: interface to use */
115: struct ifaddr *rt_ifa; /* the answer: interface to use */
116: struct sockaddr *rt_genmask; /* for generation of cloned routes */
117: caddr_t rt_llinfo; /* pointer to link level info cache */
118: struct rt_kmetrics rt_rmx; /* metrics used by rx'ing protocols */
119: struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
120: struct rtentry *rt_parent; /* If cloned, parent of this route. */
121: LIST_HEAD(, rttimer) rt_timer; /* queue of timeouts for misc funcs */
122: u_int16_t rt_labelid; /* route label ID */
123: };
124: #define rt_use rt_rmx.rmx_pksent
125:
126: #define RTF_UP 0x1 /* route usable */
127: #define RTF_GATEWAY 0x2 /* destination is a gateway */
128: #define RTF_HOST 0x4 /* host entry (net otherwise) */
129: #define RTF_REJECT 0x8 /* host or net unreachable */
130: #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
131: #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
132: #define RTF_DONE 0x40 /* message confirmed */
133: #define RTF_MASK 0x80 /* subnet mask present */
134: #define RTF_CLONING 0x100 /* generate new routes on use */
135: #define RTF_XRESOLVE 0x200 /* external daemon resolves name */
136: #define RTF_LLINFO 0x400 /* generated by ARP or ESIS */
137: #define RTF_STATIC 0x800 /* manually added */
138: #define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
139: #define RTF_PROTO3 0x2000 /* protocol specific routing flag */
140: #define RTF_PROTO2 0x4000 /* protocol specific routing flag */
141: #define RTF_PROTO1 0x8000 /* protocol specific routing flag */
142: #define RTF_CLONED 0x10000 /* this is a cloned route */
143: #define RTF_SOURCE 0x20000 /* this route has a source selector */
144: #define RTF_MPATH 0x40000 /* multipath route or operation */
145: #define RTF_JUMBO 0x80000 /* try to use jumbo frames */
146:
147: /* mask of RTF flags that are allowed to be modified by RTM_CHANGE */
148: #define RTF_FMASK \
149: (RTF_JUMBO | RTF_PROTO1 | RTF_PROTO2 | RTF_PROTO3 | RTF_BLACKHOLE | \
150: RTF_REJECT | RTF_STATIC)
151:
152: #ifndef _KERNEL
153: /* obsoleted */
154: #define RTF_TUNNEL 0x100000 /* Tunnelling bit. */
155: #endif
156:
157: /*
158: * Routing statistics.
159: */
160: struct rtstat {
161: u_int32_t rts_badredirect; /* bogus redirect calls */
162: u_int32_t rts_dynamic; /* routes created by redirects */
163: u_int32_t rts_newgateway; /* routes modified by redirects */
164: u_int32_t rts_unreach; /* lookups which failed */
165: u_int32_t rts_wildcard; /* lookups satisfied by a wildcard */
166: };
167:
168: /*
169: * Structures for routing messages.
170: */
171: struct rt_msghdr {
172: u_short rtm_msglen; /* to skip over non-understood messages */
173: u_char rtm_version; /* future binary compatibility */
174: u_char rtm_type; /* message type */
175: u_short rtm_index; /* index for associated ifp */
176: int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
177: int rtm_addrs; /* bitmask identifying sockaddrs in msg */
178: pid_t rtm_pid; /* identify sender */
179: int rtm_seq; /* for sender to identify action */
180: int rtm_errno; /* why failed */
181: int rtm_use; /* deprecated use rtm_rmx->rmx_pksent */
182: #define rtm_fmask rtm_use /* bitmask used in RTM_CHANGE message */
183: u_long rtm_inits; /* which metrics we are initializing */
184: struct rt_metrics rtm_rmx; /* metrics themselves */
185: };
186: /* overload no longer used field */
187: #define rtm_tableid rtm_rmx.rmx_rt_tableid
188:
189: #define RTM_VERSION 3 /* Up the ante and ignore older versions */
190:
191: #define RTM_ADD 0x1 /* Add Route */
192: #define RTM_DELETE 0x2 /* Delete Route */
193: #define RTM_CHANGE 0x3 /* Change Metrics or flags */
194: #define RTM_GET 0x4 /* Report Metrics */
195: #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
196: #define RTM_REDIRECT 0x6 /* Told to use different route */
197: #define RTM_MISS 0x7 /* Lookup failed on this address */
198: #define RTM_LOCK 0x8 /* fix specified metrics */
199: #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
200: #define RTM_NEWADDR 0xc /* address being added to iface */
201: #define RTM_DELADDR 0xd /* address being removed from iface */
202: #define RTM_IFINFO 0xe /* iface going up/down etc. */
203: #define RTM_IFANNOUNCE 0xf /* iface arrival/departure */
204:
205: #define RTV_MTU 0x1 /* init or lock _mtu */
206: #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
207: #define RTV_EXPIRE 0x4 /* init or lock _hopcount */
208: #define RTV_RPIPE 0x8 /* init or lock _recvpipe */
209: #define RTV_SPIPE 0x10 /* init or lock _sendpipe */
210: #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
211: #define RTV_RTT 0x40 /* init or lock _rtt */
212: #define RTV_RTTVAR 0x80 /* init or lock _rttvar */
213:
214: /*
215: * Bitmask values for rtm_addr.
216: */
217: #define RTA_DST 0x1 /* destination sockaddr present */
218: #define RTA_GATEWAY 0x2 /* gateway sockaddr present */
219: #define RTA_NETMASK 0x4 /* netmask sockaddr present */
220: #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
221: #define RTA_IFP 0x10 /* interface name sockaddr present */
222: #define RTA_IFA 0x20 /* interface addr sockaddr present */
223: #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
224: #define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
225: #define RTA_SRC 0x100 /* source sockaddr present */
226: #define RTA_SRCMASK 0x200 /* source netmask present */
227: #define RTA_LABEL 0x400 /* route label present */
228:
229: /*
230: * Index offsets for sockaddr array for alternate internal encoding.
231: */
232: #define RTAX_DST 0 /* destination sockaddr present */
233: #define RTAX_GATEWAY 1 /* gateway sockaddr present */
234: #define RTAX_NETMASK 2 /* netmask sockaddr present */
235: #define RTAX_GENMASK 3 /* cloning mask sockaddr present */
236: #define RTAX_IFP 4 /* interface name sockaddr present */
237: #define RTAX_IFA 5 /* interface addr sockaddr present */
238: #define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
239: #define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
240: #define RTAX_SRC 8 /* source sockaddr present */
241: #define RTAX_SRCMASK 9 /* source netmask present */
242: #define RTAX_LABEL 10 /* route label present */
243: #define RTAX_MAX 11 /* size of array to allocate */
244:
245: struct rt_addrinfo {
246: int rti_addrs;
247: struct sockaddr *rti_info[RTAX_MAX];
248: int rti_flags;
249: struct ifaddr *rti_ifa;
250: struct ifnet *rti_ifp;
251: struct rt_msghdr *rti_rtm;
252: };
253:
254: struct route_cb {
255: int ip_count;
256: int ip6_count;
257: int any_count;
258: };
259:
260: /*
261: * This structure, and the prototypes for the rt_timer_{init,remove_all,
262: * add,timer} functions all used with the kind permission of BSDI.
263: * These allow functions to be called for routes at specific times.
264: */
265:
266: struct rttimer {
267: TAILQ_ENTRY(rttimer) rtt_next; /* entry on timer queue */
268: LIST_ENTRY(rttimer) rtt_link; /* multiple timers per rtentry */
269: struct rttimer_queue *rtt_queue;/* back pointer to queue */
270: struct rtentry *rtt_rt; /* Back pointer to the route */
271: void (*rtt_func)(struct rtentry *,
272: struct rttimer *);
273: time_t rtt_time; /* When this timer was registered */
274: };
275:
276: struct rttimer_queue {
277: long rtq_timeout;
278: unsigned long rtq_count;
279: TAILQ_HEAD(, rttimer) rtq_head;
280: LIST_ENTRY(rttimer_queue) rtq_link;
281: };
282:
283: #define RTLABEL_LEN 32
284:
285: struct sockaddr_rtlabel {
286: u_int8_t sr_len; /* total length */
287: sa_family_t sr_family; /* address family */
288: char sr_label[RTLABEL_LEN];
289: };
290:
291: #define RT_TABLEID_MAX 255
292:
293: #ifdef _KERNEL
294: const char *rtlabel_id2name(u_int16_t);
295: u_int16_t rtlabel_name2id(char *);
296: void rtlabel_unref(u_int16_t);
297:
298: #define RTFREE(rt) do { \
299: if ((rt)->rt_refcnt <= 1) \
300: rtfree(rt); \
301: else \
302: (rt)->rt_refcnt--; \
303: } while (0)
304:
305: /*
306: * Values for additional argument to rtalloc_noclone() and rtalloc2()
307: */
308: #define ALL_CLONING 0
309: #define ONNET_CLONING 1
310: #define NO_CLONING 2
311:
312: extern struct route_cb route_cb;
313: extern struct rtstat rtstat;
314: extern const struct sockaddr_rtin rt_defmask4;
315:
316: struct socket;
317: void route_init(void);
318: int rtable_add(u_int);
319: int rtable_exists(u_int);
320: int route_output(struct mbuf *, ...);
321: int route_usrreq(struct socket *, int, struct mbuf *,
322: struct mbuf *, struct mbuf *);
323: void rt_ifmsg(struct ifnet *);
324: void rt_ifannouncemsg(struct ifnet *, int);
325: void rt_maskedcopy(struct sockaddr *,
326: struct sockaddr *, struct sockaddr *);
327: void rt_missmsg(int, struct rt_addrinfo *, int, struct ifnet *, int,
328: u_int);
329: void rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *);
330: int rt_setgate(struct rtentry *, struct sockaddr *,
331: struct sockaddr *, u_int);
332: void rt_setmetrics(u_long, struct rt_metrics *, struct rt_kmetrics *);
333: void rt_getmetrics(struct rt_kmetrics *, struct rt_metrics *);
334: int rt_timer_add(struct rtentry *,
335: void(*)(struct rtentry *, struct rttimer *),
336: struct rttimer_queue *);
337: void rt_timer_init(void);
338: struct rttimer_queue *
339: rt_timer_queue_create(u_int);
340: void rt_timer_queue_change(struct rttimer_queue *, long);
341: void rt_timer_queue_destroy(struct rttimer_queue *, int);
342: void rt_timer_remove_all(struct rtentry *);
343: unsigned long rt_timer_count(struct rttimer_queue *);
344: void rt_timer_timer(void *);
345: void rtalloc(struct route *);
346: #ifdef SMALL_KERNEL
347: #define rtalloc_mpath(r, s, t) rtalloc(r)
348: #endif
349: struct rtentry *
350: rtalloc1(struct sockaddr *, int, u_int);
351: void rtalloc_noclone(struct route *, int);
352: struct rtentry *
353: rtalloc2(struct sockaddr *, int, int);
354: void rtfree(struct rtentry *);
355: int rt_getifa(struct rt_addrinfo *);
356: int rtinit(struct ifaddr *, int, int);
357: int rtioctl(u_long, caddr_t, struct proc *);
358: void rtredirect(struct sockaddr *, struct sockaddr *,
359: struct sockaddr *, int, struct sockaddr *,
360: struct rtentry **);
361: int rtrequest(int, struct sockaddr *,
362: struct sockaddr *, struct sockaddr *, int,
363: struct rtentry **, u_int);
364: int rtrequest1(int, struct rt_addrinfo *, struct rtentry **, u_int);
365: void rt_if_remove(struct ifnet *);
366:
367: struct radix_node_head *rt_gettable(sa_family_t, u_int);
368: struct radix_node *rt_lookup(struct sockaddr *, struct sockaddr *, int);
369: #endif /* _KERNEL */
370: #endif /* _NET_ROUTE_H_ */
CVSweb