17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
545916cdjpk * Common Development and Distribution License (the "License").
645916cdjpk * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
2245916cdjpk * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/*
277c478bdstevel@tonic-gate * ip6.h - Common structures and definitions as defined by
287c478bdstevel@tonic-gate * advanced BSD API.
297c478bdstevel@tonic-gate */
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#ifndef	_NETINET_IP6_H
327c478bdstevel@tonic-gate#define	_NETINET_IP6_H
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#ifdef	__cplusplus
377c478bdstevel@tonic-gateextern "C" {
387c478bdstevel@tonic-gate#endif
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate#include <sys/types.h>
417c478bdstevel@tonic-gate#include <netinet/in.h>
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gatestruct	ip6_hdr {
447c478bdstevel@tonic-gate	union {
457c478bdstevel@tonic-gate		struct ip6_hdrctl {
467c478bdstevel@tonic-gate			uint32_t	ip6_un1_flow;   /* 4 bits version, */
477c478bdstevel@tonic-gate							/* 8 bits tclass, and */
487c478bdstevel@tonic-gate							/* 20 bits flow-ID */
497c478bdstevel@tonic-gate			uint16_t	ip6_un1_plen;   /* payload length */
507c478bdstevel@tonic-gate			uint8_t		ip6_un1_nxt;    /* next header */
517c478bdstevel@tonic-gate			uint8_t		ip6_un1_hlim;   /* hop limit */
527c478bdstevel@tonic-gate		} ip6_un1;
537c478bdstevel@tonic-gate		uint8_t	ip6_un2_vfc;	/* 4 bits version and */
547c478bdstevel@tonic-gate					/* top 4 bits of tclass */
557c478bdstevel@tonic-gate	} ip6_ctlun;
567c478bdstevel@tonic-gate	struct in6_addr ip6_src;	/* source address */
577c478bdstevel@tonic-gate	struct in6_addr ip6_dst;	/* destination address */
587c478bdstevel@tonic-gate};
597c478bdstevel@tonic-gatetypedef struct ip6_hdr	ip6_t;
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gate#define	ip6_vfc		ip6_ctlun.ip6_un2_vfc	/* 4 bits version and */
627c478bdstevel@tonic-gate						/* top 4 bits of tclass */
637c478bdstevel@tonic-gate#define	ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
647c478bdstevel@tonic-gate#define	ip6_vcf		ip6_flow		/* Version, tclass, flow-ID */
657c478bdstevel@tonic-gate#define	ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
667c478bdstevel@tonic-gate#define	ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt
677c478bdstevel@tonic-gate#define	ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
687c478bdstevel@tonic-gate#define	ip6_hops	ip6_ctlun.ip6_un1.ip6_un1_hlim
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gate/* Hop-by-Hop options header */
717c478bdstevel@tonic-gatestruct ip6_hbh {
727c478bdstevel@tonic-gate	uint8_t	ip6h_nxt;	/* next header */
737c478bdstevel@tonic-gate	uint8_t	ip6h_len;	/* length in units of 8 octets */
747c478bdstevel@tonic-gate		/* followed by options */
757c478bdstevel@tonic-gate};
767c478bdstevel@tonic-gatetypedef struct ip6_hbh	ip6_hbh_t;
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate/* Destination options header */
797c478bdstevel@tonic-gatestruct ip6_dest {
807c478bdstevel@tonic-gate	uint8_t	ip6d_nxt;	/* next header */
817c478bdstevel@tonic-gate	uint8_t	ip6d_len;	/* length in units of 8 octets */
827c478bdstevel@tonic-gate		/* followed by options */
837c478bdstevel@tonic-gate};
847c478bdstevel@tonic-gatetypedef struct ip6_dest	ip6_dest_t;
857c478bdstevel@tonic-gate
867c478bdstevel@tonic-gate/* Routing header */
877c478bdstevel@tonic-gatestruct ip6_rthdr {
887c478bdstevel@tonic-gate	uint8_t	ip6r_nxt;	/* next header */
897c478bdstevel@tonic-gate	uint8_t	ip6r_len;	/* length in units of 8 octets */
907c478bdstevel@tonic-gate	uint8_t	ip6r_type;	/* routing type */
917c478bdstevel@tonic-gate	uint8_t	ip6r_segleft;	/* segments left */
927c478bdstevel@tonic-gate		/* followed by routing type specific data */
937c478bdstevel@tonic-gate};
947c478bdstevel@tonic-gatetypedef struct ip6_rthdr	ip6_rthdr_t;
957c478bdstevel@tonic-gate
967c478bdstevel@tonic-gate/* Type 0 Routing header */
977c478bdstevel@tonic-gatestruct ip6_rthdr0 {
987c478bdstevel@tonic-gate	uint8_t	ip6r0_nxt;		/* next header */
997c478bdstevel@tonic-gate	uint8_t	ip6r0_len;		/* length in units of 8 octets */
1007c478bdstevel@tonic-gate	uint8_t	ip6r0_type;		/* always zero */
1017c478bdstevel@tonic-gate	uint8_t	ip6r0_segleft;		/* segments left */
1027c478bdstevel@tonic-gate	uint32_t ip6r0_reserved;	/* reserved field */
1037c478bdstevel@tonic-gate};
1047c478bdstevel@tonic-gatetypedef struct ip6_rthdr0	ip6_rthdr0_t;
1057c478bdstevel@tonic-gate
1067c478bdstevel@tonic-gate/* Fragment header */
1077c478bdstevel@tonic-gatestruct ip6_frag {
1087c478bdstevel@tonic-gate	uint8_t		ip6f_nxt;	/* next header */
1097c478bdstevel@tonic-gate	uint8_t		ip6f_reserved;	/* reserved field */
1107c478bdstevel@tonic-gate	uint16_t	ip6f_offlg;	/* offset, reserved, and flag */
1117c478bdstevel@tonic-gate	uint32_t	ip6f_ident;	/* identification */
1127c478bdstevel@tonic-gate};
1137c478bdstevel@tonic-gatetypedef struct ip6_frag	ip6_frag_t;
1147c478bdstevel@tonic-gate
1157c478bdstevel@tonic-gate/* ip6f_offlg field related constants (in network byte order) */
1167c478bdstevel@tonic-gate#ifdef _BIG_ENDIAN
1177c478bdstevel@tonic-gate#define	IP6F_OFF_MASK		0xfff8	/* mask out offset from _offlg */
1187c478bdstevel@tonic-gate#define	IP6F_RESERVED_MASK	0x0006	/* reserved bits in ip6f_offlg */
1197c478bdstevel@tonic-gate#define	IP6F_MORE_FRAG		0x0001	/* more-fragments flag */
1207c478bdstevel@tonic-gate#else
1217c478bdstevel@tonic-gate#define	IP6F_OFF_MASK		0xf8ff	/* mask out offset from _offlg */
1227c478bdstevel@tonic-gate#define	IP6F_RESERVED_MASK	0x0600	/* reserved bits in ip6f_offlg */
1237c478bdstevel@tonic-gate#define	IP6F_MORE_FRAG		0x0100	/* more-fragments flag */
1247c478bdstevel@tonic-gate#endif
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gate/* IPv6 options */
1277c478bdstevel@tonic-gatestruct	ip6_opt {
1287c478bdstevel@tonic-gate	uint8_t	ip6o_type;
1297c478bdstevel@tonic-gate	uint8_t	ip6o_len;
1307c478bdstevel@tonic-gate};
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gate/*
1337c478bdstevel@tonic-gate * The high-order 3 bits of the option type define the behavior
1347c478bdstevel@tonic-gate * when processing an unknown option and whether or not the option
1357c478bdstevel@tonic-gate * content changes in flight.
1367c478bdstevel@tonic-gate */
1377c478bdstevel@tonic-gate#define	IP6OPT_TYPE(o)		((o) & 0xc0)
1387c478bdstevel@tonic-gate#define	IP6OPT_TYPE_SKIP	0x00
1397c478bdstevel@tonic-gate#define	IP6OPT_TYPE_DISCARD	0x40
1407c478bdstevel@tonic-gate#define	IP6OPT_TYPE_FORCEICMP	0x80
1417c478bdstevel@tonic-gate#define	IP6OPT_TYPE_ICMP	0xc0
1427c478bdstevel@tonic-gate#define	IP6OPT_MUTABLE		0x20
1437c478bdstevel@tonic-gate
1447c478bdstevel@tonic-gate#define	IP6OPT_PAD1			0x00	/* 00 0 00000 */
1457c478bdstevel@tonic-gate#define	IP6OPT_PADN			0x01	/* 00 0 00001 */
1467c478bdstevel@tonic-gate#define	IP6OPT_JUMBO			0xc2	/* 11 0 00010 = 194 */
1477c478bdstevel@tonic-gate#define	IP6OPT_NSAP_ADDR		0xc3	/* 11 0 00011 */
1487c478bdstevel@tonic-gate#define	IP6OPT_TUNNEL_LIMIT		0x04	/* 00 0 00100 */
1497c478bdstevel@tonic-gate#define	IP6OPT_ROUTER_ALERT		0x05	/* 00 0 00101 */
1507c478bdstevel@tonic-gate#define	IP6OPT_BINDING_UPDATE		0xc6	/* 11 0 00110 */
1517c478bdstevel@tonic-gate#define	IP6OPT_BINDING_ACK		0x07	/* 00 0 00111 */
1527c478bdstevel@tonic-gate#define	IP6OPT_BINDING_REQ		0x08	/* 00 0 01000 */
1537c478bdstevel@tonic-gate#define	IP6OPT_HOME_ADDRESS		0xc9	/* 11 0 01001 */
1547c478bdstevel@tonic-gate#define	IP6OPT_EID			0x8a	/* 10 0 01010 */
1557c478bdstevel@tonic-gate
15645916cdjpk#define	IP6OPT_LS			0x0a	/* 00 0 01010 */
15745916cdjpk
15845916cdjpk#define	IP6_MAX_OPT_LENGTH	255
15945916cdjpk
1607c478bdstevel@tonic-gate/* Jumbo Payload Option */
1617c478bdstevel@tonic-gatestruct	ip6_opt_jumbo {
1627c478bdstevel@tonic-gate	uint8_t	ip6oj_type;
1637c478bdstevel@tonic-gate	uint8_t	ip6oj_len;
1647c478bdstevel@tonic-gate	uint8_t ip6oj_jumbo_len[4];
1657c478bdstevel@tonic-gate};
1667c478bdstevel@tonic-gate#define	IP6OPT_JUMBO_LEN	6
1677c478bdstevel@tonic-gate
1687c478bdstevel@tonic-gate/* NSAP Address Option */
1697c478bdstevel@tonic-gatestruct	ip6_opt_nsap {
1707c478bdstevel@tonic-gate	uint8_t	ip6on_type;
1717c478bdstevel@tonic-gate	uint8_t	ip6on_len;
1727c478bdstevel@tonic-gate	uint8_t ip6on_src_nsap_len;
1737c478bdstevel@tonic-gate	uint8_t ip6on_dst_nsap_len;
1747c478bdstevel@tonic-gate	/* Followed by source NSAP */
1757c478bdstevel@tonic-gate	/* Followed by destination NSAP */
1767c478bdstevel@tonic-gate};
1777c478bdstevel@tonic-gate
1787c478bdstevel@tonic-gate/* Tunnel Limit Option */
1797c478bdstevel@tonic-gatestruct	ip6_opt_tunnel {
1807c478bdstevel@tonic-gate	uint8_t	ip6ot_type;
1817c478bdstevel@tonic-gate	uint8_t	ip6ot_len;
1827c478bdstevel@tonic-gate	uint8_t ip6ot_encap_limit;
1837c478bdstevel@tonic-gate};
1847c478bdstevel@tonic-gate
1857c478bdstevel@tonic-gate/* Router Alert Option */
1867c478bdstevel@tonic-gatestruct	ip6_opt_router {
1877c478bdstevel@tonic-gate	uint8_t	ip6or_type;
1887c478bdstevel@tonic-gate	uint8_t	ip6or_len;
1897c478bdstevel@tonic-gate	uint8_t ip6or_value[2];
1907c478bdstevel@tonic-gate};
1917c478bdstevel@tonic-gate
1927c478bdstevel@tonic-gate/* Router alert values (in network byte order) */
1937c478bdstevel@tonic-gate#ifdef _BIG_ENDIAN
1947c478bdstevel@tonic-gate#define	IP6_ALERT_MLD			0x0000
1957c478bdstevel@tonic-gate#define	IP6_ALERT_RSVP			0x0001
1967c478bdstevel@tonic-gate#define	IP6_ALERT_AN			0x0002
1977c478bdstevel@tonic-gate#else
1987c478bdstevel@tonic-gate#define	IP6_ALERT_MLD			0x0000
1997c478bdstevel@tonic-gate#define	IP6_ALERT_RSVP			0x0100
2007c478bdstevel@tonic-gate#define	IP6_ALERT_AN			0x0200
2017c478bdstevel@tonic-gate#endif
2027c478bdstevel@tonic-gate
2037c478bdstevel@tonic-gate/* Binding Update Option */
2047c478bdstevel@tonic-gatestruct	ip6_opt_binding_update {
2057c478bdstevel@tonic-gate	uint8_t	ip6ou_type;
2067c478bdstevel@tonic-gate	uint8_t	ip6ou_len;
2077c478bdstevel@tonic-gate	uint8_t ip6ou_flags;
2087c478bdstevel@tonic-gate	uint8_t ip6ou_prefixlen;
2097c478bdstevel@tonic-gate	uint8_t ip6ou_seqno[2];
2107c478bdstevel@tonic-gate	uint8_t ip6ou_lifetime[4];
2117c478bdstevel@tonic-gate	uint8_t ip6ou_coa[16];		/* Optional based on flags */
2127c478bdstevel@tonic-gate	/* Followed by sub-options */
2137c478bdstevel@tonic-gate};
2147c478bdstevel@tonic-gate
2157c478bdstevel@tonic-gate/* Binding Update Flags */
2167c478bdstevel@tonic-gate#define	IP6_BUF_ACK	0x80	/* Request a binding ack */
2177c478bdstevel@tonic-gate#define	IP6_BUF_HOME	0x40	/* Home Registration */
2187c478bdstevel@tonic-gate#define	IP6_BUF_COA	0x20	/* Care-of-address present in option */
2197c478bdstevel@tonic-gate#define	IP6_BUF_ROUTER	0x10	/* Sending mobile node is a router */
2207c478bdstevel@tonic-gate
2217c478bdstevel@tonic-gate/* Binding Ack Option */
2227c478bdstevel@tonic-gatestruct	ip6_opt_binding_ack {
2237c478bdstevel@tonic-gate	uint8_t	ip6oa_type;
2247c478bdstevel@tonic-gate	uint8_t	ip6oa_len;
2257c478bdstevel@tonic-gate	uint8_t ip6oa_status;
2267c478bdstevel@tonic-gate	uint8_t ip6oa_seqno[2];
2277c478bdstevel@tonic-gate	uint8_t ip6oa_lifetime[4];
2287c478bdstevel@tonic-gate	uint8_t ip6oa_refresh[4];
2297c478bdstevel@tonic-gate	/* Followed by sub-options */
2307c478bdstevel@tonic-gate};
2317c478bdstevel@tonic-gate
2327c478bdstevel@tonic-gate/* Binding Request Option */
2337c478bdstevel@tonic-gatestruct	ip6_opt_binding_request {
2347c478bdstevel@tonic-gate	uint8_t	ip6or_type;
2357c478bdstevel@tonic-gate	uint8_t	ip6or_len;
2367c478bdstevel@tonic-gate	/* Followed by sub-options */
2377c478bdstevel@tonic-gate};
2387c478bdstevel@tonic-gate
2397c478bdstevel@tonic-gate/* Home Address Option */
2407c478bdstevel@tonic-gatestruct	ip6_opt_home_address {
2417c478bdstevel@tonic-gate	uint8_t	ip6oh_type;
2427c478bdstevel@tonic-gate	uint8_t	ip6oh_len;
2437c478bdstevel@tonic-gate	uint8_t ip6oh_addr[16];		/* Home Address */
2447c478bdstevel@tonic-gate	/* Followed by sub-options */
2457c478bdstevel@tonic-gate};
2467c478bdstevel@tonic-gate
24745916cdjpk/* Labeled Security Option */
24845916cdjpkstruct	ip6_opt_labeled_security {
24945916cdjpk	uint8_t ip6ol_type;
25045916cdjpk	uint8_t ip6ol_len;	/* always even for defined values */
25145916cdjpk	uint8_t ip6ol_doi[4];
25245916cdjpk	/* Followed by sub-options */
25345916cdjpk};
25445916cdjpk
25545916cdjpk#define	IP6LS_DOI_V4	0	/* IPv4 transition */
25645916cdjpk
25745916cdjpk#define	IP6LS_TT_LEVEL	1	/* level or classification; 2-octet value */
25845916cdjpk#define	IP6LS_TT_VECTOR	2	/* compartments; bit vector (even # octets) */
25945916cdjpk#define	IP6LS_TT_ENUM	3	/* set membership; list of 2-octet values */
26045916cdjpk#define	IP6LS_TT_RANGES	4	/* set membership; pairs of 2-octet values */
26145916cdjpk#define	IP6LS_TT_V4	5	/* IPv4 compatible option */
26245916cdjpk#define	IP6LS_TT_DEST	6	/* destination-only data; per DOI */
26345916cdjpk
2647c478bdstevel@tonic-gate#ifdef	__cplusplus
2657c478bdstevel@tonic-gate}
2667c478bdstevel@tonic-gate#endif
2677c478bdstevel@tonic-gate
2687c478bdstevel@tonic-gate#endif	/* _NETINET_IP6_H */
269