From f493db289078e3ed122bad9f5fd3c9ad5516f789 Mon Sep 17 00:00:00 2001 From: Wade Carpenter Date: Thu, 23 Dec 2010 16:10:55 -0800 Subject: [PATCH] Fix some issues with VLAN configuration ... - Re-use ethernet_up / ethernet_down - Fix interface references in /var/run/network/ by requiring INTERFACE definition in profile - Load required variables in network 'load_profile()' function --- examples/ethernet-iproute-vlan | 1 + src/connections/ethernet-iproute-vlan | 104 +++++---------------------------- src/network | 3 + 3 files changed, 19 insertions(+), 89 deletions(-) diff --git a/examples/ethernet-iproute-vlan b/examples/ethernet-iproute-vlan index 47778a2..36da3cc 100644 --- a/examples/ethernet-iproute-vlan +++ b/examples/ethernet-iproute-vlan @@ -1,6 +1,7 @@ CONNECTION="ethernet-iproute-vlan" DESCRIPTION="A more versatile static ethernet connection using iproute and VLAN" PHYS_INTERFACE="eth0" +INTERFACE="eth0.7" VLAN="7" FLAG="false" IP="static" diff --git a/src/connections/ethernet-iproute-vlan b/src/connections/ethernet-iproute-vlan index 61649ee..c0a733a 100644 --- a/src/connections/ethernet-iproute-vlan +++ b/src/connections/ethernet-iproute-vlan @@ -1,18 +1,17 @@ #! /bin/bash . /usr/lib/network/network -INTERFACE=$PHYS_INTERFACE.$VLAN - error() { - err_append "$*" + report_fail "$*" ip addr flush $INTERFACE &>/dev/null quirk "nodown" || ip link set $INTERFACE down &>/dev/null exit 1 } -ethernet_up() { - load_profile $1 +ethernet_iproute_vlan_up() { + PROFILE="$1" + load_profile "$PROFILE" if [[ ! -e /sys/class/net/$PHYS_INTERFACE ]]; then if ! echo "$PHYS_INTERFACE"|grep ":"; then @@ -25,7 +24,7 @@ ethernet_up() { if ! modprobe 8021q; then echo "Kernel-Module 8021q could not be loaded" fi - if [[! -e /usr/sbin/vconfig ]]; then + if [[ ! -e /usr/sbin/vconfig ]]; then error "vconfig is not executable" fi if ! vconfig add $PHYS_INTERFACE $VLAN; then @@ -36,99 +35,26 @@ ethernet_up() { fi fi - ip link set $INTERFACE up sleep 1 - - if ip link show $PHYS_INTERFACE|grep -q "NO-CARRIER"; then - err_append "No connection" - return 1 - fi - - if checkyesno ${AUTH8021X:-no}; then - . ${SUBR_DIR}/8021x - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" - [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired" - - start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_OPTS" - if ! wpa_check "$INTERFACE"; then - ip link set $INTERFACE down - return 1 - fi - fi - - case $IP in - dhcp) - # Clear remaining pid files. - rm -f /var/run/dhcpcd-${INTERFACE}.{pid,cache} >/dev/null 2>&1 - - # If using own dns, tell dhcpcd to NOT replace resolv.conf - [[ -n "$DNS" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS" - - if ! dhcpcd -qL -t ${DHCP_TIMEOUT:-10} $DHCP_OPTIONS $INTERFACE; then - error "DHCP IP lease attempt failed" - fi - ;; - static) - if [[ -n "$ADDR" ]]; then - if ! ip addr add ${ADDR}/24 brd + dev $INTERFACE; then - error "Could not configure interface" - fi - fi - if [[ -n "$GATEWAY" ]]; then - if ! ip route add default via $GATEWAY; then - error "Adding gateway failed" - fi - fi - ;; - *) - error "Profile error: IP must be either 'dhcp' or 'static'" - ;; - esac - - if [[ -n "$IPCFG" ]]; then - for line in "${IPCFG[@]}"; do - if ! ip $line; then - error "Could not configure interface" - fi - done - fi - - # Set hostname - if [[ -n "$HOSTNAME" ]]; then - if ! hostname $HOSTNAME; then - error "Cannot set hostname" - fi - fi - - # Generate a new resolv.conf - if [[ -n "$DNS" ]]; then - : >/etc/resolv.conf - [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf - [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf - - if [[ -n "$DNS" ]]; then - for dns in ${DNS[@]}; do - echo "nameserver $dns" >>/etc/resolv.conf - done - fi + if ! "$CONN_DIR/ethernet" up "$PROFILE"; then + error "VLAN-Interface up failed" + return 1 fi return 0 } -ethernet_down() { - load_profile $1 +ethernet_iproute_vlan_down() { + PROFILE="$1" + load_profile "$PROFILE" - if [[ "$IP" == "dhcp" ]]; then - if [[ -f /var/run/dhcpcd-${INTERFACE}.pid ]]; then - dhcpcd -qx $INTERFACE - fi + if ! "$CONN_DIR/ethernet" down "$PROFILE"; then + error "VLAN-Interface down failed" + return 1 fi - ip addr flush $INTERFACE quirk "nodown" || vconfig rem $INTERFACE - } -ethernet_$1 $2 +ethernet_iproute_vlan_$1 $2 exit $? # vim: set ts=4 et sw=4: diff --git a/src/network b/src/network index faf00ba..d0eef44 100644 --- a/src/network +++ b/src/network @@ -15,6 +15,7 @@ load_profile() fi report_debug "Loading profile $1" INTERFACE=$(. "$PROFILE_DIR/$1"; echo "$INTERFACE") + CONNECTION=$(. "$PROFILE_DIR/$1"; echo "$CONNECTION") report_debug "Configuring interface $INTERFACE" if [[ ! $CONNECTION == "ethernet-iproute-vlan" ]] ; then if [[ -z "$INTERFACE" ]]; then @@ -22,10 +23,12 @@ load_profile() return 1 fi else + PHYS_INTERFACE=$(. "$PROFILE_DIR/$1"; echo "$PHYS_INTERFACE") if [[ -z "$PHYS_INTERFACE" ]]; then report_err "Profile missing an physical interface to configure" return 1 fi + VLAN=$(. "$PROFILE_DIR/$1"; echo "$VLAN") if [[ -z "$VLAN" ]]; then report_err "Profile missing an VLAN to configure" return 1 -- 1.7.3.4