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 634844Sbostic * provided that the above copyright notice and this paragraph are 734844Sbostic * duplicated in all such forms and that any documentation, 834844Sbostic * advertising materials, and other materials related to such 934844Sbostic * distribution and use acknowledge that the software was developed 1034844Sbostic * by the University of California, Berkeley. The name of the 1134844Sbostic * University may not be used to endorse or promote products derived 1234844Sbostic * from this software without specific prior written permission. 1334844Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434844Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534844Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1633183Sbostic * 17*36354Ssklower * @(#)route.h 7.4 (Berkeley) 6/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 */ 45*36354Ssklower #include "radix.h" 467156Swnj struct rtentry { 47*36354Ssklower struct radix_node rt_nodes[2]; /* tree glue, and other values */ 48*36354Ssklower #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) 49*36354Ssklower #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) 50*36354Ssklower struct sockaddr *rt_gateway; /* value */ 51*36354Ssklower short rt_flags; /* up/down?, host/net */ 52*36354Ssklower short rt_refcnt; /* # held references */ 53*36354Ssklower u_long rt_use; /* raw # packets forwarded */ 54*36354Ssklower struct ifnet *rt_ifp; /* the answer: interface to use */ 55*36354Ssklower }; 56*36354Ssklower 57*36354Ssklower /* 58*36354Ssklower * Following structure necessary for 4.3 compatibility; 59*36354Ssklower * We should eventually move it to a compat file. 60*36354Ssklower */ 61*36354Ssklower struct ortentry { 627156Swnj u_long rt_hash; /* to speed lookups */ 637156Swnj struct sockaddr rt_dst; /* key */ 647156Swnj struct sockaddr rt_gateway; /* value */ 657156Swnj short rt_flags; /* up/down?, host/net */ 667156Swnj short rt_refcnt; /* # held references */ 677156Swnj u_long rt_use; /* raw # packets forwarded */ 687156Swnj struct ifnet *rt_ifp; /* the answer: interface to use */ 697156Swnj }; 707156Swnj 716339Ssam #define RTF_UP 0x1 /* route useable */ 727156Swnj #define RTF_GATEWAY 0x2 /* destination is a gateway */ 736377Ssam #define RTF_HOST 0x4 /* host entry (net otherwise) */ 7424776Skarels #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 7530396Skarels #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 76*36354Ssklower #define RTF_DONE 0x40 /* message confirmed */ 77*36354Ssklower #define RTF_MASK 0x80 /* subnet mask present */ 786332Ssam 79*36354Ssklower 8012832Ssam /* 8112832Ssam * Routing statistics. 8212832Ssam */ 8312832Ssam struct rtstat { 8412832Ssam short rts_badredirect; /* bogus redirect calls */ 8512832Ssam short rts_dynamic; /* routes created by redirects */ 8612832Ssam short rts_newgateway; /* routes modified by redirects */ 8712832Ssam short rts_unreach; /* lookups which failed */ 8812832Ssam short rts_wildcard; /* lookups satisfied by a wildcard */ 8912832Ssam }; 90*36354Ssklower /* 91*36354Ssklower * Structures for routing messages. 92*36354Ssklower */ 93*36354Ssklower struct rt_metrics { 94*36354Ssklower u_long rtm_mtu; /* MTU for this path */ 95*36354Ssklower u_long rtm_hopcount; /* max hops expected */ 96*36354Ssklower u_long rtm_expire; /* lifetime for route, e.g. redirect */ 97*36354Ssklower u_long rtm_recvpipe; /* inbound delay-bandwith product */ 98*36354Ssklower u_long rtm_sendpipe; /* outbound delay-bandwith product */ 99*36354Ssklower u_long rtm_ssthresh; /* outbound gateway buffer limit */ 100*36354Ssklower u_long rtm_rtt; /* estimated round trip time */ 101*36354Ssklower u_long rtm_rttvar; /* estimated rtt variance */ 102*36354Ssklower }; 10312832Ssam 104*36354Ssklower struct rt_msghdr { 105*36354Ssklower u_short rtm_msglen; /* to skip over non-understood messages */ 106*36354Ssklower u_char rtm_version; /* future binary compatability */ 107*36354Ssklower u_char rtm_type; /* message type */ 108*36354Ssklower u_char rtm_count; /* number of sockaddrs */ 109*36354Ssklower pid_t rtm_pid; /* identify sender */ 110*36354Ssklower int rtm_seq; /* for sender to identify action */ 111*36354Ssklower int rtm_errno; /* why failed */ 112*36354Ssklower int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 113*36354Ssklower int rtm_locks; /* which values kernel can alter */ 114*36354Ssklower int rtm_inits; /* which values we are initializing */ 115*36354Ssklower }; 116*36354Ssklower 117*36354Ssklower struct rt_chgmsg { /* Good for RTM_ADD, RTM_CHANGE, RTM_GET */ 118*36354Ssklower struct rt_msghdr cm_h; 119*36354Ssklower struct rt_metrics cm_m; 120*36354Ssklower }; 121*36354Ssklower 122*36354Ssklower struct route_cb { 123*36354Ssklower int ip_count; 124*36354Ssklower int ns_count; 125*36354Ssklower int iso_count; 126*36354Ssklower int any_count; 127*36354Ssklower }; 128*36354Ssklower 129*36354Ssklower #define RTM_ADD 0x1 /* Add Route */ 130*36354Ssklower #define RTM_DELETE 0x2 /* Delete Route */ 131*36354Ssklower #define RTM_CHANGE 0x3 /* Change Metrics or flags */ 132*36354Ssklower #define RTM_GET 0x4 /* Report Metrics */ 133*36354Ssklower #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ 134*36354Ssklower #define RTM_REDIRECT 0x6 /* Told to use different route */ 135*36354Ssklower #define RTM_MISS 0x7 /* Lookup failed on this address */ 136*36354Ssklower #define RTM_LOCK 0x8 /* fix specified metrics */ 137*36354Ssklower #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ 138*36354Ssklower #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ 139*36354Ssklower 140*36354Ssklower #define RTV_MTU 0x1 /* init or lock _mtu */ 141*36354Ssklower #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ 142*36354Ssklower #define RTV_EXPIRE 0x4 /* init or lock _hopcount */ 143*36354Ssklower #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ 144*36354Ssklower #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ 145*36354Ssklower #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ 146*36354Ssklower #define RTV_RTT 0x40 /* init or lock _rtt */ 147*36354Ssklower #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ 148*36354Ssklower 14912832Ssam #ifdef KERNEL 150*36354Ssklower struct route_cb route_cb; 151*36354Ssklower #endif 152*36354Ssklower 153*36354Ssklower #ifdef KERNEL 1546412Ssam #define RTFREE(rt) \ 1556412Ssam if ((rt)->rt_refcnt == 1) \ 1566412Ssam rtfree(rt); \ 1576412Ssam else \ 1586412Ssam (rt)->rt_refcnt--; 15912832Ssam 16017067Skarels #ifdef GATEWAY 16117067Skarels #define RTHASHSIZ 64 16217067Skarels #else 16316554Skarels #define RTHASHSIZ 8 16417067Skarels #endif 16516554Skarels #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 16616554Skarels #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 16716554Skarels #else 16816554Skarels #define RTHASHMOD(h) ((h) % RTHASHSIZ) 16916554Skarels #endif 17012832Ssam struct mbuf *rthost[RTHASHSIZ]; 17112832Ssam struct mbuf *rtnet[RTHASHSIZ]; 17212832Ssam struct rtstat rtstat; 173*36354Ssklower struct rtentry *rtalloc1(); 17412832Ssam #endif 175