xref: /illumos-gate/usr/src/uts/common/net/route.h (revision 550b6e40)
17c478bd9Sstevel@tonic-gate /*
2*550b6e40SSowmini Varadhan  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
37c478bd9Sstevel@tonic-gate  */
47c478bd9Sstevel@tonic-gate /*
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1993
67c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
97c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
107c478bd9Sstevel@tonic-gate  * are met:
117c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
127c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
137c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
147c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
157c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
167c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
177c478bd9Sstevel@tonic-gate  *    must display the following acknowledgement:
187c478bd9Sstevel@tonic-gate  *	This product includes software developed by the University of
197c478bd9Sstevel@tonic-gate  *	California, Berkeley and its contributors.
207c478bd9Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
217c478bd9Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
227c478bd9Sstevel@tonic-gate  *    without specific prior written permission.
237c478bd9Sstevel@tonic-gate  *
247c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
257c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
267c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
277c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
287c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
297c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
307c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
317c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
327c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
337c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
347c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Kernel resident routing tables.
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * The routing tables are initialized when interface addresses
417c478bd9Sstevel@tonic-gate  * are set by making entries for all directly connected interfaces.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifndef	_NET_ROUTE_H
457c478bd9Sstevel@tonic-gate #define	_NET_ROUTE_H
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* from UCB 8.5 (Berkeley) 2/8/95 */
487c478bd9Sstevel@tonic-gate 
4945916cd2Sjpk #include <sys/tsol/label.h>
5045916cd2Sjpk #include <sys/tsol/label_macro.h>
5145916cd2Sjpk 
527c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
537c478bd9Sstevel@tonic-gate extern "C" {
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * A route consists of a destination address and a reference
587c478bd9Sstevel@tonic-gate  * to a routing entry.  These are often held by protocols
597c478bd9Sstevel@tonic-gate  * in their control blocks, e.g. inpcb.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate struct route {
627c478bd9Sstevel@tonic-gate 	struct	rtentry *ro_rt;
637c478bd9Sstevel@tonic-gate 	struct	sockaddr ro_dst;
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * These numbers are used by reliable protocols for determining
687c478bd9Sstevel@tonic-gate  * retransmission behavior and are included in the routing structure.
697c478bd9Sstevel@tonic-gate  *
707c478bd9Sstevel@tonic-gate  * rmx_rtt and rmx_rttvar are stored as microseconds;
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate typedef struct rt_metrics {
737c478bd9Sstevel@tonic-gate 	uint32_t	rmx_locks;	/* Kernel must leave these values */
747c478bd9Sstevel@tonic-gate 					/* alone */
757c478bd9Sstevel@tonic-gate 	uint32_t	rmx_mtu;	/* MTU for this path */
767c478bd9Sstevel@tonic-gate 	uint32_t	rmx_hopcount;	/* max hops expected */
777c478bd9Sstevel@tonic-gate 	uint32_t	rmx_expire;	/* lifetime for route, e.g. redirect */
787c478bd9Sstevel@tonic-gate 	uint32_t	rmx_recvpipe;	/* inbound delay-bandwith product */
797c478bd9Sstevel@tonic-gate 	uint32_t	rmx_sendpipe;	/* outbound delay-bandwith product */
807c478bd9Sstevel@tonic-gate 	uint32_t	rmx_ssthresh;	/* outbound gateway buffer limit */
817c478bd9Sstevel@tonic-gate 	uint32_t	rmx_rtt;	/* estimated round trip time */
827c478bd9Sstevel@tonic-gate 	uint32_t	rmx_rttvar;	/* estimated rtt variance */
837c478bd9Sstevel@tonic-gate 	uint32_t	rmx_pksent;	/* packets sent using this route */
847c478bd9Sstevel@tonic-gate } rt_metrics_t;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * OLD rtentry structure not used in the kernel. Instead the kernel
887c478bd9Sstevel@tonic-gate  * uses struct ire defined in <inet/ip.h>.
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  * We distinguish between routes to hosts and routes to networks,
917c478bd9Sstevel@tonic-gate  * preferring the former if available.  For each route we infer
927c478bd9Sstevel@tonic-gate  * the interface to use from the gateway address supplied when
937c478bd9Sstevel@tonic-gate  * the route was entered.  Routes that forward packets through
947c478bd9Sstevel@tonic-gate  * gateways are marked so that the output routines know to address the
957c478bd9Sstevel@tonic-gate  * gateway rather than the ultimate destination.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate struct rtentry {
987c478bd9Sstevel@tonic-gate 	uint_t	rt_hash;		/* to speed lookups */
997c478bd9Sstevel@tonic-gate 	struct	sockaddr rt_dst;	/* key */
1007c478bd9Sstevel@tonic-gate 	struct	sockaddr rt_gateway;	/* value */
1017c478bd9Sstevel@tonic-gate 	short	rt_flags;		/* up/down?, host/net */
1027c478bd9Sstevel@tonic-gate 	short	rt_refcnt;		/* # held references */
1037c478bd9Sstevel@tonic-gate 	uint_t	rt_use;			/* raw # packets forwarded */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * The kernel does not use this field, and without it the structure is
1077c478bd9Sstevel@tonic-gate  * datamodel independent.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
1107c478bd9Sstevel@tonic-gate 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
1117c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) */
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	RTF_UP		0x1		/* route usable */
1157c478bd9Sstevel@tonic-gate #define	RTF_GATEWAY	0x2		/* destination is a gateway */
1167c478bd9Sstevel@tonic-gate #define	RTF_HOST	0x4		/* host entry (net otherwise) */
1177c478bd9Sstevel@tonic-gate #define	RTF_REJECT	0x8		/* host or net unreachable */
1187c478bd9Sstevel@tonic-gate #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
1197c478bd9Sstevel@tonic-gate #define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
1207c478bd9Sstevel@tonic-gate #define	RTF_DONE	0x40		/* message confirmed */
1217c478bd9Sstevel@tonic-gate #define	RTF_MASK	0x80		/* subnet mask present */
1227c478bd9Sstevel@tonic-gate #define	RTF_CLONING	0x100		/* generate new routes on use */
1237c478bd9Sstevel@tonic-gate #define	RTF_XRESOLVE	0x200		/* external daemon resolves name */
1247c478bd9Sstevel@tonic-gate #define	RTF_LLINFO	0x400		/* generated by ARP or ESIS */
1257c478bd9Sstevel@tonic-gate #define	RTF_STATIC	0x800		/* manually added */
1267c478bd9Sstevel@tonic-gate #define	RTF_BLACKHOLE	0x1000		/* just discard pkts (during updates) */
1277c478bd9Sstevel@tonic-gate #define	RTF_PRIVATE	0x2000		/* do not advertise this route */
1287c478bd9Sstevel@tonic-gate #define	RTF_PROTO2	0x4000		/* protocol specific routing flag */
1297c478bd9Sstevel@tonic-gate #define	RTF_PROTO1	0x8000		/* protocol specific routing flag */
1307c478bd9Sstevel@tonic-gate #define	RTF_MULTIRT	0x10000		/* multiroute */
1317c478bd9Sstevel@tonic-gate #define	RTF_SETSRC	0x20000		/* set default outgoing src address */
132bd670b35SErik Nordmark #define	RTF_INDIRECT	0x40000		/* gateway not directly reachable */
133bd670b35SErik Nordmark #define	RTF_KERNEL	0x80000		/* created by kernel; can't delete */
134*550b6e40SSowmini Varadhan #define	RTF_ZONE	0x100000	/* (NGZ only) route from global zone */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * OLD statistics not used by the kernel. The kernel uses <inet/mib2.h>.
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  * Routing statistics.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate struct	rtstat {
1427c478bd9Sstevel@tonic-gate 	short	rts_badredirect;	/* bogus redirect calls */
1437c478bd9Sstevel@tonic-gate 	short	rts_dynamic;		/* routes created by redirects */
1447c478bd9Sstevel@tonic-gate 	short	rts_newgateway;		/* routes modified by redirects */
1457c478bd9Sstevel@tonic-gate 	short	rts_unreach;		/* lookups which failed */
1467c478bd9Sstevel@tonic-gate 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
1477c478bd9Sstevel@tonic-gate };
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * Structures for routing messages.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate typedef struct rt_msghdr {
1537c478bd9Sstevel@tonic-gate 	ushort_t rtm_msglen;	/* to skip over non-understood messages */
1547c478bd9Sstevel@tonic-gate 	uchar_t	rtm_version;	/* future binary compatibility */
1557c478bd9Sstevel@tonic-gate 	uchar_t	rtm_type;	/* message type */
1567c478bd9Sstevel@tonic-gate 	ushort_t rtm_index;	/* index for associated ifp */
1577c478bd9Sstevel@tonic-gate 	int	rtm_flags;	/* flags, incl. kern & message, e.g. DONE */
1587c478bd9Sstevel@tonic-gate 	int	rtm_addrs;	/* bitmask identifying sockaddrs in msg */
1597c478bd9Sstevel@tonic-gate 	pid_t	rtm_pid;	/* identify sender */
1607c478bd9Sstevel@tonic-gate 	int	rtm_seq;	/* for sender to identify action */
1617c478bd9Sstevel@tonic-gate 	int	rtm_errno;	/* why failed */
1627c478bd9Sstevel@tonic-gate 	int	rtm_use;	/* from rtentry */
1637c478bd9Sstevel@tonic-gate 	uint_t	rtm_inits;	/* which metrics we are initializing */
1647c478bd9Sstevel@tonic-gate 	struct	rt_metrics rtm_rmx; /* metrics themselves */
1657c478bd9Sstevel@tonic-gate } rt_msghdr_t;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #define	RTM_VERSION	3	/* Up the ante and ignore older versions */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define	RTM_ADD		0x1	/* Add Route */
1707c478bd9Sstevel@tonic-gate #define	RTM_DELETE	0x2	/* Delete Route */
1717c478bd9Sstevel@tonic-gate #define	RTM_CHANGE	0x3	/* Change Metrics or flags */
1727c478bd9Sstevel@tonic-gate #define	RTM_GET		0x4	/* Report Metrics */
1737c478bd9Sstevel@tonic-gate #define	RTM_LOSING	0x5	/* Kernel Suspects Partitioning */
1747c478bd9Sstevel@tonic-gate #define	RTM_REDIRECT	0x6	/* Told to use different route */
1757c478bd9Sstevel@tonic-gate #define	RTM_MISS	0x7	/* Lookup failed on this address */
1767c478bd9Sstevel@tonic-gate #define	RTM_LOCK	0x8	/* fix specified metrics */
1777c478bd9Sstevel@tonic-gate #define	RTM_OLDADD	0x9	/* caused by SIOCADDRT */
1787c478bd9Sstevel@tonic-gate #define	RTM_OLDDEL	0xa	/* caused by SIOCDELRT */
1797c478bd9Sstevel@tonic-gate #define	RTM_RESOLVE	0xb	/* req to resolve dst to LL addr */
1807c478bd9Sstevel@tonic-gate #define	RTM_NEWADDR	0xc	/* address being added to iface */
1817c478bd9Sstevel@tonic-gate #define	RTM_DELADDR	0xd	/* address being removed from iface */
1827c478bd9Sstevel@tonic-gate #define	RTM_IFINFO	0xe	/* iface going up/down etc. */
1831cb875aeSCathy Zhou #define	RTM_CHGADDR	0xf	/* address added/changed (even while down) */
1841cb875aeSCathy Zhou #define	RTM_FREEADDR	0x10	/* address removed (even while down) */
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #define	RTV_MTU		0x1	/* init or lock _mtu */
1877c478bd9Sstevel@tonic-gate #define	RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
1887c478bd9Sstevel@tonic-gate #define	RTV_EXPIRE	0x4	/* init or lock _expire */
1897c478bd9Sstevel@tonic-gate #define	RTV_RPIPE	0x8	/* init or lock _recvpipe */
1907c478bd9Sstevel@tonic-gate #define	RTV_SPIPE	0x10	/* init or lock _sendpipe */
1917c478bd9Sstevel@tonic-gate #define	RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
1927c478bd9Sstevel@tonic-gate #define	RTV_RTT		0x40	/* init or lock _rtt */
1937c478bd9Sstevel@tonic-gate #define	RTV_RTTVAR	0x80	/* init or lock _rttvar */
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Bitmask values for rtm_addr.
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate #define	RTA_DST		0x1	/* destination sockaddr present */
1997c478bd9Sstevel@tonic-gate #define	RTA_GATEWAY	0x2	/* gateway sockaddr present */
2007c478bd9Sstevel@tonic-gate #define	RTA_NETMASK	0x4	/* netmask sockaddr present */
2017c478bd9Sstevel@tonic-gate #define	RTA_GENMASK	0x8	/* cloning mask sockaddr present */
2027c478bd9Sstevel@tonic-gate #define	RTA_IFP		0x10	/* interface name sockaddr present */
2037c478bd9Sstevel@tonic-gate #define	RTA_IFA		0x20	/* interface addr sockaddr present */
2047c478bd9Sstevel@tonic-gate #define	RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
2057c478bd9Sstevel@tonic-gate #define	RTA_BRD		0x80	/* for NEWADDR, broadcast or p-p dest addr */
2067c478bd9Sstevel@tonic-gate #define	RTA_SRC		0x100	/* source sockaddr present */
2077c478bd9Sstevel@tonic-gate 
2085c0b7edeSseb #define	RTA_NUMBITS	9	/* Number of bits used in RTA_* */
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * Index offsets for sockaddr_storage array for alternate internal encoding.
2127c478bd9Sstevel@tonic-gate  * There should be an RTAX_* associated with each RTA_*.
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate #define	RTAX_DST	0
2157c478bd9Sstevel@tonic-gate #define	RTAX_GATEWAY	1
2167c478bd9Sstevel@tonic-gate #define	RTAX_NETMASK	2
2177c478bd9Sstevel@tonic-gate #define	RTAX_GENMASK	3
2187c478bd9Sstevel@tonic-gate #define	RTAX_IFP	4
2197c478bd9Sstevel@tonic-gate #define	RTAX_IFA	5
2207c478bd9Sstevel@tonic-gate #define	RTAX_AUTHOR	6
2217c478bd9Sstevel@tonic-gate #define	RTAX_BRD	7
2227c478bd9Sstevel@tonic-gate #define	RTAX_SRC	8
2237c478bd9Sstevel@tonic-gate #define	RTAX_MAX	RTA_NUMBITS	/* size of array to allocate */
2247c478bd9Sstevel@tonic-gate 
22545916cd2Sjpk /*
22645916cd2Sjpk  * Routing socket message extension after sockaddrs.
22745916cd2Sjpk  */
22845916cd2Sjpk typedef struct rtm_ext_s {
22945916cd2Sjpk 	uint32_t	rtmex_type;	/* identifier for type of extension */
23045916cd2Sjpk 	uint32_t	rtmex_len;	/* length of this extension */
23145916cd2Sjpk } rtm_ext_t;
23245916cd2Sjpk 
23345916cd2Sjpk #define	RTMEX_GATEWAY_SECATTR	1	/* extension is tsol_rtsecattr */
23445916cd2Sjpk #define	RTMEX_MAX	RTMEX_GATEWAY_SECATTR
23545916cd2Sjpk 
23645916cd2Sjpk /*
23745916cd2Sjpk  * Trusted Solaris route security attributes extension.
23845916cd2Sjpk  */
239b7b2cb06Sjarrett typedef struct rtsa_s {
240b7b2cb06Sjarrett 	uint32_t	rtsa_mask;	/* see RTSA_* below */
241b7b2cb06Sjarrett 	uint32_t	rtsa_doi;	/* domain of interpretation */
242b7b2cb06Sjarrett 	brange_t	rtsa_slrange;	/* sensitivity label range */
243b7b2cb06Sjarrett } rtsa_t;
244b7b2cb06Sjarrett 
24545916cd2Sjpk typedef struct tsol_rtsecattr_s {
24645916cd2Sjpk 	uint32_t	rtsa_cnt;	/* number of attributes */
247b7b2cb06Sjarrett 	rtsa_t		rtsa_attr[1];
24845916cd2Sjpk } tsol_rtsecattr_t;
24945916cd2Sjpk 
25045916cd2Sjpk #define	TSOL_RTSECATTR_SIZE(n) \
25145916cd2Sjpk 	(sizeof (tsol_rtsecattr_t) + (((n) - 1) * sizeof (struct rtsa_s)))
25245916cd2Sjpk 
25345916cd2Sjpk #define	RTSA_MINSL	0x1	/* minimum sensitivity label is valid */
25445916cd2Sjpk #define	RTSA_MAXSL	0x2	/* maximum sensitivity label is valid */
25545916cd2Sjpk #define	RTSA_DOI	0x4	/* domain of interpretation is valid */
25645916cd2Sjpk #define	RTSA_CIPSO	0x100	/* CIPSO protocol */
25745916cd2Sjpk #define	RTSA_SLRANGE (RTSA_MINSL|RTSA_MAXSL)
25845916cd2Sjpk 
259e11c3f44Smeem /*
260e11c3f44Smeem  * Routing socket options.
261e11c3f44Smeem  */
262e11c3f44Smeem #define	RT_AWARE	0x0001	/* set awareness of hidden interfaces */
263e11c3f44Smeem 
264e11c3f44Smeem /*
265e11c3f44Smeem  * Supported RT_AWARE values.  As a convenience, the bit-values here mirror
266e11c3f44Smeem  * the LIFC_* values.
267e11c3f44Smeem  */
268e11c3f44Smeem #define	RTAW_DEFAULT	0x0000	/* unaware application */
269e11c3f44Smeem #define	RTAW_UNDER_IPMP	0x0010	/* aware of underlying IPMP interfaces */
270e11c3f44Smeem 
2717c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate #endif
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate #endif	/* _NET_ROUTE_H */
276