xref: /freebsd/include/protocols/routed.h (revision 5a1d14419a5b620430949a46cb6ee63148a43cb9)
159deaec5SRodney W. Grimes /*-
2*2321c474SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*2321c474SPedro F. Giffuni  *
459deaec5SRodney W. Grimes  * Copyright (c) 1983, 1989, 1993
559deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
659deaec5SRodney W. Grimes  *
759deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
859deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
959deaec5SRodney W. Grimes  * are met:
1059deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1159deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1259deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1359deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1459deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
152cca9f8fSWarner Losh  * 3. Neither the name of the University nor the names of its contributors
1659deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
1759deaec5SRodney W. Grimes  *    without specific prior written permission.
1859deaec5SRodney W. Grimes  *
1959deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2059deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2159deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2259deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2359deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2459deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2559deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2659deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2759deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2859deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2959deaec5SRodney W. Grimes  * SUCH DAMAGE.
30c39ebb1dSBruce M Simpson  *	$Revision: 2.26 $
3159deaec5SRodney W. Grimes  */
3259deaec5SRodney W. Grimes 
33703f5993SGarrett Wollman #ifndef _ROUTED_H_
34703f5993SGarrett Wollman #define	_ROUTED_H_
35703f5993SGarrett Wollman #ifdef __cplusplus
36703f5993SGarrett Wollman extern "C" {
37703f5993SGarrett Wollman #endif
3859deaec5SRodney W. Grimes 
3959deaec5SRodney W. Grimes /*
4059deaec5SRodney W. Grimes  * Routing Information Protocol
4159deaec5SRodney W. Grimes  *
4259deaec5SRodney W. Grimes  * Derived from Xerox NS Routing Information Protocol
4359deaec5SRodney W. Grimes  * by changing 32-bit net numbers to sockaddr's and
4459deaec5SRodney W. Grimes  * padding stuff to 32-bit boundaries.
4559deaec5SRodney W. Grimes  */
4659deaec5SRodney W. Grimes 
47703f5993SGarrett Wollman #define	RIPv1		1
48703f5993SGarrett Wollman #define	RIPv2		2
49703f5993SGarrett Wollman #ifndef RIPVERSION
50703f5993SGarrett Wollman #define	RIPVERSION	RIPv1
51703f5993SGarrett Wollman #endif
52703f5993SGarrett Wollman 
53703f5993SGarrett Wollman #define RIP_PORT	520
54703f5993SGarrett Wollman 
55703f5993SGarrett Wollman #if RIPVERSION == 1
56703f5993SGarrett Wollman /* Note that this so called sockaddr has a 2-byte sa_family and no sa_len.
57703f5993SGarrett Wollman  * It is not a UNIX sockaddr, but the shape of an address as defined
5883f9002eSGarrett Wollman  * in RIPv1.  It is still defined to allow old versions of programs
5983f9002eSGarrett Wollman  * such as `gated` to use this file to define RIPv1.
60703f5993SGarrett Wollman  */
6159deaec5SRodney W. Grimes struct netinfo {
6259deaec5SRodney W. Grimes 	struct	sockaddr rip_dst;	/* destination net/host */
6383f9002eSGarrett Wollman 	u_int32_t   rip_metric;		/* cost of route */
6459deaec5SRodney W. Grimes };
65703f5993SGarrett Wollman #else
66703f5993SGarrett Wollman struct netinfo {
6783f9002eSGarrett Wollman 	u_int16_t   n_family;
68703f5993SGarrett Wollman #define	    RIP_AF_INET	    htons(AF_INET)
69703f5993SGarrett Wollman #define	    RIP_AF_UNSPEC   0
70703f5993SGarrett Wollman #define	    RIP_AF_AUTH	    0xffff
7183f9002eSGarrett Wollman 	u_int16_t   n_tag;		/* optional in RIPv2 */
7283f9002eSGarrett Wollman 	u_int32_t   n_dst;		/* destination net or host */
73703f5993SGarrett Wollman #define	    RIP_DEFAULT	    0
7483f9002eSGarrett Wollman 	u_int32_t   n_mask;		/* netmask in RIPv2 */
7583f9002eSGarrett Wollman 	u_int32_t   n_nhop;		/* optional next hop in RIPv2 */
7683f9002eSGarrett Wollman 	u_int32_t   n_metric;		/* cost of route */
77703f5993SGarrett Wollman };
78703f5993SGarrett Wollman #endif
79703f5993SGarrett Wollman 
80703f5993SGarrett Wollman /* RIPv2 authentication */
81703f5993SGarrett Wollman struct netauth {
822832011fSGarrett Wollman 	u_int16_t   a_family;		/* always RIP_AF_AUTH */
8383f9002eSGarrett Wollman 	u_int16_t   a_type;
842832011fSGarrett Wollman #define	    RIP_AUTH_NONE   0
85703f5993SGarrett Wollman #define	    RIP_AUTH_PW	    htons(2)	/* password type */
862832011fSGarrett Wollman #define	    RIP_AUTH_MD5    htons(3)	/* Keyed MD5 */
87703f5993SGarrett Wollman 	union {
88703f5993SGarrett Wollman #define	    RIP_AUTH_PW_LEN 16
892832011fSGarrett Wollman 	    u_int8_t    au_pw[RIP_AUTH_PW_LEN];
902832011fSGarrett Wollman 	    struct a_md5 {
912832011fSGarrett Wollman 		int16_t	md5_pkt_len;	/* RIP-II packet length */
922832011fSGarrett Wollman 		int8_t	md5_keyid;	/* key ID and auth data len */
932832011fSGarrett Wollman 		int8_t	md5_auth_len;	/* 16 */
942832011fSGarrett Wollman 		u_int32_t md5_seqno;	/* sequence number */
952832011fSGarrett Wollman 		u_int32_t rsvd[2];	/* must be 0 */
96c39ebb1dSBruce M Simpson #define	    RIP_AUTH_MD5_KEY_LEN   RIP_AUTH_PW_LEN
97c39ebb1dSBruce M Simpson #define	    RIP_AUTH_MD5_HASH_XTRA (sizeof(struct netauth)-sizeof(struct a_md5))
98c39ebb1dSBruce M Simpson #define	    RIP_AUTH_MD5_HASH_LEN  (RIP_AUTH_MD5_KEY_LEN+RIP_AUTH_MD5_HASH_XTRA)
992832011fSGarrett Wollman 	    } a_md5;
100703f5993SGarrett Wollman 	} au;
101703f5993SGarrett Wollman };
10259deaec5SRodney W. Grimes 
10359deaec5SRodney W. Grimes struct rip {
10483f9002eSGarrett Wollman 	u_int8_t    rip_cmd;		/* request/response */
10583f9002eSGarrett Wollman 	u_int8_t    rip_vers;		/* protocol version # */
10683f9002eSGarrett Wollman 	u_int16_t   rip_res1;		/* pad to 32-bit boundary */
107703f5993SGarrett Wollman 	union {				/* variable length... */
108703f5993SGarrett Wollman 	    struct netinfo ru_nets[1];
10983f9002eSGarrett Wollman 	    int8_t    ru_tracefile[1];
110703f5993SGarrett Wollman 	    struct netauth ru_auth[1];
11159deaec5SRodney W. Grimes 	} ripun;
11259deaec5SRodney W. Grimes #define	rip_nets	ripun.ru_nets
1132832011fSGarrett Wollman #define rip_auths	ripun.ru_auth
11459deaec5SRodney W. Grimes #define	rip_tracefile	ripun.ru_tracefile
11559deaec5SRodney W. Grimes };
11659deaec5SRodney W. Grimes 
117703f5993SGarrett Wollman /* Packet types.
11859deaec5SRodney W. Grimes  */
11959deaec5SRodney W. Grimes #define	RIPCMD_REQUEST		1	/* want info */
12059deaec5SRodney W. Grimes #define	RIPCMD_RESPONSE		2	/* responding to request */
12159deaec5SRodney W. Grimes #define	RIPCMD_TRACEON		3	/* turn tracing on */
12259deaec5SRodney W. Grimes #define	RIPCMD_TRACEOFF		4	/* turn it off */
12359deaec5SRodney W. Grimes 
124703f5993SGarrett Wollman /* Gated extended RIP to include a "poll" command instead of using
125703f5993SGarrett Wollman  * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT).  RFC 1058 says
126703f5993SGarrett Wollman  * command 5 is used by Sun Microsystems for its own purposes.
127703f5993SGarrett Wollman  */
128703f5993SGarrett Wollman #define RIPCMD_POLL		5
129703f5993SGarrett Wollman 
130703f5993SGarrett Wollman #define	RIPCMD_MAX		6
131703f5993SGarrett Wollman 
13259deaec5SRodney W. Grimes #ifdef RIPCMDS
1330feb5794SMark Murray const char *ripcmds[RIPCMD_MAX] = {
134703f5993SGarrett Wollman 	"#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF"
135703f5993SGarrett Wollman };
13659deaec5SRodney W. Grimes #endif
13759deaec5SRodney W. Grimes 
138703f5993SGarrett Wollman #define	HOPCNT_INFINITY		16
13959deaec5SRodney W. Grimes #define	MAXPACKETSIZE		512	/* max broadcast size */
140703f5993SGarrett Wollman #define NETS_LEN ((MAXPACKETSIZE-sizeof(struct rip))	\
141703f5993SGarrett Wollman 		      / sizeof(struct netinfo) +1)
14259deaec5SRodney W. Grimes 
14383f9002eSGarrett Wollman #define INADDR_RIP_GROUP (u_int32_t)0xe0000009	/* 224.0.0.9 */
144703f5993SGarrett Wollman 
145703f5993SGarrett Wollman 
146703f5993SGarrett Wollman /* Timer values used in managing the routing table.
147703f5993SGarrett Wollman  *
14859deaec5SRodney W. Grimes  * Complete tables are broadcast every SUPPLY_INTERVAL seconds.
14959deaec5SRodney W. Grimes  * If changes occur between updates, dynamic updates containing only changes
15059deaec5SRodney W. Grimes  * may be sent.  When these are sent, a timer is set for a random value
15159deaec5SRodney W. Grimes  * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates
15259deaec5SRodney W. Grimes  * are sent until the timer expires.
15359deaec5SRodney W. Grimes  *
15459deaec5SRodney W. Grimes  * Every update of a routing entry forces an entry's timer to be reset.
15559deaec5SRodney W. Grimes  * After EXPIRE_TIME without updates, the entry is marked invalid,
156703f5993SGarrett Wollman  * but held onto until GARBAGE_TIME so that others may see it, to
157703f5993SGarrett Wollman  * "poison" the bad route.
15859deaec5SRodney W. Grimes  */
15959deaec5SRodney W. Grimes #define	SUPPLY_INTERVAL		30	/* time to supply tables */
160703f5993SGarrett Wollman #define	MIN_WAITTIME		2	/* min sec until next flash updates */
161703f5993SGarrett Wollman #define	MAX_WAITTIME		5	/* max sec until flash update */
16259deaec5SRodney W. Grimes 
163703f5993SGarrett Wollman #define STALE_TIME		90	/* switch to a new gateway */
16459deaec5SRodney W. Grimes #define	EXPIRE_TIME		180	/* time to mark entry invalid */
16559deaec5SRodney W. Grimes #define	GARBAGE_TIME		240	/* time to garbage collect */
16659deaec5SRodney W. Grimes 
167703f5993SGarrett Wollman #ifdef __cplusplus
168703f5993SGarrett Wollman }
169703f5993SGarrett Wollman #endif
17059deaec5SRodney W. Grimes #endif /* !_ROUTED_H_ */
171