123164Smckusick /* 223164Smckusick * Copyright (c) 1980 Regents of the University of California. 323164Smckusick * All rights reserved. The Berkeley software License Agreement 423164Smckusick * specifies the terms and conditions for redistribution. 523164Smckusick * 6*24381Swalsh * @(#)route.h 6.4 (Berkeley) 6/8/85 723164Smckusick */ 86332Ssam 96332Ssam /* 106412Ssam * Kernel resident routing tables. 116412Ssam * 127156Swnj * The routing tables are initialized at boot time by 137156Swnj * making entries for all directly connected interfaces. 146332Ssam */ 156332Ssam 167156Swnj /* 177156Swnj * A route consists of a destination address and a reference 187156Swnj * to a routing entry. These are often held by protocols 197156Swnj * in their control blocks, e.g. inpcb. 207156Swnj */ 216332Ssam struct route { 226332Ssam struct rtentry *ro_rt; 236332Ssam struct sockaddr ro_dst; 247156Swnj #ifdef notdef 257156Swnj caddr_t ro_pcb; /* not used yet */ 267156Swnj #endif 276332Ssam }; 286332Ssam 296332Ssam /* 307156Swnj * We distinguish between routes to hosts and routes to networks, 317156Swnj * preferring the former if available. For each route we infer 327156Swnj * the interface to use from the gateway address supplied when 337156Swnj * the route was entered. Routes that forward packets through 347156Swnj * gateways are marked so that the output routines know to address the 357156Swnj * gateway rather than the ultimate destination. 366332Ssam */ 377156Swnj struct rtentry { 387156Swnj u_long rt_hash; /* to speed lookups */ 397156Swnj struct sockaddr rt_dst; /* key */ 407156Swnj struct sockaddr rt_gateway; /* value */ 417156Swnj short rt_flags; /* up/down?, host/net */ 427156Swnj short rt_refcnt; /* # held references */ 437156Swnj u_long rt_use; /* raw # packets forwarded */ 447156Swnj struct ifnet *rt_ifp; /* the answer: interface to use */ 45*24381Swalsh union { /* domain specific info */ 46*24381Swalsh #ifdef INET 47*24381Swalsh struct { 48*24381Swalsh int in_rt_pc; /* count of pings not answered */ 49*24381Swalsh } rt_in_data; 50*24381Swalsh 51*24381Swalsh #define irt_pings rt_data.rt_in_data.in_rt_pc 52*24381Swalsh #define irt_gdown rt_data.rt_in_data.in_rt_pc 53*24381Swalsh 54*24381Swalsh #endif 55*24381Swalsh char rt_dummy[32]; 56*24381Swalsh } rt_data; 577156Swnj }; 587156Swnj 596339Ssam #define RTF_UP 0x1 /* route useable */ 607156Swnj #define RTF_GATEWAY 0x2 /* destination is a gateway */ 616377Ssam #define RTF_HOST 0x4 /* host entry (net otherwise) */ 62*24381Swalsh #define RTF_REINSTATE 0x8 /* re-instate route after timeout */ 636332Ssam 6412832Ssam /* 6512832Ssam * Routing statistics. 6612832Ssam */ 6712832Ssam struct rtstat { 6812832Ssam short rts_badredirect; /* bogus redirect calls */ 6912832Ssam short rts_dynamic; /* routes created by redirects */ 7012832Ssam short rts_newgateway; /* routes modified by redirects */ 7112832Ssam short rts_unreach; /* lookups which failed */ 7212832Ssam short rts_wildcard; /* lookups satisfied by a wildcard */ 7312832Ssam }; 7412832Ssam 7512832Ssam #ifdef KERNEL 766412Ssam #define RTFREE(rt) \ 776412Ssam if ((rt)->rt_refcnt == 1) \ 786412Ssam rtfree(rt); \ 796412Ssam else \ 806412Ssam (rt)->rt_refcnt--; 8112832Ssam 8217067Skarels #ifdef GATEWAY 8317067Skarels #define RTHASHSIZ 64 8417067Skarels #else 8516554Skarels #define RTHASHSIZ 8 8617067Skarels #endif 8716554Skarels #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 8816554Skarels #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 8916554Skarels #else 9016554Skarels #define RTHASHMOD(h) ((h) % RTHASHSIZ) 9116554Skarels #endif 9212832Ssam struct mbuf *rthost[RTHASHSIZ]; 9312832Ssam struct mbuf *rtnet[RTHASHSIZ]; 9412832Ssam struct rtstat rtstat; 9512832Ssam #endif 96