From patchwork Mon Nov 9 07:38:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 541628 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 83F141402D0 for ; Mon, 9 Nov 2015 18:41:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=DgU4OxYn; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 504D54BD6D; Mon, 9 Nov 2015 08:40:16 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bhDWp3nE_xTb; Mon, 9 Nov 2015 08:40:16 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 18DFD4BD6F; Mon, 9 Nov 2015 08:39:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D8EF14BD2D for ; Mon, 9 Nov 2015 08:39:49 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bPyg9s6dqBxt for ; Mon, 9 Nov 2015 08:39:49 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by theia.denx.de (Postfix) with ESMTPS id 681F64BCB7 for ; Mon, 9 Nov 2015 08:39:41 +0100 (CET) Received: by pasz6 with SMTP id z6so196365271pas.2 for ; Sun, 08 Nov 2015 23:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kl0FwmCdyQJr4hTA4Kpo7n4UCW75zpYnFi8G/CpgaLc=; b=DgU4OxYncSvPiNl4/P/26qaRneO52WbdbrRLjdup6Y6qugWYjh0nNVlw+CXNSyJZC9 gisagjnk7Y722TtnwSbCtPr0pD13HPc8qOK1h90CQaI6lefsVmVNIlJZP/i7hhe9C8lC 5hahgwcP2qE82l/RAvZnns0/+XVNM0yt+Vx5iSD9maF73ffJpJf0x1cvVBLBGL0fbHyI ISIBcP663ThYC9L50Wm2mmoko08gEnA5RCzKsPqxLtXW8J7Z6HRnZaWk/Le2lJ9C0IQs Z2QIspt0n/08inbXhWt9qGH768KqFNo+i/syb/fbfh9By57VA7+8YS7LTlhUBoVJ8es3 iwUQ== X-Received: by 10.68.57.137 with SMTP id i9mr28476451pbq.66.1447054780218; Sun, 08 Nov 2015 23:39:40 -0800 (PST) Received: from chrisp-dl.ws.atlnz.lc (2-163-36-202-static.alliedtelesis.co.nz. [202.36.163.2]) by smtp.gmail.com with ESMTPSA id so4sm14434198pbc.72.2015.11.08.23.39.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Nov 2015 23:39:39 -0800 (PST) From: Chris Packham To: u-boot@lists.denx.de, Joe Hershberger Date: Mon, 9 Nov 2015 20:38:51 +1300 Message-Id: <1447054736-27658-7-git-send-email-judge.packham@gmail.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: <1447054736-27658-1-git-send-email-judge.packham@gmail.com> References: <1447054736-27658-1-git-send-email-judge.packham@gmail.com> Cc: jp.tosoni@acksys.fr, hannah@marvell.com, Chris Packham , Angga Subject: [U-Boot] [RFC PATCH v2 06/11] net: IPv6 skeleton and environment variables X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Create net6.c and add CONFIG_NET6 to Kconfig/Makefile. Also add support for the following environment variables: - ip6addr - gateway6 - serverip6 Signed-off-by: Chris Packham --- Changes in v2: - Split environment variables from main implementation - remove "prefixlength6" environment variable. The prefix length is now set when specifying the address i.e. setenv ip6addr 2001:db8::1/64. include/env_callback.h | 8 +++++ include/env_flags.h | 9 +++++ net/Kconfig | 5 +++ net/Makefile | 1 + net/net6.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 net/net6.c diff --git a/include/env_callback.h b/include/env_callback.h index 90b95b5..97e245b 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -60,6 +60,13 @@ #define NET_CALLBACKS #endif +#ifdef CONFIG_NET6 +#define NET6_CALLBACKS \ + "ip6addr:ip6addr," \ + "serverip6:serverip6," +#else +#define NET6_CALLBACKS +#endif /* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. @@ -68,6 +75,7 @@ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ NET_CALLBACKS \ + NET6_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \ diff --git a/include/env_flags.h b/include/env_flags.h index 8823fb9..bf93f15 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -65,6 +65,14 @@ enum env_flags_varaccess { #define NET_FLAGS #endif +#ifdef CONFIG_NET6 +#define NET6_FLAGS \ + "ip6addr:s," \ + "serverip6:s," +#else +#define NET6_FLAGS +#endif + #ifndef CONFIG_ENV_OVERWRITE #define SERIAL_FLAGS "serial#:so," #else @@ -74,6 +82,7 @@ enum env_flags_varaccess { #define ENV_FLAGS_LIST_STATIC \ ETHADDR_FLAGS \ NET_FLAGS \ + NET6_FLAGS \ SERIAL_FLAGS \ CONFIG_ENV_FLAGS_LIST_STATIC diff --git a/net/Kconfig b/net/Kconfig index a44a783..bacd914 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -32,4 +32,9 @@ config NET_TFTP_VARS If unset, timeout and maximum are hard-defined as 1 second and 10 timouts per TFTP transfer. +config NET6 + bool "IPv6 support" + help + Support for IPv6 + endif # if NET diff --git a/net/Makefile b/net/Makefile index e9cc8ad..6da8019 100644 --- a/net/Makefile +++ b/net/Makefile @@ -20,3 +20,4 @@ obj-$(CONFIG_CMD_PING) += ping.o obj-$(CONFIG_CMD_RARP) += rarp.o obj-$(CONFIG_CMD_SNTP) += sntp.o obj-$(CONFIG_CMD_NET) += tftp.o +obj-$(CONFIG_NET6) += net6.o diff --git a/net/net6.c b/net/net6.c new file mode 100644 index 0000000..f778cef --- /dev/null +++ b/net/net6.c @@ -0,0 +1,89 @@ +/* + * Simple IPv6 network layer implementation. + * + * Based and/or adapted from the IPv4 network layer in net.[hc] + * + * (C) Copyright 2013 Allied Telesis Labs NZ + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include "ndisc.h" + +/* Our gateway's IPv6 address */ +struct in6_addr net_gateway6 = ZERO_IPV6_ADDR; +/* Our IPv6 addr (0 = unknown) */ +struct in6_addr net_ip6 = ZERO_IPV6_ADDR; +/* set server IPv6 addr (0 = unknown) */ +struct in6_addr net_server_ip6 = ZERO_IPV6_ADDR; +/* The prefix length of our network */ +u_int32_t net_prefix_length; + +static int on_ip6addr(const char *name, const char *value, enum env_op op, + int flags) +{ + char *v, *s, *strcopy; + int i; + + if (flags & H_PROGRAMMATIC) + return 0; + + if (op == env_op_delete) { + net_prefix_length = 0; + net_copy_ip6(&net_ip6, &net_null_addr_ip6); + return 0; + } + + strcopy = strdup(value); + if (strcopy == NULL) + return -1; + + net_prefix_length = 128; + i = 0; + s = strcopy; + while (s) { + v = strsep(&s, "/"); + if (!v) + break; + + switch (i++) { + case 0: + string_to_ip6(v, &net_ip6); + break; + case 1: + net_prefix_length = simple_strtoul(v, NULL, 10); + break; + default: + break; + } + } + free(strcopy); + + return 0; +} +U_BOOT_ENV_CALLBACK(ip6addr, on_ip6addr); + +static int on_gatewayip6(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + return string_to_ip6(value, &net_gateway6); +} +U_BOOT_ENV_CALLBACK(gatewayip6, on_gatewayip6); + +static int on_serverip6(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + return string_to_ip6(value, &net_server_ip6); +} +U_BOOT_ENV_CALLBACK(serverip6, on_serverip6);