{"id":810234,"url":"http://patchwork.ozlabs.org/api/patches/810234/?format=json","web_url":"http://patchwork.ozlabs.org/project/lede/patch/20d72a4907c5ebf06ca1f54ae79efc2e4000e4d5.1504634305.git.mschiffer@universe-factory.net/","project":{"id":54,"url":"http://patchwork.ozlabs.org/api/projects/54/?format=json","name":"LEDE development","link_name":"lede","list_id":"lede-dev.lists.infradead.org","list_email":"lede-dev@lists.infradead.org","web_url":"http://lede-project.org/","scm_url":"","webscm_url":"http://git.lede-project.org/","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20d72a4907c5ebf06ca1f54ae79efc2e4000e4d5.1504634305.git.mschiffer@universe-factory.net>","list_archive_url":null,"date":"2017-09-05T18:02:37","name":"[LEDE-DEV,uclient] uclient-http: fix Host: header for literal IPv6 addresses","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"7258cf3991afe2653a16f848f1265408ae4d2c6d","submitter":{"id":23467,"url":"http://patchwork.ozlabs.org/api/people/23467/?format=json","name":"Matthias Schiffer","email":"mschiffer@universe-factory.net"},"delegate":{"id":150341,"url":"http://patchwork.ozlabs.org/api/users/150341/?format=json","username":"neocturne","first_name":"Matthias","last_name":"Schiffer","email":"mschiffer@universe-factory.net"},"mbox":"http://patchwork.ozlabs.org/project/lede/patch/20d72a4907c5ebf06ca1f54ae79efc2e4000e4d5.1504634305.git.mschiffer@universe-factory.net/mbox/","series":[{"id":1620,"url":"http://patchwork.ozlabs.org/api/series/1620/?format=json","web_url":"http://patchwork.ozlabs.org/project/lede/list/?series=1620","date":"2017-09-05T18:02:37","name":"[LEDE-DEV,uclient] uclient-http: fix Host: header for literal IPv6 addresses","version":1,"mbox":"http://patchwork.ozlabs.org/series/1620/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/810234/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/810234/checks/","tags":{},"related":[],"headers":{"Return-Path":"<lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133;\n\thelo=bombadil.infradead.org;\n\tenvelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"RuuszN8h\"; \n\tdkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmvjR6K7cz9sD9\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 04:03:55 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dpICH-00045U-EB; Tue, 05 Sep 2017 18:03:37 +0000","from chaos.universe-factory.net ([31.24.148.19])\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dpIBr-0003z2-QT\n\tfor lede-dev@lists.infradead.org; Tue, 05 Sep 2017 18:03:14 +0000","from localhost.localdomain (unknown [IPv6:fd1b:c28a:2fd6::2])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby chaos.universe-factory.net (Postfix) with ESMTPSA id 76B29187353\n\tfor <lede-dev@lists.infradead.org>;\n\tTue,  5 Sep 2017 20:02:42 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help:\n\tList-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id:Date:To:\n\tFrom:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:\n\tResent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:\n\tList-Owner; bh=efezO3YL04h4oBxbd168D2zOb/W7eigOlN0YR4dS+s0=;\n\tb=RuuszN8hUrwygT\n\tXiNNHImt3Jq5MZUTiL6KINSDw8uwVzO81TLjVINPXvdbELOQE+cTPTGlryUr5m47O1jcQdTreDJfJ\n\tSxuhrJfP6/lIRHSM9NGLDwk/dSzCEKvyr3FuB+4ZvRtRiw6TRKJoBk1lVS1Kivhxjid346V9UJj/M\n\tvrgdAYKsKLplW38tY3yErrqqcne9IBopNNP4J/N+4IWwmaE4FmR3WXmqzM6hFGkGrH9pHWRh/lsiJ\n\t/XIZ+5YQ3hisvNYRSmXriBYEnCUslB47J4D5y8/4cIp3KTYJ2jqsUBJtWcA+m0yyT28nepIZeLIQe\n\txJl2FNAD2AKxn+QIndCQ==;","From":"Matthias Schiffer <mschiffer@universe-factory.net>","To":"lede-dev@lists.infradead.org","Date":"Tue,  5 Sep 2017 20:02:37 +0200","Message-Id":"<20d72a4907c5ebf06ca1f54ae79efc2e4000e4d5.1504634305.git.mschiffer@universe-factory.net>","X-Mailer":"git-send-email 2.14.1","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20170905_110312_040602_495294FD ","X-CRM114-Status":"GOOD (  11.10  )","X-Spam-Score":"-1.9 (-)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details:   (-1.9 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay\n\tdomain\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]","Subject":"[LEDE-DEV] [PATCH uclient] uclient-http: fix Host: header for\n\tliteral IPv6 addresses","X-BeenThere":"lede-dev@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<lede-dev.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/lede-dev>,\n\t<mailto:lede-dev-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/lede-dev/>","List-Post":"<mailto:lede-dev@lists.infradead.org>","List-Help":"<mailto:lede-dev-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/lede-dev>,\n\t<mailto:lede-dev-request@lists.infradead.org?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"Lede-dev\" <lede-dev-bounces@lists.infradead.org>","Errors-To":"lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"For literal IPv6 addresses, the host header must have the form\n\n  Host: [...]\n\nincluding the square brackets, as it may also contain a port. Some\nwebservers ignore the missing brackets, while others will return error 400.\n\nIPv6 addresses are determined by searching for ':' characters in the host,\nas neither IPv4 addresses nor DNS names can contain colons. An alternative\nwould be to add a flag to the uclient_url struct; but as this struct is\nexposed in public headers, such a change could be considered an ABI change,\nmaking a backport difficult.\n\nSigned-off-by: Matthias Schiffer <mschiffer@universe-factory.net>\n---\n\nTested and working fine, but I'd still like some feedback on my approach to\nfixing this. Eventually, we might want to move struct uclient_url to an\ninternal header to avoid exposing it as API/ABI.\n\n uclient-http.c | 12 +++++++++---\n 1 file changed, 9 insertions(+), 3 deletions(-)","diff":"diff --git a/uclient-http.c b/uclient-http.c\nindex ac9d50f..ef8de98 100644\n--- a/uclient-http.c\n+++ b/uclient-http.c\n@@ -20,6 +20,7 @@\n #include <ctype.h>\n #include <unistd.h>\n #include <stdint.h>\n+#include <string.h>\n #include <fcntl.h>\n \n #include <libubox/ustream.h>\n@@ -562,6 +563,7 @@ uclient_http_send_headers(struct uclient_http *uh)\n \tstruct uclient_url *url = uh->uc.url;\n \tstruct blob_attr *cur;\n \tenum request_type req_type = uh->req_type;\n+\tbool literal_ipv6;\n \tint rem;\n \n \tif (uh->state >= HTTP_STATE_HEADERS_SENT)\n@@ -570,11 +572,15 @@ uclient_http_send_headers(struct uclient_http *uh)\n \tif (uh->uc.proxy_url)\n \t\turl = uh->uc.proxy_url;\n \n+\tliteral_ipv6 = strchr(url->host, ':');\n+\n \tustream_printf(uh->us,\n \t\t\"%s %s HTTP/1.1\\r\\n\"\n-\t\t\"Host: %s%s%s\\r\\n\",\n-\t\trequest_types[req_type],\n-\t\turl->location, url->host,\n+\t\t\"Host: %s%s%s%s%s\\r\\n\",\n+\t\trequest_types[req_type], url->location,\n+\t\tliteral_ipv6 ? \"[\" : \"\",\n+\t\turl->host,\n+\t\tliteral_ipv6 ? \"]\" : \"\",\n \t\turl->port ? \":\" : \"\",\n \t\turl->port ? url->port : \"\");\n \n","prefixes":["LEDE-DEV","uclient"]}