1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)route.h 6.4 (Berkeley) 06/08/85 7 */ 8 9 /* 10 * Kernel resident routing tables. 11 * 12 * The routing tables are initialized at boot time by 13 * making entries for all directly connected interfaces. 14 */ 15 16 /* 17 * A route consists of a destination address and a reference 18 * to a routing entry. These are often held by protocols 19 * in their control blocks, e.g. inpcb. 20 */ 21 struct route { 22 struct rtentry *ro_rt; 23 struct sockaddr ro_dst; 24 #ifdef notdef 25 caddr_t ro_pcb; /* not used yet */ 26 #endif 27 }; 28 29 /* 30 * We distinguish between routes to hosts and routes to networks, 31 * preferring the former if available. For each route we infer 32 * the interface to use from the gateway address supplied when 33 * the route was entered. Routes that forward packets through 34 * gateways are marked so that the output routines know to address the 35 * gateway rather than the ultimate destination. 36 */ 37 struct rtentry { 38 u_long rt_hash; /* to speed lookups */ 39 struct sockaddr rt_dst; /* key */ 40 struct sockaddr rt_gateway; /* value */ 41 short rt_flags; /* up/down?, host/net */ 42 short rt_refcnt; /* # held references */ 43 u_long rt_use; /* raw # packets forwarded */ 44 struct ifnet *rt_ifp; /* the answer: interface to use */ 45 }; 46 47 #define RTF_UP 0x1 /* route useable */ 48 #define RTF_GATEWAY 0x2 /* destination is a gateway */ 49 #define RTF_HOST 0x4 /* host entry (net otherwise) */ 50 51 /* 52 * Routing statistics. 53 */ 54 struct rtstat { 55 short rts_badredirect; /* bogus redirect calls */ 56 short rts_dynamic; /* routes created by redirects */ 57 short rts_newgateway; /* routes modified by redirects */ 58 short rts_unreach; /* lookups which failed */ 59 short rts_wildcard; /* lookups satisfied by a wildcard */ 60 }; 61 62 #ifdef KERNEL 63 #define RTFREE(rt) \ 64 if ((rt)->rt_refcnt == 1) \ 65 rtfree(rt); \ 66 else \ 67 (rt)->rt_refcnt--; 68 69 #ifdef GATEWAY 70 #define RTHASHSIZ 64 71 #else 72 #define RTHASHSIZ 8 73 #endif 74 #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 75 #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 76 #else 77 #define RTHASHMOD(h) ((h) % RTHASHSIZ) 78 #endif 79 struct mbuf *rthost[RTHASHSIZ]; 80 struct mbuf *rtnet[RTHASHSIZ]; 81 struct rtstat rtstat; 82 #endif 83