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. 3059deaec5SRodney W. Grimes * 3159deaec5SRodney W. Grimes * @(#)routed.h 8.1 (Berkeley) 6/2/93 3283f9002eSGarrett Wollman * 33a4add9a9SPeter Wemm * $FreeBSD$ 34c39ebb1dSBruce M Simpson * $Revision: 2.26 $ 3559deaec5SRodney W. Grimes */ 3659deaec5SRodney W. Grimes 37703f5993SGarrett Wollman #ifndef _ROUTED_H_ 38703f5993SGarrett Wollman #define _ROUTED_H_ 39703f5993SGarrett Wollman #ifdef __cplusplus 40703f5993SGarrett Wollman extern "C" { 41703f5993SGarrett Wollman #endif 4259deaec5SRodney W. Grimes 4359deaec5SRodney W. Grimes /* 4459deaec5SRodney W. Grimes * Routing Information Protocol 4559deaec5SRodney W. Grimes * 4659deaec5SRodney W. Grimes * Derived from Xerox NS Routing Information Protocol 4759deaec5SRodney W. Grimes * by changing 32-bit net numbers to sockaddr's and 4859deaec5SRodney W. Grimes * padding stuff to 32-bit boundaries. 4959deaec5SRodney W. Grimes */ 5059deaec5SRodney W. Grimes 51703f5993SGarrett Wollman #define RIPv1 1 52703f5993SGarrett Wollman #define RIPv2 2 53703f5993SGarrett Wollman #ifndef RIPVERSION 54703f5993SGarrett Wollman #define RIPVERSION RIPv1 55703f5993SGarrett Wollman #endif 56703f5993SGarrett Wollman 57703f5993SGarrett Wollman #define RIP_PORT 520 58703f5993SGarrett Wollman 59703f5993SGarrett Wollman #if RIPVERSION == 1 60703f5993SGarrett Wollman /* Note that this so called sockaddr has a 2-byte sa_family and no sa_len. 61703f5993SGarrett Wollman * It is not a UNIX sockaddr, but the shape of an address as defined 6283f9002eSGarrett Wollman * in RIPv1. It is still defined to allow old versions of programs 6383f9002eSGarrett Wollman * such as `gated` to use this file to define RIPv1. 64703f5993SGarrett Wollman */ 6559deaec5SRodney W. Grimes struct netinfo { 6659deaec5SRodney W. Grimes struct sockaddr rip_dst; /* destination net/host */ 6783f9002eSGarrett Wollman u_int32_t rip_metric; /* cost of route */ 6859deaec5SRodney W. Grimes }; 69703f5993SGarrett Wollman #else 70703f5993SGarrett Wollman struct netinfo { 7183f9002eSGarrett Wollman u_int16_t n_family; 72703f5993SGarrett Wollman #define RIP_AF_INET htons(AF_INET) 73703f5993SGarrett Wollman #define RIP_AF_UNSPEC 0 74703f5993SGarrett Wollman #define RIP_AF_AUTH 0xffff 7583f9002eSGarrett Wollman u_int16_t n_tag; /* optional in RIPv2 */ 7683f9002eSGarrett Wollman u_int32_t n_dst; /* destination net or host */ 77703f5993SGarrett Wollman #define RIP_DEFAULT 0 7883f9002eSGarrett Wollman u_int32_t n_mask; /* netmask in RIPv2 */ 7983f9002eSGarrett Wollman u_int32_t n_nhop; /* optional next hop in RIPv2 */ 8083f9002eSGarrett Wollman u_int32_t n_metric; /* cost of route */ 81703f5993SGarrett Wollman }; 82703f5993SGarrett Wollman #endif 83703f5993SGarrett Wollman 84703f5993SGarrett Wollman /* RIPv2 authentication */ 85703f5993SGarrett Wollman struct netauth { 862832011fSGarrett Wollman u_int16_t a_family; /* always RIP_AF_AUTH */ 8783f9002eSGarrett Wollman u_int16_t a_type; 882832011fSGarrett Wollman #define RIP_AUTH_NONE 0 89703f5993SGarrett Wollman #define RIP_AUTH_PW htons(2) /* password type */ 902832011fSGarrett Wollman #define RIP_AUTH_MD5 htons(3) /* Keyed MD5 */ 91703f5993SGarrett Wollman union { 92703f5993SGarrett Wollman #define RIP_AUTH_PW_LEN 16 932832011fSGarrett Wollman u_int8_t au_pw[RIP_AUTH_PW_LEN]; 942832011fSGarrett Wollman struct a_md5 { 952832011fSGarrett Wollman int16_t md5_pkt_len; /* RIP-II packet length */ 962832011fSGarrett Wollman int8_t md5_keyid; /* key ID and auth data len */ 972832011fSGarrett Wollman int8_t md5_auth_len; /* 16 */ 982832011fSGarrett Wollman u_int32_t md5_seqno; /* sequence number */ 992832011fSGarrett Wollman u_int32_t rsvd[2]; /* must be 0 */ 100c39ebb1dSBruce M Simpson #define RIP_AUTH_MD5_KEY_LEN RIP_AUTH_PW_LEN 101c39ebb1dSBruce M Simpson #define RIP_AUTH_MD5_HASH_XTRA (sizeof(struct netauth)-sizeof(struct a_md5)) 102c39ebb1dSBruce M Simpson #define RIP_AUTH_MD5_HASH_LEN (RIP_AUTH_MD5_KEY_LEN+RIP_AUTH_MD5_HASH_XTRA) 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