159deaec5SRodney W. Grimes /*- 259deaec5SRodney W. Grimes * Copyright (c) 1983, 1989, 1993 359deaec5SRodney W. Grimes * The Regents of the University of California. All rights reserved. 459deaec5SRodney W. Grimes * 559deaec5SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 659deaec5SRodney W. Grimes * modification, are permitted provided that the following conditions 759deaec5SRodney W. Grimes * are met: 859deaec5SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 959deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1059deaec5SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1159deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1259deaec5SRodney W. Grimes * documentation and/or other materials provided with the distribution. 1359deaec5SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 140feb5794SMark Murray * must display the following acknowledgment: 1559deaec5SRodney W. Grimes * This product includes software developed by the University of 1659deaec5SRodney W. Grimes * California, Berkeley and its contributors. 1759deaec5SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 1859deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 1959deaec5SRodney W. Grimes * without specific prior written permission. 2059deaec5SRodney W. Grimes * 2159deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2259deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2359deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2459deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2559deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2659deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2759deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2859deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2959deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3059deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3159deaec5SRodney W. Grimes * SUCH DAMAGE. 3259deaec5SRodney W. Grimes * 3359deaec5SRodney W. Grimes * @(#)routed.h 8.1 (Berkeley) 6/2/93 3483f9002eSGarrett Wollman * 350feb5794SMark Murray * $Id$ 3659deaec5SRodney W. Grimes */ 3759deaec5SRodney W. Grimes 38703f5993SGarrett Wollman #ifndef _ROUTED_H_ 39703f5993SGarrett Wollman #define _ROUTED_H_ 40703f5993SGarrett Wollman #ifdef __cplusplus 41703f5993SGarrett Wollman extern "C" { 42703f5993SGarrett Wollman #endif 430feb5794SMark Murray #ident "$Revision: 2.16 $" 4459deaec5SRodney W. Grimes 4559deaec5SRodney W. Grimes /* 4659deaec5SRodney W. Grimes * Routing Information Protocol 4759deaec5SRodney W. Grimes * 4859deaec5SRodney W. Grimes * Derived from Xerox NS Routing Information Protocol 4959deaec5SRodney W. Grimes * by changing 32-bit net numbers to sockaddr's and 5059deaec5SRodney W. Grimes * padding stuff to 32-bit boundaries. 5159deaec5SRodney W. Grimes */ 5259deaec5SRodney W. Grimes 53703f5993SGarrett Wollman #define RIPv1 1 54703f5993SGarrett Wollman #define RIPv2 2 55703f5993SGarrett Wollman #ifndef RIPVERSION 56703f5993SGarrett Wollman #define RIPVERSION RIPv1 57703f5993SGarrett Wollman #endif 58703f5993SGarrett Wollman 59703f5993SGarrett Wollman #define RIP_PORT 520 60703f5993SGarrett Wollman 61703f5993SGarrett Wollman #if RIPVERSION == 1 62703f5993SGarrett Wollman /* Note that this so called sockaddr has a 2-byte sa_family and no sa_len. 63703f5993SGarrett Wollman * It is not a UNIX sockaddr, but the shape of an address as defined 6483f9002eSGarrett Wollman * in RIPv1. It is still defined to allow old versions of programs 6583f9002eSGarrett Wollman * such as `gated` to use this file to define RIPv1. 66703f5993SGarrett Wollman */ 6759deaec5SRodney W. Grimes struct netinfo { 6859deaec5SRodney W. Grimes struct sockaddr rip_dst; /* destination net/host */ 6983f9002eSGarrett Wollman u_int32_t rip_metric; /* cost of route */ 7059deaec5SRodney W. Grimes }; 71703f5993SGarrett Wollman #else 72703f5993SGarrett Wollman struct netinfo { 7383f9002eSGarrett Wollman u_int16_t n_family; 74703f5993SGarrett Wollman #define RIP_AF_INET htons(AF_INET) 75703f5993SGarrett Wollman #define RIP_AF_UNSPEC 0 76703f5993SGarrett Wollman #define RIP_AF_AUTH 0xffff 7783f9002eSGarrett Wollman u_int16_t n_tag; /* optional in RIPv2 */ 7883f9002eSGarrett Wollman u_int32_t n_dst; /* destination net or host */ 79703f5993SGarrett Wollman #define RIP_DEFAULT 0 8083f9002eSGarrett Wollman u_int32_t n_mask; /* netmask in RIPv2 */ 8183f9002eSGarrett Wollman u_int32_t n_nhop; /* optional next hop in RIPv2 */ 8283f9002eSGarrett Wollman u_int32_t n_metric; /* cost of route */ 83703f5993SGarrett Wollman }; 84703f5993SGarrett Wollman #endif 85703f5993SGarrett Wollman 86703f5993SGarrett Wollman /* RIPv2 authentication */ 87703f5993SGarrett Wollman struct netauth { 882832011fSGarrett Wollman u_int16_t a_family; /* always RIP_AF_AUTH */ 8983f9002eSGarrett Wollman u_int16_t a_type; 902832011fSGarrett Wollman #define RIP_AUTH_NONE 0 91703f5993SGarrett Wollman #define RIP_AUTH_PW htons(2) /* password type */ 922832011fSGarrett Wollman #define RIP_AUTH_MD5 htons(3) /* Keyed MD5 */ 93703f5993SGarrett Wollman union { 94703f5993SGarrett Wollman #define RIP_AUTH_PW_LEN 16 952832011fSGarrett Wollman u_int8_t au_pw[RIP_AUTH_PW_LEN]; 962832011fSGarrett Wollman struct a_md5 { 972832011fSGarrett Wollman int16_t md5_pkt_len; /* RIP-II packet length */ 982832011fSGarrett Wollman int8_t md5_keyid; /* key ID and auth data len */ 992832011fSGarrett Wollman int8_t md5_auth_len; /* 16 */ 1002832011fSGarrett Wollman u_int32_t md5_seqno; /* sequence number */ 1012832011fSGarrett Wollman u_int32_t rsvd[2]; /* must be 0 */ 1022832011fSGarrett Wollman #define RIP_AUTH_MD5_LEN RIP_AUTH_PW_LEN 1032832011fSGarrett Wollman } a_md5; 104703f5993SGarrett Wollman } au; 105703f5993SGarrett Wollman }; 10659deaec5SRodney W. Grimes 10759deaec5SRodney W. Grimes struct rip { 10883f9002eSGarrett Wollman u_int8_t rip_cmd; /* request/response */ 10983f9002eSGarrett Wollman u_int8_t rip_vers; /* protocol version # */ 11083f9002eSGarrett Wollman u_int16_t rip_res1; /* pad to 32-bit boundary */ 111703f5993SGarrett Wollman union { /* variable length... */ 112703f5993SGarrett Wollman struct netinfo ru_nets[1]; 11383f9002eSGarrett Wollman int8_t ru_tracefile[1]; 114703f5993SGarrett Wollman struct netauth ru_auth[1]; 11559deaec5SRodney W. Grimes } ripun; 11659deaec5SRodney W. Grimes #define rip_nets ripun.ru_nets 1172832011fSGarrett Wollman #define rip_auths ripun.ru_auth 11859deaec5SRodney W. Grimes #define rip_tracefile ripun.ru_tracefile 11959deaec5SRodney W. Grimes }; 12059deaec5SRodney W. Grimes 121703f5993SGarrett Wollman /* Packet types. 12259deaec5SRodney W. Grimes */ 12359deaec5SRodney W. Grimes #define RIPCMD_REQUEST 1 /* want info */ 12459deaec5SRodney W. Grimes #define RIPCMD_RESPONSE 2 /* responding to request */ 12559deaec5SRodney W. Grimes #define RIPCMD_TRACEON 3 /* turn tracing on */ 12659deaec5SRodney W. Grimes #define RIPCMD_TRACEOFF 4 /* turn it off */ 12759deaec5SRodney W. Grimes 128703f5993SGarrett Wollman /* Gated extended RIP to include a "poll" command instead of using 129703f5993SGarrett Wollman * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT). RFC 1058 says 130703f5993SGarrett Wollman * command 5 is used by Sun Microsystems for its own purposes. 131703f5993SGarrett Wollman */ 132703f5993SGarrett Wollman #define RIPCMD_POLL 5 133703f5993SGarrett Wollman 134703f5993SGarrett Wollman #define RIPCMD_MAX 6 135703f5993SGarrett Wollman 13659deaec5SRodney W. Grimes #ifdef RIPCMDS 1370feb5794SMark Murray const char *ripcmds[RIPCMD_MAX] = { 138703f5993SGarrett Wollman "#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF" 139703f5993SGarrett Wollman }; 14059deaec5SRodney W. Grimes #endif 14159deaec5SRodney W. Grimes 142703f5993SGarrett Wollman #define HOPCNT_INFINITY 16 14359deaec5SRodney W. Grimes #define MAXPACKETSIZE 512 /* max broadcast size */ 144703f5993SGarrett Wollman #define NETS_LEN ((MAXPACKETSIZE-sizeof(struct rip)) \ 145703f5993SGarrett Wollman / sizeof(struct netinfo) +1) 14659deaec5SRodney W. Grimes 14783f9002eSGarrett Wollman #define INADDR_RIP_GROUP (u_int32_t)0xe0000009 /* 224.0.0.9 */ 148703f5993SGarrett Wollman 149703f5993SGarrett Wollman 150703f5993SGarrett Wollman /* Timer values used in managing the routing table. 151703f5993SGarrett Wollman * 15259deaec5SRodney W. Grimes * Complete tables are broadcast every SUPPLY_INTERVAL seconds. 15359deaec5SRodney W. Grimes * If changes occur between updates, dynamic updates containing only changes 15459deaec5SRodney W. Grimes * may be sent. When these are sent, a timer is set for a random value 15559deaec5SRodney W. Grimes * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates 15659deaec5SRodney W. Grimes * are sent until the timer expires. 15759deaec5SRodney W. Grimes * 15859deaec5SRodney W. Grimes * Every update of a routing entry forces an entry's timer to be reset. 15959deaec5SRodney W. Grimes * After EXPIRE_TIME without updates, the entry is marked invalid, 160703f5993SGarrett Wollman * but held onto until GARBAGE_TIME so that others may see it, to 161703f5993SGarrett Wollman * "poison" the bad route. 16259deaec5SRodney W. Grimes */ 16359deaec5SRodney W. Grimes #define SUPPLY_INTERVAL 30 /* time to supply tables */ 164703f5993SGarrett Wollman #define MIN_WAITTIME 2 /* min sec until next flash updates */ 165703f5993SGarrett Wollman #define MAX_WAITTIME 5 /* max sec until flash update */ 16659deaec5SRodney W. Grimes 167703f5993SGarrett Wollman #define STALE_TIME 90 /* switch to a new gateway */ 16859deaec5SRodney W. Grimes #define EXPIRE_TIME 180 /* time to mark entry invalid */ 16959deaec5SRodney W. Grimes #define GARBAGE_TIME 240 /* time to garbage collect */ 17059deaec5SRodney W. Grimes 171703f5993SGarrett Wollman #ifdef __cplusplus 172703f5993SGarrett Wollman } 173703f5993SGarrett Wollman #endif 17459deaec5SRodney W. Grimes #endif /* !_ROUTED_H_ */ 175