From owner-freebsd-net@FreeBSD.ORG Tue Sep 24 18:58:19 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2001:1900:2254:206a::19:2]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 18BC61F2 for ; Tue, 24 Sep 2013 18:58:19 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from butcher-nb.yandex.net (hub.freebsd.org [IPv6:2001:1900:2254:206c::16:88]) by mx2.freebsd.org (Postfix) with ESMTP id 9C366C77 for ; Tue, 24 Sep 2013 18:58:18 +0000 (UTC) Message-ID: <5241DFC9.6070802@FreeBSD.org> Date: Tue, 24 Sep 2013 22:54:01 +0400 From: "Andrey V. Elsukov" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: freebsd-net@freebsd.org Subject: [RFC] Don't embed scope zone id into IPv6 addresses X-Enigmail-Version: 1.4.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Sep 2013 18:58:19 -0000 Hi All, As many of you know, FreeBSD uses IPv6 stack derived from the KAME project. The KAME project was started so long ago, when many RFCs and standards weren't written yet. Also the struct sockaddr_in6 did not have the sin6_scope_id field and link-local addresses had to be disambiguated in an implementation-dependent manner. The KAME-specific workaround to this problem was use of an embedded form. I.e. in the kernel we keep scope zone id in the second 16-bit field of IPv6 address structure. Also we have a bunch of helper functions in the kernel to maintain embedded form of addresses: in6_setscope(), in6_clearscope(), sa6_recoverscope(), sa6_embedscope(). Conversion to embedded form and back can be done several times per packet [1]. This is basically useless operations. And it is worth mentioning that some operations with embedded form use locking, and also changing an address on packet flow has bad effect for caching. My proposal is remove this code from our kernel. From my investigation this needs the following changes: 1. Do not keep link-local addresses in the routing tables. We already have list and hash table with all IPv6 addresses, so we can use sin6_scope_id to disambiguate an address and determine outgoing interface. 2. Add scope zone id field to the struct in_endpoints and hc_metrics. This also leads to changes in the PCB code. 3. Rework ip6_input * Don't use auxiliary data * Use ifaddr hash to check against own addresses * Remove route and lle lookups from input path 4. Rework ip6_output * Introduce new IPV6_USEROIF flag and use ifpp argument to specify outgoing interface * Rework route lookup part of ip6_output() to properly handle the fact, that now we don't keep routes for link-local addresses. It is the biggest changes, also there are many of small changes that should be done. I would like to see your opinions about first point. [1] http://tinyurl.com/figure2-12 -- WBR, Andrey V. Elsukov