[PATCH] remove zone identifier for IPv6 link-local addresses

Rob Landley rob at landley.net
Fri Jun 26 20:43:03 UTC 2009


On Friday 26 June 2009 04:31:57 Fabian Hugelshofer wrote:
> Hi all,
>
> IPv6 knows scoped address types i.e. link and site local addresses. Link
> local addresses can have a scope identifier to specify the
> interface/link an address is valid on (e.g. fe80::1%eth0). This scope
> identifier is only valid on a single node.
>
> RFC 4007 says that the scope identifier must not be sent across the
> wire, unless every node agrees on the semantics (which is not the case
> for link-local zones). Apache e.g. rejects HTTP requests with a scope
> identifier in the host header (see
> https://issues.apache.org/bugzilla/show_bug.cgi?id=35122).
>
> This patch removes the scope identifier from the HTTP request, whereas
> it remains in the structure used to connect to the server.
>
> Signed-off-by: <hugelshofer2006 at gmx.ch>
>
> Regards,
>
> Fabian
> diff --git a/networking/wget.c b/networking/wget.c
> index ca3acd0..852e628 100644
> --- a/networking/wget.c
> +++ b/networking/wget.c
> @@ -340,6 +340,57 @@ static void parse_url(char *src_url, struct host_info
> *h) sp = h->host;
>  }
>
> +/* RFC 4007 sais that the scope identifier MUST NOT be sent accross the
> wire, + * unless all nodes agree on the semantic. Apache e.g. regards zone
> identifiers + * in the Host header as invalid requests, see
> + * https://issues.apache.org/bugzilla/show_bug.cgi?id=35122
> + */
> +static void strip_ipv6_scope(struct host_info *h)
> +{
> +	char *scope, *cp;
> +
> +	/* Remove the IPv6 zone identifier from the host address,
> +	 * ugly parsing like in str2sockaddr() */
> +
> +	if (!ENABLE_FEATURE_IPV6) {
> +		/* only for ipv6 */
> +		return;
> +	}

Um, that's not how ENABLE stuff works.  We're not just trying to disable 
functionality, we're trying to save storage and memory by making the binary 
smaller.

>        parse_url(argv[optind], &target);
>-       server.host = target.host;
>+       server.host = xstrdup(target.host);
>        server.port = target.port;
>+       strip_ipv6_scope(&target);

Here, try this instead:

parse_url(argv[optind], &target);
server.port = target.port;
if (ENABLE_FEATURE_IPV6) {
  server.host = xstrdup(target.host);
  strip_ipv6_scope(&target);
} else server.host = target.host;

Now you can remove the if (ENABLE) from the actual strip_ipv6_scope function, 
and it should only get called when the feature is enabled.

The point of doing that is that the compiler can tell at compile time whether 
the ENABLE macro is set to 0 or 1, meaning it can do dead code elimination on 
code that can never be called, meaning the entire strip_ipv6_scope() function 
can be discarded when it's not configured in (since it's static, and therefore 
couldn't be called from outside this file), and won't take up space for 
everybody else.

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds


More information about the busybox mailing list