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*40445Ssklower * @(#)route.h 7.7 (Berkeley) 03/12/90 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 */ 4536354Ssklower #include "radix.h" 467156Swnj struct rtentry { 4736354Ssklower struct radix_node rt_nodes[2]; /* tree glue, and other values */ 4836354Ssklower #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) 4936354Ssklower #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) 5036354Ssklower struct sockaddr *rt_gateway; /* value */ 5136354Ssklower short rt_flags; /* up/down?, host/net */ 5236354Ssklower short rt_refcnt; /* # held references */ 5336354Ssklower u_long rt_use; /* raw # packets forwarded */ 5436354Ssklower struct ifnet *rt_ifp; /* the answer: interface to use */ 5537472Ssklower struct ifaddr *rt_ifa; /* the answer: interface to use */ 56*40445Ssklower struct sockaddr *rt_genmask; /* for generation of cloned routes */ 57*40445Ssklower caddr_t rt_llinfo; /* pointer to link level info cache */ 5836354Ssklower }; 5936354Ssklower 6036354Ssklower /* 6136354Ssklower * Following structure necessary for 4.3 compatibility; 6236354Ssklower * We should eventually move it to a compat file. 6336354Ssklower */ 6436354Ssklower struct ortentry { 657156Swnj u_long rt_hash; /* to speed lookups */ 667156Swnj struct sockaddr rt_dst; /* key */ 677156Swnj struct sockaddr rt_gateway; /* value */ 687156Swnj short rt_flags; /* up/down?, host/net */ 697156Swnj short rt_refcnt; /* # held references */ 707156Swnj u_long rt_use; /* raw # packets forwarded */ 717156Swnj struct ifnet *rt_ifp; /* the answer: interface to use */ 727156Swnj }; 737156Swnj 746339Ssam #define RTF_UP 0x1 /* route useable */ 757156Swnj #define RTF_GATEWAY 0x2 /* destination is a gateway */ 766377Ssam #define RTF_HOST 0x4 /* host entry (net otherwise) */ 7724776Skarels #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 7830396Skarels #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 7936354Ssklower #define RTF_DONE 0x40 /* message confirmed */ 8036354Ssklower #define RTF_MASK 0x80 /* subnet mask present */ 81*40445Ssklower #define RTF_CLONING 0x100 /* generate new routes on use */ 82*40445Ssklower #define RTF_XRESOLVE 0x200 /* external daemon resolves name */ 836332Ssam 8436354Ssklower 8512832Ssam /* 8612832Ssam * Routing statistics. 8712832Ssam */ 8812832Ssam struct rtstat { 8912832Ssam short rts_badredirect; /* bogus redirect calls */ 9012832Ssam short rts_dynamic; /* routes created by redirects */ 9112832Ssam short rts_newgateway; /* routes modified by redirects */ 9212832Ssam short rts_unreach; /* lookups which failed */ 9312832Ssam short rts_wildcard; /* lookups satisfied by a wildcard */ 9412832Ssam }; 9536354Ssklower /* 9636354Ssklower * Structures for routing messages. 9736354Ssklower */ 9836354Ssklower struct rt_metrics { 9936354Ssklower u_long rtm_mtu; /* MTU for this path */ 10036354Ssklower u_long rtm_hopcount; /* max hops expected */ 10136354Ssklower u_long rtm_expire; /* lifetime for route, e.g. redirect */ 10236354Ssklower u_long rtm_recvpipe; /* inbound delay-bandwith product */ 10336354Ssklower u_long rtm_sendpipe; /* outbound delay-bandwith product */ 10436354Ssklower u_long rtm_ssthresh; /* outbound gateway buffer limit */ 10536354Ssklower u_long rtm_rtt; /* estimated round trip time */ 10636354Ssklower u_long rtm_rttvar; /* estimated rtt variance */ 10736354Ssklower }; 10812832Ssam 10936354Ssklower struct rt_msghdr { 11036354Ssklower u_short rtm_msglen; /* to skip over non-understood messages */ 11136354Ssklower u_char rtm_version; /* future binary compatability */ 11236354Ssklower u_char rtm_type; /* message type */ 11336354Ssklower u_char rtm_count; /* number of sockaddrs */ 11436354Ssklower pid_t rtm_pid; /* identify sender */ 11536354Ssklower int rtm_seq; /* for sender to identify action */ 11636354Ssklower int rtm_errno; /* why failed */ 11736354Ssklower int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 11836354Ssklower int rtm_locks; /* which values kernel can alter */ 11936354Ssklower int rtm_inits; /* which values we are initializing */ 12036354Ssklower }; 12136354Ssklower 12236354Ssklower struct rt_chgmsg { /* Good for RTM_ADD, RTM_CHANGE, RTM_GET */ 12336354Ssklower struct rt_msghdr cm_h; 12436354Ssklower struct rt_metrics cm_m; 12536354Ssklower }; 12636354Ssklower 12736354Ssklower struct route_cb { 12836354Ssklower int ip_count; 12936354Ssklower int ns_count; 13036354Ssklower int iso_count; 13136354Ssklower int any_count; 13236354Ssklower }; 13336354Ssklower 13436354Ssklower #define RTM_ADD 0x1 /* Add Route */ 13536354Ssklower #define RTM_DELETE 0x2 /* Delete Route */ 13636354Ssklower #define RTM_CHANGE 0x3 /* Change Metrics or flags */ 13736354Ssklower #define RTM_GET 0x4 /* Report Metrics */ 13836354Ssklower #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ 13936354Ssklower #define RTM_REDIRECT 0x6 /* Told to use different route */ 14036354Ssklower #define RTM_MISS 0x7 /* Lookup failed on this address */ 14136354Ssklower #define RTM_LOCK 0x8 /* fix specified metrics */ 14236354Ssklower #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ 14336354Ssklower #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ 144*40445Ssklower #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ 14536354Ssklower 14636354Ssklower #define RTV_MTU 0x1 /* init or lock _mtu */ 14736354Ssklower #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ 14836354Ssklower #define RTV_EXPIRE 0x4 /* init or lock _hopcount */ 14936354Ssklower #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ 15036354Ssklower #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ 15136354Ssklower #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ 15236354Ssklower #define RTV_RTT 0x40 /* init or lock _rtt */ 15336354Ssklower #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ 15436354Ssklower 15512832Ssam #ifdef KERNEL 15636354Ssklower struct route_cb route_cb; 15736354Ssklower #endif 15836354Ssklower 15936354Ssklower #ifdef KERNEL 1606412Ssam #define RTFREE(rt) \ 161*40445Ssklower if ((rt)->rt_refcnt <= 1) \ 1626412Ssam rtfree(rt); \ 1636412Ssam else \ 1646412Ssam (rt)->rt_refcnt--; 16512832Ssam 16617067Skarels #ifdef GATEWAY 16717067Skarels #define RTHASHSIZ 64 16817067Skarels #else 16916554Skarels #define RTHASHSIZ 8 17017067Skarels #endif 17116554Skarels #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 17216554Skarels #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 17316554Skarels #else 17416554Skarels #define RTHASHMOD(h) ((h) % RTHASHSIZ) 17516554Skarels #endif 17612832Ssam struct mbuf *rthost[RTHASHSIZ]; 17712832Ssam struct mbuf *rtnet[RTHASHSIZ]; 17812832Ssam struct rtstat rtstat; 17936354Ssklower struct rtentry *rtalloc1(); 18012832Ssam #endif 181