123164Smckusick /* 229070Smckusick * Copyright (c) 1980, 1986 Regents of the University of California. 333183Sbostic * All rights reserved. 423164Smckusick * 533183Sbostic * Redistribution and use in source and binary forms are permitted 6*34844Sbostic * provided that the above copyright notice and this paragraph are 7*34844Sbostic * duplicated in all such forms and that any documentation, 8*34844Sbostic * advertising materials, and other materials related to such 9*34844Sbostic * distribution and use acknowledge that the software was developed 10*34844Sbostic * by the University of California, Berkeley. The name of the 11*34844Sbostic * University may not be used to endorse or promote products derived 12*34844Sbostic * from this software without specific prior written permission. 13*34844Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34844Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34844Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1633183Sbostic * 17*34844Sbostic * @(#)route.h 7.4 (Berkeley) 06/27/88 1823164Smckusick */ 196332Ssam 206332Ssam /* 216412Ssam * Kernel resident routing tables. 226412Ssam * 2324776Skarels * The routing tables are initialized when interface addresses 2424776Skarels * are set by making entries for all directly connected interfaces. 256332Ssam */ 266332Ssam 277156Swnj /* 287156Swnj * A route consists of a destination address and a reference 297156Swnj * to a routing entry. These are often held by protocols 307156Swnj * in their control blocks, e.g. inpcb. 317156Swnj */ 326332Ssam struct route { 336332Ssam struct rtentry *ro_rt; 346332Ssam struct sockaddr ro_dst; 356332Ssam }; 366332Ssam 376332Ssam /* 387156Swnj * We distinguish between routes to hosts and routes to networks, 397156Swnj * preferring the former if available. For each route we infer 407156Swnj * the interface to use from the gateway address supplied when 417156Swnj * the route was entered. Routes that forward packets through 427156Swnj * gateways are marked so that the output routines know to address the 437156Swnj * gateway rather than the ultimate destination. 446332Ssam */ 457156Swnj struct rtentry { 467156Swnj u_long rt_hash; /* to speed lookups */ 477156Swnj struct sockaddr rt_dst; /* key */ 487156Swnj struct sockaddr rt_gateway; /* value */ 497156Swnj short rt_flags; /* up/down?, host/net */ 507156Swnj short rt_refcnt; /* # held references */ 517156Swnj u_long rt_use; /* raw # packets forwarded */ 527156Swnj struct ifnet *rt_ifp; /* the answer: interface to use */ 537156Swnj }; 547156Swnj 556339Ssam #define RTF_UP 0x1 /* route useable */ 567156Swnj #define RTF_GATEWAY 0x2 /* destination is a gateway */ 576377Ssam #define RTF_HOST 0x4 /* host entry (net otherwise) */ 5824776Skarels #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 5930396Skarels #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 606332Ssam 6112832Ssam /* 6212832Ssam * Routing statistics. 6312832Ssam */ 6412832Ssam struct rtstat { 6512832Ssam short rts_badredirect; /* bogus redirect calls */ 6612832Ssam short rts_dynamic; /* routes created by redirects */ 6712832Ssam short rts_newgateway; /* routes modified by redirects */ 6812832Ssam short rts_unreach; /* lookups which failed */ 6912832Ssam short rts_wildcard; /* lookups satisfied by a wildcard */ 7012832Ssam }; 7112832Ssam 7212832Ssam #ifdef KERNEL 736412Ssam #define RTFREE(rt) \ 746412Ssam if ((rt)->rt_refcnt == 1) \ 756412Ssam rtfree(rt); \ 766412Ssam else \ 776412Ssam (rt)->rt_refcnt--; 7812832Ssam 7917067Skarels #ifdef GATEWAY 8017067Skarels #define RTHASHSIZ 64 8117067Skarels #else 8216554Skarels #define RTHASHSIZ 8 8317067Skarels #endif 8416554Skarels #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 8516554Skarels #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 8616554Skarels #else 8716554Skarels #define RTHASHMOD(h) ((h) % RTHASHSIZ) 8816554Skarels #endif 8912832Ssam struct mbuf *rthost[RTHASHSIZ]; 9012832Ssam struct mbuf *rtnet[RTHASHSIZ]; 9112832Ssam struct rtstat rtstat; 9212832Ssam #endif 93