xref: /freebsd-13.1/share/doc/IPv6/IMPLEMENTATION (revision b141dd5d)
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
10528f336835SJun-ichiro itojun Haginoxxx_ctlinput() calls in_mrejoin() on PRC_IFNEWADDR.  We think this is
10538f336835SJun-ichiro itojun Haginoone of 4.4BSD implementation flaws.  Since 4.4BSD keeps ia_multiaddrs
10548f336835SJun-ichiro itojun Haginoin in_ifaddr{}, it can't use multicast feature if the interface has no
10558f336835SJun-ichiro itojun Haginounicast address.  So, if an application joins to an interface and then
10568f336835SJun-ichiro itojun Haginoall unicast addresses are removed from the interface, the application
10578f336835SJun-ichiro itojun Haginocan't send/receive any multicast packets.  Moreover, if a new unicast
10588f336835SJun-ichiro itojun Haginoaddress is assigned to the interface, in_mrejoin() must be called.
10598f336835SJun-ichiro itojun HaginoKAME's interfaces, however, have ALWAYS one link-local unicast
10608f336835SJun-ichiro itojun Haginoaddress.  These extensions have thus not been implemented in KAME.
106180d21dc4SYoshinobu Inoue
106280d21dc4SYoshinobu Inoue1.12 IPv4 mapped address and IPv6 wildcard socket
106380d21dc4SYoshinobu Inoue
1064f88fe57eSHajimu UMEMOTORFC2553/3493 describes IPv4 mapped address (3.7) and special behavior
106580d21dc4SYoshinobu Inoueof IPv6 wildcard bind socket (3.8).  The spec allows you to:
106680d21dc4SYoshinobu Inoue- Accept IPv4 connections by AF_INET6 wildcard bind socket.
106780d21dc4SYoshinobu Inoue- Transmit IPv4 packet over AF_INET6 socket by using special form of
106880d21dc4SYoshinobu Inoue  the address like ::ffff:10.1.1.1.
106980d21dc4SYoshinobu Inouebut the spec itself is very complicated and does not specify how the
107080d21dc4SYoshinobu Inouesocket layer should behave.
107180d21dc4SYoshinobu InoueHere we call the former one "listening side" and the latter one "initiating
107280d21dc4SYoshinobu Inoueside", for reference purposes.
107380d21dc4SYoshinobu Inoue
107480d21dc4SYoshinobu InoueAlmost all KAME implementations treat tcp/udp port number space separately
10758f336835SJun-ichiro itojun Haginobetween IPv4 and IPv6.  You can perform wildcard bind on both of the address
107680d21dc4SYoshinobu Inouefamilies, on the same port.
107780d21dc4SYoshinobu Inoue
10788f336835SJun-ichiro itojun HaginoThere are some OS-platform differences in KAME code, as we use tcp/udp
10798f336835SJun-ichiro itojun Haginocode from different origin.  The following table summarizes the behavior.
108080d21dc4SYoshinobu Inoue
108180d21dc4SYoshinobu Inoue		listening side		initiating side
10828f336835SJun-ichiro itojun Hagino		(AF_INET6 wildcard	(connection to ::ffff:10.1.1.1)
108380d21dc4SYoshinobu Inoue		socket gets IPv4 conn.)
108480d21dc4SYoshinobu Inoue		---			---
10858f336835SJun-ichiro itojun HaginoKAME/BSDI3	not supported		not supported
10868f336835SJun-ichiro itojun HaginoKAME/FreeBSD228	not supported		not supported
10878f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x	configurable		supported
108880d21dc4SYoshinobu Inoue		default: enabled
10898f336835SJun-ichiro itojun HaginoKAME/FreeBSD4x	configurable		supported
10908f336835SJun-ichiro itojun Hagino		default: enabled
10918f336835SJun-ichiro itojun HaginoKAME/NetBSD	configurable		supported
10928f336835SJun-ichiro itojun Hagino		default: disabled
10938f336835SJun-ichiro itojun HaginoKAME/BSDI4	enabled			supported
10948f336835SJun-ichiro itojun HaginoKAME/OpenBSD	not supported		not supported
109580d21dc4SYoshinobu Inoue
109680d21dc4SYoshinobu InoueThe following sections will give you more details, and how you can
109780d21dc4SYoshinobu Inoueconfigure the behavior.
109880d21dc4SYoshinobu Inoue
109980d21dc4SYoshinobu InoueComments on listening side:
110080d21dc4SYoshinobu Inoue
1101f88fe57eSHajimu UMEMOTOIt looks that RFC2553/3493 talks too little on wildcard bind issue,
11028f336835SJun-ichiro itojun Haginospecifically on (1) port space issue, (2) failure mode, (3) relationship
11038f336835SJun-ichiro itojun Haginobetween AF_INET/INET6 wildcard bind like ordering constraint, and (4) behavior
11048f336835SJun-ichiro itojun Haginowhen conflicting socket is opened/closed.  There can be several separate
110580d21dc4SYoshinobu Inoueinterpretation for this RFC which conform to it but behaves differently.
110680d21dc4SYoshinobu InoueSo, to implement portable application you should assume nothing
110780d21dc4SYoshinobu Inoueabout the behavior in the kernel.  Using getaddrinfo() is the safest way.
110880d21dc4SYoshinobu InouePort number space and wildcard bind issues were discussed in detail
110980d21dc4SYoshinobu Inoueon ipv6imp mailing list, in mid March 1999 and it looks that there's
111080d21dc4SYoshinobu Inoueno concrete consensus (means, up to implementers).  You may want to
111180d21dc4SYoshinobu Inouecheck the mailing list archives.
11128f336835SJun-ichiro itojun HaginoWe supply a tool called "bindtest" that explores the behavior of
11138f336835SJun-ichiro itojun Haginokernel bind(2).  The tool will not be compiled by default.
111480d21dc4SYoshinobu Inoue
111580d21dc4SYoshinobu InoueIf a server application would like to accept IPv4 and IPv6 connections,
11168f336835SJun-ichiro itojun Haginoit should use AF_INET and AF_INET6 socket (you'll need two sockets).
111780d21dc4SYoshinobu InoueUse getaddrinfo() with AI_PASSIVE into ai_flags, and socket(2) and bind(2)
111880d21dc4SYoshinobu Inoueto all the addresses returned.
111980d21dc4SYoshinobu InoueBy opening multiple sockets, you can accept connections onto the socket with
112080d21dc4SYoshinobu Inoueproper address family.  IPv4 connections will be accepted by AF_INET socket,
11218f336835SJun-ichiro itojun Haginoand IPv6 connections will be accepted by AF_INET6 socket (NOTE: KAME/BSDI4
11228f336835SJun-ichiro itojun Haginokernel sometimes violate this - we will fix it).
112380d21dc4SYoshinobu Inoue
11248f336835SJun-ichiro itojun HaginoIf you try to support IPv6 traffic only and would like to reject IPv4
11258f336835SJun-ichiro itojun Haginotraffic, always check the peer address when a connection is made toward
112680d21dc4SYoshinobu InoueAF_INET6 listening socket.  If the address is IPv4 mapped address, you may
112780d21dc4SYoshinobu Inouewant to reject the connection.  You can check the condition by using
11288f336835SJun-ichiro itojun HaginoIN6_IS_ADDR_V4MAPPED() macro.  This is one of the reasons the author of
11298f336835SJun-ichiro itojun Haginothe section (itojun) dislikes special behavior of AF_INET6 wildcard bind.
113080d21dc4SYoshinobu Inoue
113180d21dc4SYoshinobu InoueComments on initiating side:
113280d21dc4SYoshinobu Inoue
113380d21dc4SYoshinobu InoueAdvise to application implementers: to implement a portable IPv6 application
113480d21dc4SYoshinobu Inoue(which works on multiple IPv6 kernels), we believe that the following
113580d21dc4SYoshinobu Inoueis the key to the success:
113680d21dc4SYoshinobu Inoue- NEVER hardcode AF_INET nor AF_INET6.
113780d21dc4SYoshinobu Inoue- Use getaddrinfo() and getnameinfo() throughout the system.
113880d21dc4SYoshinobu Inoue  Never use gethostby*(), getaddrby*(), inet_*() or getipnodeby*().
113980d21dc4SYoshinobu Inoue- If you would like to connect to destination, use getaddrinfo() and try
114080d21dc4SYoshinobu Inoue  all the destination returned, like telnet does.
114180d21dc4SYoshinobu Inoue- Some of the IPv6 stack is shipped with buggy getaddrinfo().  Ship a minimal
114280d21dc4SYoshinobu Inoue  working version with your application and use that as last resort.
114380d21dc4SYoshinobu Inoue
114480d21dc4SYoshinobu InoueIf you would like to use AF_INET6 socket for both IPv4 and IPv6 outgoing
11458f336835SJun-ichiro itojun Haginoconnection, you will need tweaked implementation in DNS support libraries,
1146f88fe57eSHajimu UMEMOTOas documented in RFC2553/3493 6.1.  KAME libinet6 includes the tweak in
11478f336835SJun-ichiro itojun Haginogetipnodebyname().  Note that getipnodebyname() itself is not recommended as
11488f336835SJun-ichiro itojun Haginoit does not handle scoped IPv6 addresses at all.  For IPv6 name resolution
11498f336835SJun-ichiro itojun Haginogetaddrinfo() is the preferred API.  getaddrinfo() does not implement the
11508f336835SJun-ichiro itojun Haginotweak.
115180d21dc4SYoshinobu Inoue
115280d21dc4SYoshinobu InoueWhen writing applications that make outgoing connections, story goes much
11538f336835SJun-ichiro itojun Haginosimpler if you treat AF_INET and AF_INET6 as totally separate address family.
115480d21dc4SYoshinobu Inoue{set,get}sockopt issue goes simpler, DNS issue will be made simpler.  We do
115580d21dc4SYoshinobu Inouenot recommend you to rely upon IPv4 mapped address.
115680d21dc4SYoshinobu Inoue
11578f336835SJun-ichiro itojun Hagino1.12.1 KAME/BSDI3 and KAME/FreeBSD228
115880d21dc4SYoshinobu Inoue
11598f336835SJun-ichiro itojun HaginoThe platforms do not support IPv4 mapped address at all (both listening side
11608f336835SJun-ichiro itojun Haginoand initiating side).  AF_INET6 and AF_INET sockets are totally separated.
116180d21dc4SYoshinobu Inoue
11628f336835SJun-ichiro itojun HaginoPort number space is totally separate between AF_INET and AF_INET6 sockets.
116380d21dc4SYoshinobu Inoue
116433841545SHajimu UMEMOTOIt should be noted that KAME/BSDI3 and KAME/FreeBSD228 are not conformant
1165f88fe57eSHajimu UMEMOTOto RFC2553/3493 section 3.7 and 3.8.  It is due to code sharing reasons.
116633841545SHajimu UMEMOTO
11678f336835SJun-ichiro itojun Hagino1.12.2 KAME/FreeBSD[34]x
116880d21dc4SYoshinobu Inoue
11698f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x and KAME/FreeBSD4x use shared tcp4/6 code (from
11708f336835SJun-ichiro itojun Haginosys/netinet/tcp*) and shared udp4/6 code (from sys/netinet/udp*).
11718f336835SJun-ichiro itojun HaginoThey use unified inpcb/in6pcb structure.
117280d21dc4SYoshinobu Inoue
11738f336835SJun-ichiro itojun Hagino1.12.2.1 KAME/FreeBSD[34]x, listening side
11748f336835SJun-ichiro itojun Hagino
11758f336835SJun-ichiro itojun HaginoThe platform can be configured to support IPv4 mapped address/special
11768f336835SJun-ichiro itojun HaginoAF_INET6 wildcard bind (enabled by default).  There is no kernel compilation
11778f336835SJun-ichiro itojun Haginooption to disable it.  You can enable/disable the behavior with sysctl
11788f336835SJun-ichiro itojun Hagino(per-node), or setsockopt (per-socket).
117980d21dc4SYoshinobu Inoue
118080d21dc4SYoshinobu InoueWildcard AF_INET6 socket grabs IPv4 connection if and only if the following
118180d21dc4SYoshinobu Inoueconditions are satisfied:
118280d21dc4SYoshinobu Inoue- there's no AF_INET socket that matches the IPv4 connection
118380d21dc4SYoshinobu Inoue- the AF_INET6 socket is configured to accept IPv4 traffic, i.e.
118433841545SHajimu UMEMOTO  getsockopt(IPV6_V6ONLY) returns 0.
118580d21dc4SYoshinobu Inoue
11868f336835SJun-ichiro itojun Hagino(XXX need checking)
118780d21dc4SYoshinobu Inoue
11888f336835SJun-ichiro itojun Hagino1.12.2.2 KAME/FreeBSD[34]x, initiating side
11898f336835SJun-ichiro itojun Hagino
11908f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x supports outgoing connection to IPv4 mapped address
11918f336835SJun-ichiro itojun Hagino(::ffff:10.1.1.1), if the node is configured to accept IPv4 connections
11928f336835SJun-ichiro itojun Haginoby AF_INET6 socket.
11938f336835SJun-ichiro itojun Hagino
11948f336835SJun-ichiro itojun Hagino(XXX need checking)
11958f336835SJun-ichiro itojun Hagino
11968f336835SJun-ichiro itojun Hagino1.12.3 KAME/NetBSD
11978f336835SJun-ichiro itojun Hagino
11988f336835SJun-ichiro itojun HaginoKAME/NetBSD uses shared tcp4/6 code (from sys/netinet/tcp*) and shared
11998f336835SJun-ichiro itojun Haginoudp4/6 code (from sys/netinet/udp*).  The implementation is made differently
12008f336835SJun-ichiro itojun Haginofrom KAME/FreeBSD[34]x.  KAME/NetBSD uses separate inpcb/in6pcb structures,
12018f336835SJun-ichiro itojun Haginowhile KAME/FreeBSD[34]x uses merged inpcb structure.
12028f336835SJun-ichiro itojun Hagino
120333841545SHajimu UMEMOTOIt should be noted that the default configuration of KAME/NetBSD is not
1204f88fe57eSHajimu UMEMOTOconformant to RFC2553/3493 section 3.8.  It is intentionally turned off by
1205f88fe57eSHajimu UMEMOTOdefault for security reasons.
12068f336835SJun-ichiro itojun Hagino
12078f336835SJun-ichiro itojun HaginoThe platform can be configured to support IPv4 mapped address/special AF_INET6
12088f336835SJun-ichiro itojun Haginowildcard bind (disabled by default).  Kernel behavior can be summarized as
12098f336835SJun-ichiro itojun Haginofollows:
12108f336835SJun-ichiro itojun Hagino- default: special support code will be compiled in, but is disabled by
121133841545SHajimu UMEMOTO  default.  It can be controlled by sysctl (net.inet6.ip6.v6only),
121233841545SHajimu UMEMOTO  or setsockopt(IPV6_V6ONLY).
1213f88fe57eSHajimu UMEMOTO- add "INET6_BINDV6ONLY": No special support code for AF_INET6 wildcard socket
12148f336835SJun-ichiro itojun Hagino  will be compiled in.  AF_INET6 sockets and AF_INET sockets are totally
12158f336835SJun-ichiro itojun Hagino  separate.  The behavior is similar to what described in 1.12.1.
12168f336835SJun-ichiro itojun Hagino
12178f336835SJun-ichiro itojun Haginosysctl setting will affect per-socket configuration at in6pcb creation time
12188f336835SJun-ichiro itojun Haginoonly.  In other words, per-socket configuration will be copied from sysctl
12198f336835SJun-ichiro itojun Haginoconfiguration at in6pcb creation time.  To change per-socket behavior, you
12208f336835SJun-ichiro itojun Haginomust perform setsockopt or reopen the socket.  Change in sysctl configuration
12218f336835SJun-ichiro itojun Haginowill not change the behavior or sockets that are already opened.
12228f336835SJun-ichiro itojun Hagino
1223f88fe57eSHajimu UMEMOTO1.12.3.1 KAME/NetBSD, listening side
1224f88fe57eSHajimu UMEMOTO
12258f336835SJun-ichiro itojun HaginoWildcard AF_INET6 socket grabs IPv4 connection if and only if the following
12268f336835SJun-ichiro itojun Haginoconditions are satisfied:
12278f336835SJun-ichiro itojun Hagino- there's no AF_INET socket that matches the IPv4 connection
12288f336835SJun-ichiro itojun Hagino- the AF_INET6 socket is configured to accept IPv4 traffic, i.e.
122933841545SHajimu UMEMOTO  getsockopt(IPV6_V6ONLY) returns 0.
12308f336835SJun-ichiro itojun Hagino
12318f336835SJun-ichiro itojun HaginoYou cannot bind(2) with IPv4 mapped address.  This is a workaround for port
12328f336835SJun-ichiro itojun Haginonumber duplicate and other twists.
12338f336835SJun-ichiro itojun Hagino
12348f336835SJun-ichiro itojun Hagino1.12.3.2 KAME/NetBSD, initiating side
12358f336835SJun-ichiro itojun Hagino
1236f88fe57eSHajimu UMEMOTOWhen getsockopt(IPV6_V6ONLY) is 0 for a socket, you can make an outgoing
1237f88fe57eSHajimu UMEMOTOtraffic to IPv4 destination over AF_INET6 socket, using IPv4 mapped
1238f88fe57eSHajimu UMEMOTOaddress destination (::ffff:10.1.1.1).
1239f88fe57eSHajimu UMEMOTO
1240f88fe57eSHajimu UMEMOTOWhen getsockopt(IPV6_V6ONLY) is 1 for a socket, you cannot use IPv4 mapped
1241f88fe57eSHajimu UMEMOTOaddress for outgoing traffic.
12428f336835SJun-ichiro itojun Hagino
12438f336835SJun-ichiro itojun Hagino1.12.4 KAME/BSDI4
12448f336835SJun-ichiro itojun Hagino
12458f336835SJun-ichiro itojun HaginoKAME/BSDI4 uses NRL-based TCP/UDP stack and inpcb source code,
12468f336835SJun-ichiro itojun Haginowhich was derived from NRL IPv6/IPsec stack.  We guess it supports IPv4 mapped
12478f336835SJun-ichiro itojun Haginoaddress and speical AF_INET6 wildcard bind.  The implementation is, again,
12488f336835SJun-ichiro itojun Haginodifferent from other KAME/*BSDs.
12498f336835SJun-ichiro itojun Hagino
12508f336835SJun-ichiro itojun Hagino1.12.4.1 KAME/BSDI4, listening side
12518f336835SJun-ichiro itojun Hagino
12528f336835SJun-ichiro itojun HaginoNRL inpcb layer supports special behavior of AF_INET6 wildcard socket.
12538f336835SJun-ichiro itojun HaginoThere is no way to disable the behavior.
12548f336835SJun-ichiro itojun Hagino
12558f336835SJun-ichiro itojun HaginoWildcard AF_INET6 socket grabs IPv4 connection if and only if the following
12568f336835SJun-ichiro itojun Haginocondition is satisfied:
12578f336835SJun-ichiro itojun Hagino- there's no AF_INET socket that matches the IPv4 connection
12588f336835SJun-ichiro itojun Hagino
12598f336835SJun-ichiro itojun Hagino1.12.4.2 KAME/BSDI4, initiating side
12608f336835SJun-ichiro itojun Hagino
12618f336835SJun-ichiro itojun HaginoKAME/BSDi4 supports connection initiation to IPv4 mapped address
12628f336835SJun-ichiro itojun Hagino(like ::ffff:10.1.1.1).
12638f336835SJun-ichiro itojun Hagino
12648f336835SJun-ichiro itojun Hagino1.12.5 KAME/OpenBSD
12658f336835SJun-ichiro itojun Hagino
12668f336835SJun-ichiro itojun HaginoKAME/OpenBSD uses NRL-based TCP/UDP stack and inpcb source code,
12678f336835SJun-ichiro itojun Haginowhich was derived from NRL IPv6/IPsec stack.
12688f336835SJun-ichiro itojun Hagino
1269f88fe57eSHajimu UMEMOTOIt should be noted that KAME/OpenBSD is not conformant to RFC2553/3493 section
1270f88fe57eSHajimu UMEMOTO3.7 and 3.8.  It is intentionally omitted for security reasons.
127133841545SHajimu UMEMOTO
12728f336835SJun-ichiro itojun Hagino1.12.5.1 KAME/OpenBSD, listening side
12738f336835SJun-ichiro itojun Hagino
12748f336835SJun-ichiro itojun HaginoKAME/OpenBSD disables special behavior on AF_INET6 wildcard bind for
12758f336835SJun-ichiro itojun Haginosecurity reasons (if IPv4 traffic toward AF_INET6 wildcard bind is allowed,
12768f336835SJun-ichiro itojun Haginoaccess control will become much harder).  KAME/BSDI4 uses NRL-based TCP/UDP
12778f336835SJun-ichiro itojun Haginostack as well, however, the behavior is different due to OpenBSD's security
12788f336835SJun-ichiro itojun Haginopolicy.
12798f336835SJun-ichiro itojun Hagino
12808f336835SJun-ichiro itojun HaginoAs a result the behavior of KAME/OpenBSD is similar to KAME/BSDI3 and
12818f336835SJun-ichiro itojun HaginoKAME/FreeBSD228 (see 1.12.1 for more detail).
12828f336835SJun-ichiro itojun Hagino
12838f336835SJun-ichiro itojun Hagino1.12.5.2 KAME/OpenBSD, initiating side
12848f336835SJun-ichiro itojun Hagino
12858f336835SJun-ichiro itojun HaginoKAME/OpenBSD does not support connection initiation to IPv4 mapped address
12868f336835SJun-ichiro itojun Hagino(like ::ffff:10.1.1.1).
12878f336835SJun-ichiro itojun Hagino
12888f336835SJun-ichiro itojun Hagino1.12.6 More issues
12898f336835SJun-ichiro itojun Hagino
12908f336835SJun-ichiro itojun HaginoIPv4 mapped address support adds a big requirement to EVERY userland codebase.
12918f336835SJun-ichiro itojun HaginoEvery userland code should check if an AF_INET6 sockaddr contains IPv4
12928f336835SJun-ichiro itojun Haginomapped address or not.  This adds many twists:
12938f336835SJun-ichiro itojun Hagino
12948f336835SJun-ichiro itojun Hagino- Access controls code becomes harder to write.
12958f336835SJun-ichiro itojun Hagino  For example, if you would like to reject packets from 10.0.0.0/8,
12968f336835SJun-ichiro itojun Hagino  you need to reject packets to AF_INET socket from 10.0.0.0/8,
12978f336835SJun-ichiro itojun Hagino  and to AF_INET6 socket from ::ffff:10.0.0.0/104.
12988f336835SJun-ichiro itojun Hagino- If a protocol on top of IPv4 is defined differently with IPv6, we need to be
12998f336835SJun-ichiro itojun Hagino  really careful when we determine which protocol to use.
13008f336835SJun-ichiro itojun Hagino  For example, with FTP protocol, we can not simply use sa_family to determine
13018f336835SJun-ichiro itojun Hagino  FTP command sets.  The following example is incorrect:
13028f336835SJun-ichiro itojun Hagino	if (sa_family == AF_INET)
13038f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or PASV/PORT;	/*IPv4*/
13048f336835SJun-ichiro itojun Hagino	else if (sa_family == AF_INET6)
13058f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or LPSV/LPRT;	/*IPv6*/
13068f336835SJun-ichiro itojun Hagino	else
13078f336835SJun-ichiro itojun Hagino		error;
130833841545SHajimu UMEMOTO  The correct code, with consideration to IPv4 mapped address, would be:
13098f336835SJun-ichiro itojun Hagino	if (sa_family == AF_INET)
13108f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or PASV/PORT;	/*IPv4*/
13118f336835SJun-ichiro itojun Hagino	else if (sa_family == AF_INET6 && IPv4 mapped address)
13128f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or PASV/PORT;	/*IPv4 command set on AF_INET6*/
13138f336835SJun-ichiro itojun Hagino	else if (sa_family == AF_INET6 && !IPv4 mapped address)
13148f336835SJun-ichiro itojun Hagino		use EPSV/EPRT or LPSV/LPRT;	/*IPv6*/
13158f336835SJun-ichiro itojun Hagino	else
13168f336835SJun-ichiro itojun Hagino		error;
13178f336835SJun-ichiro itojun Hagino  It is too much to ask for every body to be careful like this.
13188f336835SJun-ichiro itojun Hagino  The problem is, we are not sure if the above code fragment is perfect for
13198f336835SJun-ichiro itojun Hagino  all situations.
13208f336835SJun-ichiro itojun Hagino- By enabling kernel support for IPv4 mapped address (outgoing direction),
13218f336835SJun-ichiro itojun Hagino  servers on the kernel can be hosed by IPv6 native packet that has IPv4
13228f336835SJun-ichiro itojun Hagino  mapped address in IPv6 header source, and can generate unwanted IPv4 packets.
1323f88fe57eSHajimu UMEMOTO  draft-itojun-ipv6-transition-abuse-01.txt, draft-cmetz-v6ops-v4mapped-api-
1324f88fe57eSHajimu UMEMOTO  harmful-00.txt, and draft-itojun-v6ops-v4mapped-harmful-01.txt
1325f88fe57eSHajimu UMEMOTO  has more on this scenario.
13268f336835SJun-ichiro itojun Hagino
13278f336835SJun-ichiro itojun HaginoDue to the above twists, some of KAME userland programs has restrictions on
13288f336835SJun-ichiro itojun Haginothe use of IPv4 mapped addresses:
13298f336835SJun-ichiro itojun Hagino- rshd/rlogind do not accept connections from IPv4 mapped address.
13308f336835SJun-ichiro itojun Hagino  This is to avoid malicious use of IPv4 mapped address in IPv6 native
13318f336835SJun-ichiro itojun Hagino  packet, to bypass source-address based authentication.
133233841545SHajimu UMEMOTO- ftp/ftpd assume that you are on dual stack network.  IPv4 mapped address
133333841545SHajimu UMEMOTO  will be decoded in userland, and will be passed to AF_INET sockets
133433841545SHajimu UMEMOTO  (in other words, ftp/ftpd do not support SIIT environment).
133533841545SHajimu UMEMOTO
133633841545SHajimu UMEMOTO1.12.7 Interaction with SIIT translator
133733841545SHajimu UMEMOTO
133833841545SHajimu UMEMOTOSIIT translator is specified in RFC2765.  KAME node cannot become a SIIT
133933841545SHajimu UMEMOTOtranslator box, nor SIIT end node (a node in SIIT cloud).
134033841545SHajimu UMEMOTO
134133841545SHajimu UMEMOTOTo become a SIIT translator box, we need to put additional code for that.
134233841545SHajimu UMEMOTOWe do not have the code in our tree at this moment.
134333841545SHajimu UMEMOTO
134433841545SHajimu UMEMOTOThere are multiple reasons that we are unable to become SIIT end node.
134533841545SHajimu UMEMOTO(1) SIIT translators require end nodes in the SIIT cloud to be IPv6-only.
134633841545SHajimu UMEMOTOSince we are unable to compile INET-less kernel, we are unable to become
134733841545SHajimu UMEMOTOSIIT end node.  (2) As presented in 1.12.6, some of our userland code assumes
134833841545SHajimu UMEMOTOdual stack network.  (3) KAME stack filters out IPv6 packets with IPv4
134933841545SHajimu UMEMOTOmapped address in the header, to secure non-SIIT case (which is much more
135033841545SHajimu UMEMOTOcommon).  Effectively KAME node will reject any packets via SIIT translator
135133841545SHajimu UMEMOTObox.  See section 1.14 for more detail about the last item.
135233841545SHajimu UMEMOTO
135333841545SHajimu UMEMOTOThere are documentation issues too - SIIT document requires very strange
135433841545SHajimu UMEMOTOthings.  For example, SIIT document asks IPv6-only (meaning no IPv4 code)
135533841545SHajimu UMEMOTOnode to be able to construct IPv4 IPsec headers.  If a node knows how to
135633841545SHajimu UMEMOTOconstruct IPv4 IPsec headers, that is not an IPv6-only node, it is a dual-stack
135733841545SHajimu UMEMOTOnode.  The requirements imposed in SIIT document contradict with the other
135833841545SHajimu UMEMOTOpart of the document itself.
135980d21dc4SYoshinobu Inoue
136080d21dc4SYoshinobu Inoue1.13 sockaddr_storage
136180d21dc4SYoshinobu Inoue
13628f336835SJun-ichiro itojun HaginoWhen RFC2553 was about to be finalized, there was discussion on how struct
136380d21dc4SYoshinobu Inouesockaddr_storage members are named.  One proposal is to prepend "__" to the
136480d21dc4SYoshinobu Inouemembers (like "__ss_len") as they should not be touched.  The other proposal
136580d21dc4SYoshinobu Inouewas that don't prepend it (like "ss_len") as we need to touch those members
136680d21dc4SYoshinobu Inouedirectly.  There was no clear consensus on it.
136780d21dc4SYoshinobu Inoue
136880d21dc4SYoshinobu InoueAs a result, RFC2553 defines struct sockaddr_storage as follows:
136980d21dc4SYoshinobu Inoue	struct sockaddr_storage {
137080d21dc4SYoshinobu Inoue		u_char	__ss_len;	/* address length */
137180d21dc4SYoshinobu Inoue		u_char	__ss_family;	/* address family */
137280d21dc4SYoshinobu Inoue		/* and bunch of padding */
137380d21dc4SYoshinobu Inoue	};
137480d21dc4SYoshinobu InoueOn the contrary, XNET draft defines as follows:
137580d21dc4SYoshinobu Inoue	struct sockaddr_storage {
137680d21dc4SYoshinobu Inoue		u_char	ss_len;		/* address length */
137780d21dc4SYoshinobu Inoue		u_char	ss_family;	/* address family */
137880d21dc4SYoshinobu Inoue		/* and bunch of padding */
137980d21dc4SYoshinobu Inoue	};
138080d21dc4SYoshinobu Inoue
1381f88fe57eSHajimu UMEMOTOIn December 1999, it was agreed that RFC2553bis (RFC3493) should pick the
1382f88fe57eSHajimu UMEMOTOlatter (XNET) definition.
138380d21dc4SYoshinobu Inoue
138480d21dc4SYoshinobu InoueKAME kit prior to December 1999 used RFC2553 definition.  KAME kit after
138580d21dc4SYoshinobu InoueDecember 1999 (including December) will conform to XNET definition,
1386f88fe57eSHajimu UMEMOTObased on RFC3493 discussion.
138780d21dc4SYoshinobu Inoue
138880d21dc4SYoshinobu InoueIf you look at multiple IPv6 implementations, you will be able to see
138980d21dc4SYoshinobu Inoueboth definitions.  As an userland programmer, the most portable way of
139080d21dc4SYoshinobu Inouedealing with it is to:
139180d21dc4SYoshinobu Inoue(1) ensure ss_family and/or ss_len are available on the platform, by using
139280d21dc4SYoshinobu Inoue    GNU autoconf,
1393*93b03d5dSUlrich Spörlein(2) have -Dss_family=__ss_family to unify all occurrences (including header
139480d21dc4SYoshinobu Inoue    file) into __ss_family, or
139580d21dc4SYoshinobu Inoue(3) never touch __ss_family.  cast to sockaddr * and use sa_family like:
139680d21dc4SYoshinobu Inoue	struct sockaddr_storage ss;
139780d21dc4SYoshinobu Inoue	family = ((struct sockaddr *)&ss)->sa_family
139880d21dc4SYoshinobu Inoue
13998f336835SJun-ichiro itojun Hagino1.14 Invalid addresses on the wire
14008f336835SJun-ichiro itojun Hagino
14018f336835SJun-ichiro itojun HaginoSome of IPv6 transition technologies embed IPv4 address into IPv6 address.
14028f336835SJun-ichiro itojun HaginoThese specifications themselves are fine, however, there can be certain
1403*93b03d5dSUlrich Spörleinset of attacks enabled by these specifications.  Recent specification
14048f336835SJun-ichiro itojun Haginodocuments covers up those issues, however, there are already-published RFCs
14058f336835SJun-ichiro itojun Haginothat does not have protection against those (like using source address of
14068f336835SJun-ichiro itojun Hagino::ffff:127.0.0.1 to bypass "reject packet from remote" filter).
14078f336835SJun-ichiro itojun Hagino
14088f336835SJun-ichiro itojun HaginoTo name a few, these address ranges can be used to hose an IPv6 implementation,
14098f336835SJun-ichiro itojun Haginoor bypass security controls:
14108f336835SJun-ichiro itojun Hagino- IPv4 mapped address that embeds unspecified/multicast/loopback/broadcast
14118f336835SJun-ichiro itojun Hagino  IPv4 address (if they are in IPv6 native packet header, they are malicious)
14128f336835SJun-ichiro itojun Hagino	::ffff:0.0.0.0/104	::ffff:127.0.0.0/104
14138f336835SJun-ichiro itojun Hagino	::ffff:224.0.0.0/100	::ffff:255.0.0.0/104
141433841545SHajimu UMEMOTO- 6to4 (RFC3056) prefix generated from unspecified/multicast/loopback/
141533841545SHajimu UMEMOTO  broadcast/private IPv4 address
14168f336835SJun-ichiro itojun Hagino	2002:0000::/24		2002:7f00::/24		2002:e000::/24
14178f336835SJun-ichiro itojun Hagino	2002:ff00::/24		2002:0a00::/24		2002:ac10::/28
14188f336835SJun-ichiro itojun Hagino	2002:c0a8::/32
141933841545SHajimu UMEMOTO- IPv4 compatible address that embeds unspecified/multicast/loopback/broadcast
142033841545SHajimu UMEMOTO  IPv4 address (if they are in IPv6 native packet header, they are malicious).
142133841545SHajimu UMEMOTO  Note that, since KAME doe snot support RFC1933/2893 auto tunnels, KAME nodes
142233841545SHajimu UMEMOTO  are not vulnerable to these packets.
142333841545SHajimu UMEMOTO	::0.0.0.0/104	::127.0.0.0/104	::224.0.0.0/100	::255.0.0.0/104
14248f336835SJun-ichiro itojun Hagino
142533841545SHajimu UMEMOTOAlso, since KAME does not support RFC1933/2893 auto tunnels, seeing IPv4
142633841545SHajimu UMEMOTOcompatible is very rare.  You should take caution if you see those on the wire.
142733841545SHajimu UMEMOTO
142833841545SHajimu UMEMOTOIf we see IPv6 packets with IPv4 mapped address (::ffff:0.0.0.0/96) in the
142933841545SHajimu UMEMOTOheader in dual-stack environment (not in SIIT environment), they indicate
1430*93b03d5dSUlrich Spörleinthat someone is trying to impersonate IPv4 peer.  The packet should be dropped.
143133841545SHajimu UMEMOTO
143233841545SHajimu UMEMOTOIPv6 specifications do not talk very much about IPv6 unspecified address (::)
143333841545SHajimu UMEMOTOin the IPv6 source address field.  Clarification is in progress.
143433841545SHajimu UMEMOTOHere are couple of comments:
143533841545SHajimu UMEMOTO- IPv6 unspecified address can be used in IPv6 source address field, if and
143633841545SHajimu UMEMOTO  only if we have no legal source address for the node.  The legal situations
143733841545SHajimu UMEMOTO  include, but may not be limited to, (1) MLD while no IPv6 address is assigned
143833841545SHajimu UMEMOTO  to the node and (2) DAD.
143933841545SHajimu UMEMOTO- If IPv6 TCP packet has IPv6 unspecified address, it is an attack attempt.
144033841545SHajimu UMEMOTO  The form can be used as a trigger for TCP DoS attack.  KAME code already
144133841545SHajimu UMEMOTO  filters them out.
144233841545SHajimu UMEMOTO- The following examples are seemingly illegal.  It seems that there's general
1443743eee66SSUZUKI Shinsuke  consensus among ipngwg for those.  (1) Mobile IPv6 home address option,
144433841545SHajimu UMEMOTO  (2) offlink packets (so routers should not forward them).
1445*93b03d5dSUlrich Spörlein  KAME implements (2) already.
14468f336835SJun-ichiro itojun Hagino
14478f336835SJun-ichiro itojun HaginoKAME code is carefully written to avoid such incidents.  More specifically,
1448*93b03d5dSUlrich SpörleinKAME kernel will reject packets with certain source/destination address in IPv6
14498f336835SJun-ichiro itojun Haginobase header, or IPv6 routing header.  Also, KAME default configuration file
14508f336835SJun-ichiro itojun Haginois written carefully, to avoid those attacks.
14518f336835SJun-ichiro itojun Hagino
1452f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-transition-abuse-01.txt, draft-cmetz-v6ops-v4mapped-api-
1453f88fe57eSHajimu UMEMOTOharmful-00.txt and draft-itojun-v6ops-v4mapped-harmful-01.txt has more on
1454f88fe57eSHajimu UMEMOTOthis issue.
14558f336835SJun-ichiro itojun Hagino
14568f336835SJun-ichiro itojun Hagino1.15 Node's required addresses
14578f336835SJun-ichiro itojun Hagino
14588f336835SJun-ichiro itojun HaginoRFC2373 section 2.8 talks about required addresses for an IPv6
14598f336835SJun-ichiro itojun Haginonode.  The section talks about how KAME stack manages those required
14608f336835SJun-ichiro itojun Haginoaddresses.
14618f336835SJun-ichiro itojun Hagino
14628f336835SJun-ichiro itojun Hagino1.15.1 Host case
14638f336835SJun-ichiro itojun Hagino
14648f336835SJun-ichiro itojun HaginoThe following items are automatically assigned to the node (or the node will
14658f336835SJun-ichiro itojun Haginoautomatically joins the group), at bootstrap time:
14668f336835SJun-ichiro itojun Hagino- Loopback address
14678f336835SJun-ichiro itojun Hagino- All-nodes multicast addresses (ff01::1)
14688f336835SJun-ichiro itojun Hagino
14698f336835SJun-ichiro itojun HaginoThe following items will be automatically handled when the interface becomes
14708f336835SJun-ichiro itojun HaginoIFF_UP:
14718f336835SJun-ichiro itojun Hagino- Its link-local address for each interface
14728f336835SJun-ichiro itojun Hagino- Solicited-node multicast address for link-local addresses
14738f336835SJun-ichiro itojun Hagino- Link-local allnodes multicast address (ff02::1)
14748f336835SJun-ichiro itojun Hagino
14758f336835SJun-ichiro itojun HaginoThe following items need to be configured manually by ifconfig(8) or prefix(8).
14768f336835SJun-ichiro itojun HaginoAlternatively, these can be autoconfigured by using stateless address
14778f336835SJun-ichiro itojun Haginoautoconfiguration.
14788f336835SJun-ichiro itojun Hagino- Assigned unicast/anycast addresses
14798f336835SJun-ichiro itojun Hagino- Solicited-Node multicast address for assigned unicast address
14808f336835SJun-ichiro itojun Hagino
14818f336835SJun-ichiro itojun HaginoUsers can join groups by using appropriate system calls like setsockopt(2).
14828f336835SJun-ichiro itojun Hagino
14838f336835SJun-ichiro itojun Hagino1.15.2 Router case
14848f336835SJun-ichiro itojun Hagino
14858f336835SJun-ichiro itojun HaginoIn addition to the above, routers needs to handle the following items.
14868f336835SJun-ichiro itojun Hagino
14878f336835SJun-ichiro itojun HaginoThe following items need to be configured manually by using ifconfig(8).
14888f336835SJun-ichiro itojun Haginoo The subnet-router anycast addresses for the interfaces it is configured
14898f336835SJun-ichiro itojun Hagino  to act as a router on (prefix::/64)
14908f336835SJun-ichiro itojun Haginoo All other anycast addresses with which the router has been configured
14918f336835SJun-ichiro itojun Hagino
14928f336835SJun-ichiro itojun HaginoThe router will join the following multicast group when rtadvd(8) is available
14938f336835SJun-ichiro itojun Haginofor the interface.
14948f336835SJun-ichiro itojun Haginoo All-Routers Multicast Addresses (ff02::2)
14958f336835SJun-ichiro itojun Hagino
14968f336835SJun-ichiro itojun HaginoRouting daemons will join appropriate multicast groups, as necessary,
14978f336835SJun-ichiro itojun Haginolike ff02::9 for RIPng.
14988f336835SJun-ichiro itojun Hagino
14998f336835SJun-ichiro itojun HaginoUsers can join groups by using appropriate system calls like setsockopt(2).
15008f336835SJun-ichiro itojun Hagino
150133841545SHajimu UMEMOTO1.16 Advanced API
150233841545SHajimu UMEMOTO
1503f88fe57eSHajimu UMEMOTOCurrent KAME kernel implements RFC3542 API.  It also implements RFC2292 API,
150433841545SHajimu UMEMOTOfor backward compatibility purposes with *BSD-integrated codebase.
1505f88fe57eSHajimu UMEMOTOKAME tree ships with RFC3542 headers.
1506f88fe57eSHajimu UMEMOTO*BSD-integrated codebase implements either RFC2292, or RFC3542, API.
150733841545SHajimu UMEMOTOsee "COVERAGE" document for detailed implementation status.
150833841545SHajimu UMEMOTO
150933841545SHajimu UMEMOTOHere are couple of issues to mention:
151033841545SHajimu UMEMOTO- *BSD-integrated binaries, compiled for RFC2292, will work on KAME kernel.
151133841545SHajimu UMEMOTO  For example, OpenBSD 2.7 /sbin/rtsol will work on KAME/openbsd kernel.
1512f88fe57eSHajimu UMEMOTO- KAME binaries, compiled using RFC3542, will not work on *BSD-integrated
151333841545SHajimu UMEMOTO  kenrel.  For example, KAME /usr/local/v6/sbin/rtsol will not work on
151433841545SHajimu UMEMOTO  OpenBSD 2.7 kernel.
1515f88fe57eSHajimu UMEMOTO- RFC3542 API is not compatible with RFC2292 API.  RFC3542 #define symbols
151633841545SHajimu UMEMOTO  conflict with RFC2292 symbols.  Therefore, if you compile programs that
151733841545SHajimu UMEMOTO  assume RFC2292 API, the compilation itself goes fine, however, the compiled
151833841545SHajimu UMEMOTO  binary will not work correctly.  The problem is not KAME issue, but API
1519f88fe57eSHajimu UMEMOTO  issue.  For example, Solaris 8 implements RFC3542 API.  If you compile
152033841545SHajimu UMEMOTO  RFC2292-based code on Solaris 8, the binary can behave strange.
152133841545SHajimu UMEMOTO
152233841545SHajimu UMEMOTOThere are few (or couple of) incompatible behavior in RFC2292 binary backward
152333841545SHajimu UMEMOTOcompatibility support in KAME tree.  To enumerate:
152433841545SHajimu UMEMOTO- Type 0 routing header lacks support for strict/loose bitmap.
152533841545SHajimu UMEMOTO  Even if we see packets with "strict" bit set, those bits will not be made
152633841545SHajimu UMEMOTO  visible to the userland.
152733841545SHajimu UMEMOTO  Background: RFC2292 document is based on RFC1883 IPv6, and it uses
1528f88fe57eSHajimu UMEMOTO  strict/loose bitmap.  RFC3542 document is based on RFC2460 IPv6, and it has
152933841545SHajimu UMEMOTO  no strict/loose bitmap (it was removed from RFC2460).  KAME tree obeys
153033841545SHajimu UMEMOTO  RFC2460 IPv6, and lacks support for strict/loose bitmap.
153133841545SHajimu UMEMOTO
1532f88fe57eSHajimu UMEMOTOThe RFC3542 documents leave some particular cases unspecified.  The
1533f88fe57eSHajimu UMEMOTOKAME implementation treats them as follows:
1534f88fe57eSHajimu UMEMOTO- The IPV6_DONTFRAG and IPV6_RECVPATHMTU socket options for TCP
1535f88fe57eSHajimu UMEMOTO  sockets are ignored.  That is, the setsocktopt() call will succeed
1536f88fe57eSHajimu UMEMOTO  but the specified value will have no effect.
1537f88fe57eSHajimu UMEMOTO
1538f88fe57eSHajimu UMEMOTO1.17 DNS resolver
1539f88fe57eSHajimu UMEMOTO
1540f88fe57eSHajimu UMEMOTOKAME ships with modified DNS resolver, in libinet6.a.
1541*93b03d5dSUlrich Spörleinlibinet6.a has a couple of extensions against libc DNS resolver:
1542f88fe57eSHajimu UMEMOTO- Can take "options insecure1" and "options insecure2" in /etc/resolv.conf,
1543f88fe57eSHajimu UMEMOTO  which toggles RES_INSECURE[12] option flag bit.
1544f88fe57eSHajimu UMEMOTO- EDNS0 receive buffer size notification support.  It can be enabled by
1545f88fe57eSHajimu UMEMOTO  "options edns0" in /etc/resolv.conf.  See USAGE for details.
1546f88fe57eSHajimu UMEMOTO- IPv6 transport support (queries/responses over IPv6).  Most of BSD official
1547f88fe57eSHajimu UMEMOTO  releases now has it already.
1548f88fe57eSHajimu UMEMOTO- Partial A6 chain chasing/DNAME/bit string label support (KAME/BSDI4).
1549f88fe57eSHajimu UMEMOTO
1550f88fe57eSHajimu UMEMOTO
155180d21dc4SYoshinobu Inoue2. Network Drivers
155280d21dc4SYoshinobu Inoue
15538f336835SJun-ichiro itojun HaginoKAME requires three items to be added into the standard drivers:
155480d21dc4SYoshinobu Inoue
1555f88fe57eSHajimu UMEMOTO(1) (freebsd[234] and bsdi[34] only) mbuf clustering requirement.
1556f88fe57eSHajimu UMEMOTO    In this stable release, we changed MINCLSIZE into MHLEN+1 for all the
1557f88fe57eSHajimu UMEMOTO    operating systems in order to make all the drivers behave as we expect.
155880d21dc4SYoshinobu Inoue
155980d21dc4SYoshinobu Inoue(2) multicast.  If "ifmcstat" yields no multicast group for a
156080d21dc4SYoshinobu Inoue    interface, that interface has to be patched.
156180d21dc4SYoshinobu Inoue
15628f336835SJun-ichiro itojun HaginoTo avoid troubles, we suggest you to comment out the device drivers
15638f336835SJun-ichiro itojun Haginofor unsupported/unnecessary cards, from the kernel configuration file.
15648f336835SJun-ichiro itojun HaginoIf you accidentally enable unsupported drivers, some of the userland
15658f336835SJun-ichiro itojun Haginotools may not work correctly (routing daemons are typical example).
15668f336835SJun-ichiro itojun Hagino
15678f336835SJun-ichiro itojun HaginoIn the following sections, "official support" means that KAME developers
15688f336835SJun-ichiro itojun Haginoare using that ethernet card/driver frequently.
156980d21dc4SYoshinobu Inoue
157080d21dc4SYoshinobu Inoue(NOTE: In the past we required all pcmcia drivers to have a call to
157180d21dc4SYoshinobu Inouein6_ifattach().  We have no such requirement any more)
157280d21dc4SYoshinobu Inoue
15738f336835SJun-ichiro itojun Hagino2.1 FreeBSD 2.2.x-RELEASE
15748f336835SJun-ichiro itojun Hagino
15758f336835SJun-ichiro itojun HaginoHere is a list of FreeBSD 2.2.x-RELEASE drivers and its conditions:
15768f336835SJun-ichiro itojun Hagino
15778f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
15788f336835SJun-ichiro itojun Hagino	---	---		---		---
15798f336835SJun-ichiro itojun Hagino	(Ethernet)
15808f336835SJun-ichiro itojun Hagino	ar	looks ok	-		-
15818f336835SJun-ichiro itojun Hagino	cnw	ok		ok		yes (*)
15828f336835SJun-ichiro itojun Hagino	ed	ok		ok		yes
15838f336835SJun-ichiro itojun Hagino	ep	ok		ok		yes
15848f336835SJun-ichiro itojun Hagino	fe	ok		ok		yes
15858f336835SJun-ichiro itojun Hagino	sn	looks ok	-		-   (*)
15868f336835SJun-ichiro itojun Hagino	vx	looks ok	-		-
15878f336835SJun-ichiro itojun Hagino	wlp	ok		ok		-   (*)
15888f336835SJun-ichiro itojun Hagino	xl	ok		ok		yes
15898f336835SJun-ichiro itojun Hagino	zp	ok		ok		-
15908f336835SJun-ichiro itojun Hagino	(FDDI)
15918f336835SJun-ichiro itojun Hagino	fpa	looks ok	?		-
15928f336835SJun-ichiro itojun Hagino	(ATM)
15938f336835SJun-ichiro itojun Hagino	en	ok		ok		yes
15948f336835SJun-ichiro itojun Hagino	(Serial)
15958f336835SJun-ichiro itojun Hagino	lp	?		-		not work
15968f336835SJun-ichiro itojun Hagino	sl	?		-		not work
15978f336835SJun-ichiro itojun Hagino	sr	looks ok	ok		-   (**)
15988f336835SJun-ichiro itojun Hagino
15998f336835SJun-ichiro itojun HaginoYou may want to add an invocation of "rtsol" in "/etc/pccard_ether",
16008f336835SJun-ichiro itojun Haginoif you are using notebook computers and PCMCIA ethernet card.
16018f336835SJun-ichiro itojun Hagino
16028f336835SJun-ichiro itojun Hagino(*) These drivers are distributed with PAO (http://www.jp.freebsd.org/PAO/).
16038f336835SJun-ichiro itojun Hagino
16048f336835SJun-ichiro itojun Hagino(**) There was some report says that, if you make sr driver up and down and
16058f336835SJun-ichiro itojun Haginothen up, the kernel may hang up.  We have disabled frame-relay support from
16068f336835SJun-ichiro itojun Haginosr driver and after that this looks to be working fine.  If you need
16078f336835SJun-ichiro itojun Haginoframe-relay support to come back, please contact KAME developers.
16088f336835SJun-ichiro itojun Hagino
16098f336835SJun-ichiro itojun Hagino2.2 BSD/OS 3.x
16108f336835SJun-ichiro itojun Hagino
16118f336835SJun-ichiro itojun HaginoThe following lists BSD/OS 3.x device drivers and its conditions:
16128f336835SJun-ichiro itojun Hagino
16138f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
16148f336835SJun-ichiro itojun Hagino	---	---		---		---
16158f336835SJun-ichiro itojun Hagino	(Ethernet)
16168f336835SJun-ichiro itojun Hagino	cnw	ok		ok		yes
16178f336835SJun-ichiro itojun Hagino	de	ok		ok		-
16188f336835SJun-ichiro itojun Hagino	df	ok		ok		-
16198f336835SJun-ichiro itojun Hagino	eb	ok		ok		-
16208f336835SJun-ichiro itojun Hagino	ef	ok		ok		yes
16218f336835SJun-ichiro itojun Hagino	exp	ok		ok		-
16228f336835SJun-ichiro itojun Hagino	mz	ok		ok		yes
16238f336835SJun-ichiro itojun Hagino	ne	ok		ok		yes
16248f336835SJun-ichiro itojun Hagino	we	ok		ok		-
16258f336835SJun-ichiro itojun Hagino	(FDDI)
16268f336835SJun-ichiro itojun Hagino	fpa	ok		ok		-
16278f336835SJun-ichiro itojun Hagino	(ATM)
16288f336835SJun-ichiro itojun Hagino	en	maybe		ok		-
16298f336835SJun-ichiro itojun Hagino	(Serial)
16308f336835SJun-ichiro itojun Hagino	ntwo	ok		ok		yes
16318f336835SJun-ichiro itojun Hagino	sl	?		-		not work
16328f336835SJun-ichiro itojun Hagino	appp	?		-		not work
16338f336835SJun-ichiro itojun Hagino
16348f336835SJun-ichiro itojun HaginoYou may want to use "@insert" directive in /etc/pccard.conf to invoke
16358f336835SJun-ichiro itojun Hagino"rtsol" command right after dynamic insertion of PCMCIA ethernet cards.
16368f336835SJun-ichiro itojun Hagino
16378f336835SJun-ichiro itojun Hagino2.3 NetBSD
16388f336835SJun-ichiro itojun Hagino
16398f336835SJun-ichiro itojun HaginoThe following table lists the network drivers we have tried so far.
16408f336835SJun-ichiro itojun Hagino
16418f336835SJun-ichiro itojun Hagino	driver		mbuf(1)	multicast(2)	official support?
16428f336835SJun-ichiro itojun Hagino	---		---	---		---
16438f336835SJun-ichiro itojun Hagino	(Ethernet)
16448f336835SJun-ichiro itojun Hagino	awi pcmcia/i386	ok	ok		-
16458f336835SJun-ichiro itojun Hagino	bah zbus/amiga	NG(*)
16468f336835SJun-ichiro itojun Hagino	cnw pcmcia/i386	ok	ok		yes
16478f336835SJun-ichiro itojun Hagino	ep pcmcia/i386	ok	ok		-
1648743eee66SSUZUKI Shinsuke	fxp pci/i386	ok(*2)	ok		-
1649743eee66SSUZUKI Shinsuke	tlp pci/i386	ok	ok		-
16508f336835SJun-ichiro itojun Hagino	le sbus/sparc	ok	ok		yes
16518f336835SJun-ichiro itojun Hagino	ne pci/i386	ok	ok		yes
16528f336835SJun-ichiro itojun Hagino	ne pcmcia/i386	ok	ok		yes
1653743eee66SSUZUKI Shinsuke	rtk pci/i386	ok	ok		-
16548f336835SJun-ichiro itojun Hagino	wi pcmcia/i386	ok	ok		yes
16558f336835SJun-ichiro itojun Hagino	(ATM)
16568f336835SJun-ichiro itojun Hagino	en pci/i386	ok	ok		-
16578f336835SJun-ichiro itojun Hagino
16588f336835SJun-ichiro itojun Hagino(*) This may need some fix, but I'm not sure what arcnet interfaces assume...
16598f336835SJun-ichiro itojun Hagino
16608f336835SJun-ichiro itojun Hagino2.4 FreeBSD 3.x-RELEASE
16618f336835SJun-ichiro itojun Hagino
16628f336835SJun-ichiro itojun HaginoHere is a list of FreeBSD 3.x-RELEASE drivers and its conditions:
16638f336835SJun-ichiro itojun Hagino
16648f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
16658f336835SJun-ichiro itojun Hagino	---	---		---		---
16668f336835SJun-ichiro itojun Hagino	(Ethernet)
16678f336835SJun-ichiro itojun Hagino	cnw	ok		ok		-(*)
16688f336835SJun-ichiro itojun Hagino	ed	?		ok		-
16698f336835SJun-ichiro itojun Hagino	ep	ok		ok		-
16708f336835SJun-ichiro itojun Hagino	fe	ok		ok		yes
16718f336835SJun-ichiro itojun Hagino	fxp	?(**)
16728f336835SJun-ichiro itojun Hagino	lnc	?		ok		-
16738f336835SJun-ichiro itojun Hagino	sn	?		?		-(*)
16748f336835SJun-ichiro itojun Hagino	wi	ok		ok		yes
16758f336835SJun-ichiro itojun Hagino	xl	?		ok		-
16768f336835SJun-ichiro itojun Hagino
16778f336835SJun-ichiro itojun Hagino(*) These drivers are distributed with PAO as PAO3
16788f336835SJun-ichiro itojun Hagino    (http://www.jp.freebsd.org/PAO/).
1679743eee66SSUZUKI Shinsuke(**) there were trouble reports with multicast filter initialization.
16808f336835SJun-ichiro itojun Hagino
16818f336835SJun-ichiro itojun HaginoMore drivers will just simply work on KAME FreeBSD 3.x-RELEASE but have not
16828f336835SJun-ichiro itojun Haginobeen checked yet.
16838f336835SJun-ichiro itojun Hagino
168433841545SHajimu UMEMOTO2.5 FreeBSD 4.x-RELEASE
168533841545SHajimu UMEMOTO
168633841545SHajimu UMEMOTOHere is a list of FreeBSD 4.x-RELEASE drivers and its conditions:
168733841545SHajimu UMEMOTO
168833841545SHajimu UMEMOTO	driver		multicast
168933841545SHajimu UMEMOTO	---		---
169033841545SHajimu UMEMOTO	(Ethernet)
169133841545SHajimu UMEMOTO	lnc/vmware	ok
169233841545SHajimu UMEMOTO
169333841545SHajimu UMEMOTO2.6 OpenBSD 2.x
16948f336835SJun-ichiro itojun Hagino
16958f336835SJun-ichiro itojun HaginoHere is a list of OpenBSD 2.x drivers and its conditions:
16968f336835SJun-ichiro itojun Hagino
16978f336835SJun-ichiro itojun Hagino	driver		mbuf(1)		multicast(2)	official support?
16988f336835SJun-ichiro itojun Hagino	---		---		---		---
16998f336835SJun-ichiro itojun Hagino	(Ethernet)
17008f336835SJun-ichiro itojun Hagino	de pci/i386	ok		ok		yes
17018f336835SJun-ichiro itojun Hagino	fxp pci/i386	?(*)
17028f336835SJun-ichiro itojun Hagino	le sbus/sparc	ok		ok		yes
17038f336835SJun-ichiro itojun Hagino	ne pci/i386	ok		ok		yes
17048f336835SJun-ichiro itojun Hagino	ne pcmcia/i386	ok		ok		yes
17058f336835SJun-ichiro itojun Hagino	wi pcmcia/i386	ok		ok		yes
17068f336835SJun-ichiro itojun Hagino
17078f336835SJun-ichiro itojun Hagino(*) There seem to be some problem in driver, with multicast filter
17088f336835SJun-ichiro itojun Haginoconfiguration.  This happens with certain revision of chipset on the card.
17098f336835SJun-ichiro itojun HaginoShould be fixed by now by workaround in sys/net/if.c, but still not sure.
17108f336835SJun-ichiro itojun Hagino
171133841545SHajimu UMEMOTO2.7 BSD/OS 4.x
17128f336835SJun-ichiro itojun Hagino
17138f336835SJun-ichiro itojun HaginoThe following lists BSD/OS 4.x device drivers and its conditions:
17148f336835SJun-ichiro itojun Hagino
17158f336835SJun-ichiro itojun Hagino	driver	mbuf(1)		multicast(2)	official support?
17168f336835SJun-ichiro itojun Hagino	---	---		---		---
17178f336835SJun-ichiro itojun Hagino	(Ethernet)
17188f336835SJun-ichiro itojun Hagino	de	ok		ok		yes
17198f336835SJun-ichiro itojun Hagino	exp	(*)
17208f336835SJun-ichiro itojun Hagino
17218f336835SJun-ichiro itojun HaginoYou may want to use "@insert" directive in /etc/pccard.conf to invoke
17228f336835SJun-ichiro itojun Hagino"rtsol" command right after dynamic insertion of PCMCIA ethernet cards.
17238f336835SJun-ichiro itojun Hagino
17248f336835SJun-ichiro itojun Hagino(*) exp driver has serious conflict with KAME initialization sequence.
17258f336835SJun-ichiro itojun HaginoA workaround is committed into sys/i386/pci/if_exp.c, and should be okay by now.
17268f336835SJun-ichiro itojun Hagino
1727743eee66SSUZUKI Shinsuke
172880d21dc4SYoshinobu Inoue3. Translator
172980d21dc4SYoshinobu Inoue
173080d21dc4SYoshinobu InoueWe categorize IPv4/IPv6 translator into 4 types.
173180d21dc4SYoshinobu Inoue
173280d21dc4SYoshinobu InoueTranslator A --- It is used in the early stage of transition to make
173380d21dc4SYoshinobu Inoueit possible to establish a connection from an IPv6 host in an IPv6
173480d21dc4SYoshinobu Inoueisland to an IPv4 host in the IPv4 ocean.
173580d21dc4SYoshinobu Inoue
173680d21dc4SYoshinobu InoueTranslator B --- It is used in the early stage of transition to make
173780d21dc4SYoshinobu Inoueit possible to establish a connection from an IPv4 host in the IPv4
173880d21dc4SYoshinobu Inoueocean to an IPv6 host in an IPv6 island.
173980d21dc4SYoshinobu Inoue
174080d21dc4SYoshinobu InoueTranslator C --- It is used in the late stage of transition to make it
174180d21dc4SYoshinobu Inouepossible to establish a connection from an IPv4 host in an IPv4 island
174280d21dc4SYoshinobu Inoueto an IPv6 host in the IPv6 ocean.
174380d21dc4SYoshinobu Inoue
174480d21dc4SYoshinobu InoueTranslator D --- It is used in the late stage of transition to make it
174580d21dc4SYoshinobu Inouepossible to establish a connection from an IPv6 host in the IPv6 ocean
174680d21dc4SYoshinobu Inoueto an IPv4 host in an IPv4 island.
174780d21dc4SYoshinobu Inoue
174880d21dc4SYoshinobu InoueKAME provides an TCP relay translator for category A.  This is called
174980d21dc4SYoshinobu Inoue"FAITH".  We also provide IP header translator for category A.
175080d21dc4SYoshinobu Inoue
175180d21dc4SYoshinobu Inoue3.1 FAITH TCP relay translator
175280d21dc4SYoshinobu Inoue
175380d21dc4SYoshinobu InoueFAITH system uses TCP relay daemon called "faithd" helped by the KAME kernel.
175480d21dc4SYoshinobu InoueFAITH will reserve an IPv6 address prefix, and relay TCP connection
175580d21dc4SYoshinobu Inouetoward that prefix to IPv4 destination.
175680d21dc4SYoshinobu Inoue
175780d21dc4SYoshinobu InoueFor example, if the reserved IPv6 prefix is 3ffe:0501:0200:ffff::, and
175880d21dc4SYoshinobu Inouethe IPv6 destination for TCP connection is 3ffe:0501:0200:ffff::163.221.202.12,
175980d21dc4SYoshinobu Inouethe connection will be relayed toward IPv4 destination 163.221.202.12.
176080d21dc4SYoshinobu Inoue
176180d21dc4SYoshinobu Inoue	destination IPv4 node (163.221.202.12)
176280d21dc4SYoshinobu Inoue	  ^
176380d21dc4SYoshinobu Inoue	  | IPv4 tcp toward 163.221.202.12
176480d21dc4SYoshinobu Inoue	FAITH-relay dual stack node
176580d21dc4SYoshinobu Inoue	  ^
176680d21dc4SYoshinobu Inoue	  | IPv6 TCP toward 3ffe:0501:0200:ffff::163.221.202.12
176780d21dc4SYoshinobu Inoue	source IPv6 node
176880d21dc4SYoshinobu Inoue
176980d21dc4SYoshinobu Inouefaithd must be invoked on FAITH-relay dual stack node.
177080d21dc4SYoshinobu Inoue
1771743eee66SSUZUKI ShinsukeFor more details, consult kame/kame/faithd/README and RFC3142.
177280d21dc4SYoshinobu Inoue
177380d21dc4SYoshinobu Inoue3.2 IPv6-to-IPv4 header translator
177480d21dc4SYoshinobu Inoue
177533841545SHajimu UMEMOTO(to be written)
177680d21dc4SYoshinobu Inoue
1777743eee66SSUZUKI Shinsuke
177880d21dc4SYoshinobu Inoue4. IPsec
177980d21dc4SYoshinobu Inoue
17808f336835SJun-ichiro itojun HaginoIPsec is implemented as the following three components.
178180d21dc4SYoshinobu Inoue
178280d21dc4SYoshinobu Inoue(1) Policy Management
178380d21dc4SYoshinobu Inoue(2) Key Management
17848f336835SJun-ichiro itojun Hagino(3) AH, ESP and IPComp handling in kernel
17858f336835SJun-ichiro itojun Hagino
17868f336835SJun-ichiro itojun HaginoNote that KAME/OpenBSD does NOT include support for KAME IPsec code,
17878f336835SJun-ichiro itojun Haginoas OpenBSD team has their home-brew IPsec stack and they have no plan
17888f336835SJun-ichiro itojun Haginoto replace it.  IPv6 support for IPsec is, therefore, lacking on KAME/OpenBSD.
178980d21dc4SYoshinobu Inoue
179033841545SHajimu UMEMOTOhttp://www.netbsd.org/Documentation/network/ipsec/ has more information
179133841545SHajimu UMEMOTOincluding usage examples.
179233841545SHajimu UMEMOTO
179380d21dc4SYoshinobu Inoue4.1 Policy Management
179480d21dc4SYoshinobu Inoue
1795f88fe57eSHajimu UMEMOTOThe kernel implements experimental policy management code.  There are two ways
179680d21dc4SYoshinobu Inoueto manage security policy.  One is to configure per-socket policy using
179780d21dc4SYoshinobu Inouesetsockopt(3).  In this cases, policy configuration is described in
179880d21dc4SYoshinobu Inoueipsec_set_policy(3).  The other is to configure kernel packet filter-based
179980d21dc4SYoshinobu Inouepolicy using PF_KEY interface, via setkey(8).
180080d21dc4SYoshinobu Inoue
18018f336835SJun-ichiro itojun HaginoThe policy entry will be matched in order.  The order of entries makes
18028f336835SJun-ichiro itojun Haginodifference in behavior.
180380d21dc4SYoshinobu Inoue
180480d21dc4SYoshinobu Inoue4.2 Key Management
180580d21dc4SYoshinobu Inoue
180680d21dc4SYoshinobu InoueThe key management code implemented in this kit (sys/netkey) is a
180780d21dc4SYoshinobu Inouehome-brew PFKEY v2 implementation.  This conforms to RFC2367.
180880d21dc4SYoshinobu Inoue
18098f336835SJun-ichiro itojun HaginoThe home-brew IKE daemon, "racoon" is included in the kit (kame/kame/racoon,
18108f336835SJun-ichiro itojun Haginoor usr.sbin/racoon).
181180d21dc4SYoshinobu InoueBasically you'll need to run racoon as daemon, then setup a policy
181280d21dc4SYoshinobu Inoueto require keys (like ping -P 'out ipsec esp/transport//use').
181380d21dc4SYoshinobu InoueThe kernel will contact racoon daemon as necessary to exchange keys.
181480d21dc4SYoshinobu Inoue
18158f336835SJun-ichiro itojun HaginoIn IKE spec, there's ambiguity about interpretation of "tunnel" proposal.
18168f336835SJun-ichiro itojun HaginoFor example, if we would like to propose the use of following packet:
18178f336835SJun-ichiro itojun Hagino	IP AH ESP IP payload
18188f336835SJun-ichiro itojun Haginosome implementation proposes it as "AH transport and ESP tunnel", since
18198f336835SJun-ichiro itojun Haginothis is more logical from packet construction point of view.  Some
18208f336835SJun-ichiro itojun Haginoimplementation proposes it as "AH tunnel and ESP tunnel".
1821f88fe57eSHajimu UMEMOTORacoon follows the latter route (previously it followed the former, and
1822f88fe57eSHajimu UMEMOTOthe latter interpretation seems to be popular/consensus).
18238f336835SJun-ichiro itojun HaginoThis raises real interoperability issue.  We hope this to be resolved quickly.
18248f336835SJun-ichiro itojun Hagino
1825f88fe57eSHajimu UMEMOTOracoon does not implement byte lifetime for both phase 1 and phase 2
1826f88fe57eSHajimu UMEMOTO(RFC2409 page 35, Life Type = kilobytes).
1827f88fe57eSHajimu UMEMOTO
182880d21dc4SYoshinobu Inoue4.3 AH and ESP handling
182980d21dc4SYoshinobu Inoue
183080d21dc4SYoshinobu InoueIPsec module is implemented as "hooks" to the standard IPv4/IPv6
183180d21dc4SYoshinobu Inoueprocessing.  When sending a packet, ip{,6}_output() checks if ESP/AH
183280d21dc4SYoshinobu Inoueprocessing is required by checking if a matching SPD (Security
183380d21dc4SYoshinobu InouePolicy Database) is found.  If ESP/AH is needed,
183480d21dc4SYoshinobu Inoue{esp,ah}{4,6}_output() will be called and mbuf will be updated
183580d21dc4SYoshinobu Inoueaccordingly.  When a packet is received, {esp,ah}4_input() will be
183680d21dc4SYoshinobu Inouecalled based on protocol number, i.e. (*inetsw[proto])().
183780d21dc4SYoshinobu Inoue{esp,ah}4_input() will decrypt/check authenticity of the packet,
183880d21dc4SYoshinobu Inoueand strips off daisy-chained header and padding for ESP/AH.  It is
183980d21dc4SYoshinobu Inouesafe to strip off the ESP/AH header on packet reception, since we
184080d21dc4SYoshinobu Inouewill never use the received packet in "as is" form.
184180d21dc4SYoshinobu Inoue
184280d21dc4SYoshinobu InoueBy using ESP/AH, TCP4/6 effective data segment size will be affected by
184380d21dc4SYoshinobu Inoueextra daisy-chained headers inserted by ESP/AH.  Our code takes care of
184480d21dc4SYoshinobu Inouethe case.
184580d21dc4SYoshinobu Inoue
184680d21dc4SYoshinobu InoueBasic crypto functions can be found in directory "sys/crypto".  ESP/AH
184780d21dc4SYoshinobu Inouetransform are listed in {esp,ah}_core.c with wrapper functions.  If you
184880d21dc4SYoshinobu Inouewish to add some algorithm, add wrapper function in {esp,ah}_core.c, and
184980d21dc4SYoshinobu Inoueadd your crypto algorithm code into sys/crypto.
185080d21dc4SYoshinobu Inoue
18518f336835SJun-ichiro itojun HaginoTunnel mode works basically fine, but comes with the following restrictions:
18528f336835SJun-ichiro itojun Hagino- You cannot run routing daemon across IPsec tunnel, since we do not model
18538f336835SJun-ichiro itojun Hagino  IPsec tunnel as pseudo interfaces.
185480d21dc4SYoshinobu Inoue- Authentication model for AH tunnel must be revisited.  We'll need to
185580d21dc4SYoshinobu Inoue  improve the policy management engine, eventually.
185633841545SHajimu UMEMOTO- Path MTU discovery does not work across IPv6 IPsec tunnel gateway due to
185733841545SHajimu UMEMOTO  insufficient code.
185880d21dc4SYoshinobu Inoue
1859*93b03d5dSUlrich SpörleinAH specification does not talk much about "multiple AH on a packet" case.
18608f336835SJun-ichiro itojun HaginoWe incrementally compute AH checksum, from inside to outside.  Also, we
18618f336835SJun-ichiro itojun Haginotreat inner AH to be immutable.
18628f336835SJun-ichiro itojun HaginoFor example, if we are to create the following packet:
18638f336835SJun-ichiro itojun Hagino	IP AH1 AH2 AH3 payload
18648f336835SJun-ichiro itojun Haginowe do it incrementally.  As a result, we get crypto checksums like below:
18658f336835SJun-ichiro itojun Hagino	AH3 has checksum against "IP AH3' payload".
18668f336835SJun-ichiro itojun Hagino		where AH3' = AH3 with checksum field filled with 0.
18678f336835SJun-ichiro itojun Hagino	AH2 has checksum against "IP AH2' AH3 payload".
18688f336835SJun-ichiro itojun Hagino	AH1 has checksum against "IP AH1' AH2 AH3 payload",
18698f336835SJun-ichiro itojun HaginoAlso note that AH3 has the smallest sequence number, and AH1 has the largest
18708f336835SJun-ichiro itojun Haginosequence number.
18718f336835SJun-ichiro itojun Hagino
187233841545SHajimu UMEMOTOTo avoid traffic analysis on shorter packets, ESP output logic supports
187333841545SHajimu UMEMOTOrandom length padding.  By setting net.inet.ipsec.esp_randpad (or
187433841545SHajimu UMEMOTOnet.inet6.ipsec6.esp_randpad) to positive value N, you can ask the kernel
187533841545SHajimu UMEMOTOto randomly pad packets shorter than N bytes, to random length smaller than
187633841545SHajimu UMEMOTOor equal to N.  Note that N does not include ESP authentication data length.
187733841545SHajimu UMEMOTOAlso note that the random padding is not included in TCP segment
187833841545SHajimu UMEMOTOsize computation.  Negative value will turn off the functionality.
1879*93b03d5dSUlrich SpörleinRecommended value for N is like 128, or 256.  If you use a too big number
1880*93b03d5dSUlrich Spörleinas N, you may experience inefficiency due to fragmented packets.
188133841545SHajimu UMEMOTO
18828f336835SJun-ichiro itojun Hagino4.4 IPComp handling
18838f336835SJun-ichiro itojun Hagino
18848f336835SJun-ichiro itojun HaginoIPComp stands for IP payload compression protocol.  This is aimed for
18858f336835SJun-ichiro itojun Haginopayload compression, not the header compression like PPP VJ compression.
18868f336835SJun-ichiro itojun HaginoThis may be useful when you are using slow serial link (say, cell phone)
18878f336835SJun-ichiro itojun Haginowith powerful CPU (well, recent notebook PCs are really powerful...).
18888f336835SJun-ichiro itojun HaginoThe protocol design of IPComp is very similar to IPsec, though it was
18898f336835SJun-ichiro itojun Haginodefined separately from IPsec itself.
18908f336835SJun-ichiro itojun Hagino
18918f336835SJun-ichiro itojun HaginoHere are some points to be noted:
18928f336835SJun-ichiro itojun Hagino- IPComp is treated as part of IPsec protocol suite, and SPI and
18938f336835SJun-ichiro itojun Hagino  CPI space is unified.  Spec says that there's no relationship
18948f336835SJun-ichiro itojun Hagino  between two so they are assumed to be separate in specs.
18958f336835SJun-ichiro itojun Hagino- IPComp association (IPCA) is kept in SAD.
18968f336835SJun-ichiro itojun Hagino- It is possible to use well-known CPI (CPI=2 for DEFLATE for example),
18978f336835SJun-ichiro itojun Hagino  for outbound/inbound packet, but for indexing purposes one element from
18988f336835SJun-ichiro itojun Hagino  SPI/CPI space will be occupied anyway.
18998f336835SJun-ichiro itojun Hagino- pfkey is modified to support IPComp.  However, there's no official
19008f336835SJun-ichiro itojun Hagino  SA type number assignment yet.  Portability with other IPComp
19018f336835SJun-ichiro itojun Hagino  stack is questionable (anyway, who else implement IPComp on UN*X?).
19028f336835SJun-ichiro itojun Hagino- Spec says that IPComp output processing must be performed before AH/ESP
19038f336835SJun-ichiro itojun Hagino  output processing, to achieve better compression ratio and "stir" data
19048f336835SJun-ichiro itojun Hagino  stream before encryption.  The most meaningful processing order is:
19058f336835SJun-ichiro itojun Hagino  (1) compress payload by IPComp, (2) encrypt payload by ESP, then (3) attach
19068f336835SJun-ichiro itojun Hagino  authentication data by AH.
19078f336835SJun-ichiro itojun Hagino  However, with manual SPD setting, you are able to violate the ordering
19088f336835SJun-ichiro itojun Hagino  (KAME code is too generic, maybe).  Also, it is just okay to use IPComp
19098f336835SJun-ichiro itojun Hagino  alone, without AH/ESP.
19108f336835SJun-ichiro itojun Hagino- Though the packet size can be significantly decreased by using IPComp, no
19118f336835SJun-ichiro itojun Hagino  special consideration is made about path MTU (spec talks nothing about MTU
19128f336835SJun-ichiro itojun Hagino  consideration).  IPComp is designed for serial links, not ethernet-like
19138f336835SJun-ichiro itojun Hagino  medium, it seems.
19148f336835SJun-ichiro itojun Hagino- You can change compression ratio on outbound packet, by changing
19158f336835SJun-ichiro itojun Hagino  deflate_policy in sys/netinet6/ipcomp_core.c.  You can also change outbound
19168f336835SJun-ichiro itojun Hagino  history buffer size by changing deflate_window_out in the same source code.
19178f336835SJun-ichiro itojun Hagino  (should it be sysctl accessible, or per-SAD configurable?)
19188f336835SJun-ichiro itojun Hagino- Tunnel mode IPComp is not working right.  KAME box can generate tunnelled
19198f336835SJun-ichiro itojun Hagino  IPComp packet, however, cannot accept tunneled IPComp packet.
19208f336835SJun-ichiro itojun Hagino- You can negotiate IPComp association with racoon IKE daemon.
19218f336835SJun-ichiro itojun Hagino- KAME code does not attach Adler32 checksum to compressed data.
19228f336835SJun-ichiro itojun Hagino  see ipsec wg mailing list discussion in Jan 2000 for details.
19238f336835SJun-ichiro itojun Hagino
19248f336835SJun-ichiro itojun Hagino4.5 Conformance to RFCs and IDs
192580d21dc4SYoshinobu Inoue
192680d21dc4SYoshinobu InoueThe IPsec code in the kernel conforms (or, tries to conform) to the
192780d21dc4SYoshinobu Inouefollowing standards:
192880d21dc4SYoshinobu Inoue    "old IPsec" specification documented in rfc182[5-9].txt
192933841545SHajimu UMEMOTO    "new IPsec" specification documented in:
1930f88fe57eSHajimu UMEMOTO	rfc240[1-6].txt rfc241[01].txt rfc2451.txt rfc3602.txt
19318f336835SJun-ichiro itojun Hagino    IPComp:
19328f336835SJun-ichiro itojun Hagino	RFC2393: IP Payload Compression Protocol (IPComp)
193333841545SHajimu UMEMOTOIKE specifications (rfc240[7-9].txt) are implemented in userland
193433841545SHajimu UMEMOTOas "racoon" IKE daemon.
193580d21dc4SYoshinobu Inoue
193680d21dc4SYoshinobu InoueCurrently supported algorithms are:
193780d21dc4SYoshinobu Inoue    old IPsec AH
193880d21dc4SYoshinobu Inoue	null crypto checksum (no document, just for debugging)
193980d21dc4SYoshinobu Inoue	keyed MD5 with 128bit crypto checksum (rfc1828.txt)
194080d21dc4SYoshinobu Inoue	keyed SHA1 with 128bit crypto checksum (no document)
194180d21dc4SYoshinobu Inoue	HMAC MD5 with 128bit crypto checksum (rfc2085.txt)
194280d21dc4SYoshinobu Inoue	HMAC SHA1 with 128bit crypto checksum (no document)
1943492528c0SHajimu UMEMOTO	HMAC RIPEMD160 with 128bit crypto checksum (no document)
194480d21dc4SYoshinobu Inoue    old IPsec ESP
194580d21dc4SYoshinobu Inoue	null encryption (no document, similar to rfc2410.txt)
194680d21dc4SYoshinobu Inoue	DES-CBC mode (rfc1829.txt)
194780d21dc4SYoshinobu Inoue    new IPsec AH
194880d21dc4SYoshinobu Inoue	null crypto checksum (no document, just for debugging)
194980d21dc4SYoshinobu Inoue	keyed MD5 with 96bit crypto checksum (no document)
195080d21dc4SYoshinobu Inoue	keyed SHA1 with 96bit crypto checksum (no document)
195180d21dc4SYoshinobu Inoue	HMAC MD5 with 96bit crypto checksum (rfc2403.txt
195280d21dc4SYoshinobu Inoue	HMAC SHA1 with 96bit crypto checksum (rfc2404.txt)
1953743eee66SSUZUKI Shinsuke	HMAC SHA2-256 with 96bit crypto checksum (draft-ietf-ipsec-ciph-sha-256-00.txt)
195433841545SHajimu UMEMOTO	HMAC SHA2-384 with 96bit crypto checksum (no document)
195533841545SHajimu UMEMOTO	HMAC SHA2-512 with 96bit crypto checksum (no document)
1956492528c0SHajimu UMEMOTO	HMAC RIPEMD160 with 96bit crypto checksum (RFC2857)
1957b42ac57fSHajimu UMEMOTO	AES XCBC MAC with 96bit crypto checksum (RFC3566)
195880d21dc4SYoshinobu Inoue    new IPsec ESP
195980d21dc4SYoshinobu Inoue	null encryption (rfc2410.txt)
196080d21dc4SYoshinobu Inoue	DES-CBC with derived IV
196180d21dc4SYoshinobu Inoue		(draft-ietf-ipsec-ciph-des-derived-01.txt, draft expired)
196280d21dc4SYoshinobu Inoue	DES-CBC with explicit IV (rfc2405.txt)
196380d21dc4SYoshinobu Inoue	3DES-CBC with explicit IV (rfc2451.txt)
196480d21dc4SYoshinobu Inoue	BLOWFISH CBC (rfc2451.txt)
196580d21dc4SYoshinobu Inoue	CAST128 CBC (rfc2451.txt)
1966b42ac57fSHajimu UMEMOTO	RIJNDAEL/AES CBC (rfc3602.txt)
1967743eee66SSUZUKI Shinsuke	AES counter mode (rfc3686.txt)
1968b42ac57fSHajimu UMEMOTO
1969743eee66SSUZUKI Shinsuke	each of the above can be combined with new IPsec AH schemes for
1970743eee66SSUZUKI Shinsuke	ESP authentication.
19718f336835SJun-ichiro itojun Hagino    IPComp
19728f336835SJun-ichiro itojun Hagino	RFC2394: IP Payload Compression Using DEFLATE
197380d21dc4SYoshinobu Inoue
197480d21dc4SYoshinobu InoueThe following algorithms are NOT supported:
197580d21dc4SYoshinobu Inoue    old IPsec AH
197680d21dc4SYoshinobu Inoue	HMAC MD5 with 128bit crypto checksum + 64bit replay prevention
197780d21dc4SYoshinobu Inoue		(rfc2085.txt)
197880d21dc4SYoshinobu Inoue	keyed SHA1 with 160bit crypto checksum + 32bit padding (rfc1852.txt)
197980d21dc4SYoshinobu Inoue
19808f336835SJun-ichiro itojun HaginoThe key/policy management API is based on the following document, with fair
19818f336835SJun-ichiro itojun Haginoamount of extensions:
19828f336835SJun-ichiro itojun Hagino	RFC2367: PF_KEY key management API
198380d21dc4SYoshinobu Inoue
19848f336835SJun-ichiro itojun Hagino4.6 ECN consideration on IPsec tunnels
198580d21dc4SYoshinobu Inoue
198680d21dc4SYoshinobu InoueKAME IPsec implements ECN-friendly IPsec tunnel, described in
19878f336835SJun-ichiro itojun Haginodraft-ietf-ipsec-ecn-02.txt.
198880d21dc4SYoshinobu InoueNormal IPsec tunnel is described in RFC2401.  On encapsulation,
198980d21dc4SYoshinobu InoueIPv4 TOS field (or, IPv6 traffic class field) will be copied from inner
199080d21dc4SYoshinobu InoueIP header to outer IP header.  On decapsulation outer IP header
199180d21dc4SYoshinobu Inouewill be simply dropped.  The decapsulation rule is not compatible
199280d21dc4SYoshinobu Inouewith ECN, since ECN bit on the outer IP TOS/traffic class field will be
199380d21dc4SYoshinobu Inouelost.
199480d21dc4SYoshinobu InoueTo make IPsec tunnel ECN-friendly, we should modify encapsulation
199580d21dc4SYoshinobu Inoueand decapsulation procedure.  This is described in
19968f336835SJun-ichiro itojun Haginodraft-ietf-ipsec-ecn-02.txt, chapter 3.3.
199780d21dc4SYoshinobu Inoue
199880d21dc4SYoshinobu InoueKAME IPsec tunnel implementation can give you three behaviors, by setting
199980d21dc4SYoshinobu Inouenet.inet.ipsec.ecn (or net.inet6.ipsec6.ecn) to some value:
200080d21dc4SYoshinobu Inoue- RFC2401: no consideration for ECN (sysctl value -1)
200180d21dc4SYoshinobu Inoue- ECN forbidden (sysctl value 0)
200280d21dc4SYoshinobu Inoue- ECN allowed (sysctl value 1)
200380d21dc4SYoshinobu InoueNote that the behavior is configurable in per-node manner, not per-SA manner
20048f336835SJun-ichiro itojun Hagino(draft-ietf-ipsec-ecn-02 wants per-SA configuration, but it looks too much
20058f336835SJun-ichiro itojun Haginofor me).
200680d21dc4SYoshinobu Inoue
200780d21dc4SYoshinobu InoueThe behavior is summarized as follows (see source code for more detail):
200880d21dc4SYoshinobu Inoue
200980d21dc4SYoshinobu Inoue		encapsulate			decapsulate
201080d21dc4SYoshinobu Inoue		---				---
201180d21dc4SYoshinobu InoueRFC2401		copy all TOS bits		drop TOS bits on outer
201280d21dc4SYoshinobu Inoue		from inner to outer.		(use inner TOS bits as is)
201380d21dc4SYoshinobu Inoue
201480d21dc4SYoshinobu InoueECN forbidden	copy TOS bits except for ECN	drop TOS bits on outer
201580d21dc4SYoshinobu Inoue		(masked with 0xfc) from inner	(use inner TOS bits as is)
201680d21dc4SYoshinobu Inoue		to outer.  set ECN bits to 0.
201780d21dc4SYoshinobu Inoue
201880d21dc4SYoshinobu InoueECN allowed	copy TOS bits except for ECN	use inner TOS bits with some
201980d21dc4SYoshinobu Inoue		CE (masked with 0xfe) from	change.  if outer ECN CE bit
202080d21dc4SYoshinobu Inoue		inner to outer.			is 1, enable ECN CE bit on
202180d21dc4SYoshinobu Inoue		set ECN CE bit to 0.		the inner.
202280d21dc4SYoshinobu Inoue
202380d21dc4SYoshinobu InoueGeneral strategy for configuration is as follows:
202480d21dc4SYoshinobu Inoue- if both IPsec tunnel endpoint are capable of ECN-friendly behavior,
202580d21dc4SYoshinobu Inoue  you'd better configure both end to "ECN allowed" (sysctl value 1).
202680d21dc4SYoshinobu Inoue- if the other end is very strict about TOS bit, use "RFC2401"
202780d21dc4SYoshinobu Inoue  (sysctl value -1).
202880d21dc4SYoshinobu Inoue- in other cases, use "ECN forbidden" (sysctl value 0).
202980d21dc4SYoshinobu InoueThe default behavior is "ECN forbidden" (sysctl value 0).
203080d21dc4SYoshinobu Inoue
203180d21dc4SYoshinobu InoueFor more information, please refer to:
20328f336835SJun-ichiro itojun Hagino	draft-ietf-ipsec-ecn-02.txt
203380d21dc4SYoshinobu Inoue	RFC2481 (Explicit Congestion Notification)
203480d21dc4SYoshinobu Inoue	KAME sys/netinet6/{ah,esp}_input.c
203580d21dc4SYoshinobu Inoue
203680d21dc4SYoshinobu Inoue(Thanks goes to Kenjiro Cho <[email protected]> for detailed analysis)
203780d21dc4SYoshinobu Inoue
20388f336835SJun-ichiro itojun Hagino4.7 Interoperability
20398f336835SJun-ichiro itojun Hagino
20408f336835SJun-ichiro itojun HaginoIPsec, IPComp (in kernel) and IKE (in userland as "racoon") has been tested
20418f336835SJun-ichiro itojun Haginoat several interoperability test events, and it is known to interoperate
20428f336835SJun-ichiro itojun Haginowith many other implementations well.  Also, KAME IPsec has quite wide
20438f336835SJun-ichiro itojun Haginocoverage for IPsec crypto algorithms documented in RFC (we do not cover
20448f336835SJun-ichiro itojun Haginoalgorithms with intellectual property issues, though).
204580d21dc4SYoshinobu Inoue
204680d21dc4SYoshinobu InoueHere are (some of) platforms we have tested IPsec/IKE interoperability
204733841545SHajimu UMEMOTOin the past, no particular order.  Note that both ends (KAME and
20488f336835SJun-ichiro itojun Haginoothers) may have modified their implementation, so use the following
20498f336835SJun-ichiro itojun Haginolist just for reference purposes.
2050743eee66SSUZUKI Shinsuke	6WIND, ACC, Allied-telesis, Altiga, Ashley-laurent (vpcom.com),
2051743eee66SSUZUKI Shinsuke	BlueSteel, CISCO IOS, Checkpoint FW-1, Compaq Tru54 UNIX
2052743eee66SSUZUKI Shinsuke	X5.1B-BL4, Cryptek, Data Fellows (F-Secure), Ericsson,
2053743eee66SSUZUKI Shinsuke	F-Secure VPN+ 5.40, Fitec, Fitel, FreeS/WAN, HITACHI, HiFn,
2054743eee66SSUZUKI Shinsuke	IBM AIX 5.1, III, IIJ (fujie stack), Intel Canada, Intel
2055743eee66SSUZUKI Shinsuke	Packet Protect, MEW NetCocoon, MGCS, Microsoft WinNT/2000/XP,
2056743eee66SSUZUKI Shinsuke	NAI PGPnet, NEC IX5000, NIST (linux IPsec + plutoplus),
2057743eee66SSUZUKI Shinsuke	NetLock, Netoctave, Netopia, Netscreen, Nokia EPOC, Nortel
2058743eee66SSUZUKI Shinsuke	GatewayController/CallServer 2000 (not released yet),
2059743eee66SSUZUKI Shinsuke	NxNetworks, OpenBSD isakmpd on OpenBSD, Oullim information
2060743eee66SSUZUKI Shinsuke	technologies SECUREWORKS VPN gateway 3.0, Pivotal, RSA,
2061743eee66SSUZUKI Shinsuke	Radguard, RapidStream, RedCreek, Routerware, SSH, SecGo
2062743eee66SSUZUKI Shinsuke	CryptoIP v3, Secure Computing, Soliton, Sun Solaris 8,
2063743eee66SSUZUKI Shinsuke	TIS/NAI Gauntret, Toshiba, Trilogy AdmitOne 2.6, Trustworks
2064743eee66SSUZUKI Shinsuke	TrustedClient v3.2, USAGI linux, VPNet, Yamaha RT series,
2065743eee66SSUZUKI Shinsuke	ZyXEL
206680d21dc4SYoshinobu Inoue
20678f336835SJun-ichiro itojun HaginoHere are (some of) platforms we have tested IPComp/IKE interoperability
20688f336835SJun-ichiro itojun Haginoin the past, in no particular order.
2069743eee66SSUZUKI Shinsuke	Compaq, IRE, SSH, NetLock, FreeS/WAN, F-Secure VPN+ 5.40
207033841545SHajimu UMEMOTO
207133841545SHajimu UMEMOTOVPNC (vpnc.org) provides IPsec conformance tests, using KAME and OpenBSD
207233841545SHajimu UMEMOTOIPsec/IKE implementations.  Their test results are available at
207333841545SHajimu UMEMOTOhttp://www.vpnc.org/conformance.html, and it may give you more idea
207433841545SHajimu UMEMOTOabout which implementation interoperates with KAME IPsec/IKE implementation.
207580d21dc4SYoshinobu Inoue
2076f88fe57eSHajimu UMEMOTO4.8 Operations with IPsec tunnel mode
2077f88fe57eSHajimu UMEMOTO
2078f88fe57eSHajimu UMEMOTOFirst of all, IPsec tunnel is a very hairy thing.  It seems to do a neat thing
2079f88fe57eSHajimu UMEMOTOlike VPN configuration or secure remote accesses, however, it comes with lots
2080f88fe57eSHajimu UMEMOTOof architectural twists.
2081f88fe57eSHajimu UMEMOTO
2082f88fe57eSHajimu UMEMOTORFC2401 defines IPsec tunnel mode, within the context of IPsec.  RFC2401
2083f88fe57eSHajimu UMEMOTOdefines tunnel mode packet encapsulation/decapsulation on its own, and
2084f88fe57eSHajimu UMEMOTOdoes not refer other tunnelling specifications.  Since RFC2401 advocates
2085f88fe57eSHajimu UMEMOTOfilter-based SPD database matches, it would be natural for us to implement
2086*93b03d5dSUlrich SpörleinIPsec tunnel mode as filters - not as pseudo interfaces.
2087f88fe57eSHajimu UMEMOTO
2088f88fe57eSHajimu UMEMOTOThere are some people who are trying to separate IPsec "tunnel mode" from
2089f88fe57eSHajimu UMEMOTOthe IPsec itself.  They would like to implement IPsec transport mode only,
2090f88fe57eSHajimu UMEMOTOand combine it with tunneling pseudo devices.  The prime example is found
2091f88fe57eSHajimu UMEMOTOin draft-touch-ipsec-vpn-01.txt.  However, if you really define pseudo
2092f88fe57eSHajimu UMEMOTOinterfaces separately from IPsec, IKE daemons would need to negotiate
2093f88fe57eSHajimu UMEMOTOtransport mode SAs, instead of tunnel mode SAs.  Therefore, we cannot
2094f88fe57eSHajimu UMEMOTOreally mix RFC2401-based interpretation and draft-touch-ipsec-vpn-01.txt
2095f88fe57eSHajimu UMEMOTOinterpretation.
2096f88fe57eSHajimu UMEMOTO
2097f88fe57eSHajimu UMEMOTOThe KAME stack implements can be configured in two ways.  You may need
2098f88fe57eSHajimu UMEMOTOto recompile your kernel to switch the behavior.
2099*93b03d5dSUlrich Spörlein- RFC2401 IPsec tunnel mode approach (4.8.1)
2100f88fe57eSHajimu UMEMOTO- draft-touch-ipsec-vpn approach (4.8.2)
2101f88fe57eSHajimu UMEMOTO	Works in all kernel configuration, but racoon(8) may not interoperate.
2102f88fe57eSHajimu UMEMOTO
2103f88fe57eSHajimu UMEMOTOThere are pros and cons on these approaches:
2104f88fe57eSHajimu UMEMOTO
2105f88fe57eSHajimu UMEMOTORFC2401 IPsec tunnel mode (filter-like) approach
2106f88fe57eSHajimu UMEMOTO	PRO: SPD lookup fits nicely with packet filters (if you integrate them)
2107f88fe57eSHajimu UMEMOTO	CON: cannot run routing daemons across IPsec tunnels
2108f88fe57eSHajimu UMEMOTO	CON: it is very hard to control source address selection on originating
2109f88fe57eSHajimu UMEMOTO		cases
2110f88fe57eSHajimu UMEMOTO	???: IPv6 scope zone is kept the same
2111f88fe57eSHajimu UMEMOTOdraft-touch-ipsec-vpn (transportmode + Pseudo-interface) approach
2112f88fe57eSHajimu UMEMOTO	PRO: run routing daemons across IPsec tunnels
2113f88fe57eSHajimu UMEMOTO	PRO: source address selection can be done normally, by looking at
2114f88fe57eSHajimu UMEMOTO		IPsec tunnel pseudo devices
2115f88fe57eSHajimu UMEMOTO	CON: on outbound, possibility of infinite loops if routing setup
2116f88fe57eSHajimu UMEMOTO		is wrong
2117f88fe57eSHajimu UMEMOTO	CON: due to differences in encap/decap logic from RFC2401, it may not
2118f88fe57eSHajimu UMEMOTO		interoperate with very picky RFC2401 implementations
2119f88fe57eSHajimu UMEMOTO		(those who check TOS bits, for example)
2120f88fe57eSHajimu UMEMOTO	CON: cannot negotiate IKE with other IPsec tunnel-mode devices
2121f88fe57eSHajimu UMEMOTO		(the other end has to implement
2122f88fe57eSHajimu UMEMOTO	???: IPv6 scope zone is likely to be different from the real ethernet
2123f88fe57eSHajimu UMEMOTO		interface
2124f88fe57eSHajimu UMEMOTO
2125f88fe57eSHajimu UMEMOTOThe recommendation is different depending on the situation you have:
2126f88fe57eSHajimu UMEMOTO- use draft-touch-ipsec-vpn if you have the control over the other end.
2127f88fe57eSHajimu UMEMOTO  this one is the best in terms of simplicity.
2128f88fe57eSHajimu UMEMOTO- if the other end is normal IPsec device with RFC2401 implementation,
2129f88fe57eSHajimu UMEMOTO  you need to use RFC2401, otherwise you won't be able to run IKE.
2130f88fe57eSHajimu UMEMOTO- use RFC2401 approach if you just want to forward packets back and forth
2131f88fe57eSHajimu UMEMOTO  and there's no plan to use IPsec gateway itself as an originating device.
2132f88fe57eSHajimu UMEMOTO
2133f88fe57eSHajimu UMEMOTO4.8.1 RFC2401 IPsec tunnel mode approach
2134f88fe57eSHajimu UMEMOTO
2135f88fe57eSHajimu UMEMOTOTo configure your device as RFC2401 IPsec tunnel mode endpoint, you will
2136f88fe57eSHajimu UMEMOTOuse "tunnel" keyword in setkey(8) "spdadd" directives.  Let us assume the
2137f88fe57eSHajimu UMEMOTOfollowing topology (A and B could be a network, like prefix/length):
2138f88fe57eSHajimu UMEMOTO
2139f88fe57eSHajimu UMEMOTO	((((((((((((The internet))))))))))))
2140f88fe57eSHajimu UMEMOTO	  |			  |
2141f88fe57eSHajimu UMEMOTO	  |C (global)		  |D
2142f88fe57eSHajimu UMEMOTO	your device		peer's device
2143f88fe57eSHajimu UMEMOTO	  |A (private)		  |B
2144f88fe57eSHajimu UMEMOTO	==+===== VPN net	==+===== VPN net
2145f88fe57eSHajimu UMEMOTO
2146f88fe57eSHajimu UMEMOTOThe policy configuration directive is like this.  You will need manual
2147f88fe57eSHajimu UMEMOTOSAs, or IKE daemon, for actual encryption:
2148f88fe57eSHajimu UMEMOTO
2149f88fe57eSHajimu UMEMOTO	# setkey -c <<EOF
2150f88fe57eSHajimu UMEMOTO	spdadd A B any -P out ipsec esp/tunnel/C-D/use;
2151f88fe57eSHajimu UMEMOTO	spdadd B A any -P in ipsec esp/tunnel/D-C/use;
2152f88fe57eSHajimu UMEMOTO	^D
2153f88fe57eSHajimu UMEMOTO
2154f88fe57eSHajimu UMEMOTOThe inbound/outbound traffic is monitored/captured by SPD engine, which works
2155f88fe57eSHajimu UMEMOTOjust like packet filters.
2156f88fe57eSHajimu UMEMOTO
2157f88fe57eSHajimu UMEMOTOWith this, forwarding case should work flawlessly.  However, troubles arise
2158f88fe57eSHajimu UMEMOTOwhen you have one of the following requirements:
2159f88fe57eSHajimu UMEMOTO- When you originate traffic from your VPN gateway device to VPN net on the
2160f88fe57eSHajimu UMEMOTO  other end (like B), you want your source address to be A (private side)
2161f88fe57eSHajimu UMEMOTO  so that the traffic would be protected by the policy.
2162f88fe57eSHajimu UMEMOTO  With this approach, however, the source address selection logic follows
2163f88fe57eSHajimu UMEMOTO  normal routing table, and C (global side) will be picked for any outgoing
2164f88fe57eSHajimu UMEMOTO  traffic, even if the destination is B.  The resulting packet will be like
2165f88fe57eSHajimu UMEMOTO  this:
2166f88fe57eSHajimu UMEMOTO	IP[C -> B] payload
2167f88fe57eSHajimu UMEMOTO  and will not match the policy (= sent in clear).
2168f88fe57eSHajimu UMEMOTO- When you want to run routing protocols on top of the IPsec tunnel, it is
2169f88fe57eSHajimu UMEMOTO  not possible.  As there is no pseudo device that identifies the IPsec tunnel,
2170f88fe57eSHajimu UMEMOTO  you cannot identify where the routing information came from.  As a result,
2171f88fe57eSHajimu UMEMOTO  you can't run routing daemons.
2172f88fe57eSHajimu UMEMOTO
2173f88fe57eSHajimu UMEMOTO4.8.2 draft-touch-ipsec-vpn approach
2174f88fe57eSHajimu UMEMOTO
2175f88fe57eSHajimu UMEMOTOWith this approach, you will configure gif(4) tunnel interfaces, as well as
2176f88fe57eSHajimu UMEMOTOIPsec transport mode SAs.
2177f88fe57eSHajimu UMEMOTO
2178f88fe57eSHajimu UMEMOTO	# gifconfig gif0 C D
2179f88fe57eSHajimu UMEMOTO	# ifconfig gif0 A B
2180f88fe57eSHajimu UMEMOTO	# setkey -c <<EOF
2181f88fe57eSHajimu UMEMOTO	spdadd C D any -P out ipsec esp/transport//use;
2182f88fe57eSHajimu UMEMOTO	spdadd D C any -P in ipsec esp/transport//use;
2183f88fe57eSHajimu UMEMOTO	^D
2184f88fe57eSHajimu UMEMOTO
2185f88fe57eSHajimu UMEMOTOSince we have a pseudo-interface "gif0", and it affects the routes and
2186f88fe57eSHajimu UMEMOTOthe source address selection logic, we can have source address A, for
2187f88fe57eSHajimu UMEMOTOpackets originated by the VPN gateway to B (and the VPN cloud).
2188f88fe57eSHajimu UMEMOTOWe can also exchange routing information over the tunnel (gif0), as the tunnel
2189f88fe57eSHajimu UMEMOTOis represented as a pseudo interface (dynamic routes points to the
2190f88fe57eSHajimu UMEMOTOpseudo interface).
2191f88fe57eSHajimu UMEMOTO
2192f88fe57eSHajimu UMEMOTOThere is a big drawbacks, however; with this, you can use IKE if and only if
2193f88fe57eSHajimu UMEMOTOthe other end is using draft-touch-ipsec-vpn approach too.  Since racoon(8)
2194f88fe57eSHajimu UMEMOTOgrabs phase 2 IKE proposals from the kernel SPD database, you will be
2195f88fe57eSHajimu UMEMOTOnegotiating IPsec transport-mode SAs with the other end, not tunnel-mode SAs.
2196f88fe57eSHajimu UMEMOTOAlso, since the encapsulation mechanism is different from RFC2401, you may not
2197f88fe57eSHajimu UMEMOTObe able to interoperate with a picky RFC2401 implementations - if the other
2198f88fe57eSHajimu UMEMOTOend checks certain outer IP header fields (like TOS), you will not be able to
2199f88fe57eSHajimu UMEMOTOinteroperate.
2200f88fe57eSHajimu UMEMOTO
2201f88fe57eSHajimu UMEMOTO
22028f336835SJun-ichiro itojun Hagino5. ALTQ
220380d21dc4SYoshinobu Inoue
2204743eee66SSUZUKI ShinsukeKAME kit includes ALTQ, which supports FreeBSD3, FreeBSD4, FreeBSD5
2205743eee66SSUZUKI ShinsukeNetBSD.  OpenBSD has ALTQ merged into pf and its ALTQ code is not
2206743eee66SSUZUKI Shinsukecompatible with other platforms so that KAME's ALTQ is not used for
2207743eee66SSUZUKI ShinsukeOpenBSD.  For BSD/OS, ALTQ does not work.
2208743eee66SSUZUKI ShinsukeALTQ in KAME supports IPv6.
220933841545SHajimu UMEMOTO(actually, ALTQ is developed on KAME repository since ALTQ 2.1 - Jan 2000)
221033841545SHajimu UMEMOTO
221133841545SHajimu UMEMOTOALTQ occupies single character device number.  For FreeBSD, it is officially
221233841545SHajimu UMEMOTOallocated.  For OpenBSD and NetBSD, we use the number which is not
221333841545SHajimu UMEMOTOcurrently allocated (will eventually get an official number).
221433841545SHajimu UMEMOTOThe character device is enabled for i386 architecture only.  To enable and
2215*93b03d5dSUlrich Spörleincompile ALTQ-ready kernel for other architectures, take the following steps:
221633841545SHajimu UMEMOTO- assume that your architecture is FOOBAA.
221733841545SHajimu UMEMOTO- modify sys/arch/FOOBAA/FOOBAA/conf.c (or somewhere that defines cdevsw),
221833841545SHajimu UMEMOTO  to include a line for ALTQ.  look at sys/arch/i386/i386/conf.c for
221933841545SHajimu UMEMOTO  example.  The major number must be same as i386 case.
222033841545SHajimu UMEMOTO- copy kernel configuration file (like ALTQ.v6 or GENERIC.v6) from i386,
222133841545SHajimu UMEMOTO  and modify accordingly.
222233841545SHajimu UMEMOTO- build a kernel.
222333841545SHajimu UMEMOTO- before building userland, change netbsd/{lib,usr.sbin,usr.bin}/Makefile
222433841545SHajimu UMEMOTO  (or openbsd/foobaa) so that it will visit altq-related sub directories.
222580d21dc4SYoshinobu Inoue
2226743eee66SSUZUKI Shinsuke
2227743eee66SSUZUKI Shinsuke6. Mobile IPv6
222880d21dc4SYoshinobu Inoue
222933841545SHajimu UMEMOTO6.1 KAME node as correspondent node
223033841545SHajimu UMEMOTO
223133841545SHajimu UMEMOTODefault installation recognizes home address option (in destination
2232*93b03d5dSUlrich Spörleinoptions header).  No sub-options are supported.  Interaction with
223333841545SHajimu UMEMOTOIPsec, and/or 2292bis API, needs further study.
223433841545SHajimu UMEMOTO
223533841545SHajimu UMEMOTO6.2 KAME node as home agent/mobile node
223633841545SHajimu UMEMOTO
223733841545SHajimu UMEMOTOKAME kit includes Ericsson mobile-ip6 code.  The integration is just started
223833841545SHajimu UMEMOTO(in Feb 2000), and we will need some more time to integrate it better.
223933841545SHajimu UMEMOTO
224033841545SHajimu UMEMOTOSee kame/mip6config/{QUICKSTART,README_MIP6.txt} for more details.
224133841545SHajimu UMEMOTO
224233841545SHajimu UMEMOTOThe Ericsson code implements revision 09 of the mobile-ip6 draft.  There
224333841545SHajimu UMEMOTOare other implementations available:
224433841545SHajimu UMEMOTO	NEC: http://www.6bone.nec.co.jp/mipv6/internal-dist/ (-13 draft)
224533841545SHajimu UMEMOTO	SFC: http://neo.sfc.wide.ad.jp/~mip6/ (-13 draft)
224633841545SHajimu UMEMOTO
224733841545SHajimu UMEMOTO7. Coding style
224833841545SHajimu UMEMOTO
224933841545SHajimu UMEMOTOThe KAME developers basically do not make a bother about coding
225033841545SHajimu UMEMOTOstyle.  However, there is still some agreement on the style, in order
2251*93b03d5dSUlrich Spörleinto make the distributed development smooth.
225233841545SHajimu UMEMOTO
2253f88fe57eSHajimu UMEMOTO- follow *BSD KNF where possible.  note: there are multiple KNF standards.
225433841545SHajimu UMEMOTO- the tab character should be 8 columns wide (tabstops are at 8, 16, 24, ...
225533841545SHajimu UMEMOTO  column).  With vi, use ":set ts=8 sw=8".
2256f88fe57eSHajimu UMEMOTO  With GNU Emacs 20 and later, the easiest way is to use the "bsd" style of
2257f88fe57eSHajimu UMEMOTO  cc-mode with the variable "c-basic-offset" being 8;
2258f88fe57eSHajimu UMEMOTO  (add-hook 'c-mode-common-hook
2259f88fe57eSHajimu UMEMOTO	    (function
2260f88fe57eSHajimu UMEMOTO	     (lambda ()
2261f88fe57eSHajimu UMEMOTO	       (c-set-style "bsd")
2262f88fe57eSHajimu UMEMOTO	       (setq c-basic-offset 8)  ; XXX for Emacs 20 only
2263f88fe57eSHajimu UMEMOTO	       )))
2264f88fe57eSHajimu UMEMOTO  The "bsd" style in GNU Emacs 21 sets the variable to 8 by default,
2265f88fe57eSHajimu UMEMOTO  so the line marked by "XXX" is not necessary if you only use GNU
2266f88fe57eSHajimu UMEMOTO  Emacs 21.
226733841545SHajimu UMEMOTO- each line should be within 80 characters.
226833841545SHajimu UMEMOTO- keep a single open/close bracket in a comment such as in the following
226933841545SHajimu UMEMOTO  line:
227033841545SHajimu UMEMOTO	putchar('(');	/* ) */
227133841545SHajimu UMEMOTO  without this, some vi users would have a hard time to match a pair of
227233841545SHajimu UMEMOTO  brackets.  Although this type of bracket seems clumsy and is even
227333841545SHajimu UMEMOTO  harmful for some other type of vi users and Emacs users, the
227433841545SHajimu UMEMOTO  agreement in the KAME developers is to allow it.
227533841545SHajimu UMEMOTO- add the following line to the head of every KAME-derived file:
227633841545SHajimu UMEMOTO  /*	(dollar)KAME(dollar)	*/
227733841545SHajimu UMEMOTO  where "(dollar)" is the dollar character ($), and around "$" are tabs.
227833841545SHajimu UMEMOTO  (this is for C.  For other language, you should use its own comment
227933841545SHajimu UMEMOTO  line.)
2280*93b03d5dSUlrich Spörlein  Once committed to the CVS repository, this line will contain its
228133841545SHajimu UMEMOTO  version number (see, for example, at the top of this file).  This
228233841545SHajimu UMEMOTO  would make it easy to report a bug.
228333841545SHajimu UMEMOTO- when creating a new file with the WIDE copyright, tap "make copyright.c" at
228433841545SHajimu UMEMOTO  the top-level, and use copyright.c as a template.  KAME RCS tag will be
228533841545SHajimu UMEMOTO  included automatically.
2286*93b03d5dSUlrich Spörlein- when editing a third-party package, keep its own coding style as
228733841545SHajimu UMEMOTO  much as possible, even if the style does not follow the items above.
2288f88fe57eSHajimu UMEMOTO- it is recommended to always wrap an expression containing
2289f88fe57eSHajimu UMEMOTO  bitwise operators by parentheses, especially when the expression is
2290f88fe57eSHajimu UMEMOTO  combined with relational operators, in order to avoid unintentional
2291f88fe57eSHajimu UMEMOTO  mismatch of operators.  Thus, we should write
2292f88fe57eSHajimu UMEMOTO	if ((a & b) == 0)	/* (A) */
2293f88fe57eSHajimu UMEMOTO  or
2294f88fe57eSHajimu UMEMOTO	if (a & (b == 0))	/* (B) */
2295f88fe57eSHajimu UMEMOTO  instead of
2296f88fe57eSHajimu UMEMOTO	if (a & b == 0)		/* (C) */
2297f88fe57eSHajimu UMEMOTO  even if the programmer's intention was (C), which is equivalent to
2298f88fe57eSHajimu UMEMOTO  (B) according to the grammar of the language C.
2299f88fe57eSHajimu UMEMOTO  Thus, we should write a code to test if a bit-flag is set for a
2300f88fe57eSHajimu UMEMOTO  given variable as follows:
2301f88fe57eSHajimu UMEMOTO	if ((flag & FLAG_A) == 0)	/* (D) the FLAG_A is NOT set */
2302f88fe57eSHajimu UMEMOTO	if ((flag & FLAG_A) != 0)	/* (E) the FLAG_A is set */
2303f88fe57eSHajimu UMEMOTO  Some developers in the KAME project rather prefer the following style:
2304f88fe57eSHajimu UMEMOTO	if (!(flag & FLAG_A))	/* (F) the FLAG_A is NOT set */
2305f88fe57eSHajimu UMEMOTO	if ((flag & FLAG_A))	/* (G) the FLAG_A is set */
2306f88fe57eSHajimu UMEMOTO  because it would be more intuitive in terms of the relationship
2307f88fe57eSHajimu UMEMOTO  between the negation operator (!) and the semantics of the
2308f88fe57eSHajimu UMEMOTO  condition.  The KAME developers have discussed the style, and have
2309f88fe57eSHajimu UMEMOTO  agreed that all the styles from (D) to (G) are valid.  So, when you
2310f88fe57eSHajimu UMEMOTO  see styles like (D) and (E) in the KAME code and feel a bit strange,
2311f88fe57eSHajimu UMEMOTO  please just keep them.  They are intentional.
2312f88fe57eSHajimu UMEMOTO- When inserting a separate block just to define some intra-block
2313f88fe57eSHajimu UMEMOTO  variables, add the level of indentation as if the block was in a
2314f88fe57eSHajimu UMEMOTO  control statement such as if-else, for, or while.  For example,
2315f88fe57eSHajimu UMEMOTO	foo ()
2316f88fe57eSHajimu UMEMOTO	{
2317f88fe57eSHajimu UMEMOTO		int a;
2318f88fe57eSHajimu UMEMOTO
2319f88fe57eSHajimu UMEMOTO		{
2320f88fe57eSHajimu UMEMOTO			int internal_a;
2321f88fe57eSHajimu UMEMOTO			...
2322f88fe57eSHajimu UMEMOTO		}
2323f88fe57eSHajimu UMEMOTO	}
2324f88fe57eSHajimu UMEMOTO  should be used, instead of
2325f88fe57eSHajimu UMEMOTO	foo ()
2326f88fe57eSHajimu UMEMOTO	{
2327f88fe57eSHajimu UMEMOTO		int a;
2328f88fe57eSHajimu UMEMOTO
2329f88fe57eSHajimu UMEMOTO	    {
2330f88fe57eSHajimu UMEMOTO		int internal_a;
2331f88fe57eSHajimu UMEMOTO		...
2332f88fe57eSHajimu UMEMOTO	     }
2333f88fe57eSHajimu UMEMOTO	}
2334f88fe57eSHajimu UMEMOTO- Do not use printf() or log() in the packet input path of the kernel code.
2335f88fe57eSHajimu UMEMOTO  They can make the system vulnerable to packet flooding attacks (results in
2336f88fe57eSHajimu UMEMOTO  /var overflow).
2337f88fe57eSHajimu UMEMOTO- (not a style issue)
2338f88fe57eSHajimu UMEMOTO  To disable a module that is mistakenly imported (by CVS), just
2339f88fe57eSHajimu UMEMOTO  remove the source tree in the repository.  Note, however, that the
2340f88fe57eSHajimu UMEMOTO  removal might annoy other developers who have already checked the
2341f88fe57eSHajimu UMEMOTO  module out, so you should announce the removal as soon as possible.
2342f88fe57eSHajimu UMEMOTO  Also, be 100% sure not to remove other modules.
234333841545SHajimu UMEMOTO
234433841545SHajimu UMEMOTOWhen you want to contribute something to the KAME project, and if *you
234533841545SHajimu UMEMOTOdo not mind* the agreement, it would be helpful for the project to
234633841545SHajimu UMEMOTOkeep these rules.  Note, however, that we would never intend to force
234733841545SHajimu UMEMOTOyou to adopt our rules.  We would rather regard your own style,
234833841545SHajimu UMEMOTOespecially when you have a policy about the style.
234980d21dc4SYoshinobu Inoue
2350f88fe57eSHajimu UMEMOTO
23512ea36b5dSBjoern A. Zeeb8. Policy on technology with intellectual property right restriction
2352f88fe57eSHajimu UMEMOTO
2353f88fe57eSHajimu UMEMOTOThere are quite a few IETF documents/whatever which has intellectual property
2354f88fe57eSHajimu UMEMOTOright (IPR) restriction.  KAME's stance is stated below.
2355f88fe57eSHajimu UMEMOTO
2356f88fe57eSHajimu UMEMOTO    The goal of KAME is to provide freely redistributable, BSD-licensed,
2357f88fe57eSHajimu UMEMOTO    implementation of Internet protocol technologies.
2358f88fe57eSHajimu UMEMOTO    For this purpose, we implement protocols that (1) do not need license
2359f88fe57eSHajimu UMEMOTO    contract with IPR holder, and (2) are royalty-free.
2360f88fe57eSHajimu UMEMOTO    The reason for (1) is, even if KAME contracts with the IPR holder in
2361f88fe57eSHajimu UMEMOTO    question, the users of KAME stack (usually implementers of some other
2362f88fe57eSHajimu UMEMOTO    codebase) would need to make a license contract with the IPR holder.
2363f88fe57eSHajimu UMEMOTO    It would damage the "freely redistributable" status of KAME codebase.
2364f88fe57eSHajimu UMEMOTO
2365f88fe57eSHajimu UMEMOTO    By doing so KAME is (implicitly) trying to advocate no-license-contract,
2366f88fe57eSHajimu UMEMOTO    royalty-free, release of IPRs.
2367f88fe57eSHajimu UMEMOTO
2368f88fe57eSHajimu UMEMOTONote however, as documented in README, we do not guarantee that KAME code
2369f88fe57eSHajimu UMEMOTOis free of IPR infringement, you MUST check it if you are to integrate
2370f88fe57eSHajimu UMEMOTOKAME into your product (or whatever):
2371f88fe57eSHajimu UMEMOTO    READ CAREFULLY: Several countries have legal enforcement for
2372f88fe57eSHajimu UMEMOTO    export/import/use of cryptographic software.  Check it before playing
2373*93b03d5dSUlrich Spörlein    with the kit.  We do not intend to be your legalese clearing house
2374f88fe57eSHajimu UMEMOTO    (NO WARRANTY).  If you intend to include KAME stack into your product,
2375f88fe57eSHajimu UMEMOTO    you'll need to check if the licenses on each file fit your situations,
2376f88fe57eSHajimu UMEMOTO    and/or possible intellectual property right issues.
2377f88fe57eSHajimu UMEMOTO
237880d21dc4SYoshinobu Inoue						 <end of IMPLEMENTATION>
2379