From fb419a9f7d983eec67d7994cc7c824dc436e09ac Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Tue, 25 Jun 2013 20:04:59 +0400 Subject: [PATCH] initial net-eth feature This one is also putting an end to an overly long lived hack named vm-net by replacing it with a bit more generic mechanism. --- features.in/net-eth/README | 1 + features.in/net-eth/config.mk | 9 ++++ .../net-eth/rootfs/image-scripts.d/50-net-eth | 50 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 features.in/net-eth/README create mode 100644 features.in/net-eth/config.mk create mode 100755 features.in/net-eth/rootfs/image-scripts.d/50-net-eth diff --git a/features.in/net-eth/README b/features.in/net-eth/README new file mode 100644 index 00000000..f5ef8036 --- /dev/null +++ b/features.in/net-eth/README @@ -0,0 +1 @@ +Эта фича позволяет задать конфигурацию Ethernet-интерфейсов. diff --git a/features.in/net-eth/config.mk b/features.in/net-eth/config.mk new file mode 100644 index 00000000..9c493b37 --- /dev/null +++ b/features.in/net-eth/config.mk @@ -0,0 +1,9 @@ +use/net-eth: use/net + @$(call add_feature) + @$(call xport,NET_ETH) + +# typical boilerplate +use/net-eth/dhcp: use/net-eth use/net/dhcp + @$(call add,NET_ETH,eth0:dhcp) + +# use e.g. eth0:static:10.0.0.2/24:10.0.0.1 for predefined static configuration diff --git a/features.in/net-eth/rootfs/image-scripts.d/50-net-eth b/features.in/net-eth/rootfs/image-scripts.d/50-net-eth new file mode 100755 index 00000000..714eaa02 --- /dev/null +++ b/features.in/net-eth/rootfs/image-scripts.d/50-net-eth @@ -0,0 +1,50 @@ +#!/bin/sh +# parse interface configuration tuples: +# iface:proto[:ipv4addr/netmask[:ipv4gw]] +# and write it down as intended + +fatal() { echo "error: $*" >&2; exit 1; } + +# simple etcnet configurations are also picked up by NM +if type -t NetworkManager >&/dev/null || + type -t connmand >&/dev/null; then + NMCTL=yes +else + NMCTL=no +fi + +IFACEDIR="/etc/net/ifaces" + +# uses global variables +write_iface() { + dir="$IFACEDIR/$iface" + mkdir -p "$dir" + case "$proto" in + dhcp) + ;; + static) + [ -n "$ipv4addr" ] || fatal "ipv4addr missing" + echo "$ipv4addr" > "$dir/ipv4address" + [ -z "$ipv4gw" ] || + echo "default via $ipv4gw" > "$dir/ipv4route" + ;; + *) + fatal "unknown proto value: $proto" + ;; + esac + { + echo "TYPE=eth" + echo "DISABLED=no" + echo "BOOTPROTO=$proto" + echo "NM_CONTROLLED=$NMCTL" + echo "USE_IFPLUGD=yes" + } > "$dir/options" +} + +[ -z "$GLOBAL_NET_ETH" ] || + echo "$GLOBAL_NET_ETH" \ + | tr ' ' '\n' \ + | while IFS=':' read iface proto ipv4addr ipv4gw; do + [ -n "$iface" -a -n "$proto" ] || continue + write_iface + done