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