xref: /freebsd-12.1/share/doc/IPv6/IMPLEMENTATION (revision 93b03d5d)
180d21dc4SYoshinobu Inoue	Implementation Note
280d21dc4SYoshinobu Inoue
380d21dc4SYoshinobu Inoue	KAME Project
480d21dc4SYoshinobu Inoue	http://www.kame.net/
533841545SHajimu UMEMOTO	$KAME: IMPLEMENTATION,v 1.216 2001/05/25 07:43:01 jinmei Exp $
680d21dc4SYoshinobu Inoue	$FreeBSD$
780d21dc4SYoshinobu Inoue
8f88fe57eSHajimu UMEMOTONOTE: The document tries to describe behaviors/implementation choices
92ea36b5dSBjoern A. Zeebof the latest KAME/*BSD stack.  The description here may not be
102ea36b5dSBjoern A. Zeebapplicable to KAME-integrated *BSD releases, as we have certain amount
112ea36b5dSBjoern A. Zeebof changes between them.  Still, some of the content can be useful for
122ea36b5dSBjoern A. ZeebKAME-integrated *BSD releases.
13f88fe57eSHajimu UMEMOTO
14f88fe57eSHajimu UMEMOTOTable of Contents
15f88fe57eSHajimu UMEMOTO
16f88fe57eSHajimu UMEMOTO	1. IPv6
17f88fe57eSHajimu UMEMOTO	1.1 Conformance
18f88fe57eSHajimu UMEMOTO	1.2 Neighbor Discovery
19f88fe57eSHajimu UMEMOTO	1.3 Scope Zone Index
20f88fe57eSHajimu UMEMOTO	1.3.1 Kernel internal
21f88fe57eSHajimu UMEMOTO	1.3.2 Interaction with API
22f88fe57eSHajimu UMEMOTO	1.3.3 Interaction with users (command line)
23f88fe57eSHajimu UMEMOTO	1.4 Plug and Play
24f88fe57eSHajimu UMEMOTO	1.4.1 Assignment of link-local, and special addresses
25f88fe57eSHajimu UMEMOTO	1.4.2 Stateless address autoconfiguration on hosts
26f88fe57eSHajimu UMEMOTO	1.4.3 DHCPv6
27f88fe57eSHajimu UMEMOTO	1.5 Generic tunnel interface
28f88fe57eSHajimu UMEMOTO	1.6 Address Selection
29f88fe57eSHajimu UMEMOTO	1.6.1 Source Address Selection
30f88fe57eSHajimu UMEMOTO	1.6.2 Destination Address Ordering
31f88fe57eSHajimu UMEMOTO	1.7 Jumbo Payload
32f88fe57eSHajimu UMEMOTO	1.8 Loop prevention in header processing
33f88fe57eSHajimu UMEMOTO	1.9 ICMPv6
34f88fe57eSHajimu UMEMOTO	1.10 Applications
35f88fe57eSHajimu UMEMOTO	1.11 Kernel Internals
36f88fe57eSHajimu UMEMOTO	1.12 IPv4 mapped address and IPv6 wildcard socket
37f88fe57eSHajimu UMEMOTO	1.12.1 KAME/BSDI3 and KAME/FreeBSD228
38f88fe57eSHajimu UMEMOTO	1.12.2 KAME/FreeBSD[34]x
39f88fe57eSHajimu UMEMOTO	1.12.2.1 KAME/FreeBSD[34]x, listening side
40f88fe57eSHajimu UMEMOTO	1.12.2.2 KAME/FreeBSD[34]x, initiating side
41f88fe57eSHajimu UMEMOTO	1.12.3 KAME/NetBSD
42f88fe57eSHajimu UMEMOTO	1.12.3.1 KAME/NetBSD, listening side
43f88fe57eSHajimu UMEMOTO	1.12.3.2 KAME/NetBSD, initiating side
44f88fe57eSHajimu UMEMOTO	1.12.4 KAME/BSDI4
45f88fe57eSHajimu UMEMOTO	1.12.4.1 KAME/BSDI4, listening side
46f88fe57eSHajimu UMEMOTO	1.12.4.2 KAME/BSDI4, initiating side
47f88fe57eSHajimu UMEMOTO	1.12.5 KAME/OpenBSD
48f88fe57eSHajimu UMEMOTO	1.12.5.1 KAME/OpenBSD, listening side
49f88fe57eSHajimu UMEMOTO	1.12.5.2 KAME/OpenBSD, initiating side
50f88fe57eSHajimu UMEMOTO	1.12.6 More issues
51f88fe57eSHajimu UMEMOTO	1.12.7 Interaction with SIIT translator
52f88fe57eSHajimu UMEMOTO	1.13 sockaddr_storage
53f88fe57eSHajimu UMEMOTO	1.14 Invalid addresses on the wire
54f88fe57eSHajimu UMEMOTO	1.15 Node's required addresses
55f88fe57eSHajimu UMEMOTO	1.15.1 Host case
56f88fe57eSHajimu UMEMOTO	1.15.2 Router case
57f88fe57eSHajimu UMEMOTO	1.16 Advanced API
58f88fe57eSHajimu UMEMOTO	1.17 DNS resolver
59f88fe57eSHajimu UMEMOTO	2. Network Drivers
60f88fe57eSHajimu UMEMOTO	2.1 FreeBSD 2.2.x-RELEASE
61f88fe57eSHajimu UMEMOTO	2.2 BSD/OS 3.x
62f88fe57eSHajimu UMEMOTO	2.3 NetBSD
63f88fe57eSHajimu UMEMOTO	2.4 FreeBSD 3.x-RELEASE
64f88fe57eSHajimu UMEMOTO	2.5 FreeBSD 4.x-RELEASE
65f88fe57eSHajimu UMEMOTO	2.6 OpenBSD 2.x
66f88fe57eSHajimu UMEMOTO	2.7 BSD/OS 4.x
67f88fe57eSHajimu UMEMOTO	3. Translator
68f88fe57eSHajimu UMEMOTO	3.1 FAITH TCP relay translator
69f88fe57eSHajimu UMEMOTO	3.2 IPv6-to-IPv4 header translator
70f88fe57eSHajimu UMEMOTO	4. IPsec
71f88fe57eSHajimu UMEMOTO	4.1 Policy Management
72f88fe57eSHajimu UMEMOTO	4.2 Key Management
73f88fe57eSHajimu UMEMOTO	4.3 AH and ESP handling
74f88fe57eSHajimu UMEMOTO	4.4 IPComp handling
75f88fe57eSHajimu UMEMOTO	4.5 Conformance to RFCs and IDs
76f88fe57eSHajimu UMEMOTO	4.6 ECN consideration on IPsec tunnels
77f88fe57eSHajimu UMEMOTO	4.7 Interoperability
78f88fe57eSHajimu UMEMOTO	4.8 Operations with IPsec tunnel mode
79f88fe57eSHajimu UMEMOTO	4.8.1 RFC2401 IPsec tunnel mode approach
80f88fe57eSHajimu UMEMOTO	4.8.2 draft-touch-ipsec-vpn approach
81f88fe57eSHajimu UMEMOTO	5. ALTQ
82f88fe57eSHajimu UMEMOTO	6. Mobile IPv6
83f88fe57eSHajimu UMEMOTO	6.1 KAME node as correspondent node
84f88fe57eSHajimu UMEMOTO	6.2 KAME node as home agent/mobile node
85f88fe57eSHajimu UMEMOTO	6.3 Old Mobile IPv6 code
862ea36b5dSBjoern A. Zeeb	7. Coding style
872ea36b5dSBjoern A. Zeeb	8. Policy on technology with intellectual property right restriction
88f88fe57eSHajimu UMEMOTO
8980d21dc4SYoshinobu Inoue1. IPv6
9080d21dc4SYoshinobu Inoue
9180d21dc4SYoshinobu Inoue1.1 Conformance
9280d21dc4SYoshinobu Inoue
9380d21dc4SYoshinobu InoueThe KAME kit conforms, or tries to conform, to the latest set of IPv6
9480d21dc4SYoshinobu Inouespecifications.  For future reference we list some of the relevant documents
9580d21dc4SYoshinobu Inouebelow (NOTE: this is not a complete list - this is too hard to maintain...).
9680d21dc4SYoshinobu InoueFor details please refer to specific chapter in the document, RFCs, manpages
9780d21dc4SYoshinobu Inouecome with KAME, or comments in the source code.
9880d21dc4SYoshinobu Inoue
998f336835SJun-ichiro itojun HaginoConformance tests have been performed on past and latest KAME STABLE kit,
10080d21dc4SYoshinobu Inoueat TAHI project.  Results can be viewed at http://www.tahi.org/report/KAME/.
10180d21dc4SYoshinobu InoueWe also attended Univ. of New Hampshire IOL tests (http://www.iol.unh.edu/)
10280d21dc4SYoshinobu Inouein the past, with our past snapshots.
10380d21dc4SYoshinobu Inoue
10480d21dc4SYoshinobu InoueRFC1639: FTP Operation Over Big Address Records (FOOBAR)
10580d21dc4SYoshinobu Inoue    * RFC2428 is preferred over RFC1639.  ftp clients will first try RFC2428,
10680d21dc4SYoshinobu Inoue      then RFC1639 if failed.
10780d21dc4SYoshinobu InoueRFC1886: DNS Extensions to support IPv6
10833841545SHajimu UMEMOTORFC1933: (see RFC2893)
10980d21dc4SYoshinobu InoueRFC1981: Path MTU Discovery for IPv6
11080d21dc4SYoshinobu InoueRFC2080: RIPng for IPv6
11180d21dc4SYoshinobu Inoue    * KAME-supplied route6d, bgpd and hroute6d support this.
11280d21dc4SYoshinobu InoueRFC2283: Multiprotocol Extensions for BGP-4
11380d21dc4SYoshinobu Inoue    * so-called "BGP4+".
11480d21dc4SYoshinobu Inoue    * KAME-supplied bgpd supports this.
11580d21dc4SYoshinobu InoueRFC2292: Advanced Sockets API for IPv6
116f88fe57eSHajimu UMEMOTO    * see RFC3542
11780d21dc4SYoshinobu InoueRFC2362: Protocol Independent Multicast-Sparse Mode (PIM-SM)
11833841545SHajimu UMEMOTO    * RFC2362 defines the packet formats and the protcol of PIM-SM.
11980d21dc4SYoshinobu InoueRFC2373: IPv6 Addressing Architecture
12080d21dc4SYoshinobu Inoue    * KAME supports node required addresses, and conforms to the scope
12180d21dc4SYoshinobu Inoue      requirement.
12280d21dc4SYoshinobu InoueRFC2374: An IPv6 Aggregatable Global Unicast Address Format
12380d21dc4SYoshinobu Inoue    * KAME supports 64-bit length of Interface ID.
12480d21dc4SYoshinobu InoueRFC2375: IPv6 Multicast Address Assignments
12580d21dc4SYoshinobu Inoue    * Userland applications use the well-known addresses assigned in the RFC.
12680d21dc4SYoshinobu InoueRFC2428: FTP Extensions for IPv6 and NATs
12780d21dc4SYoshinobu Inoue    * RFC2428 is preferred over RFC1639.  ftp clients will first try RFC2428,
12880d21dc4SYoshinobu Inoue      then RFC1639 if failed.
12980d21dc4SYoshinobu InoueRFC2460: IPv6 specification
13080d21dc4SYoshinobu InoueRFC2461: Neighbor discovery for IPv6
13180d21dc4SYoshinobu Inoue    * See 1.2 in this document for details.
13280d21dc4SYoshinobu InoueRFC2462: IPv6 Stateless Address Autoconfiguration
13380d21dc4SYoshinobu Inoue    * See 1.4 in this document for details.
13480d21dc4SYoshinobu InoueRFC2463: ICMPv6 for IPv6 specification
135f88fe57eSHajimu UMEMOTO    * See 1.9 in this document for details.
13680d21dc4SYoshinobu InoueRFC2464: Transmission of IPv6 Packets over Ethernet Networks
13780d21dc4SYoshinobu InoueRFC2465: MIB for IPv6: Textual Conventions and General Group
13880d21dc4SYoshinobu Inoue    * Necessary statistics are gathered by the kernel.  Actual IPv6 MIB
13980d21dc4SYoshinobu Inoue      support is provided as patchkit for ucd-snmp.
14080d21dc4SYoshinobu InoueRFC2466: MIB for IPv6: ICMPv6 group
14180d21dc4SYoshinobu Inoue    * Necessary statistics are gathered by the kernel.  Actual IPv6 MIB
14280d21dc4SYoshinobu Inoue      support is provided as patchkit for ucd-snmp.
14380d21dc4SYoshinobu InoueRFC2467: Transmission of IPv6 Packets over FDDI Networks
14480d21dc4SYoshinobu InoueRFC2472: IPv6 over PPP
14580d21dc4SYoshinobu InoueRFC2492: IPv6 over ATM Networks
14680d21dc4SYoshinobu Inoue    * only PVC is supported.
14780d21dc4SYoshinobu InoueRFC2497: Transmission of IPv6 packet over ARCnet Networks
14880d21dc4SYoshinobu InoueRFC2545: Use of BGP-4 Multiprotocol Extensions for IPv6 Inter-Domain Routing
149f88fe57eSHajimu UMEMOTORFC2553: (see RFC3493)
15033841545SHajimu UMEMOTORFC2671: Extension Mechanisms for DNS (EDNS0)
15133841545SHajimu UMEMOTO    * see USAGE for how to use it.
15233841545SHajimu UMEMOTO    * not supported on kame/freebsd4 and kame/bsdi4.
15333841545SHajimu UMEMOTORFC2673: Binary Labels in the Domain Name System
15433841545SHajimu UMEMOTO    * KAME/bsdi4 supports A6, DNAME and binary label to some extent.
15533841545SHajimu UMEMOTO    * KAME apps/bind8 repository has resolver library with partial A6, DNAME
15633841545SHajimu UMEMOTO      and binary label support.
15780d21dc4SYoshinobu InoueRFC2675: IPv6 Jumbograms
15880d21dc4SYoshinobu Inoue    * See 1.7 in this document for details.
15980d21dc4SYoshinobu InoueRFC2710: Multicast Listener Discovery for IPv6
16080d21dc4SYoshinobu InoueRFC2711: IPv6 router alert option
1618f336835SJun-ichiro itojun HaginoRFC2732: Format for Literal IPv6 Addresses in URL's
1628f336835SJun-ichiro itojun Hagino    * The spec is implemented in programs that handle URLs
1638f336835SJun-ichiro itojun Hagino      (like freebsd ftpio(3) and fetch(1), or netbsd ftp(1))
16433841545SHajimu UMEMOTORFC2874: DNS Extensions to Support IPv6 Address Aggregation and Renumbering
16533841545SHajimu UMEMOTO    * KAME/bsdi4 supports A6, DNAME and binary label to some extent.
16633841545SHajimu UMEMOTO    * KAME apps/bind8 repository has resolver library with partial A6, DNAME
16733841545SHajimu UMEMOTO      and binary label support.
16833841545SHajimu UMEMOTORFC2893: Transition Mechanisms for IPv6 Hosts and Routers
16933841545SHajimu UMEMOTO    * IPv4 compatible address is not supported.
17033841545SHajimu UMEMOTO    * automatic tunneling (4.3) is not supported.
17133841545SHajimu UMEMOTO    * "gif" interface implements IPv[46]-over-IPv[46] tunnel in a generic way,
17233841545SHajimu UMEMOTO      and it covers "configured tunnel" described in the spec.
17333841545SHajimu UMEMOTO      See 1.5 in this document for details.
17433841545SHajimu UMEMOTORFC2894: Router renumbering for IPv6
17533841545SHajimu UMEMOTORFC3041: Privacy Extensions for Stateless Address Autoconfiguration in IPv6
17633841545SHajimu UMEMOTORFC3056: Connection of IPv6 Domains via IPv4 Clouds
17733841545SHajimu UMEMOTO    * So-called "6to4".
17833841545SHajimu UMEMOTO    * "stf" interface implements it.  Be sure to read
17933841545SHajimu UMEMOTO      draft-itojun-ipv6-transition-abuse-01.txt
18033841545SHajimu UMEMOTO      below before configuring it, there can be security issues.
1811f320556SHajimu UMEMOTORFC3142: An IPv6-to-IPv4 transport relay translator
1821f320556SHajimu UMEMOTO    * FAITH tcp relay translator (faithd) implements this.  See 3.1 for more
1831f320556SHajimu UMEMOTO      details.
184f88fe57eSHajimu UMEMOTORFC3152: Delegation of IP6.ARPA
185f88fe57eSHajimu UMEMOTO    * libinet6 resolvers contained in the KAME snaps support to use
186f88fe57eSHajimu UMEMOTO      the ip6.arpa domain (with the nibble format) for IPv6 reverse
187f88fe57eSHajimu UMEMOTO      lookups.
188f88fe57eSHajimu UMEMOTORFC3484: Default Address Selection for IPv6
189f88fe57eSHajimu UMEMOTO    * the selection algorithm for both source and destination addresses
190f88fe57eSHajimu UMEMOTO      is implemented based on the RFC, though some rules are still omitted.
191f88fe57eSHajimu UMEMOTORFC3493: Basic Socket Interface Extensions for IPv6
192f88fe57eSHajimu UMEMOTO    * IPv4 mapped address (3.7) and special behavior of IPv6 wildcard bind
193f88fe57eSHajimu UMEMOTO      socket (3.8) are,
194f88fe57eSHajimu UMEMOTO	- supported and turned on by default on KAME/FreeBSD[34]
195f88fe57eSHajimu UMEMOTO	  and KAME/BSDI4,
196f88fe57eSHajimu UMEMOTO	- supported but turned off by default on KAME/NetBSD and KAME/FreeBSD5,
197f88fe57eSHajimu UMEMOTO	- not supported on KAME/FreeBSD228, KAME/OpenBSD and KAME/BSDI3.
198f88fe57eSHajimu UMEMOTO      see 1.12 in this document for details.
1991f320556SHajimu UMEMOTO    * The AI_ALL and AI_V4MAPPED flags are not supported.
200f88fe57eSHajimu UMEMOTORFC3542: Advanced Sockets API for IPv6 (revised)
201f88fe57eSHajimu UMEMOTO    * For supported library functions/kernel APIs, see sys/netinet6/ADVAPI.
20233841545SHajimu UMEMOTO    * Some of the updates in the draft are not implemented yet.  See
20333841545SHajimu UMEMOTO      TODO.2292bis for more details.
204743eee66SSUZUKI ShinsukeRFC4007: IPv6 Scoped Address Architecture
20533841545SHajimu UMEMOTO    * some part of the documentation (especially about the routing
20633841545SHajimu UMEMOTO      model) is not supported yet.
207743eee66SSUZUKI Shinsuke    * zone indices that contain scope types have not been supported yet.
208743eee66SSUZUKI Shinsuke
209743eee66SSUZUKI Shinsukedraft-ietf-ipngwg-icmp-name-lookups-09: IPv6 Name Lookups Through ICMP
210743eee66SSUZUKI Shinsukedraft-ietf-ipv6-router-selection-07.txt:
211743eee66SSUZUKI Shinsuke	Default Router Preferences and More-Specific Routes
212743eee66SSUZUKI Shinsuke    * router-side: both router preference and specific routes are supported.
213743eee66SSUZUKI Shinsuke    * host-side: only router preference is supported.
21433841545SHajimu UMEMOTOdraft-ietf-pim-sm-v2-new-02.txt
21533841545SHajimu UMEMOTO	A revised version of RFC2362, which includes the IPv6 specific
21633841545SHajimu UMEMOTO	packet format and protocol descriptions.
21733841545SHajimu UMEMOTOdraft-ietf-dnsext-mdns-00.txt: Multicast DNS
21833841545SHajimu UMEMOTO    * kame/mdnsd has test implementation, which will not be built in
21933841545SHajimu UMEMOTO      default compilation.  The draft will experience a major change in the
22033841545SHajimu UMEMOTO      near future, so don't rely upon it.
221743eee66SSUZUKI Shinsukedraft-ietf-ipngwg-icmp-v3-02.txt: ICMPv6 for IPv6 specification (revised)
222743eee66SSUZUKI Shinsuke    * See 1.9 in this document for details.
223f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-tcp-to-anycast-01.txt:
224f88fe57eSHajimu UMEMOTO	Disconnecting TCP connection toward IPv6 anycast address
225743eee66SSUZUKI Shinsukedraft-ietf-ipv6-rfc2462bis-06.txt: IPv6 Stateless Address
226743eee66SSUZUKI Shinsuke	Autoconfiguration (revised)
227f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-transition-abuse-01.txt:
22833841545SHajimu UMEMOTO	Possible abuse against IPv6 transition technologies (expired)
22933841545SHajimu UMEMOTO    * KAME does not implement RFC1933/2893 automatic tunnel.
2308f336835SJun-ichiro itojun Hagino    * "stf" interface implements some address filters.  Refer to stf(4)
2318f336835SJun-ichiro itojun Hagino      for details.  Since there's no way to make 6to4 interface 100% secure,
2328f336835SJun-ichiro itojun Hagino      we do not include "stf" interface into GENERIC.v6 compilation.
2338f336835SJun-ichiro itojun Hagino    * kame/openbsd completely disables IPv4 mapped address support.
2348f336835SJun-ichiro itojun Hagino    * kame/netbsd makes IPv4 mapped address support off by default.
23533841545SHajimu UMEMOTO    * See section 1.12.6 and 1.14 for more details.
23633841545SHajimu UMEMOTOdraft-itojun-ipv6-flowlabel-api-01.txt: Socket API for IPv6 flow label field
23733841545SHajimu UMEMOTO    * no consideration is made against the use of routing headers and such.
23880d21dc4SYoshinobu Inoue
23980d21dc4SYoshinobu Inoue1.2 Neighbor Discovery
24080d21dc4SYoshinobu Inoue
241743eee66SSUZUKI ShinsukeOur implementation of Neighbor Discovery is fairly stable.  Currently
242743eee66SSUZUKI ShinsukeAddress Resolution, Duplicated Address Detection, and Neighbor
243743eee66SSUZUKI ShinsukeUnreachability Detection are supported.  In the near future we will be
244743eee66SSUZUKI Shinsukeadding an Unsolicited Neighbor Advertisement transmission command as
245743eee66SSUZUKI Shinsukean administration tool.
24680d21dc4SYoshinobu Inoue
2478f336835SJun-ichiro itojun HaginoDuplicated Address Detection (DAD) will be performed when an IPv6 address
2488f336835SJun-ichiro itojun Haginois assigned to a network interface, or the network interface is enabled
2498f336835SJun-ichiro itojun Hagino(ifconfig up).  It is documented in RFC2462 5.4.
25080d21dc4SYoshinobu InoueIf DAD fails, the address will be marked "duplicated" and message will be
25180d21dc4SYoshinobu Inouegenerated to syslog (and usually to console).  The "duplicated" mark
25280d21dc4SYoshinobu Inouecan be checked with ifconfig.  It is administrators' responsibility to check
2538f336835SJun-ichiro itojun Haginofor and recover from DAD failures.  We may try to improve failure recovery
2548f336835SJun-ichiro itojun Haginoin future KAME code.
255743eee66SSUZUKI Shinsuke
256743eee66SSUZUKI ShinsukeA successor version of RFC2462 (called rfc2462bis) clarifies the
257743eee66SSUZUKI Shinsukebehavior when DAD fails (i.e., duplicate is detected): if the
258743eee66SSUZUKI Shinsukeduplicate address is a link-local address formed from an interface
259743eee66SSUZUKI Shinsukeidentifier based on the hardware address which is supposed to be
260743eee66SSUZUKI Shinsukeuniquely assigned (e.g., EUI-64 for an Ethernet interface), IPv6
261743eee66SSUZUKI Shinsukeoperation on the interface should be disabled.  The KAME
262743eee66SSUZUKI Shinsukeimplementation supports this as follows: if this type of duplicate is
263743eee66SSUZUKI Shinsukedetected, the kernel marks "disabled" in the ND specific data
264743eee66SSUZUKI Shinsukestructure for the interface.  Every IPv6 I/O operation in the kernel
265743eee66SSUZUKI Shinsukechecks this mark, and the kernel will drop packets received on or
266743eee66SSUZUKI Shinsukebeing sent to the "disabled" interface.  Whether the IPv6 operation is
267743eee66SSUZUKI Shinsukedisabled or not can be confirmed by the ndp(8) command.  See the man
268743eee66SSUZUKI Shinsukepage for more details.
269743eee66SSUZUKI Shinsuke
2708f336835SJun-ichiro itojun HaginoDAD procedure may not be effective on certain network interfaces/drivers.
2718f336835SJun-ichiro itojun HaginoIf a network driver needs long initialization time (with wireless network
2728f336835SJun-ichiro itojun Haginointerfaces this situation is popular), and the driver mistakingly raises
2738f336835SJun-ichiro itojun HaginoIFF_RUNNING before the driver becomes ready, DAD code will try to transmit
2748f336835SJun-ichiro itojun HaginoDAD probes to not-really-ready network driver and the packet will not go out
2758f336835SJun-ichiro itojun Haginofrom the interface.  In such cases, network drivers should be corrected.
27680d21dc4SYoshinobu Inoue
2778f336835SJun-ichiro itojun HaginoSome of network drivers loop multicast packets back to themselves,
278743eee66SSUZUKI Shinsukeeven if instructed not to do so (especially in promiscuous mode).  In
279743eee66SSUZUKI Shinsukesuch cases DAD may fail, because the DAD engine sees inbound NS packet
280743eee66SSUZUKI Shinsuke(actually from the node itself) and considers it as a sign of
281743eee66SSUZUKI Shinsukeduplicate.  In this case, drivers should be corrected to honor
282743eee66SSUZUKI ShinsukeIFF_SIMPLEX behavior.  For example, you may need to check source MAC
283743eee66SSUZUKI Shinsukeaddress on an inbound packet, and reject it if it is from the node
284743eee66SSUZUKI Shinsukeitself.
28580d21dc4SYoshinobu Inoue
28680d21dc4SYoshinobu InoueNeighbor Discovery specification (RFC2461) does not talk about neighbor
28780d21dc4SYoshinobu Inouecache handling in the following cases:
28880d21dc4SYoshinobu Inoue(1) when there was no neighbor cache entry, node received unsolicited
28980d21dc4SYoshinobu Inoue    RS/NS/NA/redirect packet without link-layer address
29080d21dc4SYoshinobu Inoue(2) neighbor cache handling on medium without link-layer address
29180d21dc4SYoshinobu Inoue    (we need a neighbor cache entry for IsRouter bit)
29280d21dc4SYoshinobu InoueFor (1), we implemented workaround based on discussions on IETF ipngwg mailing
29380d21dc4SYoshinobu Inouelist.  For more details, see the comments in the source code and email
29480d21dc4SYoshinobu Inouethread started from (IPng 7155), dated Feb 6 1999.
29580d21dc4SYoshinobu Inoue
296743eee66SSUZUKI ShinsukeIPv6 on-link determination rule (RFC2461) is quite different from
297743eee66SSUZUKI Shinsukeassumptions in BSD IPv4 network code.  To implement the behavior in
298743eee66SSUZUKI ShinsukeRFC2461 section 6.3.6 (3), the kernel needs to know the default
2998f336835SJun-ichiro itojun Haginooutgoing interface.  To configure the default outgoing interface, use
300743eee66SSUZUKI Shinsukecommands like "ndp -I de0" as root.  Then the kernel will have a
301743eee66SSUZUKI Shinsuke"default" route to the interface with the cloning "C" bit being on.
302743eee66SSUZUKI ShinsukeThis default route will cause to make a neighbor cache entry for every
303743eee66SSUZUKI Shinsukedestination that does not match an explicit route entry.
304743eee66SSUZUKI Shinsuke
305743eee66SSUZUKI ShinsukeNote that we intentionally disable configuring the default interface
306743eee66SSUZUKI Shinsukeby default.  This is because we found it sometimes caused inconvenient
307743eee66SSUZUKI Shinsukesituation while it was rarely useful in practical usage.  For example,
308743eee66SSUZUKI Shinsukeconsider a destination that has both IPv4 and IPv6 addresses but is
309743eee66SSUZUKI Shinsukeonly reachable via IPv4.  Since our getaddrinfo(3) prefers IPv6 by
310743eee66SSUZUKI Shinsukedefault, an (TCP) application using the library with PF_UNSPEC first
311743eee66SSUZUKI Shinsuketries to connect to the IPv6 address.  If we turn on RFC 2461 6.3.6
312743eee66SSUZUKI Shinsuke(3), we have to wait for quite a long period before the first attempt
313743eee66SSUZUKI Shinsuketo make a connection fails.  If we turn it off, the first attempt will
314743eee66SSUZUKI Shinsukeimmediately fail with EHOSTUNREACH, and then the application can try
315743eee66SSUZUKI Shinsukethe next, reachable address.
316743eee66SSUZUKI Shinsuke
317743eee66SSUZUKI ShinsukeThe notion of the default interface is also disabled when the node is
318743eee66SSUZUKI Shinsukeacting as a router.  The reason is that routers tend to control all
319743eee66SSUZUKI Shinsukeroutes stored in the kernel and the default route automatically
320743eee66SSUZUKI Shinsukeinstalled would rather confuse the routers.  Note that the spec misuse
321743eee66SSUZUKI Shinsukethe word "host" and "node" in several places in Section 5.2 of RFC
322743eee66SSUZUKI Shinsuke2461.  We basically read the word "node" in this section as "host,"
323743eee66SSUZUKI Shinsukeand thus believe the implementation policy does not break the
324743eee66SSUZUKI Shinsukespecification.
32580d21dc4SYoshinobu Inoue
32680d21dc4SYoshinobu InoueTo avoid possible DoS attacks and infinite loops, KAME stack will accept
32780d21dc4SYoshinobu Inoueonly 10 options on ND packet.  Therefore, if you have 20 prefix options
32880d21dc4SYoshinobu Inoueattached to RA, only the first 10 prefixes will be recognized.
3291f320556SHajimu UMEMOTOIf this troubles you, please contact the KAME team and/or modify
33080d21dc4SYoshinobu Inouend6_maxndopt in sys/netinet6/nd6.c.  If there are high demands we may
3311f320556SHajimu UMEMOTOprovide a sysctl knob for the variable.
33280d21dc4SYoshinobu Inoue
3338f336835SJun-ichiro itojun HaginoProxy Neighbor Advertisement support is implemented in the kernel.
3348f336835SJun-ichiro itojun HaginoFor instance, you can configure it by using the following command:
3358f336835SJun-ichiro itojun Hagino	# ndp -s fe80::1234%ne0 0:1:2:3:4:5 proxy
3368f336835SJun-ichiro itojun Haginowhere ne0 is the interface which attaches to the same link as the
3378f336835SJun-ichiro itojun Haginoproxy target.
3388f336835SJun-ichiro itojun HaginoThere are certain limitations, though:
3398f336835SJun-ichiro itojun Hagino- It does not send unsolicited multicast NA on configuration.  This is MAY
3408f336835SJun-ichiro itojun Hagino  behavior in RFC2461.
3418f336835SJun-ichiro itojun Hagino- It does not add random delay before transmission of solicited NA.  This is
3428f336835SJun-ichiro itojun Hagino  SHOULD behavior in RFC2461.
3438f336835SJun-ichiro itojun Hagino- We cannot configure proxy NDP for off-link address.  The target address for
3448f336835SJun-ichiro itojun Hagino  proxying must be link-local address, or must be in prefixes configured to
3458f336835SJun-ichiro itojun Hagino  node which does proxy NDP.
3468f336835SJun-ichiro itojun Hagino- RFC2461 is unclear about if it is legal for a host to perform proxy ND.
3478f336835SJun-ichiro itojun Hagino  We do not prohibit hosts from doing proxy ND, but there will be very limited
3488f336835SJun-ichiro itojun Hagino  use in it.
3498f336835SJun-ichiro itojun Hagino
350743eee66SSUZUKI ShinsukeStarting mid March 2000, we support Neighbor Unreachability Detection
351743eee66SSUZUKI Shinsuke(NUD) on p2p interfaces, including tunnel interfaces (gif).  NUD is
352743eee66SSUZUKI Shinsuketurned on by default.  Before March 2000 the KAME stack did not
353743eee66SSUZUKI Shinsukeperform NUD on p2p interfaces.  If the change raises any
354743eee66SSUZUKI Shinsukeinteroperability issues, you can turn off/on NUD by per-interface
355743eee66SSUZUKI Shinsukebasis.  Use "ndp -i interface -nud" to turn it off.  Consult ndp(8)
356743eee66SSUZUKI Shinsukefor details.
3578f336835SJun-ichiro itojun Hagino
3588f336835SJun-ichiro itojun HaginoRFC2461 specifies upper-layer reachability confirmation hint.  Whenever
3598f336835SJun-ichiro itojun Haginoupper-layer reachability confirmation hint comes, ND process can use it
3608f336835SJun-ichiro itojun Haginoto optimize neighbor discovery process - ND process can omit real ND exchange
3618f336835SJun-ichiro itojun Haginoand keep the neighbor cache state in REACHABLE.
3628f336835SJun-ichiro itojun HaginoWe currently have two sources for hints: (1) setsockopt(IPV6_REACHCONF)
363743eee66SSUZUKI Shinsukedefined by the RFC3542 API, and (2) hints from tcp(6)_input.
364743eee66SSUZUKI Shinsuke
365743eee66SSUZUKI ShinsukeIt is questionable if they are really trustworthy.  For example, a
366743eee66SSUZUKI Shinsukerogue userland program can use IPV6_REACHCONF to confuse the ND
367743eee66SSUZUKI Shinsukeprocess.  Neighbor cache is a system-wide information pool, and it is
368743eee66SSUZUKI Shinsukebad to allow a single process to affect others.  Also, tcp(6)_input
369743eee66SSUZUKI Shinsukecan be hosed by hijack attempts.  It is wrong to allow hijack attempts
370743eee66SSUZUKI Shinsuketo affect the ND process.
371743eee66SSUZUKI Shinsuke
372743eee66SSUZUKI ShinsukeStarting June 2000, the ND code has a protection mechanism against
373743eee66SSUZUKI Shinsukeincorrect upper-layer reachability confirmation.  The ND code counts
374743eee66SSUZUKI Shinsukesubsequent upper-layer hints.  If the number of hints reaches the
375743eee66SSUZUKI Shinsukemaximum, the ND code will ignore further upper-layer hints and run
376743eee66SSUZUKI Shinsukereal ND process to confirm reachability to the peer.  sysctl
377743eee66SSUZUKI Shinsukenet.inet6.icmp6.nd6_maxnudhint defines the maximum # of subsequent
3788f336835SJun-ichiro itojun Haginoupper-layer hints to be accepted.
3798f336835SJun-ichiro itojun Hagino(from April 2000 to June 2000, we rejected setsockopt(IPV6_REACHCONF) from
380743eee66SSUZUKI Shinsukenon-root process - after a local discussion, it looks that hints are not
3818f336835SJun-ichiro itojun Haginothat trustworthy even if they are from privileged processes)
3828f336835SJun-ichiro itojun Hagino
38333841545SHajimu UMEMOTOIf inbound ND packets carry invalid values, the KAME kernel will
38433841545SHajimu UMEMOTOdrop these packet and increment statistics variable.  See
38533841545SHajimu UMEMOTO"netstat -sn", icmp6 section.  For detailed debugging session, you can
38633841545SHajimu UMEMOTOturn on syslog output from the kernel on errors, by turning on sysctl MIB
38733841545SHajimu UMEMOTOnet.inet6.icmp6.nd6_debug.  nd6_debug can be turned on at bootstrap
38833841545SHajimu UMEMOTOtime, by defining ND6_DEBUG kernel compilation option (so you can
38933841545SHajimu UMEMOTOdebug behavior during bootstrap).  nd6_debug configuration should
3901f320556SHajimu UMEMOTOonly be used for test/debug purposes - for a production environment,
39133841545SHajimu UMEMOTOnd6_debug must be set to 0.  If you leave it to 1, malicious parties
39233841545SHajimu UMEMOTOcan inject broken packet and fill up /var/log partition.
39333841545SHajimu UMEMOTO
39433841545SHajimu UMEMOTO1.3 Scope Zone Index
39580d21dc4SYoshinobu Inoue
3968f336835SJun-ichiro itojun HaginoIPv6 uses scoped addresses.  It is therefore very important to
39733841545SHajimu UMEMOTOspecify the scope zone index (link index for a link-local address, or
39833841545SHajimu UMEMOTOsite index for a site-local address) with an IPv6 address.  Without a
39933841545SHajimu UMEMOTOzone index, a scoped IPv6 address is ambiguous to the kernel, and
4001f320556SHajimu UMEMOTOthe kernel would not be able to determine the outbound zone for a
40133841545SHajimu UMEMOTOpacket to the scoped address.  KAME code tries to address the issue in
40233841545SHajimu UMEMOTOseveral ways.
40380d21dc4SYoshinobu Inoue
4041f320556SHajimu UMEMOTOThe entire architecture of scoped addresses is documented in RFC4007.
4051f320556SHajimu UMEMOTOOne non-trivial point of the architecture is that the link scope is
4061f320556SHajimu UMEMOTO(theoretically) larger than the interface scope.  That is, two
4071f320556SHajimu UMEMOTOdifferent interfaces can belong to a same single link.  However, in a
4081f320556SHajimu UMEMOTOnormal operation, we can assume that there is 1-to-1 relationship
4091f320556SHajimu UMEMOTObetween links and interfaces.  In other words, we can usually put
4101f320556SHajimu UMEMOTOlinks and interfaces in the same scope type.  The current KAME
4111f320556SHajimu UMEMOTOimplementation assumes the 1-to-1 relationship.  In particular, we use
4121f320556SHajimu UMEMOTOinterface names such as "ne1" as unique link identifiers.  This would
4131f320556SHajimu UMEMOTObe much more human-readable and intuitive than numeric identifiers,
4141f320556SHajimu UMEMOTObut please keep your mind on the theoretical difference between links
4151f320556SHajimu UMEMOTOand interfaces.
41633841545SHajimu UMEMOTO
41733841545SHajimu UMEMOTOSite-local addresses are very vaguely defined in the specs, and both
41833841545SHajimu UMEMOTOthe specification and the KAME code need tons of improvements to
41933841545SHajimu UMEMOTOenable its actual use.  For example, it is still very unclear how we
42033841545SHajimu UMEMOTOdefine a site, or how we resolve host names in a site.  There is work
42133841545SHajimu UMEMOTOunderway to define behavior of routers at site border, but, we have
4221f320556SHajimu UMEMOTOalmost no code for site boundary node support (neither forwarding nor
42333841545SHajimu UMEMOTOrouting) and we bet almost noone has.  We recommend, at this moment,
42433841545SHajimu UMEMOTOyou to use global addresses for experiments - there are way too many
42533841545SHajimu UMEMOTOpitfalls if you use site-local addresses.
42680d21dc4SYoshinobu Inoue
4278f336835SJun-ichiro itojun Hagino1.3.1 Kernel internal
4288f336835SJun-ichiro itojun Hagino
42933841545SHajimu UMEMOTOIn the kernel, the link index for a link-local scope address is
4308f336835SJun-ichiro itojun Haginoembedded into the 2nd 16bit-word (the 3rd and 4th bytes) in the IPv6
4318f336835SJun-ichiro itojun Haginoaddress.
43280d21dc4SYoshinobu InoueFor example, you may see something like:
43380d21dc4SYoshinobu Inoue	fe80:1::200:f8ff:fe01:6317
43433841545SHajimu UMEMOTOin the routing table and the interface address structure (struct
43533841545SHajimu UMEMOTOin6_ifaddr).  The address above is a link-local unicast address which
43633841545SHajimu UMEMOTObelongs to a network link whose link identifier is 1 (note that it
43733841545SHajimu UMEMOTOeqauls to the interface index by the assumption of our
43833841545SHajimu UMEMOTOimplementation).  The embedded index enables us to identify IPv6
43933841545SHajimu UMEMOTOlink-local addresses over multiple links effectively and with only a
44080d21dc4SYoshinobu Inouelittle code change.
4418f336835SJun-ichiro itojun Hagino
4421f320556SHajimu UMEMOTOThe use of the internal format must be limited inside the kernel.  In
4431f320556SHajimu UMEMOTOparticular, addresses sent by an application should not contain the
4441f320556SHajimu UMEMOTOembedded index (except via some very special APIs such as routing
4451f320556SHajimu UMEMOTOsockets).  Instead, the index should be specified in the sin6_scope_id
4461f320556SHajimu UMEMOTOfield of a sockaddr_in6 structure.  Obviously, packets sent to or
4471f320556SHajimu UMEMOTOreceived from must not contain the embedded index either, since the
4481f320556SHajimu UMEMOTOindex is meaningful only within the sending/receiving node.
4491f320556SHajimu UMEMOTO
4501f320556SHajimu UMEMOTOIn order to deal with the differences, several kernel routines are
4511f320556SHajimu UMEMOTOprovided.  These are available by including <netinet6/scope_var.h>.
4521f320556SHajimu UMEMOTOTypically, the following functions will be most generally used:
4531f320556SHajimu UMEMOTO
4541f320556SHajimu UMEMOTO- int sa6_embedscope(struct sockaddr_in6 *sa6, int defaultok);
4551f320556SHajimu UMEMOTO  Embed sa6->sin6_scope_id into sa6->sin6_addr.  If sin6_scope_id is
4561f320556SHajimu UMEMOTO  0, defaultok is non-0, and the default zone ID (see RFC4007) is
4571f320556SHajimu UMEMOTO  configured, the default ID will be used instead of the value of the
4581f320556SHajimu UMEMOTO  sin6_scope_id field.  On success, sa6->sin6_scope_id will be reset
4591f320556SHajimu UMEMOTO  to 0.
4601f320556SHajimu UMEMOTO
4611f320556SHajimu UMEMOTO  This function returns 0 on success, or a non-0 error code otherwise.
4621f320556SHajimu UMEMOTO
4631f320556SHajimu UMEMOTO- int sa6_recoverscope(struct sockaddr_in6 *sa6);
4641f320556SHajimu UMEMOTO  Extract embedded zone ID in sa6->sin6_addr and set
4651f320556SHajimu UMEMOTO  sa6->sin6_scope_id to that ID.  The embedded ID will be cleared with
4661f320556SHajimu UMEMOTO  0.
4671f320556SHajimu UMEMOTO
4681f320556SHajimu UMEMOTO  This function returns 0 on success, or a non-0 error code otherwise.
4691f320556SHajimu UMEMOTO
4701f320556SHajimu UMEMOTO- int in6_clearscope(struct in6_addr *in6);
4711f320556SHajimu UMEMOTO  Reset the embedded zone ID in 'in6' to 0.  This function never fails, and
4721f320556SHajimu UMEMOTO  returns 0 if the original address is intact or non 0 if the address is
4731f320556SHajimu UMEMOTO  modified.  The return value doesn't matter in most cases; currently, the
4741f320556SHajimu UMEMOTO  only point where we care about the return value is ip6_input() for checking
4751f320556SHajimu UMEMOTO  whether the source or destination addresses of the incoming packet is in
4761f320556SHajimu UMEMOTO  the embedded form.
4771f320556SHajimu UMEMOTO
4781f320556SHajimu UMEMOTO- int in6_setscope(struct in6_addr *in6, struct ifnet *ifp,
4791f320556SHajimu UMEMOTO                   u_int32_t *zoneidp);
4801f320556SHajimu UMEMOTO  Embed zone ID determined by the address scope type for 'in6' and the
4811f320556SHajimu UMEMOTO  interface 'ifp' into 'in6'.  If zoneidp is non NULL, *zoneidp will
4821f320556SHajimu UMEMOTO  also have the zone ID.
4831f320556SHajimu UMEMOTO
4841f320556SHajimu UMEMOTO  This function returns 0 on success, or a non-0 error code otherwise.
4851f320556SHajimu UMEMOTO
4861f320556SHajimu UMEMOTOThe typical usage of these functions is as follows:
4871f320556SHajimu UMEMOTO
4881f320556SHajimu UMEMOTOsa6_embedscope() will be used at the socket or transport layer to
4891f320556SHajimu UMEMOTOconvert a sockaddr_in6 structure passed by an application into the
4901f320556SHajimu UMEMOTOkernel-internal form.  In this usage, the second argument is often the
4911f320556SHajimu UMEMOTO'ip6_use_defzone' global variable.
4921f320556SHajimu UMEMOTO
4931f320556SHajimu UMEMOTOsa6_recoverscope() will also be used at the socket or transport layer
4941f320556SHajimu UMEMOTOto convert an in6_addr structure with the embedded zone ID into a
4951f320556SHajimu UMEMOTOsockaddr_in6 structure with the corresponding ID in the sin6_scope_id
4961f320556SHajimu UMEMOTOfield (and without the embedded ID in sin6_addr).
4971f320556SHajimu UMEMOTO
4981f320556SHajimu UMEMOTOin6_clearscope() will be used just before sending a packet to the wire
4991f320556SHajimu UMEMOTOto remove the embedded ID.  In general, this must be done at the last
5001f320556SHajimu UMEMOTOstage of an output path, since otherwise the address would lose the ID
5011f320556SHajimu UMEMOTOand could be ambiguous with regard to scope.
5021f320556SHajimu UMEMOTO
5031f320556SHajimu UMEMOTOin6_setscope() will be used when the kernel receives a packet from the
5041f320556SHajimu UMEMOTOwire to construct the kernel internal form for each address field in
5051f320556SHajimu UMEMOTOthe packet (typical examples are the source and destination addresses
5061f320556SHajimu UMEMOTOof the packet).  In the typical usage, the third argument 'zoneidp'
5071f320556SHajimu UMEMOTOwill be NULL.  A non-NULL value will be used when the validity of the
5081f320556SHajimu UMEMOTOzone ID must be checked, e.g., when forwarding a packet to another
5091f320556SHajimu UMEMOTOlink (see ip6_forward() for this usage).
5101f320556SHajimu UMEMOTO
5111f320556SHajimu UMEMOTOAn application, when sending a packet, is basically assumed to specify
5121f320556SHajimu UMEMOTOthe appropriate scope zone of the destination address by the
5131f320556SHajimu UMEMOTOsin6_scope_id field (this might be done transparently from the
5141f320556SHajimu UMEMOTOapplication with getaddrinfo() and the extended textual format - see
5151f320556SHajimu UMEMOTObelow), or at least the default scope zone(s) must be configured as a
5161f320556SHajimu UMEMOTOlast resort.  In some cases, however, an application could specify an
5171f320556SHajimu UMEMOTOambiguous address with regard to scope, expecting it is disambiguated
5181f320556SHajimu UMEMOTOin the kernel by some other means.  A typical usage is to specify the
5191f320556SHajimu UMEMOTOoutgoing interface through another API, which can disambiguate the
5201f320556SHajimu UMEMOTOunspecified scope zone.  Such a usage is not recommended, but the
5211f320556SHajimu UMEMOTOkernel implements some trick to deal with even this case.
5221f320556SHajimu UMEMOTO
5231f320556SHajimu UMEMOTOA rough sketch of the trick can be summarized as the following
5241f320556SHajimu UMEMOTOsequence.
5251f320556SHajimu UMEMOTO
5261f320556SHajimu UMEMOTO   sa6_embedscope(dst, ip6_use_defzone);
5271f320556SHajimu UMEMOTO   in6_selectsrc(dst, ..., &ifp, ...);
5281f320556SHajimu UMEMOTO   in6_setscope(&dst->sin6_addr, ifp, NULL);
5291f320556SHajimu UMEMOTO
5301f320556SHajimu UMEMOTOsa6_embedscope() first tries to convert sin6_scope_id (or the default
5311f320556SHajimu UMEMOTOzone ID) into the kernel-internal form.  This can fail with an
5321f320556SHajimu UMEMOTOambiguous destination, but it still tries to get the outgoing
5331f320556SHajimu UMEMOTOinterface (ifp) in the attempt of determining the source address of
5341f320556SHajimu UMEMOTOthe outgoing packet using in6_selectsrc().  If the interface is
5351f320556SHajimu UMEMOTOdetected, and the scope zone was originally ambiguous, in6_setscope()
5361f320556SHajimu UMEMOTOcan finally determine the appropriate ID with the address itself and
5371f320556SHajimu UMEMOTOthe interface, and construct the kernel-internal form.  See, for
5381f320556SHajimu UMEMOTOexample, comments in udp6_output() for more concrete example.
5391f320556SHajimu UMEMOTO
5401f320556SHajimu UMEMOTOIn any case, kernel routines except ones in netinet6/scope6.c MUST NOT
5411f320556SHajimu UMEMOTOdirectly refer to the embedded form.  They MUST use the above
5421f320556SHajimu UMEMOTOinterface functions.  In particular, kernel routines MUST NOT have the
5431f320556SHajimu UMEMOTOfollowing code fragment:
5441f320556SHajimu UMEMOTO
5451f320556SHajimu UMEMOTO	/* This is a bad practice.  Don't do this */
5461f320556SHajimu UMEMOTO	if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
5471f320556SHajimu UMEMOTO		sin6->sin6_addr.s6_addr16[1] = htons(ifp->if_index);
5481f320556SHajimu UMEMOTO
5491f320556SHajimu UMEMOTOThis is bad for several reasons.  First, address ambiguity is not
5501f320556SHajimu UMEMOTOspecific to link-local addresses (any non-global multicast addresses
5511f320556SHajimu UMEMOTOare inherently ambiguous, and this is particularly true for
5521f320556SHajimu UMEMOTOinterface-local addresses).  Secondly, this is vulnerable to future
5531f320556SHajimu UMEMOTOchanges of the embedded form (the embedded position may change, or the
5541f320556SHajimu UMEMOTOzone ID may not actually be the interface index).  Only scope6.c
5551f320556SHajimu UMEMOTOroutines should know the details.
5561f320556SHajimu UMEMOTO
5571f320556SHajimu UMEMOTOThe above code fragment should thus actually be as follows:
5581f320556SHajimu UMEMOTO
5591f320556SHajimu UMEMOTO	/* This is correct. */
5601f320556SHajimu UMEMOTO	in6_setscope(&sin6->sin6_addr, ifp, NULL);
5611f320556SHajimu UMEMOTO	(and catch errors if possible and necessary)
5621f320556SHajimu UMEMOTO
5638f336835SJun-ichiro itojun Hagino1.3.2 Interaction with API
5648f336835SJun-ichiro itojun Hagino
56533841545SHajimu UMEMOTOThere are several candidates of API to deal with scoped addresses
56633841545SHajimu UMEMOTOwithout ambiguity.
5678f336835SJun-ichiro itojun Hagino
56833841545SHajimu UMEMOTOThe IPV6_PKTINFO ancillary data type or socket option defined in the
569f88fe57eSHajimu UMEMOTOadvanced API (RFC2292 or RFC3542) can specify
57033841545SHajimu UMEMOTOthe outgoing interface of a packet.  Similarly, the IPV6_PKTINFO or
57133841545SHajimu UMEMOTOIPV6_RECVPKTINFO socket options tell kernel to pass the incoming
57233841545SHajimu UMEMOTOinterface to user applications.
57380d21dc4SYoshinobu Inoue
57433841545SHajimu UMEMOTOThese options are enough to disambiguate scoped addresses of an
57533841545SHajimu UMEMOTOincoming packet, because we can uniquely identify the corresponding
57633841545SHajimu UMEMOTOzone of the scoped address(es) by the incoming interface.  However,
57733841545SHajimu UMEMOTOthey are too strong for outgoing packets.  For example, consider a
57833841545SHajimu UMEMOTOmulti-sited node and suppose that more than one interface of the node
57933841545SHajimu UMEMOTObelongs to a same site.  When we want to send a packet to the site,
58033841545SHajimu UMEMOTOwe can only specify one of the interfaces for the outgoing packet with
58133841545SHajimu UMEMOTOthese options; we cannot just say "send the packet to (one of the
58233841545SHajimu UMEMOTOinterfaces of) the site."
58333841545SHajimu UMEMOTO
58433841545SHajimu UMEMOTOAnother kind of candidates is to use the sin6_scope_id member in the
585f88fe57eSHajimu UMEMOTOsockaddr_in6 structure, defined in RFC2553.  The KAME kernel
586f88fe57eSHajimu UMEMOTOinterprets the sin6_scope_id field properly in order to disambiguate scoped
58733841545SHajimu UMEMOTOaddresses.  For example, if an application passes a sockaddr_in6
58833841545SHajimu UMEMOTOstructure that has a non-zero sin6_scope_id value to the sendto(2)
58933841545SHajimu UMEMOTOsystem call, the kernel should send the packet to the appropriate zone
59033841545SHajimu UMEMOTOaccording to the sin6_scope_id field.  Similarly, when the source or
59133841545SHajimu UMEMOTOthe destination address of an incoming packet is a scoped one, the
59233841545SHajimu UMEMOTOkernel should detect the correct zone identifier based on the address
59333841545SHajimu UMEMOTOand the receiving interface, fill the identifier in the sin6_scope_id
59433841545SHajimu UMEMOTOfield of a sockaddr_in6 structure, and then pass the packet to an
59533841545SHajimu UMEMOTOapplication via the recvfrom(2) system call, etc.
59633841545SHajimu UMEMOTO
59733841545SHajimu UMEMOTOHowever, the semantics of the sin6_scope_id is still vague and on the
59833841545SHajimu UMEMOTOway to standardization.  Additionally, not so many operating systems
59933841545SHajimu UMEMOTOsupport the behavior above at this moment.
60033841545SHajimu UMEMOTO
60133841545SHajimu UMEMOTOIn summary,
60233841545SHajimu UMEMOTO- If your target system is limited to KAME based ones (i.e. BSD
60333841545SHajimu UMEMOTO  variants and KAME snaps), use the sin6_scope_id field assuming the
60433841545SHajimu UMEMOTO  kernel behavior described above.
60533841545SHajimu UMEMOTO- Otherwise, (i.e. if your program should be portable on other systems
60633841545SHajimu UMEMOTO  than BSDs)
60733841545SHajimu UMEMOTO  + Use the advanced API to disambiguate scoped addresses of incoming
60833841545SHajimu UMEMOTO    packets.
60933841545SHajimu UMEMOTO  + To disambiguate scoped addresses of outgoing packets,
61033841545SHajimu UMEMOTO    * if it is okay to just specify the outgoing interface, use the
61133841545SHajimu UMEMOTO      advanced API.  This would be the case, for example, when you
61233841545SHajimu UMEMOTO      should only consider link-local addresses and your system
61333841545SHajimu UMEMOTO      assumes 1-to-1 relationship between links and interfaces.
61433841545SHajimu UMEMOTO    * otherwise, sorry but you lose.  Please rush the IETF IPv6
61533841545SHajimu UMEMOTO      community into standardizing the semantics of the sin6_scope_id
61633841545SHajimu UMEMOTO      field.
61733841545SHajimu UMEMOTO
61833841545SHajimu UMEMOTORouting daemons and configuration programs, like route6d and ifconfig,
61933841545SHajimu UMEMOTOwill need to manipulate the "embedded" zone index.  These programs use
62033841545SHajimu UMEMOTOrouting sockets and ioctls (like SIOCGIFADDR_IN6) and the kernel API
62133841545SHajimu UMEMOTOwill return IPv6 addresses with the 2nd 16bit-word filled in.  The
62233841545SHajimu UMEMOTOAPIs are for manipulating kernel internal structure.  Programs that
62333841545SHajimu UMEMOTOuse these APIs have to be prepared about differences in kernels
62433841545SHajimu UMEMOTOanyway.
62533841545SHajimu UMEMOTO
62633841545SHajimu UMEMOTOgetaddrinfo(3) and getnameinfo(3) support an extended numeric IPv6
6271f320556SHajimu UMEMOTOsyntax, as documented in RFC4007.  You can specify the outgoing link,
6281f320556SHajimu UMEMOTOby using the name of the outgoing interface as the link, like
6291f320556SHajimu UMEMOTO"fe80::1%ne0" (again, note that we assume there is 1-to-1 relationship
6301f320556SHajimu UMEMOTObetween links and interfaces.)  This way you will be able to specify a
6311f320556SHajimu UMEMOTOlink-local scoped address without much trouble.
63233841545SHajimu UMEMOTO
63333841545SHajimu UMEMOTOOther APIs like inet_pton(3) and inet_ntop(3) are inherently
63433841545SHajimu UMEMOTOunfriendly with scoped addresses, since they are unable to annotate
63533841545SHajimu UMEMOTOaddresses with zone identifier.
6368f336835SJun-ichiro itojun Hagino
6378f336835SJun-ichiro itojun Hagino1.3.3 Interaction with users (command line)
6388f336835SJun-ichiro itojun Hagino
63933841545SHajimu UMEMOTOMost of user applications now support the extended numeric IPv6
64033841545SHajimu UMEMOTOsyntax.  In this case, you can specify outgoing link, by using the name
64133841545SHajimu UMEMOTOof the outgoing interface like "fe80::1%ne0" (sorry for the duplicated
64233841545SHajimu UMEMOTOnotice, but please recall again that we assume 1-to-1 relationship
64333841545SHajimu UMEMOTObetween links and interfaces).  This is even the case for some
64433841545SHajimu UMEMOTOmanagement tools such as route(8) or ndp(8).  For example, to install
64533841545SHajimu UMEMOTOthe IPv6 default route by hand, you can type like
6468f336835SJun-ichiro itojun Hagino	# route add -inet6 default fe80::9876:5432:1234:abcd%ne0
6478f336835SJun-ichiro itojun Hagino(Although we suggest you to run dynamic routing instead of static
6488f336835SJun-ichiro itojun Haginoroutes, in order to avoid configuration mistakes.)
6498f336835SJun-ichiro itojun Hagino
6508f336835SJun-ichiro itojun HaginoSome applications have command line options for specifying an
6518f336835SJun-ichiro itojun Haginoappropriate zone of a scoped address (like "ping6 -I ne0 ff02::1" to
6528f336835SJun-ichiro itojun Haginospecify the outgoing interface).  However, you can't always expect such
653f88fe57eSHajimu UMEMOTOoptions.  Additionally, specifying the outgoing "interface" is in
654f88fe57eSHajimu UMEMOTOtheory an overspecification as a way to specify the outgoing "link"
655f88fe57eSHajimu UMEMOTO(see above).  Thus, we recommend you to use the extended format
656f88fe57eSHajimu UMEMOTOdescribed above.  This should apply to the case where the outgoing
657f88fe57eSHajimu UMEMOTOinterface is specified.
6588f336835SJun-ichiro itojun Hagino
6598f336835SJun-ichiro itojun HaginoIn any case, when you specify a scoped address to the command line,
6608f336835SJun-ichiro itojun HaginoNEVER write the embedded form (such as ff02:1::1 or fe80:2::fedc),
6618f336835SJun-ichiro itojun Haginowhich should only be used inside the kernel (see Section 1.3.1), and
6628f336835SJun-ichiro itojun Haginois not supposed to work.
66380d21dc4SYoshinobu Inoue
66480d21dc4SYoshinobu Inoue1.4 Plug and Play
66580d21dc4SYoshinobu Inoue
66680d21dc4SYoshinobu InoueThe KAME kit implements most of the IPv6 stateless address
66780d21dc4SYoshinobu Inoueautoconfiguration in the kernel.
66880d21dc4SYoshinobu InoueNeighbor Discovery functions are implemented in the kernel as a whole.
66980d21dc4SYoshinobu InoueRouter Advertisement (RA) input for hosts is implemented in the
67080d21dc4SYoshinobu Inouekernel.  Router Solicitation (RS) output for endhosts, RS input
67180d21dc4SYoshinobu Inouefor routers, and RA output for routers are implemented in the
67280d21dc4SYoshinobu Inoueuserland.
67380d21dc4SYoshinobu Inoue
67480d21dc4SYoshinobu Inoue1.4.1 Assignment of link-local, and special addresses
67580d21dc4SYoshinobu Inoue
6768f336835SJun-ichiro itojun HaginoIPv6 link-local address is generated from IEEE802 address (ethernet MAC
67780d21dc4SYoshinobu Inoueaddress).  Each of interface is assigned an IPv6 link-local address
67880d21dc4SYoshinobu Inoueautomatically, when the interface becomes up (IFF_UP).  Also, direct route
67980d21dc4SYoshinobu Inouefor the link-local address is added to routing table.
68080d21dc4SYoshinobu Inoue
68180d21dc4SYoshinobu InoueHere is an output of netstat command:
68280d21dc4SYoshinobu Inoue
68380d21dc4SYoshinobu InoueInternet6:
68480d21dc4SYoshinobu InoueDestination                   Gateway                   Flags      Netif Expire
6858f336835SJun-ichiro itojun Haginofe80::%ed0/64                 link#1                    UC           ed0
6868f336835SJun-ichiro itojun Haginofe80::%ep0/64                 link#2                    UC           ep0
68780d21dc4SYoshinobu Inoue
68880d21dc4SYoshinobu InoueInterfaces that has no IEEE802 address (pseudo interfaces like tunnel
68980d21dc4SYoshinobu Inoueinterfaces, or ppp interfaces) will borrow IEEE802 address from other
69080d21dc4SYoshinobu Inoueinterfaces, such as ethernet interfaces, whenever possible.
69180d21dc4SYoshinobu InoueIf there is no IEEE802 hardware attached, last-resort pseudorandom value,
69280d21dc4SYoshinobu Inouewhich is from MD5(hostname), will be used as source of link-local address.
69380d21dc4SYoshinobu InoueIf it is not suitable for your usage, you will need to configure the
69480d21dc4SYoshinobu Inouelink-local address manually.
69580d21dc4SYoshinobu Inoue
69680d21dc4SYoshinobu InoueIf an interface is not capable of handling IPv6 (such as lack of multicast
69780d21dc4SYoshinobu Inouesupport), link-local address will not be assigned to that interface.
69880d21dc4SYoshinobu InoueSee section 2 for details.
69980d21dc4SYoshinobu Inoue
70080d21dc4SYoshinobu InoueEach interface joins the solicited multicast address and the
70180d21dc4SYoshinobu Inouelink-local all-nodes multicast addresses (e.g.  fe80::1:ff01:6317
70280d21dc4SYoshinobu Inoueand ff02::1, respectively, on the link the interface is attached).
70380d21dc4SYoshinobu InoueIn addition to a link-local address, the loopback address (::1) will be
70480d21dc4SYoshinobu Inoueassigned to the loopback interface.  Also, ::1/128 and ff01::/32 are
70580d21dc4SYoshinobu Inoueautomatically added to routing table, and loopback interface joins
70680d21dc4SYoshinobu Inouenode-local multicast group ff01::1.
70780d21dc4SYoshinobu Inoue
70880d21dc4SYoshinobu Inoue1.4.2 Stateless address autoconfiguration on hosts
70980d21dc4SYoshinobu Inoue
71080d21dc4SYoshinobu InoueIn IPv6 specification, nodes are separated into two categories:
71180d21dc4SYoshinobu Inouerouters and hosts.  Routers forward packets addressed to others, hosts does
71280d21dc4SYoshinobu Inouenot forward the packets.  net.inet6.ip6.forwarding defines whether this
7138f336835SJun-ichiro itojun Haginonode is a router or a host (router if it is 1, host if it is 0).
7148f336835SJun-ichiro itojun Hagino
7158f336835SJun-ichiro itojun HaginoIt is NOT recommended to change net.inet6.ip6.forwarding while the node
7168f336835SJun-ichiro itojun Haginois in operation.  IPv6 specification defines behavior for "host" and "router"
7178f336835SJun-ichiro itojun Haginoquite differently, and switching from one to another can cause serious
7188f336835SJun-ichiro itojun Haginotroubles.  It is recommended to configure the variable at bootstrap time only.
7198f336835SJun-ichiro itojun Hagino
7208f336835SJun-ichiro itojun HaginoThe first step in stateless address configuration is Duplicated Address
7218f336835SJun-ichiro itojun HaginoDetection (DAD).  See 1.2 for more detail on DAD.
72280d21dc4SYoshinobu Inoue
72380d21dc4SYoshinobu InoueWhen a host hears Router Advertisement from the router, a host may
724743eee66SSUZUKI Shinsukeautoconfigure itself by stateless address autoconfiguration.  This
725743eee66SSUZUKI Shinsukebehavior can be controlled by the net.inet6.ip6.accept_rtadv sysctl
726743eee66SSUZUKI Shinsukevariable and a per-interface flag managed in the kernel.  The latter,
727743eee66SSUZUKI Shinsukewhich we call "if_accept_rtadv" here, can be changed by the ndp(8)
728743eee66SSUZUKI Shinsukecommand (see the manpage for more details).  When the sysctl variable
729743eee66SSUZUKI Shinsukeis set to 1, and the flag is set, the host autoconfigures itself.  By
730743eee66SSUZUKI Shinsukeautoconfiguration, network address prefixes for the receiving
731743eee66SSUZUKI Shinsukeinterface (usually global address prefix) are added.  The default
732743eee66SSUZUKI Shinsukeroute is also configured.
7338f336835SJun-ichiro itojun Hagino
7348f336835SJun-ichiro itojun HaginoRouters periodically generate Router Advertisement packets.  To
7358f336835SJun-ichiro itojun Haginorequest an adjacent router to generate RA packet, a host can transmit
7368f336835SJun-ichiro itojun HaginoRouter Solicitation.  To generate an RS packet at any time, use the
7378f336835SJun-ichiro itojun Hagino"rtsol" command.  The "rtsold" daemon is also available. "rtsold"
738743eee66SSUZUKI Shinsukegenerates Router Solicitation whenever necessary, and it works greatly
7398f336835SJun-ichiro itojun Haginofor nomadic usage (notebooks/laptops).  If one wishes to ignore Router
7408f336835SJun-ichiro itojun HaginoAdvertisements, use sysctl to set net.inet6.ip6.accept_rtadv to 0.
741743eee66SSUZUKI ShinsukeAdditionally, ndp(8) command can be used to control the behavior
742743eee66SSUZUKI Shinsukeper-interface basis.
74380d21dc4SYoshinobu Inoue
74480d21dc4SYoshinobu InoueTo generate Router Advertisement from a router, use the "rtadvd" daemon.
74580d21dc4SYoshinobu Inoue
7468f336835SJun-ichiro itojun HaginoNote that the IPv6 specification assumes the following items and that
7478f336835SJun-ichiro itojun Haginononconforming cases are left unspecified:
74880d21dc4SYoshinobu Inoue- Only hosts will listen to router advertisements
749743eee66SSUZUKI Shinsuke- Hosts have a single network interface (except loopback)
7508f336835SJun-ichiro itojun HaginoThis is therefore unwise to enable net.inet6.ip6.accept_rtadv on routers,
751743eee66SSUZUKI Shinsukeor multi-interface hosts.  A misconfigured node can behave strange
75280d21dc4SYoshinobu Inoue(KAME code allows nonconforming configuration, for those who would like
75380d21dc4SYoshinobu Inoueto do some experiments).
75480d21dc4SYoshinobu Inoue
75580d21dc4SYoshinobu InoueTo summarize the sysctl knob:
75680d21dc4SYoshinobu Inoue	accept_rtadv	forwarding	role of the node
75780d21dc4SYoshinobu Inoue	---		---		---
75880d21dc4SYoshinobu Inoue	0		0		host (to be manually configured)
75980d21dc4SYoshinobu Inoue	0		1		router
76080d21dc4SYoshinobu Inoue	1		0		autoconfigured host
761743eee66SSUZUKI Shinsuke					(spec assumes that hosts have a single
762743eee66SSUZUKI Shinsuke					interface only, autoconfigred hosts
763743eee66SSUZUKI Shinsuke					with multiple interfaces are
764743eee66SSUZUKI Shinsuke					out-of-scope)
76580d21dc4SYoshinobu Inoue	1		1		invalid, or experimental
76680d21dc4SYoshinobu Inoue					(out-of-scope of spec)
76780d21dc4SYoshinobu Inoue
768743eee66SSUZUKI ShinsukeThe if_accept_rtadv flag is referred only when accept_rtadv is 1 (the
769743eee66SSUZUKI Shinsukelatter two cases).  The flag does not have any effects when the sysctl
770743eee66SSUZUKI Shinsukevariable is 0.
771743eee66SSUZUKI Shinsuke
77280d21dc4SYoshinobu InoueSee 1.2 in the document for relationship between DAD and autoconfiguration.
77380d21dc4SYoshinobu Inoue
7748f336835SJun-ichiro itojun Hagino1.4.3 DHCPv6
77580d21dc4SYoshinobu Inoue
77680d21dc4SYoshinobu InoueWe supply a tiny DHCPv6 server/client in kame/dhcp6. However, the
7778f336835SJun-ichiro itojun Haginoimplementation is premature (for example, this does NOT implement
7788f336835SJun-ichiro itojun Haginoaddress lease/release), and it is not in default compilation tree on
7798f336835SJun-ichiro itojun Haginosome platforms. If you want to do some experiment, compile it on your
7808f336835SJun-ichiro itojun Haginoown.
78180d21dc4SYoshinobu Inoue
78280d21dc4SYoshinobu InoueDHCPv6 and autoconfiguration also needs more work.  "Managed" and "Other"
78380d21dc4SYoshinobu Inouebits in RA have no special effect to stateful autoconfiguration procedure
78480d21dc4SYoshinobu Inouein DHCPv6 client program ("Managed" bit actually prevents stateless
78580d21dc4SYoshinobu Inoueautoconfiguration, but no special action will be taken for DHCPv6 client).
78680d21dc4SYoshinobu Inoue
78780d21dc4SYoshinobu Inoue1.5 Generic tunnel interface
78880d21dc4SYoshinobu Inoue
78980d21dc4SYoshinobu InoueGIF (Generic InterFace) is a pseudo interface for configured tunnel.
79080d21dc4SYoshinobu InoueDetails are described in gif(4) manpage.
79180d21dc4SYoshinobu InoueCurrently
79280d21dc4SYoshinobu Inoue	v6 in v6
79380d21dc4SYoshinobu Inoue	v6 in v4
79480d21dc4SYoshinobu Inoue	v4 in v6
79580d21dc4SYoshinobu Inoue	v4 in v4
79680d21dc4SYoshinobu Inoueare available.  Use "gifconfig" to assign physical (outer) source
79780d21dc4SYoshinobu Inoueand destination address to gif interfaces.
79880d21dc4SYoshinobu InoueConfiguration that uses same address family for inner and outer IP
79980d21dc4SYoshinobu Inoueheader (v4 in v4, or v6 in v6) is dangerous.  It is very easy to
80080d21dc4SYoshinobu Inoueconfigure interfaces and routing tables to perform infinite level
80180d21dc4SYoshinobu Inoueof tunneling.  Please be warned.
80280d21dc4SYoshinobu Inoue
80380d21dc4SYoshinobu Inouegif can be configured to be ECN-friendly.  See 4.5 for ECN-friendliness
80480d21dc4SYoshinobu Inoueof tunnels, and gif(4) manpage for how to configure.
80580d21dc4SYoshinobu Inoue
80680d21dc4SYoshinobu InoueIf you would like to configure an IPv4-in-IPv6 tunnel with gif interface,
8078f336835SJun-ichiro itojun Haginoread gif(4) carefully.  You may need to remove IPv6 link-local address
80880d21dc4SYoshinobu Inoueautomatically assigned to the gif interface.
80980d21dc4SYoshinobu Inoue
810f88fe57eSHajimu UMEMOTO1.6 Address Selection
81180d21dc4SYoshinobu Inoue
812f88fe57eSHajimu UMEMOTO1.6.1 Source Address Selection
81380d21dc4SYoshinobu Inoue
814f88fe57eSHajimu UMEMOTOThe KAME kernel chooses the source address for an outgoing packet
815f88fe57eSHajimu UMEMOTOsent from a user application as follows:
8168f336835SJun-ichiro itojun Hagino
817f88fe57eSHajimu UMEMOTO1. if the source address is explicitly specified via an IPV6_PKTINFO
818f88fe57eSHajimu UMEMOTO   ancillary data item or the socket option of that name, just use it.
819f88fe57eSHajimu UMEMOTO   Note that this item/option overrides the bound address of the
820f88fe57eSHajimu UMEMOTO   corresponding (datagram) socket.
82180d21dc4SYoshinobu Inoue
822f88fe57eSHajimu UMEMOTO2. if the corresponding socket is bound, use the bound address.
8238f336835SJun-ichiro itojun Hagino
824f88fe57eSHajimu UMEMOTO3. otherwise, the kernel first tries to find the outgoing interface of
825f88fe57eSHajimu UMEMOTO   the packet.  If it fails, the source address selection also fails.
826f88fe57eSHajimu UMEMOTO   If the kernel can find an interface, choose the most appropriate
827f88fe57eSHajimu UMEMOTO   address based on the algorithm described in RFC3484.
8288f336835SJun-ichiro itojun Hagino
829f88fe57eSHajimu UMEMOTO   The policy table used in this algorithm is stored in the kernel.
830f88fe57eSHajimu UMEMOTO   To install or view the policy, use the ip6addrctl(8) command.  The
831f88fe57eSHajimu UMEMOTO   kernel does not have pre-installed policy.  It is expected that the
832f88fe57eSHajimu UMEMOTO   default policy described in the draft should be installed at the
833f88fe57eSHajimu UMEMOTO   bootstrap time using this command.
8348f336835SJun-ichiro itojun Hagino
835f88fe57eSHajimu UMEMOTO   This draft allows an implementation to add implementation-specific
836f88fe57eSHajimu UMEMOTO   rules with higher precedence than the rule "Use longest matching
837f88fe57eSHajimu UMEMOTO   prefix."  KAME's implementation has the following additional rules
838f88fe57eSHajimu UMEMOTO   (that apply in the appeared order):
83933841545SHajimu UMEMOTO
840f88fe57eSHajimu UMEMOTO   - prefer addresses on alive interfaces, that is, interfaces with
841f88fe57eSHajimu UMEMOTO     the UP flag being on.  This rule is particularly useful for
842f88fe57eSHajimu UMEMOTO     routers, since some routing daemons stop advertising prefixes
843f88fe57eSHajimu UMEMOTO    (addresses) on interfaces that have become down.
8448f336835SJun-ichiro itojun Hagino
845743eee66SSUZUKI Shinsuke   - prefer addresses on "preferred" interfaces.  "Preferred"
846743eee66SSUZUKI Shinsuke     interfaces can be specified by the ndp(8) command.  By default,
847743eee66SSUZUKI Shinsuke     no interface is preferred, that is, this rule does not apply.
848743eee66SSUZUKI Shinsuke     Again, this rule is particularly useful for routers, since there
849743eee66SSUZUKI Shinsuke     is a convention, among router administrators, of assigning
850743eee66SSUZUKI Shinsuke     "stable" addresses on a particular interface (typically a
851743eee66SSUZUKI Shinsuke     loopback interface).
852743eee66SSUZUKI Shinsuke
853f88fe57eSHajimu UMEMOTO   In any case, addresses that break the scope zone of the
854f88fe57eSHajimu UMEMOTO   destination, or addresses whose zone do not contain the outgoing
855f88fe57eSHajimu UMEMOTO   interface are never chosen.
8568f336835SJun-ichiro itojun Hagino
857f88fe57eSHajimu UMEMOTOWhen the procedure above fails, the kernel usually returns
858f88fe57eSHajimu UMEMOTOEADDRNOTAVAIL to the application.
8598f336835SJun-ichiro itojun Hagino
860f88fe57eSHajimu UMEMOTOIn some cases, the specification explicitly requires the
861f88fe57eSHajimu UMEMOTOimplementation to choose a particular source address.  The source
862f88fe57eSHajimu UMEMOTOaddress for a Neighbor Advertisement (NA) message is an example.
86380d21dc4SYoshinobu InoueUnder the spec (RFC2461 7.2.2) NA's source should be the target
864f88fe57eSHajimu UMEMOTOaddress of the corresponding NS's target.  In this case we follow the
865f88fe57eSHajimu UMEMOTOspec rather than the above rule.
86680d21dc4SYoshinobu Inoue
8678f336835SJun-ichiro itojun HaginoIf you would like to prohibit the use of deprecated address for some
8688f336835SJun-ichiro itojun Haginoreason, configure net.inet6.ip6.use_deprecated to 0.  The issue
8698f336835SJun-ichiro itojun Haginorelated to deprecated address is described in RFC2462 5.5.4 (NOTE:
8708f336835SJun-ichiro itojun Haginothere is some debate underway in IETF ipngwg on how to use
87180d21dc4SYoshinobu Inoue"deprecated" address).
87280d21dc4SYoshinobu Inoue
873f88fe57eSHajimu UMEMOTOAs documented in the source address selection document, temporary
874f88fe57eSHajimu UMEMOTOaddresses for privacy extension are less preferred to public addresses
875f88fe57eSHajimu UMEMOTOby default.  However, for administrators who are particularly aware of
876f88fe57eSHajimu UMEMOTOthe privacy, there is a system-wide sysctl(3) variable
877f88fe57eSHajimu UMEMOTO"net.inet6.ip6.prefer_tempaddr".  When the variable is set to
878f88fe57eSHajimu UMEMOTOnon-zero, the kernel will rather prefer temporary addresses.  The
879f88fe57eSHajimu UMEMOTOdefault value of this variable is 0.
880f88fe57eSHajimu UMEMOTO
881f88fe57eSHajimu UMEMOTO1.6.2 Destination Address Ordering
882f88fe57eSHajimu UMEMOTO
883f88fe57eSHajimu UMEMOTOKAME's getaddrinfo(3) supports the destination address ordering
884f88fe57eSHajimu UMEMOTOalgorithm described in RFC3484.  Getaddrinfo(3) needs to know the
885f88fe57eSHajimu UMEMOTOsource address for each destination address and policy entries
886f88fe57eSHajimu UMEMOTO(described in the previous section) for the source and destination
887f88fe57eSHajimu UMEMOTOaddresses.  To get the source address, the library function opens a
888f88fe57eSHajimu UMEMOTOUDP socket and tries to connect(2) for the destination.  To get the
889f88fe57eSHajimu UMEMOTOpolicy entry, the function issues sysctl(3).
890f88fe57eSHajimu UMEMOTO
89180d21dc4SYoshinobu Inoue1.7 Jumbo Payload
89280d21dc4SYoshinobu Inoue
89380d21dc4SYoshinobu InoueKAME supports the Jumbo Payload hop-by-hop option used to send IPv6
89480d21dc4SYoshinobu Inouepackets with payloads longer than 65,535 octets.  But since currently
89580d21dc4SYoshinobu InoueKAME does not support any physical interface whose MTU is more than
89680d21dc4SYoshinobu Inoue65,535, such payloads can be seen only on the loopback interface(i.e.
89780d21dc4SYoshinobu Inouelo0).
89880d21dc4SYoshinobu Inoue
89980d21dc4SYoshinobu InoueIf you want to try jumbo payloads, you first have to reconfigure the
90080d21dc4SYoshinobu Inouekernel so that the MTU of the loopback interface is more than 65,535
90180d21dc4SYoshinobu Inouebytes; add the following to the kernel configuration file:
90280d21dc4SYoshinobu Inoue	options		"LARGE_LOMTU"		#To test jumbo payload
90380d21dc4SYoshinobu Inoueand recompile the new kernel.
90480d21dc4SYoshinobu Inoue
90580d21dc4SYoshinobu InoueThen you can test jumbo payloads by the ping6 command with -b and -s
90680d21dc4SYoshinobu Inoueoptions.  The -b option must be specified to enlarge the size of the
90780d21dc4SYoshinobu Inouesocket buffer and the -s option specifies the length of the packet,
90880d21dc4SYoshinobu Inouewhich should be more than 65,535.  For example, type as follows;
90980d21dc4SYoshinobu Inoue	% ping6 -b 70000 -s 68000 ::1
91080d21dc4SYoshinobu Inoue
91180d21dc4SYoshinobu InoueThe IPv6 specification requires that the Jumbo Payload option must not
91280d21dc4SYoshinobu Inouebe used in a packet that carries a fragment header.  If this condition
91380d21dc4SYoshinobu Inoueis broken, an ICMPv6 Parameter Problem message must be sent to the
91480d21dc4SYoshinobu Inouesender.  KAME kernel follows the specification, but you cannot usually
91580d21dc4SYoshinobu Inouesee an ICMPv6 error caused by this requirement.
91680d21dc4SYoshinobu Inoue
91780d21dc4SYoshinobu InoueIf KAME kernel receives an IPv6 packet, it checks the frame length of
91880d21dc4SYoshinobu Inouethe packet and compares it to the length specified in the payload
91980d21dc4SYoshinobu Inouelength field of the IPv6 header or in the value of the Jumbo Payload
92080d21dc4SYoshinobu Inoueoption, if any.  If the former is shorter than the latter, KAME kernel
92180d21dc4SYoshinobu Inouediscards the packet and increments the statistics.  You can see the
92280d21dc4SYoshinobu Inouestatistics as output of netstat command with `-s -p ip6' option:
92380d21dc4SYoshinobu Inoue	% netstat -s -p ip6
92480d21dc4SYoshinobu Inoue	ip6:
92580d21dc4SYoshinobu Inoue		(snip)
92680d21dc4SYoshinobu Inoue		1 with data size < data length
92780d21dc4SYoshinobu Inoue
92880d21dc4SYoshinobu InoueSo, KAME kernel does not send an ICMPv6 error unless the erroneous
92980d21dc4SYoshinobu Inouepacket is an actual Jumbo Payload, that is, its packet size is more
93080d21dc4SYoshinobu Inouethan 65,535 bytes.  As described above, KAME kernel currently does not
93180d21dc4SYoshinobu Inouesupport physical interface with such a huge MTU, so it rarely returns an
93280d21dc4SYoshinobu InoueICMPv6 error.
93380d21dc4SYoshinobu Inoue
93480d21dc4SYoshinobu InoueTCP/UDP over jumbogram is not supported at this moment.  This is because
93580d21dc4SYoshinobu Inouewe have no medium (other than loopback) to test this.  Contact us if you
93680d21dc4SYoshinobu Inoueneed this.
93780d21dc4SYoshinobu Inoue
93880d21dc4SYoshinobu InoueIPsec does not work on jumbograms.  This is due to some specification twists
93980d21dc4SYoshinobu Inouein supporting AH with jumbograms (AH header size influences payload length,
94080d21dc4SYoshinobu Inoueand this makes it real hard to authenticate inbound packet with jumbo payload
94180d21dc4SYoshinobu Inoueoption as well as AH).
94280d21dc4SYoshinobu Inoue
94380d21dc4SYoshinobu InoueThere are fundamental issues in *BSD support for jumbograms.  We would like to
9448f336835SJun-ichiro itojun Haginoaddress those, but we need more time to finalize the task.  To name a few:
9458f336835SJun-ichiro itojun Hagino- mbuf pkthdr.len field is typed as "int" in 4.4BSD, so it cannot hold
94680d21dc4SYoshinobu Inoue  jumbogram with len > 2G on 32bit architecture CPUs.  If we would like to
94780d21dc4SYoshinobu Inoue  support jumbogram properly, the field must be expanded to hold 4G +
94880d21dc4SYoshinobu Inoue  IPv6 header + link-layer header.  Therefore, it must be expanded to at least
94980d21dc4SYoshinobu Inoue  int64_t (u_int32_t is NOT enough).
95080d21dc4SYoshinobu Inoue- We mistakingly use "int" to hold packet length in many places.  We need
9518f336835SJun-ichiro itojun Hagino  to convert them into larger numeric type.  It needs a great care, as we may
95280d21dc4SYoshinobu Inoue  experience overflow during packet length computation.
95380d21dc4SYoshinobu Inoue- We mistakingly check for ip6_plen field of IPv6 header for packet payload
95480d21dc4SYoshinobu Inoue  length in various places.  We should be checking mbuf pkthdr.len instead.
95580d21dc4SYoshinobu Inoue  ip6_input() will perform sanity check on jumbo payload option on input,
95680d21dc4SYoshinobu Inoue  and we can safely use mbuf pkthdr.len afterwards.
9578f336835SJun-ichiro itojun Hagino- TCP code needs careful updates in bunch of places, of course.
95880d21dc4SYoshinobu Inoue
95980d21dc4SYoshinobu Inoue1.8 Loop prevention in header processing
96080d21dc4SYoshinobu Inoue
96180d21dc4SYoshinobu InoueIPv6 specification allows arbitrary number of extension headers to
96280d21dc4SYoshinobu Inouebe placed onto packets.  If we implement IPv6 packet processing
96380d21dc4SYoshinobu Inouecode in the way BSD IPv4 code is implemented, kernel stack may
96480d21dc4SYoshinobu Inoueoverflow due to long function call chain.  KAME sys/netinet6 code
96580d21dc4SYoshinobu Inoueis carefully designed to avoid kernel stack overflow.  Because of
96680d21dc4SYoshinobu Inouethis, KAME sys/netinet6 code defines its own protocol switch
96780d21dc4SYoshinobu Inouestructure, as "struct ip6protosw" (see netinet6/ip6protosw.h).
96833841545SHajimu UMEMOTO
96933841545SHajimu UMEMOTOIn addition to this, we restrict the number of extension headers
97033841545SHajimu UMEMOTO(including the IPv6 header) in each incoming packet, in order to
97133841545SHajimu UMEMOTOprevent a DoS attack that tries to send packets with a massive number
97233841545SHajimu UMEMOTOof extension headers.  The upper limit can be configured by the sysctl
97333841545SHajimu UMEMOTOvalue net.inet6.ip6.hdrnestlimit.  In particular, if the value is 0,
97433841545SHajimu UMEMOTOthe node will allow an arbitrary number of headers. As of writing this
97533841545SHajimu UMEMOTOdocument, the default value is 50.
97633841545SHajimu UMEMOTO
9778f336835SJun-ichiro itojun HaginoIPv4 part (sys/netinet) remains untouched for compatibility.
97880d21dc4SYoshinobu InoueBecause of this, if you receive IPsec-over-IPv4 packet with massive
97980d21dc4SYoshinobu Inouenumber of IPsec headers, kernel stack may blow up.  IPsec-over-IPv6 is okay.
98080d21dc4SYoshinobu Inoue
98180d21dc4SYoshinobu Inoue1.9 ICMPv6
98280d21dc4SYoshinobu Inoue
98380d21dc4SYoshinobu InoueAfter RFC2463 was published, IETF ipngwg has decided to disallow ICMPv6 error
98480d21dc4SYoshinobu Inouepacket against ICMPv6 redirect, to prevent ICMPv6 storm on a network medium.
98580d21dc4SYoshinobu InoueKAME already implements this into the kernel.
98680d21dc4SYoshinobu Inoue
9878f336835SJun-ichiro itojun HaginoRFC2463 requires rate limitation for ICMPv6 error packets generated by a
9888f336835SJun-ichiro itojun Haginonode, to avoid possible DoS attacks.  KAME kernel implements two rate-
9898f336835SJun-ichiro itojun Haginolimitation mechanisms, tunable via sysctl:
9908f336835SJun-ichiro itojun Hagino- Minimum time interval between ICMPv6 error packets
9918f336835SJun-ichiro itojun Hagino	KAME kernel will generate no more than one ICMPv6 error packet,
9928f336835SJun-ichiro itojun Hagino	during configured time interval.  net.inet6.icmp6.errratelimit
9938f336835SJun-ichiro itojun Hagino	controls the interval (default: disabled).
9948f336835SJun-ichiro itojun Hagino- Maximum ICMPv6 error packet-per-second
9958f336835SJun-ichiro itojun Hagino	KAME kernel will generate no more than the configured number of
9968f336835SJun-ichiro itojun Hagino	packets in one second.  net.inet6.icmp6.errppslimit controls the
9978f336835SJun-ichiro itojun Hagino	maximum packet-per-second value (default: 200pps)
9988f336835SJun-ichiro itojun HaginoBasically, we need to pick values that are suitable against the bandwidth
9998f336835SJun-ichiro itojun Haginoof link layer devices directly attached to the node.  In some cases the
10008f336835SJun-ichiro itojun Haginodefault values may not fit well.  We are still unsure if the default value
10018f336835SJun-ichiro itojun Haginois sane or not.  Comments are welcome.
10028f336835SJun-ichiro itojun Hagino
100380d21dc4SYoshinobu Inoue1.10 Applications
100480d21dc4SYoshinobu Inoue
100580d21dc4SYoshinobu InoueFor userland programming, we support IPv6 socket API as specified in
10061f320556SHajimu UMEMOTORFC2553/3493, RFC3542 and upcoming internet drafts.
100780d21dc4SYoshinobu Inoue
100880d21dc4SYoshinobu InoueTCP/UDP over IPv6 is available and quite stable.  You can enjoy "telnet",
100980d21dc4SYoshinobu Inoue"ftp", "rlogin", "rsh", "ssh", etc.  These applications are protocol
101080d21dc4SYoshinobu Inoueindependent.  That is, they automatically chooses IPv4 or IPv6
101180d21dc4SYoshinobu Inoueaccording to DNS.
101280d21dc4SYoshinobu Inoue
101380d21dc4SYoshinobu Inoue1.11 Kernel Internals
101480d21dc4SYoshinobu Inoue
101580d21dc4SYoshinobu Inoue (*) TCP/UDP part is handled differently between operating system platforms.
101680d21dc4SYoshinobu Inoue     See 1.12 for details.
101780d21dc4SYoshinobu Inoue
101880d21dc4SYoshinobu InoueThe current KAME has escaped from the IPv4 netinet logic.  While
101980d21dc4SYoshinobu Inoueip_forward() calls ip_output(), ip6_forward() directly calls
102080d21dc4SYoshinobu Inoueif_output() since routers must not divide IPv6 packets into fragments.
102180d21dc4SYoshinobu Inoue
102280d21dc4SYoshinobu InoueICMPv6 should contain the original packet as long as possible up to
102380d21dc4SYoshinobu Inoue1280.  UDP6/IP6 port unreach, for instance, should contain all
102480d21dc4SYoshinobu Inoueextension headers and the *unchanged* UDP6 and IP6 headers.
10258f336835SJun-ichiro itojun HaginoSo, all IP6 functions except TCP6 never convert network byte
102680d21dc4SYoshinobu Inoueorder into host byte order, to save the original packet.
102780d21dc4SYoshinobu Inoue
10288f336835SJun-ichiro itojun Haginotcp6_input(), udp6_input() and icmp6_input() can't assume that IP6
102980d21dc4SYoshinobu Inoueheader is preceding the transport headers due to extension
103080d21dc4SYoshinobu Inoueheaders.  So, in6_cksum() was implemented to handle packets whose IP6
10318f336835SJun-ichiro itojun Haginoheader and transport header is not continuous.  TCP/IP6 nor UDP/IP6
103280d21dc4SYoshinobu Inoueheader structure don't exist for checksum calculation.
103380d21dc4SYoshinobu Inoue
103480d21dc4SYoshinobu InoueTo process IP6 header, extension headers and transport headers easily,
103580d21dc4SYoshinobu InoueKAME requires network drivers to store packets in one internal mbuf or
103680d21dc4SYoshinobu Inoueone or more external mbufs.  A typical old driver prepares two
10378f336835SJun-ichiro itojun Haginointernal mbufs for 100 - 208 bytes data, however, KAME's reference
103880d21dc4SYoshinobu Inoueimplementation stores it in one external mbuf.
103980d21dc4SYoshinobu Inoue
104080d21dc4SYoshinobu Inoue"netstat -s -p ip6" tells you whether or not your driver conforms
104180d21dc4SYoshinobu InoueKAME's requirement.  In the following example, "cce0" violates the
104280d21dc4SYoshinobu Inouerequirement. (For more information, refer to Section 2.)
104380d21dc4SYoshinobu Inoue
104480d21dc4SYoshinobu Inoue        Mbuf statistics:
104580d21dc4SYoshinobu Inoue                317 one mbuf
104680d21dc4SYoshinobu Inoue                two or more mbuf::
104780d21dc4SYoshinobu Inoue                        lo0 = 8
104880d21dc4SYoshinobu Inoue			cce0 = 10
104980d21dc4SYoshinobu Inoue                3282 one ext mbuf
105080d21dc4SYoshinobu Inoue                0 two or more ext mbuf
105180d21dc4SYoshinobu Inoue
105280d21dc4SYoshinobu InoueEach input function calls IP6_EXTHDR_CHECK in the beginning to check
105380d21dc4SYoshinobu Inoueif the region between IP6 and its header is
105480d21dc4SYoshinobu Inouecontinuous.  IP6_EXTHDR_CHECK calls m_pullup() only if the mbuf has
105580d21dc4SYoshinobu InoueM_LOOP flag, that is, the packet comes from the loopback
105680d21dc4SYoshinobu Inoueinterface.  m_pullup() is never called for packets coming from physical
105780d21dc4SYoshinobu Inouenetwork interfaces.
105880d21dc4SYoshinobu Inoue
10598f336835SJun-ichiro itojun HaginoTCP6 reassembly makes use of IP6 header to store reassemble
10608f336835SJun-ichiro itojun Haginoinformation.  IP6 is not supposed to be just before TCP6, so
10618f336835SJun-ichiro itojun Haginoip6tcpreass structure has a pointer to TCP6 header.  Of course, it has
10628f336835SJun-ichiro itojun Haginoalso a pointer back to mbuf to avoid m_pullup().
10638f336835SJun-ichiro itojun Hagino
10648f336835SJun-ichiro itojun HaginoLike TCP6, both IP and IP6 reassemble functions never call m_pullup().
10658f336835SJun-ichiro itojun Hagino
10668f336835SJun-ichiro itojun Haginoxxx_ctlinput() calls in_mrejoin() on PRC_IFNEWADDR.  We think this is
10678f336835SJun-ichiro itojun Haginoone of 4.4BSD implementation flaws.  Since 4.4BSD keeps ia_multiaddrs
10688f336835SJun-ichiro itojun Haginoin in_ifaddr{}, it can't use multicast feature if the interface has no
10698f336835SJun-ichiro itojun Haginounicast address.  So, if an application joins to an interface and then
10708f336835SJun-ichiro itojun Haginoall unicast addresses are removed from the interface, the application
10718f336835SJun-ichiro itojun Haginocan't send/receive any multicast packets.  Moreover, if a new unicast
10728f336835SJun-ichiro itojun Haginoaddress is assigned to the interface, in_mrejoin() must be called.
10738f336835SJun-ichiro itojun HaginoKAME's interfaces, however, have ALWAYS one link-local unicast
10748f336835SJun-ichiro itojun Haginoaddress.  These extensions have thus not been implemented in KAME.
107580d21dc4SYoshinobu Inoue
107680d21dc4SYoshinobu Inoue1.12 IPv4 mapped address and IPv6 wildcard socket
107780d21dc4SYoshinobu Inoue
1078f88fe57eSHajimu UMEMOTORFC2553/3493 describes IPv4 mapped address (3.7) and special behavior
107980d21dc4SYoshinobu Inoueof IPv6 wildcard bind socket (3.8).  The spec allows you to:
108080d21dc4SYoshinobu Inoue- Accept IPv4 connections by AF_INET6 wildcard bind socket.
108180d21dc4SYoshinobu Inoue- Transmit IPv4 packet over AF_INET6 socket by using special form of
108280d21dc4SYoshinobu Inoue  the address like ::ffff:10.1.1.1.
108380d21dc4SYoshinobu Inouebut the spec itself is very complicated and does not specify how the
108480d21dc4SYoshinobu Inouesocket layer should behave.
108580d21dc4SYoshinobu InoueHere we call the former one "listening side" and the latter one "initiating
108680d21dc4SYoshinobu Inoueside", for reference purposes.
108780d21dc4SYoshinobu Inoue
108880d21dc4SYoshinobu InoueAlmost all KAME implementations treat tcp/udp port number space separately
10898f336835SJun-ichiro itojun Haginobetween IPv4 and IPv6.  You can perform wildcard bind on both of the address
109080d21dc4SYoshinobu Inouefamilies, on the same port.
109180d21dc4SYoshinobu Inoue
10928f336835SJun-ichiro itojun HaginoThere are some OS-platform differences in KAME code, as we use tcp/udp
10938f336835SJun-ichiro itojun Haginocode from different origin.  The following table summarizes the behavior.
109480d21dc4SYoshinobu Inoue
109580d21dc4SYoshinobu Inoue		listening side		initiating side
10968f336835SJun-ichiro itojun Hagino		(AF_INET6 wildcard	(connection to ::ffff:10.1.1.1)
109780d21dc4SYoshinobu Inoue		socket gets IPv4 conn.)
109880d21dc4SYoshinobu Inoue		---			---
10998f336835SJun-ichiro itojun HaginoKAME/BSDI3	not supported		not supported
11008f336835SJun-ichiro itojun HaginoKAME/FreeBSD228	not supported		not supported
11018f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x	configurable		supported
110280d21dc4SYoshinobu Inoue		default: enabled
11038f336835SJun-ichiro itojun HaginoKAME/FreeBSD4x	configurable		supported
11048f336835SJun-ichiro itojun Hagino		default: enabled
11058f336835SJun-ichiro itojun HaginoKAME/NetBSD	configurable		supported
11068f336835SJun-ichiro itojun Hagino		default: disabled
11078f336835SJun-ichiro itojun HaginoKAME/BSDI4	enabled			supported
11088f336835SJun-ichiro itojun HaginoKAME/OpenBSD	not supported		not supported
110980d21dc4SYoshinobu Inoue
111080d21dc4SYoshinobu InoueThe following sections will give you more details, and how you can
111180d21dc4SYoshinobu Inoueconfigure the behavior.
111280d21dc4SYoshinobu Inoue
111380d21dc4SYoshinobu InoueComments on listening side:
111480d21dc4SYoshinobu Inoue
1115f88fe57eSHajimu UMEMOTOIt looks that RFC2553/3493 talks too little on wildcard bind issue,
11168f336835SJun-ichiro itojun Haginospecifically on (1) port space issue, (2) failure mode, (3) relationship
11178f336835SJun-ichiro itojun Haginobetween AF_INET/INET6 wildcard bind like ordering constraint, and (4) behavior
11188f336835SJun-ichiro itojun Haginowhen conflicting socket is opened/closed.  There can be several separate
111980d21dc4SYoshinobu Inoueinterpretation for this RFC which conform to it but behaves differently.
112080d21dc4SYoshinobu InoueSo, to implement portable application you should assume nothing
112180d21dc4SYoshinobu Inoueabout the behavior in the kernel.  Using getaddrinfo() is the safest way.
112280d21dc4SYoshinobu InouePort number space and wildcard bind issues were discussed in detail
112380d21dc4SYoshinobu Inoueon ipv6imp mailing list, in mid March 1999 and it looks that there's
112480d21dc4SYoshinobu Inoueno concrete consensus (means, up to implementers).  You may want to
112580d21dc4SYoshinobu Inouecheck the mailing list archives.
11268f336835SJun-ichiro itojun HaginoWe supply a tool called "bindtest" that explores the behavior of
11278f336835SJun-ichiro itojun Haginokernel bind(2).  The tool will not be compiled by default.
112880d21dc4SYoshinobu Inoue
112980d21dc4SYoshinobu InoueIf a server application would like to accept IPv4 and IPv6 connections,
11308f336835SJun-ichiro itojun Haginoit should use AF_INET and AF_INET6 socket (you'll need two sockets).
113180d21dc4SYoshinobu InoueUse getaddrinfo() with AI_PASSIVE into ai_flags, and socket(2) and bind(2)
113280d21dc4SYoshinobu Inoueto all the addresses returned.
113380d21dc4SYoshinobu InoueBy opening multiple sockets, you can accept connections onto the socket with
113480d21dc4SYoshinobu Inoueproper address family.  IPv4 connections will be accepted by AF_INET socket,
11358f336835SJun-ichiro itojun Haginoand IPv6 connections will be accepted by AF_INET6 socket (NOTE: KAME/BSDI4
11368f336835SJun-ichiro itojun Haginokernel sometimes violate this - we will fix it).
113780d21dc4SYoshinobu Inoue
11388f336835SJun-ichiro itojun HaginoIf you try to support IPv6 traffic only and would like to reject IPv4
11398f336835SJun-ichiro itojun Haginotraffic, always check the peer address when a connection is made toward
114080d21dc4SYoshinobu InoueAF_INET6 listening socket.  If the address is IPv4 mapped address, you may
114180d21dc4SYoshinobu Inouewant to reject the connection.  You can check the condition by using
11428f336835SJun-ichiro itojun HaginoIN6_IS_ADDR_V4MAPPED() macro.  This is one of the reasons the author of
11438f336835SJun-ichiro itojun Haginothe section (itojun) dislikes special behavior of AF_INET6 wildcard bind.
114480d21dc4SYoshinobu Inoue
114580d21dc4SYoshinobu InoueComments on initiating side:
114680d21dc4SYoshinobu Inoue
114780d21dc4SYoshinobu InoueAdvise to application implementers: to implement a portable IPv6 application
114880d21dc4SYoshinobu Inoue(which works on multiple IPv6 kernels), we believe that the following
114980d21dc4SYoshinobu Inoueis the key to the success:
115080d21dc4SYoshinobu Inoue- NEVER hardcode AF_INET nor AF_INET6.
115180d21dc4SYoshinobu Inoue- Use getaddrinfo() and getnameinfo() throughout the system.
115280d21dc4SYoshinobu Inoue  Never use gethostby*(), getaddrby*(), inet_*() or getipnodeby*().
115380d21dc4SYoshinobu Inoue- If you would like to connect to destination, use getaddrinfo() and try
115480d21dc4SYoshinobu Inoue  all the destination returned, like telnet does.
115580d21dc4SYoshinobu Inoue- Some of the IPv6 stack is shipped with buggy getaddrinfo().  Ship a minimal
115680d21dc4SYoshinobu Inoue  working version with your application and use that as last resort.
115780d21dc4SYoshinobu Inoue
115880d21dc4SYoshinobu InoueIf you would like to use AF_INET6 socket for both IPv4 and IPv6 outgoing
11598f336835SJun-ichiro itojun Haginoconnection, you will need tweaked implementation in DNS support libraries,
1160f88fe57eSHajimu UMEMOTOas documented in RFC2553/3493 6.1.  KAME libinet6 includes the tweak in
11618f336835SJun-ichiro itojun Haginogetipnodebyname().  Note that getipnodebyname() itself is not recommended as
11628f336835SJun-ichiro itojun Haginoit does not handle scoped IPv6 addresses at all.  For IPv6 name resolution
11638f336835SJun-ichiro itojun Haginogetaddrinfo() is the preferred API.  getaddrinfo() does not implement the
11648f336835SJun-ichiro itojun Haginotweak.
116580d21dc4SYoshinobu Inoue
116680d21dc4SYoshinobu InoueWhen writing applications that make outgoing connections, story goes much
11678f336835SJun-ichiro itojun Haginosimpler if you treat AF_INET and AF_INET6 as totally separate address family.
116880d21dc4SYoshinobu Inoue{set,get}sockopt issue goes simpler, DNS issue will be made simpler.  We do
116980d21dc4SYoshinobu Inouenot recommend you to rely upon IPv4 mapped address.
117080d21dc4SYoshinobu Inoue
11718f336835SJun-ichiro itojun Hagino1.12.1 KAME/BSDI3 and KAME/FreeBSD228
117280d21dc4SYoshinobu Inoue
11738f336835SJun-ichiro itojun HaginoThe platforms do not support IPv4 mapped address at all (both listening side
11748f336835SJun-ichiro itojun Haginoand initiating side).  AF_INET6 and AF_INET sockets are totally separated.
117580d21dc4SYoshinobu Inoue
11768f336835SJun-ichiro itojun HaginoPort number space is totally separate between AF_INET and AF_INET6 sockets.
117780d21dc4SYoshinobu Inoue
117833841545SHajimu UMEMOTOIt should be noted that KAME/BSDI3 and KAME/FreeBSD228 are not conformant
1179f88fe57eSHajimu UMEMOTOto RFC2553/3493 section 3.7 and 3.8.  It is due to code sharing reasons.
118033841545SHajimu UMEMOTO
11818f336835SJun-ichiro itojun Hagino1.12.2 KAME/FreeBSD[34]x
118280d21dc4SYoshinobu Inoue
11838f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x and KAME/FreeBSD4x use shared tcp4/6 code (from
11848f336835SJun-ichiro itojun Haginosys/netinet/tcp*) and shared udp4/6 code (from sys/netinet/udp*).
11858f336835SJun-ichiro itojun HaginoThey use unified inpcb/in6pcb structure.
118680d21dc4SYoshinobu Inoue
11878f336835SJun-ichiro itojun Hagino1.12.2.1 KAME/FreeBSD[34]x, listening side
11888f336835SJun-ichiro itojun Hagino
11898f336835SJun-ichiro itojun HaginoThe platform can be configured to support IPv4 mapped address/special
11908f336835SJun-ichiro itojun HaginoAF_INET6 wildcard bind (enabled by default).  There is no kernel compilation
11918f336835SJun-ichiro itojun Haginooption to disable it.  You can enable/disable the behavior with sysctl
11928f336835SJun-ichiro itojun Hagino(per-node), or setsockopt (per-socket).
119380d21dc4SYoshinobu Inoue
119480d21dc4SYoshinobu InoueWildcard AF_INET6 socket grabs IPv4 connection if and only if the following
119580d21dc4SYoshinobu Inoueconditions are satisfied:
119680d21dc4SYoshinobu Inoue- there's no AF_INET socket that matches the IPv4 connection
119780d21dc4SYoshinobu Inoue- the AF_INET6 socket is configured to accept IPv4 traffic, i.e.
119833841545SHajimu UMEMOTO  getsockopt(IPV6_V6ONLY) returns 0.
119980d21dc4SYoshinobu Inoue
12008f336835SJun-ichiro itojun Hagino(XXX need checking)
120180d21dc4SYoshinobu Inoue
12028f336835SJun-ichiro itojun Hagino1.12.2.2 KAME/FreeBSD[34]x, initiating side
12038f336835SJun-ichiro itojun Hagino
12048f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x supports outgoing connection to IPv4 mapped address
12058f336835SJun-ichiro itojun Hagino(::ffff:10.1.1.1), if the node is configured to accept IPv4 connections
12068f336835SJun-ichiro itojun Haginoby AF_INET6 socket.
12078f336835SJun-ichiro itojun Hagino
12088f336835SJun-ichiro itojun Hagino(XXX need checking)
12098f336835SJun-ichiro itojun Hagino
12108f336835SJun-ichiro itojun Hagino1.12.3 KAME/NetBSD
12118f336835SJun-ichiro itojun Hagino
12128f336835SJun-ichiro itojun HaginoKAME/NetBSD uses shared tcp4/6 code (from sys/netinet/tcp*) and shared
12138f336835SJun-ichiro itojun Haginoudp4/6 code (from sys/netinet/udp*).  The implementation is made differently
12148f336835SJun-ichiro itojun Haginofrom KAME/FreeBSD[34]x.  KAME/NetBSD uses separate inpcb/in6pcb structures,
12158f336835SJun-ichiro itojun Haginowhile KAME/FreeBSD[34]x uses merged inpcb structure.
12168f336835SJun-ichiro itojun Hagino
121733841545SHajimu UMEMOTOIt should be noted that the default configuration of KAME/NetBSD is not
1218f88fe57eSHajimu UMEMOTOconformant to RFC2553/3493 section 3.8.  It is intentionally turned off by
1219f88fe57eSHajimu UMEMOTOdefault for security reasons.
12208f336835SJun-ichiro itojun Hagino
12218f336835SJun-ichiro itojun HaginoThe platform can be configured to support IPv4 mapped address/special AF_INET6
12228f336835SJun-ichiro itojun Haginowildcard bind (disabled by default).  Kernel behavior can be summarized as
12238f336835SJun-ichiro itojun Haginofollows:
12248f336835SJun-ichiro itojun Hagino- default: special support code will be compiled in, but is disabled by
122533841545SHajimu UMEMOTO  default.  It can be controlled by sysctl (net.inet6.ip6.v6only),
122633841545SHajimu UMEMOTO  or setsockopt(IPV6_V6ONLY).
1227f88fe57eSHajimu UMEMOTO- add "INET6_BINDV6ONLY": No special support code for AF_INET6 wildcard socket
12288f336835SJun-ichiro itojun Hagino  will be compiled in.  AF_INET6 sockets and AF_INET sockets are totally
12298f336835SJun-ichiro itojun Hagino  separate.  The behavior is similar to what described in 1.12.1.
12308f336835SJun-ichiro itojun Hagino
12318f336835SJun-ichiro itojun Haginosysctl setting will affect per-socket configuration at in6pcb creation time
12328f336835SJun-ichiro itojun Haginoonly.  In other words, per-socket configuration will be copied from sysctl
12338f336835SJun-ichiro itojun Haginoconfiguration at in6pcb creation time.  To change per-socket behavior, you
12348f336835SJun-ichiro itojun Haginomust perform setsockopt or reopen the socket.  Change in sysctl configuration
12358f336835SJun-ichiro itojun Haginowill not change the behavior or sockets that are already opened.
12368f336835SJun-ichiro itojun Hagino
1237f88fe57eSHajimu UMEMOTO1.12.3.1 KAME/NetBSD, listening side
1238f88fe57eSHajimu UMEMOTO
12398f336835SJun-ichiro itojun HaginoWildcard AF_INET6 socket grabs IPv4 connection if and only if the following
12408f336835SJun-ichiro itojun Haginoconditions are satisfied:
12418f336835SJun-ichiro itojun Hagino- there's no AF_INET socket that matches the IPv4 connection
12428f336835SJun-ichiro itojun Hagino- the AF_INET6 socket is configured to accept IPv4 traffic, i.e.
124333841545SHajimu UMEMOTO  getsockopt(IPV6_V6ONLY) returns 0.
12448f336835SJun-ichiro itojun Hagino
12458f336835SJun-ichiro itojun HaginoYou cannot bind(2) with IPv4 mapped address.  This is a workaround for port
12468f336835SJun-ichiro itojun Haginonumber duplicate and other twists.
12478f336835SJun-ichiro itojun Hagino
12488f336835SJun-ichiro itojun Hagino1.12.3.2 KAME/NetBSD, initiating side
12498f336835SJun-ichiro itojun Hagino
1250f88fe57eSHajimu UMEMOTOWhen getsockopt(IPV6_V6ONLY) is 0 for a socket, you can make an outgoing
1251f88fe57eSHajimu UMEMOTOtraffic to IPv4 destination over AF_INET6 socket, using IPv4 mapped
1252f88fe57eSHajimu UMEMOTOaddress destination (::ffff:10.1.1.1).
1253f88fe57eSHajimu UMEMOTO
1254f88fe57eSHajimu UMEMOTOWhen getsockopt(IPV6_V6ONLY) is 1 for a socket, you cannot use IPv4 mapped
1255f88fe57eSHajimu UMEMOTOaddress for outgoing traffic.
12568f336835SJun-ichiro itojun Hagino
12578f336835SJun-ichiro itojun Hagino1.12.4 KAME/BSDI4
12588f336835SJun-ichiro itojun Hagino
12598f336835SJun-ichiro itojun HaginoKAME/BSDI4 uses NRL-based TCP/UDP stack and inpcb source code,
12608f336835SJun-ichiro itojun Haginowhich was derived from NRL IPv6/IPsec stack.  We guess it supports IPv4 mapped
12618f336835SJun-ichiro itojun Haginoaddress and speical AF_INET6 wildcard bind.  The implementation is, again,
12628f336835SJun-ichiro itojun Haginodifferent from other KAME/*BSDs.
12638f336835SJun-ichiro itojun Hagino
12648f336835SJun-ichiro itojun Hagino1.12.4.1 KAME/BSDI4, listening side
12658f336835SJun-ichiro itojun Hagino
12668f336835SJun-ichiro itojun HaginoNRL inpcb layer supports special behavior of AF_INET6 wildcard socket.
12678f336835SJun-ichiro itojun HaginoThere is no way to disable the behavior.
12688f336835SJun-ichiro itojun Hagino
12698f336835SJun-ichiro itojun HaginoWildcard AF_INET6 socket grabs IPv4 connection if and only if the following
12708f336835SJun-ichiro itojun Haginocondition is satisfied:
12718f336835SJun-ichiro itojun Hagino- there's no AF_INET socket that matches the IPv4 connection
12728f336835SJun-ichiro itojun Hagino
12738f336835SJun-ichiro itojun Hagino1.12.4.2 KAME/BSDI4, initiating side
12748f336835SJun-ichiro itojun Hagino
12758f336835SJun-ichiro itojun HaginoKAME/BSDi4 supports connection initiation to IPv4 mapped address
12768f336835SJun-ichiro itojun Hagino(like ::ffff:10.1.1.1).
12778f336835SJun-ichiro itojun Hagino
12788f336835SJun-ichiro itojun Hagino1.12.5 KAME/OpenBSD
12798f336835SJun-ichiro itojun Hagino
12808f336835SJun-ichiro itojun HaginoKAME/OpenBSD uses NRL-based TCP/UDP stack and inpcb source code,
12818f336835SJun-ichiro itojun Haginowhich was derived from NRL IPv6/IPsec stack.
12828f336835SJun-ichiro itojun Hagino
1283f88fe57eSHajimu UMEMOTOIt should be noted that KAME/OpenBSD is not conformant to RFC2553/3493 section
1284f88fe57eSHajimu UMEMOTO3.7 and 3.8.  It is intentionally omitted for security reasons.
128533841545SHajimu UMEMOTO
12868f336835SJun-ichiro itojun Hagino1.12.5.1 KAME/OpenBSD, listening side
12878f336835SJun-ichiro itojun Hagino
12888f336835SJun-ichiro itojun HaginoKAME/OpenBSD disables special behavior on AF_INET6 wildcard bind for
12898f336835SJun-ichiro itojun Haginosecurity reasons (if IPv4 traffic toward AF_INET6 wildcard bind is allowed,
12908f336835SJun-ichiro itojun Haginoaccess control will become much harder).  KAME/BSDI4 uses NRL-based TCP/UDP
12918f336835SJun-ichiro itojun Haginostack as well, however, the behavior is different due to OpenBSD's security
12928f336835SJun-ichiro itojun Haginopolicy.
12938f336835SJun-ichiro itojun Hagino
12948f336835SJun-ichiro itojun HaginoAs a result the behavior of KAME/OpenBSD is similar to KAME/BSDI3 and
12958f336835SJun-ichiro itojun HaginoKAME/FreeBSD228 (see 1.12.1 for more detail).
12968f336835SJun-ichiro itojun Hagino
12978f336835SJun-ichiro itojun Hagino1.12.5.2 KAME/OpenBSD, initiating side
12988f336835SJun-ichiro itojun Hagino
12998f336835SJun-ichiro itojun HaginoKAME/OpenBSD does not support connection initiation to IPv4 mapped address
13008f336835SJun-ichiro itojun Hagino(like ::ffff:10.1.1.1).
13018f336835SJun-ichiro itojun Hagino
13028f336835SJun-ichiro itojun Hagino1.12.6 More issues
13038f336835SJun-ichiro itojun Hagino
13048f336835SJun-ichiro itojun HaginoIPv4 mapped address support adds a big requirement to EVERY userland codebase.
13058f336835SJun-ichiro itojun HaginoEvery userland code should check if an AF_INET6 sockaddr contains IPv4
13068f336835SJun-ichiro itojun Haginomapped address or not.  This adds many twists:
13078f336835SJun-ichiro itojun Hagino
13088f336835SJun-ichiro itojun Hagino- Access controls code becomes harder to write.
13098f336835SJun-ichiro itojun Hagino  For example, if you would like to reject packets from 10.0.0.0/8,
13108f336835SJun-ichiro itojun Hagino  you need to reject packets to AF_INET socket from 10.0.0.0/8,
13118f336835SJun-ichiro itojun Hagino  and to AF_INET6 socket from ::ffff:10.0.0.0/104.
13128f336835SJun-ichiro itojun Hagino- If a protocol on top of IPv4 is defined differently with IPv6, we need to be
13138f336835SJun-ichiro itojun Hagino  really careful when we determine which protocol to use.
13148f336835SJun-ichiro itojun Hagino  For example, with FTP protocol, we can not simply use sa_family to determine
13158f336835SJun-ichiro itojun Hagino  FTP command sets.  The following example is incorrect:
13168f336835SJun-ichiro itojun Hagino	if (sa_family == AF_INET)
13178f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or PASV/PORT;	/*IPv4*/
13188f336835SJun-ichiro itojun Hagino	else if (sa_family == AF_INET6)
13198f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or LPSV/LPRT;	/*IPv6*/
13208f336835SJun-ichiro itojun Hagino	else
13218f336835SJun-ichiro itojun Hagino		error;
132233841545SHajimu UMEMOTO  The correct code, with consideration to IPv4 mapped address, would be:
13238f336835SJun-ichiro itojun Hagino	if (sa_family == AF_INET)
13248f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or PASV/PORT;	/*IPv4*/
13258f336835SJun-ichiro itojun Hagino	else if (sa_family == AF_INET6 && IPv4 mapped address)
13268f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or PASV/PORT;	/*IPv4 command set on AF_INET6*/
13278f336835SJun-ichiro itojun Hagino	else if (sa_family == AF_INET6 && !IPv4 mapped address)
13288f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or LPSV/LPRT;	/*IPv6*/
13298f336835SJun-ichiro itojun Hagino	else
13308f336835SJun-ichiro itojun Hagino		error;
13318f336835SJun-ichiro itojun Hagino  It is too much to ask for every body to be careful like this.
13328f336835SJun-ichiro itojun Hagino  The problem is, we are not sure if the above code fragment is perfect for
13338f336835SJun-ichiro itojun Hagino  all situations.
13348f336835SJun-ichiro itojun Hagino- By enabling kernel support for IPv4 mapped address (outgoing direction),
13358f336835SJun-ichiro itojun Hagino  servers on the kernel can be hosed by IPv6 native packet that has IPv4
13368f336835SJun-ichiro itojun Hagino  mapped address in IPv6 header source, and can generate unwanted IPv4 packets.
1337f88fe57eSHajimu UMEMOTO  draft-itojun-ipv6-transition-abuse-01.txt, draft-cmetz-v6ops-v4mapped-api-
1338f88fe57eSHajimu UMEMOTO  harmful-00.txt, and draft-itojun-v6ops-v4mapped-harmful-01.txt
1339f88fe57eSHajimu UMEMOTO  has more on this scenario.
13408f336835SJun-ichiro itojun Hagino
13418f336835SJun-ichiro itojun HaginoDue to the above twists, some of KAME userland programs has restrictions on
13428f336835SJun-ichiro itojun Haginothe use of IPv4 mapped addresses:
13438f336835SJun-ichiro itojun Hagino- rshd/rlogind do not accept connections from IPv4 mapped address.
13448f336835SJun-ichiro itojun Hagino  This is to avoid malicious use of IPv4 mapped address in IPv6 native
13458f336835SJun-ichiro itojun Hagino  packet, to bypass source-address based authentication.
134633841545SHajimu UMEMOTO- ftp/ftpd assume that you are on dual stack network.  IPv4 mapped address
134733841545SHajimu UMEMOTO  will be decoded in userland, and will be passed to AF_INET sockets
134833841545SHajimu UMEMOTO  (in other words, ftp/ftpd do not support SIIT environment).
134933841545SHajimu UMEMOTO
135033841545SHajimu UMEMOTO1.12.7 Interaction with SIIT translator
135133841545SHajimu UMEMOTO
135233841545SHajimu UMEMOTOSIIT translator is specified in RFC2765.  KAME node cannot become a SIIT
135333841545SHajimu UMEMOTOtranslator box, nor SIIT end node (a node in SIIT cloud).
135433841545SHajimu UMEMOTO
135533841545SHajimu UMEMOTOTo become a SIIT translator box, we need to put additional code for that.
135633841545SHajimu UMEMOTOWe do not have the code in our tree at this moment.
135733841545SHajimu UMEMOTO
135833841545SHajimu UMEMOTOThere are multiple reasons that we are unable to become SIIT end node.
135933841545SHajimu UMEMOTO(1) SIIT translators require end nodes in the SIIT cloud to be IPv6-only.
136033841545SHajimu UMEMOTOSince we are unable to compile INET-less kernel, we are unable to become
136133841545SHajimu UMEMOTOSIIT end node.  (2) As presented in 1.12.6, some of our userland code assumes
136233841545SHajimu UMEMOTOdual stack network.  (3) KAME stack filters out IPv6 packets with IPv4
136333841545SHajimu UMEMOTOmapped address in the header, to secure non-SIIT case (which is much more
136433841545SHajimu UMEMOTOcommon).  Effectively KAME node will reject any packets via SIIT translator
136533841545SHajimu UMEMOTObox.  See section 1.14 for more detail about the last item.
136633841545SHajimu UMEMOTO
136733841545SHajimu UMEMOTOThere are documentation issues too - SIIT document requires very strange
136833841545SHajimu UMEMOTOthings.  For example, SIIT document asks IPv6-only (meaning no IPv4 code)
136933841545SHajimu UMEMOTOnode to be able to construct IPv4 IPsec headers.  If a node knows how to
137033841545SHajimu UMEMOTOconstruct IPv4 IPsec headers, that is not an IPv6-only node, it is a dual-stack
137133841545SHajimu UMEMOTOnode.  The requirements imposed in SIIT document contradict with the other
137233841545SHajimu UMEMOTOpart of the document itself.
137380d21dc4SYoshinobu Inoue
137480d21dc4SYoshinobu Inoue1.13 sockaddr_storage
137580d21dc4SYoshinobu Inoue
13768f336835SJun-ichiro itojun HaginoWhen RFC2553 was about to be finalized, there was discussion on how struct
137780d21dc4SYoshinobu Inouesockaddr_storage members are named.  One proposal is to prepend "__" to the
137880d21dc4SYoshinobu Inouemembers (like "__ss_len") as they should not be touched.  The other proposal
137980d21dc4SYoshinobu Inouewas that don't prepend it (like "ss_len") as we need to touch those members
138080d21dc4SYoshinobu Inouedirectly.  There was no clear consensus on it.
138180d21dc4SYoshinobu Inoue
138280d21dc4SYoshinobu InoueAs a result, RFC2553 defines struct sockaddr_storage as follows:
138380d21dc4SYoshinobu Inoue	struct sockaddr_storage {
138480d21dc4SYoshinobu Inoue		u_char	__ss_len;	/* address length */
138580d21dc4SYoshinobu Inoue		u_char	__ss_family;	/* address family */
138680d21dc4SYoshinobu Inoue		/* and bunch of padding */
138780d21dc4SYoshinobu Inoue	};
138880d21dc4SYoshinobu InoueOn the contrary, XNET draft defines as follows:
138980d21dc4SYoshinobu Inoue	struct sockaddr_storage {
139080d21dc4SYoshinobu Inoue		u_char	ss_len;		/* address length */
139180d21dc4SYoshinobu Inoue		u_char	ss_family;	/* address family */
139280d21dc4SYoshinobu Inoue		/* and bunch of padding */
139380d21dc4SYoshinobu Inoue	};
139480d21dc4SYoshinobu Inoue
1395f88fe57eSHajimu UMEMOTOIn December 1999, it was agreed that RFC2553bis (RFC3493) should pick the
1396f88fe57eSHajimu UMEMOTOlatter (XNET) definition.
139780d21dc4SYoshinobu Inoue
139880d21dc4SYoshinobu InoueKAME kit prior to December 1999 used RFC2553 definition.  KAME kit after
139980d21dc4SYoshinobu InoueDecember 1999 (including December) will conform to XNET definition,
1400f88fe57eSHajimu UMEMOTObased on RFC3493 discussion.
140180d21dc4SYoshinobu Inoue
140280d21dc4SYoshinobu InoueIf you look at multiple IPv6 implementations, you will be able to see
140380d21dc4SYoshinobu Inoueboth definitions.  As an userland programmer, the most portable way of
140480d21dc4SYoshinobu Inouedealing with it is to:
140580d21dc4SYoshinobu Inoue(1) ensure ss_family and/or ss_len are available on the platform, by using
140680d21dc4SYoshinobu Inoue    GNU autoconf,
1407*93b03d5dSUlrich Spörlein(2) have -Dss_family=__ss_family to unify all occurrences (including header
140880d21dc4SYoshinobu Inoue    file) into __ss_family, or
140980d21dc4SYoshinobu Inoue(3) never touch __ss_family.  cast to sockaddr * and use sa_family like:
141080d21dc4SYoshinobu Inoue	struct sockaddr_storage ss;
141180d21dc4SYoshinobu Inoue	family = ((struct sockaddr *)&ss)->sa_family
141280d21dc4SYoshinobu Inoue
14138f336835SJun-ichiro itojun Hagino1.14 Invalid addresses on the wire
14148f336835SJun-ichiro itojun Hagino
14158f336835SJun-ichiro itojun HaginoSome of IPv6 transition technologies embed IPv4 address into IPv6 address.
14168f336835SJun-ichiro itojun HaginoThese specifications themselves are fine, however, there can be certain
1417*93b03d5dSUlrich Spörleinset of attacks enabled by these specifications.  Recent specification
14188f336835SJun-ichiro itojun Haginodocuments covers up those issues, however, there are already-published RFCs
14198f336835SJun-ichiro itojun Haginothat does not have protection against those (like using source address of
14208f336835SJun-ichiro itojun Hagino::ffff:127.0.0.1 to bypass "reject packet from remote" filter).
14218f336835SJun-ichiro itojun Hagino
14228f336835SJun-ichiro itojun HaginoTo name a few, these address ranges can be used to hose an IPv6 implementation,
14238f336835SJun-ichiro itojun Haginoor bypass security controls:
14248f336835SJun-ichiro itojun Hagino- IPv4 mapped address that embeds unspecified/multicast/loopback/broadcast
14258f336835SJun-ichiro itojun Hagino  IPv4 address (if they are in IPv6 native packet header, they are malicious)
14268f336835SJun-ichiro itojun Hagino	::ffff:0.0.0.0/104	::ffff:127.0.0.0/104
14278f336835SJun-ichiro itojun Hagino	::ffff:224.0.0.0/100	::ffff:255.0.0.0/104
142833841545SHajimu UMEMOTO- 6to4 (RFC3056) prefix generated from unspecified/multicast/loopback/
142933841545SHajimu UMEMOTO  broadcast/private IPv4 address
14308f336835SJun-ichiro itojun Hagino	2002:0000::/24		2002:7f00::/24		2002:e000::/24
14318f336835SJun-ichiro itojun Hagino	2002:ff00::/24		2002:0a00::/24		2002:ac10::/28
14328f336835SJun-ichiro itojun Hagino	2002:c0a8::/32
143333841545SHajimu UMEMOTO- IPv4 compatible address that embeds unspecified/multicast/loopback/broadcast
143433841545SHajimu UMEMOTO  IPv4 address (if they are in IPv6 native packet header, they are malicious).
143533841545SHajimu UMEMOTO  Note that, since KAME doe snot support RFC1933/2893 auto tunnels, KAME nodes
143633841545SHajimu UMEMOTO  are not vulnerable to these packets.
143733841545SHajimu UMEMOTO	::0.0.0.0/104	::127.0.0.0/104	::224.0.0.0/100	::255.0.0.0/104
14388f336835SJun-ichiro itojun Hagino
143933841545SHajimu UMEMOTOAlso, since KAME does not support RFC1933/2893 auto tunnels, seeing IPv4
144033841545SHajimu UMEMOTOcompatible is very rare.  You should take caution if you see those on the wire.
144133841545SHajimu UMEMOTO
144233841545SHajimu UMEMOTOIf we see IPv6 packets with IPv4 mapped address (::ffff:0.0.0.0/96) in the
144333841545SHajimu UMEMOTOheader in dual-stack environment (not in SIIT environment), they indicate
1444*93b03d5dSUlrich Spörleinthat someone is trying to impersonate IPv4 peer.  The packet should be dropped.
144533841545SHajimu UMEMOTO
144633841545SHajimu UMEMOTOIPv6 specifications do not talk very much about IPv6 unspecified address (::)
144733841545SHajimu UMEMOTOin the IPv6 source address field.  Clarification is in progress.
144833841545SHajimu UMEMOTOHere are couple of comments:
144933841545SHajimu UMEMOTO- IPv6 unspecified address can be used in IPv6 source address field, if and
145033841545SHajimu UMEMOTO  only if we have no legal source address for the node.  The legal situations
145133841545SHajimu UMEMOTO  include, but may not be limited to, (1) MLD while no IPv6 address is assigned
145233841545SHajimu UMEMOTO  to the node and (2) DAD.
145333841545SHajimu UMEMOTO- If IPv6 TCP packet has IPv6 unspecified address, it is an attack attempt.
145433841545SHajimu UMEMOTO  The form can be used as a trigger for TCP DoS attack.  KAME code already
145533841545SHajimu UMEMOTO  filters them out.
145633841545SHajimu UMEMOTO- The following examples are seemingly illegal.  It seems that there's general
1457743eee66SSUZUKI Shinsuke  consensus among ipngwg for those.  (1) Mobile IPv6 home address option,
145833841545SHajimu UMEMOTO  (2) offlink packets (so routers should not forward them).
1459*93b03d5dSUlrich Spörlein  KAME implements (2) already.
14608f336835SJun-ichiro itojun Hagino
14618f336835SJun-ichiro itojun HaginoKAME code is carefully written to avoid such incidents.  More specifically,
1462*93b03d5dSUlrich SpörleinKAME kernel will reject packets with certain source/destination address in IPv6
14638f336835SJun-ichiro itojun Haginobase header, or IPv6 routing header.  Also, KAME default configuration file
14648f336835SJun-ichiro itojun Haginois written carefully, to avoid those attacks.
14658f336835SJun-ichiro itojun Hagino
1466f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-transition-abuse-01.txt, draft-cmetz-v6ops-v4mapped-api-
1467f88fe57eSHajimu UMEMOTOharmful-00.txt and draft-itojun-v6ops-v4mapped-harmful-01.txt has more on
1468f88fe57eSHajimu UMEMOTOthis issue.
14698f336835SJun-ichiro itojun Hagino
14708f336835SJun-ichiro itojun Hagino1.15 Node's required addresses
14718f336835SJun-ichiro itojun Hagino
14728f336835SJun-ichiro itojun HaginoRFC2373 section 2.8 talks about required addresses for an IPv6
14738f336835SJun-ichiro itojun Haginonode.  The section talks about how KAME stack manages those required
14748f336835SJun-ichiro itojun Haginoaddresses.
14758f336835SJun-ichiro itojun Hagino
14768f336835SJun-ichiro itojun Hagino1.15.1 Host case
14778f336835SJun-ichiro itojun Hagino
14788f336835SJun-ichiro itojun HaginoThe following items are automatically assigned to the node (or the node will
14798f336835SJun-ichiro itojun Haginoautomatically joins the group), at bootstrap time:
14808f336835SJun-ichiro itojun Hagino- Loopback address
14818f336835SJun-ichiro itojun Hagino- All-nodes multicast addresses (ff01::1)
14828f336835SJun-ichiro itojun Hagino
14838f336835SJun-ichiro itojun HaginoThe following items will be automatically handled when the interface becomes
14848f336835SJun-ichiro itojun HaginoIFF_UP:
14858f336835SJun-ichiro itojun Hagino- Its link-local address for each interface
14868f336835SJun-ichiro itojun Hagino- Solicited-node multicast address for link-local addresses
14878f336835SJun-ichiro itojun Hagino- Link-local allnodes multicast address (ff02::1)
14888f336835SJun-ichiro itojun Hagino
14898f336835SJun-ichiro itojun HaginoThe following items need to be configured manually by ifconfig(8) or prefix(8).
14908f336835SJun-ichiro itojun HaginoAlternatively, these can be autoconfigured by using stateless address
14918f336835SJun-ichiro itojun Haginoautoconfiguration.
14928f336835SJun-ichiro itojun Hagino- Assigned unicast/anycast addresses
14938f336835SJun-ichiro itojun Hagino- Solicited-Node multicast address for assigned unicast address
14948f336835SJun-ichiro itojun Hagino
14958f336835SJun-ichiro itojun HaginoUsers can join groups by using appropriate system calls like setsockopt(2).
14968f336835SJun-ichiro itojun Hagino
14978f336835SJun-ichiro itojun Hagino1.15.2 Router case
14988f336835SJun-ichiro itojun Hagino
14998f336835SJun-ichiro itojun HaginoIn addition to the above, routers needs to handle the following items.
15008f336835SJun-ichiro itojun Hagino
15018f336835SJun-ichiro itojun HaginoThe following items need to be configured manually by using ifconfig(8).
15028f336835SJun-ichiro itojun Haginoo The subnet-router anycast addresses for the interfaces it is configured
15038f336835SJun-ichiro itojun Hagino  to act as a router on (prefix::/64)
15048f336835SJun-ichiro itojun Haginoo All other anycast addresses with which the router has been configured
15058f336835SJun-ichiro itojun Hagino
15068f336835SJun-ichiro itojun HaginoThe router will join the following multicast group when rtadvd(8) is available
15078f336835SJun-ichiro itojun Haginofor the interface.
15088f336835SJun-ichiro itojun Haginoo All-Routers Multicast Addresses (ff02::2)
15098f336835SJun-ichiro itojun Hagino
15108f336835SJun-ichiro itojun HaginoRouting daemons will join appropriate multicast groups, as necessary,
15118f336835SJun-ichiro itojun Haginolike ff02::9 for RIPng.
15128f336835SJun-ichiro itojun Hagino
15138f336835SJun-ichiro itojun HaginoUsers can join groups by using appropriate system calls like setsockopt(2).
15148f336835SJun-ichiro itojun Hagino
151533841545SHajimu UMEMOTO1.16 Advanced API
151633841545SHajimu UMEMOTO
1517f88fe57eSHajimu UMEMOTOCurrent KAME kernel implements RFC3542 API.  It also implements RFC2292 API,
151833841545SHajimu UMEMOTOfor backward compatibility purposes with *BSD-integrated codebase.
1519f88fe57eSHajimu UMEMOTOKAME tree ships with RFC3542 headers.
1520f88fe57eSHajimu UMEMOTO*BSD-integrated codebase implements either RFC2292, or RFC3542, API.
152133841545SHajimu UMEMOTOsee "COVERAGE" document for detailed implementation status.
152233841545SHajimu UMEMOTO
152333841545SHajimu UMEMOTOHere are couple of issues to mention:
152433841545SHajimu UMEMOTO- *BSD-integrated binaries, compiled for RFC2292, will work on KAME kernel.
152533841545SHajimu UMEMOTO  For example, OpenBSD 2.7 /sbin/rtsol will work on KAME/openbsd kernel.
1526f88fe57eSHajimu UMEMOTO- KAME binaries, compiled using RFC3542, will not work on *BSD-integrated
152733841545SHajimu UMEMOTO  kenrel.  For example, KAME /usr/local/v6/sbin/rtsol will not work on
152833841545SHajimu UMEMOTO  OpenBSD 2.7 kernel.
1529f88fe57eSHajimu UMEMOTO- RFC3542 API is not compatible with RFC2292 API.  RFC3542 #define symbols
153033841545SHajimu UMEMOTO  conflict with RFC2292 symbols.  Therefore, if you compile programs that
153133841545SHajimu UMEMOTO  assume RFC2292 API, the compilation itself goes fine, however, the compiled
153233841545SHajimu UMEMOTO  binary will not work correctly.  The problem is not KAME issue, but API
1533f88fe57eSHajimu UMEMOTO  issue.  For example, Solaris 8 implements RFC3542 API.  If you compile
153433841545SHajimu UMEMOTO  RFC2292-based code on Solaris 8, the binary can behave strange.
153533841545SHajimu UMEMOTO
153633841545SHajimu UMEMOTOThere are few (or couple of) incompatible behavior in RFC2292 binary backward
153733841545SHajimu UMEMOTOcompatibility support in KAME tree.  To enumerate:
153833841545SHajimu UMEMOTO- Type 0 routing header lacks support for strict/loose bitmap.
153933841545SHajimu UMEMOTO  Even if we see packets with "strict" bit set, those bits will not be made
154033841545SHajimu UMEMOTO  visible to the userland.
154133841545SHajimu UMEMOTO  Background: RFC2292 document is based on RFC1883 IPv6, and it uses
1542f88fe57eSHajimu UMEMOTO  strict/loose bitmap.  RFC3542 document is based on RFC2460 IPv6, and it has
154333841545SHajimu UMEMOTO  no strict/loose bitmap (it was removed from RFC2460).  KAME tree obeys
154433841545SHajimu UMEMOTO  RFC2460 IPv6, and lacks support for strict/loose bitmap.
154533841545SHajimu UMEMOTO
1546f88fe57eSHajimu UMEMOTOThe RFC3542 documents leave some particular cases unspecified.  The
1547f88fe57eSHajimu UMEMOTOKAME implementation treats them as follows:
1548f88fe57eSHajimu UMEMOTO- The IPV6_DONTFRAG and IPV6_RECVPATHMTU socket options for TCP
1549f88fe57eSHajimu UMEMOTO  sockets are ignored.  That is, the setsocktopt() call will succeed
1550f88fe57eSHajimu UMEMOTO  but the specified value will have no effect.
1551f88fe57eSHajimu UMEMOTO
1552f88fe57eSHajimu UMEMOTO1.17 DNS resolver
1553f88fe57eSHajimu UMEMOTO
1554f88fe57eSHajimu UMEMOTOKAME ships with modified DNS resolver, in libinet6.a.
1555*93b03d5dSUlrich Spörleinlibinet6.a has a couple of extensions against libc DNS resolver:
1556f88fe57eSHajimu UMEMOTO- Can take "options insecure1" and "options insecure2" in /etc/resolv.conf,
1557f88fe57eSHajimu UMEMOTO  which toggles RES_INSECURE[12] option flag bit.
1558f88fe57eSHajimu UMEMOTO- EDNS0 receive buffer size notification support.  It can be enabled by
1559f88fe57eSHajimu UMEMOTO  "options edns0" in /etc/resolv.conf.  See USAGE for details.
1560f88fe57eSHajimu UMEMOTO- IPv6 transport support (queries/responses over IPv6).  Most of BSD official
1561f88fe57eSHajimu UMEMOTO  releases now has it already.
1562f88fe57eSHajimu UMEMOTO- Partial A6 chain chasing/DNAME/bit string label support (KAME/BSDI4).
1563f88fe57eSHajimu UMEMOTO
1564f88fe57eSHajimu UMEMOTO
156580d21dc4SYoshinobu Inoue2. Network Drivers
156680d21dc4SYoshinobu Inoue
15678f336835SJun-ichiro itojun HaginoKAME requires three items to be added into the standard drivers:
156880d21dc4SYoshinobu Inoue
1569f88fe57eSHajimu UMEMOTO(1) (freebsd[234] and bsdi[34] only) mbuf clustering requirement.
1570f88fe57eSHajimu UMEMOTO    In this stable release, we changed MINCLSIZE into MHLEN+1 for all the
1571f88fe57eSHajimu UMEMOTO    operating systems in order to make all the drivers behave as we expect.
157280d21dc4SYoshinobu Inoue
157380d21dc4SYoshinobu Inoue(2) multicast.  If "ifmcstat" yields no multicast group for a
157480d21dc4SYoshinobu Inoue    interface, that interface has to be patched.
157580d21dc4SYoshinobu Inoue
15768f336835SJun-ichiro itojun HaginoTo avoid troubles, we suggest you to comment out the device drivers
15778f336835SJun-ichiro itojun Haginofor unsupported/unnecessary cards, from the kernel configuration file.
15788f336835SJun-ichiro itojun HaginoIf you accidentally enable unsupported drivers, some of the userland
15798f336835SJun-ichiro itojun Haginotools may not work correctly (routing daemons are typical example).
15808f336835SJun-ichiro itojun Hagino
15818f336835SJun-ichiro itojun HaginoIn the following sections, "official support" means that KAME developers
15828f336835SJun-ichiro itojun Haginoare using that ethernet card/driver frequently.
158380d21dc4SYoshinobu Inoue
158480d21dc4SYoshinobu Inoue(NOTE: In the past we required all pcmcia drivers to have a call to
158580d21dc4SYoshinobu Inouein6_ifattach().  We have no such requirement any more)
158680d21dc4SYoshinobu Inoue
15878f336835SJun-ichiro itojun Hagino2.1 FreeBSD 2.2.x-RELEASE
15888f336835SJun-ichiro itojun Hagino
15898f336835SJun-ichiro itojun HaginoHere is a list of FreeBSD 2.2.x-RELEASE drivers and its conditions:
15908f336835SJun-ichiro itojun Hagino
15918f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
15928f336835SJun-ichiro itojun Hagino	---	---		---		---
15938f336835SJun-ichiro itojun Hagino	(Ethernet)
15948f336835SJun-ichiro itojun Hagino	ar	looks ok	-		-
15958f336835SJun-ichiro itojun Hagino	cnw	ok		ok		yes (*)
15968f336835SJun-ichiro itojun Hagino	ed	ok		ok		yes
15978f336835SJun-ichiro itojun Hagino	ep	ok		ok		yes
15988f336835SJun-ichiro itojun Hagino	fe	ok		ok		yes
15998f336835SJun-ichiro itojun Hagino	sn	looks ok	-		-   (*)
16008f336835SJun-ichiro itojun Hagino	vx	looks ok	-		-
16018f336835SJun-ichiro itojun Hagino	wlp	ok		ok		-   (*)
16028f336835SJun-ichiro itojun Hagino	xl	ok		ok		yes
16038f336835SJun-ichiro itojun Hagino	zp	ok		ok		-
16048f336835SJun-ichiro itojun Hagino	(FDDI)
16058f336835SJun-ichiro itojun Hagino	fpa	looks ok	?		-
16068f336835SJun-ichiro itojun Hagino	(ATM)
16078f336835SJun-ichiro itojun Hagino	en	ok		ok		yes
16088f336835SJun-ichiro itojun Hagino	(Serial)
16098f336835SJun-ichiro itojun Hagino	lp	?		-		not work
16108f336835SJun-ichiro itojun Hagino	sl	?		-		not work
16118f336835SJun-ichiro itojun Hagino	sr	looks ok	ok		-   (**)
16128f336835SJun-ichiro itojun Hagino
16138f336835SJun-ichiro itojun HaginoYou may want to add an invocation of "rtsol" in "/etc/pccard_ether",
16148f336835SJun-ichiro itojun Haginoif you are using notebook computers and PCMCIA ethernet card.
16158f336835SJun-ichiro itojun Hagino
16168f336835SJun-ichiro itojun Hagino(*) These drivers are distributed with PAO (http://www.jp.freebsd.org/PAO/).
16178f336835SJun-ichiro itojun Hagino
16188f336835SJun-ichiro itojun Hagino(**) There was some report says that, if you make sr driver up and down and
16198f336835SJun-ichiro itojun Haginothen up, the kernel may hang up.  We have disabled frame-relay support from
16208f336835SJun-ichiro itojun Haginosr driver and after that this looks to be working fine.  If you need
16218f336835SJun-ichiro itojun Haginoframe-relay support to come back, please contact KAME developers.
16228f336835SJun-ichiro itojun Hagino
16238f336835SJun-ichiro itojun Hagino2.2 BSD/OS 3.x
16248f336835SJun-ichiro itojun Hagino
16258f336835SJun-ichiro itojun HaginoThe following lists BSD/OS 3.x device drivers and its conditions:
16268f336835SJun-ichiro itojun Hagino
16278f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
16288f336835SJun-ichiro itojun Hagino	---	---		---		---
16298f336835SJun-ichiro itojun Hagino	(Ethernet)
16308f336835SJun-ichiro itojun Hagino	cnw	ok		ok		yes
16318f336835SJun-ichiro itojun Hagino	de	ok		ok		-
16328f336835SJun-ichiro itojun Hagino	df	ok		ok		-
16338f336835SJun-ichiro itojun Hagino	eb	ok		ok		-
16348f336835SJun-ichiro itojun Hagino	ef	ok		ok		yes
16358f336835SJun-ichiro itojun Hagino	exp	ok		ok		-
16368f336835SJun-ichiro itojun Hagino	mz	ok		ok		yes
16378f336835SJun-ichiro itojun Hagino	ne	ok		ok		yes
16388f336835SJun-ichiro itojun Hagino	we	ok		ok		-
16398f336835SJun-ichiro itojun Hagino	(FDDI)
16408f336835SJun-ichiro itojun Hagino	fpa	ok		ok		-
16418f336835SJun-ichiro itojun Hagino	(ATM)
16428f336835SJun-ichiro itojun Hagino	en	maybe		ok		-
16438f336835SJun-ichiro itojun Hagino	(Serial)
16448f336835SJun-ichiro itojun Hagino	ntwo	ok		ok		yes
16458f336835SJun-ichiro itojun Hagino	sl	?		-		not work
16468f336835SJun-ichiro itojun Hagino	appp	?		-		not work
16478f336835SJun-ichiro itojun Hagino
16488f336835SJun-ichiro itojun HaginoYou may want to use "@insert" directive in /etc/pccard.conf to invoke
16498f336835SJun-ichiro itojun Hagino"rtsol" command right after dynamic insertion of PCMCIA ethernet cards.
16508f336835SJun-ichiro itojun Hagino
16518f336835SJun-ichiro itojun Hagino2.3 NetBSD
16528f336835SJun-ichiro itojun Hagino
16538f336835SJun-ichiro itojun HaginoThe following table lists the network drivers we have tried so far.
16548f336835SJun-ichiro itojun Hagino
16558f336835SJun-ichiro itojun Hagino	driver		mbuf(1)	multicast(2)	official support?
16568f336835SJun-ichiro itojun Hagino	---		---	---		---
16578f336835SJun-ichiro itojun Hagino	(Ethernet)
16588f336835SJun-ichiro itojun Hagino	awi pcmcia/i386	ok	ok		-
16598f336835SJun-ichiro itojun Hagino	bah zbus/amiga	NG(*)
16608f336835SJun-ichiro itojun Hagino	cnw pcmcia/i386	ok	ok		yes
16618f336835SJun-ichiro itojun Hagino	ep pcmcia/i386	ok	ok		-
1662743eee66SSUZUKI Shinsuke	fxp pci/i386	ok(*2)	ok		-
1663743eee66SSUZUKI Shinsuke	tlp pci/i386	ok	ok		-
16648f336835SJun-ichiro itojun Hagino	le sbus/sparc	ok	ok		yes
16658f336835SJun-ichiro itojun Hagino	ne pci/i386	ok	ok		yes
16668f336835SJun-ichiro itojun Hagino	ne pcmcia/i386	ok	ok		yes
1667743eee66SSUZUKI Shinsuke	rtk pci/i386	ok	ok		-
16688f336835SJun-ichiro itojun Hagino	wi pcmcia/i386	ok	ok		yes
16698f336835SJun-ichiro itojun Hagino	(ATM)
16708f336835SJun-ichiro itojun Hagino	en pci/i386	ok	ok		-
16718f336835SJun-ichiro itojun Hagino
16728f336835SJun-ichiro itojun Hagino(*) This may need some fix, but I'm not sure what arcnet interfaces assume...
16738f336835SJun-ichiro itojun Hagino
16748f336835SJun-ichiro itojun Hagino2.4 FreeBSD 3.x-RELEASE
16758f336835SJun-ichiro itojun Hagino
16768f336835SJun-ichiro itojun HaginoHere is a list of FreeBSD 3.x-RELEASE drivers and its conditions:
16778f336835SJun-ichiro itojun Hagino
16788f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
16798f336835SJun-ichiro itojun Hagino	---	---		---		---
16808f336835SJun-ichiro itojun Hagino	(Ethernet)
16818f336835SJun-ichiro itojun Hagino	cnw	ok		ok		-(*)
16828f336835SJun-ichiro itojun Hagino	ed	?		ok		-
16838f336835SJun-ichiro itojun Hagino	ep	ok		ok		-
16848f336835SJun-ichiro itojun Hagino	fe	ok		ok		yes
16858f336835SJun-ichiro itojun Hagino	fxp	?(**)
16868f336835SJun-ichiro itojun Hagino	lnc	?		ok		-
16878f336835SJun-ichiro itojun Hagino	sn	?		?		-(*)
16888f336835SJun-ichiro itojun Hagino	wi	ok		ok		yes
16898f336835SJun-ichiro itojun Hagino	xl	?		ok		-
16908f336835SJun-ichiro itojun Hagino
16918f336835SJun-ichiro itojun Hagino(*) These drivers are distributed with PAO as PAO3
16928f336835SJun-ichiro itojun Hagino    (http://www.jp.freebsd.org/PAO/).
1693743eee66SSUZUKI Shinsuke(**) there were trouble reports with multicast filter initialization.
16948f336835SJun-ichiro itojun Hagino
16958f336835SJun-ichiro itojun HaginoMore drivers will just simply work on KAME FreeBSD 3.x-RELEASE but have not
16968f336835SJun-ichiro itojun Haginobeen checked yet.
16978f336835SJun-ichiro itojun Hagino
169833841545SHajimu UMEMOTO2.5 FreeBSD 4.x-RELEASE
169933841545SHajimu UMEMOTO
170033841545SHajimu UMEMOTOHere is a list of FreeBSD 4.x-RELEASE drivers and its conditions:
170133841545SHajimu UMEMOTO
170233841545SHajimu UMEMOTO	driver		multicast
170333841545SHajimu UMEMOTO	---		---
170433841545SHajimu UMEMOTO	(Ethernet)
170533841545SHajimu UMEMOTO	lnc/vmware	ok
170633841545SHajimu UMEMOTO
170733841545SHajimu UMEMOTO2.6 OpenBSD 2.x
17088f336835SJun-ichiro itojun Hagino
17098f336835SJun-ichiro itojun HaginoHere is a list of OpenBSD 2.x drivers and its conditions:
17108f336835SJun-ichiro itojun Hagino
17118f336835SJun-ichiro itojun Hagino	driver		mbuf(1)		multicast(2)	official support?
17128f336835SJun-ichiro itojun Hagino	---		---		---		---
17138f336835SJun-ichiro itojun Hagino	(Ethernet)
17148f336835SJun-ichiro itojun Hagino	de pci/i386	ok		ok		yes
17158f336835SJun-ichiro itojun Hagino	fxp pci/i386	?(*)
17168f336835SJun-ichiro itojun Hagino	le sbus/sparc	ok		ok		yes
17178f336835SJun-ichiro itojun Hagino	ne pci/i386	ok		ok		yes
17188f336835SJun-ichiro itojun Hagino	ne pcmcia/i386	ok		ok		yes
17198f336835SJun-ichiro itojun Hagino	wi pcmcia/i386	ok		ok		yes
17208f336835SJun-ichiro itojun Hagino
17218f336835SJun-ichiro itojun Hagino(*) There seem to be some problem in driver, with multicast filter
17228f336835SJun-ichiro itojun Haginoconfiguration.  This happens with certain revision of chipset on the card.
17238f336835SJun-ichiro itojun HaginoShould be fixed by now by workaround in sys/net/if.c, but still not sure.
17248f336835SJun-ichiro itojun Hagino
172533841545SHajimu UMEMOTO2.7 BSD/OS 4.x
17268f336835SJun-ichiro itojun Hagino
17278f336835SJun-ichiro itojun HaginoThe following lists BSD/OS 4.x device drivers and its conditions:
17288f336835SJun-ichiro itojun Hagino
17298f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
17308f336835SJun-ichiro itojun Hagino	---	---		---		---
17318f336835SJun-ichiro itojun Hagino	(Ethernet)
17328f336835SJun-ichiro itojun Hagino	de	ok		ok		yes
17338f336835SJun-ichiro itojun Hagino	exp	(*)
17348f336835SJun-ichiro itojun Hagino
17358f336835SJun-ichiro itojun HaginoYou may want to use "@insert" directive in /etc/pccard.conf to invoke
17368f336835SJun-ichiro itojun Hagino"rtsol" command right after dynamic insertion of PCMCIA ethernet cards.
17378f336835SJun-ichiro itojun Hagino
17388f336835SJun-ichiro itojun Hagino(*) exp driver has serious conflict with KAME initialization sequence.
17398f336835SJun-ichiro itojun HaginoA workaround is committed into sys/i386/pci/if_exp.c, and should be okay by now.
17408f336835SJun-ichiro itojun Hagino
1741743eee66SSUZUKI Shinsuke
174280d21dc4SYoshinobu Inoue3. Translator
174380d21dc4SYoshinobu Inoue
174480d21dc4SYoshinobu InoueWe categorize IPv4/IPv6 translator into 4 types.
174580d21dc4SYoshinobu Inoue
174680d21dc4SYoshinobu InoueTranslator A --- It is used in the early stage of transition to make
174780d21dc4SYoshinobu Inoueit possible to establish a connection from an IPv6 host in an IPv6
174880d21dc4SYoshinobu Inoueisland to an IPv4 host in the IPv4 ocean.
174980d21dc4SYoshinobu Inoue
175080d21dc4SYoshinobu InoueTranslator B --- It is used in the early stage of transition to make
175180d21dc4SYoshinobu Inoueit possible to establish a connection from an IPv4 host in the IPv4
175280d21dc4SYoshinobu Inoueocean to an IPv6 host in an IPv6 island.
175380d21dc4SYoshinobu Inoue
175480d21dc4SYoshinobu InoueTranslator C --- It is used in the late stage of transition to make it
175580d21dc4SYoshinobu Inouepossible to establish a connection from an IPv4 host in an IPv4 island
175680d21dc4SYoshinobu Inoueto an IPv6 host in the IPv6 ocean.
175780d21dc4SYoshinobu Inoue
175880d21dc4SYoshinobu InoueTranslator D --- It is used in the late stage of transition to make it
175980d21dc4SYoshinobu Inouepossible to establish a connection from an IPv6 host in the IPv6 ocean
176080d21dc4SYoshinobu Inoueto an IPv4 host in an IPv4 island.
176180d21dc4SYoshinobu Inoue
176280d21dc4SYoshinobu InoueKAME provides an TCP relay translator for category A.  This is called
176380d21dc4SYoshinobu Inoue"FAITH".  We also provide IP header translator for category A.
176480d21dc4SYoshinobu Inoue
176580d21dc4SYoshinobu Inoue3.1 FAITH TCP relay translator
176680d21dc4SYoshinobu Inoue
176780d21dc4SYoshinobu InoueFAITH system uses TCP relay daemon called "faithd" helped by the KAME kernel.
176880d21dc4SYoshinobu InoueFAITH will reserve an IPv6 address prefix, and relay TCP connection
176980d21dc4SYoshinobu Inouetoward that prefix to IPv4 destination.
177080d21dc4SYoshinobu Inoue
177180d21dc4SYoshinobu InoueFor example, if the reserved IPv6 prefix is 3ffe:0501:0200:ffff::, and
177280d21dc4SYoshinobu Inouethe IPv6 destination for TCP connection is 3ffe:0501:0200:ffff::163.221.202.12,
177380d21dc4SYoshinobu Inouethe connection will be relayed toward IPv4 destination 163.221.202.12.
177480d21dc4SYoshinobu Inoue
177580d21dc4SYoshinobu Inoue	destination IPv4 node (163.221.202.12)
177680d21dc4SYoshinobu Inoue	  ^
177780d21dc4SYoshinobu Inoue	  | IPv4 tcp toward 163.221.202.12
177880d21dc4SYoshinobu Inoue	FAITH-relay dual stack node
177980d21dc4SYoshinobu Inoue	  ^
178080d21dc4SYoshinobu Inoue	  | IPv6 TCP toward 3ffe:0501:0200:ffff::163.221.202.12
178180d21dc4SYoshinobu Inoue	source IPv6 node
178280d21dc4SYoshinobu Inoue
178380d21dc4SYoshinobu Inouefaithd must be invoked on FAITH-relay dual stack node.
178480d21dc4SYoshinobu Inoue
1785743eee66SSUZUKI ShinsukeFor more details, consult kame/kame/faithd/README and RFC3142.
178680d21dc4SYoshinobu Inoue
178780d21dc4SYoshinobu Inoue3.2 IPv6-to-IPv4 header translator
178880d21dc4SYoshinobu Inoue
178933841545SHajimu UMEMOTO(to be written)
179080d21dc4SYoshinobu Inoue
1791743eee66SSUZUKI Shinsuke
179280d21dc4SYoshinobu Inoue4. IPsec
179380d21dc4SYoshinobu Inoue
17948f336835SJun-ichiro itojun HaginoIPsec is implemented as the following three components.
179580d21dc4SYoshinobu Inoue
179680d21dc4SYoshinobu Inoue(1) Policy Management
179780d21dc4SYoshinobu Inoue(2) Key Management
17988f336835SJun-ichiro itojun Hagino(3) AH, ESP and IPComp handling in kernel
17998f336835SJun-ichiro itojun Hagino
18008f336835SJun-ichiro itojun HaginoNote that KAME/OpenBSD does NOT include support for KAME IPsec code,
18018f336835SJun-ichiro itojun Haginoas OpenBSD team has their home-brew IPsec stack and they have no plan
18028f336835SJun-ichiro itojun Haginoto replace it.  IPv6 support for IPsec is, therefore, lacking on KAME/OpenBSD.
180380d21dc4SYoshinobu Inoue
180433841545SHajimu UMEMOTOhttp://www.netbsd.org/Documentation/network/ipsec/ has more information
180533841545SHajimu UMEMOTOincluding usage examples.
180633841545SHajimu UMEMOTO
180780d21dc4SYoshinobu Inoue4.1 Policy Management
180880d21dc4SYoshinobu Inoue
1809f88fe57eSHajimu UMEMOTOThe kernel implements experimental policy management code.  There are two ways
181080d21dc4SYoshinobu Inoueto manage security policy.  One is to configure per-socket policy using
181180d21dc4SYoshinobu Inouesetsockopt(3).  In this cases, policy configuration is described in
181280d21dc4SYoshinobu Inoueipsec_set_policy(3).  The other is to configure kernel packet filter-based
181380d21dc4SYoshinobu Inouepolicy using PF_KEY interface, via setkey(8).
181480d21dc4SYoshinobu Inoue
18158f336835SJun-ichiro itojun HaginoThe policy entry will be matched in order.  The order of entries makes
18168f336835SJun-ichiro itojun Haginodifference in behavior.
181780d21dc4SYoshinobu Inoue
181880d21dc4SYoshinobu Inoue4.2 Key Management
181980d21dc4SYoshinobu Inoue
182080d21dc4SYoshinobu InoueThe key management code implemented in this kit (sys/netkey) is a
182180d21dc4SYoshinobu Inouehome-brew PFKEY v2 implementation.  This conforms to RFC2367.
182280d21dc4SYoshinobu Inoue
18238f336835SJun-ichiro itojun HaginoThe home-brew IKE daemon, "racoon" is included in the kit (kame/kame/racoon,
18248f336835SJun-ichiro itojun Haginoor usr.sbin/racoon).
182580d21dc4SYoshinobu InoueBasically you'll need to run racoon as daemon, then setup a policy
182680d21dc4SYoshinobu Inoueto require keys (like ping -P 'out ipsec esp/transport//use').
182780d21dc4SYoshinobu InoueThe kernel will contact racoon daemon as necessary to exchange keys.
182880d21dc4SYoshinobu Inoue
18298f336835SJun-ichiro itojun HaginoIn IKE spec, there's ambiguity about interpretation of "tunnel" proposal.
18308f336835SJun-ichiro itojun HaginoFor example, if we would like to propose the use of following packet:
18318f336835SJun-ichiro itojun Hagino	IP AH ESP IP payload
18328f336835SJun-ichiro itojun Haginosome implementation proposes it as "AH transport and ESP tunnel", since
18338f336835SJun-ichiro itojun Haginothis is more logical from packet construction point of view.  Some
18348f336835SJun-ichiro itojun Haginoimplementation proposes it as "AH tunnel and ESP tunnel".
1835f88fe57eSHajimu UMEMOTORacoon follows the latter route (previously it followed the former, and
1836f88fe57eSHajimu UMEMOTOthe latter interpretation seems to be popular/consensus).
18378f336835SJun-ichiro itojun HaginoThis raises real interoperability issue.  We hope this to be resolved quickly.
18388f336835SJun-ichiro itojun Hagino
1839f88fe57eSHajimu UMEMOTOracoon does not implement byte lifetime for both phase 1 and phase 2
1840f88fe57eSHajimu UMEMOTO(RFC2409 page 35, Life Type = kilobytes).
1841f88fe57eSHajimu UMEMOTO
184280d21dc4SYoshinobu Inoue4.3 AH and ESP handling
184380d21dc4SYoshinobu Inoue
184480d21dc4SYoshinobu InoueIPsec module is implemented as "hooks" to the standard IPv4/IPv6
184580d21dc4SYoshinobu Inoueprocessing.  When sending a packet, ip{,6}_output() checks if ESP/AH
184680d21dc4SYoshinobu Inoueprocessing is required by checking if a matching SPD (Security
184780d21dc4SYoshinobu InouePolicy Database) is found.  If ESP/AH is needed,
184880d21dc4SYoshinobu Inoue{esp,ah}{4,6}_output() will be called and mbuf will be updated
184980d21dc4SYoshinobu Inoueaccordingly.  When a packet is received, {esp,ah}4_input() will be
185080d21dc4SYoshinobu Inouecalled based on protocol number, i.e. (*inetsw[proto])().
185180d21dc4SYoshinobu Inoue{esp,ah}4_input() will decrypt/check authenticity of the packet,
185280d21dc4SYoshinobu Inoueand strips off daisy-chained header and padding for ESP/AH.  It is
185380d21dc4SYoshinobu Inouesafe to strip off the ESP/AH header on packet reception, since we
185480d21dc4SYoshinobu Inouewill never use the received packet in "as is" form.
185580d21dc4SYoshinobu Inoue
185680d21dc4SYoshinobu InoueBy using ESP/AH, TCP4/6 effective data segment size will be affected by
185780d21dc4SYoshinobu Inoueextra daisy-chained headers inserted by ESP/AH.  Our code takes care of
185880d21dc4SYoshinobu Inouethe case.
185980d21dc4SYoshinobu Inoue
186080d21dc4SYoshinobu InoueBasic crypto functions can be found in directory "sys/crypto".  ESP/AH
186180d21dc4SYoshinobu Inouetransform are listed in {esp,ah}_core.c with wrapper functions.  If you
186280d21dc4SYoshinobu Inouewish to add some algorithm, add wrapper function in {esp,ah}_core.c, and
186380d21dc4SYoshinobu Inoueadd your crypto algorithm code into sys/crypto.
186480d21dc4SYoshinobu Inoue
18658f336835SJun-ichiro itojun HaginoTunnel mode works basically fine, but comes with the following restrictions:
18668f336835SJun-ichiro itojun Hagino- You cannot run routing daemon across IPsec tunnel, since we do not model
18678f336835SJun-ichiro itojun Hagino  IPsec tunnel as pseudo interfaces.
186880d21dc4SYoshinobu Inoue- Authentication model for AH tunnel must be revisited.  We'll need to
186980d21dc4SYoshinobu Inoue  improve the policy management engine, eventually.
187033841545SHajimu UMEMOTO- Path MTU discovery does not work across IPv6 IPsec tunnel gateway due to
187133841545SHajimu UMEMOTO  insufficient code.
187280d21dc4SYoshinobu Inoue
1873*93b03d5dSUlrich SpörleinAH specification does not talk much about "multiple AH on a packet" case.
18748f336835SJun-ichiro itojun HaginoWe incrementally compute AH checksum, from inside to outside.  Also, we
18758f336835SJun-ichiro itojun Haginotreat inner AH to be immutable.
18768f336835SJun-ichiro itojun HaginoFor example, if we are to create the following packet:
18778f336835SJun-ichiro itojun Hagino	IP AH1 AH2 AH3 payload
18788f336835SJun-ichiro itojun Haginowe do it incrementally.  As a result, we get crypto checksums like below:
18798f336835SJun-ichiro itojun Hagino	AH3 has checksum against "IP AH3' payload".
18808f336835SJun-ichiro itojun Hagino		where AH3' = AH3 with checksum field filled with 0.
18818f336835SJun-ichiro itojun Hagino	AH2 has checksum against "IP AH2' AH3 payload".
18828f336835SJun-ichiro itojun Hagino	AH1 has checksum against "IP AH1' AH2 AH3 payload",
18838f336835SJun-ichiro itojun HaginoAlso note that AH3 has the smallest sequence number, and AH1 has the largest
18848f336835SJun-ichiro itojun Haginosequence number.
18858f336835SJun-ichiro itojun Hagino
188633841545SHajimu UMEMOTOTo avoid traffic analysis on shorter packets, ESP output logic supports
188733841545SHajimu UMEMOTOrandom length padding.  By setting net.inet.ipsec.esp_randpad (or
188833841545SHajimu UMEMOTOnet.inet6.ipsec6.esp_randpad) to positive value N, you can ask the kernel
188933841545SHajimu UMEMOTOto randomly pad packets shorter than N bytes, to random length smaller than
189033841545SHajimu UMEMOTOor equal to N.  Note that N does not include ESP authentication data length.
189133841545SHajimu UMEMOTOAlso note that the random padding is not included in TCP segment
189233841545SHajimu UMEMOTOsize computation.  Negative value will turn off the functionality.
1893*93b03d5dSUlrich SpörleinRecommended value for N is like 128, or 256.  If you use a too big number
1894*93b03d5dSUlrich Spörleinas N, you may experience inefficiency due to fragmented packets.
189533841545SHajimu UMEMOTO
18968f336835SJun-ichiro itojun Hagino4.4 IPComp handling
18978f336835SJun-ichiro itojun Hagino
18988f336835SJun-ichiro itojun HaginoIPComp stands for IP payload compression protocol.  This is aimed for
18998f336835SJun-ichiro itojun Haginopayload compression, not the header compression like PPP VJ compression.
19008f336835SJun-ichiro itojun HaginoThis may be useful when you are using slow serial link (say, cell phone)
19018f336835SJun-ichiro itojun Haginowith powerful CPU (well, recent notebook PCs are really powerful...).
19028f336835SJun-ichiro itojun HaginoThe protocol design of IPComp is very similar to IPsec, though it was
19038f336835SJun-ichiro itojun Haginodefined separately from IPsec itself.
19048f336835SJun-ichiro itojun Hagino
19058f336835SJun-ichiro itojun HaginoHere are some points to be noted:
19068f336835SJun-ichiro itojun Hagino- IPComp is treated as part of IPsec protocol suite, and SPI and
19078f336835SJun-ichiro itojun Hagino  CPI space is unified.  Spec says that there's no relationship
19088f336835SJun-ichiro itojun Hagino  between two so they are assumed to be separate in specs.
19098f336835SJun-ichiro itojun Hagino- IPComp association (IPCA) is kept in SAD.
19108f336835SJun-ichiro itojun Hagino- It is possible to use well-known CPI (CPI=2 for DEFLATE for example),
19118f336835SJun-ichiro itojun Hagino  for outbound/inbound packet, but for indexing purposes one element from
19128f336835SJun-ichiro itojun Hagino  SPI/CPI space will be occupied anyway.
19138f336835SJun-ichiro itojun Hagino- pfkey is modified to support IPComp.  However, there's no official
19148f336835SJun-ichiro itojun Hagino  SA type number assignment yet.  Portability with other IPComp
19158f336835SJun-ichiro itojun Hagino  stack is questionable (anyway, who else implement IPComp on UN*X?).
19168f336835SJun-ichiro itojun Hagino- Spec says that IPComp output processing must be performed before AH/ESP
19178f336835SJun-ichiro itojun Hagino  output processing, to achieve better compression ratio and "stir" data
19188f336835SJun-ichiro itojun Hagino  stream before encryption.  The most meaningful processing order is:
19198f336835SJun-ichiro itojun Hagino  (1) compress payload by IPComp, (2) encrypt payload by ESP, then (3) attach
19208f336835SJun-ichiro itojun Hagino  authentication data by AH.
19218f336835SJun-ichiro itojun Hagino  However, with manual SPD setting, you are able to violate the ordering
19228f336835SJun-ichiro itojun Hagino  (KAME code is too generic, maybe).  Also, it is just okay to use IPComp
19238f336835SJun-ichiro itojun Hagino  alone, without AH/ESP.
19248f336835SJun-ichiro itojun Hagino- Though the packet size can be significantly decreased by using IPComp, no
19258f336835SJun-ichiro itojun Hagino  special consideration is made about path MTU (spec talks nothing about MTU
19268f336835SJun-ichiro itojun Hagino  consideration).  IPComp is designed for serial links, not ethernet-like
19278f336835SJun-ichiro itojun Hagino  medium, it seems.
19288f336835SJun-ichiro itojun Hagino- You can change compression ratio on outbound packet, by changing
19298f336835SJun-ichiro itojun Hagino  deflate_policy in sys/netinet6/ipcomp_core.c.  You can also change outbound
19308f336835SJun-ichiro itojun Hagino  history buffer size by changing deflate_window_out in the same source code.
19318f336835SJun-ichiro itojun Hagino  (should it be sysctl accessible, or per-SAD configurable?)
19328f336835SJun-ichiro itojun Hagino- Tunnel mode IPComp is not working right.  KAME box can generate tunnelled
19338f336835SJun-ichiro itojun Hagino  IPComp packet, however, cannot accept tunneled IPComp packet.
19348f336835SJun-ichiro itojun Hagino- You can negotiate IPComp association with racoon IKE daemon.
19358f336835SJun-ichiro itojun Hagino- KAME code does not attach Adler32 checksum to compressed data.
19368f336835SJun-ichiro itojun Hagino  see ipsec wg mailing list discussion in Jan 2000 for details.
19378f336835SJun-ichiro itojun Hagino
19388f336835SJun-ichiro itojun Hagino4.5 Conformance to RFCs and IDs
193980d21dc4SYoshinobu Inoue
194080d21dc4SYoshinobu InoueThe IPsec code in the kernel conforms (or, tries to conform) to the
194180d21dc4SYoshinobu Inouefollowing standards:
194280d21dc4SYoshinobu Inoue    "old IPsec" specification documented in rfc182[5-9].txt
194333841545SHajimu UMEMOTO    "new IPsec" specification documented in:
1944f88fe57eSHajimu UMEMOTO	rfc240[1-6].txt rfc241[01].txt rfc2451.txt rfc3602.txt
19458f336835SJun-ichiro itojun Hagino    IPComp:
19468f336835SJun-ichiro itojun Hagino	RFC2393: IP Payload Compression Protocol (IPComp)
194733841545SHajimu UMEMOTOIKE specifications (rfc240[7-9].txt) are implemented in userland
194833841545SHajimu UMEMOTOas "racoon" IKE daemon.
194980d21dc4SYoshinobu Inoue
195080d21dc4SYoshinobu InoueCurrently supported algorithms are:
195180d21dc4SYoshinobu Inoue    old IPsec AH
195280d21dc4SYoshinobu Inoue	null crypto checksum (no document, just for debugging)
195380d21dc4SYoshinobu Inoue	keyed MD5 with 128bit crypto checksum (rfc1828.txt)
195480d21dc4SYoshinobu Inoue	keyed SHA1 with 128bit crypto checksum (no document)
195580d21dc4SYoshinobu Inoue	HMAC MD5 with 128bit crypto checksum (rfc2085.txt)
195680d21dc4SYoshinobu Inoue	HMAC SHA1 with 128bit crypto checksum (no document)
1957492528c0SHajimu UMEMOTO	HMAC RIPEMD160 with 128bit crypto checksum (no document)
195880d21dc4SYoshinobu Inoue    old IPsec ESP
195980d21dc4SYoshinobu Inoue	null encryption (no document, similar to rfc2410.txt)
196080d21dc4SYoshinobu Inoue	DES-CBC mode (rfc1829.txt)
196180d21dc4SYoshinobu Inoue    new IPsec AH
196280d21dc4SYoshinobu Inoue	null crypto checksum (no document, just for debugging)
196380d21dc4SYoshinobu Inoue	keyed MD5 with 96bit crypto checksum (no document)
196480d21dc4SYoshinobu Inoue	keyed SHA1 with 96bit crypto checksum (no document)
196580d21dc4SYoshinobu Inoue	HMAC MD5 with 96bit crypto checksum (rfc2403.txt
196680d21dc4SYoshinobu Inoue	HMAC SHA1 with 96bit crypto checksum (rfc2404.txt)
1967743eee66SSUZUKI Shinsuke	HMAC SHA2-256 with 96bit crypto checksum (draft-ietf-ipsec-ciph-sha-256-00.txt)
196833841545SHajimu UMEMOTO	HMAC SHA2-384 with 96bit crypto checksum (no document)
196933841545SHajimu UMEMOTO	HMAC SHA2-512 with 96bit crypto checksum (no document)
1970492528c0SHajimu UMEMOTO	HMAC RIPEMD160 with 96bit crypto checksum (RFC2857)
1971b42ac57fSHajimu UMEMOTO	AES XCBC MAC with 96bit crypto checksum (RFC3566)
197280d21dc4SYoshinobu Inoue    new IPsec ESP
197380d21dc4SYoshinobu Inoue	null encryption (rfc2410.txt)
197480d21dc4SYoshinobu Inoue	DES-CBC with derived IV
197580d21dc4SYoshinobu Inoue		(draft-ietf-ipsec-ciph-des-derived-01.txt, draft expired)
197680d21dc4SYoshinobu Inoue	DES-CBC with explicit IV (rfc2405.txt)
197780d21dc4SYoshinobu Inoue	3DES-CBC with explicit IV (rfc2451.txt)
197880d21dc4SYoshinobu Inoue	BLOWFISH CBC (rfc2451.txt)
197980d21dc4SYoshinobu Inoue	CAST128 CBC (rfc2451.txt)
1980b42ac57fSHajimu UMEMOTO	RIJNDAEL/AES CBC (rfc3602.txt)
1981743eee66SSUZUKI Shinsuke	AES counter mode (rfc3686.txt)
1982b42ac57fSHajimu UMEMOTO
1983743eee66SSUZUKI Shinsuke	each of the above can be combined with new IPsec AH schemes for
1984743eee66SSUZUKI Shinsuke	ESP authentication.
19858f336835SJun-ichiro itojun Hagino    IPComp
19868f336835SJun-ichiro itojun Hagino	RFC2394: IP Payload Compression Using DEFLATE
198780d21dc4SYoshinobu Inoue
198880d21dc4SYoshinobu InoueThe following algorithms are NOT supported:
198980d21dc4SYoshinobu Inoue    old IPsec AH
199080d21dc4SYoshinobu Inoue	HMAC MD5 with 128bit crypto checksum + 64bit replay prevention
199180d21dc4SYoshinobu Inoue		(rfc2085.txt)
199280d21dc4SYoshinobu Inoue	keyed SHA1 with 160bit crypto checksum + 32bit padding (rfc1852.txt)
199380d21dc4SYoshinobu Inoue
19948f336835SJun-ichiro itojun HaginoThe key/policy management API is based on the following document, with fair
19958f336835SJun-ichiro itojun Haginoamount of extensions:
19968f336835SJun-ichiro itojun Hagino	RFC2367: PF_KEY key management API
199780d21dc4SYoshinobu Inoue
19988f336835SJun-ichiro itojun Hagino4.6 ECN consideration on IPsec tunnels
199980d21dc4SYoshinobu Inoue
200080d21dc4SYoshinobu InoueKAME IPsec implements ECN-friendly IPsec tunnel, described in
20018f336835SJun-ichiro itojun Haginodraft-ietf-ipsec-ecn-02.txt.
200280d21dc4SYoshinobu InoueNormal IPsec tunnel is described in RFC2401.  On encapsulation,
200380d21dc4SYoshinobu InoueIPv4 TOS field (or, IPv6 traffic class field) will be copied from inner
200480d21dc4SYoshinobu InoueIP header to outer IP header.  On decapsulation outer IP header
200580d21dc4SYoshinobu Inouewill be simply dropped.  The decapsulation rule is not compatible
200680d21dc4SYoshinobu Inouewith ECN, since ECN bit on the outer IP TOS/traffic class field will be
200780d21dc4SYoshinobu Inouelost.
200880d21dc4SYoshinobu InoueTo make IPsec tunnel ECN-friendly, we should modify encapsulation
200980d21dc4SYoshinobu Inoueand decapsulation procedure.  This is described in
20108f336835SJun-ichiro itojun Haginodraft-ietf-ipsec-ecn-02.txt, chapter 3.3.
201180d21dc4SYoshinobu Inoue
201280d21dc4SYoshinobu InoueKAME IPsec tunnel implementation can give you three behaviors, by setting
201380d21dc4SYoshinobu Inouenet.inet.ipsec.ecn (or net.inet6.ipsec6.ecn) to some value:
201480d21dc4SYoshinobu Inoue- RFC2401: no consideration for ECN (sysctl value -1)
201580d21dc4SYoshinobu Inoue- ECN forbidden (sysctl value 0)
201680d21dc4SYoshinobu Inoue- ECN allowed (sysctl value 1)
201780d21dc4SYoshinobu InoueNote that the behavior is configurable in per-node manner, not per-SA manner
20188f336835SJun-ichiro itojun Hagino(draft-ietf-ipsec-ecn-02 wants per-SA configuration, but it looks too much
20198f336835SJun-ichiro itojun Haginofor me).
202080d21dc4SYoshinobu Inoue
202180d21dc4SYoshinobu InoueThe behavior is summarized as follows (see source code for more detail):
202280d21dc4SYoshinobu Inoue
202380d21dc4SYoshinobu Inoue		encapsulate			decapsulate
202480d21dc4SYoshinobu Inoue		---				---
202580d21dc4SYoshinobu InoueRFC2401		copy all TOS bits		drop TOS bits on outer
202680d21dc4SYoshinobu Inoue		from inner to outer.		(use inner TOS bits as is)
202780d21dc4SYoshinobu Inoue
202880d21dc4SYoshinobu InoueECN forbidden	copy TOS bits except for ECN	drop TOS bits on outer
202980d21dc4SYoshinobu Inoue		(masked with 0xfc) from inner	(use inner TOS bits as is)
203080d21dc4SYoshinobu Inoue		to outer.  set ECN bits to 0.
203180d21dc4SYoshinobu Inoue
203280d21dc4SYoshinobu InoueECN allowed	copy TOS bits except for ECN	use inner TOS bits with some
203380d21dc4SYoshinobu Inoue		CE (masked with 0xfe) from	change.  if outer ECN CE bit
203480d21dc4SYoshinobu Inoue		inner to outer.			is 1, enable ECN CE bit on
203580d21dc4SYoshinobu Inoue		set ECN CE bit to 0.		the inner.
203680d21dc4SYoshinobu Inoue
203780d21dc4SYoshinobu InoueGeneral strategy for configuration is as follows:
203880d21dc4SYoshinobu Inoue- if both IPsec tunnel endpoint are capable of ECN-friendly behavior,
203980d21dc4SYoshinobu Inoue  you'd better configure both end to "ECN allowed" (sysctl value 1).
204080d21dc4SYoshinobu Inoue- if the other end is very strict about TOS bit, use "RFC2401"
204180d21dc4SYoshinobu Inoue  (sysctl value -1).
204280d21dc4SYoshinobu Inoue- in other cases, use "ECN forbidden" (sysctl value 0).
204380d21dc4SYoshinobu InoueThe default behavior is "ECN forbidden" (sysctl value 0).
204480d21dc4SYoshinobu Inoue
204580d21dc4SYoshinobu InoueFor more information, please refer to:
20468f336835SJun-ichiro itojun Hagino	draft-ietf-ipsec-ecn-02.txt
204780d21dc4SYoshinobu Inoue	RFC2481 (Explicit Congestion Notification)
204880d21dc4SYoshinobu Inoue	KAME sys/netinet6/{ah,esp}_input.c
204980d21dc4SYoshinobu Inoue
205080d21dc4SYoshinobu Inoue(Thanks goes to Kenjiro Cho <[email protected]> for detailed analysis)
205180d21dc4SYoshinobu Inoue
20528f336835SJun-ichiro itojun Hagino4.7 Interoperability
20538f336835SJun-ichiro itojun Hagino
20548f336835SJun-ichiro itojun HaginoIPsec, IPComp (in kernel) and IKE (in userland as "racoon") has been tested
20558f336835SJun-ichiro itojun Haginoat several interoperability test events, and it is known to interoperate
20568f336835SJun-ichiro itojun Haginowith many other implementations well.  Also, KAME IPsec has quite wide
20578f336835SJun-ichiro itojun Haginocoverage for IPsec crypto algorithms documented in RFC (we do not cover
20588f336835SJun-ichiro itojun Haginoalgorithms with intellectual property issues, though).
205980d21dc4SYoshinobu Inoue
206080d21dc4SYoshinobu InoueHere are (some of) platforms we have tested IPsec/IKE interoperability
206133841545SHajimu UMEMOTOin the past, no particular order.  Note that both ends (KAME and
20628f336835SJun-ichiro itojun Haginoothers) may have modified their implementation, so use the following
20638f336835SJun-ichiro itojun Haginolist just for reference purposes.
2064743eee66SSUZUKI Shinsuke	6WIND, ACC, Allied-telesis, Altiga, Ashley-laurent (vpcom.com),
2065743eee66SSUZUKI Shinsuke	BlueSteel, CISCO IOS, Checkpoint FW-1, Compaq Tru54 UNIX
2066743eee66SSUZUKI Shinsuke	X5.1B-BL4, Cryptek, Data Fellows (F-Secure), Ericsson,
2067743eee66SSUZUKI Shinsuke	F-Secure VPN+ 5.40, Fitec, Fitel, FreeS/WAN, HITACHI, HiFn,
2068743eee66SSUZUKI Shinsuke	IBM AIX 5.1, III, IIJ (fujie stack), Intel Canada, Intel
2069743eee66SSUZUKI Shinsuke	Packet Protect, MEW NetCocoon, MGCS, Microsoft WinNT/2000/XP,
2070743eee66SSUZUKI Shinsuke	NAI PGPnet, NEC IX5000, NIST (linux IPsec + plutoplus),
2071743eee66SSUZUKI Shinsuke	NetLock, Netoctave, Netopia, Netscreen, Nokia EPOC, Nortel
2072743eee66SSUZUKI Shinsuke	GatewayController/CallServer 2000 (not released yet),
2073743eee66SSUZUKI Shinsuke	NxNetworks, OpenBSD isakmpd on OpenBSD, Oullim information
2074743eee66SSUZUKI Shinsuke	technologies SECUREWORKS VPN gateway 3.0, Pivotal, RSA,
2075743eee66SSUZUKI Shinsuke	Radguard, RapidStream, RedCreek, Routerware, SSH, SecGo
2076743eee66SSUZUKI Shinsuke	CryptoIP v3, Secure Computing, Soliton, Sun Solaris 8,
2077743eee66SSUZUKI Shinsuke	TIS/NAI Gauntret, Toshiba, Trilogy AdmitOne 2.6, Trustworks
2078743eee66SSUZUKI Shinsuke	TrustedClient v3.2, USAGI linux, VPNet, Yamaha RT series,
2079743eee66SSUZUKI Shinsuke	ZyXEL
208080d21dc4SYoshinobu Inoue
20818f336835SJun-ichiro itojun HaginoHere are (some of) platforms we have tested IPComp/IKE interoperability
20828f336835SJun-ichiro itojun Haginoin the past, in no particular order.
2083743eee66SSUZUKI Shinsuke	Compaq, IRE, SSH, NetLock, FreeS/WAN, F-Secure VPN+ 5.40
208433841545SHajimu UMEMOTO
208533841545SHajimu UMEMOTOVPNC (vpnc.org) provides IPsec conformance tests, using KAME and OpenBSD
208633841545SHajimu UMEMOTOIPsec/IKE implementations.  Their test results are available at
208733841545SHajimu UMEMOTOhttp://www.vpnc.org/conformance.html, and it may give you more idea
208833841545SHajimu UMEMOTOabout which implementation interoperates with KAME IPsec/IKE implementation.
208980d21dc4SYoshinobu Inoue
2090f88fe57eSHajimu UMEMOTO4.8 Operations with IPsec tunnel mode
2091f88fe57eSHajimu UMEMOTO
2092f88fe57eSHajimu UMEMOTOFirst of all, IPsec tunnel is a very hairy thing.  It seems to do a neat thing
2093f88fe57eSHajimu UMEMOTOlike VPN configuration or secure remote accesses, however, it comes with lots
2094f88fe57eSHajimu UMEMOTOof architectural twists.
2095f88fe57eSHajimu UMEMOTO
2096f88fe57eSHajimu UMEMOTORFC2401 defines IPsec tunnel mode, within the context of IPsec.  RFC2401
2097f88fe57eSHajimu UMEMOTOdefines tunnel mode packet encapsulation/decapsulation on its own, and
2098f88fe57eSHajimu UMEMOTOdoes not refer other tunnelling specifications.  Since RFC2401 advocates
2099f88fe57eSHajimu UMEMOTOfilter-based SPD database matches, it would be natural for us to implement
2100*93b03d5dSUlrich SpörleinIPsec tunnel mode as filters - not as pseudo interfaces.
2101f88fe57eSHajimu UMEMOTO
2102f88fe57eSHajimu UMEMOTOThere are some people who are trying to separate IPsec "tunnel mode" from
2103f88fe57eSHajimu UMEMOTOthe IPsec itself.  They would like to implement IPsec transport mode only,
2104f88fe57eSHajimu UMEMOTOand combine it with tunneling pseudo devices.  The prime example is found
2105f88fe57eSHajimu UMEMOTOin draft-touch-ipsec-vpn-01.txt.  However, if you really define pseudo
2106f88fe57eSHajimu UMEMOTOinterfaces separately from IPsec, IKE daemons would need to negotiate
2107f88fe57eSHajimu UMEMOTOtransport mode SAs, instead of tunnel mode SAs.  Therefore, we cannot
2108f88fe57eSHajimu UMEMOTOreally mix RFC2401-based interpretation and draft-touch-ipsec-vpn-01.txt
2109f88fe57eSHajimu UMEMOTOinterpretation.
2110f88fe57eSHajimu UMEMOTO
2111f88fe57eSHajimu UMEMOTOThe KAME stack implements can be configured in two ways.  You may need
2112f88fe57eSHajimu UMEMOTOto recompile your kernel to switch the behavior.
2113*93b03d5dSUlrich Spörlein- RFC2401 IPsec tunnel mode approach (4.8.1)
2114f88fe57eSHajimu UMEMOTO- draft-touch-ipsec-vpn approach (4.8.2)
2115f88fe57eSHajimu UMEMOTO	Works in all kernel configuration, but racoon(8) may not interoperate.
2116f88fe57eSHajimu UMEMOTO
2117f88fe57eSHajimu UMEMOTOThere are pros and cons on these approaches:
2118f88fe57eSHajimu UMEMOTO
2119f88fe57eSHajimu UMEMOTORFC2401 IPsec tunnel mode (filter-like) approach
2120f88fe57eSHajimu UMEMOTO	PRO: SPD lookup fits nicely with packet filters (if you integrate them)
2121f88fe57eSHajimu UMEMOTO	CON: cannot run routing daemons across IPsec tunnels
2122f88fe57eSHajimu UMEMOTO	CON: it is very hard to control source address selection on originating
2123f88fe57eSHajimu UMEMOTO		cases
2124f88fe57eSHajimu UMEMOTO	???: IPv6 scope zone is kept the same
2125f88fe57eSHajimu UMEMOTOdraft-touch-ipsec-vpn (transportmode + Pseudo-interface) approach
2126f88fe57eSHajimu UMEMOTO	PRO: run routing daemons across IPsec tunnels
2127f88fe57eSHajimu UMEMOTO	PRO: source address selection can be done normally, by looking at
2128f88fe57eSHajimu UMEMOTO		IPsec tunnel pseudo devices
2129f88fe57eSHajimu UMEMOTO	CON: on outbound, possibility of infinite loops if routing setup
2130f88fe57eSHajimu UMEMOTO		is wrong
2131f88fe57eSHajimu UMEMOTO	CON: due to differences in encap/decap logic from RFC2401, it may not
2132f88fe57eSHajimu UMEMOTO		interoperate with very picky RFC2401 implementations
2133f88fe57eSHajimu UMEMOTO		(those who check TOS bits, for example)
2134f88fe57eSHajimu UMEMOTO	CON: cannot negotiate IKE with other IPsec tunnel-mode devices
2135f88fe57eSHajimu UMEMOTO		(the other end has to implement
2136f88fe57eSHajimu UMEMOTO	???: IPv6 scope zone is likely to be different from the real ethernet
2137f88fe57eSHajimu UMEMOTO		interface
2138f88fe57eSHajimu UMEMOTO
2139f88fe57eSHajimu UMEMOTOThe recommendation is different depending on the situation you have:
2140f88fe57eSHajimu UMEMOTO- use draft-touch-ipsec-vpn if you have the control over the other end.
2141f88fe57eSHajimu UMEMOTO  this one is the best in terms of simplicity.
2142f88fe57eSHajimu UMEMOTO- if the other end is normal IPsec device with RFC2401 implementation,
2143f88fe57eSHajimu UMEMOTO  you need to use RFC2401, otherwise you won't be able to run IKE.
2144f88fe57eSHajimu UMEMOTO- use RFC2401 approach if you just want to forward packets back and forth
2145f88fe57eSHajimu UMEMOTO  and there's no plan to use IPsec gateway itself as an originating device.
2146f88fe57eSHajimu UMEMOTO
2147f88fe57eSHajimu UMEMOTO4.8.1 RFC2401 IPsec tunnel mode approach
2148f88fe57eSHajimu UMEMOTO
2149f88fe57eSHajimu UMEMOTOTo configure your device as RFC2401 IPsec tunnel mode endpoint, you will
2150f88fe57eSHajimu UMEMOTOuse "tunnel" keyword in setkey(8) "spdadd" directives.  Let us assume the
2151f88fe57eSHajimu UMEMOTOfollowing topology (A and B could be a network, like prefix/length):
2152f88fe57eSHajimu UMEMOTO
2153f88fe57eSHajimu UMEMOTO	((((((((((((The internet))))))))))))
2154f88fe57eSHajimu UMEMOTO	  |			  |
2155f88fe57eSHajimu UMEMOTO	  |C (global)		  |D
2156f88fe57eSHajimu UMEMOTO	your device		peer's device
2157f88fe57eSHajimu UMEMOTO	  |A (private)		  |B
2158f88fe57eSHajimu UMEMOTO	==+===== VPN net	==+===== VPN net
2159f88fe57eSHajimu UMEMOTO
2160f88fe57eSHajimu UMEMOTOThe policy configuration directive is like this.  You will need manual
2161f88fe57eSHajimu UMEMOTOSAs, or IKE daemon, for actual encryption:
2162f88fe57eSHajimu UMEMOTO
2163f88fe57eSHajimu UMEMOTO	# setkey -c <<EOF
2164f88fe57eSHajimu UMEMOTO	spdadd A B any -P out ipsec esp/tunnel/C-D/use;
2165f88fe57eSHajimu UMEMOTO	spdadd B A any -P in ipsec esp/tunnel/D-C/use;
2166f88fe57eSHajimu UMEMOTO	^D
2167f88fe57eSHajimu UMEMOTO
2168f88fe57eSHajimu UMEMOTOThe inbound/outbound traffic is monitored/captured by SPD engine, which works
2169f88fe57eSHajimu UMEMOTOjust like packet filters.
2170f88fe57eSHajimu UMEMOTO
2171f88fe57eSHajimu UMEMOTOWith this, forwarding case should work flawlessly.  However, troubles arise
2172f88fe57eSHajimu UMEMOTOwhen you have one of the following requirements:
2173f88fe57eSHajimu UMEMOTO- When you originate traffic from your VPN gateway device to VPN net on the
2174f88fe57eSHajimu UMEMOTO  other end (like B), you want your source address to be A (private side)
2175f88fe57eSHajimu UMEMOTO  so that the traffic would be protected by the policy.
2176f88fe57eSHajimu UMEMOTO  With this approach, however, the source address selection logic follows
2177f88fe57eSHajimu UMEMOTO  normal routing table, and C (global side) will be picked for any outgoing
2178f88fe57eSHajimu UMEMOTO  traffic, even if the destination is B.  The resulting packet will be like
2179f88fe57eSHajimu UMEMOTO  this:
2180f88fe57eSHajimu UMEMOTO	IP[C -> B] payload
2181f88fe57eSHajimu UMEMOTO  and will not match the policy (= sent in clear).
2182f88fe57eSHajimu UMEMOTO- When you want to run routing protocols on top of the IPsec tunnel, it is
2183f88fe57eSHajimu UMEMOTO  not possible.  As there is no pseudo device that identifies the IPsec tunnel,
2184f88fe57eSHajimu UMEMOTO  you cannot identify where the routing information came from.  As a result,
2185f88fe57eSHajimu UMEMOTO  you can't run routing daemons.
2186f88fe57eSHajimu UMEMOTO
2187f88fe57eSHajimu UMEMOTO4.8.2 draft-touch-ipsec-vpn approach
2188f88fe57eSHajimu UMEMOTO
2189f88fe57eSHajimu UMEMOTOWith this approach, you will configure gif(4) tunnel interfaces, as well as
2190f88fe57eSHajimu UMEMOTOIPsec transport mode SAs.
2191f88fe57eSHajimu UMEMOTO
2192f88fe57eSHajimu UMEMOTO	# gifconfig gif0 C D
2193f88fe57eSHajimu UMEMOTO	# ifconfig gif0 A B
2194f88fe57eSHajimu UMEMOTO	# setkey -c <<EOF
2195f88fe57eSHajimu UMEMOTO	spdadd C D any -P out ipsec esp/transport//use;
2196f88fe57eSHajimu UMEMOTO	spdadd D C any -P in ipsec esp/transport//use;
2197f88fe57eSHajimu UMEMOTO	^D
2198f88fe57eSHajimu UMEMOTO
2199f88fe57eSHajimu UMEMOTOSince we have a pseudo-interface "gif0", and it affects the routes and
2200f88fe57eSHajimu UMEMOTOthe source address selection logic, we can have source address A, for
2201f88fe57eSHajimu UMEMOTOpackets originated by the VPN gateway to B (and the VPN cloud).
2202f88fe57eSHajimu UMEMOTOWe can also exchange routing information over the tunnel (gif0), as the tunnel
2203f88fe57eSHajimu UMEMOTOis represented as a pseudo interface (dynamic routes points to the
2204f88fe57eSHajimu UMEMOTOpseudo interface).
2205f88fe57eSHajimu UMEMOTO
2206f88fe57eSHajimu UMEMOTOThere is a big drawbacks, however; with this, you can use IKE if and only if
2207f88fe57eSHajimu UMEMOTOthe other end is using draft-touch-ipsec-vpn approach too.  Since racoon(8)
2208f88fe57eSHajimu UMEMOTOgrabs phase 2 IKE proposals from the kernel SPD database, you will be
2209f88fe57eSHajimu UMEMOTOnegotiating IPsec transport-mode SAs with the other end, not tunnel-mode SAs.
2210f88fe57eSHajimu UMEMOTOAlso, since the encapsulation mechanism is different from RFC2401, you may not
2211f88fe57eSHajimu UMEMOTObe able to interoperate with a picky RFC2401 implementations - if the other
2212f88fe57eSHajimu UMEMOTOend checks certain outer IP header fields (like TOS), you will not be able to
2213f88fe57eSHajimu UMEMOTOinteroperate.
2214f88fe57eSHajimu UMEMOTO
2215f88fe57eSHajimu UMEMOTO
22168f336835SJun-ichiro itojun Hagino5. ALTQ
221780d21dc4SYoshinobu Inoue
2218743eee66SSUZUKI ShinsukeKAME kit includes ALTQ, which supports FreeBSD3, FreeBSD4, FreeBSD5
2219743eee66SSUZUKI ShinsukeNetBSD.  OpenBSD has ALTQ merged into pf and its ALTQ code is not
2220743eee66SSUZUKI Shinsukecompatible with other platforms so that KAME's ALTQ is not used for
2221743eee66SSUZUKI ShinsukeOpenBSD.  For BSD/OS, ALTQ does not work.
2222743eee66SSUZUKI ShinsukeALTQ in KAME supports IPv6.
222333841545SHajimu UMEMOTO(actually, ALTQ is developed on KAME repository since ALTQ 2.1 - Jan 2000)
222433841545SHajimu UMEMOTO
222533841545SHajimu UMEMOTOALTQ occupies single character device number.  For FreeBSD, it is officially
222633841545SHajimu UMEMOTOallocated.  For OpenBSD and NetBSD, we use the number which is not
222733841545SHajimu UMEMOTOcurrently allocated (will eventually get an official number).
222833841545SHajimu UMEMOTOThe character device is enabled for i386 architecture only.  To enable and
2229*93b03d5dSUlrich Spörleincompile ALTQ-ready kernel for other architectures, take the following steps:
223033841545SHajimu UMEMOTO- assume that your architecture is FOOBAA.
223133841545SHajimu UMEMOTO- modify sys/arch/FOOBAA/FOOBAA/conf.c (or somewhere that defines cdevsw),
223233841545SHajimu UMEMOTO  to include a line for ALTQ.  look at sys/arch/i386/i386/conf.c for
223333841545SHajimu UMEMOTO  example.  The major number must be same as i386 case.
223433841545SHajimu UMEMOTO- copy kernel configuration file (like ALTQ.v6 or GENERIC.v6) from i386,
223533841545SHajimu UMEMOTO  and modify accordingly.
223633841545SHajimu UMEMOTO- build a kernel.
223733841545SHajimu UMEMOTO- before building userland, change netbsd/{lib,usr.sbin,usr.bin}/Makefile
223833841545SHajimu UMEMOTO  (or openbsd/foobaa) so that it will visit altq-related sub directories.
223980d21dc4SYoshinobu Inoue
2240743eee66SSUZUKI Shinsuke
2241743eee66SSUZUKI Shinsuke6. Mobile IPv6
224280d21dc4SYoshinobu Inoue
224333841545SHajimu UMEMOTO6.1 KAME node as correspondent node
224433841545SHajimu UMEMOTO
224533841545SHajimu UMEMOTODefault installation recognizes home address option (in destination
2246*93b03d5dSUlrich Spörleinoptions header).  No sub-options are supported.  Interaction with
224733841545SHajimu UMEMOTOIPsec, and/or 2292bis API, needs further study.
224833841545SHajimu UMEMOTO
224933841545SHajimu UMEMOTO6.2 KAME node as home agent/mobile node
225033841545SHajimu UMEMOTO
225133841545SHajimu UMEMOTOKAME kit includes Ericsson mobile-ip6 code.  The integration is just started
225233841545SHajimu UMEMOTO(in Feb 2000), and we will need some more time to integrate it better.
225333841545SHajimu UMEMOTO
225433841545SHajimu UMEMOTOSee kame/mip6config/{QUICKSTART,README_MIP6.txt} for more details.
225533841545SHajimu UMEMOTO
225633841545SHajimu UMEMOTOThe Ericsson code implements revision 09 of the mobile-ip6 draft.  There
225733841545SHajimu UMEMOTOare other implementations available:
225833841545SHajimu UMEMOTO	NEC: http://www.6bone.nec.co.jp/mipv6/internal-dist/ (-13 draft)
225933841545SHajimu UMEMOTO	SFC: http://neo.sfc.wide.ad.jp/~mip6/ (-13 draft)
226033841545SHajimu UMEMOTO
226133841545SHajimu UMEMOTO7. Coding style
226233841545SHajimu UMEMOTO
226333841545SHajimu UMEMOTOThe KAME developers basically do not make a bother about coding
226433841545SHajimu UMEMOTOstyle.  However, there is still some agreement on the style, in order
2265*93b03d5dSUlrich Spörleinto make the distributed development smooth.
226633841545SHajimu UMEMOTO
2267f88fe57eSHajimu UMEMOTO- follow *BSD KNF where possible.  note: there are multiple KNF standards.
226833841545SHajimu UMEMOTO- the tab character should be 8 columns wide (tabstops are at 8, 16, 24, ...
226933841545SHajimu UMEMOTO  column).  With vi, use ":set ts=8 sw=8".
2270f88fe57eSHajimu UMEMOTO  With GNU Emacs 20 and later, the easiest way is to use the "bsd" style of
2271f88fe57eSHajimu UMEMOTO  cc-mode with the variable "c-basic-offset" being 8;
2272f88fe57eSHajimu UMEMOTO  (add-hook 'c-mode-common-hook
2273f88fe57eSHajimu UMEMOTO	    (function
2274f88fe57eSHajimu UMEMOTO	     (lambda ()
2275f88fe57eSHajimu UMEMOTO	       (c-set-style "bsd")
2276f88fe57eSHajimu UMEMOTO	       (setq c-basic-offset 8)  ; XXX for Emacs 20 only
2277f88fe57eSHajimu UMEMOTO	       )))
2278f88fe57eSHajimu UMEMOTO  The "bsd" style in GNU Emacs 21 sets the variable to 8 by default,
2279f88fe57eSHajimu UMEMOTO  so the line marked by "XXX" is not necessary if you only use GNU
2280f88fe57eSHajimu UMEMOTO  Emacs 21.
228133841545SHajimu UMEMOTO- each line should be within 80 characters.
228233841545SHajimu UMEMOTO- keep a single open/close bracket in a comment such as in the following
228333841545SHajimu UMEMOTO  line:
228433841545SHajimu UMEMOTO	putchar('(');	/* ) */
228533841545SHajimu UMEMOTO  without this, some vi users would have a hard time to match a pair of
228633841545SHajimu UMEMOTO  brackets.  Although this type of bracket seems clumsy and is even
228733841545SHajimu UMEMOTO  harmful for some other type of vi users and Emacs users, the
228833841545SHajimu UMEMOTO  agreement in the KAME developers is to allow it.
228933841545SHajimu UMEMOTO- add the following line to the head of every KAME-derived file:
229033841545SHajimu UMEMOTO  /*	(dollar)KAME(dollar)	*/
229133841545SHajimu UMEMOTO  where "(dollar)" is the dollar character ($), and around "$" are tabs.
229233841545SHajimu UMEMOTO  (this is for C.  For other language, you should use its own comment
229333841545SHajimu UMEMOTO  line.)
2294*93b03d5dSUlrich Spörlein  Once committed to the CVS repository, this line will contain its
229533841545SHajimu UMEMOTO  version number (see, for example, at the top of this file).  This
229633841545SHajimu UMEMOTO  would make it easy to report a bug.
229733841545SHajimu UMEMOTO- when creating a new file with the WIDE copyright, tap "make copyright.c" at
229833841545SHajimu UMEMOTO  the top-level, and use copyright.c as a template.  KAME RCS tag will be
229933841545SHajimu UMEMOTO  included automatically.
2300*93b03d5dSUlrich Spörlein- when editing a third-party package, keep its own coding style as
230133841545SHajimu UMEMOTO  much as possible, even if the style does not follow the items above.
2302f88fe57eSHajimu UMEMOTO- it is recommended to always wrap an expression containing
2303f88fe57eSHajimu UMEMOTO  bitwise operators by parentheses, especially when the expression is
2304f88fe57eSHajimu UMEMOTO  combined with relational operators, in order to avoid unintentional
2305f88fe57eSHajimu UMEMOTO  mismatch of operators.  Thus, we should write
2306f88fe57eSHajimu UMEMOTO	if ((a & b) == 0)	/* (A) */
2307f88fe57eSHajimu UMEMOTO  or
2308f88fe57eSHajimu UMEMOTO	if (a & (b == 0))	/* (B) */
2309f88fe57eSHajimu UMEMOTO  instead of
2310f88fe57eSHajimu UMEMOTO	if (a & b == 0)		/* (C) */
2311f88fe57eSHajimu UMEMOTO  even if the programmer's intention was (C), which is equivalent to
2312f88fe57eSHajimu UMEMOTO  (B) according to the grammar of the language C.
2313f88fe57eSHajimu UMEMOTO  Thus, we should write a code to test if a bit-flag is set for a
2314f88fe57eSHajimu UMEMOTO  given variable as follows:
2315f88fe57eSHajimu UMEMOTO	if ((flag & FLAG_A) == 0)	/* (D) the FLAG_A is NOT set */
2316f88fe57eSHajimu UMEMOTO	if ((flag & FLAG_A) != 0)	/* (E) the FLAG_A is set */
2317f88fe57eSHajimu UMEMOTO  Some developers in the KAME project rather prefer the following style:
2318f88fe57eSHajimu UMEMOTO	if (!(flag & FLAG_A))	/* (F) the FLAG_A is NOT set */
2319f88fe57eSHajimu UMEMOTO	if ((flag & FLAG_A))	/* (G) the FLAG_A is set */
2320f88fe57eSHajimu UMEMOTO  because it would be more intuitive in terms of the relationship
2321f88fe57eSHajimu UMEMOTO  between the negation operator (!) and the semantics of the
2322f88fe57eSHajimu UMEMOTO  condition.  The KAME developers have discussed the style, and have
2323f88fe57eSHajimu UMEMOTO  agreed that all the styles from (D) to (G) are valid.  So, when you
2324f88fe57eSHajimu UMEMOTO  see styles like (D) and (E) in the KAME code and feel a bit strange,
2325f88fe57eSHajimu UMEMOTO  please just keep them.  They are intentional.
2326f88fe57eSHajimu UMEMOTO- When inserting a separate block just to define some intra-block
2327f88fe57eSHajimu UMEMOTO  variables, add the level of indentation as if the block was in a
2328f88fe57eSHajimu UMEMOTO  control statement such as if-else, for, or while.  For example,
2329f88fe57eSHajimu UMEMOTO	foo ()
2330f88fe57eSHajimu UMEMOTO	{
2331f88fe57eSHajimu UMEMOTO		int a;
2332f88fe57eSHajimu UMEMOTO
2333f88fe57eSHajimu UMEMOTO		{
2334f88fe57eSHajimu UMEMOTO			int internal_a;
2335f88fe57eSHajimu UMEMOTO			...
2336f88fe57eSHajimu UMEMOTO		}
2337f88fe57eSHajimu UMEMOTO	}
2338f88fe57eSHajimu UMEMOTO  should be used, instead of
2339f88fe57eSHajimu UMEMOTO	foo ()
2340f88fe57eSHajimu UMEMOTO	{
2341f88fe57eSHajimu UMEMOTO		int a;
2342f88fe57eSHajimu UMEMOTO
2343f88fe57eSHajimu UMEMOTO	    {
2344f88fe57eSHajimu UMEMOTO		int internal_a;
2345f88fe57eSHajimu UMEMOTO		...
2346f88fe57eSHajimu UMEMOTO	     }
2347f88fe57eSHajimu UMEMOTO	}
2348f88fe57eSHajimu UMEMOTO- Do not use printf() or log() in the packet input path of the kernel code.
2349f88fe57eSHajimu UMEMOTO  They can make the system vulnerable to packet flooding attacks (results in
2350f88fe57eSHajimu UMEMOTO  /var overflow).
2351f88fe57eSHajimu UMEMOTO- (not a style issue)
2352f88fe57eSHajimu UMEMOTO  To disable a module that is mistakenly imported (by CVS), just
2353f88fe57eSHajimu UMEMOTO  remove the source tree in the repository.  Note, however, that the
2354f88fe57eSHajimu UMEMOTO  removal might annoy other developers who have already checked the
2355f88fe57eSHajimu UMEMOTO  module out, so you should announce the removal as soon as possible.
2356f88fe57eSHajimu UMEMOTO  Also, be 100% sure not to remove other modules.
235733841545SHajimu UMEMOTO
235833841545SHajimu UMEMOTOWhen you want to contribute something to the KAME project, and if *you
235933841545SHajimu UMEMOTOdo not mind* the agreement, it would be helpful for the project to
236033841545SHajimu UMEMOTOkeep these rules.  Note, however, that we would never intend to force
236133841545SHajimu UMEMOTOyou to adopt our rules.  We would rather regard your own style,
236233841545SHajimu UMEMOTOespecially when you have a policy about the style.
236380d21dc4SYoshinobu Inoue
2364f88fe57eSHajimu UMEMOTO
23652ea36b5dSBjoern A. Zeeb8. Policy on technology with intellectual property right restriction
2366f88fe57eSHajimu UMEMOTO
2367f88fe57eSHajimu UMEMOTOThere are quite a few IETF documents/whatever which has intellectual property
2368f88fe57eSHajimu UMEMOTOright (IPR) restriction.  KAME's stance is stated below.
2369f88fe57eSHajimu UMEMOTO
2370f88fe57eSHajimu UMEMOTO    The goal of KAME is to provide freely redistributable, BSD-licensed,
2371f88fe57eSHajimu UMEMOTO    implementation of Internet protocol technologies.
2372f88fe57eSHajimu UMEMOTO    For this purpose, we implement protocols that (1) do not need license
2373f88fe57eSHajimu UMEMOTO    contract with IPR holder, and (2) are royalty-free.
2374f88fe57eSHajimu UMEMOTO    The reason for (1) is, even if KAME contracts with the IPR holder in
2375f88fe57eSHajimu UMEMOTO    question, the users of KAME stack (usually implementers of some other
2376f88fe57eSHajimu UMEMOTO    codebase) would need to make a license contract with the IPR holder.
2377f88fe57eSHajimu UMEMOTO    It would damage the "freely redistributable" status of KAME codebase.
2378f88fe57eSHajimu UMEMOTO
2379f88fe57eSHajimu UMEMOTO    By doing so KAME is (implicitly) trying to advocate no-license-contract,
2380f88fe57eSHajimu UMEMOTO    royalty-free, release of IPRs.
2381f88fe57eSHajimu UMEMOTO
2382f88fe57eSHajimu UMEMOTONote however, as documented in README, we do not guarantee that KAME code
2383f88fe57eSHajimu UMEMOTOis free of IPR infringement, you MUST check it if you are to integrate
2384f88fe57eSHajimu UMEMOTOKAME into your product (or whatever):
2385f88fe57eSHajimu UMEMOTO    READ CAREFULLY: Several countries have legal enforcement for
2386f88fe57eSHajimu UMEMOTO    export/import/use of cryptographic software.  Check it before playing
2387*93b03d5dSUlrich Spörlein    with the kit.  We do not intend to be your legalese clearing house
2388f88fe57eSHajimu UMEMOTO    (NO WARRANTY).  If you intend to include KAME stack into your product,
2389f88fe57eSHajimu UMEMOTO    you'll need to check if the licenses on each file fit your situations,
2390f88fe57eSHajimu UMEMOTO    and/or possible intellectual property right issues.
2391f88fe57eSHajimu UMEMOTO
239280d21dc4SYoshinobu Inoue						 <end of IMPLEMENTATION>
2393