1*a8c9c98eSdholland /* $NetBSD: routed.h,v 1.15 2016/01/22 23:11:50 dholland Exp $ */ 24d2cbfceScgd 361f28255Scgd /*- 492c712a0Sthorpej * Copyright (c) 1983, 1989, 1993 592c712a0Sthorpej * The Regents of the University of California. All rights reserved. 661f28255Scgd * 761f28255Scgd * Redistribution and use in source and binary forms, with or without 861f28255Scgd * modification, are permitted provided that the following conditions 961f28255Scgd * are met: 1061f28255Scgd * 1. Redistributions of source code must retain the above copyright 1161f28255Scgd * notice, this list of conditions and the following disclaimer. 1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright 1361f28255Scgd * notice, this list of conditions and the following disclaimer in the 1461f28255Scgd * documentation and/or other materials provided with the distribution. 15039cc956Sagc * 3. Neither the name of the University nor the names of its contributors 1661f28255Scgd * may be used to endorse or promote products derived from this software 1761f28255Scgd * without specific prior written permission. 1861f28255Scgd * 1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2961f28255Scgd * SUCH DAMAGE. 3061f28255Scgd * 3192c712a0Sthorpej * @(#)routed.h 8.1 (Berkeley) 6/2/93 3261f28255Scgd */ 3361f28255Scgd 343b3774fcSperry #ifndef _PROTOCOLS_ROUTED_H_ 353b3774fcSperry #define _PROTOCOLS_ROUTED_H_ 36*a8c9c98eSdholland 37*a8c9c98eSdholland #include <stdint.h> 38*a8c9c98eSdholland 3992c712a0Sthorpej #ifdef __cplusplus 4092c712a0Sthorpej extern "C" { 4192c712a0Sthorpej #endif 4261f28255Scgd 4361f28255Scgd /* 4461f28255Scgd * Routing Information Protocol 4561f28255Scgd * 4661f28255Scgd * Derived from Xerox NS Routing Information Protocol 4761f28255Scgd * by changing 32-bit net numbers to sockaddr's and 4861f28255Scgd * padding stuff to 32-bit boundaries. 4961f28255Scgd */ 5092c712a0Sthorpej 51fce59c47Schristos #define RIP_VERSION_0 0 52fce59c47Schristos #define RIP_VERSION_1 1 53fce59c47Schristos #define RIP_VERSION_2 2 5461f28255Scgd 5592c712a0Sthorpej #define RIPv1 RIP_VERSION_1 5692c712a0Sthorpej #define RIPv2 RIP_VERSION_2 5792c712a0Sthorpej #ifndef RIPVERSION 5892c712a0Sthorpej #define RIPVERSION RIPv1 5992c712a0Sthorpej #endif 6092c712a0Sthorpej 6192c712a0Sthorpej #define RIP_PORT 520 6292c712a0Sthorpej 6392c712a0Sthorpej #if RIPVERSION == 1 64bd7bec20Schristos /* We include the V2 fields to get the right size */ 6561f28255Scgd struct netinfo { 665f65228bSperry uint16_t rip_family; 675f65228bSperry uint16_t rip_tag; 685f65228bSperry uint32_t rip_dst; /* destination net/host */ 695f65228bSperry uint32_t rip_dst_mask; /* destination mask (V2 only) */ 705f65228bSperry uint32_t rip_router; /* next host (V2 only) */ 715f65228bSperry uint32_t rip_metric; /* cost of route */ 7261f28255Scgd }; 7392c712a0Sthorpej #else 7492c712a0Sthorpej struct netinfo { 755f65228bSperry uint16_t n_family; 7692c712a0Sthorpej #define RIP_AF_INET htons(AF_INET) 7792c712a0Sthorpej #define RIP_AF_UNSPEC 0 7892c712a0Sthorpej #define RIP_AF_AUTH 0xffff 795f65228bSperry uint16_t n_tag; /* optional in RIPv2 */ 805f65228bSperry uint32_t n_dst; /* destination net or host */ 8192c712a0Sthorpej #define RIP_DEFAULT 0 825f65228bSperry uint32_t n_mask; /* netmask in RIPv2 */ 835f65228bSperry uint32_t n_nhop; /* optional next hop in RIPv2 */ 845f65228bSperry uint32_t n_metric; /* cost of route */ 8592c712a0Sthorpej }; 8692c712a0Sthorpej #endif 8792c712a0Sthorpej 8892c712a0Sthorpej /* RIPv2 authentication */ 8992c712a0Sthorpej struct netauth { 905f65228bSperry uint16_t a_family; /* always RIP_AF_AUTH */ 915f65228bSperry uint16_t a_type; 92fb80ce77Schristos #define RIP_AUTH_NONE 0 9392c712a0Sthorpej #define RIP_AUTH_PW htons(2) /* password type */ 94fb80ce77Schristos #define RIP_AUTH_MD5 htons(3) /* Keyed MD5 */ 9592c712a0Sthorpej union { 9692c712a0Sthorpej #define RIP_AUTH_PW_LEN 16 975f65228bSperry uint8_t au_pw[RIP_AUTH_PW_LEN]; 98fb80ce77Schristos struct a_md5 { 99fb80ce77Schristos int16_t md5_pkt_len; /* RIP-II packet length */ 100fb80ce77Schristos int8_t md5_keyid; /* key ID and auth data len */ 101fb80ce77Schristos int8_t md5_auth_len; /* 16 */ 1025f65228bSperry uint32_t md5_seqno; /* sequence number */ 1035f65228bSperry uint32_t rsvd[2]; /* must be 0 */ 104d8c7cd31Schristos #define RIP_AUTH_MD5_KEY_LEN RIP_AUTH_PW_LEN 105d8c7cd31Schristos #define RIP_AUTH_MD5_HASH_XTRA (sizeof(struct netauth)-sizeof(struct a_md5)) 106d8c7cd31Schristos #define RIP_AUTH_MD5_HASH_LEN (RIP_AUTH_MD5_KEY_LEN+RIP_AUTH_MD5_HASH_XTRA) 107fb80ce77Schristos } a_md5; 10892c712a0Sthorpej } au; 10992c712a0Sthorpej }; 11061f28255Scgd 11161f28255Scgd struct rip { 1125f65228bSperry uint8_t rip_cmd; /* request/response */ 1135f65228bSperry uint8_t rip_vers; /* protocol version # */ 1145f65228bSperry uint16_t rip_res1; /* pad to 32-bit boundary */ 11592c712a0Sthorpej union { /* variable length... */ 11692c712a0Sthorpej struct netinfo ru_nets[1]; 11792c712a0Sthorpej int8_t ru_tracefile[1]; 11892c712a0Sthorpej struct netauth ru_auth[1]; 11961f28255Scgd } ripun; 12061f28255Scgd #define rip_nets ripun.ru_nets 121fb80ce77Schristos #define rip_auths ripun.ru_auth 12261f28255Scgd #define rip_tracefile ripun.ru_tracefile 12361f28255Scgd }; 12461f28255Scgd 12592c712a0Sthorpej /* Packet types. 12661f28255Scgd */ 12761f28255Scgd #define RIPCMD_REQUEST 1 /* want info */ 12861f28255Scgd #define RIPCMD_RESPONSE 2 /* responding to request */ 12961f28255Scgd #define RIPCMD_TRACEON 3 /* turn tracing on */ 13061f28255Scgd #define RIPCMD_TRACEOFF 4 /* turn it off */ 13161f28255Scgd 13292c712a0Sthorpej /* Gated extended RIP to include a "poll" command instead of using 13392c712a0Sthorpej * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT). RFC 1058 says 13492c712a0Sthorpej * command 5 is used by Sun Microsystems for its own purposes. 13592c712a0Sthorpej */ 13692c712a0Sthorpej #define RIPCMD_POLL 5 13792c712a0Sthorpej 13892c712a0Sthorpej #define RIPCMD_MAX 6 13992c712a0Sthorpej 14061f28255Scgd #ifdef RIPCMDS 141d8c7cd31Schristos const char *ripcmds[RIPCMD_MAX] = { 14292c712a0Sthorpej "#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF" 14392c712a0Sthorpej }; 14461f28255Scgd #endif 14561f28255Scgd 14692c712a0Sthorpej #define HOPCNT_INFINITY 16 14761f28255Scgd #define MAXPACKETSIZE 512 /* max broadcast size */ 14892c712a0Sthorpej #define NETS_LEN ((MAXPACKETSIZE-sizeof(struct rip)) \ 14992c712a0Sthorpej / sizeof(struct netinfo) +1) 15061f28255Scgd 1515f65228bSperry #define INADDR_RIP_GROUP (uint32_t)0xe0000009 /* 224.0.0.9 */ 15292c712a0Sthorpej 15392c712a0Sthorpej 15492c712a0Sthorpej /* Timer values used in managing the routing table. 15592c712a0Sthorpej * 15661f28255Scgd * Complete tables are broadcast every SUPPLY_INTERVAL seconds. 15761f28255Scgd * If changes occur between updates, dynamic updates containing only changes 15861f28255Scgd * may be sent. When these are sent, a timer is set for a random value 15961f28255Scgd * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates 16061f28255Scgd * are sent until the timer expires. 16161f28255Scgd * 16261f28255Scgd * Every update of a routing entry forces an entry's timer to be reset. 16361f28255Scgd * After EXPIRE_TIME without updates, the entry is marked invalid, 16492c712a0Sthorpej * but held onto until GARBAGE_TIME so that others may see it, to 16592c712a0Sthorpej * "poison" the bad route. 16661f28255Scgd */ 16761f28255Scgd #define SUPPLY_INTERVAL 30 /* time to supply tables */ 16892c712a0Sthorpej #define MIN_WAITTIME 2 /* min sec until next flash updates */ 16992c712a0Sthorpej #define MAX_WAITTIME 5 /* max sec until flash update */ 17061f28255Scgd 17192c712a0Sthorpej #define STALE_TIME 90 /* switch to a new gateway */ 17261f28255Scgd #define EXPIRE_TIME 180 /* time to mark entry invalid */ 17361f28255Scgd #define GARBAGE_TIME 240 /* time to garbage collect */ 17461f28255Scgd 17592c712a0Sthorpej #ifdef __cplusplus 17692c712a0Sthorpej } 17792c712a0Sthorpej #endif 1783b3774fcSperry #endif /* !_PROTOCOLS_ROUTED_H_ */ 179