From patchwork Mon Oct 20 14:14:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeremy Rosen X-Patchwork-Id: 401139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id 4486F14003E for ; Tue, 21 Oct 2014 01:15:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 75A9494D41; Mon, 20 Oct 2014 14:15:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PBbYRzTqLVYg; Mon, 20 Oct 2014 14:15:01 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 2F4C094D88; Mon, 20 Oct 2014 14:15:01 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id C3D0F1C151C for ; Mon, 20 Oct 2014 14:14:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id BBCA5317AB for ; Mon, 20 Oct 2014 14:14:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JGqqmYbZVUBN for ; Mon, 20 Oct 2014 14:14:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by silver.osuosl.org (Postfix) with ESMTPS id CF8472FC90 for ; Mon, 20 Oct 2014 14:14:56 +0000 (UTC) Received: by mail-wi0-f174.google.com with SMTP id h11so8032277wiw.7 for ; Mon, 20 Oct 2014 07:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=lXE7CNuwTMXtbJUklhaFravLi44wLLY05OdIS01vQcA=; b=c9ejXSop6i6S2c36BLcqmvizk2Ij/4cax8yPsP4tikRgIAtxyLFsw+1yXtLLubAPK7 mpmE60WbR7Qmlndv/pjxZvK2PetjDE3HnDKvkN7itAR/VaOp5zl5y7JJ5/T0rU05lbuD RhSF5kp+x2/FVhubktk0gmmxTS7ZLqwfknSrklO9KpCmBbjSOC5Id3dVfKhltedwvRIC /nMGXZSld8yN3O6Y8q2ZBAJqZulOsqmsE6acXbb04v572RwaTWeHDiRfaOY8n0e4kmrS 7yZ+xoym4OxERrLK6inhiFdFi2BxvZhOryyeBPSLogNiuvudyEqdZ5f08GF572TdF3Dz EwSg== X-Received: by 10.180.211.173 with SMTP id nd13mr18003969wic.71.1413814494970; Mon, 20 Oct 2014 07:14:54 -0700 (PDT) Received: from pcrosen.daviel.openwide.fr. ([193.56.60.161]) by mx.google.com with ESMTPSA id pe8sm9787794wic.3.2014.10.20.07.14.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Oct 2014 07:14:54 -0700 (PDT) From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rosen?= To: buildroot@buildroot.org Date: Mon, 20 Oct 2014 16:14:46 +0200 Message-Id: <1413814486-10716-1-git-send-email-jeremy.rosen@openwide.fr> X-Mailer: git-send-email 2.1.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH v2] set simple network setup via the system configuration submenu X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch allows the setup of simple /etc/network/interfaces via the configuration menus instead of using an overlay * supports manual ipv4 configuration * supports dhcp configuration Signed-off-by: Jérémy Rosen --- This patch is here to avoid having to do an overlay for the most common cases (ipv4 with fixed IP or DHCP) It can be made more complex (second network if, support ipv6) depending on what people want/need, but I want to keep it simple. The point is to avoid having to tweak overlays to change stuff that everybody needs to change for prototyping When networkd is enabled, this option will be deactivated. Networkd support is tricky to get right on first approximation. It can be added later if it is deemed usefull --- v1->v2 : * moved to TARGET_FINALIZE * removed support for lo. It should always be on. * reworked default parameters --- support/scripts/generate-interfaces-ifconfig.sh | 70 +++++++++++++++++++++++++ system/Config.in | 66 +++++++++++++++++++++++ system/system.mk | 5 ++ 3 files changed, 141 insertions(+) create mode 100755 support/scripts/generate-interfaces-ifconfig.sh diff --git a/support/scripts/generate-interfaces-ifconfig.sh b/support/scripts/generate-interfaces-ifconfig.sh new file mode 100755 index 0000000..873e824 --- /dev/null +++ b/support/scripts/generate-interfaces-ifconfig.sh @@ -0,0 +1,70 @@ +#!/bin/sh + + +#extract our parameters from the config file +# see comment in support/scripts/mkusers at to why we can't simply source +for PARAM in \ + BR2_SIMPLE_NETWORK \ + BR2_SIMPLE_NETWORK_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_NAME \ + BR2_SIMPLE_NETWORK_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + + +function do_generate_interfaces +{ + echo "# interface file auto-generated by buildroot" + echo + echo "auto lo" + echo "iface lo inet loopback" + echo + + if [ $BR2_SIMPLE_NETWORK ] ; then + if [ -z $BR2_SIMPLE_NETWORK_NAME ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + echo "auto $BR2_SIMPLE_NETWORK_NAME" + if [ $BR2_SIMPLE_NETWORK_IPV4_DHCP ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet dhcp" + elif [ $BR2_SIMPLE_NETWORK_IPV4_MANUAL ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet static" + + if [ -z $BR2_SIMPLE_NETWORK_IPV4_ADDRESS ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_ADDRESS not set 1>&2 + exit 1 + fi + echo " address $BR2_SIMPLE_NETWORK_IPV4_ADDRESS" + + + if [ -z $BR2_SIMPLE_NETWORK_IPV4_NETMASK ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_NETMASK not set 1>&2 + exit 1 + fi + echo " netmask $BR2_SIMPLE_NETWORK_IPV4_NETMASK" + + if [ $BR2_SIMPLE_NETWORK_IPV4_BROADCAST ] ; then + echo " broadcast $BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + if [ $BR2_SIMPLE_NETWORK_IPV4_GATEWAY ] ; then + echo " gateway $BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + fi + fi + fi +} + +mkdir -p $TARGET_DIR/etc/network/ +do_generate_interfaces > $TARGET_DIR/etc/network/interfaces diff --git a/system/Config.in b/system/Config.in index 2465f79..92ee705 100644 --- a/system/Config.in +++ b/system/Config.in @@ -324,6 +324,72 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW endif # BR2_ROOTFS_SKELETON_DEFAULT +comment 'Simple network configuration is not supported with networkd' + depends on BR2_PACKAGE_SYSTEMD_NETWORKD + +config BR2_SIMPLE_NETWORK + bool "Generate simple network configuration" + depends on !BR2_PACKAGE_SYSTEMD_NETWORKD + default n + help + Let buildroot create a simple network configuration for a network + interface. This will generate the corresponding lines in + /etc/network/interfaces which is used by ifupdown. + + The simple network configuration only supports a single network + interface using a static or DHCP-allocated IPv4 address. If you + need something more complicate, create your own configuration file + in the BR2_ROOTFS_OVERLAY. + + +if BR2_SIMPLE_NETWORK + + +config BR2_SIMPLE_NETWORK_NAME + string "name of the physical network interface" + default "eth0" + help + The name used to recognise the network interface as reported + by the kernel + +choice + prompt "Configuration type" + default BR2_SIMPLE_NETWORK_DHCP + help + The type of configuration to use for the physical interface + +config BR2_SIMPLE_NETWORK_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_IPV4_MANUAL + bool "IPv4 with static IP address" + help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_IPV4_ADDRESS + string "IP Address of the network interface" + default "0.0.0.0" + +config BR2_SIMPLE_NETWORK_IPV4_NETMASK + string "Netmask of the network interface" + default "255.255.255.255" + +config BR2_SIMPLE_NETWORK_IPV4_BROADCAST + string "Broadcast Address of the network interface" + +config BR2_SIMPLE_NETWORK_IPV4_GATEWAY + string "Address of the gateway for the network interface" + +endif # BR2_SIMPLE_NETWORK_IPV4_MANUAL + +endif # BR2_SIMPLE_NETWORK + + + config BR2_TARGET_TZ_INFO bool "Install timezone info" # No timezone for musl; only for uClibc or (e)glibc. diff --git a/system/system.mk b/system/system.mk index 5802e2d..af2641c 100644 --- a/system/system.mk +++ b/system/system.mk @@ -38,6 +38,11 @@ ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) TARGETS += host-mkpasswd endif +define SIMPLE_NETWORK + $(TOPDIR)/support/scripts/generate-interfaces-ifconfig.sh $(TARGET_DIR) +endef +TARGET_FINALIZE_HOOKS += SIMPLE_NETWORK + ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y) define SYSTEM_ROOT_PASSWD