icmp6.h revision 53541
153541Sshin/*
253541Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
353541Sshin * All rights reserved.
453541Sshin *
553541Sshin * Redistribution and use in source and binary forms, with or without
653541Sshin * modification, are permitted provided that the following conditions
753541Sshin * are met:
853541Sshin * 1. Redistributions of source code must retain the above copyright
953541Sshin *    notice, this list of conditions and the following disclaimer.
1053541Sshin * 2. Redistributions in binary form must reproduce the above copyright
1153541Sshin *    notice, this list of conditions and the following disclaimer in the
1253541Sshin *    documentation and/or other materials provided with the distribution.
1353541Sshin * 3. Neither the name of the project nor the names of its contributors
1453541Sshin *    may be used to endorse or promote products derived from this software
1553541Sshin *    without specific prior written permission.
1653541Sshin *
1753541Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1853541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1953541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2053541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2153541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2253541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2353541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2453541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2553541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2653541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2753541Sshin * SUCH DAMAGE.
2853541Sshin *
2953541Sshin * $FreeBSD: head/sys/netinet6/icmp6.h 53541 1999-11-22 02:45:11Z shin $
3053541Sshin */
3153541Sshin
3253541Sshin/*
3353541Sshin * Copyright (c) 1982, 1986, 1993
3453541Sshin *	The Regents of the University of California.  All rights reserved.
3553541Sshin *
3653541Sshin * Redistribution and use in source and binary forms, with or without
3753541Sshin * modification, are permitted provided that the following conditions
3853541Sshin * are met:
3953541Sshin * 1. Redistributions of source code must retain the above copyright
4053541Sshin *    notice, this list of conditions and the following disclaimer.
4153541Sshin * 2. Redistributions in binary form must reproduce the above copyright
4253541Sshin *    notice, this list of conditions and the following disclaimer in the
4353541Sshin *    documentation and/or other materials provided with the distribution.
4453541Sshin * 3. All advertising materials mentioning features or use of this software
4553541Sshin *    must display the following acknowledgement:
4653541Sshin *	This product includes software developed by the University of
4753541Sshin *	California, Berkeley and its contributors.
4853541Sshin * 4. Neither the name of the University nor the names of its contributors
4953541Sshin *    may be used to endorse or promote products derived from this software
5053541Sshin *    without specific prior written permission.
5153541Sshin *
5253541Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5353541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5453541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5553541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5653541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5753541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5853541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5953541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6053541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6153541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6253541Sshin * SUCH DAMAGE.
6353541Sshin *
6453541Sshin *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
6553541Sshin */
6653541Sshin
6753541Sshin#ifndef _NETINET6_ICMPV6_H_
6853541Sshin#define _NETINET6_ICMPV6_H_
6953541Sshin
7053541Sshin#define ICMPV6_PLD_MAXLEN	1232	/* IPV6_MMTU - sizeof(struct ip6_hdr)
7153541Sshin					   - sizeof(struct icmp6_hdr) */
7253541Sshin
7353541Sshinstruct icmp6_hdr {
7453541Sshin	u_int8_t	icmp6_type;	/* type field */
7553541Sshin	u_int8_t	icmp6_code;	/* code field */
7653541Sshin	u_int16_t	icmp6_cksum;	/* checksum field */
7753541Sshin	union {
7853541Sshin		u_int32_t	icmp6_un_data32[1]; /* type-specific field */
7953541Sshin		u_int16_t	icmp6_un_data16[2]; /* type-specific field */
8053541Sshin		u_int8_t	icmp6_un_data8[4];  /* type-specific field */
8153541Sshin	} icmp6_dataun;
8253541Sshin};
8353541Sshin
8453541Sshin#define	icmp6_data32	icmp6_dataun.icmp6_un_data32
8553541Sshin#define	icmp6_data16	icmp6_dataun.icmp6_un_data16
8653541Sshin#define	icmp6_data8	icmp6_dataun.icmp6_un_data8
8753541Sshin#define	icmp6_pptr	icmp6_data32[0]		/* parameter prob */
8853541Sshin#define	icmp6_mtu	icmp6_data32[0]		/* packet too big */
8953541Sshin#define	icmp6_id	icmp6_data16[0]		/* echo request/reply */
9053541Sshin#define	icmp6_seq	icmp6_data16[1]		/* echo request/reply */
9153541Sshin#define	icmp6_maxdelay	icmp6_data16[0]		/* mcast group membership */
9253541Sshin
9353541Sshin#define	ICMP6_DST_UNREACH		1	/* dest unreachable, codes: */
9453541Sshin#define	ICMP6_PACKET_TOO_BIG		2	/* packet too big */
9553541Sshin#define	ICMP6_TIME_EXCEEDED		3	/* time exceeded, code: */
9653541Sshin#define	ICMP6_PARAM_PROB		4	/* ip6 header bad */
9753541Sshin
9853541Sshin#define	ICMP6_ECHO_REQUEST		128	/* echo service */
9953541Sshin#define	ICMP6_ECHO_REPLY		129	/* echo reply */
10053541Sshin#define	ICMP6_MEMBERSHIP_QUERY		130	/* group membership query */
10153541Sshin#define	MLD6_LISTENER_QUERY		130 	/* multicast listener query */
10253541Sshin#define	ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
10353541Sshin#define	MLD6_LISTENER_REPORT		131	/* multicast listener report */
10453541Sshin#define	ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
10553541Sshin#define	MLD6_LISTENER_DONE		132	/* multicast listener done */
10653541Sshin
10753541Sshin#define	ND_ROUTER_SOLICIT		133	/* router solicitation */
10853541Sshin#define	ND_ROUTER_ADVERT		134	/* router advertisment */
10953541Sshin#define	ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
11053541Sshin#define	ND_NEIGHBOR_ADVERT		136	/* neighbor advertisment */
11153541Sshin#define	ND_REDIRECT			137	/* redirect */
11253541Sshin
11353541Sshin#define	ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
11453541Sshin
11553541Sshin#define	ICMP6_WRUREQUEST		139	/* who are you request */
11653541Sshin#define	ICMP6_WRUREPLY			140	/* who are you reply */
11753541Sshin#define	ICMP6_FQDN_QUERY		139	/* FQDN query */
11853541Sshin#define	ICMP6_FQDN_REPLY		140	/* FQDN reply */
11953541Sshin#define	ICMP6_NI_QUERY			139	/* node information request */
12053541Sshin#define	ICMP6_NI_REPLY			140	/* node information reply */
12153541Sshin
12253541Sshin/* The definitions below are experimental. TBA */
12353541Sshin#define	MLD6_MTRACE_RESP		141	/* mtrace response(to sender) */
12453541Sshin#define	MLD6_MTRACE			142	/* mtrace messages */
12553541Sshin
12653541Sshin#define	ICMP6_MAXTYPE			142
12753541Sshin
12853541Sshin#define	ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
12953541Sshin#define	ICMP6_DST_UNREACH_ADMIN	 	1	/* administratively prohibited */
13053541Sshin#define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2	/* not a neighbor(obsolete) */
13153541Sshin#define	ICMP6_DST_UNREACH_BEYONDSCOPE	2	/* beyond scope of source address */
13253541Sshin#define	ICMP6_DST_UNREACH_ADDR		3	/* address unreachable */
13353541Sshin#define	ICMP6_DST_UNREACH_NOPORT	4	/* port unreachable */
13453541Sshin
13553541Sshin#define	ICMP6_TIME_EXCEED_TRANSIT 	0	/* ttl==0 in transit */
13653541Sshin#define	ICMP6_TIME_EXCEED_REASSEMBLY	1	/* ttl==0 in reass */
13753541Sshin
13853541Sshin#define	ICMP6_PARAMPROB_HEADER 	 	0	/* erroneous header field */
13953541Sshin#define	ICMP6_PARAMPROB_NEXTHEADER	1	/* unrecognized next header */
14053541Sshin#define	ICMP6_PARAMPROB_OPTION		2	/* unrecognized option */
14153541Sshin
14253541Sshin#define	ICMP6_INFOMSG_MASK		0x80	/* all informational messages */
14353541Sshin
14453541Sshin#define	ICMP6_NI_SUCESS		0	/* node information successful reply */
14553541Sshin#define	ICMP6_NI_REFUSED	1	/* node information request is refused */
14653541Sshin#define	ICMP6_NI_UNKNOWN	2	/* unknown Qtype */
14753541Sshin
14853541Sshin#define	ICMP6_ROUTER_RENUMBERING_COMMAND  0	/* rr command */
14953541Sshin#define	ICMP6_ROUTER_RENUMBERING_RESULT   1	/* rr result */
15053541Sshin#define	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255	/* rr seq num reset */
15153541Sshin
15253541Sshin/* Used in kernel only */
15353541Sshin#define	ND_REDIRECT_ONLINK	0	/* redirect to an on-link node */
15453541Sshin#define	ND_REDIRECT_ROUTER	1	/* redirect to a better router */
15553541Sshin
15653541Sshin/*
15753541Sshin * Multicast Listener Discovery
15853541Sshin */
15953541Sshinstruct mld6_hdr {
16053541Sshin	struct	icmp6_hdr	mld6_hdr;
16153541Sshin	struct	in6_addr	mld6_addr; /* multicast address */
16253541Sshin};
16353541Sshin
16453541Sshin#define	mld6_type	mld6_hdr.icmp6_type
16553541Sshin#define	mld6_code	mld6_hdr.icmp6_code
16653541Sshin#define	mld6_cksum	mld6_hdr.icmp6_cksum
16753541Sshin#define	mld6_maxdelay	mld6_hdr.icmp6_data16[0]
16853541Sshin#define	mld6_reserved	mld6_hdr.icmp6_data16[1]
16953541Sshin
17053541Sshin/*
17153541Sshin * Neighbor Discovery
17253541Sshin */
17353541Sshin
17453541Sshinstruct nd_router_solicit {	/* router solicitation */
17553541Sshin	struct	icmp6_hdr 	nd_rs_hdr;
17653541Sshin	/* could be followed by options */
17753541Sshin};
17853541Sshin
17953541Sshin#define	nd_rs_type	nd_rs_hdr.icmp6_type
18053541Sshin#define	nd_rs_code	nd_rs_hdr.icmp6_code
18153541Sshin#define	nd_rs_cksum	nd_rs_hdr.icmp6_cksum
18253541Sshin#define	nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]
18353541Sshin
18453541Sshinstruct nd_router_advert {	/* router advertisement */
18553541Sshin	struct	icmp6_hdr	nd_ra_hdr;
18653541Sshin	u_int32_t	nd_ra_reachable;	/* reachable time */
18753541Sshin	u_int32_t	nd_ra_retransmit;	/* retransmit timer */
18853541Sshin	/* could be followed by options */
18953541Sshin};
19053541Sshin
19153541Sshin#define	nd_ra_type		nd_ra_hdr.icmp6_type
19253541Sshin#define	nd_ra_code		nd_ra_hdr.icmp6_code
19353541Sshin#define	nd_ra_cksum		nd_ra_hdr.icmp6_cksum
19453541Sshin#define	nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
19553541Sshin#define	nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]
19653541Sshin#define	ND_RA_FLAG_MANAGED	0x80
19753541Sshin#define	ND_RA_FLAG_OTHER	0x40
19853541Sshin#define	nd_ra_router_lifetime	nd_ra_hdr.icmp6_data16[1]
19953541Sshin
20053541Sshinstruct nd_neighbor_solicit {	/* neighbor solicitation */
20153541Sshin	struct	icmp6_hdr	nd_ns_hdr;
20253541Sshin	struct	in6_addr	nd_ns_target;	/*target address */
20353541Sshin	/* could be followed by options */
20453541Sshin};
20553541Sshin
20653541Sshin#define	nd_ns_type		nd_ns_hdr.icmp6_type
20753541Sshin#define	nd_ns_code		nd_ns_hdr.icmp6_code
20853541Sshin#define	nd_ns_cksum		nd_ns_hdr.icmp6_cksum
20953541Sshin#define	nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]
21053541Sshin
21153541Sshinstruct nd_neighbor_advert {	/* neighbor advertisement */
21253541Sshin	struct	icmp6_hdr	nd_na_hdr;
21353541Sshin	struct	in6_addr	nd_na_target;	/* target address */
21453541Sshin	/* could be followed by options */
21553541Sshin};
21653541Sshin
21753541Sshin#define	nd_na_type		nd_na_hdr.icmp6_type
21853541Sshin#define	nd_na_code		nd_na_hdr.icmp6_code
21953541Sshin#define	nd_na_cksum		nd_na_hdr.icmp6_cksum
22053541Sshin#define	nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]
22153541Sshin#if BYTE_ORDER == BIG_ENDIAN
22253541Sshin#define	ND_NA_FLAG_ROUTER		0x80000000
22353541Sshin#define	ND_NA_FLAG_SOLICITED		0x40000000
22453541Sshin#define	ND_NA_FLAG_OVERRIDE		0x20000000
22553541Sshin#elif BYTE_ORDER == LITTLE_ENDIAN
22653541Sshin#define	ND_NA_FLAG_ROUTER		0x80
22753541Sshin#define	ND_NA_FLAG_SOLICITED		0x40
22853541Sshin#define	ND_NA_FLAG_OVERRIDE		0x20
22953541Sshin#endif
23053541Sshin
23153541Sshinstruct nd_redirect {		/* redirect */
23253541Sshin	struct	icmp6_hdr	nd_rd_hdr;
23353541Sshin	struct	in6_addr	nd_rd_target;	/* target address */
23453541Sshin	struct	in6_addr	nd_rd_dst;	/* destination address */
23553541Sshin	/* could be followed by options */
23653541Sshin};
23753541Sshin
23853541Sshin#define	nd_rd_type		nd_rd_hdr.icmp6_type
23953541Sshin#define	nd_rd_code		nd_rd_hdr.icmp6_code
24053541Sshin#define	nd_rd_cksum		nd_rd_hdr.icmp6_cksum
24153541Sshin#define	nd_rd_reserved		nd_rd_hdr.icmp6_data32[0]
24253541Sshin
24353541Sshinstruct nd_opt_hdr {		/* Neighbor discovery option header */
24453541Sshin	u_int8_t	nd_opt_type;
24553541Sshin	u_int8_t	nd_opt_len;
24653541Sshin	/* followed by option specific data*/
24753541Sshin};
24853541Sshin
24953541Sshin#define	ND_OPT_SOURCE_LINKADDR		1
25053541Sshin#define	ND_OPT_TARGET_LINKADDR		2
25153541Sshin#define	ND_OPT_PREFIX_INFORMATION	3
25253541Sshin#define	ND_OPT_REDIRECTED_HEADER	4
25353541Sshin#define	ND_OPT_MTU			5
25453541Sshin
25553541Sshinstruct nd_opt_prefix_info {	/* prefix information */
25653541Sshin	u_int8_t	nd_opt_pi_type;
25753541Sshin	u_int8_t	nd_opt_pi_len;
25853541Sshin	u_int8_t	nd_opt_pi_prefix_len;
25953541Sshin	u_int8_t	nd_opt_pi_flags_reserved;
26053541Sshin	u_int32_t	nd_opt_pi_valid_time;
26153541Sshin	u_int32_t	nd_opt_pi_preferred_time;
26253541Sshin	u_int32_t	nd_opt_pi_reserved2;
26353541Sshin	struct	in6_addr	nd_opt_pi_prefix;
26453541Sshin};
26553541Sshin
26653541Sshin#define	ND_OPT_PI_FLAG_ONLINK		0x80
26753541Sshin#define	ND_OPT_PI_FLAG_AUTO		0x40
26853541Sshin
26953541Sshinstruct nd_opt_rd_hdr {         /* redirected header */
27053541Sshin	u_int8_t	nd_opt_rh_type;
27153541Sshin	u_int8_t	nd_opt_rh_len;
27253541Sshin	u_int16_t	nd_opt_rh_reserved1;
27353541Sshin	u_int32_t	nd_opt_rh_reserved2;
27453541Sshin	/* followed by IP header and data */
27553541Sshin};
27653541Sshin
27753541Sshinstruct nd_opt_mtu {		/* MTU option */
27853541Sshin	u_int8_t	nd_opt_mtu_type;
27953541Sshin	u_int8_t	nd_opt_mtu_len;
28053541Sshin	u_int16_t	nd_opt_mtu_reserved;
28153541Sshin	u_int32_t	nd_opt_mtu_mtu;
28253541Sshin};
28353541Sshin
28453541Sshin/*
28553541Sshin * icmp6 namelookup
28653541Sshin */
28753541Sshin
28853541Sshinstruct icmp6_namelookup {
28953541Sshin	struct	icmp6_hdr	icmp6_nl_hdr;
29053541Sshin	u_int64_t	icmp6_nl_nonce;
29153541Sshin	u_int32_t	icmp6_nl_ttl;
29253541Sshin	/* could be followed by options */
29353541Sshin};
29453541Sshin
29553541Sshin/*
29653541Sshin * icmp6 node information
29753541Sshin */
29853541Sshinstruct icmp6_nodeinfo {
29953541Sshin	struct	icmp6_hdr icmp6_ni_hdr;
30053541Sshin	u_int64_t	icmp6_ni_nonce;
30153541Sshin	/* could be followed by reply data */
30253541Sshin};
30353541Sshin
30453541Sshin#define	ni_type		icmp6_ni_hdr.icmp6_type
30553541Sshin#define	ni_code		icmp6_ni_hdr.icmp6_code
30653541Sshin#define	ni_cksum	icmp6_ni_hdr.icmp6_cksum
30753541Sshin#define	ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
30853541Sshin#define	ni_flags	icmp6_ni_hdr.icmp6_data16[1]
30953541Sshin
31053541Sshin
31153541Sshin#define	NI_QTYPE_NOOP		0 /* NOOP  */
31253541Sshin#define	NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
31353541Sshin#define	NI_QTYPE_FQDN		2 /* FQDN */
31453541Sshin#define	NI_QTYPE_NODEADDR	3 /* Node Addresses. XXX: spec says 2, but it may be a typo... */
31553541Sshin
31653541Sshin#if BYTE_ORDER == BIG_ENDIAN
31753541Sshin#define	NI_SUPTYPE_FLAG_COMPRESS	0x1
31853541Sshin#define	NI_FQDN_FLAG_VALIDTTL		0x1
31953541Sshin#define	NI_NODEADDR_FLAG_LINKLOCAL	0x1
32053541Sshin#define	NI_NODEADDR_FLAG_SITELOCAL	0x2
32153541Sshin#define	NI_NODEADDR_FLAG_GLOBAL		0x4
32253541Sshin#define	NI_NODEADDR_FLAG_ALL		0x8
32353541Sshin#define	NI_NODEADDR_FLAG_TRUNCATE	0x10
32453541Sshin#define	NI_NODEADDR_FLAG_ANYCAST	0x20 /* just experimental. not in spec */
32553541Sshin#elif BYTE_ORDER == LITTLE_ENDIAN
32653541Sshin#define	NI_SUPTYPE_FLAG_COMPRESS	0x0100
32753541Sshin#define	NI_FQDN_FLAG_VALIDTTL		0x0100
32853541Sshin#define	NI_NODEADDR_FLAG_LINKLOCAL	0x0100
32953541Sshin#define	NI_NODEADDR_FLAG_SITELOCAL	0x0200
33053541Sshin#define	NI_NODEADDR_FLAG_GLOBAL		0x0400
33153541Sshin#define	NI_NODEADDR_FLAG_ALL		0x0800
33253541Sshin#define	NI_NODEADDR_FLAG_TRUNCATE	0x1000
33353541Sshin#define	NI_NODEADDR_FLAG_ANYCAST	0x2000 /* just experimental. not in spec */
33453541Sshin#endif
33553541Sshin
33653541Sshinstruct ni_reply_fqdn {
33753541Sshin	u_int32_t	ni_fqdn_ttl;	/* TTL */
33853541Sshin	u_int8_t	ni_fqdn_namelen; /* length in octets of the FQDN */
33953541Sshin	u_int8_t	ni_fqdn_name[3]; /* XXX: alignment */
34053541Sshin};
34153541Sshin
34253541Sshin/*
34353541Sshin * Router Renumbering. as router-renum-08.txt
34453541Sshin */
34553541Sshinstruct icmp6_router_renum {	/* router renumbering header */
34653541Sshin	struct icmp6_hdr	rr_hdr;
34753541Sshin	u_int8_t	rr_segnum;
34853541Sshin	u_int8_t	rr_flags;
34953541Sshin	u_int16_t	rr_maxdelay;
35053541Sshin	u_int32_t	rr_reserved;
35153541Sshin};
35253541Sshin#define	ICMP6_RR_FLAGS_SEGNUM		0x80
35353541Sshin#define	ICMP6_RR_FLAGS_TEST		0x40
35453541Sshin#define	ICMP6_RR_FLAGS_REQRESULT	0x20
35553541Sshin#define	ICMP6_RR_FLAGS_FORCEAPPLY	0x10
35653541Sshin#define	ICMP6_RR_FLAGS_SPECSITE		0x08
35753541Sshin#define	ICMP6_RR_FLAGS_PREVDONE		0x04
35853541Sshin
35953541Sshin#define	rr_type		rr_hdr.icmp6_type
36053541Sshin#define	rr_code		rr_hdr.icmp6_code
36153541Sshin#define	rr_cksum	rr_hdr.icmp6_cksum
36253541Sshin#define	rr_seqnum 	rr_hdr.icmp6_data32[0]
36353541Sshin
36453541Sshinstruct rr_pco_match {		/* match prefix part */
36553541Sshin	u_int8_t	rpm_code;
36653541Sshin	u_int8_t	rpm_len;
36753541Sshin	u_int8_t	rpm_ordinal;
36853541Sshin	u_int8_t	rpm_matchlen;
36953541Sshin	u_int8_t	rpm_minlen;
37053541Sshin	u_int8_t	rpm_maxlen;
37153541Sshin	u_int16_t	rpm_reserved;
37253541Sshin	struct	in6_addr	rpm_prefix;
37353541Sshin};
37453541Sshin
37553541Sshin#define	RPM_PCO_ADD		1
37653541Sshin#define	RPM_PCO_CHANGE		2
37753541Sshin#define	RPM_PCO_SETGLOBAL	3
37853541Sshin
37953541Sshinstruct rr_pco_use {		/* use prefix part */
38053541Sshin	u_int8_t	rpu_uselen;
38153541Sshin	u_int8_t	rpu_keeplen;
38253541Sshin	u_int8_t	rpu_ramask;
38353541Sshin	u_int8_t	rpu_raflags;
38453541Sshin	u_int32_t	rpu_vltime;
38553541Sshin	u_int32_t	rpu_pltime;
38653541Sshin	u_int32_t	rpu_flags;
38753541Sshin	struct	in6_addr rpu_prefix;
38853541Sshin};
38953541Sshin#define	ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x20
39053541Sshin#define	ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x10
39153541Sshin
39253541Sshin#if BYTE_ORDER == BIG_ENDIAN
39353541Sshin#define	ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
39453541Sshin#define	ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
39553541Sshin#elif BYTE_ORDER == LITTLE_ENDIAN
39653541Sshin#define	ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
39753541Sshin#define	ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
39853541Sshin#endif
39953541Sshin
40053541Sshinstruct rr_result {		/* router renumbering result message */
40153541Sshin	u_int16_t	rrr_flags;
40253541Sshin	u_int8_t	rrr_ordinal;
40353541Sshin	u_int8_t	rrr_matchedlen;
40453541Sshin	u_int32_t	rrr_ifid;
40553541Sshin	struct	in6_addr rrr_prefix;
40653541Sshin};
40753541Sshin#if BYTE_ORDER == BIG_ENDIAN
40853541Sshin#define	ICMP6_RR_RESULT_FLAGS_OOB		0x0002
40953541Sshin#define	ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
41053541Sshin#elif BYTE_ORDER == LITTLE_ENDIAN
41153541Sshin#define	ICMP6_RR_RESULT_FLAGS_OOB		0x02
41253541Sshin#define	ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x01
41353541Sshin#endif
41453541Sshin
41553541Sshin/*
41653541Sshin * icmp6 filter structures.
41753541Sshin */
41853541Sshin
41953541Sshinstruct icmp6_filter {
42053541Sshin	u_int32_t	icmp6_filter[8];
42153541Sshin};
42253541Sshin
42353541Sshin#ifdef _KERNEL
42453541Sshin#define	ICMP6_FILTER_SETPASSALL(filterp) \
42553541Sshin    {								\
42653541Sshin	int i; u_char *p;					\
42753541Sshin	p = (u_char *)filterp;					\
42853541Sshin	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
42953541Sshin		p[i] = 0xff;					\
43053541Sshin    }
43153541Sshin#define	ICMP6_FILTER_SETBLOCKALL(filterp) \
43253541Sshin	bzero(filterp, sizeof(struct icmp6_filter))
43353541Sshin#else /* _KERNEL */
43453541Sshin#define	ICMP6_FILTER_SETPASSALL(filterp) \
43553541Sshin	memset(filterp, 0xff, sizeof(struct icmp6_filter))
43653541Sshin#define	ICMP6_FILTER_SETBLOCKALL(filterp) \
43753541Sshin	memset(filterp, 0x00, sizeof(struct icmp6_filter))
43853541Sshin#endif /* _KERNEL */
43953541Sshin
44053541Sshin#define	ICMP6_FILTER_SETPASS(type, filterp) \
44153541Sshin	(((filterp)->icmp6_filter[(type) >> 5]) |= (1 << ((type) & 31)))
44253541Sshin#define	ICMP6_FILTER_SETBLOCK(type, filterp) \
44353541Sshin	(((filterp)->icmp6_filter[(type) >> 5]) &= ~(1 << ((type) & 31)))
44453541Sshin#define	ICMP6_FILTER_WILLPASS(type, filterp) \
44553541Sshin	((((filterp)->icmp6_filter[(type) >> 5]) & (1 << ((type) & 31))) != 0)
44653541Sshin#define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
44753541Sshin	((((filterp)->icmp6_filter[(type) >> 5]) & (1 << ((type) & 31))) == 0)
44853541Sshin
44953541Sshin/*
45053541Sshin * Variables related to this implementation
45153541Sshin * of the internet control message protocol version 6.
45253541Sshin */
45353541Sshinstruct icmp6stat {
45453541Sshin/* statistics related to icmp6 packets generated */
45553541Sshin	u_long	icp6s_error;		/* # of calls to icmp6_error */
45653541Sshin	u_long	icp6s_canterror;	/* no error 'cuz old was icmp */
45753541Sshin	u_long	icp6s_toofreq;		/* no error 'cuz rate limitation */
45853541Sshin	u_long	icp6s_outhist[256];
45953541Sshin/* statistics related to input messages proccesed */
46053541Sshin	u_long	icp6s_badcode;		/* icmp6_code out of range */
46153541Sshin	u_long	icp6s_tooshort;		/* packet < sizeof(struct icmp6_hdr) */
46253541Sshin	u_long	icp6s_checksum;		/* bad checksum */
46353541Sshin	u_long	icp6s_badlen;		/* calculated bound mismatch */
46453541Sshin	u_long	icp6s_reflect;		/* number of responses */
46553541Sshin	u_long	icp6s_inhist[256];
46653541Sshin};
46753541Sshin
46853541Sshin/*
46953541Sshin * Names for ICMP sysctl objects
47053541Sshin */
47153541Sshin#define	ICMPV6CTL_STATS			1
47253541Sshin#define	ICMPV6CTL_REDIRACCEPT		2 /* accept/process redirects */
47353541Sshin#define	ICMPV6CTL_REDIRTIMEOUT		3 /* redirect cache time */
47453541Sshin#define	ICMPV6CTL_ERRRATELIMIT		5 /* ICMPv6 error rate limitation */
47553541Sshin#define	ICMPV6CTL_ND6_PRUNE		6
47653541Sshin#define	ICMPV6CTL_ND6_DELAY		8
47753541Sshin#define	ICMPV6CTL_ND6_UMAXTRIES		9
47853541Sshin#define	ICMPV6CTL_ND6_MMAXTRIES		10
47953541Sshin#define	ICMPV6CTL_ND6_USELOOPBACK	11
48053541Sshin#define	ICMPV6CTL_ND6_PROXYALL		12
48153541Sshin#define	ICMPV6CTL_MAXID			13
48253541Sshin
48353541Sshin#define ICMPV6CTL_NAMES { \
48453541Sshin	{ 0, 0 }, \
48553541Sshin	{ 0, 0 }, \
48653541Sshin	{ "rediraccept", CTLTYPE_INT }, \
48753541Sshin	{ "redirtimeout", CTLTYPE_INT }, \
48853541Sshin	{ 0, 0 }, \
48953541Sshin	{ "errratelimit", CTLTYPE_INT }, \
49053541Sshin	{ "nd6_prune", CTLTYPE_INT }, \
49153541Sshin	{ 0, 0 }, \
49253541Sshin	{ "nd6_delay", CTLTYPE_INT }, \
49353541Sshin	{ "nd6_umaxtries", CTLTYPE_INT }, \
49453541Sshin	{ "nd6_mmaxtries", CTLTYPE_INT }, \
49553541Sshin	{ "nd6_useloopback", CTLTYPE_INT }, \
49653541Sshin	{ "nd6_proxyall", CTLTYPE_INT }, \
49753541Sshin}
49853541Sshin
49953541Sshin#define ICMPV6CTL_VARS { \
50053541Sshin	0, \
50153541Sshin	0, \
50253541Sshin	&icmp6_rediraccept,   \
50353541Sshin	&icmp6_redirtimeout,  \
50453541Sshin	0, \
50553541Sshin	0, \
50653541Sshin	&icmp6errratelim, \
50753541Sshin	&nd6_prune,	\
50853541Sshin	0, \
50953541Sshin	&nd6_delay,	\
51053541Sshin	&nd6_umaxtries, \
51153541Sshin	&nd6_mmaxtries,	\
51253541Sshin	&nd6_useloopback, \
51353541Sshin	&nd6_proxyall, \
51453541Sshin}
51553541Sshin
51653541Sshin#define RTF_PROBEMTU	RTF_PROTO1
51753541Sshin
51853541Sshin#ifdef _KERNEL
51953541Sshin# ifdef __STDC__
52053541Sshinstruct	rtentry;
52153541Sshinstruct	rttimer;
52253541Sshinstruct	in6_multi;
52353541Sshin# endif
52453541Sshinvoid	icmp6_init __P((void));
52553541Sshinvoid	icmp6_paramerror __P((struct mbuf *, int));
52653541Sshinvoid	icmp6_error __P((struct mbuf *, int, int, int));
52753541Sshinint	icmp6_input __P((struct mbuf **, int *, int));
52853541Sshinvoid	icmp6_fasttimo __P((void));
52953541Sshinvoid	icmp6_reflect __P((struct mbuf *, size_t));
53053541Sshinvoid	icmp6_prepare __P((struct mbuf *));
53153541Sshinvoid	icmp6_redirect_input __P((struct mbuf *, int));
53253541Sshinvoid	icmp6_redirect_output __P((struct mbuf *, struct rtentry *));
53353541Sshin
53453541Sshin/* XXX: is this the right place for these macros? */
53553541Sshin#define icmp6_ifstat_inc(ifp, tag) \
53653541Sshindo {								\
53753541Sshin	if ((ifp) && (ifp)->if_index <= if_index			\
53853541Sshin	 && (ifp)->if_index < icmp6_ifstatmax			\
53953541Sshin	 && icmp6_ifstat && icmp6_ifstat[(ifp)->if_index]) {	\
54053541Sshin		icmp6_ifstat[(ifp)->if_index]->tag++;		\
54153541Sshin	}							\
54253541Sshin} while (0)
54353541Sshin
54453541Sshin#define icmp6_ifoutstat_inc(ifp, type, code) \
54553541Sshindo { \
54653541Sshin		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
54753541Sshin 		if (type < ICMP6_INFOMSG_MASK) \
54853541Sshin 			icmp6_ifstat_inc(ifp, ifs6_out_error); \
54953541Sshin		switch(type) { \
55053541Sshin		 case ICMP6_DST_UNREACH: \
55153541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
55253541Sshin			 if (code == ICMP6_DST_UNREACH_ADMIN) \
55353541Sshin				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
55453541Sshin			 break; \
55553541Sshin		 case ICMP6_PACKET_TOO_BIG: \
55653541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
55753541Sshin			 break; \
55853541Sshin		 case ICMP6_TIME_EXCEEDED: \
55953541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
56053541Sshin			 break; \
56153541Sshin		 case ICMP6_PARAM_PROB: \
56253541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
56353541Sshin			 break; \
56453541Sshin		 case ICMP6_ECHO_REQUEST: \
56553541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
56653541Sshin			 break; \
56753541Sshin		 case ICMP6_ECHO_REPLY: \
56853541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
56953541Sshin			 break; \
57053541Sshin		 case MLD6_LISTENER_QUERY: \
57153541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
57253541Sshin			 break; \
57353541Sshin		 case MLD6_LISTENER_REPORT: \
57453541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
57553541Sshin			 break; \
57653541Sshin		 case MLD6_LISTENER_DONE: \
57753541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
57853541Sshin			 break; \
57953541Sshin		 case ND_ROUTER_SOLICIT: \
58053541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
58153541Sshin			 break; \
58253541Sshin		 case ND_ROUTER_ADVERT: \
58353541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
58453541Sshin			 break; \
58553541Sshin		 case ND_NEIGHBOR_SOLICIT: \
58653541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
58753541Sshin			 break; \
58853541Sshin		 case ND_NEIGHBOR_ADVERT: \
58953541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
59053541Sshin			 break; \
59153541Sshin		 case ND_REDIRECT: \
59253541Sshin			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
59353541Sshin			 break; \
59453541Sshin		} \
59553541Sshin} while (0)
59653541Sshin
59753541Sshinextern int	icmp6_rediraccept;	/* accept/process redirects */
59853541Sshinextern int	icmp6_redirtimeout;	/* cache time for redirect routes */
59953541Sshin#endif /* _KERNEL */
60053541Sshin
60153541Sshin#endif /* not _NETINET6_ICMPV6_H_ */
60253541Sshin
603