1*23164Smckusick /* 2*23164Smckusick * Copyright (c) 1980 Regents of the University of California. 3*23164Smckusick * All rights reserved. The Berkeley software License Agreement 4*23164Smckusick * specifies the terms and conditions for redistribution. 5*23164Smckusick * 6*23164Smckusick * @(#)route.h 6.4 (Berkeley) 06/08/85 7*23164Smckusick */ 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 */ 457156Swnj }; 467156Swnj 476339Ssam #define RTF_UP 0x1 /* route useable */ 487156Swnj #define RTF_GATEWAY 0x2 /* destination is a gateway */ 496377Ssam #define RTF_HOST 0x4 /* host entry (net otherwise) */ 506332Ssam 5112832Ssam /* 5212832Ssam * Routing statistics. 5312832Ssam */ 5412832Ssam struct rtstat { 5512832Ssam short rts_badredirect; /* bogus redirect calls */ 5612832Ssam short rts_dynamic; /* routes created by redirects */ 5712832Ssam short rts_newgateway; /* routes modified by redirects */ 5812832Ssam short rts_unreach; /* lookups which failed */ 5912832Ssam short rts_wildcard; /* lookups satisfied by a wildcard */ 6012832Ssam }; 6112832Ssam 6212832Ssam #ifdef KERNEL 636412Ssam #define RTFREE(rt) \ 646412Ssam if ((rt)->rt_refcnt == 1) \ 656412Ssam rtfree(rt); \ 666412Ssam else \ 676412Ssam (rt)->rt_refcnt--; 6812832Ssam 6917067Skarels #ifdef GATEWAY 7017067Skarels #define RTHASHSIZ 64 7117067Skarels #else 7216554Skarels #define RTHASHSIZ 8 7317067Skarels #endif 7416554Skarels #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 7516554Skarels #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 7616554Skarels #else 7716554Skarels #define RTHASHMOD(h) ((h) % RTHASHSIZ) 7816554Skarels #endif 7912832Ssam struct mbuf *rthost[RTHASHSIZ]; 8012832Ssam struct mbuf *rtnet[RTHASHSIZ]; 8112832Ssam struct rtstat rtstat; 8212832Ssam #endif 83