|
|
1.1 root 1: /*
2: * Copyright (c) 1980, 1986 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution is only permitted until one year after the first shipment
6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7: * binary forms are permitted provided that: (1) source distributions retain
8: * this entire copyright notice and comment, and (2) distributions including
9: * binaries display the following acknowledgement: This product includes
10: * software developed by the University of California, Berkeley and its
11: * contributors'' in the documentation or other materials provided with the
12: * distribution and in all advertising materials mentioning features or use
13: * of this software. Neither the name of the University nor the names of
14: * its contributors may be used to endorse or promote products derived from
15: * this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: *
20: * @(#)route.h 7.11 (Berkeley) 6/28/90
21: */
22:
23: /*
24: * Kernel resident routing tables.
25: *
26: * The routing tables are initialized when interface addresses
27: * are set by making entries for all directly connected interfaces.
28: */
29:
30: /*
31: * A route consists of a destination address and a reference
32: * to a routing entry. These are often held by protocols
33: * in their control blocks, e.g. inpcb.
34: */
35: struct route {
36: struct rtentry *ro_rt;
37: struct sockaddr ro_dst;
38: };
39:
40: /*
41: * These numbers are used by reliable protocols for determining
42: * retransmission behavior and are included in the routing structure.
43: */
44: struct rt_metrics {
45: u_long rmx_locks; /* Kernel must leave these values alone */
46: u_long rmx_mtu; /* MTU for this path */
47: u_long rmx_hopcount; /* max hops expected */
48: u_long rmx_expire; /* lifetime for route, e.g. redirect */
49: u_long rmx_recvpipe; /* inbound delay-bandwith product */
50: u_long rmx_sendpipe; /* outbound delay-bandwith product */
51: u_long rmx_ssthresh; /* outbound gateway buffer limit */
52: u_long rmx_rtt; /* estimated round trip time */
53: u_long rmx_rttvar; /* estimated rtt variance */
54: };
55:
56: /*
57: * rmx_rtt and rmx_rttvar are stored as microseconds;
58: * RTTTOPRHZ(rtt) converts to a value suitable for use
59: * by a protocol slowtimo counter.
60: */
61: #define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
62: #define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
63:
64: /*
65: * We distinguish between routes to hosts and routes to networks,
66: * preferring the former if available. For each route we infer
67: * the interface to use from the gateway address supplied when
68: * the route was entered. Routes that forward packets through
69: * gateways are marked so that the output routines know to address the
70: * gateway rather than the ultimate destination.
71: */
72: #include "radix.h"
73: struct rtentry {
74: struct radix_node rt_nodes[2]; /* tree glue, and other values */
75: #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key))
76: #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask))
77: struct sockaddr *rt_gateway; /* value */
78: short rt_flags; /* up/down?, host/net */
79: short rt_refcnt; /* # held references */
80: u_long rt_use; /* raw # packets forwarded */
81: struct ifnet *rt_ifp; /* the answer: interface to use */
82: struct ifaddr *rt_ifa; /* the answer: interface to use */
83: struct sockaddr *rt_genmask; /* for generation of cloned routes */
84: caddr_t rt_llinfo; /* pointer to link level info cache */
85: struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */
86: short rt_idle; /* easy to tell llayer still live */
87: };
88:
89: /*
90: * Following structure necessary for 4.3 compatibility;
91: * We should eventually move it to a compat file.
92: */
93: struct ortentry {
94: u_long rt_hash; /* to speed lookups */
95: struct sockaddr rt_dst; /* key */
96: struct sockaddr rt_gateway; /* value */
97: short rt_flags; /* up/down?, host/net */
98: short rt_refcnt; /* # held references */
99: u_long rt_use; /* raw # packets forwarded */
100: struct ifnet *rt_ifp; /* the answer: interface to use */
101: };
102:
103: #define RTF_UP 0x1 /* route useable */
104: #define RTF_GATEWAY 0x2 /* destination is a gateway */
105: #define RTF_HOST 0x4 /* host entry (net otherwise) */
106: #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
107: #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
108: #define RTF_DONE 0x40 /* message confirmed */
109: #define RTF_MASK 0x80 /* subnet mask present */
110: #define RTF_CLONING 0x100 /* generate new routes on use */
111: #define RTF_XRESOLVE 0x200 /* external daemon resolves name */
112: #define RTF_LLINFO 0x400 /* generated by ARP or ESIS */
113:
114:
115: /*
116: * Routing statistics.
117: */
118: struct rtstat {
119: short rts_badredirect; /* bogus redirect calls */
120: short rts_dynamic; /* routes created by redirects */
121: short rts_newgateway; /* routes modified by redirects */
122: short rts_unreach; /* lookups which failed */
123: short rts_wildcard; /* lookups satisfied by a wildcard */
124: };
125: /*
126: * Structures for routing messages.
127: */
128: struct rt_msghdr {
129: u_short rtm_msglen; /* to skip over non-understood messages */
130: u_char rtm_version; /* future binary compatability */
131: u_char rtm_type; /* message type */
132: u_short rtm_index; /* index for associated ifp */
133: pid_t rtm_pid; /* identify sender */
134: int rtm_addrs; /* bitmask identifying sockaddrs in msg */
135: int rtm_seq; /* for sender to identify action */
136: int rtm_errno; /* why failed */
137: int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
138: int rtm_use; /* from rtentry */
139: u_long rtm_inits; /* which metrics we are initializing */
140: struct rt_metrics rtm_rmx; /* metrics themselves */
141: };
142:
143: struct route_cb {
144: int ip_count;
145: int ns_count;
146: int iso_count;
147: int any_count;
148: };
149: #define RTM_VERSION 2 /* Up the ante and ignore older versions */
150:
151: #define RTM_ADD 0x1 /* Add Route */
152: #define RTM_DELETE 0x2 /* Delete Route */
153: #define RTM_CHANGE 0x3 /* Change Metrics or flags */
154: #define RTM_GET 0x4 /* Report Metrics */
155: #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
156: #define RTM_REDIRECT 0x6 /* Told to use different route */
157: #define RTM_MISS 0x7 /* Lookup failed on this address */
158: #define RTM_LOCK 0x8 /* fix specified metrics */
159: #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
160: #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
161: #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
162:
163: #define RTV_MTU 0x1 /* init or lock _mtu */
164: #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
165: #define RTV_EXPIRE 0x4 /* init or lock _hopcount */
166: #define RTV_RPIPE 0x8 /* init or lock _recvpipe */
167: #define RTV_SPIPE 0x10 /* init or lock _sendpipe */
168: #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
169: #define RTV_RTT 0x40 /* init or lock _rtt */
170: #define RTV_RTTVAR 0x80 /* init or lock _rttvar */
171:
172: #define RTA_DST 0x1 /* destination sockaddr present */
173: #define RTA_GATEWAY 0x2 /* gateway sockaddr present */
174: #define RTA_NETMASK 0x4 /* netmask sockaddr present */
175: #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
176: #define RTA_IFP 0x10 /* interface name sockaddr present */
177: #define RTA_IFA 0x20 /* interface addr sockaddr present */
178: #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
179:
180: #ifdef KERNEL
181: struct route_cb route_cb;
182: #endif
183:
184: #ifdef KERNEL
185: #define RTFREE(rt) \
186: if ((rt)->rt_refcnt <= 1) \
187: rtfree(rt); \
188: else \
189: (rt)->rt_refcnt--;
190:
191: #ifdef GATEWAY
192: #define RTHASHSIZ 64
193: #else
194: #define RTHASHSIZ 8
195: #endif
196: #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0
197: #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1))
198: #else
199: #define RTHASHMOD(h) ((h) % RTHASHSIZ)
200: #endif
201: struct mbuf *rthost[RTHASHSIZ];
202: struct mbuf *rtnet[RTHASHSIZ];
203: struct rtstat rtstat;
204: struct rtentry *rtalloc1();
205: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.