xref: /illumos-gate/usr/src/uts/common/net/route.h (revision 45916cd2)
17c478bd9Sstevel@tonic-gate /*
2*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate /*
67c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1993
77c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
107c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
117c478bd9Sstevel@tonic-gate  * are met:
127c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
137c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
147c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
157c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
167c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
177c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
187c478bd9Sstevel@tonic-gate  *    must display the following acknowledgement:
197c478bd9Sstevel@tonic-gate  *	This product includes software developed by the University of
207c478bd9Sstevel@tonic-gate  *	California, Berkeley and its contributors.
217c478bd9Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
227c478bd9Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
237c478bd9Sstevel@tonic-gate  *    without specific prior written permission.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
267c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
277c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
287c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
297c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
307c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
317c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
327c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
337c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
347c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
357c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Kernel resident routing tables.
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * The routing tables are initialized when interface addresses
427c478bd9Sstevel@tonic-gate  * are set by making entries for all directly connected interfaces.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifndef	_NET_ROUTE_H
467c478bd9Sstevel@tonic-gate #define	_NET_ROUTE_H
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
497c478bd9Sstevel@tonic-gate /* from UCB 8.5 (Berkeley) 2/8/95 */
507c478bd9Sstevel@tonic-gate 
51*45916cd2Sjpk #include <sys/tsol/label.h>
52*45916cd2Sjpk #include <sys/tsol/label_macro.h>
53*45916cd2Sjpk 
547c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
557c478bd9Sstevel@tonic-gate extern "C" {
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * A route consists of a destination address and a reference
607c478bd9Sstevel@tonic-gate  * to a routing entry.  These are often held by protocols
617c478bd9Sstevel@tonic-gate  * in their control blocks, e.g. inpcb.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate struct route {
647c478bd9Sstevel@tonic-gate 	struct	rtentry *ro_rt;
657c478bd9Sstevel@tonic-gate 	struct	sockaddr ro_dst;
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * These numbers are used by reliable protocols for determining
707c478bd9Sstevel@tonic-gate  * retransmission behavior and are included in the routing structure.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * rmx_rtt and rmx_rttvar are stored as microseconds;
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate typedef struct rt_metrics {
757c478bd9Sstevel@tonic-gate 	uint32_t	rmx_locks;	/* Kernel must leave these values */
767c478bd9Sstevel@tonic-gate 					/* alone */
777c478bd9Sstevel@tonic-gate 	uint32_t	rmx_mtu;	/* MTU for this path */
787c478bd9Sstevel@tonic-gate 	uint32_t	rmx_hopcount;	/* max hops expected */
797c478bd9Sstevel@tonic-gate 	uint32_t	rmx_expire;	/* lifetime for route, e.g. redirect */
807c478bd9Sstevel@tonic-gate 	uint32_t	rmx_recvpipe;	/* inbound delay-bandwith product */
817c478bd9Sstevel@tonic-gate 	uint32_t	rmx_sendpipe;	/* outbound delay-bandwith product */
827c478bd9Sstevel@tonic-gate 	uint32_t	rmx_ssthresh;	/* outbound gateway buffer limit */
837c478bd9Sstevel@tonic-gate 	uint32_t	rmx_rtt;	/* estimated round trip time */
847c478bd9Sstevel@tonic-gate 	uint32_t	rmx_rttvar;	/* estimated rtt variance */
857c478bd9Sstevel@tonic-gate 	uint32_t	rmx_pksent;	/* packets sent using this route */
867c478bd9Sstevel@tonic-gate } rt_metrics_t;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * OLD rtentry structure not used in the kernel. Instead the kernel
907c478bd9Sstevel@tonic-gate  * uses struct ire defined in <inet/ip.h>.
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * We distinguish between routes to hosts and routes to networks,
937c478bd9Sstevel@tonic-gate  * preferring the former if available.  For each route we infer
947c478bd9Sstevel@tonic-gate  * the interface to use from the gateway address supplied when
957c478bd9Sstevel@tonic-gate  * the route was entered.  Routes that forward packets through
967c478bd9Sstevel@tonic-gate  * gateways are marked so that the output routines know to address the
977c478bd9Sstevel@tonic-gate  * gateway rather than the ultimate destination.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate struct rtentry {
1007c478bd9Sstevel@tonic-gate 	uint_t	rt_hash;		/* to speed lookups */
1017c478bd9Sstevel@tonic-gate 	struct	sockaddr rt_dst;	/* key */
1027c478bd9Sstevel@tonic-gate 	struct	sockaddr rt_gateway;	/* value */
1037c478bd9Sstevel@tonic-gate 	short	rt_flags;		/* up/down?, host/net */
1047c478bd9Sstevel@tonic-gate 	short	rt_refcnt;		/* # held references */
1057c478bd9Sstevel@tonic-gate 	uint_t	rt_use;			/* raw # packets forwarded */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * The kernel does not use this field, and without it the structure is
1097c478bd9Sstevel@tonic-gate  * datamodel independent.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
1127c478bd9Sstevel@tonic-gate 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
1137c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) */
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	RTF_UP		0x1		/* route usable */
1177c478bd9Sstevel@tonic-gate #define	RTF_GATEWAY	0x2		/* destination is a gateway */
1187c478bd9Sstevel@tonic-gate #define	RTF_HOST	0x4		/* host entry (net otherwise) */
1197c478bd9Sstevel@tonic-gate #define	RTF_REJECT	0x8		/* host or net unreachable */
1207c478bd9Sstevel@tonic-gate #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
1217c478bd9Sstevel@tonic-gate #define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
1227c478bd9Sstevel@tonic-gate #define	RTF_DONE	0x40		/* message confirmed */
1237c478bd9Sstevel@tonic-gate #define	RTF_MASK	0x80		/* subnet mask present */
1247c478bd9Sstevel@tonic-gate #define	RTF_CLONING	0x100		/* generate new routes on use */
1257c478bd9Sstevel@tonic-gate #define	RTF_XRESOLVE	0x200		/* external daemon resolves name */
1267c478bd9Sstevel@tonic-gate #define	RTF_LLINFO	0x400		/* generated by ARP or ESIS */
1277c478bd9Sstevel@tonic-gate #define	RTF_STATIC	0x800		/* manually added */
1287c478bd9Sstevel@tonic-gate #define	RTF_BLACKHOLE	0x1000		/* just discard pkts (during updates) */
1297c478bd9Sstevel@tonic-gate #define	RTF_PRIVATE	0x2000		/* do not advertise this route */
1307c478bd9Sstevel@tonic-gate #define	RTF_PROTO2	0x4000		/* protocol specific routing flag */
1317c478bd9Sstevel@tonic-gate #define	RTF_PROTO1	0x8000		/* protocol specific routing flag */
1327c478bd9Sstevel@tonic-gate #define	RTF_MULTIRT	0x10000		/* multiroute */
1337c478bd9Sstevel@tonic-gate #define	RTF_SETSRC	0x20000		/* set default outgoing src address */
1347c478bd9Sstevel@tonic-gate 
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. */
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	RTV_MTU		0x1	/* init or lock _mtu */
1857c478bd9Sstevel@tonic-gate #define	RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
1867c478bd9Sstevel@tonic-gate #define	RTV_EXPIRE	0x4	/* init or lock _expire */
1877c478bd9Sstevel@tonic-gate #define	RTV_RPIPE	0x8	/* init or lock _recvpipe */
1887c478bd9Sstevel@tonic-gate #define	RTV_SPIPE	0x10	/* init or lock _sendpipe */
1897c478bd9Sstevel@tonic-gate #define	RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
1907c478bd9Sstevel@tonic-gate #define	RTV_RTT		0x40	/* init or lock _rtt */
1917c478bd9Sstevel@tonic-gate #define	RTV_RTTVAR	0x80	/* init or lock _rttvar */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * Bitmask values for rtm_addr.
1957c478bd9Sstevel@tonic-gate  */
1967c478bd9Sstevel@tonic-gate #define	RTA_DST		0x1	/* destination sockaddr present */
1977c478bd9Sstevel@tonic-gate #define	RTA_GATEWAY	0x2	/* gateway sockaddr present */
1987c478bd9Sstevel@tonic-gate #define	RTA_NETMASK	0x4	/* netmask sockaddr present */
1997c478bd9Sstevel@tonic-gate #define	RTA_GENMASK	0x8	/* cloning mask sockaddr present */
2007c478bd9Sstevel@tonic-gate #define	RTA_IFP		0x10	/* interface name sockaddr present */
2017c478bd9Sstevel@tonic-gate #define	RTA_IFA		0x20	/* interface addr sockaddr present */
2027c478bd9Sstevel@tonic-gate #define	RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
2037c478bd9Sstevel@tonic-gate #define	RTA_BRD		0x80	/* for NEWADDR, broadcast or p-p dest addr */
2047c478bd9Sstevel@tonic-gate #define	RTA_SRC		0x100	/* source sockaddr present */
2057c478bd9Sstevel@tonic-gate #define	RTA_SRCIFP	0x200	/* source interface index sockaddr present */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #define	RTA_NUMBITS	10	/* Number of bits used in RTA_* */
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * Index offsets for sockaddr_storage array for alternate internal encoding.
2117c478bd9Sstevel@tonic-gate  * There should be an RTAX_* associated with each RTA_*.
2127c478bd9Sstevel@tonic-gate  */
2137c478bd9Sstevel@tonic-gate #define	RTAX_DST	0
2147c478bd9Sstevel@tonic-gate #define	RTAX_GATEWAY	1
2157c478bd9Sstevel@tonic-gate #define	RTAX_NETMASK	2
2167c478bd9Sstevel@tonic-gate #define	RTAX_GENMASK	3
2177c478bd9Sstevel@tonic-gate #define	RTAX_IFP	4
2187c478bd9Sstevel@tonic-gate #define	RTAX_IFA	5
2197c478bd9Sstevel@tonic-gate #define	RTAX_AUTHOR	6
2207c478bd9Sstevel@tonic-gate #define	RTAX_BRD	7
2217c478bd9Sstevel@tonic-gate #define	RTAX_SRC	8
2227c478bd9Sstevel@tonic-gate #define	RTAX_SRCIFP	9
2237c478bd9Sstevel@tonic-gate #define	RTAX_MAX	RTA_NUMBITS	/* size of array to allocate */
2247c478bd9Sstevel@tonic-gate 
225*45916cd2Sjpk /*
226*45916cd2Sjpk  * Routing socket message extension after sockaddrs.
227*45916cd2Sjpk  */
228*45916cd2Sjpk typedef struct rtm_ext_s {
229*45916cd2Sjpk 	uint32_t	rtmex_type;	/* identifier for type of extension */
230*45916cd2Sjpk 	uint32_t	rtmex_len;	/* length of this extension */
231*45916cd2Sjpk } rtm_ext_t;
232*45916cd2Sjpk 
233*45916cd2Sjpk #define	RTMEX_GATEWAY_SECATTR	1	/* extension is tsol_rtsecattr */
234*45916cd2Sjpk #define	RTMEX_MAX	RTMEX_GATEWAY_SECATTR
235*45916cd2Sjpk 
236*45916cd2Sjpk /*
237*45916cd2Sjpk  * Trusted Solaris route security attributes extension.
238*45916cd2Sjpk  */
239*45916cd2Sjpk typedef struct tsol_rtsecattr_s {
240*45916cd2Sjpk 	uint32_t	rtsa_cnt;	/* number of attributes */
241*45916cd2Sjpk 	struct rtsa_s {
242*45916cd2Sjpk 		uint32_t rtsa_mask;	/* see RTSA_* below */
243*45916cd2Sjpk 		uint32_t rtsa_doi;	/* domain of interpretation */
244*45916cd2Sjpk 		brange_t rtsa_slrange;	/* sensitivity label range */
245*45916cd2Sjpk 	} rtsa_attr[1];
246*45916cd2Sjpk } tsol_rtsecattr_t;
247*45916cd2Sjpk 
248*45916cd2Sjpk #define	TSOL_RTSECATTR_SIZE(n) \
249*45916cd2Sjpk 	(sizeof (tsol_rtsecattr_t) + (((n) - 1) * sizeof (struct rtsa_s)))
250*45916cd2Sjpk 
251*45916cd2Sjpk #define	RTSA_MINSL	0x1	/* minimum sensitivity label is valid */
252*45916cd2Sjpk #define	RTSA_MAXSL	0x2	/* maximum sensitivity label is valid */
253*45916cd2Sjpk #define	RTSA_DOI	0x4	/* domain of interpretation is valid */
254*45916cd2Sjpk #define	RTSA_CIPSO	0x100	/* CIPSO protocol */
255*45916cd2Sjpk #define	RTSA_SLRANGE (RTSA_MINSL|RTSA_MAXSL)
256*45916cd2Sjpk 
2577c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate #endif
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #endif	/* _NET_ROUTE_H */
262