180d21dc4SYoshinobu Inoue Implementation Note 280d21dc4SYoshinobu Inoue 380d21dc4SYoshinobu Inoue KAME Project 41f9aaf18SWolfram Schneider https://www.kame.net/ 533841545SHajimu UMEMOTO $KAME: IMPLEMENTATION,v 1.216 2001/05/25 07:43:01 jinmei Exp $ 680d21dc4SYoshinobu Inoue 7f88fe57eSHajimu UMEMOTONOTE: The document tries to describe behaviors/implementation choices 82ea36b5dSBjoern A. Zeebof the latest KAME/*BSD stack. The description here may not be 92ea36b5dSBjoern A. Zeebapplicable to KAME-integrated *BSD releases, as we have certain amount 102ea36b5dSBjoern A. Zeebof changes between them. Still, some of the content can be useful for 112ea36b5dSBjoern A. ZeebKAME-integrated *BSD releases. 12f88fe57eSHajimu UMEMOTO 13f88fe57eSHajimu UMEMOTOTable of Contents 14f88fe57eSHajimu UMEMOTO 15f88fe57eSHajimu UMEMOTO 1. IPv6 16f88fe57eSHajimu UMEMOTO 1.1 Conformance 17f88fe57eSHajimu UMEMOTO 1.2 Neighbor Discovery 18f88fe57eSHajimu UMEMOTO 1.3 Scope Zone Index 19f88fe57eSHajimu UMEMOTO 1.3.1 Kernel internal 20f88fe57eSHajimu UMEMOTO 1.3.2 Interaction with API 21f88fe57eSHajimu UMEMOTO 1.3.3 Interaction with users (command line) 22f88fe57eSHajimu UMEMOTO 1.4 Plug and Play 23f88fe57eSHajimu UMEMOTO 1.4.1 Assignment of link-local, and special addresses 24f88fe57eSHajimu UMEMOTO 1.4.2 Stateless address autoconfiguration on hosts 25f88fe57eSHajimu UMEMOTO 1.4.3 DHCPv6 26f88fe57eSHajimu UMEMOTO 1.5 Generic tunnel interface 27f88fe57eSHajimu UMEMOTO 1.6 Address Selection 28f88fe57eSHajimu UMEMOTO 1.6.1 Source Address Selection 29f88fe57eSHajimu UMEMOTO 1.6.2 Destination Address Ordering 30f88fe57eSHajimu UMEMOTO 1.7 Jumbo Payload 31f88fe57eSHajimu UMEMOTO 1.8 Loop prevention in header processing 32f88fe57eSHajimu UMEMOTO 1.9 ICMPv6 33f88fe57eSHajimu UMEMOTO 1.10 Applications 34f88fe57eSHajimu UMEMOTO 1.11 Kernel Internals 35f88fe57eSHajimu UMEMOTO 1.12 IPv4 mapped address and IPv6 wildcard socket 36f88fe57eSHajimu UMEMOTO 1.12.1 KAME/BSDI3 and KAME/FreeBSD228 37f88fe57eSHajimu UMEMOTO 1.12.2 KAME/FreeBSD[34]x 38f88fe57eSHajimu UMEMOTO 1.12.2.1 KAME/FreeBSD[34]x, listening side 39f88fe57eSHajimu UMEMOTO 1.12.2.2 KAME/FreeBSD[34]x, initiating side 40f88fe57eSHajimu UMEMOTO 1.12.3 KAME/NetBSD 41f88fe57eSHajimu UMEMOTO 1.12.3.1 KAME/NetBSD, listening side 42f88fe57eSHajimu UMEMOTO 1.12.3.2 KAME/NetBSD, initiating side 43f88fe57eSHajimu UMEMOTO 1.12.4 KAME/BSDI4 44f88fe57eSHajimu UMEMOTO 1.12.4.1 KAME/BSDI4, listening side 45f88fe57eSHajimu UMEMOTO 1.12.4.2 KAME/BSDI4, initiating side 46f88fe57eSHajimu UMEMOTO 1.12.5 KAME/OpenBSD 47f88fe57eSHajimu UMEMOTO 1.12.5.1 KAME/OpenBSD, listening side 48f88fe57eSHajimu UMEMOTO 1.12.5.2 KAME/OpenBSD, initiating side 49f88fe57eSHajimu UMEMOTO 1.12.6 More issues 50f88fe57eSHajimu UMEMOTO 1.12.7 Interaction with SIIT translator 51f88fe57eSHajimu UMEMOTO 1.13 sockaddr_storage 52f88fe57eSHajimu UMEMOTO 1.14 Invalid addresses on the wire 53f88fe57eSHajimu UMEMOTO 1.15 Node's required addresses 54f88fe57eSHajimu UMEMOTO 1.15.1 Host case 55f88fe57eSHajimu UMEMOTO 1.15.2 Router case 56f88fe57eSHajimu UMEMOTO 1.16 Advanced API 57f88fe57eSHajimu UMEMOTO 1.17 DNS resolver 58f88fe57eSHajimu UMEMOTO 2. Network Drivers 59f88fe57eSHajimu UMEMOTO 2.1 FreeBSD 2.2.x-RELEASE 60f88fe57eSHajimu UMEMOTO 2.2 BSD/OS 3.x 61f88fe57eSHajimu UMEMOTO 2.3 NetBSD 62f88fe57eSHajimu UMEMOTO 2.4 FreeBSD 3.x-RELEASE 63f88fe57eSHajimu UMEMOTO 2.5 FreeBSD 4.x-RELEASE 64f88fe57eSHajimu UMEMOTO 2.6 OpenBSD 2.x 65f88fe57eSHajimu UMEMOTO 2.7 BSD/OS 4.x 66f88fe57eSHajimu UMEMOTO 3. Translator 67f88fe57eSHajimu UMEMOTO 3.1 FAITH TCP relay translator 68f88fe57eSHajimu UMEMOTO 3.2 IPv6-to-IPv4 header translator 69f88fe57eSHajimu UMEMOTO 4. IPsec 70f88fe57eSHajimu UMEMOTO 4.1 Policy Management 71f88fe57eSHajimu UMEMOTO 4.2 Key Management 72f88fe57eSHajimu UMEMOTO 4.3 AH and ESP handling 73f88fe57eSHajimu UMEMOTO 4.4 IPComp handling 74f88fe57eSHajimu UMEMOTO 4.5 Conformance to RFCs and IDs 75f88fe57eSHajimu UMEMOTO 4.6 ECN consideration on IPsec tunnels 76f88fe57eSHajimu UMEMOTO 4.7 Interoperability 77f88fe57eSHajimu UMEMOTO 4.8 Operations with IPsec tunnel mode 78f88fe57eSHajimu UMEMOTO 4.8.1 RFC2401 IPsec tunnel mode approach 79f88fe57eSHajimu UMEMOTO 4.8.2 draft-touch-ipsec-vpn approach 80f88fe57eSHajimu UMEMOTO 5. ALTQ 81f88fe57eSHajimu UMEMOTO 6. Mobile IPv6 82f88fe57eSHajimu UMEMOTO 6.1 KAME node as correspondent node 83f88fe57eSHajimu UMEMOTO 6.2 KAME node as home agent/mobile node 84f88fe57eSHajimu UMEMOTO 6.3 Old Mobile IPv6 code 852ea36b5dSBjoern A. Zeeb 7. Coding style 862ea36b5dSBjoern A. Zeeb 8. Policy on technology with intellectual property right restriction 87f88fe57eSHajimu UMEMOTO 8880d21dc4SYoshinobu Inoue1. IPv6 8980d21dc4SYoshinobu Inoue 9080d21dc4SYoshinobu Inoue1.1 Conformance 9180d21dc4SYoshinobu Inoue 9280d21dc4SYoshinobu InoueThe KAME kit conforms, or tries to conform, to the latest set of IPv6 9380d21dc4SYoshinobu Inouespecifications. For future reference we list some of the relevant documents 9480d21dc4SYoshinobu Inouebelow (NOTE: this is not a complete list - this is too hard to maintain...). 9580d21dc4SYoshinobu InoueFor details please refer to specific chapter in the document, RFCs, manpages 9680d21dc4SYoshinobu Inouecome with KAME, or comments in the source code. 9780d21dc4SYoshinobu Inoue 988f336835SJun-ichiro itojun HaginoConformance tests have been performed on past and latest KAME STABLE kit, 9980d21dc4SYoshinobu Inoueat TAHI project. Results can be viewed at http://www.tahi.org/report/KAME/. 10080d21dc4SYoshinobu InoueWe also attended Univ. of New Hampshire IOL tests (http://www.iol.unh.edu/) 10180d21dc4SYoshinobu Inouein the past, with our past snapshots. 10280d21dc4SYoshinobu Inoue 10380d21dc4SYoshinobu InoueRFC1639: FTP Operation Over Big Address Records (FOOBAR) 10480d21dc4SYoshinobu Inoue * RFC2428 is preferred over RFC1639. ftp clients will first try RFC2428, 10580d21dc4SYoshinobu Inoue then RFC1639 if failed. 10680d21dc4SYoshinobu InoueRFC1886: DNS Extensions to support IPv6 10733841545SHajimu UMEMOTORFC1933: (see RFC2893) 10880d21dc4SYoshinobu InoueRFC1981: Path MTU Discovery for IPv6 10980d21dc4SYoshinobu InoueRFC2080: RIPng for IPv6 11080d21dc4SYoshinobu Inoue * KAME-supplied route6d, bgpd and hroute6d support this. 11180d21dc4SYoshinobu InoueRFC2283: Multiprotocol Extensions for BGP-4 11280d21dc4SYoshinobu Inoue * so-called "BGP4+". 11380d21dc4SYoshinobu Inoue * KAME-supplied bgpd supports this. 11480d21dc4SYoshinobu InoueRFC2292: Advanced Sockets API for IPv6 115f88fe57eSHajimu UMEMOTO * see RFC3542 11680d21dc4SYoshinobu InoueRFC2362: Protocol Independent Multicast-Sparse Mode (PIM-SM) 11733841545SHajimu UMEMOTO * RFC2362 defines the packet formats and the protcol of PIM-SM. 11880d21dc4SYoshinobu InoueRFC2373: IPv6 Addressing Architecture 11980d21dc4SYoshinobu Inoue * KAME supports node required addresses, and conforms to the scope 12080d21dc4SYoshinobu Inoue requirement. 12180d21dc4SYoshinobu InoueRFC2374: An IPv6 Aggregatable Global Unicast Address Format 12280d21dc4SYoshinobu Inoue * KAME supports 64-bit length of Interface ID. 12380d21dc4SYoshinobu InoueRFC2375: IPv6 Multicast Address Assignments 12480d21dc4SYoshinobu Inoue * Userland applications use the well-known addresses assigned in the RFC. 12580d21dc4SYoshinobu InoueRFC2428: FTP Extensions for IPv6 and NATs 12680d21dc4SYoshinobu Inoue * RFC2428 is preferred over RFC1639. ftp clients will first try RFC2428, 12780d21dc4SYoshinobu Inoue then RFC1639 if failed. 12880d21dc4SYoshinobu InoueRFC2460: IPv6 specification 12980d21dc4SYoshinobu InoueRFC2461: Neighbor discovery for IPv6 13080d21dc4SYoshinobu Inoue * See 1.2 in this document for details. 13180d21dc4SYoshinobu InoueRFC2462: IPv6 Stateless Address Autoconfiguration 13280d21dc4SYoshinobu Inoue * See 1.4 in this document for details. 13380d21dc4SYoshinobu InoueRFC2463: ICMPv6 for IPv6 specification 134f88fe57eSHajimu UMEMOTO * See 1.9 in this document for details. 13580d21dc4SYoshinobu InoueRFC2464: Transmission of IPv6 Packets over Ethernet Networks 13680d21dc4SYoshinobu InoueRFC2465: MIB for IPv6: Textual Conventions and General Group 13780d21dc4SYoshinobu Inoue * Necessary statistics are gathered by the kernel. Actual IPv6 MIB 13880d21dc4SYoshinobu Inoue support is provided as patchkit for ucd-snmp. 13980d21dc4SYoshinobu InoueRFC2466: MIB for IPv6: ICMPv6 group 14080d21dc4SYoshinobu Inoue * Necessary statistics are gathered by the kernel. Actual IPv6 MIB 14180d21dc4SYoshinobu Inoue support is provided as patchkit for ucd-snmp. 14280d21dc4SYoshinobu InoueRFC2467: Transmission of IPv6 Packets over FDDI Networks 14380d21dc4SYoshinobu InoueRFC2472: IPv6 over PPP 14480d21dc4SYoshinobu InoueRFC2492: IPv6 over ATM Networks 14580d21dc4SYoshinobu Inoue * only PVC is supported. 14680d21dc4SYoshinobu InoueRFC2497: Transmission of IPv6 packet over ARCnet Networks 14780d21dc4SYoshinobu InoueRFC2545: Use of BGP-4 Multiprotocol Extensions for IPv6 Inter-Domain Routing 148f88fe57eSHajimu UMEMOTORFC2553: (see RFC3493) 14933841545SHajimu UMEMOTORFC2671: Extension Mechanisms for DNS (EDNS0) 15033841545SHajimu UMEMOTO * see USAGE for how to use it. 15133841545SHajimu UMEMOTO * not supported on kame/freebsd4 and kame/bsdi4. 15233841545SHajimu UMEMOTORFC2673: Binary Labels in the Domain Name System 15333841545SHajimu UMEMOTO * KAME/bsdi4 supports A6, DNAME and binary label to some extent. 15433841545SHajimu UMEMOTO * KAME apps/bind8 repository has resolver library with partial A6, DNAME 15533841545SHajimu UMEMOTO and binary label support. 15680d21dc4SYoshinobu InoueRFC2675: IPv6 Jumbograms 15780d21dc4SYoshinobu Inoue * See 1.7 in this document for details. 15880d21dc4SYoshinobu InoueRFC2710: Multicast Listener Discovery for IPv6 15980d21dc4SYoshinobu InoueRFC2711: IPv6 router alert option 1608f336835SJun-ichiro itojun HaginoRFC2732: Format for Literal IPv6 Addresses in URL's 1618f336835SJun-ichiro itojun Hagino * The spec is implemented in programs that handle URLs 1628f336835SJun-ichiro itojun Hagino (like freebsd ftpio(3) and fetch(1), or netbsd ftp(1)) 16333841545SHajimu UMEMOTORFC2874: DNS Extensions to Support IPv6 Address Aggregation and Renumbering 16433841545SHajimu UMEMOTO * KAME/bsdi4 supports A6, DNAME and binary label to some extent. 16533841545SHajimu UMEMOTO * KAME apps/bind8 repository has resolver library with partial A6, DNAME 16633841545SHajimu UMEMOTO and binary label support. 16733841545SHajimu UMEMOTORFC2893: Transition Mechanisms for IPv6 Hosts and Routers 16833841545SHajimu UMEMOTO * IPv4 compatible address is not supported. 16933841545SHajimu UMEMOTO * automatic tunneling (4.3) is not supported. 17033841545SHajimu UMEMOTO * "gif" interface implements IPv[46]-over-IPv[46] tunnel in a generic way, 17133841545SHajimu UMEMOTO and it covers "configured tunnel" described in the spec. 17233841545SHajimu UMEMOTO See 1.5 in this document for details. 17333841545SHajimu UMEMOTORFC2894: Router renumbering for IPv6 17433841545SHajimu UMEMOTORFC3041: Privacy Extensions for Stateless Address Autoconfiguration in IPv6 17533841545SHajimu UMEMOTORFC3056: Connection of IPv6 Domains via IPv4 Clouds 17633841545SHajimu UMEMOTO * So-called "6to4". 17733841545SHajimu UMEMOTO * "stf" interface implements it. Be sure to read 17833841545SHajimu UMEMOTO draft-itojun-ipv6-transition-abuse-01.txt 17933841545SHajimu UMEMOTO below before configuring it, there can be security issues. 1801f320556SHajimu UMEMOTORFC3142: An IPv6-to-IPv4 transport relay translator 1811f320556SHajimu UMEMOTO * FAITH tcp relay translator (faithd) implements this. See 3.1 for more 1821f320556SHajimu UMEMOTO details. 183f88fe57eSHajimu UMEMOTORFC3152: Delegation of IP6.ARPA 184f88fe57eSHajimu UMEMOTO * libinet6 resolvers contained in the KAME snaps support to use 185f88fe57eSHajimu UMEMOTO the ip6.arpa domain (with the nibble format) for IPv6 reverse 186f88fe57eSHajimu UMEMOTO lookups. 187f88fe57eSHajimu UMEMOTORFC3484: Default Address Selection for IPv6 188f88fe57eSHajimu UMEMOTO * the selection algorithm for both source and destination addresses 189f88fe57eSHajimu UMEMOTO is implemented based on the RFC, though some rules are still omitted. 190f88fe57eSHajimu UMEMOTORFC3493: Basic Socket Interface Extensions for IPv6 191f88fe57eSHajimu UMEMOTO * IPv4 mapped address (3.7) and special behavior of IPv6 wildcard bind 192f88fe57eSHajimu UMEMOTO socket (3.8) are, 193f88fe57eSHajimu UMEMOTO - supported and turned on by default on KAME/FreeBSD[34] 194f88fe57eSHajimu UMEMOTO and KAME/BSDI4, 195f88fe57eSHajimu UMEMOTO - supported but turned off by default on KAME/NetBSD and KAME/FreeBSD5, 196f88fe57eSHajimu UMEMOTO - not supported on KAME/FreeBSD228, KAME/OpenBSD and KAME/BSDI3. 197f88fe57eSHajimu UMEMOTO see 1.12 in this document for details. 1981f320556SHajimu UMEMOTO * The AI_ALL and AI_V4MAPPED flags are not supported. 199f88fe57eSHajimu UMEMOTORFC3542: Advanced Sockets API for IPv6 (revised) 200f88fe57eSHajimu UMEMOTO * For supported library functions/kernel APIs, see sys/netinet6/ADVAPI. 20133841545SHajimu UMEMOTO * Some of the updates in the draft are not implemented yet. See 20233841545SHajimu UMEMOTO TODO.2292bis for more details. 203743eee66SSUZUKI ShinsukeRFC4007: IPv6 Scoped Address Architecture 20433841545SHajimu UMEMOTO * some part of the documentation (especially about the routing 20533841545SHajimu UMEMOTO model) is not supported yet. 206743eee66SSUZUKI Shinsuke * zone indices that contain scope types have not been supported yet. 207743eee66SSUZUKI Shinsuke 208743eee66SSUZUKI Shinsukedraft-ietf-ipngwg-icmp-name-lookups-09: IPv6 Name Lookups Through ICMP 209743eee66SSUZUKI Shinsukedraft-ietf-ipv6-router-selection-07.txt: 210743eee66SSUZUKI Shinsuke Default Router Preferences and More-Specific Routes 211743eee66SSUZUKI Shinsuke * router-side: both router preference and specific routes are supported. 212743eee66SSUZUKI Shinsuke * host-side: only router preference is supported. 21333841545SHajimu UMEMOTOdraft-ietf-pim-sm-v2-new-02.txt 21433841545SHajimu UMEMOTO A revised version of RFC2362, which includes the IPv6 specific 21533841545SHajimu UMEMOTO packet format and protocol descriptions. 21633841545SHajimu UMEMOTOdraft-ietf-dnsext-mdns-00.txt: Multicast DNS 21733841545SHajimu UMEMOTO * kame/mdnsd has test implementation, which will not be built in 21833841545SHajimu UMEMOTO default compilation. The draft will experience a major change in the 21933841545SHajimu UMEMOTO near future, so don't rely upon it. 220743eee66SSUZUKI Shinsukedraft-ietf-ipngwg-icmp-v3-02.txt: ICMPv6 for IPv6 specification (revised) 221743eee66SSUZUKI Shinsuke * See 1.9 in this document for details. 222f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-tcp-to-anycast-01.txt: 223f88fe57eSHajimu UMEMOTO Disconnecting TCP connection toward IPv6 anycast address 224743eee66SSUZUKI Shinsukedraft-ietf-ipv6-rfc2462bis-06.txt: IPv6 Stateless Address 225743eee66SSUZUKI Shinsuke Autoconfiguration (revised) 226f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-transition-abuse-01.txt: 22733841545SHajimu UMEMOTO Possible abuse against IPv6 transition technologies (expired) 22833841545SHajimu UMEMOTO * KAME does not implement RFC1933/2893 automatic tunnel. 2298f336835SJun-ichiro itojun Hagino * "stf" interface implements some address filters. Refer to stf(4) 2308f336835SJun-ichiro itojun Hagino for details. Since there's no way to make 6to4 interface 100% secure, 2318f336835SJun-ichiro itojun Hagino we do not include "stf" interface into GENERIC.v6 compilation. 2328f336835SJun-ichiro itojun Hagino * kame/openbsd completely disables IPv4 mapped address support. 2338f336835SJun-ichiro itojun Hagino * kame/netbsd makes IPv4 mapped address support off by default. 23433841545SHajimu UMEMOTO * See section 1.12.6 and 1.14 for more details. 23533841545SHajimu UMEMOTOdraft-itojun-ipv6-flowlabel-api-01.txt: Socket API for IPv6 flow label field 23633841545SHajimu UMEMOTO * no consideration is made against the use of routing headers and such. 23780d21dc4SYoshinobu Inoue 23880d21dc4SYoshinobu Inoue1.2 Neighbor Discovery 23980d21dc4SYoshinobu Inoue 240743eee66SSUZUKI ShinsukeOur implementation of Neighbor Discovery is fairly stable. Currently 241743eee66SSUZUKI ShinsukeAddress Resolution, Duplicated Address Detection, and Neighbor 242743eee66SSUZUKI ShinsukeUnreachability Detection are supported. In the near future we will be 243743eee66SSUZUKI Shinsukeadding an Unsolicited Neighbor Advertisement transmission command as 244743eee66SSUZUKI Shinsukean administration tool. 24580d21dc4SYoshinobu Inoue 2468f336835SJun-ichiro itojun HaginoDuplicated Address Detection (DAD) will be performed when an IPv6 address 2478f336835SJun-ichiro itojun Haginois assigned to a network interface, or the network interface is enabled 2488f336835SJun-ichiro itojun Hagino(ifconfig up). It is documented in RFC2462 5.4. 24980d21dc4SYoshinobu InoueIf DAD fails, the address will be marked "duplicated" and message will be 25080d21dc4SYoshinobu Inouegenerated to syslog (and usually to console). The "duplicated" mark 25180d21dc4SYoshinobu Inouecan be checked with ifconfig. It is administrators' responsibility to check 2528f336835SJun-ichiro itojun Haginofor and recover from DAD failures. We may try to improve failure recovery 2538f336835SJun-ichiro itojun Haginoin future KAME code. 254743eee66SSUZUKI Shinsuke 255743eee66SSUZUKI ShinsukeA successor version of RFC2462 (called rfc2462bis) clarifies the 256743eee66SSUZUKI Shinsukebehavior when DAD fails (i.e., duplicate is detected): if the 257743eee66SSUZUKI Shinsukeduplicate address is a link-local address formed from an interface 258743eee66SSUZUKI Shinsukeidentifier based on the hardware address which is supposed to be 259743eee66SSUZUKI Shinsukeuniquely assigned (e.g., EUI-64 for an Ethernet interface), IPv6 260743eee66SSUZUKI Shinsukeoperation on the interface should be disabled. The KAME 261743eee66SSUZUKI Shinsukeimplementation supports this as follows: if this type of duplicate is 262743eee66SSUZUKI Shinsukedetected, the kernel marks "disabled" in the ND specific data 263743eee66SSUZUKI Shinsukestructure for the interface. Every IPv6 I/O operation in the kernel 264743eee66SSUZUKI Shinsukechecks this mark, and the kernel will drop packets received on or 265743eee66SSUZUKI Shinsukebeing sent to the "disabled" interface. Whether the IPv6 operation is 266743eee66SSUZUKI Shinsukedisabled or not can be confirmed by the ndp(8) command. See the man 267743eee66SSUZUKI Shinsukepage for more details. 268743eee66SSUZUKI Shinsuke 2698f336835SJun-ichiro itojun HaginoDAD procedure may not be effective on certain network interfaces/drivers. 2708f336835SJun-ichiro itojun HaginoIf a network driver needs long initialization time (with wireless network 2718f336835SJun-ichiro itojun Haginointerfaces this situation is popular), and the driver mistakingly raises 2728f336835SJun-ichiro itojun HaginoIFF_RUNNING before the driver becomes ready, DAD code will try to transmit 2738f336835SJun-ichiro itojun HaginoDAD probes to not-really-ready network driver and the packet will not go out 2748f336835SJun-ichiro itojun Haginofrom the interface. In such cases, network drivers should be corrected. 27580d21dc4SYoshinobu Inoue 2768f336835SJun-ichiro itojun HaginoSome of network drivers loop multicast packets back to themselves, 277743eee66SSUZUKI Shinsukeeven if instructed not to do so (especially in promiscuous mode). In 278743eee66SSUZUKI Shinsukesuch cases DAD may fail, because the DAD engine sees inbound NS packet 279743eee66SSUZUKI Shinsuke(actually from the node itself) and considers it as a sign of 280743eee66SSUZUKI Shinsukeduplicate. In this case, drivers should be corrected to honor 281743eee66SSUZUKI ShinsukeIFF_SIMPLEX behavior. For example, you may need to check source MAC 282743eee66SSUZUKI Shinsukeaddress on an inbound packet, and reject it if it is from the node 283743eee66SSUZUKI Shinsukeitself. 28480d21dc4SYoshinobu Inoue 28580d21dc4SYoshinobu InoueNeighbor Discovery specification (RFC2461) does not talk about neighbor 28680d21dc4SYoshinobu Inouecache handling in the following cases: 28780d21dc4SYoshinobu Inoue(1) when there was no neighbor cache entry, node received unsolicited 28880d21dc4SYoshinobu Inoue RS/NS/NA/redirect packet without link-layer address 28980d21dc4SYoshinobu Inoue(2) neighbor cache handling on medium without link-layer address 29080d21dc4SYoshinobu Inoue (we need a neighbor cache entry for IsRouter bit) 29180d21dc4SYoshinobu InoueFor (1), we implemented workaround based on discussions on IETF ipngwg mailing 29280d21dc4SYoshinobu Inouelist. For more details, see the comments in the source code and email 29380d21dc4SYoshinobu Inouethread started from (IPng 7155), dated Feb 6 1999. 29480d21dc4SYoshinobu Inoue 295743eee66SSUZUKI ShinsukeIPv6 on-link determination rule (RFC2461) is quite different from 296743eee66SSUZUKI Shinsukeassumptions in BSD IPv4 network code. To implement the behavior in 297743eee66SSUZUKI ShinsukeRFC2461 section 6.3.6 (3), the kernel needs to know the default 2988f336835SJun-ichiro itojun Haginooutgoing interface. To configure the default outgoing interface, use 299743eee66SSUZUKI Shinsukecommands like "ndp -I de0" as root. Then the kernel will have a 300743eee66SSUZUKI Shinsuke"default" route to the interface with the cloning "C" bit being on. 301743eee66SSUZUKI ShinsukeThis default route will cause to make a neighbor cache entry for every 302743eee66SSUZUKI Shinsukedestination that does not match an explicit route entry. 303743eee66SSUZUKI Shinsuke 304743eee66SSUZUKI ShinsukeNote that we intentionally disable configuring the default interface 305743eee66SSUZUKI Shinsukeby default. This is because we found it sometimes caused inconvenient 306743eee66SSUZUKI Shinsukesituation while it was rarely useful in practical usage. For example, 307743eee66SSUZUKI Shinsukeconsider a destination that has both IPv4 and IPv6 addresses but is 308743eee66SSUZUKI Shinsukeonly reachable via IPv4. Since our getaddrinfo(3) prefers IPv6 by 309743eee66SSUZUKI Shinsukedefault, an (TCP) application using the library with PF_UNSPEC first 310743eee66SSUZUKI Shinsuketries to connect to the IPv6 address. If we turn on RFC 2461 6.3.6 311743eee66SSUZUKI Shinsuke(3), we have to wait for quite a long period before the first attempt 312743eee66SSUZUKI Shinsuketo make a connection fails. If we turn it off, the first attempt will 313743eee66SSUZUKI Shinsukeimmediately fail with EHOSTUNREACH, and then the application can try 314743eee66SSUZUKI Shinsukethe next, reachable address. 315743eee66SSUZUKI Shinsuke 316743eee66SSUZUKI ShinsukeThe notion of the default interface is also disabled when the node is 317743eee66SSUZUKI Shinsukeacting as a router. The reason is that routers tend to control all 318743eee66SSUZUKI Shinsukeroutes stored in the kernel and the default route automatically 319743eee66SSUZUKI Shinsukeinstalled would rather confuse the routers. Note that the spec misuse 320743eee66SSUZUKI Shinsukethe word "host" and "node" in several places in Section 5.2 of RFC 321743eee66SSUZUKI Shinsuke2461. We basically read the word "node" in this section as "host," 322743eee66SSUZUKI Shinsukeand thus believe the implementation policy does not break the 323743eee66SSUZUKI Shinsukespecification. 32480d21dc4SYoshinobu Inoue 32580d21dc4SYoshinobu InoueTo avoid possible DoS attacks and infinite loops, KAME stack will accept 32680d21dc4SYoshinobu Inoueonly 10 options on ND packet. Therefore, if you have 20 prefix options 32780d21dc4SYoshinobu Inoueattached to RA, only the first 10 prefixes will be recognized. 3281f320556SHajimu UMEMOTOIf this troubles you, please contact the KAME team and/or modify 32980d21dc4SYoshinobu Inouend6_maxndopt in sys/netinet6/nd6.c. If there are high demands we may 3301f320556SHajimu UMEMOTOprovide a sysctl knob for the variable. 33180d21dc4SYoshinobu Inoue 3328f336835SJun-ichiro itojun HaginoProxy Neighbor Advertisement support is implemented in the kernel. 3338f336835SJun-ichiro itojun HaginoFor instance, you can configure it by using the following command: 3348f336835SJun-ichiro itojun Hagino # ndp -s fe80::1234%ne0 0:1:2:3:4:5 proxy 3358f336835SJun-ichiro itojun Haginowhere ne0 is the interface which attaches to the same link as the 3368f336835SJun-ichiro itojun Haginoproxy target. 3378f336835SJun-ichiro itojun HaginoThere are certain limitations, though: 3388f336835SJun-ichiro itojun Hagino- It does not send unsolicited multicast NA on configuration. This is MAY 3398f336835SJun-ichiro itojun Hagino behavior in RFC2461. 3408f336835SJun-ichiro itojun Hagino- It does not add random delay before transmission of solicited NA. This is 3418f336835SJun-ichiro itojun Hagino SHOULD behavior in RFC2461. 3428f336835SJun-ichiro itojun Hagino- We cannot configure proxy NDP for off-link address. The target address for 3438f336835SJun-ichiro itojun Hagino proxying must be link-local address, or must be in prefixes configured to 3448f336835SJun-ichiro itojun Hagino node which does proxy NDP. 3458f336835SJun-ichiro itojun Hagino- RFC2461 is unclear about if it is legal for a host to perform proxy ND. 3468f336835SJun-ichiro itojun Hagino We do not prohibit hosts from doing proxy ND, but there will be very limited 3478f336835SJun-ichiro itojun Hagino use in it. 3488f336835SJun-ichiro itojun Hagino 349743eee66SSUZUKI ShinsukeStarting mid March 2000, we support Neighbor Unreachability Detection 350743eee66SSUZUKI Shinsuke(NUD) on p2p interfaces, including tunnel interfaces (gif). NUD is 351743eee66SSUZUKI Shinsuketurned on by default. Before March 2000 the KAME stack did not 352743eee66SSUZUKI Shinsukeperform NUD on p2p interfaces. If the change raises any 353743eee66SSUZUKI Shinsukeinteroperability issues, you can turn off/on NUD by per-interface 354743eee66SSUZUKI Shinsukebasis. Use "ndp -i interface -nud" to turn it off. Consult ndp(8) 355743eee66SSUZUKI Shinsukefor details. 3568f336835SJun-ichiro itojun Hagino 3578f336835SJun-ichiro itojun HaginoRFC2461 specifies upper-layer reachability confirmation hint. Whenever 3588f336835SJun-ichiro itojun Haginoupper-layer reachability confirmation hint comes, ND process can use it 3598f336835SJun-ichiro itojun Haginoto optimize neighbor discovery process - ND process can omit real ND exchange 3608f336835SJun-ichiro itojun Haginoand keep the neighbor cache state in REACHABLE. 3618f336835SJun-ichiro itojun HaginoWe currently have two sources for hints: (1) setsockopt(IPV6_REACHCONF) 362743eee66SSUZUKI Shinsukedefined by the RFC3542 API, and (2) hints from tcp(6)_input. 363743eee66SSUZUKI Shinsuke 364743eee66SSUZUKI ShinsukeIt is questionable if they are really trustworthy. For example, a 365743eee66SSUZUKI Shinsukerogue userland program can use IPV6_REACHCONF to confuse the ND 366743eee66SSUZUKI Shinsukeprocess. Neighbor cache is a system-wide information pool, and it is 367743eee66SSUZUKI Shinsukebad to allow a single process to affect others. Also, tcp(6)_input 368743eee66SSUZUKI Shinsukecan be hosed by hijack attempts. It is wrong to allow hijack attempts 369743eee66SSUZUKI Shinsuketo affect the ND process. 370743eee66SSUZUKI Shinsuke 371743eee66SSUZUKI ShinsukeStarting June 2000, the ND code has a protection mechanism against 372743eee66SSUZUKI Shinsukeincorrect upper-layer reachability confirmation. The ND code counts 373743eee66SSUZUKI Shinsukesubsequent upper-layer hints. If the number of hints reaches the 374743eee66SSUZUKI Shinsukemaximum, the ND code will ignore further upper-layer hints and run 375743eee66SSUZUKI Shinsukereal ND process to confirm reachability to the peer. sysctl 376743eee66SSUZUKI Shinsukenet.inet6.icmp6.nd6_maxnudhint defines the maximum # of subsequent 3778f336835SJun-ichiro itojun Haginoupper-layer hints to be accepted. 3788f336835SJun-ichiro itojun Hagino(from April 2000 to June 2000, we rejected setsockopt(IPV6_REACHCONF) from 379743eee66SSUZUKI Shinsukenon-root process - after a local discussion, it looks that hints are not 3808f336835SJun-ichiro itojun Haginothat trustworthy even if they are from privileged processes) 3818f336835SJun-ichiro itojun Hagino 38233841545SHajimu UMEMOTOIf inbound ND packets carry invalid values, the KAME kernel will 38333841545SHajimu UMEMOTOdrop these packet and increment statistics variable. See 38433841545SHajimu UMEMOTO"netstat -sn", icmp6 section. For detailed debugging session, you can 38533841545SHajimu UMEMOTOturn on syslog output from the kernel on errors, by turning on sysctl MIB 38633841545SHajimu UMEMOTOnet.inet6.icmp6.nd6_debug. nd6_debug can be turned on at bootstrap 38733841545SHajimu UMEMOTOtime, by defining ND6_DEBUG kernel compilation option (so you can 38833841545SHajimu UMEMOTOdebug behavior during bootstrap). nd6_debug configuration should 3891f320556SHajimu UMEMOTOonly be used for test/debug purposes - for a production environment, 39033841545SHajimu UMEMOTOnd6_debug must be set to 0. If you leave it to 1, malicious parties 39133841545SHajimu UMEMOTOcan inject broken packet and fill up /var/log partition. 39233841545SHajimu UMEMOTO 39333841545SHajimu UMEMOTO1.3 Scope Zone Index 39480d21dc4SYoshinobu Inoue 3958f336835SJun-ichiro itojun HaginoIPv6 uses scoped addresses. It is therefore very important to 39633841545SHajimu UMEMOTOspecify the scope zone index (link index for a link-local address, or 39733841545SHajimu UMEMOTOsite index for a site-local address) with an IPv6 address. Without a 39833841545SHajimu UMEMOTOzone index, a scoped IPv6 address is ambiguous to the kernel, and 3991f320556SHajimu UMEMOTOthe kernel would not be able to determine the outbound zone for a 40033841545SHajimu UMEMOTOpacket to the scoped address. KAME code tries to address the issue in 40133841545SHajimu UMEMOTOseveral ways. 40280d21dc4SYoshinobu Inoue 4031f320556SHajimu UMEMOTOThe entire architecture of scoped addresses is documented in RFC4007. 4041f320556SHajimu UMEMOTOOne non-trivial point of the architecture is that the link scope is 4051f320556SHajimu UMEMOTO(theoretically) larger than the interface scope. That is, two 4061f320556SHajimu UMEMOTOdifferent interfaces can belong to a same single link. However, in a 4071f320556SHajimu UMEMOTOnormal operation, we can assume that there is 1-to-1 relationship 4081f320556SHajimu UMEMOTObetween links and interfaces. In other words, we can usually put 4091f320556SHajimu UMEMOTOlinks and interfaces in the same scope type. The current KAME 4101f320556SHajimu UMEMOTOimplementation assumes the 1-to-1 relationship. In particular, we use 4111f320556SHajimu UMEMOTOinterface names such as "ne1" as unique link identifiers. This would 4121f320556SHajimu UMEMOTObe much more human-readable and intuitive than numeric identifiers, 4131f320556SHajimu UMEMOTObut please keep your mind on the theoretical difference between links 4141f320556SHajimu UMEMOTOand interfaces. 41533841545SHajimu UMEMOTO 41633841545SHajimu UMEMOTOSite-local addresses are very vaguely defined in the specs, and both 41733841545SHajimu UMEMOTOthe specification and the KAME code need tons of improvements to 41833841545SHajimu UMEMOTOenable its actual use. For example, it is still very unclear how we 41933841545SHajimu UMEMOTOdefine a site, or how we resolve host names in a site. There is work 42033841545SHajimu UMEMOTOunderway to define behavior of routers at site border, but, we have 4211f320556SHajimu UMEMOTOalmost no code for site boundary node support (neither forwarding nor 42233841545SHajimu UMEMOTOrouting) and we bet almost noone has. We recommend, at this moment, 42333841545SHajimu UMEMOTOyou to use global addresses for experiments - there are way too many 42433841545SHajimu UMEMOTOpitfalls if you use site-local addresses. 42580d21dc4SYoshinobu Inoue 4268f336835SJun-ichiro itojun Hagino1.3.1 Kernel internal 4278f336835SJun-ichiro itojun Hagino 42833841545SHajimu UMEMOTOIn the kernel, the link index for a link-local scope address is 4298f336835SJun-ichiro itojun Haginoembedded into the 2nd 16bit-word (the 3rd and 4th bytes) in the IPv6 4308f336835SJun-ichiro itojun Haginoaddress. 43180d21dc4SYoshinobu InoueFor example, you may see something like: 43280d21dc4SYoshinobu Inoue fe80:1::200:f8ff:fe01:6317 43333841545SHajimu UMEMOTOin the routing table and the interface address structure (struct 43433841545SHajimu UMEMOTOin6_ifaddr). The address above is a link-local unicast address which 43533841545SHajimu UMEMOTObelongs to a network link whose link identifier is 1 (note that it 43633841545SHajimu UMEMOTOeqauls to the interface index by the assumption of our 43733841545SHajimu UMEMOTOimplementation). The embedded index enables us to identify IPv6 43833841545SHajimu UMEMOTOlink-local addresses over multiple links effectively and with only a 43980d21dc4SYoshinobu Inouelittle code change. 4408f336835SJun-ichiro itojun Hagino 4411f320556SHajimu UMEMOTOThe use of the internal format must be limited inside the kernel. In 4421f320556SHajimu UMEMOTOparticular, addresses sent by an application should not contain the 4431f320556SHajimu UMEMOTOembedded index (except via some very special APIs such as routing 4441f320556SHajimu UMEMOTOsockets). Instead, the index should be specified in the sin6_scope_id 4451f320556SHajimu UMEMOTOfield of a sockaddr_in6 structure. Obviously, packets sent to or 4461f320556SHajimu UMEMOTOreceived from must not contain the embedded index either, since the 4471f320556SHajimu UMEMOTOindex is meaningful only within the sending/receiving node. 4481f320556SHajimu UMEMOTO 4491f320556SHajimu UMEMOTOIn order to deal with the differences, several kernel routines are 4501f320556SHajimu UMEMOTOprovided. These are available by including <netinet6/scope_var.h>. 4511f320556SHajimu UMEMOTOTypically, the following functions will be most generally used: 4521f320556SHajimu UMEMOTO 4531f320556SHajimu UMEMOTO- int sa6_embedscope(struct sockaddr_in6 *sa6, int defaultok); 4541f320556SHajimu UMEMOTO Embed sa6->sin6_scope_id into sa6->sin6_addr. If sin6_scope_id is 4551f320556SHajimu UMEMOTO 0, defaultok is non-0, and the default zone ID (see RFC4007) is 4561f320556SHajimu UMEMOTO configured, the default ID will be used instead of the value of the 4571f320556SHajimu UMEMOTO sin6_scope_id field. On success, sa6->sin6_scope_id will be reset 4581f320556SHajimu UMEMOTO to 0. 4591f320556SHajimu UMEMOTO 4601f320556SHajimu UMEMOTO This function returns 0 on success, or a non-0 error code otherwise. 4611f320556SHajimu UMEMOTO 4621f320556SHajimu UMEMOTO- int sa6_recoverscope(struct sockaddr_in6 *sa6); 4631f320556SHajimu UMEMOTO Extract embedded zone ID in sa6->sin6_addr and set 4641f320556SHajimu UMEMOTO sa6->sin6_scope_id to that ID. The embedded ID will be cleared with 4651f320556SHajimu UMEMOTO 0. 4661f320556SHajimu UMEMOTO 4671f320556SHajimu UMEMOTO This function returns 0 on success, or a non-0 error code otherwise. 4681f320556SHajimu UMEMOTO 4691f320556SHajimu UMEMOTO- int in6_clearscope(struct in6_addr *in6); 4701f320556SHajimu UMEMOTO Reset the embedded zone ID in 'in6' to 0. This function never fails, and 4711f320556SHajimu UMEMOTO returns 0 if the original address is intact or non 0 if the address is 4721f320556SHajimu UMEMOTO modified. The return value doesn't matter in most cases; currently, the 4731f320556SHajimu UMEMOTO only point where we care about the return value is ip6_input() for checking 4741f320556SHajimu UMEMOTO whether the source or destination addresses of the incoming packet is in 4751f320556SHajimu UMEMOTO the embedded form. 4761f320556SHajimu UMEMOTO 4771f320556SHajimu UMEMOTO- int in6_setscope(struct in6_addr *in6, struct ifnet *ifp, 4781f320556SHajimu UMEMOTO u_int32_t *zoneidp); 4791f320556SHajimu UMEMOTO Embed zone ID determined by the address scope type for 'in6' and the 4801f320556SHajimu UMEMOTO interface 'ifp' into 'in6'. If zoneidp is non NULL, *zoneidp will 4811f320556SHajimu UMEMOTO also have the zone ID. 4821f320556SHajimu UMEMOTO 4831f320556SHajimu UMEMOTO This function returns 0 on success, or a non-0 error code otherwise. 4841f320556SHajimu UMEMOTO 4851f320556SHajimu UMEMOTOThe typical usage of these functions is as follows: 4861f320556SHajimu UMEMOTO 4871f320556SHajimu UMEMOTOsa6_embedscope() will be used at the socket or transport layer to 4881f320556SHajimu UMEMOTOconvert a sockaddr_in6 structure passed by an application into the 4891f320556SHajimu UMEMOTOkernel-internal form. In this usage, the second argument is often the 4901f320556SHajimu UMEMOTO'ip6_use_defzone' global variable. 4911f320556SHajimu UMEMOTO 4921f320556SHajimu UMEMOTOsa6_recoverscope() will also be used at the socket or transport layer 4931f320556SHajimu UMEMOTOto convert an in6_addr structure with the embedded zone ID into a 4941f320556SHajimu UMEMOTOsockaddr_in6 structure with the corresponding ID in the sin6_scope_id 4951f320556SHajimu UMEMOTOfield (and without the embedded ID in sin6_addr). 4961f320556SHajimu UMEMOTO 4971f320556SHajimu UMEMOTOin6_clearscope() will be used just before sending a packet to the wire 4981f320556SHajimu UMEMOTOto remove the embedded ID. In general, this must be done at the last 4991f320556SHajimu UMEMOTOstage of an output path, since otherwise the address would lose the ID 5001f320556SHajimu UMEMOTOand could be ambiguous with regard to scope. 5011f320556SHajimu UMEMOTO 5021f320556SHajimu UMEMOTOin6_setscope() will be used when the kernel receives a packet from the 5031f320556SHajimu UMEMOTOwire to construct the kernel internal form for each address field in 5041f320556SHajimu UMEMOTOthe packet (typical examples are the source and destination addresses 5051f320556SHajimu UMEMOTOof the packet). In the typical usage, the third argument 'zoneidp' 5061f320556SHajimu UMEMOTOwill be NULL. A non-NULL value will be used when the validity of the 5071f320556SHajimu UMEMOTOzone ID must be checked, e.g., when forwarding a packet to another 5081f320556SHajimu UMEMOTOlink (see ip6_forward() for this usage). 5091f320556SHajimu UMEMOTO 5101f320556SHajimu UMEMOTOAn application, when sending a packet, is basically assumed to specify 5111f320556SHajimu UMEMOTOthe appropriate scope zone of the destination address by the 5121f320556SHajimu UMEMOTOsin6_scope_id field (this might be done transparently from the 5131f320556SHajimu UMEMOTOapplication with getaddrinfo() and the extended textual format - see 5141f320556SHajimu UMEMOTObelow), or at least the default scope zone(s) must be configured as a 5151f320556SHajimu UMEMOTOlast resort. In some cases, however, an application could specify an 5161f320556SHajimu UMEMOTOambiguous address with regard to scope, expecting it is disambiguated 5171f320556SHajimu UMEMOTOin the kernel by some other means. A typical usage is to specify the 5181f320556SHajimu UMEMOTOoutgoing interface through another API, which can disambiguate the 5191f320556SHajimu UMEMOTOunspecified scope zone. Such a usage is not recommended, but the 5201f320556SHajimu UMEMOTOkernel implements some trick to deal with even this case. 5211f320556SHajimu UMEMOTO 5221f320556SHajimu UMEMOTOA rough sketch of the trick can be summarized as the following 5231f320556SHajimu UMEMOTOsequence. 5241f320556SHajimu UMEMOTO 5251f320556SHajimu UMEMOTO sa6_embedscope(dst, ip6_use_defzone); 5261f320556SHajimu UMEMOTO in6_selectsrc(dst, ..., &ifp, ...); 5271f320556SHajimu UMEMOTO in6_setscope(&dst->sin6_addr, ifp, NULL); 5281f320556SHajimu UMEMOTO 5291f320556SHajimu UMEMOTOsa6_embedscope() first tries to convert sin6_scope_id (or the default 5301f320556SHajimu UMEMOTOzone ID) into the kernel-internal form. This can fail with an 5311f320556SHajimu UMEMOTOambiguous destination, but it still tries to get the outgoing 5321f320556SHajimu UMEMOTOinterface (ifp) in the attempt of determining the source address of 5331f320556SHajimu UMEMOTOthe outgoing packet using in6_selectsrc(). If the interface is 5341f320556SHajimu UMEMOTOdetected, and the scope zone was originally ambiguous, in6_setscope() 5351f320556SHajimu UMEMOTOcan finally determine the appropriate ID with the address itself and 5361f320556SHajimu UMEMOTOthe interface, and construct the kernel-internal form. See, for 5371f320556SHajimu UMEMOTOexample, comments in udp6_output() for more concrete example. 5381f320556SHajimu UMEMOTO 5391f320556SHajimu UMEMOTOIn any case, kernel routines except ones in netinet6/scope6.c MUST NOT 5401f320556SHajimu UMEMOTOdirectly refer to the embedded form. They MUST use the above 5411f320556SHajimu UMEMOTOinterface functions. In particular, kernel routines MUST NOT have the 5421f320556SHajimu UMEMOTOfollowing code fragment: 5431f320556SHajimu UMEMOTO 5441f320556SHajimu UMEMOTO /* This is a bad practice. Don't do this */ 5451f320556SHajimu UMEMOTO if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) 5461f320556SHajimu UMEMOTO sin6->sin6_addr.s6_addr16[1] = htons(ifp->if_index); 5471f320556SHajimu UMEMOTO 5481f320556SHajimu UMEMOTOThis is bad for several reasons. First, address ambiguity is not 5491f320556SHajimu UMEMOTOspecific to link-local addresses (any non-global multicast addresses 5501f320556SHajimu UMEMOTOare inherently ambiguous, and this is particularly true for 5511f320556SHajimu UMEMOTOinterface-local addresses). Secondly, this is vulnerable to future 5521f320556SHajimu UMEMOTOchanges of the embedded form (the embedded position may change, or the 5531f320556SHajimu UMEMOTOzone ID may not actually be the interface index). Only scope6.c 5541f320556SHajimu UMEMOTOroutines should know the details. 5551f320556SHajimu UMEMOTO 5561f320556SHajimu UMEMOTOThe above code fragment should thus actually be as follows: 5571f320556SHajimu UMEMOTO 5581f320556SHajimu UMEMOTO /* This is correct. */ 5591f320556SHajimu UMEMOTO in6_setscope(&sin6->sin6_addr, ifp, NULL); 5601f320556SHajimu UMEMOTO (and catch errors if possible and necessary) 5611f320556SHajimu UMEMOTO 5628f336835SJun-ichiro itojun Hagino1.3.2 Interaction with API 5638f336835SJun-ichiro itojun Hagino 56433841545SHajimu UMEMOTOThere are several candidates of API to deal with scoped addresses 56533841545SHajimu UMEMOTOwithout ambiguity. 5668f336835SJun-ichiro itojun Hagino 56733841545SHajimu UMEMOTOThe IPV6_PKTINFO ancillary data type or socket option defined in the 568f88fe57eSHajimu UMEMOTOadvanced API (RFC2292 or RFC3542) can specify 56933841545SHajimu UMEMOTOthe outgoing interface of a packet. Similarly, the IPV6_PKTINFO or 57033841545SHajimu UMEMOTOIPV6_RECVPKTINFO socket options tell kernel to pass the incoming 57133841545SHajimu UMEMOTOinterface to user applications. 57280d21dc4SYoshinobu Inoue 57333841545SHajimu UMEMOTOThese options are enough to disambiguate scoped addresses of an 57433841545SHajimu UMEMOTOincoming packet, because we can uniquely identify the corresponding 57533841545SHajimu UMEMOTOzone of the scoped address(es) by the incoming interface. However, 57633841545SHajimu UMEMOTOthey are too strong for outgoing packets. For example, consider a 57733841545SHajimu UMEMOTOmulti-sited node and suppose that more than one interface of the node 57833841545SHajimu UMEMOTObelongs to a same site. When we want to send a packet to the site, 57933841545SHajimu UMEMOTOwe can only specify one of the interfaces for the outgoing packet with 58033841545SHajimu UMEMOTOthese options; we cannot just say "send the packet to (one of the 58133841545SHajimu UMEMOTOinterfaces of) the site." 58233841545SHajimu UMEMOTO 58333841545SHajimu UMEMOTOAnother kind of candidates is to use the sin6_scope_id member in the 584f88fe57eSHajimu UMEMOTOsockaddr_in6 structure, defined in RFC2553. The KAME kernel 585f88fe57eSHajimu UMEMOTOinterprets the sin6_scope_id field properly in order to disambiguate scoped 58633841545SHajimu UMEMOTOaddresses. For example, if an application passes a sockaddr_in6 58733841545SHajimu UMEMOTOstructure that has a non-zero sin6_scope_id value to the sendto(2) 58833841545SHajimu UMEMOTOsystem call, the kernel should send the packet to the appropriate zone 58933841545SHajimu UMEMOTOaccording to the sin6_scope_id field. Similarly, when the source or 59033841545SHajimu UMEMOTOthe destination address of an incoming packet is a scoped one, the 59133841545SHajimu UMEMOTOkernel should detect the correct zone identifier based on the address 59233841545SHajimu UMEMOTOand the receiving interface, fill the identifier in the sin6_scope_id 59333841545SHajimu UMEMOTOfield of a sockaddr_in6 structure, and then pass the packet to an 59433841545SHajimu UMEMOTOapplication via the recvfrom(2) system call, etc. 59533841545SHajimu UMEMOTO 59633841545SHajimu UMEMOTOHowever, the semantics of the sin6_scope_id is still vague and on the 59733841545SHajimu UMEMOTOway to standardization. Additionally, not so many operating systems 59833841545SHajimu UMEMOTOsupport the behavior above at this moment. 59933841545SHajimu UMEMOTO 60033841545SHajimu UMEMOTOIn summary, 60133841545SHajimu UMEMOTO- If your target system is limited to KAME based ones (i.e. BSD 60233841545SHajimu UMEMOTO variants and KAME snaps), use the sin6_scope_id field assuming the 60333841545SHajimu UMEMOTO kernel behavior described above. 60433841545SHajimu UMEMOTO- Otherwise, (i.e. if your program should be portable on other systems 60533841545SHajimu UMEMOTO than BSDs) 60633841545SHajimu UMEMOTO + Use the advanced API to disambiguate scoped addresses of incoming 60733841545SHajimu UMEMOTO packets. 60833841545SHajimu UMEMOTO + To disambiguate scoped addresses of outgoing packets, 60933841545SHajimu UMEMOTO * if it is okay to just specify the outgoing interface, use the 61033841545SHajimu UMEMOTO advanced API. This would be the case, for example, when you 61133841545SHajimu UMEMOTO should only consider link-local addresses and your system 61233841545SHajimu UMEMOTO assumes 1-to-1 relationship between links and interfaces. 61333841545SHajimu UMEMOTO * otherwise, sorry but you lose. Please rush the IETF IPv6 61433841545SHajimu UMEMOTO community into standardizing the semantics of the sin6_scope_id 61533841545SHajimu UMEMOTO field. 61633841545SHajimu UMEMOTO 61733841545SHajimu UMEMOTORouting daemons and configuration programs, like route6d and ifconfig, 61833841545SHajimu UMEMOTOwill need to manipulate the "embedded" zone index. These programs use 61933841545SHajimu UMEMOTOrouting sockets and ioctls (like SIOCGIFADDR_IN6) and the kernel API 62033841545SHajimu UMEMOTOwill return IPv6 addresses with the 2nd 16bit-word filled in. The 62133841545SHajimu UMEMOTOAPIs are for manipulating kernel internal structure. Programs that 62233841545SHajimu UMEMOTOuse these APIs have to be prepared about differences in kernels 62333841545SHajimu UMEMOTOanyway. 62433841545SHajimu UMEMOTO 62533841545SHajimu UMEMOTOgetaddrinfo(3) and getnameinfo(3) support an extended numeric IPv6 6261f320556SHajimu UMEMOTOsyntax, as documented in RFC4007. You can specify the outgoing link, 6271f320556SHajimu UMEMOTOby using the name of the outgoing interface as the link, like 6281f320556SHajimu UMEMOTO"fe80::1%ne0" (again, note that we assume there is 1-to-1 relationship 6291f320556SHajimu UMEMOTObetween links and interfaces.) This way you will be able to specify a 6301f320556SHajimu UMEMOTOlink-local scoped address without much trouble. 63133841545SHajimu UMEMOTO 63233841545SHajimu UMEMOTOOther APIs like inet_pton(3) and inet_ntop(3) are inherently 63333841545SHajimu UMEMOTOunfriendly with scoped addresses, since they are unable to annotate 63433841545SHajimu UMEMOTOaddresses with zone identifier. 6358f336835SJun-ichiro itojun Hagino 6368f336835SJun-ichiro itojun Hagino1.3.3 Interaction with users (command line) 6378f336835SJun-ichiro itojun Hagino 63833841545SHajimu UMEMOTOMost of user applications now support the extended numeric IPv6 63933841545SHajimu UMEMOTOsyntax. In this case, you can specify outgoing link, by using the name 64033841545SHajimu UMEMOTOof the outgoing interface like "fe80::1%ne0" (sorry for the duplicated 64133841545SHajimu UMEMOTOnotice, but please recall again that we assume 1-to-1 relationship 64233841545SHajimu UMEMOTObetween links and interfaces). This is even the case for some 64333841545SHajimu UMEMOTOmanagement tools such as route(8) or ndp(8). For example, to install 64433841545SHajimu UMEMOTOthe IPv6 default route by hand, you can type like 6458f336835SJun-ichiro itojun Hagino # route add -inet6 default fe80::9876:5432:1234:abcd%ne0 6468f336835SJun-ichiro itojun Hagino(Although we suggest you to run dynamic routing instead of static 6478f336835SJun-ichiro itojun Haginoroutes, in order to avoid configuration mistakes.) 6488f336835SJun-ichiro itojun Hagino 6498f336835SJun-ichiro itojun HaginoSome applications have command line options for specifying an 6508f336835SJun-ichiro itojun Haginoappropriate zone of a scoped address (like "ping6 -I ne0 ff02::1" to 6518f336835SJun-ichiro itojun Haginospecify the outgoing interface). However, you can't always expect such 652f88fe57eSHajimu UMEMOTOoptions. Additionally, specifying the outgoing "interface" is in 653f88fe57eSHajimu UMEMOTOtheory an overspecification as a way to specify the outgoing "link" 654f88fe57eSHajimu UMEMOTO(see above). Thus, we recommend you to use the extended format 655f88fe57eSHajimu UMEMOTOdescribed above. This should apply to the case where the outgoing 656f88fe57eSHajimu UMEMOTOinterface is specified. 6578f336835SJun-ichiro itojun Hagino 6588f336835SJun-ichiro itojun HaginoIn any case, when you specify a scoped address to the command line, 6598f336835SJun-ichiro itojun HaginoNEVER write the embedded form (such as ff02:1::1 or fe80:2::fedc), 6608f336835SJun-ichiro itojun Haginowhich should only be used inside the kernel (see Section 1.3.1), and 6618f336835SJun-ichiro itojun Haginois not supposed to work. 66280d21dc4SYoshinobu Inoue 66380d21dc4SYoshinobu Inoue1.4 Plug and Play 66480d21dc4SYoshinobu Inoue 66580d21dc4SYoshinobu InoueThe KAME kit implements most of the IPv6 stateless address 66680d21dc4SYoshinobu Inoueautoconfiguration in the kernel. 66780d21dc4SYoshinobu InoueNeighbor Discovery functions are implemented in the kernel as a whole. 66880d21dc4SYoshinobu InoueRouter Advertisement (RA) input for hosts is implemented in the 66980d21dc4SYoshinobu Inouekernel. Router Solicitation (RS) output for endhosts, RS input 67080d21dc4SYoshinobu Inouefor routers, and RA output for routers are implemented in the 67180d21dc4SYoshinobu Inoueuserland. 67280d21dc4SYoshinobu Inoue 67380d21dc4SYoshinobu Inoue1.4.1 Assignment of link-local, and special addresses 67480d21dc4SYoshinobu Inoue 6758f336835SJun-ichiro itojun HaginoIPv6 link-local address is generated from IEEE802 address (ethernet MAC 67680d21dc4SYoshinobu Inoueaddress). Each of interface is assigned an IPv6 link-local address 67780d21dc4SYoshinobu Inoueautomatically, when the interface becomes up (IFF_UP). Also, direct route 67880d21dc4SYoshinobu Inouefor the link-local address is added to routing table. 67980d21dc4SYoshinobu Inoue 68080d21dc4SYoshinobu InoueHere is an output of netstat command: 68180d21dc4SYoshinobu Inoue 68280d21dc4SYoshinobu InoueInternet6: 68380d21dc4SYoshinobu InoueDestination Gateway Flags Netif Expire 6848f336835SJun-ichiro itojun Haginofe80::%ed0/64 link#1 UC ed0 6858f336835SJun-ichiro itojun Haginofe80::%ep0/64 link#2 UC ep0 68680d21dc4SYoshinobu Inoue 68780d21dc4SYoshinobu InoueInterfaces that has no IEEE802 address (pseudo interfaces like tunnel 68880d21dc4SYoshinobu Inoueinterfaces, or ppp interfaces) will borrow IEEE802 address from other 68980d21dc4SYoshinobu Inoueinterfaces, such as ethernet interfaces, whenever possible. 69080d21dc4SYoshinobu InoueIf there is no IEEE802 hardware attached, last-resort pseudorandom value, 69180d21dc4SYoshinobu Inouewhich is from MD5(hostname), will be used as source of link-local address. 69280d21dc4SYoshinobu InoueIf it is not suitable for your usage, you will need to configure the 69380d21dc4SYoshinobu Inouelink-local address manually. 69480d21dc4SYoshinobu Inoue 69580d21dc4SYoshinobu InoueIf an interface is not capable of handling IPv6 (such as lack of multicast 69680d21dc4SYoshinobu Inouesupport), link-local address will not be assigned to that interface. 69780d21dc4SYoshinobu InoueSee section 2 for details. 69880d21dc4SYoshinobu Inoue 69980d21dc4SYoshinobu InoueEach interface joins the solicited multicast address and the 70080d21dc4SYoshinobu Inouelink-local all-nodes multicast addresses (e.g. fe80::1:ff01:6317 70180d21dc4SYoshinobu Inoueand ff02::1, respectively, on the link the interface is attached). 70280d21dc4SYoshinobu InoueIn addition to a link-local address, the loopback address (::1) will be 70380d21dc4SYoshinobu Inoueassigned to the loopback interface. Also, ::1/128 and ff01::/32 are 70480d21dc4SYoshinobu Inoueautomatically added to routing table, and loopback interface joins 70580d21dc4SYoshinobu Inouenode-local multicast group ff01::1. 70680d21dc4SYoshinobu Inoue 70780d21dc4SYoshinobu Inoue1.4.2 Stateless address autoconfiguration on hosts 70880d21dc4SYoshinobu Inoue 70980d21dc4SYoshinobu InoueIn IPv6 specification, nodes are separated into two categories: 710*dcde2454SHo-Kun Linrouters and hosts. Routers forward packets addressed to others, hosts do 71180d21dc4SYoshinobu Inouenot forward the packets. net.inet6.ip6.forwarding defines whether this 7128f336835SJun-ichiro itojun Haginonode is a router or a host (router if it is 1, host if it is 0). 7138f336835SJun-ichiro itojun Hagino 7148f336835SJun-ichiro itojun HaginoIt is NOT recommended to change net.inet6.ip6.forwarding while the node 7158f336835SJun-ichiro itojun Haginois in operation. IPv6 specification defines behavior for "host" and "router" 7168f336835SJun-ichiro itojun Haginoquite differently, and switching from one to another can cause serious 7178f336835SJun-ichiro itojun Haginotroubles. It is recommended to configure the variable at bootstrap time only. 7188f336835SJun-ichiro itojun Hagino 7198f336835SJun-ichiro itojun HaginoThe first step in stateless address configuration is Duplicated Address 7208f336835SJun-ichiro itojun HaginoDetection (DAD). See 1.2 for more detail on DAD. 72180d21dc4SYoshinobu Inoue 72280d21dc4SYoshinobu InoueWhen a host hears Router Advertisement from the router, a host may 723743eee66SSUZUKI Shinsukeautoconfigure itself by stateless address autoconfiguration. This 724743eee66SSUZUKI Shinsukebehavior can be controlled by the net.inet6.ip6.accept_rtadv sysctl 725743eee66SSUZUKI Shinsukevariable and a per-interface flag managed in the kernel. The latter, 726743eee66SSUZUKI Shinsukewhich we call "if_accept_rtadv" here, can be changed by the ndp(8) 727743eee66SSUZUKI Shinsukecommand (see the manpage for more details). When the sysctl variable 728743eee66SSUZUKI Shinsukeis set to 1, and the flag is set, the host autoconfigures itself. By 729743eee66SSUZUKI Shinsukeautoconfiguration, network address prefixes for the receiving 730743eee66SSUZUKI Shinsukeinterface (usually global address prefix) are added. The default 731743eee66SSUZUKI Shinsukeroute is also configured. 7328f336835SJun-ichiro itojun Hagino 7338f336835SJun-ichiro itojun HaginoRouters periodically generate Router Advertisement packets. To 7348f336835SJun-ichiro itojun Haginorequest an adjacent router to generate RA packet, a host can transmit 7358f336835SJun-ichiro itojun HaginoRouter Solicitation. To generate an RS packet at any time, use the 7368f336835SJun-ichiro itojun Hagino"rtsol" command. The "rtsold" daemon is also available. "rtsold" 737743eee66SSUZUKI Shinsukegenerates Router Solicitation whenever necessary, and it works greatly 7388f336835SJun-ichiro itojun Haginofor nomadic usage (notebooks/laptops). If one wishes to ignore Router 7398f336835SJun-ichiro itojun HaginoAdvertisements, use sysctl to set net.inet6.ip6.accept_rtadv to 0. 740743eee66SSUZUKI ShinsukeAdditionally, ndp(8) command can be used to control the behavior 741743eee66SSUZUKI Shinsukeper-interface basis. 74280d21dc4SYoshinobu Inoue 74380d21dc4SYoshinobu InoueTo generate Router Advertisement from a router, use the "rtadvd" daemon. 74480d21dc4SYoshinobu Inoue 7458f336835SJun-ichiro itojun HaginoNote that the IPv6 specification assumes the following items and that 7468f336835SJun-ichiro itojun Haginononconforming cases are left unspecified: 74780d21dc4SYoshinobu Inoue- Only hosts will listen to router advertisements 748743eee66SSUZUKI Shinsuke- Hosts have a single network interface (except loopback) 7498f336835SJun-ichiro itojun HaginoThis is therefore unwise to enable net.inet6.ip6.accept_rtadv on routers, 750743eee66SSUZUKI Shinsukeor multi-interface hosts. A misconfigured node can behave strange 75180d21dc4SYoshinobu Inoue(KAME code allows nonconforming configuration, for those who would like 75280d21dc4SYoshinobu Inoueto do some experiments). 75380d21dc4SYoshinobu Inoue 75480d21dc4SYoshinobu InoueTo summarize the sysctl knob: 75580d21dc4SYoshinobu Inoue accept_rtadv forwarding role of the node 75680d21dc4SYoshinobu Inoue --- --- --- 75780d21dc4SYoshinobu Inoue 0 0 host (to be manually configured) 75880d21dc4SYoshinobu Inoue 0 1 router 75980d21dc4SYoshinobu Inoue 1 0 autoconfigured host 760743eee66SSUZUKI Shinsuke (spec assumes that hosts have a single 761743eee66SSUZUKI Shinsuke interface only, autoconfigred hosts 762743eee66SSUZUKI Shinsuke with multiple interfaces are 763743eee66SSUZUKI Shinsuke out-of-scope) 76480d21dc4SYoshinobu Inoue 1 1 invalid, or experimental 76580d21dc4SYoshinobu Inoue (out-of-scope of spec) 76680d21dc4SYoshinobu Inoue 767743eee66SSUZUKI ShinsukeThe if_accept_rtadv flag is referred only when accept_rtadv is 1 (the 768743eee66SSUZUKI Shinsukelatter two cases). The flag does not have any effects when the sysctl 769743eee66SSUZUKI Shinsukevariable is 0. 770743eee66SSUZUKI Shinsuke 77180d21dc4SYoshinobu InoueSee 1.2 in the document for relationship between DAD and autoconfiguration. 77280d21dc4SYoshinobu Inoue 7738f336835SJun-ichiro itojun Hagino1.4.3 DHCPv6 77480d21dc4SYoshinobu Inoue 77580d21dc4SYoshinobu InoueWe supply a tiny DHCPv6 server/client in kame/dhcp6. However, the 7768f336835SJun-ichiro itojun Haginoimplementation is premature (for example, this does NOT implement 7778f336835SJun-ichiro itojun Haginoaddress lease/release), and it is not in default compilation tree on 7788f336835SJun-ichiro itojun Haginosome platforms. If you want to do some experiment, compile it on your 7798f336835SJun-ichiro itojun Haginoown. 78080d21dc4SYoshinobu Inoue 78180d21dc4SYoshinobu InoueDHCPv6 and autoconfiguration also needs more work. "Managed" and "Other" 78280d21dc4SYoshinobu Inouebits in RA have no special effect to stateful autoconfiguration procedure 78380d21dc4SYoshinobu Inouein DHCPv6 client program ("Managed" bit actually prevents stateless 78480d21dc4SYoshinobu Inoueautoconfiguration, but no special action will be taken for DHCPv6 client). 78580d21dc4SYoshinobu Inoue 78680d21dc4SYoshinobu Inoue1.5 Generic tunnel interface 78780d21dc4SYoshinobu Inoue 78880d21dc4SYoshinobu InoueGIF (Generic InterFace) is a pseudo interface for configured tunnel. 78980d21dc4SYoshinobu InoueDetails are described in gif(4) manpage. 79080d21dc4SYoshinobu InoueCurrently 79180d21dc4SYoshinobu Inoue v6 in v6 79280d21dc4SYoshinobu Inoue v6 in v4 79380d21dc4SYoshinobu Inoue v4 in v6 79480d21dc4SYoshinobu Inoue v4 in v4 79580d21dc4SYoshinobu Inoueare available. Use "gifconfig" to assign physical (outer) source 79680d21dc4SYoshinobu Inoueand destination address to gif interfaces. 79780d21dc4SYoshinobu InoueConfiguration that uses same address family for inner and outer IP 79880d21dc4SYoshinobu Inoueheader (v4 in v4, or v6 in v6) is dangerous. It is very easy to 79980d21dc4SYoshinobu Inoueconfigure interfaces and routing tables to perform infinite level 80080d21dc4SYoshinobu Inoueof tunneling. Please be warned. 80180d21dc4SYoshinobu Inoue 80280d21dc4SYoshinobu Inouegif can be configured to be ECN-friendly. See 4.5 for ECN-friendliness 80380d21dc4SYoshinobu Inoueof tunnels, and gif(4) manpage for how to configure. 80480d21dc4SYoshinobu Inoue 80580d21dc4SYoshinobu InoueIf you would like to configure an IPv4-in-IPv6 tunnel with gif interface, 8068f336835SJun-ichiro itojun Haginoread gif(4) carefully. You may need to remove IPv6 link-local address 80780d21dc4SYoshinobu Inoueautomatically assigned to the gif interface. 80880d21dc4SYoshinobu Inoue 809f88fe57eSHajimu UMEMOTO1.6 Address Selection 81080d21dc4SYoshinobu Inoue 811f88fe57eSHajimu UMEMOTO1.6.1 Source Address Selection 81280d21dc4SYoshinobu Inoue 813f88fe57eSHajimu UMEMOTOThe KAME kernel chooses the source address for an outgoing packet 814f88fe57eSHajimu UMEMOTOsent from a user application as follows: 8158f336835SJun-ichiro itojun Hagino 816f88fe57eSHajimu UMEMOTO1. if the source address is explicitly specified via an IPV6_PKTINFO 817f88fe57eSHajimu UMEMOTO ancillary data item or the socket option of that name, just use it. 818f88fe57eSHajimu UMEMOTO Note that this item/option overrides the bound address of the 819f88fe57eSHajimu UMEMOTO corresponding (datagram) socket. 82080d21dc4SYoshinobu Inoue 821f88fe57eSHajimu UMEMOTO2. if the corresponding socket is bound, use the bound address. 8228f336835SJun-ichiro itojun Hagino 823f88fe57eSHajimu UMEMOTO3. otherwise, the kernel first tries to find the outgoing interface of 824f88fe57eSHajimu UMEMOTO the packet. If it fails, the source address selection also fails. 825f88fe57eSHajimu UMEMOTO If the kernel can find an interface, choose the most appropriate 826f88fe57eSHajimu UMEMOTO address based on the algorithm described in RFC3484. 8278f336835SJun-ichiro itojun Hagino 828f88fe57eSHajimu UMEMOTO The policy table used in this algorithm is stored in the kernel. 829f88fe57eSHajimu UMEMOTO To install or view the policy, use the ip6addrctl(8) command. The 830f88fe57eSHajimu UMEMOTO kernel does not have pre-installed policy. It is expected that the 831f88fe57eSHajimu UMEMOTO default policy described in the draft should be installed at the 832f88fe57eSHajimu UMEMOTO bootstrap time using this command. 8338f336835SJun-ichiro itojun Hagino 834f88fe57eSHajimu UMEMOTO This draft allows an implementation to add implementation-specific 835f88fe57eSHajimu UMEMOTO rules with higher precedence than the rule "Use longest matching 836f88fe57eSHajimu UMEMOTO prefix." KAME's implementation has the following additional rules 837f88fe57eSHajimu UMEMOTO (that apply in the appeared order): 83833841545SHajimu UMEMOTO 839f88fe57eSHajimu UMEMOTO - prefer addresses on alive interfaces, that is, interfaces with 840f88fe57eSHajimu UMEMOTO the UP flag being on. This rule is particularly useful for 841f88fe57eSHajimu UMEMOTO routers, since some routing daemons stop advertising prefixes 842f88fe57eSHajimu UMEMOTO (addresses) on interfaces that have become down. 8438f336835SJun-ichiro itojun Hagino 844743eee66SSUZUKI Shinsuke - prefer addresses on "preferred" interfaces. "Preferred" 845743eee66SSUZUKI Shinsuke interfaces can be specified by the ndp(8) command. By default, 846743eee66SSUZUKI Shinsuke no interface is preferred, that is, this rule does not apply. 847743eee66SSUZUKI Shinsuke Again, this rule is particularly useful for routers, since there 848743eee66SSUZUKI Shinsuke is a convention, among router administrators, of assigning 849743eee66SSUZUKI Shinsuke "stable" addresses on a particular interface (typically a 850743eee66SSUZUKI Shinsuke loopback interface). 851743eee66SSUZUKI Shinsuke 852f88fe57eSHajimu UMEMOTO In any case, addresses that break the scope zone of the 853f88fe57eSHajimu UMEMOTO destination, or addresses whose zone do not contain the outgoing 854f88fe57eSHajimu UMEMOTO interface are never chosen. 8558f336835SJun-ichiro itojun Hagino 856f88fe57eSHajimu UMEMOTOWhen the procedure above fails, the kernel usually returns 857f88fe57eSHajimu UMEMOTOEADDRNOTAVAIL to the application. 8588f336835SJun-ichiro itojun Hagino 859f88fe57eSHajimu UMEMOTOIn some cases, the specification explicitly requires the 860f88fe57eSHajimu UMEMOTOimplementation to choose a particular source address. The source 861f88fe57eSHajimu UMEMOTOaddress for a Neighbor Advertisement (NA) message is an example. 86280d21dc4SYoshinobu InoueUnder the spec (RFC2461 7.2.2) NA's source should be the target 863f88fe57eSHajimu UMEMOTOaddress of the corresponding NS's target. In this case we follow the 864f88fe57eSHajimu UMEMOTOspec rather than the above rule. 86580d21dc4SYoshinobu Inoue 8668f336835SJun-ichiro itojun HaginoIf you would like to prohibit the use of deprecated address for some 8678f336835SJun-ichiro itojun Haginoreason, configure net.inet6.ip6.use_deprecated to 0. The issue 8688f336835SJun-ichiro itojun Haginorelated to deprecated address is described in RFC2462 5.5.4 (NOTE: 8698f336835SJun-ichiro itojun Haginothere is some debate underway in IETF ipngwg on how to use 87080d21dc4SYoshinobu Inoue"deprecated" address). 87180d21dc4SYoshinobu Inoue 872f88fe57eSHajimu UMEMOTOAs documented in the source address selection document, temporary 873f88fe57eSHajimu UMEMOTOaddresses for privacy extension are less preferred to public addresses 874f88fe57eSHajimu UMEMOTOby default. However, for administrators who are particularly aware of 875f88fe57eSHajimu UMEMOTOthe privacy, there is a system-wide sysctl(3) variable 876f88fe57eSHajimu UMEMOTO"net.inet6.ip6.prefer_tempaddr". When the variable is set to 877f88fe57eSHajimu UMEMOTOnon-zero, the kernel will rather prefer temporary addresses. The 878f88fe57eSHajimu UMEMOTOdefault value of this variable is 0. 879f88fe57eSHajimu UMEMOTO 880f88fe57eSHajimu UMEMOTO1.6.2 Destination Address Ordering 881f88fe57eSHajimu UMEMOTO 882f88fe57eSHajimu UMEMOTOKAME's getaddrinfo(3) supports the destination address ordering 883f88fe57eSHajimu UMEMOTOalgorithm described in RFC3484. Getaddrinfo(3) needs to know the 884f88fe57eSHajimu UMEMOTOsource address for each destination address and policy entries 885f88fe57eSHajimu UMEMOTO(described in the previous section) for the source and destination 886f88fe57eSHajimu UMEMOTOaddresses. To get the source address, the library function opens a 887f88fe57eSHajimu UMEMOTOUDP socket and tries to connect(2) for the destination. To get the 888f88fe57eSHajimu UMEMOTOpolicy entry, the function issues sysctl(3). 889f88fe57eSHajimu UMEMOTO 89080d21dc4SYoshinobu Inoue1.7 Jumbo Payload 89180d21dc4SYoshinobu Inoue 89280d21dc4SYoshinobu InoueKAME supports the Jumbo Payload hop-by-hop option used to send IPv6 89380d21dc4SYoshinobu Inouepackets with payloads longer than 65,535 octets. But since currently 89480d21dc4SYoshinobu InoueKAME does not support any physical interface whose MTU is more than 89580d21dc4SYoshinobu Inoue65,535, such payloads can be seen only on the loopback interface(i.e. 89680d21dc4SYoshinobu Inouelo0). 89780d21dc4SYoshinobu Inoue 89880d21dc4SYoshinobu InoueIf you want to try jumbo payloads, you first have to reconfigure the 89980d21dc4SYoshinobu Inouekernel so that the MTU of the loopback interface is more than 65,535 90080d21dc4SYoshinobu Inouebytes; add the following to the kernel configuration file: 90180d21dc4SYoshinobu Inoue options "LARGE_LOMTU" #To test jumbo payload 90280d21dc4SYoshinobu Inoueand recompile the new kernel. 90380d21dc4SYoshinobu Inoue 90480d21dc4SYoshinobu InoueThen you can test jumbo payloads by the ping6 command with -b and -s 90580d21dc4SYoshinobu Inoueoptions. The -b option must be specified to enlarge the size of the 90680d21dc4SYoshinobu Inouesocket buffer and the -s option specifies the length of the packet, 90780d21dc4SYoshinobu Inouewhich should be more than 65,535. For example, type as follows; 90880d21dc4SYoshinobu Inoue % ping6 -b 70000 -s 68000 ::1 90980d21dc4SYoshinobu Inoue 91080d21dc4SYoshinobu InoueThe IPv6 specification requires that the Jumbo Payload option must not 91180d21dc4SYoshinobu Inouebe used in a packet that carries a fragment header. If this condition 91280d21dc4SYoshinobu Inoueis broken, an ICMPv6 Parameter Problem message must be sent to the 91380d21dc4SYoshinobu Inouesender. KAME kernel follows the specification, but you cannot usually 91480d21dc4SYoshinobu Inouesee an ICMPv6 error caused by this requirement. 91580d21dc4SYoshinobu Inoue 91680d21dc4SYoshinobu InoueIf KAME kernel receives an IPv6 packet, it checks the frame length of 91780d21dc4SYoshinobu Inouethe packet and compares it to the length specified in the payload 91880d21dc4SYoshinobu Inouelength field of the IPv6 header or in the value of the Jumbo Payload 91980d21dc4SYoshinobu Inoueoption, if any. If the former is shorter than the latter, KAME kernel 92080d21dc4SYoshinobu Inouediscards the packet and increments the statistics. You can see the 92180d21dc4SYoshinobu Inouestatistics as output of netstat command with `-s -p ip6' option: 92280d21dc4SYoshinobu Inoue % netstat -s -p ip6 92380d21dc4SYoshinobu Inoue ip6: 92480d21dc4SYoshinobu Inoue (snip) 92580d21dc4SYoshinobu Inoue 1 with data size < data length 92680d21dc4SYoshinobu Inoue 92780d21dc4SYoshinobu InoueSo, KAME kernel does not send an ICMPv6 error unless the erroneous 92880d21dc4SYoshinobu Inouepacket is an actual Jumbo Payload, that is, its packet size is more 92980d21dc4SYoshinobu Inouethan 65,535 bytes. As described above, KAME kernel currently does not 93080d21dc4SYoshinobu Inouesupport physical interface with such a huge MTU, so it rarely returns an 93180d21dc4SYoshinobu InoueICMPv6 error. 93280d21dc4SYoshinobu Inoue 93380d21dc4SYoshinobu InoueTCP/UDP over jumbogram is not supported at this moment. This is because 93480d21dc4SYoshinobu Inouewe have no medium (other than loopback) to test this. Contact us if you 93580d21dc4SYoshinobu Inoueneed this. 93680d21dc4SYoshinobu Inoue 93780d21dc4SYoshinobu InoueIPsec does not work on jumbograms. This is due to some specification twists 93880d21dc4SYoshinobu Inouein supporting AH with jumbograms (AH header size influences payload length, 93980d21dc4SYoshinobu Inoueand this makes it real hard to authenticate inbound packet with jumbo payload 94080d21dc4SYoshinobu Inoueoption as well as AH). 94180d21dc4SYoshinobu Inoue 94280d21dc4SYoshinobu InoueThere are fundamental issues in *BSD support for jumbograms. We would like to 9438f336835SJun-ichiro itojun Haginoaddress those, but we need more time to finalize the task. To name a few: 9448f336835SJun-ichiro itojun Hagino- mbuf pkthdr.len field is typed as "int" in 4.4BSD, so it cannot hold 94580d21dc4SYoshinobu Inoue jumbogram with len > 2G on 32bit architecture CPUs. If we would like to 94680d21dc4SYoshinobu Inoue support jumbogram properly, the field must be expanded to hold 4G + 94780d21dc4SYoshinobu Inoue IPv6 header + link-layer header. Therefore, it must be expanded to at least 94880d21dc4SYoshinobu Inoue int64_t (u_int32_t is NOT enough). 94980d21dc4SYoshinobu Inoue- We mistakingly use "int" to hold packet length in many places. We need 9508f336835SJun-ichiro itojun Hagino to convert them into larger numeric type. It needs a great care, as we may 95180d21dc4SYoshinobu Inoue experience overflow during packet length computation. 95280d21dc4SYoshinobu Inoue- We mistakingly check for ip6_plen field of IPv6 header for packet payload 95380d21dc4SYoshinobu Inoue length in various places. We should be checking mbuf pkthdr.len instead. 95480d21dc4SYoshinobu Inoue ip6_input() will perform sanity check on jumbo payload option on input, 95580d21dc4SYoshinobu Inoue and we can safely use mbuf pkthdr.len afterwards. 9568f336835SJun-ichiro itojun Hagino- TCP code needs careful updates in bunch of places, of course. 95780d21dc4SYoshinobu Inoue 95880d21dc4SYoshinobu Inoue1.8 Loop prevention in header processing 95980d21dc4SYoshinobu Inoue 96080d21dc4SYoshinobu InoueIPv6 specification allows arbitrary number of extension headers to 96180d21dc4SYoshinobu Inouebe placed onto packets. If we implement IPv6 packet processing 96280d21dc4SYoshinobu Inouecode in the way BSD IPv4 code is implemented, kernel stack may 96380d21dc4SYoshinobu Inoueoverflow due to long function call chain. KAME sys/netinet6 code 96480d21dc4SYoshinobu Inoueis carefully designed to avoid kernel stack overflow. Because of 96580d21dc4SYoshinobu Inouethis, KAME sys/netinet6 code defines its own protocol switch 96680d21dc4SYoshinobu Inouestructure, as "struct ip6protosw" (see netinet6/ip6protosw.h). 96733841545SHajimu UMEMOTO 96833841545SHajimu UMEMOTOIn addition to this, we restrict the number of extension headers 96933841545SHajimu UMEMOTO(including the IPv6 header) in each incoming packet, in order to 97033841545SHajimu UMEMOTOprevent a DoS attack that tries to send packets with a massive number 97133841545SHajimu UMEMOTOof extension headers. The upper limit can be configured by the sysctl 97233841545SHajimu UMEMOTOvalue net.inet6.ip6.hdrnestlimit. In particular, if the value is 0, 97333841545SHajimu UMEMOTOthe node will allow an arbitrary number of headers. As of writing this 97433841545SHajimu UMEMOTOdocument, the default value is 50. 97533841545SHajimu UMEMOTO 9768f336835SJun-ichiro itojun HaginoIPv4 part (sys/netinet) remains untouched for compatibility. 97780d21dc4SYoshinobu InoueBecause of this, if you receive IPsec-over-IPv4 packet with massive 97880d21dc4SYoshinobu Inouenumber of IPsec headers, kernel stack may blow up. IPsec-over-IPv6 is okay. 97980d21dc4SYoshinobu Inoue 98080d21dc4SYoshinobu Inoue1.9 ICMPv6 98180d21dc4SYoshinobu Inoue 98280d21dc4SYoshinobu InoueAfter RFC2463 was published, IETF ipngwg has decided to disallow ICMPv6 error 98380d21dc4SYoshinobu Inouepacket against ICMPv6 redirect, to prevent ICMPv6 storm on a network medium. 98480d21dc4SYoshinobu InoueKAME already implements this into the kernel. 98580d21dc4SYoshinobu Inoue 9868f336835SJun-ichiro itojun HaginoRFC2463 requires rate limitation for ICMPv6 error packets generated by a 9878f336835SJun-ichiro itojun Haginonode, to avoid possible DoS attacks. KAME kernel implements two rate- 9888f336835SJun-ichiro itojun Haginolimitation mechanisms, tunable via sysctl: 9898f336835SJun-ichiro itojun Hagino- Minimum time interval between ICMPv6 error packets 9908f336835SJun-ichiro itojun Hagino KAME kernel will generate no more than one ICMPv6 error packet, 9918f336835SJun-ichiro itojun Hagino during configured time interval. net.inet6.icmp6.errratelimit 9928f336835SJun-ichiro itojun Hagino controls the interval (default: disabled). 9938f336835SJun-ichiro itojun Hagino- Maximum ICMPv6 error packet-per-second 9948f336835SJun-ichiro itojun Hagino KAME kernel will generate no more than the configured number of 9958f336835SJun-ichiro itojun Hagino packets in one second. net.inet6.icmp6.errppslimit controls the 9968f336835SJun-ichiro itojun Hagino maximum packet-per-second value (default: 200pps) 9978f336835SJun-ichiro itojun HaginoBasically, we need to pick values that are suitable against the bandwidth 9988f336835SJun-ichiro itojun Haginoof link layer devices directly attached to the node. In some cases the 9998f336835SJun-ichiro itojun Haginodefault values may not fit well. We are still unsure if the default value 10008f336835SJun-ichiro itojun Haginois sane or not. Comments are welcome. 10018f336835SJun-ichiro itojun Hagino 100280d21dc4SYoshinobu Inoue1.10 Applications 100380d21dc4SYoshinobu Inoue 100480d21dc4SYoshinobu InoueFor userland programming, we support IPv6 socket API as specified in 10051f320556SHajimu UMEMOTORFC2553/3493, RFC3542 and upcoming internet drafts. 100680d21dc4SYoshinobu Inoue 100780d21dc4SYoshinobu InoueTCP/UDP over IPv6 is available and quite stable. You can enjoy "telnet", 100880d21dc4SYoshinobu Inoue"ftp", "rlogin", "rsh", "ssh", etc. These applications are protocol 100980d21dc4SYoshinobu Inoueindependent. That is, they automatically chooses IPv4 or IPv6 101080d21dc4SYoshinobu Inoueaccording to DNS. 101180d21dc4SYoshinobu Inoue 101280d21dc4SYoshinobu Inoue1.11 Kernel Internals 101380d21dc4SYoshinobu Inoue 101480d21dc4SYoshinobu Inoue (*) TCP/UDP part is handled differently between operating system platforms. 101580d21dc4SYoshinobu Inoue See 1.12 for details. 101680d21dc4SYoshinobu Inoue 101780d21dc4SYoshinobu InoueThe current KAME has escaped from the IPv4 netinet logic. While 101880d21dc4SYoshinobu Inoueip_forward() calls ip_output(), ip6_forward() directly calls 101980d21dc4SYoshinobu Inoueif_output() since routers must not divide IPv6 packets into fragments. 102080d21dc4SYoshinobu Inoue 102180d21dc4SYoshinobu InoueICMPv6 should contain the original packet as long as possible up to 102280d21dc4SYoshinobu Inoue1280. UDP6/IP6 port unreach, for instance, should contain all 102380d21dc4SYoshinobu Inoueextension headers and the *unchanged* UDP6 and IP6 headers. 10248f336835SJun-ichiro itojun HaginoSo, all IP6 functions except TCP6 never convert network byte 102580d21dc4SYoshinobu Inoueorder into host byte order, to save the original packet. 102680d21dc4SYoshinobu Inoue 10278f336835SJun-ichiro itojun Haginotcp6_input(), udp6_input() and icmp6_input() can't assume that IP6 102880d21dc4SYoshinobu Inoueheader is preceding the transport headers due to extension 102980d21dc4SYoshinobu Inoueheaders. So, in6_cksum() was implemented to handle packets whose IP6 10308f336835SJun-ichiro itojun Haginoheader and transport header is not continuous. TCP/IP6 nor UDP/IP6 103180d21dc4SYoshinobu Inoueheader structure don't exist for checksum calculation. 103280d21dc4SYoshinobu Inoue 103380d21dc4SYoshinobu InoueTo process IP6 header, extension headers and transport headers easily, 103480d21dc4SYoshinobu InoueKAME requires network drivers to store packets in one internal mbuf or 103580d21dc4SYoshinobu Inoueone or more external mbufs. A typical old driver prepares two 10368f336835SJun-ichiro itojun Haginointernal mbufs for 100 - 208 bytes data, however, KAME's reference 103780d21dc4SYoshinobu Inoueimplementation stores it in one external mbuf. 103880d21dc4SYoshinobu Inoue 103980d21dc4SYoshinobu Inoue"netstat -s -p ip6" tells you whether or not your driver conforms 104080d21dc4SYoshinobu InoueKAME's requirement. In the following example, "cce0" violates the 104180d21dc4SYoshinobu Inouerequirement. (For more information, refer to Section 2.) 104280d21dc4SYoshinobu Inoue 104380d21dc4SYoshinobu Inoue Mbuf statistics: 104480d21dc4SYoshinobu Inoue 317 one mbuf 104580d21dc4SYoshinobu Inoue two or more mbuf:: 104680d21dc4SYoshinobu Inoue lo0 = 8 104780d21dc4SYoshinobu Inoue cce0 = 10 104880d21dc4SYoshinobu Inoue 3282 one ext mbuf 104980d21dc4SYoshinobu Inoue 0 two or more ext mbuf 105080d21dc4SYoshinobu Inoue 10518f336835SJun-ichiro itojun Haginoxxx_ctlinput() calls in_mrejoin() on PRC_IFNEWADDR. We think this is 10528f336835SJun-ichiro itojun Haginoone of 4.4BSD implementation flaws. Since 4.4BSD keeps ia_multiaddrs 10538f336835SJun-ichiro itojun Haginoin in_ifaddr{}, it can't use multicast feature if the interface has no 10548f336835SJun-ichiro itojun Haginounicast address. So, if an application joins to an interface and then 10558f336835SJun-ichiro itojun Haginoall unicast addresses are removed from the interface, the application 10568f336835SJun-ichiro itojun Haginocan't send/receive any multicast packets. Moreover, if a new unicast 10578f336835SJun-ichiro itojun Haginoaddress is assigned to the interface, in_mrejoin() must be called. 10588f336835SJun-ichiro itojun HaginoKAME's interfaces, however, have ALWAYS one link-local unicast 10598f336835SJun-ichiro itojun Haginoaddress. These extensions have thus not been implemented in KAME. 106080d21dc4SYoshinobu Inoue 106180d21dc4SYoshinobu Inoue1.12 IPv4 mapped address and IPv6 wildcard socket 106280d21dc4SYoshinobu Inoue 1063f88fe57eSHajimu UMEMOTORFC2553/3493 describes IPv4 mapped address (3.7) and special behavior 106480d21dc4SYoshinobu Inoueof IPv6 wildcard bind socket (3.8). The spec allows you to: 106580d21dc4SYoshinobu Inoue- Accept IPv4 connections by AF_INET6 wildcard bind socket. 106680d21dc4SYoshinobu Inoue- Transmit IPv4 packet over AF_INET6 socket by using special form of 106780d21dc4SYoshinobu Inoue the address like ::ffff:10.1.1.1. 106880d21dc4SYoshinobu Inouebut the spec itself is very complicated and does not specify how the 106980d21dc4SYoshinobu Inouesocket layer should behave. 107080d21dc4SYoshinobu InoueHere we call the former one "listening side" and the latter one "initiating 107180d21dc4SYoshinobu Inoueside", for reference purposes. 107280d21dc4SYoshinobu Inoue 107380d21dc4SYoshinobu InoueAlmost all KAME implementations treat tcp/udp port number space separately 10748f336835SJun-ichiro itojun Haginobetween IPv4 and IPv6. You can perform wildcard bind on both of the address 107580d21dc4SYoshinobu Inouefamilies, on the same port. 107680d21dc4SYoshinobu Inoue 10778f336835SJun-ichiro itojun HaginoThere are some OS-platform differences in KAME code, as we use tcp/udp 10788f336835SJun-ichiro itojun Haginocode from different origin. The following table summarizes the behavior. 107980d21dc4SYoshinobu Inoue 108080d21dc4SYoshinobu Inoue listening side initiating side 10818f336835SJun-ichiro itojun Hagino (AF_INET6 wildcard (connection to ::ffff:10.1.1.1) 108280d21dc4SYoshinobu Inoue socket gets IPv4 conn.) 108380d21dc4SYoshinobu Inoue --- --- 10848f336835SJun-ichiro itojun HaginoKAME/BSDI3 not supported not supported 10858f336835SJun-ichiro itojun HaginoKAME/FreeBSD228 not supported not supported 10868f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x configurable supported 108780d21dc4SYoshinobu Inoue default: enabled 10888f336835SJun-ichiro itojun HaginoKAME/FreeBSD4x configurable supported 10898f336835SJun-ichiro itojun Hagino default: enabled 10908f336835SJun-ichiro itojun HaginoKAME/NetBSD configurable supported 10918f336835SJun-ichiro itojun Hagino default: disabled 10928f336835SJun-ichiro itojun HaginoKAME/BSDI4 enabled supported 10938f336835SJun-ichiro itojun HaginoKAME/OpenBSD not supported not supported 109480d21dc4SYoshinobu Inoue 109580d21dc4SYoshinobu InoueThe following sections will give you more details, and how you can 109680d21dc4SYoshinobu Inoueconfigure the behavior. 109780d21dc4SYoshinobu Inoue 109880d21dc4SYoshinobu InoueComments on listening side: 109980d21dc4SYoshinobu Inoue 1100f88fe57eSHajimu UMEMOTOIt looks that RFC2553/3493 talks too little on wildcard bind issue, 11018f336835SJun-ichiro itojun Haginospecifically on (1) port space issue, (2) failure mode, (3) relationship 11028f336835SJun-ichiro itojun Haginobetween AF_INET/INET6 wildcard bind like ordering constraint, and (4) behavior 11038f336835SJun-ichiro itojun Haginowhen conflicting socket is opened/closed. There can be several separate 110480d21dc4SYoshinobu Inoueinterpretation for this RFC which conform to it but behaves differently. 110580d21dc4SYoshinobu InoueSo, to implement portable application you should assume nothing 110680d21dc4SYoshinobu Inoueabout the behavior in the kernel. Using getaddrinfo() is the safest way. 110780d21dc4SYoshinobu InouePort number space and wildcard bind issues were discussed in detail 110880d21dc4SYoshinobu Inoueon ipv6imp mailing list, in mid March 1999 and it looks that there's 110980d21dc4SYoshinobu Inoueno concrete consensus (means, up to implementers). You may want to 111080d21dc4SYoshinobu Inouecheck the mailing list archives. 11118f336835SJun-ichiro itojun HaginoWe supply a tool called "bindtest" that explores the behavior of 11128f336835SJun-ichiro itojun Haginokernel bind(2). The tool will not be compiled by default. 111380d21dc4SYoshinobu Inoue 111480d21dc4SYoshinobu InoueIf a server application would like to accept IPv4 and IPv6 connections, 11158f336835SJun-ichiro itojun Haginoit should use AF_INET and AF_INET6 socket (you'll need two sockets). 111680d21dc4SYoshinobu InoueUse getaddrinfo() with AI_PASSIVE into ai_flags, and socket(2) and bind(2) 111780d21dc4SYoshinobu Inoueto all the addresses returned. 111880d21dc4SYoshinobu InoueBy opening multiple sockets, you can accept connections onto the socket with 111980d21dc4SYoshinobu Inoueproper address family. IPv4 connections will be accepted by AF_INET socket, 11208f336835SJun-ichiro itojun Haginoand IPv6 connections will be accepted by AF_INET6 socket (NOTE: KAME/BSDI4 11218f336835SJun-ichiro itojun Haginokernel sometimes violate this - we will fix it). 112280d21dc4SYoshinobu Inoue 11238f336835SJun-ichiro itojun HaginoIf you try to support IPv6 traffic only and would like to reject IPv4 11248f336835SJun-ichiro itojun Haginotraffic, always check the peer address when a connection is made toward 112580d21dc4SYoshinobu InoueAF_INET6 listening socket. If the address is IPv4 mapped address, you may 112680d21dc4SYoshinobu Inouewant to reject the connection. You can check the condition by using 11278f336835SJun-ichiro itojun HaginoIN6_IS_ADDR_V4MAPPED() macro. This is one of the reasons the author of 11288f336835SJun-ichiro itojun Haginothe section (itojun) dislikes special behavior of AF_INET6 wildcard bind. 112980d21dc4SYoshinobu Inoue 113080d21dc4SYoshinobu InoueComments on initiating side: 113180d21dc4SYoshinobu Inoue 113280d21dc4SYoshinobu InoueAdvise to application implementers: to implement a portable IPv6 application 113380d21dc4SYoshinobu Inoue(which works on multiple IPv6 kernels), we believe that the following 113480d21dc4SYoshinobu Inoueis the key to the success: 113580d21dc4SYoshinobu Inoue- NEVER hardcode AF_INET nor AF_INET6. 113680d21dc4SYoshinobu Inoue- Use getaddrinfo() and getnameinfo() throughout the system. 113780d21dc4SYoshinobu Inoue Never use gethostby*(), getaddrby*(), inet_*() or getipnodeby*(). 113880d21dc4SYoshinobu Inoue- If you would like to connect to destination, use getaddrinfo() and try 113980d21dc4SYoshinobu Inoue all the destination returned, like telnet does. 114080d21dc4SYoshinobu Inoue- Some of the IPv6 stack is shipped with buggy getaddrinfo(). Ship a minimal 114180d21dc4SYoshinobu Inoue working version with your application and use that as last resort. 114280d21dc4SYoshinobu Inoue 114380d21dc4SYoshinobu InoueIf you would like to use AF_INET6 socket for both IPv4 and IPv6 outgoing 11448f336835SJun-ichiro itojun Haginoconnection, you will need tweaked implementation in DNS support libraries, 1145f88fe57eSHajimu UMEMOTOas documented in RFC2553/3493 6.1. KAME libinet6 includes the tweak in 11468f336835SJun-ichiro itojun Haginogetipnodebyname(). Note that getipnodebyname() itself is not recommended as 11478f336835SJun-ichiro itojun Haginoit does not handle scoped IPv6 addresses at all. For IPv6 name resolution 11488f336835SJun-ichiro itojun Haginogetaddrinfo() is the preferred API. getaddrinfo() does not implement the 11498f336835SJun-ichiro itojun Haginotweak. 115080d21dc4SYoshinobu Inoue 115180d21dc4SYoshinobu InoueWhen writing applications that make outgoing connections, story goes much 11528f336835SJun-ichiro itojun Haginosimpler if you treat AF_INET and AF_INET6 as totally separate address family. 115380d21dc4SYoshinobu Inoue{set,get}sockopt issue goes simpler, DNS issue will be made simpler. We do 115480d21dc4SYoshinobu Inouenot recommend you to rely upon IPv4 mapped address. 115580d21dc4SYoshinobu Inoue 11568f336835SJun-ichiro itojun Hagino1.12.1 KAME/BSDI3 and KAME/FreeBSD228 115780d21dc4SYoshinobu Inoue 11588f336835SJun-ichiro itojun HaginoThe platforms do not support IPv4 mapped address at all (both listening side 11598f336835SJun-ichiro itojun Haginoand initiating side). AF_INET6 and AF_INET sockets are totally separated. 116080d21dc4SYoshinobu Inoue 11618f336835SJun-ichiro itojun HaginoPort number space is totally separate between AF_INET and AF_INET6 sockets. 116280d21dc4SYoshinobu Inoue 116333841545SHajimu UMEMOTOIt should be noted that KAME/BSDI3 and KAME/FreeBSD228 are not conformant 1164f88fe57eSHajimu UMEMOTOto RFC2553/3493 section 3.7 and 3.8. It is due to code sharing reasons. 116533841545SHajimu UMEMOTO 11668f336835SJun-ichiro itojun Hagino1.12.2 KAME/FreeBSD[34]x 116780d21dc4SYoshinobu Inoue 11688f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x and KAME/FreeBSD4x use shared tcp4/6 code (from 11698f336835SJun-ichiro itojun Haginosys/netinet/tcp*) and shared udp4/6 code (from sys/netinet/udp*). 11708f336835SJun-ichiro itojun HaginoThey use unified inpcb/in6pcb structure. 117180d21dc4SYoshinobu Inoue 11728f336835SJun-ichiro itojun Hagino1.12.2.1 KAME/FreeBSD[34]x, listening side 11738f336835SJun-ichiro itojun Hagino 11748f336835SJun-ichiro itojun HaginoThe platform can be configured to support IPv4 mapped address/special 11758f336835SJun-ichiro itojun HaginoAF_INET6 wildcard bind (enabled by default). There is no kernel compilation 11768f336835SJun-ichiro itojun Haginooption to disable it. You can enable/disable the behavior with sysctl 11778f336835SJun-ichiro itojun Hagino(per-node), or setsockopt (per-socket). 117880d21dc4SYoshinobu Inoue 117980d21dc4SYoshinobu InoueWildcard AF_INET6 socket grabs IPv4 connection if and only if the following 118080d21dc4SYoshinobu Inoueconditions are satisfied: 118180d21dc4SYoshinobu Inoue- there's no AF_INET socket that matches the IPv4 connection 118280d21dc4SYoshinobu Inoue- the AF_INET6 socket is configured to accept IPv4 traffic, i.e. 118333841545SHajimu UMEMOTO getsockopt(IPV6_V6ONLY) returns 0. 118480d21dc4SYoshinobu Inoue 11858f336835SJun-ichiro itojun Hagino(XXX need checking) 118680d21dc4SYoshinobu Inoue 11878f336835SJun-ichiro itojun Hagino1.12.2.2 KAME/FreeBSD[34]x, initiating side 11888f336835SJun-ichiro itojun Hagino 11898f336835SJun-ichiro itojun HaginoKAME/FreeBSD3x supports outgoing connection to IPv4 mapped address 11908f336835SJun-ichiro itojun Hagino(::ffff:10.1.1.1), if the node is configured to accept IPv4 connections 11918f336835SJun-ichiro itojun Haginoby AF_INET6 socket. 11928f336835SJun-ichiro itojun Hagino 11938f336835SJun-ichiro itojun Hagino(XXX need checking) 11948f336835SJun-ichiro itojun Hagino 11958f336835SJun-ichiro itojun Hagino1.12.3 KAME/NetBSD 11968f336835SJun-ichiro itojun Hagino 11978f336835SJun-ichiro itojun HaginoKAME/NetBSD uses shared tcp4/6 code (from sys/netinet/tcp*) and shared 11988f336835SJun-ichiro itojun Haginoudp4/6 code (from sys/netinet/udp*). The implementation is made differently 11998f336835SJun-ichiro itojun Haginofrom KAME/FreeBSD[34]x. KAME/NetBSD uses separate inpcb/in6pcb structures, 12008f336835SJun-ichiro itojun Haginowhile KAME/FreeBSD[34]x uses merged inpcb structure. 12018f336835SJun-ichiro itojun Hagino 120233841545SHajimu UMEMOTOIt should be noted that the default configuration of KAME/NetBSD is not 1203f88fe57eSHajimu UMEMOTOconformant to RFC2553/3493 section 3.8. It is intentionally turned off by 1204f88fe57eSHajimu UMEMOTOdefault for security reasons. 12058f336835SJun-ichiro itojun Hagino 12068f336835SJun-ichiro itojun HaginoThe platform can be configured to support IPv4 mapped address/special AF_INET6 12078f336835SJun-ichiro itojun Haginowildcard bind (disabled by default). Kernel behavior can be summarized as 12088f336835SJun-ichiro itojun Haginofollows: 12098f336835SJun-ichiro itojun Hagino- default: special support code will be compiled in, but is disabled by 121033841545SHajimu UMEMOTO default. It can be controlled by sysctl (net.inet6.ip6.v6only), 121133841545SHajimu UMEMOTO or setsockopt(IPV6_V6ONLY). 1212f88fe57eSHajimu UMEMOTO- add "INET6_BINDV6ONLY": No special support code for AF_INET6 wildcard socket 12138f336835SJun-ichiro itojun Hagino will be compiled in. AF_INET6 sockets and AF_INET sockets are totally 12148f336835SJun-ichiro itojun Hagino separate. The behavior is similar to what described in 1.12.1. 12158f336835SJun-ichiro itojun Hagino 12168f336835SJun-ichiro itojun Haginosysctl setting will affect per-socket configuration at in6pcb creation time 12178f336835SJun-ichiro itojun Haginoonly. In other words, per-socket configuration will be copied from sysctl 12188f336835SJun-ichiro itojun Haginoconfiguration at in6pcb creation time. To change per-socket behavior, you 12198f336835SJun-ichiro itojun Haginomust perform setsockopt or reopen the socket. Change in sysctl configuration 12208f336835SJun-ichiro itojun Haginowill not change the behavior or sockets that are already opened. 12218f336835SJun-ichiro itojun Hagino 1222f88fe57eSHajimu UMEMOTO1.12.3.1 KAME/NetBSD, listening side 1223f88fe57eSHajimu UMEMOTO 12248f336835SJun-ichiro itojun HaginoWildcard AF_INET6 socket grabs IPv4 connection if and only if the following 12258f336835SJun-ichiro itojun Haginoconditions are satisfied: 12268f336835SJun-ichiro itojun Hagino- there's no AF_INET socket that matches the IPv4 connection 12278f336835SJun-ichiro itojun Hagino- the AF_INET6 socket is configured to accept IPv4 traffic, i.e. 122833841545SHajimu UMEMOTO getsockopt(IPV6_V6ONLY) returns 0. 12298f336835SJun-ichiro itojun Hagino 12308f336835SJun-ichiro itojun HaginoYou cannot bind(2) with IPv4 mapped address. This is a workaround for port 12318f336835SJun-ichiro itojun Haginonumber duplicate and other twists. 12328f336835SJun-ichiro itojun Hagino 12338f336835SJun-ichiro itojun Hagino1.12.3.2 KAME/NetBSD, initiating side 12348f336835SJun-ichiro itojun Hagino 1235f88fe57eSHajimu UMEMOTOWhen getsockopt(IPV6_V6ONLY) is 0 for a socket, you can make an outgoing 1236f88fe57eSHajimu UMEMOTOtraffic to IPv4 destination over AF_INET6 socket, using IPv4 mapped 1237f88fe57eSHajimu UMEMOTOaddress destination (::ffff:10.1.1.1). 1238f88fe57eSHajimu UMEMOTO 1239f88fe57eSHajimu UMEMOTOWhen getsockopt(IPV6_V6ONLY) is 1 for a socket, you cannot use IPv4 mapped 1240f88fe57eSHajimu UMEMOTOaddress for outgoing traffic. 12418f336835SJun-ichiro itojun Hagino 12428f336835SJun-ichiro itojun Hagino1.12.4 KAME/BSDI4 12438f336835SJun-ichiro itojun Hagino 12448f336835SJun-ichiro itojun HaginoKAME/BSDI4 uses NRL-based TCP/UDP stack and inpcb source code, 12458f336835SJun-ichiro itojun Haginowhich was derived from NRL IPv6/IPsec stack. We guess it supports IPv4 mapped 12468f336835SJun-ichiro itojun Haginoaddress and speical AF_INET6 wildcard bind. The implementation is, again, 12478f336835SJun-ichiro itojun Haginodifferent from other KAME/*BSDs. 12488f336835SJun-ichiro itojun Hagino 12498f336835SJun-ichiro itojun Hagino1.12.4.1 KAME/BSDI4, listening side 12508f336835SJun-ichiro itojun Hagino 12518f336835SJun-ichiro itojun HaginoNRL inpcb layer supports special behavior of AF_INET6 wildcard socket. 12528f336835SJun-ichiro itojun HaginoThere is no way to disable the behavior. 12538f336835SJun-ichiro itojun Hagino 12548f336835SJun-ichiro itojun HaginoWildcard AF_INET6 socket grabs IPv4 connection if and only if the following 12558f336835SJun-ichiro itojun Haginocondition is satisfied: 12568f336835SJun-ichiro itojun Hagino- there's no AF_INET socket that matches the IPv4 connection 12578f336835SJun-ichiro itojun Hagino 12588f336835SJun-ichiro itojun Hagino1.12.4.2 KAME/BSDI4, initiating side 12598f336835SJun-ichiro itojun Hagino 12608f336835SJun-ichiro itojun HaginoKAME/BSDi4 supports connection initiation to IPv4 mapped address 12618f336835SJun-ichiro itojun Hagino(like ::ffff:10.1.1.1). 12628f336835SJun-ichiro itojun Hagino 12638f336835SJun-ichiro itojun Hagino1.12.5 KAME/OpenBSD 12648f336835SJun-ichiro itojun Hagino 12658f336835SJun-ichiro itojun HaginoKAME/OpenBSD uses NRL-based TCP/UDP stack and inpcb source code, 12668f336835SJun-ichiro itojun Haginowhich was derived from NRL IPv6/IPsec stack. 12678f336835SJun-ichiro itojun Hagino 1268f88fe57eSHajimu UMEMOTOIt should be noted that KAME/OpenBSD is not conformant to RFC2553/3493 section 1269f88fe57eSHajimu UMEMOTO3.7 and 3.8. It is intentionally omitted for security reasons. 127033841545SHajimu UMEMOTO 12718f336835SJun-ichiro itojun Hagino1.12.5.1 KAME/OpenBSD, listening side 12728f336835SJun-ichiro itojun Hagino 12738f336835SJun-ichiro itojun HaginoKAME/OpenBSD disables special behavior on AF_INET6 wildcard bind for 12748f336835SJun-ichiro itojun Haginosecurity reasons (if IPv4 traffic toward AF_INET6 wildcard bind is allowed, 12758f336835SJun-ichiro itojun Haginoaccess control will become much harder). KAME/BSDI4 uses NRL-based TCP/UDP 12768f336835SJun-ichiro itojun Haginostack as well, however, the behavior is different due to OpenBSD's security 12778f336835SJun-ichiro itojun Haginopolicy. 12788f336835SJun-ichiro itojun Hagino 12798f336835SJun-ichiro itojun HaginoAs a result the behavior of KAME/OpenBSD is similar to KAME/BSDI3 and 12808f336835SJun-ichiro itojun HaginoKAME/FreeBSD228 (see 1.12.1 for more detail). 12818f336835SJun-ichiro itojun Hagino 12828f336835SJun-ichiro itojun Hagino1.12.5.2 KAME/OpenBSD, initiating side 12838f336835SJun-ichiro itojun Hagino 12848f336835SJun-ichiro itojun HaginoKAME/OpenBSD does not support connection initiation to IPv4 mapped address 12858f336835SJun-ichiro itojun Hagino(like ::ffff:10.1.1.1). 12868f336835SJun-ichiro itojun Hagino 12878f336835SJun-ichiro itojun Hagino1.12.6 More issues 12888f336835SJun-ichiro itojun Hagino 12898f336835SJun-ichiro itojun HaginoIPv4 mapped address support adds a big requirement to EVERY userland codebase. 12908f336835SJun-ichiro itojun HaginoEvery userland code should check if an AF_INET6 sockaddr contains IPv4 12918f336835SJun-ichiro itojun Haginomapped address or not. This adds many twists: 12928f336835SJun-ichiro itojun Hagino 12938f336835SJun-ichiro itojun Hagino- Access controls code becomes harder to write. 12948f336835SJun-ichiro itojun Hagino For example, if you would like to reject packets from 10.0.0.0/8, 12958f336835SJun-ichiro itojun Hagino you need to reject packets to AF_INET socket from 10.0.0.0/8, 12968f336835SJun-ichiro itojun Hagino and to AF_INET6 socket from ::ffff:10.0.0.0/104. 12978f336835SJun-ichiro itojun Hagino- If a protocol on top of IPv4 is defined differently with IPv6, we need to be 12988f336835SJun-ichiro itojun Hagino really careful when we determine which protocol to use. 12998f336835SJun-ichiro itojun Hagino For example, with FTP protocol, we can not simply use sa_family to determine 13008f336835SJun-ichiro itojun Hagino FTP command sets. The following example is incorrect: 13018f336835SJun-ichiro itojun Hagino if (sa_family == AF_INET) 13028f336835SJun-ichiro itojun Hagino use EPSV/EPRT or PASV/PORT; /*IPv4*/ 13038f336835SJun-ichiro itojun Hagino else if (sa_family == AF_INET6) 13048f336835SJun-ichiro itojun Hagino use EPSV/EPRT or LPSV/LPRT; /*IPv6*/ 13058f336835SJun-ichiro itojun Hagino else 13068f336835SJun-ichiro itojun Hagino error; 130733841545SHajimu UMEMOTO The correct code, with consideration to IPv4 mapped address, would be: 13088f336835SJun-ichiro itojun Hagino if (sa_family == AF_INET) 13098f336835SJun-ichiro itojun Hagino use EPSV/EPRT or PASV/PORT; /*IPv4*/ 13108f336835SJun-ichiro itojun Hagino else if (sa_family == AF_INET6 && IPv4 mapped address) 13118f336835SJun-ichiro itojun Hagino use EPSV/EPRT or PASV/PORT; /*IPv4 command set on AF_INET6*/ 13128f336835SJun-ichiro itojun Hagino else if (sa_family == AF_INET6 && !IPv4 mapped address) 13138f336835SJun-ichiro itojun Hagino use EPSV/EPRT or LPSV/LPRT; /*IPv6*/ 13148f336835SJun-ichiro itojun Hagino else 13158f336835SJun-ichiro itojun Hagino error; 13168f336835SJun-ichiro itojun Hagino It is too much to ask for every body to be careful like this. 13178f336835SJun-ichiro itojun Hagino The problem is, we are not sure if the above code fragment is perfect for 13188f336835SJun-ichiro itojun Hagino all situations. 13198f336835SJun-ichiro itojun Hagino- By enabling kernel support for IPv4 mapped address (outgoing direction), 13208f336835SJun-ichiro itojun Hagino servers on the kernel can be hosed by IPv6 native packet that has IPv4 13218f336835SJun-ichiro itojun Hagino mapped address in IPv6 header source, and can generate unwanted IPv4 packets. 1322f88fe57eSHajimu UMEMOTO draft-itojun-ipv6-transition-abuse-01.txt, draft-cmetz-v6ops-v4mapped-api- 1323f88fe57eSHajimu UMEMOTO harmful-00.txt, and draft-itojun-v6ops-v4mapped-harmful-01.txt 1324f88fe57eSHajimu UMEMOTO has more on this scenario. 13258f336835SJun-ichiro itojun Hagino 13268f336835SJun-ichiro itojun HaginoDue to the above twists, some of KAME userland programs has restrictions on 13278f336835SJun-ichiro itojun Haginothe use of IPv4 mapped addresses: 13288f336835SJun-ichiro itojun Hagino- rshd/rlogind do not accept connections from IPv4 mapped address. 13298f336835SJun-ichiro itojun Hagino This is to avoid malicious use of IPv4 mapped address in IPv6 native 13308f336835SJun-ichiro itojun Hagino packet, to bypass source-address based authentication. 133133841545SHajimu UMEMOTO- ftp/ftpd assume that you are on dual stack network. IPv4 mapped address 133233841545SHajimu UMEMOTO will be decoded in userland, and will be passed to AF_INET sockets 133333841545SHajimu UMEMOTO (in other words, ftp/ftpd do not support SIIT environment). 133433841545SHajimu UMEMOTO 133533841545SHajimu UMEMOTO1.12.7 Interaction with SIIT translator 133633841545SHajimu UMEMOTO 133733841545SHajimu UMEMOTOSIIT translator is specified in RFC2765. KAME node cannot become a SIIT 133833841545SHajimu UMEMOTOtranslator box, nor SIIT end node (a node in SIIT cloud). 133933841545SHajimu UMEMOTO 134033841545SHajimu UMEMOTOTo become a SIIT translator box, we need to put additional code for that. 134133841545SHajimu UMEMOTOWe do not have the code in our tree at this moment. 134233841545SHajimu UMEMOTO 134333841545SHajimu UMEMOTOThere are multiple reasons that we are unable to become SIIT end node. 134433841545SHajimu UMEMOTO(1) SIIT translators require end nodes in the SIIT cloud to be IPv6-only. 134533841545SHajimu UMEMOTOSince we are unable to compile INET-less kernel, we are unable to become 134633841545SHajimu UMEMOTOSIIT end node. (2) As presented in 1.12.6, some of our userland code assumes 134733841545SHajimu UMEMOTOdual stack network. (3) KAME stack filters out IPv6 packets with IPv4 134833841545SHajimu UMEMOTOmapped address in the header, to secure non-SIIT case (which is much more 134933841545SHajimu UMEMOTOcommon). Effectively KAME node will reject any packets via SIIT translator 135033841545SHajimu UMEMOTObox. See section 1.14 for more detail about the last item. 135133841545SHajimu UMEMOTO 135233841545SHajimu UMEMOTOThere are documentation issues too - SIIT document requires very strange 135333841545SHajimu UMEMOTOthings. For example, SIIT document asks IPv6-only (meaning no IPv4 code) 135433841545SHajimu UMEMOTOnode to be able to construct IPv4 IPsec headers. If a node knows how to 135533841545SHajimu UMEMOTOconstruct IPv4 IPsec headers, that is not an IPv6-only node, it is a dual-stack 135633841545SHajimu UMEMOTOnode. The requirements imposed in SIIT document contradict with the other 135733841545SHajimu UMEMOTOpart of the document itself. 135880d21dc4SYoshinobu Inoue 135980d21dc4SYoshinobu Inoue1.13 sockaddr_storage 136080d21dc4SYoshinobu Inoue 13618f336835SJun-ichiro itojun HaginoWhen RFC2553 was about to be finalized, there was discussion on how struct 136280d21dc4SYoshinobu Inouesockaddr_storage members are named. One proposal is to prepend "__" to the 136380d21dc4SYoshinobu Inouemembers (like "__ss_len") as they should not be touched. The other proposal 136480d21dc4SYoshinobu Inouewas that don't prepend it (like "ss_len") as we need to touch those members 136580d21dc4SYoshinobu Inouedirectly. There was no clear consensus on it. 136680d21dc4SYoshinobu Inoue 136780d21dc4SYoshinobu InoueAs a result, RFC2553 defines struct sockaddr_storage as follows: 136880d21dc4SYoshinobu Inoue struct sockaddr_storage { 136980d21dc4SYoshinobu Inoue u_char __ss_len; /* address length */ 137080d21dc4SYoshinobu Inoue u_char __ss_family; /* address family */ 137180d21dc4SYoshinobu Inoue /* and bunch of padding */ 137280d21dc4SYoshinobu Inoue }; 137380d21dc4SYoshinobu InoueOn the contrary, XNET draft defines as follows: 137480d21dc4SYoshinobu Inoue struct sockaddr_storage { 137580d21dc4SYoshinobu Inoue u_char ss_len; /* address length */ 137680d21dc4SYoshinobu Inoue u_char ss_family; /* address family */ 137780d21dc4SYoshinobu Inoue /* and bunch of padding */ 137880d21dc4SYoshinobu Inoue }; 137980d21dc4SYoshinobu Inoue 1380f88fe57eSHajimu UMEMOTOIn December 1999, it was agreed that RFC2553bis (RFC3493) should pick the 1381f88fe57eSHajimu UMEMOTOlatter (XNET) definition. 138280d21dc4SYoshinobu Inoue 138380d21dc4SYoshinobu InoueKAME kit prior to December 1999 used RFC2553 definition. KAME kit after 138480d21dc4SYoshinobu InoueDecember 1999 (including December) will conform to XNET definition, 1385f88fe57eSHajimu UMEMOTObased on RFC3493 discussion. 138680d21dc4SYoshinobu Inoue 138780d21dc4SYoshinobu InoueIf you look at multiple IPv6 implementations, you will be able to see 138880d21dc4SYoshinobu Inoueboth definitions. As an userland programmer, the most portable way of 138980d21dc4SYoshinobu Inouedealing with it is to: 139080d21dc4SYoshinobu Inoue(1) ensure ss_family and/or ss_len are available on the platform, by using 139180d21dc4SYoshinobu Inoue GNU autoconf, 139293b03d5dSUlrich Spörlein(2) have -Dss_family=__ss_family to unify all occurrences (including header 139380d21dc4SYoshinobu Inoue file) into __ss_family, or 139480d21dc4SYoshinobu Inoue(3) never touch __ss_family. cast to sockaddr * and use sa_family like: 139580d21dc4SYoshinobu Inoue struct sockaddr_storage ss; 139680d21dc4SYoshinobu Inoue family = ((struct sockaddr *)&ss)->sa_family 139780d21dc4SYoshinobu Inoue 13988f336835SJun-ichiro itojun Hagino1.14 Invalid addresses on the wire 13998f336835SJun-ichiro itojun Hagino 14008f336835SJun-ichiro itojun HaginoSome of IPv6 transition technologies embed IPv4 address into IPv6 address. 14018f336835SJun-ichiro itojun HaginoThese specifications themselves are fine, however, there can be certain 140293b03d5dSUlrich Spörleinset of attacks enabled by these specifications. Recent specification 14038f336835SJun-ichiro itojun Haginodocuments covers up those issues, however, there are already-published RFCs 14048f336835SJun-ichiro itojun Haginothat does not have protection against those (like using source address of 14058f336835SJun-ichiro itojun Hagino::ffff:127.0.0.1 to bypass "reject packet from remote" filter). 14068f336835SJun-ichiro itojun Hagino 14078f336835SJun-ichiro itojun HaginoTo name a few, these address ranges can be used to hose an IPv6 implementation, 14088f336835SJun-ichiro itojun Haginoor bypass security controls: 14098f336835SJun-ichiro itojun Hagino- IPv4 mapped address that embeds unspecified/multicast/loopback/broadcast 14108f336835SJun-ichiro itojun Hagino IPv4 address (if they are in IPv6 native packet header, they are malicious) 14118f336835SJun-ichiro itojun Hagino ::ffff:0.0.0.0/104 ::ffff:127.0.0.0/104 14128f336835SJun-ichiro itojun Hagino ::ffff:224.0.0.0/100 ::ffff:255.0.0.0/104 141333841545SHajimu UMEMOTO- 6to4 (RFC3056) prefix generated from unspecified/multicast/loopback/ 141433841545SHajimu UMEMOTO broadcast/private IPv4 address 14158f336835SJun-ichiro itojun Hagino 2002:0000::/24 2002:7f00::/24 2002:e000::/24 14168f336835SJun-ichiro itojun Hagino 2002:ff00::/24 2002:0a00::/24 2002:ac10::/28 14178f336835SJun-ichiro itojun Hagino 2002:c0a8::/32 141833841545SHajimu UMEMOTO- IPv4 compatible address that embeds unspecified/multicast/loopback/broadcast 141933841545SHajimu UMEMOTO IPv4 address (if they are in IPv6 native packet header, they are malicious). 142033841545SHajimu UMEMOTO Note that, since KAME doe snot support RFC1933/2893 auto tunnels, KAME nodes 142133841545SHajimu UMEMOTO are not vulnerable to these packets. 142233841545SHajimu UMEMOTO ::0.0.0.0/104 ::127.0.0.0/104 ::224.0.0.0/100 ::255.0.0.0/104 14238f336835SJun-ichiro itojun Hagino 142433841545SHajimu UMEMOTOAlso, since KAME does not support RFC1933/2893 auto tunnels, seeing IPv4 142533841545SHajimu UMEMOTOcompatible is very rare. You should take caution if you see those on the wire. 142633841545SHajimu UMEMOTO 142733841545SHajimu UMEMOTOIf we see IPv6 packets with IPv4 mapped address (::ffff:0.0.0.0/96) in the 142833841545SHajimu UMEMOTOheader in dual-stack environment (not in SIIT environment), they indicate 142993b03d5dSUlrich Spörleinthat someone is trying to impersonate IPv4 peer. The packet should be dropped. 143033841545SHajimu UMEMOTO 143133841545SHajimu UMEMOTOIPv6 specifications do not talk very much about IPv6 unspecified address (::) 143233841545SHajimu UMEMOTOin the IPv6 source address field. Clarification is in progress. 143333841545SHajimu UMEMOTOHere are couple of comments: 143433841545SHajimu UMEMOTO- IPv6 unspecified address can be used in IPv6 source address field, if and 143533841545SHajimu UMEMOTO only if we have no legal source address for the node. The legal situations 143633841545SHajimu UMEMOTO include, but may not be limited to, (1) MLD while no IPv6 address is assigned 143733841545SHajimu UMEMOTO to the node and (2) DAD. 143833841545SHajimu UMEMOTO- If IPv6 TCP packet has IPv6 unspecified address, it is an attack attempt. 143933841545SHajimu UMEMOTO The form can be used as a trigger for TCP DoS attack. KAME code already 144033841545SHajimu UMEMOTO filters them out. 144133841545SHajimu UMEMOTO- The following examples are seemingly illegal. It seems that there's general 1442743eee66SSUZUKI Shinsuke consensus among ipngwg for those. (1) Mobile IPv6 home address option, 144333841545SHajimu UMEMOTO (2) offlink packets (so routers should not forward them). 144493b03d5dSUlrich Spörlein KAME implements (2) already. 14458f336835SJun-ichiro itojun Hagino 14468f336835SJun-ichiro itojun HaginoKAME code is carefully written to avoid such incidents. More specifically, 144793b03d5dSUlrich SpörleinKAME kernel will reject packets with certain source/destination address in IPv6 14488f336835SJun-ichiro itojun Haginobase header, or IPv6 routing header. Also, KAME default configuration file 14498f336835SJun-ichiro itojun Haginois written carefully, to avoid those attacks. 14508f336835SJun-ichiro itojun Hagino 1451f88fe57eSHajimu UMEMOTOdraft-itojun-ipv6-transition-abuse-01.txt, draft-cmetz-v6ops-v4mapped-api- 1452f88fe57eSHajimu UMEMOTOharmful-00.txt and draft-itojun-v6ops-v4mapped-harmful-01.txt has more on 1453f88fe57eSHajimu UMEMOTOthis issue. 14548f336835SJun-ichiro itojun Hagino 14558f336835SJun-ichiro itojun Hagino1.15 Node's required addresses 14568f336835SJun-ichiro itojun Hagino 14578f336835SJun-ichiro itojun HaginoRFC2373 section 2.8 talks about required addresses for an IPv6 14588f336835SJun-ichiro itojun Haginonode. The section talks about how KAME stack manages those required 14598f336835SJun-ichiro itojun Haginoaddresses. 14608f336835SJun-ichiro itojun Hagino 14618f336835SJun-ichiro itojun Hagino1.15.1 Host case 14628f336835SJun-ichiro itojun Hagino 14638f336835SJun-ichiro itojun HaginoThe following items are automatically assigned to the node (or the node will 14648f336835SJun-ichiro itojun Haginoautomatically joins the group), at bootstrap time: 14658f336835SJun-ichiro itojun Hagino- Loopback address 14668f336835SJun-ichiro itojun Hagino- All-nodes multicast addresses (ff01::1) 14678f336835SJun-ichiro itojun Hagino 14688f336835SJun-ichiro itojun HaginoThe following items will be automatically handled when the interface becomes 14698f336835SJun-ichiro itojun HaginoIFF_UP: 14708f336835SJun-ichiro itojun Hagino- Its link-local address for each interface 14718f336835SJun-ichiro itojun Hagino- Solicited-node multicast address for link-local addresses 14728f336835SJun-ichiro itojun Hagino- Link-local allnodes multicast address (ff02::1) 14738f336835SJun-ichiro itojun Hagino 14748f336835SJun-ichiro itojun HaginoThe following items need to be configured manually by ifconfig(8) or prefix(8). 14758f336835SJun-ichiro itojun HaginoAlternatively, these can be autoconfigured by using stateless address 14768f336835SJun-ichiro itojun Haginoautoconfiguration. 14778f336835SJun-ichiro itojun Hagino- Assigned unicast/anycast addresses 14788f336835SJun-ichiro itojun Hagino- Solicited-Node multicast address for assigned unicast address 14798f336835SJun-ichiro itojun Hagino 14808f336835SJun-ichiro itojun HaginoUsers can join groups by using appropriate system calls like setsockopt(2). 14818f336835SJun-ichiro itojun Hagino 14828f336835SJun-ichiro itojun Hagino1.15.2 Router case 14838f336835SJun-ichiro itojun Hagino 1484*dcde2454SHo-Kun LinIn addition to the above, routers need to handle the following items. 14858f336835SJun-ichiro itojun Hagino 14868f336835SJun-ichiro itojun HaginoThe following items need to be configured manually by using ifconfig(8). 14878f336835SJun-ichiro itojun Haginoo The subnet-router anycast addresses for the interfaces it is configured 14888f336835SJun-ichiro itojun Hagino to act as a router on (prefix::/64) 14898f336835SJun-ichiro itojun Haginoo All other anycast addresses with which the router has been configured 14908f336835SJun-ichiro itojun Hagino 14918f336835SJun-ichiro itojun HaginoThe router will join the following multicast group when rtadvd(8) is available 14928f336835SJun-ichiro itojun Haginofor the interface. 14938f336835SJun-ichiro itojun Haginoo All-Routers Multicast Addresses (ff02::2) 14948f336835SJun-ichiro itojun Hagino 14958f336835SJun-ichiro itojun HaginoRouting daemons will join appropriate multicast groups, as necessary, 14968f336835SJun-ichiro itojun Haginolike ff02::9 for RIPng. 14978f336835SJun-ichiro itojun Hagino 14988f336835SJun-ichiro itojun HaginoUsers can join groups by using appropriate system calls like setsockopt(2). 14998f336835SJun-ichiro itojun Hagino 150033841545SHajimu UMEMOTO1.16 Advanced API 150133841545SHajimu UMEMOTO 1502f88fe57eSHajimu UMEMOTOCurrent KAME kernel implements RFC3542 API. It also implements RFC2292 API, 150333841545SHajimu UMEMOTOfor backward compatibility purposes with *BSD-integrated codebase. 1504f88fe57eSHajimu UMEMOTOKAME tree ships with RFC3542 headers. 1505f88fe57eSHajimu UMEMOTO*BSD-integrated codebase implements either RFC2292, or RFC3542, API. 150633841545SHajimu UMEMOTOsee "COVERAGE" document for detailed implementation status. 150733841545SHajimu UMEMOTO 150833841545SHajimu UMEMOTOHere are couple of issues to mention: 150933841545SHajimu UMEMOTO- *BSD-integrated binaries, compiled for RFC2292, will work on KAME kernel. 151033841545SHajimu UMEMOTO For example, OpenBSD 2.7 /sbin/rtsol will work on KAME/openbsd kernel. 1511f88fe57eSHajimu UMEMOTO- KAME binaries, compiled using RFC3542, will not work on *BSD-integrated 151233841545SHajimu UMEMOTO kenrel. For example, KAME /usr/local/v6/sbin/rtsol will not work on 151333841545SHajimu UMEMOTO OpenBSD 2.7 kernel. 1514f88fe57eSHajimu UMEMOTO- RFC3542 API is not compatible with RFC2292 API. RFC3542 #define symbols 151533841545SHajimu UMEMOTO conflict with RFC2292 symbols. Therefore, if you compile programs that 151633841545SHajimu UMEMOTO assume RFC2292 API, the compilation itself goes fine, however, the compiled 151733841545SHajimu UMEMOTO binary will not work correctly. The problem is not KAME issue, but API 1518f88fe57eSHajimu UMEMOTO issue. For example, Solaris 8 implements RFC3542 API. If you compile 151933841545SHajimu UMEMOTO RFC2292-based code on Solaris 8, the binary can behave strange. 152033841545SHajimu UMEMOTO 152133841545SHajimu UMEMOTOThere are few (or couple of) incompatible behavior in RFC2292 binary backward 152233841545SHajimu UMEMOTOcompatibility support in KAME tree. To enumerate: 152333841545SHajimu UMEMOTO- Type 0 routing header lacks support for strict/loose bitmap. 152433841545SHajimu UMEMOTO Even if we see packets with "strict" bit set, those bits will not be made 152533841545SHajimu UMEMOTO visible to the userland. 152633841545SHajimu UMEMOTO Background: RFC2292 document is based on RFC1883 IPv6, and it uses 1527f88fe57eSHajimu UMEMOTO strict/loose bitmap. RFC3542 document is based on RFC2460 IPv6, and it has 152833841545SHajimu UMEMOTO no strict/loose bitmap (it was removed from RFC2460). KAME tree obeys 152933841545SHajimu UMEMOTO RFC2460 IPv6, and lacks support for strict/loose bitmap. 153033841545SHajimu UMEMOTO 1531f88fe57eSHajimu UMEMOTOThe RFC3542 documents leave some particular cases unspecified. The 1532f88fe57eSHajimu UMEMOTOKAME implementation treats them as follows: 1533f88fe57eSHajimu UMEMOTO- The IPV6_DONTFRAG and IPV6_RECVPATHMTU socket options for TCP 1534f88fe57eSHajimu UMEMOTO sockets are ignored. That is, the setsocktopt() call will succeed 1535f88fe57eSHajimu UMEMOTO but the specified value will have no effect. 1536f88fe57eSHajimu UMEMOTO 1537f88fe57eSHajimu UMEMOTO1.17 DNS resolver 1538f88fe57eSHajimu UMEMOTO 1539f88fe57eSHajimu UMEMOTOKAME ships with modified DNS resolver, in libinet6.a. 154093b03d5dSUlrich Spörleinlibinet6.a has a couple of extensions against libc DNS resolver: 1541f88fe57eSHajimu UMEMOTO- Can take "options insecure1" and "options insecure2" in /etc/resolv.conf, 1542f88fe57eSHajimu UMEMOTO which toggles RES_INSECURE[12] option flag bit. 1543f88fe57eSHajimu UMEMOTO- EDNS0 receive buffer size notification support. It can be enabled by 1544f88fe57eSHajimu UMEMOTO "options edns0" in /etc/resolv.conf. See USAGE for details. 1545f88fe57eSHajimu UMEMOTO- IPv6 transport support (queries/responses over IPv6). Most of BSD official 1546f88fe57eSHajimu UMEMOTO releases now has it already. 1547f88fe57eSHajimu UMEMOTO- Partial A6 chain chasing/DNAME/bit string label support (KAME/BSDI4). 1548f88fe57eSHajimu UMEMOTO 1549f88fe57eSHajimu UMEMOTO 155080d21dc4SYoshinobu Inoue2. Network Drivers 155180d21dc4SYoshinobu Inoue 15528f336835SJun-ichiro itojun HaginoKAME requires three items to be added into the standard drivers: 155380d21dc4SYoshinobu Inoue 1554f88fe57eSHajimu UMEMOTO(1) (freebsd[234] and bsdi[34] only) mbuf clustering requirement. 1555f88fe57eSHajimu UMEMOTO In this stable release, we changed MINCLSIZE into MHLEN+1 for all the 1556f88fe57eSHajimu UMEMOTO operating systems in order to make all the drivers behave as we expect. 155780d21dc4SYoshinobu Inoue 155880d21dc4SYoshinobu Inoue(2) multicast. If "ifmcstat" yields no multicast group for a 155980d21dc4SYoshinobu Inoue interface, that interface has to be patched. 156080d21dc4SYoshinobu Inoue 15618f336835SJun-ichiro itojun HaginoTo avoid troubles, we suggest you to comment out the device drivers 15628f336835SJun-ichiro itojun Haginofor unsupported/unnecessary cards, from the kernel configuration file. 15638f336835SJun-ichiro itojun HaginoIf you accidentally enable unsupported drivers, some of the userland 15648f336835SJun-ichiro itojun Haginotools may not work correctly (routing daemons are typical example). 15658f336835SJun-ichiro itojun Hagino 15668f336835SJun-ichiro itojun HaginoIn the following sections, "official support" means that KAME developers 15678f336835SJun-ichiro itojun Haginoare using that ethernet card/driver frequently. 156880d21dc4SYoshinobu Inoue 156980d21dc4SYoshinobu Inoue(NOTE: In the past we required all pcmcia drivers to have a call to 157080d21dc4SYoshinobu Inouein6_ifattach(). We have no such requirement any more) 157180d21dc4SYoshinobu Inoue 15728f336835SJun-ichiro itojun Hagino2.1 FreeBSD 2.2.x-RELEASE 15738f336835SJun-ichiro itojun Hagino 15748f336835SJun-ichiro itojun HaginoHere is a list of FreeBSD 2.2.x-RELEASE drivers and its conditions: 15758f336835SJun-ichiro itojun Hagino 15768f336835SJun-ichiro itojun Hagino driver mbuf(1) multicast(2) official support? 15778f336835SJun-ichiro itojun Hagino --- --- --- --- 15788f336835SJun-ichiro itojun Hagino (Ethernet) 15798f336835SJun-ichiro itojun Hagino ar looks ok - - 15808f336835SJun-ichiro itojun Hagino cnw ok ok yes (*) 15818f336835SJun-ichiro itojun Hagino ed ok ok yes 15828f336835SJun-ichiro itojun Hagino ep ok ok yes 15838f336835SJun-ichiro itojun Hagino fe ok ok yes 15848f336835SJun-ichiro itojun Hagino sn looks ok - - (*) 15858f336835SJun-ichiro itojun Hagino vx looks ok - - 15868f336835SJun-ichiro itojun Hagino wlp ok ok - (*) 15878f336835SJun-ichiro itojun Hagino xl ok ok yes 15888f336835SJun-ichiro itojun Hagino zp ok ok - 15898f336835SJun-ichiro itojun Hagino (FDDI) 15908f336835SJun-ichiro itojun Hagino fpa looks ok ? - 15918f336835SJun-ichiro itojun Hagino (ATM) 15928f336835SJun-ichiro itojun Hagino en ok ok yes 15938f336835SJun-ichiro itojun Hagino (Serial) 15948f336835SJun-ichiro itojun Hagino lp ? - not work 15958f336835SJun-ichiro itojun Hagino sl ? - not work 15968f336835SJun-ichiro itojun Hagino sr looks ok ok - (**) 15978f336835SJun-ichiro itojun Hagino 15988f336835SJun-ichiro itojun HaginoYou may want to add an invocation of "rtsol" in "/etc/pccard_ether", 15998f336835SJun-ichiro itojun Haginoif you are using notebook computers and PCMCIA ethernet card. 16008f336835SJun-ichiro itojun Hagino 16018f336835SJun-ichiro itojun Hagino(*) These drivers are distributed with PAO (http://www.jp.freebsd.org/PAO/). 16028f336835SJun-ichiro itojun Hagino 16038f336835SJun-ichiro itojun Hagino(**) There was some report says that, if you make sr driver up and down and 16048f336835SJun-ichiro itojun Haginothen up, the kernel may hang up. We have disabled frame-relay support from 16058f336835SJun-ichiro itojun Haginosr driver and after that this looks to be working fine. If you need 16068f336835SJun-ichiro itojun Haginoframe-relay support to come back, please contact KAME developers. 16078f336835SJun-ichiro itojun Hagino 16088f336835SJun-ichiro itojun Hagino2.2 BSD/OS 3.x 16098f336835SJun-ichiro itojun Hagino 16108f336835SJun-ichiro itojun HaginoThe following lists BSD/OS 3.x device drivers and its conditions: 16118f336835SJun-ichiro itojun Hagino 16128f336835SJun-ichiro itojun Hagino driver mbuf(1) multicast(2) official support? 16138f336835SJun-ichiro itojun Hagino --- --- --- --- 16148f336835SJun-ichiro itojun Hagino (Ethernet) 16158f336835SJun-ichiro itojun Hagino cnw ok ok yes 16168f336835SJun-ichiro itojun Hagino de ok ok - 16178f336835SJun-ichiro itojun Hagino df ok ok - 16188f336835SJun-ichiro itojun Hagino eb ok ok - 16198f336835SJun-ichiro itojun Hagino ef ok ok yes 16208f336835SJun-ichiro itojun Hagino exp ok ok - 16218f336835SJun-ichiro itojun Hagino mz ok ok yes 16228f336835SJun-ichiro itojun Hagino ne ok ok yes 16238f336835SJun-ichiro itojun Hagino we ok ok - 16248f336835SJun-ichiro itojun Hagino (FDDI) 16258f336835SJun-ichiro itojun Hagino fpa ok ok - 16268f336835SJun-ichiro itojun Hagino (ATM) 16278f336835SJun-ichiro itojun Hagino en maybe ok - 16288f336835SJun-ichiro itojun Hagino (Serial) 16298f336835SJun-ichiro itojun Hagino ntwo ok ok yes 16308f336835SJun-ichiro itojun Hagino sl ? - not work 16318f336835SJun-ichiro itojun Hagino appp ? - not work 16328f336835SJun-ichiro itojun Hagino 16338f336835SJun-ichiro itojun HaginoYou may want to use "@insert" directive in /etc/pccard.conf to invoke 16348f336835SJun-ichiro itojun Hagino"rtsol" command right after dynamic insertion of PCMCIA ethernet cards. 16358f336835SJun-ichiro itojun Hagino 16368f336835SJun-ichiro itojun Hagino2.3 NetBSD 16378f336835SJun-ichiro itojun Hagino 16388f336835SJun-ichiro itojun HaginoThe following table lists the network drivers we have tried so far. 16398f336835SJun-ichiro itojun Hagino 16408f336835SJun-ichiro itojun Hagino driver mbuf(1) multicast(2) official support? 16418f336835SJun-ichiro itojun Hagino --- --- --- --- 16428f336835SJun-ichiro itojun Hagino (Ethernet) 16438f336835SJun-ichiro itojun Hagino awi pcmcia/i386 ok ok - 16448f336835SJun-ichiro itojun Hagino bah zbus/amiga NG(*) 16458f336835SJun-ichiro itojun Hagino cnw pcmcia/i386 ok ok yes 16468f336835SJun-ichiro itojun Hagino ep pcmcia/i386 ok ok - 1647743eee66SSUZUKI Shinsuke fxp pci/i386 ok(*2) ok - 1648743eee66SSUZUKI Shinsuke tlp pci/i386 ok ok - 16498f336835SJun-ichiro itojun Hagino le sbus/sparc ok ok yes 16508f336835SJun-ichiro itojun Hagino ne pci/i386 ok ok yes 16518f336835SJun-ichiro itojun Hagino ne pcmcia/i386 ok ok yes 1652743eee66SSUZUKI Shinsuke rtk pci/i386 ok ok - 16538f336835SJun-ichiro itojun Hagino wi pcmcia/i386 ok ok yes 16548f336835SJun-ichiro itojun Hagino (ATM) 16558f336835SJun-ichiro itojun Hagino en pci/i386 ok ok - 16568f336835SJun-ichiro itojun Hagino 16578f336835SJun-ichiro itojun Hagino(*) This may need some fix, but I'm not sure what arcnet interfaces assume... 16588f336835SJun-ichiro itojun Hagino 16598f336835SJun-ichiro itojun Hagino2.4 FreeBSD 3.x-RELEASE 16608f336835SJun-ichiro itojun Hagino 16618f336835SJun-ichiro itojun HaginoHere is a list of FreeBSD 3.x-RELEASE drivers and its conditions: 16628f336835SJun-ichiro itojun Hagino 16638f336835SJun-ichiro itojun Hagino driver mbuf(1) multicast(2) official support? 16648f336835SJun-ichiro itojun Hagino --- --- --- --- 16658f336835SJun-ichiro itojun Hagino (Ethernet) 16668f336835SJun-ichiro itojun Hagino cnw ok ok -(*) 16678f336835SJun-ichiro itojun Hagino ed ? ok - 16688f336835SJun-ichiro itojun Hagino ep ok ok - 16698f336835SJun-ichiro itojun Hagino fe ok ok yes 16708f336835SJun-ichiro itojun Hagino fxp ?(**) 16718f336835SJun-ichiro itojun Hagino lnc ? ok - 16728f336835SJun-ichiro itojun Hagino sn ? ? -(*) 16738f336835SJun-ichiro itojun Hagino wi ok ok yes 16748f336835SJun-ichiro itojun Hagino xl ? ok - 16758f336835SJun-ichiro itojun Hagino 16768f336835SJun-ichiro itojun Hagino(*) These drivers are distributed with PAO as PAO3 16778f336835SJun-ichiro itojun Hagino (http://www.jp.freebsd.org/PAO/). 1678743eee66SSUZUKI Shinsuke(**) there were trouble reports with multicast filter initialization. 16798f336835SJun-ichiro itojun Hagino 16808f336835SJun-ichiro itojun HaginoMore drivers will just simply work on KAME FreeBSD 3.x-RELEASE but have not 16818f336835SJun-ichiro itojun Haginobeen checked yet. 16828f336835SJun-ichiro itojun Hagino 168333841545SHajimu UMEMOTO2.5 FreeBSD 4.x-RELEASE 168433841545SHajimu UMEMOTO 168533841545SHajimu UMEMOTOHere is a list of FreeBSD 4.x-RELEASE drivers and its conditions: 168633841545SHajimu UMEMOTO 168733841545SHajimu UMEMOTO driver multicast 168833841545SHajimu UMEMOTO --- --- 168933841545SHajimu UMEMOTO (Ethernet) 169033841545SHajimu UMEMOTO lnc/vmware ok 169133841545SHajimu UMEMOTO 169233841545SHajimu UMEMOTO2.6 OpenBSD 2.x 16938f336835SJun-ichiro itojun Hagino 16948f336835SJun-ichiro itojun HaginoHere is a list of OpenBSD 2.x drivers and its conditions: 16958f336835SJun-ichiro itojun Hagino 16968f336835SJun-ichiro itojun Hagino driver mbuf(1) multicast(2) official support? 16978f336835SJun-ichiro itojun Hagino --- --- --- --- 16988f336835SJun-ichiro itojun Hagino (Ethernet) 16998f336835SJun-ichiro itojun Hagino de pci/i386 ok ok yes 17008f336835SJun-ichiro itojun Hagino fxp pci/i386 ?(*) 17018f336835SJun-ichiro itojun Hagino le sbus/sparc ok ok yes 17028f336835SJun-ichiro itojun Hagino ne pci/i386 ok ok yes 17038f336835SJun-ichiro itojun Hagino ne pcmcia/i386 ok ok yes 17048f336835SJun-ichiro itojun Hagino wi pcmcia/i386 ok ok yes 17058f336835SJun-ichiro itojun Hagino 17068f336835SJun-ichiro itojun Hagino(*) There seem to be some problem in driver, with multicast filter 17078f336835SJun-ichiro itojun Haginoconfiguration. This happens with certain revision of chipset on the card. 17088f336835SJun-ichiro itojun HaginoShould be fixed by now by workaround in sys/net/if.c, but still not sure. 17098f336835SJun-ichiro itojun Hagino 171033841545SHajimu UMEMOTO2.7 BSD/OS 4.x 17118f336835SJun-ichiro itojun Hagino 17128f336835SJun-ichiro itojun HaginoThe following lists BSD/OS 4.x device drivers and its conditions: 17138f336835SJun-ichiro itojun Hagino 17148f336835SJun-ichiro itojun Hagino driver mbuf(1) multicast(2) official support? 17158f336835SJun-ichiro itojun Hagino --- --- --- --- 17168f336835SJun-ichiro itojun Hagino (Ethernet) 17178f336835SJun-ichiro itojun Hagino de ok ok yes 17188f336835SJun-ichiro itojun Hagino exp (*) 17198f336835SJun-ichiro itojun Hagino 17208f336835SJun-ichiro itojun HaginoYou may want to use "@insert" directive in /etc/pccard.conf to invoke 17218f336835SJun-ichiro itojun Hagino"rtsol" command right after dynamic insertion of PCMCIA ethernet cards. 17228f336835SJun-ichiro itojun Hagino 17238f336835SJun-ichiro itojun Hagino(*) exp driver has serious conflict with KAME initialization sequence. 17248f336835SJun-ichiro itojun HaginoA workaround is committed into sys/i386/pci/if_exp.c, and should be okay by now. 17258f336835SJun-ichiro itojun Hagino 1726743eee66SSUZUKI Shinsuke 172780d21dc4SYoshinobu Inoue3. Translator 172880d21dc4SYoshinobu Inoue 172980d21dc4SYoshinobu InoueWe categorize IPv4/IPv6 translator into 4 types. 173080d21dc4SYoshinobu Inoue 173180d21dc4SYoshinobu InoueTranslator A --- It is used in the early stage of transition to make 173280d21dc4SYoshinobu Inoueit possible to establish a connection from an IPv6 host in an IPv6 173380d21dc4SYoshinobu Inoueisland to an IPv4 host in the IPv4 ocean. 173480d21dc4SYoshinobu Inoue 173580d21dc4SYoshinobu InoueTranslator B --- It is used in the early stage of transition to make 173680d21dc4SYoshinobu Inoueit possible to establish a connection from an IPv4 host in the IPv4 173780d21dc4SYoshinobu Inoueocean to an IPv6 host in an IPv6 island. 173880d21dc4SYoshinobu Inoue 173980d21dc4SYoshinobu InoueTranslator C --- It is used in the late stage of transition to make it 174080d21dc4SYoshinobu Inouepossible to establish a connection from an IPv4 host in an IPv4 island 174180d21dc4SYoshinobu Inoueto an IPv6 host in the IPv6 ocean. 174280d21dc4SYoshinobu Inoue 174380d21dc4SYoshinobu InoueTranslator D --- It is used in the late stage of transition to make it 174480d21dc4SYoshinobu Inouepossible to establish a connection from an IPv6 host in the IPv6 ocean 174580d21dc4SYoshinobu Inoueto an IPv4 host in an IPv4 island. 174680d21dc4SYoshinobu Inoue 174780d21dc4SYoshinobu InoueKAME provides an TCP relay translator for category A. This is called 174880d21dc4SYoshinobu Inoue"FAITH". We also provide IP header translator for category A. 174980d21dc4SYoshinobu Inoue 175080d21dc4SYoshinobu Inoue3.1 FAITH TCP relay translator 175180d21dc4SYoshinobu Inoue 175280d21dc4SYoshinobu InoueFAITH system uses TCP relay daemon called "faithd" helped by the KAME kernel. 175380d21dc4SYoshinobu InoueFAITH will reserve an IPv6 address prefix, and relay TCP connection 175480d21dc4SYoshinobu Inouetoward that prefix to IPv4 destination. 175580d21dc4SYoshinobu Inoue 175680d21dc4SYoshinobu InoueFor example, if the reserved IPv6 prefix is 3ffe:0501:0200:ffff::, and 175780d21dc4SYoshinobu Inouethe IPv6 destination for TCP connection is 3ffe:0501:0200:ffff::163.221.202.12, 175880d21dc4SYoshinobu Inouethe connection will be relayed toward IPv4 destination 163.221.202.12. 175980d21dc4SYoshinobu Inoue 176080d21dc4SYoshinobu Inoue destination IPv4 node (163.221.202.12) 176180d21dc4SYoshinobu Inoue ^ 176280d21dc4SYoshinobu Inoue | IPv4 tcp toward 163.221.202.12 176380d21dc4SYoshinobu Inoue FAITH-relay dual stack node 176480d21dc4SYoshinobu Inoue ^ 176580d21dc4SYoshinobu Inoue | IPv6 TCP toward 3ffe:0501:0200:ffff::163.221.202.12 176680d21dc4SYoshinobu Inoue source IPv6 node 176780d21dc4SYoshinobu Inoue 176880d21dc4SYoshinobu Inouefaithd must be invoked on FAITH-relay dual stack node. 176980d21dc4SYoshinobu Inoue 1770743eee66SSUZUKI ShinsukeFor more details, consult kame/kame/faithd/README and RFC3142. 177180d21dc4SYoshinobu Inoue 177280d21dc4SYoshinobu Inoue3.2 IPv6-to-IPv4 header translator 177380d21dc4SYoshinobu Inoue 177433841545SHajimu UMEMOTO(to be written) 177580d21dc4SYoshinobu Inoue 1776743eee66SSUZUKI Shinsuke 177780d21dc4SYoshinobu Inoue4. IPsec 177880d21dc4SYoshinobu Inoue 17798f336835SJun-ichiro itojun HaginoIPsec is implemented as the following three components. 178080d21dc4SYoshinobu Inoue 178180d21dc4SYoshinobu Inoue(1) Policy Management 178280d21dc4SYoshinobu Inoue(2) Key Management 17838f336835SJun-ichiro itojun Hagino(3) AH, ESP and IPComp handling in kernel 17848f336835SJun-ichiro itojun Hagino 17858f336835SJun-ichiro itojun HaginoNote that KAME/OpenBSD does NOT include support for KAME IPsec code, 17868f336835SJun-ichiro itojun Haginoas OpenBSD team has their home-brew IPsec stack and they have no plan 17878f336835SJun-ichiro itojun Haginoto replace it. IPv6 support for IPsec is, therefore, lacking on KAME/OpenBSD. 178880d21dc4SYoshinobu Inoue 178933841545SHajimu UMEMOTOhttp://www.netbsd.org/Documentation/network/ipsec/ has more information 179033841545SHajimu UMEMOTOincluding usage examples. 179133841545SHajimu UMEMOTO 179280d21dc4SYoshinobu Inoue4.1 Policy Management 179380d21dc4SYoshinobu Inoue 1794f88fe57eSHajimu UMEMOTOThe kernel implements experimental policy management code. There are two ways 179580d21dc4SYoshinobu Inoueto manage security policy. One is to configure per-socket policy using 179680d21dc4SYoshinobu Inouesetsockopt(3). In this cases, policy configuration is described in 179780d21dc4SYoshinobu Inoueipsec_set_policy(3). The other is to configure kernel packet filter-based 179880d21dc4SYoshinobu Inouepolicy using PF_KEY interface, via setkey(8). 179980d21dc4SYoshinobu Inoue 18008f336835SJun-ichiro itojun HaginoThe policy entry will be matched in order. The order of entries makes 18018f336835SJun-ichiro itojun Haginodifference in behavior. 180280d21dc4SYoshinobu Inoue 180380d21dc4SYoshinobu Inoue4.2 Key Management 180480d21dc4SYoshinobu Inoue 180580d21dc4SYoshinobu InoueThe key management code implemented in this kit (sys/netkey) is a 180680d21dc4SYoshinobu Inouehome-brew PFKEY v2 implementation. This conforms to RFC2367. 180780d21dc4SYoshinobu Inoue 18088f336835SJun-ichiro itojun HaginoThe home-brew IKE daemon, "racoon" is included in the kit (kame/kame/racoon, 18098f336835SJun-ichiro itojun Haginoor usr.sbin/racoon). 181080d21dc4SYoshinobu InoueBasically you'll need to run racoon as daemon, then setup a policy 181180d21dc4SYoshinobu Inoueto require keys (like ping -P 'out ipsec esp/transport//use'). 181280d21dc4SYoshinobu InoueThe kernel will contact racoon daemon as necessary to exchange keys. 181380d21dc4SYoshinobu Inoue 18148f336835SJun-ichiro itojun HaginoIn IKE spec, there's ambiguity about interpretation of "tunnel" proposal. 18158f336835SJun-ichiro itojun HaginoFor example, if we would like to propose the use of following packet: 18168f336835SJun-ichiro itojun Hagino IP AH ESP IP payload 18178f336835SJun-ichiro itojun Haginosome implementation proposes it as "AH transport and ESP tunnel", since 18188f336835SJun-ichiro itojun Haginothis is more logical from packet construction point of view. Some 18198f336835SJun-ichiro itojun Haginoimplementation proposes it as "AH tunnel and ESP tunnel". 1820f88fe57eSHajimu UMEMOTORacoon follows the latter route (previously it followed the former, and 1821f88fe57eSHajimu UMEMOTOthe latter interpretation seems to be popular/consensus). 18228f336835SJun-ichiro itojun HaginoThis raises real interoperability issue. We hope this to be resolved quickly. 18238f336835SJun-ichiro itojun Hagino 1824f88fe57eSHajimu UMEMOTOracoon does not implement byte lifetime for both phase 1 and phase 2 1825f88fe57eSHajimu UMEMOTO(RFC2409 page 35, Life Type = kilobytes). 1826f88fe57eSHajimu UMEMOTO 182780d21dc4SYoshinobu Inoue4.3 AH and ESP handling 182880d21dc4SYoshinobu Inoue 182980d21dc4SYoshinobu InoueIPsec module is implemented as "hooks" to the standard IPv4/IPv6 183080d21dc4SYoshinobu Inoueprocessing. When sending a packet, ip{,6}_output() checks if ESP/AH 183180d21dc4SYoshinobu Inoueprocessing is required by checking if a matching SPD (Security 183280d21dc4SYoshinobu InouePolicy Database) is found. If ESP/AH is needed, 183380d21dc4SYoshinobu Inoue{esp,ah}{4,6}_output() will be called and mbuf will be updated 183480d21dc4SYoshinobu Inoueaccordingly. When a packet is received, {esp,ah}4_input() will be 183580d21dc4SYoshinobu Inouecalled based on protocol number, i.e. (*inetsw[proto])(). 183680d21dc4SYoshinobu Inoue{esp,ah}4_input() will decrypt/check authenticity of the packet, 183780d21dc4SYoshinobu Inoueand strips off daisy-chained header and padding for ESP/AH. It is 183880d21dc4SYoshinobu Inouesafe to strip off the ESP/AH header on packet reception, since we 183980d21dc4SYoshinobu Inouewill never use the received packet in "as is" form. 184080d21dc4SYoshinobu Inoue 184180d21dc4SYoshinobu InoueBy using ESP/AH, TCP4/6 effective data segment size will be affected by 184280d21dc4SYoshinobu Inoueextra daisy-chained headers inserted by ESP/AH. Our code takes care of 184380d21dc4SYoshinobu Inouethe case. 184480d21dc4SYoshinobu Inoue 184580d21dc4SYoshinobu InoueBasic crypto functions can be found in directory "sys/crypto". ESP/AH 184680d21dc4SYoshinobu Inouetransform are listed in {esp,ah}_core.c with wrapper functions. If you 184780d21dc4SYoshinobu Inouewish to add some algorithm, add wrapper function in {esp,ah}_core.c, and 184880d21dc4SYoshinobu Inoueadd your crypto algorithm code into sys/crypto. 184980d21dc4SYoshinobu Inoue 18508f336835SJun-ichiro itojun HaginoTunnel mode works basically fine, but comes with the following restrictions: 18518f336835SJun-ichiro itojun Hagino- You cannot run routing daemon across IPsec tunnel, since we do not model 18528f336835SJun-ichiro itojun Hagino IPsec tunnel as pseudo interfaces. 185380d21dc4SYoshinobu Inoue- Authentication model for AH tunnel must be revisited. We'll need to 185480d21dc4SYoshinobu Inoue improve the policy management engine, eventually. 185533841545SHajimu UMEMOTO- Path MTU discovery does not work across IPv6 IPsec tunnel gateway due to 185633841545SHajimu UMEMOTO insufficient code. 185780d21dc4SYoshinobu Inoue 185893b03d5dSUlrich SpörleinAH specification does not talk much about "multiple AH on a packet" case. 18598f336835SJun-ichiro itojun HaginoWe incrementally compute AH checksum, from inside to outside. Also, we 18608f336835SJun-ichiro itojun Haginotreat inner AH to be immutable. 18618f336835SJun-ichiro itojun HaginoFor example, if we are to create the following packet: 18628f336835SJun-ichiro itojun Hagino IP AH1 AH2 AH3 payload 18638f336835SJun-ichiro itojun Haginowe do it incrementally. As a result, we get crypto checksums like below: 18648f336835SJun-ichiro itojun Hagino AH3 has checksum against "IP AH3' payload". 18658f336835SJun-ichiro itojun Hagino where AH3' = AH3 with checksum field filled with 0. 18668f336835SJun-ichiro itojun Hagino AH2 has checksum against "IP AH2' AH3 payload". 18678f336835SJun-ichiro itojun Hagino AH1 has checksum against "IP AH1' AH2 AH3 payload", 18688f336835SJun-ichiro itojun HaginoAlso note that AH3 has the smallest sequence number, and AH1 has the largest 18698f336835SJun-ichiro itojun Haginosequence number. 18708f336835SJun-ichiro itojun Hagino 187133841545SHajimu UMEMOTOTo avoid traffic analysis on shorter packets, ESP output logic supports 187233841545SHajimu UMEMOTOrandom length padding. By setting net.inet.ipsec.esp_randpad (or 187333841545SHajimu UMEMOTOnet.inet6.ipsec6.esp_randpad) to positive value N, you can ask the kernel 187433841545SHajimu UMEMOTOto randomly pad packets shorter than N bytes, to random length smaller than 187533841545SHajimu UMEMOTOor equal to N. Note that N does not include ESP authentication data length. 187633841545SHajimu UMEMOTOAlso note that the random padding is not included in TCP segment 187733841545SHajimu UMEMOTOsize computation. Negative value will turn off the functionality. 187893b03d5dSUlrich SpörleinRecommended value for N is like 128, or 256. If you use a too big number 187993b03d5dSUlrich Spörleinas N, you may experience inefficiency due to fragmented packets. 188033841545SHajimu UMEMOTO 18818f336835SJun-ichiro itojun Hagino4.4 IPComp handling 18828f336835SJun-ichiro itojun Hagino 18838f336835SJun-ichiro itojun HaginoIPComp stands for IP payload compression protocol. This is aimed for 18848f336835SJun-ichiro itojun Haginopayload compression, not the header compression like PPP VJ compression. 18858f336835SJun-ichiro itojun HaginoThis may be useful when you are using slow serial link (say, cell phone) 18868f336835SJun-ichiro itojun Haginowith powerful CPU (well, recent notebook PCs are really powerful...). 18878f336835SJun-ichiro itojun HaginoThe protocol design of IPComp is very similar to IPsec, though it was 18888f336835SJun-ichiro itojun Haginodefined separately from IPsec itself. 18898f336835SJun-ichiro itojun Hagino 18908f336835SJun-ichiro itojun HaginoHere are some points to be noted: 18918f336835SJun-ichiro itojun Hagino- IPComp is treated as part of IPsec protocol suite, and SPI and 18928f336835SJun-ichiro itojun Hagino CPI space is unified. Spec says that there's no relationship 18938f336835SJun-ichiro itojun Hagino between two so they are assumed to be separate in specs. 18948f336835SJun-ichiro itojun Hagino- IPComp association (IPCA) is kept in SAD. 18958f336835SJun-ichiro itojun Hagino- It is possible to use well-known CPI (CPI=2 for DEFLATE for example), 18968f336835SJun-ichiro itojun Hagino for outbound/inbound packet, but for indexing purposes one element from 18978f336835SJun-ichiro itojun Hagino SPI/CPI space will be occupied anyway. 18988f336835SJun-ichiro itojun Hagino- pfkey is modified to support IPComp. However, there's no official 18998f336835SJun-ichiro itojun Hagino SA type number assignment yet. Portability with other IPComp 19008f336835SJun-ichiro itojun Hagino stack is questionable (anyway, who else implement IPComp on UN*X?). 19018f336835SJun-ichiro itojun Hagino- Spec says that IPComp output processing must be performed before AH/ESP 19028f336835SJun-ichiro itojun Hagino output processing, to achieve better compression ratio and "stir" data 19038f336835SJun-ichiro itojun Hagino stream before encryption. The most meaningful processing order is: 19048f336835SJun-ichiro itojun Hagino (1) compress payload by IPComp, (2) encrypt payload by ESP, then (3) attach 19058f336835SJun-ichiro itojun Hagino authentication data by AH. 19068f336835SJun-ichiro itojun Hagino However, with manual SPD setting, you are able to violate the ordering 19078f336835SJun-ichiro itojun Hagino (KAME code is too generic, maybe). Also, it is just okay to use IPComp 19088f336835SJun-ichiro itojun Hagino alone, without AH/ESP. 19098f336835SJun-ichiro itojun Hagino- Though the packet size can be significantly decreased by using IPComp, no 19108f336835SJun-ichiro itojun Hagino special consideration is made about path MTU (spec talks nothing about MTU 19118f336835SJun-ichiro itojun Hagino consideration). IPComp is designed for serial links, not ethernet-like 19128f336835SJun-ichiro itojun Hagino medium, it seems. 19138f336835SJun-ichiro itojun Hagino- You can change compression ratio on outbound packet, by changing 19148f336835SJun-ichiro itojun Hagino deflate_policy in sys/netinet6/ipcomp_core.c. You can also change outbound 19158f336835SJun-ichiro itojun Hagino history buffer size by changing deflate_window_out in the same source code. 19168f336835SJun-ichiro itojun Hagino (should it be sysctl accessible, or per-SAD configurable?) 19178f336835SJun-ichiro itojun Hagino- Tunnel mode IPComp is not working right. KAME box can generate tunnelled 19188f336835SJun-ichiro itojun Hagino IPComp packet, however, cannot accept tunneled IPComp packet. 19198f336835SJun-ichiro itojun Hagino- You can negotiate IPComp association with racoon IKE daemon. 19208f336835SJun-ichiro itojun Hagino- KAME code does not attach Adler32 checksum to compressed data. 19218f336835SJun-ichiro itojun Hagino see ipsec wg mailing list discussion in Jan 2000 for details. 19228f336835SJun-ichiro itojun Hagino 19238f336835SJun-ichiro itojun Hagino4.5 Conformance to RFCs and IDs 192480d21dc4SYoshinobu Inoue 192580d21dc4SYoshinobu InoueThe IPsec code in the kernel conforms (or, tries to conform) to the 192680d21dc4SYoshinobu Inouefollowing standards: 192780d21dc4SYoshinobu Inoue "old IPsec" specification documented in rfc182[5-9].txt 192833841545SHajimu UMEMOTO "new IPsec" specification documented in: 1929f88fe57eSHajimu UMEMOTO rfc240[1-6].txt rfc241[01].txt rfc2451.txt rfc3602.txt 19308f336835SJun-ichiro itojun Hagino IPComp: 19318f336835SJun-ichiro itojun Hagino RFC2393: IP Payload Compression Protocol (IPComp) 193233841545SHajimu UMEMOTOIKE specifications (rfc240[7-9].txt) are implemented in userland 193333841545SHajimu UMEMOTOas "racoon" IKE daemon. 193480d21dc4SYoshinobu Inoue 193580d21dc4SYoshinobu InoueCurrently supported algorithms are: 193680d21dc4SYoshinobu Inoue old IPsec AH 193780d21dc4SYoshinobu Inoue null crypto checksum (no document, just for debugging) 193880d21dc4SYoshinobu Inoue keyed MD5 with 128bit crypto checksum (rfc1828.txt) 193980d21dc4SYoshinobu Inoue keyed SHA1 with 128bit crypto checksum (no document) 194080d21dc4SYoshinobu Inoue HMAC MD5 with 128bit crypto checksum (rfc2085.txt) 194180d21dc4SYoshinobu Inoue HMAC SHA1 with 128bit crypto checksum (no document) 1942492528c0SHajimu UMEMOTO HMAC RIPEMD160 with 128bit crypto checksum (no document) 194380d21dc4SYoshinobu Inoue old IPsec ESP 194480d21dc4SYoshinobu Inoue null encryption (no document, similar to rfc2410.txt) 194580d21dc4SYoshinobu Inoue DES-CBC mode (rfc1829.txt) 194680d21dc4SYoshinobu Inoue new IPsec AH 194780d21dc4SYoshinobu Inoue null crypto checksum (no document, just for debugging) 194880d21dc4SYoshinobu Inoue keyed MD5 with 96bit crypto checksum (no document) 194980d21dc4SYoshinobu Inoue keyed SHA1 with 96bit crypto checksum (no document) 195080d21dc4SYoshinobu Inoue HMAC MD5 with 96bit crypto checksum (rfc2403.txt 195180d21dc4SYoshinobu Inoue HMAC SHA1 with 96bit crypto checksum (rfc2404.txt) 1952743eee66SSUZUKI Shinsuke HMAC SHA2-256 with 96bit crypto checksum (draft-ietf-ipsec-ciph-sha-256-00.txt) 195333841545SHajimu UMEMOTO HMAC SHA2-384 with 96bit crypto checksum (no document) 195433841545SHajimu UMEMOTO HMAC SHA2-512 with 96bit crypto checksum (no document) 1955492528c0SHajimu UMEMOTO HMAC RIPEMD160 with 96bit crypto checksum (RFC2857) 1956b42ac57fSHajimu UMEMOTO AES XCBC MAC with 96bit crypto checksum (RFC3566) 195780d21dc4SYoshinobu Inoue new IPsec ESP 195880d21dc4SYoshinobu Inoue null encryption (rfc2410.txt) 195980d21dc4SYoshinobu Inoue DES-CBC with derived IV 196080d21dc4SYoshinobu Inoue (draft-ietf-ipsec-ciph-des-derived-01.txt, draft expired) 196180d21dc4SYoshinobu Inoue DES-CBC with explicit IV (rfc2405.txt) 196280d21dc4SYoshinobu Inoue 3DES-CBC with explicit IV (rfc2451.txt) 196380d21dc4SYoshinobu Inoue BLOWFISH CBC (rfc2451.txt) 196480d21dc4SYoshinobu Inoue CAST128 CBC (rfc2451.txt) 1965b42ac57fSHajimu UMEMOTO RIJNDAEL/AES CBC (rfc3602.txt) 1966743eee66SSUZUKI Shinsuke AES counter mode (rfc3686.txt) 1967b42ac57fSHajimu UMEMOTO 1968743eee66SSUZUKI Shinsuke each of the above can be combined with new IPsec AH schemes for 1969743eee66SSUZUKI Shinsuke ESP authentication. 19708f336835SJun-ichiro itojun Hagino IPComp 19718f336835SJun-ichiro itojun Hagino RFC2394: IP Payload Compression Using DEFLATE 197280d21dc4SYoshinobu Inoue 197380d21dc4SYoshinobu InoueThe following algorithms are NOT supported: 197480d21dc4SYoshinobu Inoue old IPsec AH 197580d21dc4SYoshinobu Inoue HMAC MD5 with 128bit crypto checksum + 64bit replay prevention 197680d21dc4SYoshinobu Inoue (rfc2085.txt) 197780d21dc4SYoshinobu Inoue keyed SHA1 with 160bit crypto checksum + 32bit padding (rfc1852.txt) 197880d21dc4SYoshinobu Inoue 19798f336835SJun-ichiro itojun HaginoThe key/policy management API is based on the following document, with fair 19808f336835SJun-ichiro itojun Haginoamount of extensions: 19818f336835SJun-ichiro itojun Hagino RFC2367: PF_KEY key management API 198280d21dc4SYoshinobu Inoue 19838f336835SJun-ichiro itojun Hagino4.6 ECN consideration on IPsec tunnels 198480d21dc4SYoshinobu Inoue 198580d21dc4SYoshinobu InoueKAME IPsec implements ECN-friendly IPsec tunnel, described in 19868f336835SJun-ichiro itojun Haginodraft-ietf-ipsec-ecn-02.txt. 198780d21dc4SYoshinobu InoueNormal IPsec tunnel is described in RFC2401. On encapsulation, 198880d21dc4SYoshinobu InoueIPv4 TOS field (or, IPv6 traffic class field) will be copied from inner 198980d21dc4SYoshinobu InoueIP header to outer IP header. On decapsulation outer IP header 199080d21dc4SYoshinobu Inouewill be simply dropped. The decapsulation rule is not compatible 199180d21dc4SYoshinobu Inouewith ECN, since ECN bit on the outer IP TOS/traffic class field will be 199280d21dc4SYoshinobu Inouelost. 199380d21dc4SYoshinobu InoueTo make IPsec tunnel ECN-friendly, we should modify encapsulation 199480d21dc4SYoshinobu Inoueand decapsulation procedure. This is described in 19958f336835SJun-ichiro itojun Haginodraft-ietf-ipsec-ecn-02.txt, chapter 3.3. 199680d21dc4SYoshinobu Inoue 199780d21dc4SYoshinobu InoueKAME IPsec tunnel implementation can give you three behaviors, by setting 199880d21dc4SYoshinobu Inouenet.inet.ipsec.ecn (or net.inet6.ipsec6.ecn) to some value: 199980d21dc4SYoshinobu Inoue- RFC2401: no consideration for ECN (sysctl value -1) 200080d21dc4SYoshinobu Inoue- ECN forbidden (sysctl value 0) 200180d21dc4SYoshinobu Inoue- ECN allowed (sysctl value 1) 200280d21dc4SYoshinobu InoueNote that the behavior is configurable in per-node manner, not per-SA manner 20038f336835SJun-ichiro itojun Hagino(draft-ietf-ipsec-ecn-02 wants per-SA configuration, but it looks too much 20048f336835SJun-ichiro itojun Haginofor me). 200580d21dc4SYoshinobu Inoue 200680d21dc4SYoshinobu InoueThe behavior is summarized as follows (see source code for more detail): 200780d21dc4SYoshinobu Inoue 200880d21dc4SYoshinobu Inoue encapsulate decapsulate 200980d21dc4SYoshinobu Inoue --- --- 201080d21dc4SYoshinobu InoueRFC2401 copy all TOS bits drop TOS bits on outer 201180d21dc4SYoshinobu Inoue from inner to outer. (use inner TOS bits as is) 201280d21dc4SYoshinobu Inoue 201380d21dc4SYoshinobu InoueECN forbidden copy TOS bits except for ECN drop TOS bits on outer 201480d21dc4SYoshinobu Inoue (masked with 0xfc) from inner (use inner TOS bits as is) 201580d21dc4SYoshinobu Inoue to outer. set ECN bits to 0. 201680d21dc4SYoshinobu Inoue 201780d21dc4SYoshinobu InoueECN allowed copy TOS bits except for ECN use inner TOS bits with some 201880d21dc4SYoshinobu Inoue CE (masked with 0xfe) from change. if outer ECN CE bit 201980d21dc4SYoshinobu Inoue inner to outer. is 1, enable ECN CE bit on 202080d21dc4SYoshinobu Inoue set ECN CE bit to 0. the inner. 202180d21dc4SYoshinobu Inoue 202280d21dc4SYoshinobu InoueGeneral strategy for configuration is as follows: 202380d21dc4SYoshinobu Inoue- if both IPsec tunnel endpoint are capable of ECN-friendly behavior, 202480d21dc4SYoshinobu Inoue you'd better configure both end to "ECN allowed" (sysctl value 1). 202580d21dc4SYoshinobu Inoue- if the other end is very strict about TOS bit, use "RFC2401" 202680d21dc4SYoshinobu Inoue (sysctl value -1). 202780d21dc4SYoshinobu Inoue- in other cases, use "ECN forbidden" (sysctl value 0). 202880d21dc4SYoshinobu InoueThe default behavior is "ECN forbidden" (sysctl value 0). 202980d21dc4SYoshinobu Inoue 203080d21dc4SYoshinobu InoueFor more information, please refer to: 20318f336835SJun-ichiro itojun Hagino draft-ietf-ipsec-ecn-02.txt 203280d21dc4SYoshinobu Inoue RFC2481 (Explicit Congestion Notification) 203380d21dc4SYoshinobu Inoue KAME sys/netinet6/{ah,esp}_input.c 203480d21dc4SYoshinobu Inoue 203580d21dc4SYoshinobu Inoue(Thanks goes to Kenjiro Cho <kjc@csl.sony.co.jp> for detailed analysis) 203680d21dc4SYoshinobu Inoue 20378f336835SJun-ichiro itojun Hagino4.7 Interoperability 20388f336835SJun-ichiro itojun Hagino 20398f336835SJun-ichiro itojun HaginoIPsec, IPComp (in kernel) and IKE (in userland as "racoon") has been tested 20408f336835SJun-ichiro itojun Haginoat several interoperability test events, and it is known to interoperate 20418f336835SJun-ichiro itojun Haginowith many other implementations well. Also, KAME IPsec has quite wide 20428f336835SJun-ichiro itojun Haginocoverage for IPsec crypto algorithms documented in RFC (we do not cover 20438f336835SJun-ichiro itojun Haginoalgorithms with intellectual property issues, though). 204480d21dc4SYoshinobu Inoue 204580d21dc4SYoshinobu InoueHere are (some of) platforms we have tested IPsec/IKE interoperability 204633841545SHajimu UMEMOTOin the past, no particular order. Note that both ends (KAME and 20478f336835SJun-ichiro itojun Haginoothers) may have modified their implementation, so use the following 20488f336835SJun-ichiro itojun Haginolist just for reference purposes. 2049743eee66SSUZUKI Shinsuke 6WIND, ACC, Allied-telesis, Altiga, Ashley-laurent (vpcom.com), 2050743eee66SSUZUKI Shinsuke BlueSteel, CISCO IOS, Checkpoint FW-1, Compaq Tru54 UNIX 2051743eee66SSUZUKI Shinsuke X5.1B-BL4, Cryptek, Data Fellows (F-Secure), Ericsson, 2052743eee66SSUZUKI Shinsuke F-Secure VPN+ 5.40, Fitec, Fitel, FreeS/WAN, HITACHI, HiFn, 2053743eee66SSUZUKI Shinsuke IBM AIX 5.1, III, IIJ (fujie stack), Intel Canada, Intel 2054743eee66SSUZUKI Shinsuke Packet Protect, MEW NetCocoon, MGCS, Microsoft WinNT/2000/XP, 2055743eee66SSUZUKI Shinsuke NAI PGPnet, NEC IX5000, NIST (linux IPsec + plutoplus), 2056743eee66SSUZUKI Shinsuke NetLock, Netoctave, Netopia, Netscreen, Nokia EPOC, Nortel 2057743eee66SSUZUKI Shinsuke GatewayController/CallServer 2000 (not released yet), 2058743eee66SSUZUKI Shinsuke NxNetworks, OpenBSD isakmpd on OpenBSD, Oullim information 2059743eee66SSUZUKI Shinsuke technologies SECUREWORKS VPN gateway 3.0, Pivotal, RSA, 2060743eee66SSUZUKI Shinsuke Radguard, RapidStream, RedCreek, Routerware, SSH, SecGo 2061743eee66SSUZUKI Shinsuke CryptoIP v3, Secure Computing, Soliton, Sun Solaris 8, 2062743eee66SSUZUKI Shinsuke TIS/NAI Gauntret, Toshiba, Trilogy AdmitOne 2.6, Trustworks 2063743eee66SSUZUKI Shinsuke TrustedClient v3.2, USAGI linux, VPNet, Yamaha RT series, 2064743eee66SSUZUKI Shinsuke ZyXEL 206580d21dc4SYoshinobu Inoue 20668f336835SJun-ichiro itojun HaginoHere are (some of) platforms we have tested IPComp/IKE interoperability 20678f336835SJun-ichiro itojun Haginoin the past, in no particular order. 2068743eee66SSUZUKI Shinsuke Compaq, IRE, SSH, NetLock, FreeS/WAN, F-Secure VPN+ 5.40 206933841545SHajimu UMEMOTO 207033841545SHajimu UMEMOTOVPNC (vpnc.org) provides IPsec conformance tests, using KAME and OpenBSD 207133841545SHajimu UMEMOTOIPsec/IKE implementations. Their test results are available at 207233841545SHajimu UMEMOTOhttp://www.vpnc.org/conformance.html, and it may give you more idea 207333841545SHajimu UMEMOTOabout which implementation interoperates with KAME IPsec/IKE implementation. 207480d21dc4SYoshinobu Inoue 2075f88fe57eSHajimu UMEMOTO4.8 Operations with IPsec tunnel mode 2076f88fe57eSHajimu UMEMOTO 2077f88fe57eSHajimu UMEMOTOFirst of all, IPsec tunnel is a very hairy thing. It seems to do a neat thing 2078f88fe57eSHajimu UMEMOTOlike VPN configuration or secure remote accesses, however, it comes with lots 2079f88fe57eSHajimu UMEMOTOof architectural twists. 2080f88fe57eSHajimu UMEMOTO 2081f88fe57eSHajimu UMEMOTORFC2401 defines IPsec tunnel mode, within the context of IPsec. RFC2401 2082f88fe57eSHajimu UMEMOTOdefines tunnel mode packet encapsulation/decapsulation on its own, and 2083f88fe57eSHajimu UMEMOTOdoes not refer other tunnelling specifications. Since RFC2401 advocates 2084f88fe57eSHajimu UMEMOTOfilter-based SPD database matches, it would be natural for us to implement 208593b03d5dSUlrich SpörleinIPsec tunnel mode as filters - not as pseudo interfaces. 2086f88fe57eSHajimu UMEMOTO 2087f88fe57eSHajimu UMEMOTOThere are some people who are trying to separate IPsec "tunnel mode" from 2088f88fe57eSHajimu UMEMOTOthe IPsec itself. They would like to implement IPsec transport mode only, 2089f88fe57eSHajimu UMEMOTOand combine it with tunneling pseudo devices. The prime example is found 2090f88fe57eSHajimu UMEMOTOin draft-touch-ipsec-vpn-01.txt. However, if you really define pseudo 2091f88fe57eSHajimu UMEMOTOinterfaces separately from IPsec, IKE daemons would need to negotiate 2092f88fe57eSHajimu UMEMOTOtransport mode SAs, instead of tunnel mode SAs. Therefore, we cannot 2093f88fe57eSHajimu UMEMOTOreally mix RFC2401-based interpretation and draft-touch-ipsec-vpn-01.txt 2094f88fe57eSHajimu UMEMOTOinterpretation. 2095f88fe57eSHajimu UMEMOTO 2096f88fe57eSHajimu UMEMOTOThe KAME stack implements can be configured in two ways. You may need 2097f88fe57eSHajimu UMEMOTOto recompile your kernel to switch the behavior. 209893b03d5dSUlrich Spörlein- RFC2401 IPsec tunnel mode approach (4.8.1) 2099f88fe57eSHajimu UMEMOTO- draft-touch-ipsec-vpn approach (4.8.2) 2100f88fe57eSHajimu UMEMOTO Works in all kernel configuration, but racoon(8) may not interoperate. 2101f88fe57eSHajimu UMEMOTO 2102f88fe57eSHajimu UMEMOTOThere are pros and cons on these approaches: 2103f88fe57eSHajimu UMEMOTO 2104f88fe57eSHajimu UMEMOTORFC2401 IPsec tunnel mode (filter-like) approach 2105f88fe57eSHajimu UMEMOTO PRO: SPD lookup fits nicely with packet filters (if you integrate them) 2106f88fe57eSHajimu UMEMOTO CON: cannot run routing daemons across IPsec tunnels 2107f88fe57eSHajimu UMEMOTO CON: it is very hard to control source address selection on originating 2108f88fe57eSHajimu UMEMOTO cases 2109f88fe57eSHajimu UMEMOTO ???: IPv6 scope zone is kept the same 2110f88fe57eSHajimu UMEMOTOdraft-touch-ipsec-vpn (transportmode + Pseudo-interface) approach 2111f88fe57eSHajimu UMEMOTO PRO: run routing daemons across IPsec tunnels 2112f88fe57eSHajimu UMEMOTO PRO: source address selection can be done normally, by looking at 2113f88fe57eSHajimu UMEMOTO IPsec tunnel pseudo devices 2114f88fe57eSHajimu UMEMOTO CON: on outbound, possibility of infinite loops if routing setup 2115f88fe57eSHajimu UMEMOTO is wrong 2116f88fe57eSHajimu UMEMOTO CON: due to differences in encap/decap logic from RFC2401, it may not 2117f88fe57eSHajimu UMEMOTO interoperate with very picky RFC2401 implementations 2118f88fe57eSHajimu UMEMOTO (those who check TOS bits, for example) 2119f88fe57eSHajimu UMEMOTO CON: cannot negotiate IKE with other IPsec tunnel-mode devices 2120f88fe57eSHajimu UMEMOTO (the other end has to implement 2121f88fe57eSHajimu UMEMOTO ???: IPv6 scope zone is likely to be different from the real ethernet 2122f88fe57eSHajimu UMEMOTO interface 2123f88fe57eSHajimu UMEMOTO 2124f88fe57eSHajimu UMEMOTOThe recommendation is different depending on the situation you have: 2125f88fe57eSHajimu UMEMOTO- use draft-touch-ipsec-vpn if you have the control over the other end. 2126f88fe57eSHajimu UMEMOTO this one is the best in terms of simplicity. 2127f88fe57eSHajimu UMEMOTO- if the other end is normal IPsec device with RFC2401 implementation, 2128f88fe57eSHajimu UMEMOTO you need to use RFC2401, otherwise you won't be able to run IKE. 2129f88fe57eSHajimu UMEMOTO- use RFC2401 approach if you just want to forward packets back and forth 2130f88fe57eSHajimu UMEMOTO and there's no plan to use IPsec gateway itself as an originating device. 2131f88fe57eSHajimu UMEMOTO 2132f88fe57eSHajimu UMEMOTO4.8.1 RFC2401 IPsec tunnel mode approach 2133f88fe57eSHajimu UMEMOTO 2134f88fe57eSHajimu UMEMOTOTo configure your device as RFC2401 IPsec tunnel mode endpoint, you will 2135f88fe57eSHajimu UMEMOTOuse "tunnel" keyword in setkey(8) "spdadd" directives. Let us assume the 2136f88fe57eSHajimu UMEMOTOfollowing topology (A and B could be a network, like prefix/length): 2137f88fe57eSHajimu UMEMOTO 2138f88fe57eSHajimu UMEMOTO ((((((((((((The internet)))))))))))) 2139f88fe57eSHajimu UMEMOTO | | 2140f88fe57eSHajimu UMEMOTO |C (global) |D 2141f88fe57eSHajimu UMEMOTO your device peer's device 2142f88fe57eSHajimu UMEMOTO |A (private) |B 2143f88fe57eSHajimu UMEMOTO ==+===== VPN net ==+===== VPN net 2144f88fe57eSHajimu UMEMOTO 2145f88fe57eSHajimu UMEMOTOThe policy configuration directive is like this. You will need manual 2146f88fe57eSHajimu UMEMOTOSAs, or IKE daemon, for actual encryption: 2147f88fe57eSHajimu UMEMOTO 2148f88fe57eSHajimu UMEMOTO # setkey -c <<EOF 2149f88fe57eSHajimu UMEMOTO spdadd A B any -P out ipsec esp/tunnel/C-D/use; 2150f88fe57eSHajimu UMEMOTO spdadd B A any -P in ipsec esp/tunnel/D-C/use; 2151f88fe57eSHajimu UMEMOTO ^D 2152f88fe57eSHajimu UMEMOTO 2153f88fe57eSHajimu UMEMOTOThe inbound/outbound traffic is monitored/captured by SPD engine, which works 2154f88fe57eSHajimu UMEMOTOjust like packet filters. 2155f88fe57eSHajimu UMEMOTO 2156f88fe57eSHajimu UMEMOTOWith this, forwarding case should work flawlessly. However, troubles arise 2157f88fe57eSHajimu UMEMOTOwhen you have one of the following requirements: 2158f88fe57eSHajimu UMEMOTO- When you originate traffic from your VPN gateway device to VPN net on the 2159f88fe57eSHajimu UMEMOTO other end (like B), you want your source address to be A (private side) 2160f88fe57eSHajimu UMEMOTO so that the traffic would be protected by the policy. 2161f88fe57eSHajimu UMEMOTO With this approach, however, the source address selection logic follows 2162f88fe57eSHajimu UMEMOTO normal routing table, and C (global side) will be picked for any outgoing 2163f88fe57eSHajimu UMEMOTO traffic, even if the destination is B. The resulting packet will be like 2164f88fe57eSHajimu UMEMOTO this: 2165f88fe57eSHajimu UMEMOTO IP[C -> B] payload 2166f88fe57eSHajimu UMEMOTO and will not match the policy (= sent in clear). 2167f88fe57eSHajimu UMEMOTO- When you want to run routing protocols on top of the IPsec tunnel, it is 2168f88fe57eSHajimu UMEMOTO not possible. As there is no pseudo device that identifies the IPsec tunnel, 2169f88fe57eSHajimu UMEMOTO you cannot identify where the routing information came from. As a result, 2170f88fe57eSHajimu UMEMOTO you can't run routing daemons. 2171f88fe57eSHajimu UMEMOTO 2172f88fe57eSHajimu UMEMOTO4.8.2 draft-touch-ipsec-vpn approach 2173f88fe57eSHajimu UMEMOTO 2174f88fe57eSHajimu UMEMOTOWith this approach, you will configure gif(4) tunnel interfaces, as well as 2175f88fe57eSHajimu UMEMOTOIPsec transport mode SAs. 2176f88fe57eSHajimu UMEMOTO 2177f88fe57eSHajimu UMEMOTO # gifconfig gif0 C D 2178f88fe57eSHajimu UMEMOTO # ifconfig gif0 A B 2179f88fe57eSHajimu UMEMOTO # setkey -c <<EOF 2180f88fe57eSHajimu UMEMOTO spdadd C D any -P out ipsec esp/transport//use; 2181f88fe57eSHajimu UMEMOTO spdadd D C any -P in ipsec esp/transport//use; 2182f88fe57eSHajimu UMEMOTO ^D 2183f88fe57eSHajimu UMEMOTO 2184f88fe57eSHajimu UMEMOTOSince we have a pseudo-interface "gif0", and it affects the routes and 2185f88fe57eSHajimu UMEMOTOthe source address selection logic, we can have source address A, for 2186f88fe57eSHajimu UMEMOTOpackets originated by the VPN gateway to B (and the VPN cloud). 2187f88fe57eSHajimu UMEMOTOWe can also exchange routing information over the tunnel (gif0), as the tunnel 2188f88fe57eSHajimu UMEMOTOis represented as a pseudo interface (dynamic routes points to the 2189f88fe57eSHajimu UMEMOTOpseudo interface). 2190f88fe57eSHajimu UMEMOTO 2191f88fe57eSHajimu UMEMOTOThere is a big drawbacks, however; with this, you can use IKE if and only if 2192f88fe57eSHajimu UMEMOTOthe other end is using draft-touch-ipsec-vpn approach too. Since racoon(8) 2193f88fe57eSHajimu UMEMOTOgrabs phase 2 IKE proposals from the kernel SPD database, you will be 2194f88fe57eSHajimu UMEMOTOnegotiating IPsec transport-mode SAs with the other end, not tunnel-mode SAs. 2195f88fe57eSHajimu UMEMOTOAlso, since the encapsulation mechanism is different from RFC2401, you may not 2196f88fe57eSHajimu UMEMOTObe able to interoperate with a picky RFC2401 implementations - if the other 2197f88fe57eSHajimu UMEMOTOend checks certain outer IP header fields (like TOS), you will not be able to 2198f88fe57eSHajimu UMEMOTOinteroperate. 2199f88fe57eSHajimu UMEMOTO 2200f88fe57eSHajimu UMEMOTO 22018f336835SJun-ichiro itojun Hagino5. ALTQ 220280d21dc4SYoshinobu Inoue 2203743eee66SSUZUKI ShinsukeKAME kit includes ALTQ, which supports FreeBSD3, FreeBSD4, FreeBSD5 2204743eee66SSUZUKI ShinsukeNetBSD. OpenBSD has ALTQ merged into pf and its ALTQ code is not 2205743eee66SSUZUKI Shinsukecompatible with other platforms so that KAME's ALTQ is not used for 2206743eee66SSUZUKI ShinsukeOpenBSD. For BSD/OS, ALTQ does not work. 2207743eee66SSUZUKI ShinsukeALTQ in KAME supports IPv6. 220833841545SHajimu UMEMOTO(actually, ALTQ is developed on KAME repository since ALTQ 2.1 - Jan 2000) 220933841545SHajimu UMEMOTO 221033841545SHajimu UMEMOTOALTQ occupies single character device number. For FreeBSD, it is officially 221133841545SHajimu UMEMOTOallocated. For OpenBSD and NetBSD, we use the number which is not 221233841545SHajimu UMEMOTOcurrently allocated (will eventually get an official number). 221333841545SHajimu UMEMOTOThe character device is enabled for i386 architecture only. To enable and 221493b03d5dSUlrich Spörleincompile ALTQ-ready kernel for other architectures, take the following steps: 221533841545SHajimu UMEMOTO- assume that your architecture is FOOBAA. 221633841545SHajimu UMEMOTO- modify sys/arch/FOOBAA/FOOBAA/conf.c (or somewhere that defines cdevsw), 221733841545SHajimu UMEMOTO to include a line for ALTQ. look at sys/arch/i386/i386/conf.c for 221833841545SHajimu UMEMOTO example. The major number must be same as i386 case. 221933841545SHajimu UMEMOTO- copy kernel configuration file (like ALTQ.v6 or GENERIC.v6) from i386, 222033841545SHajimu UMEMOTO and modify accordingly. 222133841545SHajimu UMEMOTO- build a kernel. 222233841545SHajimu UMEMOTO- before building userland, change netbsd/{lib,usr.sbin,usr.bin}/Makefile 222333841545SHajimu UMEMOTO (or openbsd/foobaa) so that it will visit altq-related sub directories. 222480d21dc4SYoshinobu Inoue 2225743eee66SSUZUKI Shinsuke 2226743eee66SSUZUKI Shinsuke6. Mobile IPv6 222780d21dc4SYoshinobu Inoue 222833841545SHajimu UMEMOTO6.1 KAME node as correspondent node 222933841545SHajimu UMEMOTO 223033841545SHajimu UMEMOTODefault installation recognizes home address option (in destination 223193b03d5dSUlrich Spörleinoptions header). No sub-options are supported. Interaction with 223233841545SHajimu UMEMOTOIPsec, and/or 2292bis API, needs further study. 223333841545SHajimu UMEMOTO 223433841545SHajimu UMEMOTO6.2 KAME node as home agent/mobile node 223533841545SHajimu UMEMOTO 223633841545SHajimu UMEMOTOKAME kit includes Ericsson mobile-ip6 code. The integration is just started 223733841545SHajimu UMEMOTO(in Feb 2000), and we will need some more time to integrate it better. 223833841545SHajimu UMEMOTO 223933841545SHajimu UMEMOTOSee kame/mip6config/{QUICKSTART,README_MIP6.txt} for more details. 224033841545SHajimu UMEMOTO 224133841545SHajimu UMEMOTOThe Ericsson code implements revision 09 of the mobile-ip6 draft. There 224233841545SHajimu UMEMOTOare other implementations available: 224333841545SHajimu UMEMOTO NEC: http://www.6bone.nec.co.jp/mipv6/internal-dist/ (-13 draft) 224433841545SHajimu UMEMOTO SFC: http://neo.sfc.wide.ad.jp/~mip6/ (-13 draft) 224533841545SHajimu UMEMOTO 224633841545SHajimu UMEMOTO7. Coding style 224733841545SHajimu UMEMOTO 224833841545SHajimu UMEMOTOThe KAME developers basically do not make a bother about coding 224933841545SHajimu UMEMOTOstyle. However, there is still some agreement on the style, in order 225093b03d5dSUlrich Spörleinto make the distributed development smooth. 225133841545SHajimu UMEMOTO 2252f88fe57eSHajimu UMEMOTO- follow *BSD KNF where possible. note: there are multiple KNF standards. 225333841545SHajimu UMEMOTO- the tab character should be 8 columns wide (tabstops are at 8, 16, 24, ... 225433841545SHajimu UMEMOTO column). With vi, use ":set ts=8 sw=8". 2255f88fe57eSHajimu UMEMOTO With GNU Emacs 20 and later, the easiest way is to use the "bsd" style of 2256f88fe57eSHajimu UMEMOTO cc-mode with the variable "c-basic-offset" being 8; 2257f88fe57eSHajimu UMEMOTO (add-hook 'c-mode-common-hook 2258f88fe57eSHajimu UMEMOTO (function 2259f88fe57eSHajimu UMEMOTO (lambda () 2260f88fe57eSHajimu UMEMOTO (c-set-style "bsd") 2261f88fe57eSHajimu UMEMOTO (setq c-basic-offset 8) ; XXX for Emacs 20 only 2262f88fe57eSHajimu UMEMOTO ))) 2263f88fe57eSHajimu UMEMOTO The "bsd" style in GNU Emacs 21 sets the variable to 8 by default, 2264f88fe57eSHajimu UMEMOTO so the line marked by "XXX" is not necessary if you only use GNU 2265f88fe57eSHajimu UMEMOTO Emacs 21. 226633841545SHajimu UMEMOTO- each line should be within 80 characters. 226733841545SHajimu UMEMOTO- keep a single open/close bracket in a comment such as in the following 226833841545SHajimu UMEMOTO line: 226933841545SHajimu UMEMOTO putchar('('); /* ) */ 227033841545SHajimu UMEMOTO without this, some vi users would have a hard time to match a pair of 227133841545SHajimu UMEMOTO brackets. Although this type of bracket seems clumsy and is even 227233841545SHajimu UMEMOTO harmful for some other type of vi users and Emacs users, the 227333841545SHajimu UMEMOTO agreement in the KAME developers is to allow it. 227433841545SHajimu UMEMOTO- add the following line to the head of every KAME-derived file: 227533841545SHajimu UMEMOTO /* (dollar)KAME(dollar) */ 227633841545SHajimu UMEMOTO where "(dollar)" is the dollar character ($), and around "$" are tabs. 227733841545SHajimu UMEMOTO (this is for C. For other language, you should use its own comment 227833841545SHajimu UMEMOTO line.) 227993b03d5dSUlrich Spörlein Once committed to the CVS repository, this line will contain its 228033841545SHajimu UMEMOTO version number (see, for example, at the top of this file). This 228133841545SHajimu UMEMOTO would make it easy to report a bug. 228233841545SHajimu UMEMOTO- when creating a new file with the WIDE copyright, tap "make copyright.c" at 228333841545SHajimu UMEMOTO the top-level, and use copyright.c as a template. KAME RCS tag will be 228433841545SHajimu UMEMOTO included automatically. 228593b03d5dSUlrich Spörlein- when editing a third-party package, keep its own coding style as 228633841545SHajimu UMEMOTO much as possible, even if the style does not follow the items above. 2287f88fe57eSHajimu UMEMOTO- it is recommended to always wrap an expression containing 2288f88fe57eSHajimu UMEMOTO bitwise operators by parentheses, especially when the expression is 2289f88fe57eSHajimu UMEMOTO combined with relational operators, in order to avoid unintentional 2290f88fe57eSHajimu UMEMOTO mismatch of operators. Thus, we should write 2291f88fe57eSHajimu UMEMOTO if ((a & b) == 0) /* (A) */ 2292f88fe57eSHajimu UMEMOTO or 2293f88fe57eSHajimu UMEMOTO if (a & (b == 0)) /* (B) */ 2294f88fe57eSHajimu UMEMOTO instead of 2295f88fe57eSHajimu UMEMOTO if (a & b == 0) /* (C) */ 2296f88fe57eSHajimu UMEMOTO even if the programmer's intention was (C), which is equivalent to 2297f88fe57eSHajimu UMEMOTO (B) according to the grammar of the language C. 2298f88fe57eSHajimu UMEMOTO Thus, we should write a code to test if a bit-flag is set for a 2299f88fe57eSHajimu UMEMOTO given variable as follows: 2300f88fe57eSHajimu UMEMOTO if ((flag & FLAG_A) == 0) /* (D) the FLAG_A is NOT set */ 2301f88fe57eSHajimu UMEMOTO if ((flag & FLAG_A) != 0) /* (E) the FLAG_A is set */ 2302f88fe57eSHajimu UMEMOTO Some developers in the KAME project rather prefer the following style: 2303f88fe57eSHajimu UMEMOTO if (!(flag & FLAG_A)) /* (F) the FLAG_A is NOT set */ 2304f88fe57eSHajimu UMEMOTO if ((flag & FLAG_A)) /* (G) the FLAG_A is set */ 2305f88fe57eSHajimu UMEMOTO because it would be more intuitive in terms of the relationship 2306f88fe57eSHajimu UMEMOTO between the negation operator (!) and the semantics of the 2307f88fe57eSHajimu UMEMOTO condition. The KAME developers have discussed the style, and have 2308f88fe57eSHajimu UMEMOTO agreed that all the styles from (D) to (G) are valid. So, when you 2309f88fe57eSHajimu UMEMOTO see styles like (D) and (E) in the KAME code and feel a bit strange, 2310f88fe57eSHajimu UMEMOTO please just keep them. They are intentional. 2311f88fe57eSHajimu UMEMOTO- When inserting a separate block just to define some intra-block 2312f88fe57eSHajimu UMEMOTO variables, add the level of indentation as if the block was in a 2313f88fe57eSHajimu UMEMOTO control statement such as if-else, for, or while. For example, 2314f88fe57eSHajimu UMEMOTO foo () 2315f88fe57eSHajimu UMEMOTO { 2316f88fe57eSHajimu UMEMOTO int a; 2317f88fe57eSHajimu UMEMOTO 2318f88fe57eSHajimu UMEMOTO { 2319f88fe57eSHajimu UMEMOTO int internal_a; 2320f88fe57eSHajimu UMEMOTO ... 2321f88fe57eSHajimu UMEMOTO } 2322f88fe57eSHajimu UMEMOTO } 2323f88fe57eSHajimu UMEMOTO should be used, instead of 2324f88fe57eSHajimu UMEMOTO foo () 2325f88fe57eSHajimu UMEMOTO { 2326f88fe57eSHajimu UMEMOTO int a; 2327f88fe57eSHajimu UMEMOTO 2328f88fe57eSHajimu UMEMOTO { 2329f88fe57eSHajimu UMEMOTO int internal_a; 2330f88fe57eSHajimu UMEMOTO ... 2331f88fe57eSHajimu UMEMOTO } 2332f88fe57eSHajimu UMEMOTO } 2333f88fe57eSHajimu UMEMOTO- Do not use printf() or log() in the packet input path of the kernel code. 2334f88fe57eSHajimu UMEMOTO They can make the system vulnerable to packet flooding attacks (results in 2335f88fe57eSHajimu UMEMOTO /var overflow). 2336f88fe57eSHajimu UMEMOTO- (not a style issue) 2337f88fe57eSHajimu UMEMOTO To disable a module that is mistakenly imported (by CVS), just 2338f88fe57eSHajimu UMEMOTO remove the source tree in the repository. Note, however, that the 2339f88fe57eSHajimu UMEMOTO removal might annoy other developers who have already checked the 2340f88fe57eSHajimu UMEMOTO module out, so you should announce the removal as soon as possible. 2341f88fe57eSHajimu UMEMOTO Also, be 100% sure not to remove other modules. 234233841545SHajimu UMEMOTO 234333841545SHajimu UMEMOTOWhen you want to contribute something to the KAME project, and if *you 234433841545SHajimu UMEMOTOdo not mind* the agreement, it would be helpful for the project to 234533841545SHajimu UMEMOTOkeep these rules. Note, however, that we would never intend to force 234633841545SHajimu UMEMOTOyou to adopt our rules. We would rather regard your own style, 234733841545SHajimu UMEMOTOespecially when you have a policy about the style. 234880d21dc4SYoshinobu Inoue 2349f88fe57eSHajimu UMEMOTO 23502ea36b5dSBjoern A. Zeeb8. Policy on technology with intellectual property right restriction 2351f88fe57eSHajimu UMEMOTO 2352f88fe57eSHajimu UMEMOTOThere are quite a few IETF documents/whatever which has intellectual property 2353f88fe57eSHajimu UMEMOTOright (IPR) restriction. KAME's stance is stated below. 2354f88fe57eSHajimu UMEMOTO 2355f88fe57eSHajimu UMEMOTO The goal of KAME is to provide freely redistributable, BSD-licensed, 2356f88fe57eSHajimu UMEMOTO implementation of Internet protocol technologies. 2357f88fe57eSHajimu UMEMOTO For this purpose, we implement protocols that (1) do not need license 2358f88fe57eSHajimu UMEMOTO contract with IPR holder, and (2) are royalty-free. 2359f88fe57eSHajimu UMEMOTO The reason for (1) is, even if KAME contracts with the IPR holder in 2360f88fe57eSHajimu UMEMOTO question, the users of KAME stack (usually implementers of some other 2361f88fe57eSHajimu UMEMOTO codebase) would need to make a license contract with the IPR holder. 2362f88fe57eSHajimu UMEMOTO It would damage the "freely redistributable" status of KAME codebase. 2363f88fe57eSHajimu UMEMOTO 2364f88fe57eSHajimu UMEMOTO By doing so KAME is (implicitly) trying to advocate no-license-contract, 2365f88fe57eSHajimu UMEMOTO royalty-free, release of IPRs. 2366f88fe57eSHajimu UMEMOTO 2367f88fe57eSHajimu UMEMOTONote however, as documented in README, we do not guarantee that KAME code 2368f88fe57eSHajimu UMEMOTOis free of IPR infringement, you MUST check it if you are to integrate 2369f88fe57eSHajimu UMEMOTOKAME into your product (or whatever): 2370f88fe57eSHajimu UMEMOTO READ CAREFULLY: Several countries have legal enforcement for 2371f88fe57eSHajimu UMEMOTO export/import/use of cryptographic software. Check it before playing 237293b03d5dSUlrich Spörlein with the kit. We do not intend to be your legalese clearing house 2373f88fe57eSHajimu UMEMOTO (NO WARRANTY). If you intend to include KAME stack into your product, 2374f88fe57eSHajimu UMEMOTO you'll need to check if the licenses on each file fit your situations, 2375f88fe57eSHajimu UMEMOTO and/or possible intellectual property right issues. 2376f88fe57eSHajimu UMEMOTO 237780d21dc4SYoshinobu Inoue <end of IMPLEMENTATION> 2378