/* * © Copyright 1976, 2004 Hewlett-Packard Development Company, L.P. * * Confidential computer software. Valid license from HP and/or its * subsidiaries required for possession, use, or copying. * * Consistent with FAR 12.211 and 12.212, Commercial Computer Software, * Computer Software Documentation, and Technical Data for Commercial * Items are licensed to the U.S. Government under vendor's standard * commercial license. * * Neither HP nor any of its subsidiaries shall be liable for technical * or editorial errors or omissions contained herein. The information * in this document is provided "as is" without warranty of any kind * and is subject to change without notice. The warranties for HP * products are set forth in the express limited warranty statements * accompanying such products. Nothing herein should be construed as * constituting an additional warranty. */ /* * HISTORY */ /* * @(#)$RCSfile: route.h,v $ $Revision: 4.2.51.2 $ (DEC) $Date: 2001/12/17 20:54:39 $ */ /* */ /* * (c) Copyright 1990, OPEN SOFTWARE FOUNDATION, INC. * ALL RIGHTS RESERVED */ /* * OSF/1 Release 1.0 */ /* * Copyright (C) 1988,1989 Encore Computer Corporation. All Rights Reserved * * Property of Encore Computer Corporation. * This software is made available solely pursuant to the terms of * a software license agreement which governs its use. Unauthorized * duplication, distribution or sale are strictly prohibited. * */ /* * Copyright (c) 1980, 1986 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted provided * that: (1) source distributions retain this entire copyright notice and * comment, and (2) distributions including binaries display the following * acknowledgement: ``This product includes software developed by the * University of California, Berkeley and its contributors'' in the * documentation or other materials provided with the distribution and in * all advertising materials mentioning features or use of this software. * Neither the name of the University nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Base: route.h 7.4 (Berkeley) 6/27/88 * Merged: route.h 7.11 (Berkeley) 6/28/90 */ #ifndef _ROUTE_H_ #define _ROUTE_H_ /* forward decls for DECC and C++ */ struct mip6_binding_cache; /* * Kernel resident routing tables. * * The routing tables are initialized when interface addresses * are set by making entries for all directly connected interfaces. */ /* * A route consists of a destination address and a reference * to a routing entry. These are often held by protocols * in their control blocks, e.g. inpcb. */ struct route { struct rtentry *ro_rt; struct sockaddr ro_dst; }; /* * These numbers are used by reliable protocols for determining * retransmission behavior and are included in the routing structure. */ struct rt_metrics { u_int rmx_locks; /* Kernel must leave these values alone */ u_int rmx_mtu; /* MTU for this path */ u_int rmx_hopcount; /* max hops expected */ u_int rmx_expire; /* lifetime for route, e.g. redirect */ u_int rmx_recvpipe; /* inbound delay-bandwith product */ u_int rmx_sendpipe; /* outbound delay-bandwith product */ u_int rmx_ssthresh; /* outbound gateway buffer limit */ u_int rmx_rtt; /* estimated round trip time */ u_int rmx_rttvar; /* estimated rtt variance */ }; /* * rmx_rtt and rmx_rttvar are stored as microseconds; * RTTTOPRHZ(rtt) converts to a value suitable for use * by a protocol slowtimo counter. */ #define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ #define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ)) /* * We distinguish between routes to hosts and routes to networks, * preferring the former if available. For each route we infer * the interface to use from the gateway address supplied when * the route was entered. Routes that forward packets through * gateways are marked so that the output routines know to address the * gateway rather than the ultimate destination. */ #ifndef RNF_NORMAL #include "net/radix.h" #endif struct rtentry { struct radix_node rt_nodes[2]; /* tree glue, and other values */ #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) struct sockaddr *rt_gateway; /* value */ int rt_flags; /* up/down?, host/net */ int rt_refcnt; /* # held references */ u_long rt_use; /* raw # packets forwarded */ struct ifnet *rt_ifp; /* the answer: interface to use */ struct ifaddr *rt_ifa; /* the answer: interface to use */ struct sockaddr *rt_genmask; /* for generation of cloned routes */ caddr_t rt_llinfo; /* pointer to link level info cache */ struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ short rt_idle; /* easy to tell llayer still live */ short rt_aliasid; /* cluster aliasid id of dst */ u_int rt_precedence; /* precedence */ #if SEC_NET struct tnrh_rem_host *rt_host; /* Remote host structure. */ #endif struct rtentry *rt_gwroute; /* entry for gateway route */ struct mip6_binding_cache *rt_mip6cache;/* ptr to Mobile IPv6 binding */ u_long rt_reserved[5]; /* reserved for future use */ }; /* * Following structure necessary for 4.3 compatibility; * We should eventually move it to a compat file. */ struct ortentry { u_int rt_hash; /* to speed lookups */ struct sockaddr rt_dst; /* key */ struct sockaddr rt_gateway; /* value */ short rt_flags; /* up/down?, host/net */ short rt_refcnt; /* # held references */ u_int rt_use; /* raw # packets forwarded */ struct ifnet *rt_ifp; /* the answer: interface to use */ }; #define RTF_UP 0x00000001 /* route useable */ #define RTF_GATEWAY 0x00000002 /* destination is through a gateway */ #define RTF_HOST 0x00000004 /* host entry (net otherwise) */ #define RTF_REJECT 0x00000008 /* host or net unreachable */ #define RTF_DYNAMIC 0x00000010 /* created dynamically (by redirect) */ #define RTF_MODIFIED 0x00000020 /* modified dynamically (by redirect) */ #define RTF_DONE 0x00000040 /* message confirmed */ #define RTF_MASK 0x00000080 /* subnet mask present */ #define RTF_CLONING 0x00000100 /* generate new routes on use */ #define RTF_XRESOLVE 0x00000200 /* external daemon resolves name */ #define RTF_LLINFO 0x00000400 /* generated by ARP or ESIS */ #define RTF_STATIC 0x00000800 /* manually added */ #define RTF_BLACKHOLE 0x00001000 /* just discard pkts (during updates) */ #define RTF_PROTO3 0x00002000 /* protocol specific routing flag */ #define RTF_PROTO2 0x00004000 /* protocol specific routing flag */ #define RTF_PROTO1 0x00008000 /* protocol specific routing flag */ #define RTF_WASCLONED 0x00010000 /* route entry was cloned */ #define RTF_ALLROUTES 0x00040000 /* add/delete all possible routes */ #define RTF_LOOPBACK 0x00080000 /* send packets over loopback device */ #define RTF_CLUALIAS 0x00100000 /* route to a cluster alias */ #define RTF_ISGATEWAY 0x00200000 /* destination is a gateway */ #define RTF_LLVALID 0x00400000 /* link layer address is valid */ #define RTF_MOBILE 0x00800000 /* route to a mobile node */ /* * used in struct rtgetreq: */ #define RTF_NOT_MROUTING 0x10000000 /* vif_mask/ifc_mask invalid */ #define RTF_SND_USES_SHARED_TREE 0x20000000 #define RTF_ALL_USE_SHARED_TREE 0x40000000 #include /* * Define the event names */ #define EVENT_ROUTE_IP_ADD _EvmSYSTEM_EVENT_NAME("net.route.ip.add") #define EVENT_ROUTE_IP_DELETE _EvmSYSTEM_EVENT_NAME("net.route.ip.delete") #define EVENT_ROUTE_IP_CHANGE _EvmSYSTEM_EVENT_NAME("net.route.ip.change") /* * Structures for routing messages. */ struct rt_msghdr { u_short rtm_msglen; /* to skip over non-understood messages */ u_char rtm_version; /* future binary compatability */ u_char rtm_type; /* message type */ u_short rtm_index; /* index for associated ifp */ #ifdef __digital__ int rtm_pid; /* identify sender */ #else pid_t rtm_pid; /* identify sender */ #endif int rtm_addrs; /* bitmask identifying sockaddrs in msg */ int rtm_seq; /* for sender to identify action */ int rtm_errno; /* why failed */ int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ int rtm_use; /* from rtentry */ u_int rtm_inits; /* which metrics we are initializing */ struct rt_metrics rtm_rmx; /* metrics themselves */ }; struct ip6_msghdr { u_short ip6m_msglen; /* to skip over non-understood messages */ u_char ip6m_version; /* PF_ROUTE msg version for * future binary compatibility */ u_char ip6m_type; /* message type */ int ip6m_addrs; /* bitmask indentifying sockaddrs in msg */ int ip6m_op; /* sub-type indicating operation * (INIT, AIFADDR etc.) */ int ip6m_ifindex; /* index of associated ifnet */ union { /* IPV6 specific info */ int ip6m_addrflags; /* address flags for AIFADDR/DIFADDR */ int ip6m_ifnetflags; /* value of if_flags for INIT/UNINIT*/ }ip6m_msghdr_un; }; #define ip6m_aflags ip6m_msghdr_un.ip6m_addrflags #define ip6m_ifflags ip6m_msghdr_un.ip6m_ifnetflags #define IP6M_INIT 0x1 /* SIOCIPV6IFINIT */ #define IP6M_UNINIT 0x2 /* SIOCIPV6IFUNINIT */ #define IP6M_AIFADDR 0x3 /* SIOCIPV6AIFADDR */ #define IP6M_DIFADDR 0x4 /* SIOCIPV6DIFADDR */ struct route_cb { int count[AF_MAX]; }; #define ip_count count[AF_INET] #define ns_count count[AF_NS] #define iso_count count[AF_ISO] #define any_count count[AF_UNSPEC] #ifdef _KERNEL #ifndef REPLICATED #define REPLICATED #endif /* * Global route timestamps, updated on route table changes * Initialized to: 1 */ extern REPLICATED u_long route_timestamp; extern REPLICATED u_long route6_timestamp; /* * Routing modes for >1 interface on the same subnet * * Current modes are: * 0 = multiple routes behavior based on rt->rt_refcnt and rt->rt_use * Default: 0 * * NOTE: Currently unused */ extern int routemode; /* * When set to 1, this triggers the routing code to automatically add all * possible routes to a destination through all relevant interfaces. * Similar to using 'route add -net net gw -all' * Default: 0 */ extern REPLICATED int routeallroutes; /* * When set to 1, this triggers the routing code to automatically scrub, * or flush, all routes through an interface when the last address * associated with the interface is deleted (e.g. ifconfig tu0 down delete). * Default: 1 */ extern int routescrub; /* * When set to 1, this allows the routing code to fail-over a route from * one interface to another in the same subnet when the last address * associated with the interface is deleted (e.g. ifconfig tu0 down delete). * 'routescrub' must be set to 1 for this to have any effect. * Default: 0 */ extern int routefailover; /* * When set to 1, this turns-on printf debugging in the routing code for * add/delete/change cases. When set to 2, this also turns-on printf * debugging in the routing code for lookup cases. When set to 3, you get * the radix code as well. NOTE: Most printfs at levels >1 require a * recompile of the kernel with ROUTEDEBUG defined. * Default: 0 */ extern REPLICATED int routedebug; /* Structure for multiple routes support */ struct mr_ifp { struct ifaddr *ifa; struct ifnet *ifp; struct mr_ifp *next; }; /* Structure for RAD support */ struct rad_rt_update { struct rtentry *rru_cur_rt; /* current rtentry pointer */ struct rtentry rru_rt; /* holds new rtentry values */ int rru_flags; /* see RRU_*_FLAGS below */ u_int rru_rtm_inits; /* which metrics we are initializing */ int rru_ifa_req; /* request to issue to rt_ifa->ifa_rt_request */ int rru_inc_timestamp; /* increment route*_timestamp? */ }; #define RRU_IGNORE_FLAGS 0 /* ignore rt->rt_flags (default) */ #define RRU_OR_FLAGS 1 /* OR-in rt->rt_flags */ #define RRU_AND_FLAGS 2 /* AND-in rt->rt_flags */ #define RRU_SET_FLAGS 3 /* set rt->rt_flags */ /* Flags for kernel internal rtalloc*()/rn_match*() calls */ #define RTALLOC_REPORT 0x00000001 /* report desired */ #define RTALLOC_GLOBAL 0x00000002 /* route from any RAD is OK */ #define RTALLOC_LOADBALANCE 0x00000004 /* find "best" if duplicates */ #define RTALLOC_NOMOBILE 0x00000008 /* RTF_MOBILE not desired */ #endif /* _KERNEL */ #define RTM_VERSION 2 /* Up the ante and ignore older versions */ #define RTM_ADD 0x1 /* Add Route */ #define RTM_DELETE 0x2 /* Delete Route */ #define RTM_CHANGE 0x3 /* Change Metrics or flags */ #define RTM_GET 0x4 /* Report Metrics */ #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ #define RTM_REDIRECT 0x6 /* Told to use different route */ #define RTM_MISS 0x7 /* Lookup failed on this address */ #define RTM_LOCK 0x8 /* fix specified metrics */ #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ #define RTM_NEWADDR 0xc /* address being added to iface */ #define RTM_DELADDR 0xd /* address being removed from iface */ #define RTM_IFINFO 0xe /* iface going up/down etc. */ #define RTM_VIFINFO 0xf /* vif going up/down etc. */ /* * sockaddr usage in RTM_MC_xxx messages: * RTA_DST: multicast group * RTA_SRC: origin * RTA_BITMAP: vif_mask/ifc_mask put into a struct sockaddr: * sa_family is AF_UNSPEC, sa_len is length in bytes * sa_data contains some padding for 4/8 byte alignment * followed by the bitmask * * usage of struct rt_msghdr elements in RTM_MC_xxx messages: * rtm_index: expected incoming vif/interface */ #define RTM_MC_ADD 0x10 /* multicast route added notification */ #define RTM_MC_DELETE 0x11 /* multicast route deleted notification */ #define RTM_MC_CHANGE 0x12 /* multicast route changed notification */ #define RTM_IPV6INFO 0x13 /* ipv6 related routing messages */ #define RTM_CONFIRM 0x100 /* llinfo is still good */ #define RTV_MTU 0x1 /* init or lock _mtu */ #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ #define RTV_EXPIRE 0x4 /* init or lock _expire */ #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ #define RTV_RTT 0x40 /* init or lock _rtt */ #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ /* * Bitmask values for rtm_addr. */ #define RTA_DST 0x1 /* destination sockaddr present */ #define RTA_GATEWAY 0x2 /* gateway sockaddr present */ #define RTA_NETMASK 0x4 /* netmask sockaddr present */ #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ #define RTA_IFP 0x10 /* interface name sockaddr present */ #define RTA_IFA 0x20 /* interface addr sockaddr present */ #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ #define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */ #define RTA_SRC 0x100 /* for RTM_MC_xxx */ #define RTA_BITMAP 0x200 /* for RTM_MC_xxx */ #define RTA_PRECEDENCE 0x400 /* precedence present */ #define RTA_OLDGATEWAY 0x800 /* old gateway sockaddr present */ #define RTA_OLDIFINDEX 0x1000 /* old interface name sockaddr present */ #define RT_ROUNDUP(sa) \ ((int)(((sa)->sa_len + (sizeof(long) - 1)) & ~(sizeof(long) - 1))) #ifdef _KERNEL /* AF_INET family route lock macros */ #if NETSYNC_LOCK ndecl_lock_data(extern, route_lock) #define ROUTE_LOCKINIT() ulock_setup(&route_lock, route_li, TRUE) #define ROUTE_LOCK_DECL() NETSPL_DECL(_rs) #define ROUTE_READ_LOCK() { NETSPL(_rs,net); ulock_read(&route_lock); } #define ROUTE_UNLOCK() { ulock_done(&route_lock); NETSPLX(_rs); } #define ROUTE_WRITE_LOCK() { NETSPL(_rs,net); ulock_write(&route_lock); } #define ROUTE_WRITETOREAD_LOCK() { ulock_write_to_read(&route_lock); } #else #define ROUTE_LOCKINIT() #define ROUTE_LOCK_DECL() #define ROUTE_READ_LOCK() #define ROUTE_UNLOCK() #define ROUTE_WRITE_LOCK() #define ROUTE_WRITETOREAD_LOCK() #endif /* NETSYNC_LOCK */ /* AF_INET6 family route lock macros */ #if NETSYNC_LOCK ndecl_lock_data(extern, route6_lock) #define ROUTE6_LOCKINIT() ulock_setup(&route6_lock, route6_li, TRUE) #define ROUTE6_LOCK_DECL() NETSPL_DECL(_rs6) #define ROUTE6_READ_LOCK() { NETSPL(_rs6,net); ulock_read(&route6_lock); } #define ROUTE6_UNLOCK() { ulock_done(&route6_lock); NETSPLX(_rs6); } #define ROUTE6_WRITE_LOCK() { NETSPL(_rs6,net); ulock_write(&route6_lock); } #define ROUTE6_WRITETOREAD_LOCK() { ulock_write_to_read(&route6_lock); } #else #define ROUTE6_LOCKINIT() #define ROUTE6_LOCK_DECL() #define ROUTE6_READ_LOCK() #define ROUTE6_UNLOCK() #define ROUTE6_WRITE_LOCK() #define ROUTE6_WRITETOREAD_LOCK() #endif /* NETSYNC_LOCK */ /* * Generic macros to lock the correct family's route lock. * AF_INET6 uses the route6_lock, all others use the route_lock. */ #if NETSYNC_LOCK #define ROUTE_LOCK_DECL_AF() NETSPL_DECL2(_rs, _rs6) #define ROUTE_READ_LOCK_AF(af) { \ if ((af) == AF_INET6) \ ROUTE6_READ_LOCK() \ else \ ROUTE_READ_LOCK() \ } #define ROUTE_UNLOCK_AF(af) { \ if ((af) == AF_INET6) \ ROUTE6_UNLOCK() \ else \ ROUTE_UNLOCK() \ } #define ROUTE_WRITE_LOCK_AF(af) { \ if ((af) == AF_INET6) \ ROUTE6_WRITE_LOCK() \ else \ ROUTE_WRITE_LOCK() \ } #define ROUTE_WRITETOREAD_LOCK_AF(af) { \ if ((af) == AF_INET6) \ ROUTE6_WRITETOREAD_LOCK() \ else \ ROUTE_WRITETOREAD_LOCK() \ } /* * Generic macro to check if we're holding a family's route lock. */ #define ROUTE_LOCK_HOLDER_AF(af) \ (((af) == AF_INET6 && lock_holder(&route6_lock)) || \ ((af) != AF_INET6 && lock_holder(&route_lock))) #else #define ROUTE_LOCK_DECL_AF() #define ROUTE_READ_LOCK_AF(af) #define ROUTE_UNLOCK_AF(af) #define ROUTE_WRITE_LOCK_AF(af) #define ROUTE_WRITETOREAD_LOCK_AF(af) #define ROUTE_LOCK_HOLDER_AF(af) 1 #endif /* NETSYNC_LOCK */ #define ROUTE_INC_REFCNT(rt) (atomic_incl(&((rt).rt_refcnt))) #define ROUTE_DEC_REFCNT(rt) (atomic_decl(&((rt).rt_refcnt))) /* * Macros to increment the global route timestamps - this will tell * everyone the route table just changed. We don't want a zero * timestamp since we always want bzero'd structures to rtalloc(). * AF_INET6 uses the route6_timestamp, all others use the route_timestamp. */ #define INC_ROUTE_TIMESTAMP() { \ u_long _stamp = route_timestamp + 1; \ write_const_data((void *)&_stamp, \ (void *)&route_timestamp, \ sizeof(u_long)); \ } #define INC_ROUTE6_TIMESTAMP() { \ u_long _stamp = route6_timestamp + 1; \ write_const_data((void *)&_stamp, \ (void *)&route6_timestamp, \ sizeof(u_long)); \ } #define INC_ROUTE_TIMESTAMP_AF(af) { \ if ((af) == AF_INET6) \ INC_ROUTE6_TIMESTAMP() \ else \ INC_ROUTE_TIMESTAMP() \ } #if NETSYNC_LOCK #define RTFREE(rt) rtfree(rt) #define RTFREENL(rt) rtfreeNL(rt) #else /* !NETSYNC_LOCK */ #define RTFREE(rt) \ if ((rt)->rt_refcnt <= 1) \ rtfree(rt); \ else \ atomic_decl(&rt->rt_refcnt); #define RTFREENL(rt) \ if ((rt)->rt_refcnt <= 1) \ rtfreeNL(rt); \ else \ atomic_decl(&rt->rt_refcnt); #endif extern struct route_cb route_cb; extern struct rtstat rtstat; extern struct radix_node_head *rnheads[AF_MAX+1]; #endif #endif