xref: /illumos-gate/usr/src/head/protocols/routed.h (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved	*/
8 
9 /*
10  * Copyright (c) 1983, 1989, 1993
11  *	The Regents of the University of California.  All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgment:
23  *	This product includes software developed by the University of
24  *	California, Berkeley and its contributors.
25  * 4. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  */
41 
42 /*
43  * Routing Information Protocol
44  *
45  * Derived from Xerox NS Routing Information Protocol
46  * by changing 32-bit net numbers to sockaddr's and
47  * padding stuff to 32-bit boundaries.
48  */
49 
50 #ifndef _PROTOCOLS_ROUTED_H
51 #define	_PROTOCOLS_ROUTED_H
52 
53 #ifdef	__cplusplus
54 extern "C" {
55 #endif
56 
57 /* The RIPv2 protocol is described in RFC 2453 */
58 
59 #define	RIPv1		1
60 #define	RIPv2		2
61 #ifndef RIPVERSION
62 #define	RIPVERSION	RIPv1
63 #endif
64 
65 #define	RIP_PORT	520
66 
67 #if RIPVERSION == RIPv1
68 struct netinfo {
69 	struct	sockaddr rip_dst;	/* destination net/host */
70 	uint32_t   rip_metric;		/* cost of route */
71 };
72 #else
73 struct netinfo {
74 	uint16_t   n_family;
75 #define	RIP_AF_INET	htons(AF_INET)
76 #define	    RIP_AF_UNSPEC   0
77 #define	    RIP_AF_AUTH	    0xffff
78 	uint16_t   n_tag;		/* optional in RIPv2 */
79 	uint32_t   n_dst;		/* destination net or host */
80 #define	    RIP_DEFAULT	    0
81 	uint32_t   n_mask;		/* netmask in RIPv2 */
82 	uint32_t   n_nhop;		/* optional next hop in RIPv2 */
83 	uint32_t   n_metric;		/* cost of route */
84 };
85 #endif /* RIPv1 */
86 
87 /* RIPv2 authentication */
88 struct netauth {
89 	uint16_t   a_family;		/* always RIP_AF_AUTH */
90 	uint16_t   a_type;
91 #define	RIP_AUTH_NONE		0
92 #define	RIP_AUTH_TRAILER	htons(1)	/* authentication data */
93 #define	RIP_AUTH_PW		htons(2)	/* password type */
94 #define	RIP_AUTH_MD5		htons(3)	/* Keyed MD5 */
95 	union {
96 #define	    RIP_AUTH_PW_LEN 16
97 	    uint8_t    au_pw[RIP_AUTH_PW_LEN];
98 	    struct a_md5 {
99 		int16_t	md5_pkt_len;	/* RIP-II packet length */
100 		int8_t	md5_keyid;	/* key ID and auth data len */
101 		int8_t	md5_auth_len;	/* 16 */
102 		uint32_t md5_seqno;	/* sequence number */
103 		uint32_t rsvd[2];	/* must be 0 */
104 #define	    RIP_AUTH_MD5_LEN RIP_AUTH_PW_LEN
105 	    } a_md5;
106 	} au;
107 };
108 
109 struct rip_emetric {
110 	uint16_t	rip_metric;
111 	uint16_t	rip_mask;
112 	uint32_t	rip_token[1];
113 };
114 
115 struct rip_sec_entry {
116 	uint32_t	rip_dst;
117 	uint32_t	rip_count;
118 	struct rip_emetric rip_emetric[1];
119 };
120 
121 struct rip {
122 	uint8_t    rip_cmd;		/* request/response */
123 	uint8_t    rip_vers;		/* protocol version # */
124 	uint16_t   rip_res1;		/* pad to 32-bit boundary */
125 	union {				/* variable length... */
126 	    struct netinfo ru_nets[1];	/* variable length... */
127 	    char    ru_tracefile[1];	/* ditto ... */
128 	    struct netauth ru_auth[1];
129 	    struct {
130 		uint32_t rip_generation;
131 		struct rip_sec_entry rip_sec_entry[1];
132 	    } ru_tsol;
133 	} ripun;
134 #define	rip_nets	ripun.ru_nets
135 #define	rip_tracefile	ripun.ru_tracefile
136 #define	rip_auths	ripun.ru_auth
137 #define	rip_tsol	ripun.ru_tsol
138 };
139 
140 struct entryinfo {
141 	struct	sockaddr rtu_dst;
142 	struct	sockaddr rtu_router;
143 	short	rtu_flags;
144 	short	rtu_state;
145 	int	rtu_timer;
146 	int	rtu_metric;
147 	int	int_flags;
148 	char	int_name[16];
149 };
150 
151 typedef struct rdisc_info_s {
152 	uint_t  info_type;
153 	uint_t  info_version;
154 	uint_t	info_num_of_routers;
155 } rdisc_info_t;
156 
157 /*
158  * Structure that is returned with the default router info.
159  */
160 typedef struct defr_s {
161 	uint32_t	defr_info_type;
162 	uint32_t	defr_version;
163 	struct in_addr	defr_addr;
164 	uint32_t	defr_index;
165 	uint32_t	defr_life;
166 	uint32_t	defr_pref;
167 } defr_t;
168 
169 
170 /*
171  * Packet types.
172  */
173 #define	RIPCMD_REQUEST		1	/* want info - from suppliers */
174 #define	RIPCMD_RESPONSE		2	/* responding to request */
175 #define	RIPCMD_TRACEON		3	/* turn tracing on */
176 #define	RIPCMD_TRACEOFF		4	/* turn it off */
177 
178 /*
179  * Gated extended RIP to include a "poll" command instead of using
180  * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT).  RFC 1058 says
181  * command 5 is used by Sun Microsystems for its own purposes.
182  */
183 #define	RIPCMD_POLL		5	/* like request, but anyone answers */
184 #define	RIPCMD_POLLENTRY	6	/* like poll, but for entire entry */
185 
186 #define	RIPCMD_SEC_RESPONSE	51	/* response includes E-metrics */
187 #define	RIPCMD_SEC_T_RESPONSE	52	/* tunneling */
188 
189 #define	RIPCMD_MAX		7
190 
191 #define	RDISC_SNMP_SOCKET	"/var/run/in.rdisc_mib"
192 
193 #define	RDISC_SNMP_INFO_REQ		1
194 #define	RDISC_SNMP_INFO_RESPONSE	2
195 #define	RDISC_DEF_ROUTER_INFO		3
196 
197 #define	RDISC_SNMP_INFO_VER	1
198 #define	RDISC_DEF_ROUTER_VER	1
199 
200 #define	HOPCNT_INFINITY		16	/* per Xerox NS */
201 #define	MAXPACKETSIZE		512	/* max broadcast size */
202 #define	NETS_LEN ((MAXPACKETSIZE - sizeof (struct rip))	\
203 	/ sizeof (struct netinfo) +1)
204 
205 #define	INADDR_RIP_GROUP 0xe0000009U	/* 224.0.0.9 */
206 
207 /*
208  * Timer values used in managing the routing table.
209  *
210  * Complete tables are broadcast every SUPPLY_INTERVAL seconds.
211  * If changes occur between updates, dynamic updates containing only changes
212  * may be sent.  When these are sent, a timer is set for a random value
213  * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates
214  * are sent until the timer expires.
215  *
216  * Every update of a routing entry forces an entry's timer to be reset.
217  * After EXPIRE_TIME without updates, the entry is marked invalid,
218  * but held onto until GARBAGE_TIME so that others may see it, to
219  * "poison" the bad route.
220  */
221 #define	TIMER_RATE		30	/* alarm clocks every 30 seconds */
222 
223 #define	SUPPLY_INTERVAL		30	/* time to supply tables */
224 #define	MIN_WAITTIME		2	/* min sec until next flash updates */
225 #define	MAX_WAITTIME		5	/* max sec until flash update */
226 
227 #define	STALE_TIME		90	/* switch to a new gateway */
228 #define	EXPIRE_TIME		180	/* time to mark entry invalid */
229 #define	GARBAGE_TIME		300	/* time to garbage collect */
230 
231 #ifdef	__cplusplus
232 }
233 #endif
234 
235 #endif	/* _PROTOCOLS_ROUTED_H */
236