route.h revision 8876
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1980, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)route.h	8.3 (Berkeley) 4/19/94
348876Srgrimes * $Id: route.h,v 1.13 1995/03/20 21:30:21 wollman Exp $
351541Srgrimes */
361541Srgrimes
372168Spaul#ifndef _NET_ROUTE_H_
382168Spaul#define _NET_ROUTE_H_
392168Spaul
401541Srgrimes/*
411541Srgrimes * Kernel resident routing tables.
428876Srgrimes *
431541Srgrimes * The routing tables are initialized when interface addresses
441541Srgrimes * are set by making entries for all directly connected interfaces.
451541Srgrimes */
461541Srgrimes
471541Srgrimes/*
481541Srgrimes * A route consists of a destination address and a reference
491541Srgrimes * to a routing entry.  These are often held by protocols
501541Srgrimes * in their control blocks, e.g. inpcb.
511541Srgrimes */
521541Srgrimesstruct route {
531541Srgrimes	struct	rtentry *ro_rt;
541541Srgrimes	struct	sockaddr ro_dst;
551541Srgrimes};
561541Srgrimes
571541Srgrimes/*
581541Srgrimes * These numbers are used by reliable protocols for determining
591541Srgrimes * retransmission behavior and are included in the routing structure.
601541Srgrimes */
611541Srgrimesstruct rt_metrics {
621541Srgrimes	u_long	rmx_locks;	/* Kernel must leave these values alone */
631541Srgrimes	u_long	rmx_mtu;	/* MTU for this path */
641541Srgrimes	u_long	rmx_hopcount;	/* max hops expected */
651541Srgrimes	u_long	rmx_expire;	/* lifetime for route, e.g. redirect */
661541Srgrimes	u_long	rmx_recvpipe;	/* inbound delay-bandwith product */
671541Srgrimes	u_long	rmx_sendpipe;	/* outbound delay-bandwith product */
681541Srgrimes	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
691541Srgrimes	u_long	rmx_rtt;	/* estimated round trip time */
701541Srgrimes	u_long	rmx_rttvar;	/* estimated rtt variance */
711541Srgrimes	u_long	rmx_pksent;	/* packets sent using this route */
725791Swollman	u_long	rmx_filler[4];	/* will be used for T/TCP later */
731541Srgrimes};
741541Srgrimes
751541Srgrimes/*
761541Srgrimes * rmx_rtt and rmx_rttvar are stored as microseconds;
771541Srgrimes * RTTTOPRHZ(rtt) converts to a value suitable for use
781541Srgrimes * by a protocol slowtimo counter.
791541Srgrimes */
801541Srgrimes#define	RTM_RTTUNIT	1000000	/* units for rtt, rttvar, as units per sec */
811541Srgrimes#define	RTTTOPRHZ(r)	((r) / (RTM_RTTUNIT / PR_SLOWHZ))
821541Srgrimes
831541Srgrimes/*
845833Sbde * XXX kernel function pointer `rt_output' is visible to applications.
855833Sbde */
865833Sbdestruct mbuf;
875833Sbde
885833Sbde/*
891541Srgrimes * We distinguish between routes to hosts and routes to networks,
901541Srgrimes * preferring the former if available.  For each route we infer
911541Srgrimes * the interface to use from the gateway address supplied when
921541Srgrimes * the route was entered.  Routes that forward packets through
931541Srgrimes * gateways are marked so that the output routines know to address the
941541Srgrimes * gateway rather than the ultimate destination.
951541Srgrimes */
961541Srgrimes#ifndef RNF_NORMAL
971541Srgrimes#include <net/radix.h>
981541Srgrimes#endif
991541Srgrimesstruct rtentry {
1001541Srgrimes	struct	radix_node rt_nodes[2];	/* tree glue, and other values */
1011541Srgrimes#define	rt_key(r)	((struct sockaddr *)((r)->rt_nodes->rn_key))
1021541Srgrimes#define	rt_mask(r)	((struct sockaddr *)((r)->rt_nodes->rn_mask))
1031541Srgrimes	struct	sockaddr *rt_gateway;	/* value */
1047197Swollman	short	rt_filler;		/* was short flags field */
1051541Srgrimes	short	rt_refcnt;		/* # held references */
1067197Swollman	u_long	rt_flags;		/* up/down?, host/net */
1071541Srgrimes	struct	ifnet *rt_ifp;		/* the answer: interface to use */
1081541Srgrimes	struct	ifaddr *rt_ifa;		/* the answer: interface to use */
1091541Srgrimes	struct	sockaddr *rt_genmask;	/* for generation of cloned routes */
1101541Srgrimes	caddr_t	rt_llinfo;		/* pointer to link level info cache */
1111541Srgrimes	struct	rt_metrics rt_rmx;	/* metrics used by rx'ing protocols */
1121541Srgrimes	struct	rtentry *rt_gwroute;	/* implied entry for gatewayed routes */
1135791Swollman	int	(*rt_output) __P((struct rtentry *, struct mbuf *,
1145791Swollman				  struct sockaddr *, int));
1155791Swollman					/* output routine for this (rt,if) */
1165791Swollman	struct	rtentry *rt_parent; 	/* cloning parent of this route */
1177197Swollman	void	*rt_filler2;		/* more filler */
1181541Srgrimes};
1191541Srgrimes
1201541Srgrimes/*
1211541Srgrimes * Following structure necessary for 4.3 compatibility;
1221541Srgrimes * We should eventually move it to a compat file.
1231541Srgrimes */
1241541Srgrimesstruct ortentry {
1251541Srgrimes	u_long	rt_hash;		/* to speed lookups */
1261541Srgrimes	struct	sockaddr rt_dst;	/* key */
1271541Srgrimes	struct	sockaddr rt_gateway;	/* value */
1281541Srgrimes	short	rt_flags;		/* up/down?, host/net */
1291541Srgrimes	short	rt_refcnt;		/* # held references */
1301541Srgrimes	u_long	rt_use;			/* raw # packets forwarded */
1311541Srgrimes	struct	ifnet *rt_ifp;		/* the answer: interface to use */
1321541Srgrimes};
1331541Srgrimes
1344104Swollman#define rt_use rt_rmx.rmx_pksent
1354104Swollman
1361541Srgrimes#define	RTF_UP		0x1		/* route usable */
1371541Srgrimes#define	RTF_GATEWAY	0x2		/* destination is a gateway */
1381541Srgrimes#define	RTF_HOST	0x4		/* host entry (net otherwise) */
1391541Srgrimes#define	RTF_REJECT	0x8		/* host or net unreachable */
1401541Srgrimes#define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
1411541Srgrimes#define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
1421541Srgrimes#define RTF_DONE	0x40		/* message confirmed */
1431541Srgrimes#define RTF_MASK	0x80		/* subnet mask present */
1441541Srgrimes#define RTF_CLONING	0x100		/* generate new routes on use */
1451541Srgrimes#define RTF_XRESOLVE	0x200		/* external daemon resolves name */
1461541Srgrimes#define RTF_LLINFO	0x400		/* generated by ARP or ESIS */
1471541Srgrimes#define RTF_STATIC	0x800		/* manually added */
1481541Srgrimes#define RTF_BLACKHOLE	0x1000		/* just discard pkts (during updates) */
1491541Srgrimes#define RTF_PROTO2	0x4000		/* protocol specific routing flag */
1501541Srgrimes#define RTF_PROTO1	0x8000		/* protocol specific routing flag */
1511541Srgrimes
1525099Swollman#define RTF_PRCLONING	0x10000		/* protocol requires cloning */
1535099Swollman#define RTF_WASCLONED	0x20000		/* route generated through cloning */
1545099Swollman#define RTF_PROTO3	0x40000		/* protocol specific routing flag */
1555791Swollman#define RTF_CHAINDELETE	0x80000		/* chain is being deleted (internal) */
1566245Swollman#define RTF_PINNED	0x100000	/* future use */
1576245Swollman					/* 0x200000 and up unassigned */
1581541Srgrimes
1591541Srgrimes/*
1601541Srgrimes * Routing statistics.
1611541Srgrimes */
1621541Srgrimesstruct	rtstat {
1631541Srgrimes	short	rts_badredirect;	/* bogus redirect calls */
1641541Srgrimes	short	rts_dynamic;		/* routes created by redirects */
1651541Srgrimes	short	rts_newgateway;		/* routes modified by redirects */
1661541Srgrimes	short	rts_unreach;		/* lookups which failed */
1671541Srgrimes	short	rts_wildcard;		/* lookups satisfied by a wildcard */
1681541Srgrimes};
1691541Srgrimes/*
1701541Srgrimes * Structures for routing messages.
1711541Srgrimes */
1721541Srgrimesstruct rt_msghdr {
1731541Srgrimes	u_short	rtm_msglen;	/* to skip over non-understood messages */
1741541Srgrimes	u_char	rtm_version;	/* future binary compatibility */
1751541Srgrimes	u_char	rtm_type;	/* message type */
1761541Srgrimes	u_short	rtm_index;	/* index for associated ifp */
1771541Srgrimes	int	rtm_flags;	/* flags, incl. kern & message, e.g. DONE */
1781541Srgrimes	int	rtm_addrs;	/* bitmask identifying sockaddrs in msg */
1791541Srgrimes	pid_t	rtm_pid;	/* identify sender */
1801541Srgrimes	int	rtm_seq;	/* for sender to identify action */
1811541Srgrimes	int	rtm_errno;	/* why failed */
1821541Srgrimes	int	rtm_use;	/* from rtentry */
1831541Srgrimes	u_long	rtm_inits;	/* which metrics we are initializing */
1841541Srgrimes	struct	rt_metrics rtm_rmx; /* metrics themselves */
1851541Srgrimes};
1861541Srgrimes
1875791Swollman#define RTM_VERSION	5	/* Up the ante and ignore older versions */
1881541Srgrimes
1891541Srgrimes#define RTM_ADD		0x1	/* Add Route */
1901541Srgrimes#define RTM_DELETE	0x2	/* Delete Route */
1911541Srgrimes#define RTM_CHANGE	0x3	/* Change Metrics or flags */
1921541Srgrimes#define RTM_GET		0x4	/* Report Metrics */
1931541Srgrimes#define RTM_LOSING	0x5	/* Kernel Suspects Partitioning */
1941541Srgrimes#define RTM_REDIRECT	0x6	/* Told to use different route */
1951541Srgrimes#define RTM_MISS	0x7	/* Lookup failed on this address */
1961541Srgrimes#define RTM_LOCK	0x8	/* fix specified metrics */
1971541Srgrimes#define RTM_OLDADD	0x9	/* caused by SIOCADDRT */
1981541Srgrimes#define RTM_OLDDEL	0xa	/* caused by SIOCDELRT */
1991541Srgrimes#define RTM_RESOLVE	0xb	/* req to resolve dst to LL addr */
2001541Srgrimes#define RTM_NEWADDR	0xc	/* address being added to iface */
2011541Srgrimes#define RTM_DELADDR	0xd	/* address being removed from iface */
2021541Srgrimes#define RTM_IFINFO	0xe	/* iface going up/down etc. */
2031541Srgrimes
2041541Srgrimes#define RTV_MTU		0x1	/* init or lock _mtu */
2051541Srgrimes#define RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
2061541Srgrimes#define RTV_EXPIRE	0x4	/* init or lock _hopcount */
2071541Srgrimes#define RTV_RPIPE	0x8	/* init or lock _recvpipe */
2081541Srgrimes#define RTV_SPIPE	0x10	/* init or lock _sendpipe */
2091541Srgrimes#define RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
2101541Srgrimes#define RTV_RTT		0x40	/* init or lock _rtt */
2111541Srgrimes#define RTV_RTTVAR	0x80	/* init or lock _rttvar */
2121541Srgrimes
2131541Srgrimes/*
2141541Srgrimes * Bitmask values for rtm_addr.
2151541Srgrimes */
2161541Srgrimes#define RTA_DST		0x1	/* destination sockaddr present */
2171541Srgrimes#define RTA_GATEWAY	0x2	/* gateway sockaddr present */
2181541Srgrimes#define RTA_NETMASK	0x4	/* netmask sockaddr present */
2191541Srgrimes#define RTA_GENMASK	0x8	/* cloning mask sockaddr present */
2201541Srgrimes#define RTA_IFP		0x10	/* interface name sockaddr present */
2211541Srgrimes#define RTA_IFA		0x20	/* interface addr sockaddr present */
2221541Srgrimes#define RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
2231541Srgrimes#define RTA_BRD		0x80	/* for NEWADDR, broadcast or p-p dest addr */
2241541Srgrimes
2251541Srgrimes/*
2261541Srgrimes * Index offsets for sockaddr array for alternate internal encoding.
2271541Srgrimes */
2281541Srgrimes#define RTAX_DST	0	/* destination sockaddr present */
2291541Srgrimes#define RTAX_GATEWAY	1	/* gateway sockaddr present */
2301541Srgrimes#define RTAX_NETMASK	2	/* netmask sockaddr present */
2311541Srgrimes#define RTAX_GENMASK	3	/* cloning mask sockaddr present */
2321541Srgrimes#define RTAX_IFP	4	/* interface name sockaddr present */
2331541Srgrimes#define RTAX_IFA	5	/* interface addr sockaddr present */
2341541Srgrimes#define RTAX_AUTHOR	6	/* sockaddr for author of redirect */
2351541Srgrimes#define RTAX_BRD	7	/* for NEWADDR, broadcast or p-p dest addr */
2361541Srgrimes#define RTAX_MAX	8	/* size of array to allocate */
2371541Srgrimes
2381541Srgrimesstruct rt_addrinfo {
2391541Srgrimes	int	rti_addrs;
2401541Srgrimes	struct	sockaddr *rti_info[RTAX_MAX];
2411541Srgrimes};
2421541Srgrimes
2431541Srgrimesstruct route_cb {
2441541Srgrimes	int	ip_count;
2451541Srgrimes	int	ns_count;
2461541Srgrimes	int	iso_count;
2471541Srgrimes	int	any_count;
2481541Srgrimes};
2491541Srgrimes
2501541Srgrimes#ifdef KERNEL
2511541Srgrimes#define	RTFREE(rt) \
2521541Srgrimes	if ((rt)->rt_refcnt <= 1) \
2531541Srgrimes		rtfree(rt); \
2541541Srgrimes	else \
2551541Srgrimes		(rt)->rt_refcnt--;
2561541Srgrimes
2571541Srgrimesstruct	route_cb route_cb;
2581541Srgrimesstruct	rtstat	rtstat;
2591541Srgrimesstruct	radix_node_head *rt_tables[AF_MAX+1];
2601541Srgrimes
2611541Srgrimesvoid	 route_init __P((void));
2621541Srgrimesint	 route_output __P((struct mbuf *, struct socket *));
2631541Srgrimesint	 route_usrreq __P((struct socket *,
2641541Srgrimes	    int, struct mbuf *, struct mbuf *, struct mbuf *));
2651541Srgrimesvoid	 rt_ifmsg __P((struct ifnet *));
2661541Srgrimesvoid	 rt_maskedcopy __P((struct sockaddr *,
2671541Srgrimes	    struct sockaddr *, struct sockaddr *));
2681541Srgrimesvoid	 rt_missmsg __P((int, struct rt_addrinfo *, int, int));
2691541Srgrimesvoid	 rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *));
2701541Srgrimesint	 rt_setgate __P((struct rtentry *,
2711541Srgrimes	    struct sockaddr *, struct sockaddr *));
2721541Srgrimesvoid	 rt_setmetrics __P((u_long, struct rt_metrics *, struct rt_metrics *));
2731541Srgrimesvoid	 rtable_init __P((void **));
2741541Srgrimesvoid	 rtalloc __P((struct route *));
2755099Swollmanvoid	 rtalloc_ign __P((struct route *, unsigned long));
2761541Srgrimesstruct rtentry *
2775099Swollman	 rtalloc1 __P((struct sockaddr *, int, unsigned long));
2781541Srgrimesvoid	 rtfree __P((struct rtentry *));
2791541Srgrimesint	 rtinit __P((struct ifaddr *, int, int));
2801541Srgrimesint	 rtioctl __P((int, caddr_t, struct proc *));
2811549Srgrimesvoid	 rtredirect __P((struct sockaddr *, struct sockaddr *,
2821541Srgrimes	    struct sockaddr *, int, struct sockaddr *, struct rtentry **));
2831541Srgrimesint	 rtrequest __P((int, struct sockaddr *,
2841541Srgrimes	    struct sockaddr *, struct sockaddr *, int, struct rtentry **));
2851541Srgrimes#endif
2862168Spaul
2872168Spaul#endif
288