123164Smckusick /* 229070Smckusick * Copyright (c) 1980, 1986 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*30396Skarels * @(#)route.h 7.2 (Berkeley) 01/15/87 723164Smckusick */ 86332Ssam 96332Ssam /* 106412Ssam * Kernel resident routing tables. 116412Ssam * 1224776Skarels * The routing tables are initialized when interface addresses 1324776Skarels * are set by 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; 246332Ssam }; 256332Ssam 266332Ssam /* 277156Swnj * We distinguish between routes to hosts and routes to networks, 287156Swnj * preferring the former if available. For each route we infer 297156Swnj * the interface to use from the gateway address supplied when 307156Swnj * the route was entered. Routes that forward packets through 317156Swnj * gateways are marked so that the output routines know to address the 327156Swnj * gateway rather than the ultimate destination. 336332Ssam */ 347156Swnj struct rtentry { 357156Swnj u_long rt_hash; /* to speed lookups */ 367156Swnj struct sockaddr rt_dst; /* key */ 377156Swnj struct sockaddr rt_gateway; /* value */ 387156Swnj short rt_flags; /* up/down?, host/net */ 397156Swnj short rt_refcnt; /* # held references */ 407156Swnj u_long rt_use; /* raw # packets forwarded */ 417156Swnj struct ifnet *rt_ifp; /* the answer: interface to use */ 427156Swnj }; 437156Swnj 446339Ssam #define RTF_UP 0x1 /* route useable */ 457156Swnj #define RTF_GATEWAY 0x2 /* destination is a gateway */ 466377Ssam #define RTF_HOST 0x4 /* host entry (net otherwise) */ 4724776Skarels #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 48*30396Skarels #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 496332Ssam 5012832Ssam /* 5112832Ssam * Routing statistics. 5212832Ssam */ 5312832Ssam struct rtstat { 5412832Ssam short rts_badredirect; /* bogus redirect calls */ 5512832Ssam short rts_dynamic; /* routes created by redirects */ 5612832Ssam short rts_newgateway; /* routes modified by redirects */ 5712832Ssam short rts_unreach; /* lookups which failed */ 5812832Ssam short rts_wildcard; /* lookups satisfied by a wildcard */ 5912832Ssam }; 6012832Ssam 6112832Ssam #ifdef KERNEL 626412Ssam #define RTFREE(rt) \ 636412Ssam if ((rt)->rt_refcnt == 1) \ 646412Ssam rtfree(rt); \ 656412Ssam else \ 666412Ssam (rt)->rt_refcnt--; 6712832Ssam 6817067Skarels #ifdef GATEWAY 6917067Skarels #define RTHASHSIZ 64 7017067Skarels #else 7116554Skarels #define RTHASHSIZ 8 7217067Skarels #endif 7316554Skarels #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 7416554Skarels #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 7516554Skarels #else 7616554Skarels #define RTHASHMOD(h) ((h) % RTHASHSIZ) 7716554Skarels #endif 7812832Ssam struct mbuf *rthost[RTHASHSIZ]; 7912832Ssam struct mbuf *rtnet[RTHASHSIZ]; 8012832Ssam struct rtstat rtstat; 8112832Ssam #endif 82