]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
Add a script to create VLAN interfaces (on console).
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 24 Aug 2012 13:58:38 +0000 (15:58 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 24 Aug 2012 13:58:38 +0000 (15:58 +0200)
config/cfgroot/ethernet-vlans [new file with mode: 0644]
config/rootfiles/common/armv5tel/initscripts
config/rootfiles/common/i586/initscripts
config/rootfiles/core/62/filelists/files
lfs/configroot
lfs/initscripts
src/initscripts/init.d/network-vlans [new file with mode: 0755]

diff --git a/config/cfgroot/ethernet-vlans b/config/cfgroot/ethernet-vlans
new file mode 100644 (file)
index 0000000..08cb36a
--- /dev/null
@@ -0,0 +1,9 @@
+#GREEN_PARENT_DEV="eth0"
+#GREEN_VLAN_ID=20
+#GREEN_MAC_ADDRESS="00:11:22:33:44:55"
+#BLUE_PARENT_DEV="green0"
+#BLUE_VLAN_ID=30
+#BLUE_MAC_ADDRESS="00:22:33:44:55:66"
+#ORANGE_PARENT_DEV="green0"
+#ORANGE_VLAN_ID=40
+#ORANGE_MAC_ADDRESS="00:33:44:55:66:77"
index c23416692c08c73017adb4ee2f8c58a5098d16bd..ccb7bfb33892b6452fc92150cc1870f08e8d8d61 100644 (file)
@@ -58,6 +58,7 @@ etc/rc.d/init.d/mountkernfs
 #etc/rc.d/init.d/mysql
 #etc/rc.d/init.d/netsnmpd
 etc/rc.d/init.d/network
+etc/rc.d/init.d/network-vlans
 #etc/rc.d/init.d/networking
 etc/rc.d/init.d/networking/any
 etc/rc.d/init.d/networking/blue
@@ -213,6 +214,7 @@ etc/rc.d/rcsysinit.d/S70console
 etc/rc.d/rcsysinit.d/S75firstsetup
 etc/rc.d/rcsysinit.d/S80localnet
 etc/rc.d/rcsysinit.d/S90sysctl
+etc/rc.d/rcsysinit.d/S91network-vlans
 etc/rc.d/rc3.d/S15fireinfo
 #etc/sysconfig
 etc/sysconfig/createfiles
index 63cd27448d99517a9da87a59da5ebc0bf4f31783..653060f72237f611564af15cb6ab931c45189556 100644 (file)
@@ -59,6 +59,7 @@ etc/rc.d/init.d/mountkernfs
 #etc/rc.d/init.d/mysql
 #etc/rc.d/init.d/netsnmpd
 etc/rc.d/init.d/network
+etc/rc.d/init.d/network-vlans
 #etc/rc.d/init.d/networking
 etc/rc.d/init.d/networking/any
 etc/rc.d/init.d/networking/blue
@@ -216,6 +217,7 @@ etc/rc.d/rcsysinit.d/S70console
 etc/rc.d/rcsysinit.d/S75firstsetup
 etc/rc.d/rcsysinit.d/S80localnet
 etc/rc.d/rcsysinit.d/S90sysctl
+etc/rc.d/rcsysinit.d/S91network-vlans
 etc/rc.d/rc3.d/S15fireinfo
 #etc/sysconfig
 etc/sysconfig/createfiles
index 731daa03c902a2bf4234d167796b726a1c4f5709..34f0d1620a691926b7e0b00a62d81130006cef25 100644 (file)
@@ -1,5 +1,8 @@
 etc/system-release
 etc/issue
+etc/rc.d/init.d/network-vlans
+etc/rc.d/rcsysinit.d/S91network-vlans
 srv/web/ipfire/cgi-bin/connections.cgi
 usr/lib/gconv
+var/ipfire/ethernet/vlans
 var/ipfire/outgoing/bin/outgoingfw.pl
index f35361469d4d99212339ebacc7b067d90bcc3817..90f5afab6cffe0b1e28f134216ca4e61e67ce3f7 100644 (file)
@@ -100,6 +100,7 @@ $(TARGET) :
        cp $(DIR_SRC)/config/cfgroot/time-settings              $(CONFIG_ROOT)/time/settings
        cp $(DIR_SRC)/config/cfgroot/logging-settings           $(CONFIG_ROOT)/logging/settings
        cp $(DIR_SRC)/config/cfgroot/useragents                 $(CONFIG_ROOT)/proxy/advanced
+       cp $(DIR_SRC)/config/cfgroot/ethernet-vlans             $(CONFIG_ROOT)/ethernet/vlans
        cp $(DIR_SRC)/langs/list                                        $(CONFIG_ROOT)/langs/
 
        # Oneliner configfiles
index 03cec8031cb64c15d2f19ff611d5795f6672d07c..7210c0d2ea8e97a9dc216fb4372766c22d33fbb8 100644 (file)
@@ -170,6 +170,7 @@ $(TARGET) :
        ln -sf ../init.d/firstsetup  /etc/rc.d/rcsysinit.d/S75firstsetup
        ln -sf ../init.d/localnet    /etc/rc.d/rcsysinit.d/S80localnet
        ln -sf ../init.d/sysctl      /etc/rc.d/rcsysinit.d/S90sysctl
+       ln -sf ../init.d/network-vlans /etc/rc.d/rcsysinit.d/S91network-vlans
 
        ln -sf ../../dnsmasq /etc/rc.d/init.d/networking/red.up/05-RS-dnsmasq
        ln -sf ../../firewall /etc/rc.d/init.d/networking/red.up/20-RL-firewall
diff --git a/src/initscripts/init.d/network-vlans b/src/initscripts/init.d/network-vlans
new file mode 100755 (executable)
index 0000000..88733e6
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/bash
+############################################################################
+#                                                                          #
+# This file is part of the IPFire Firewall.                                #
+#                                                                          #
+# IPFire is free software; you can redistribute it and/or modify           #
+# it under the terms of the GNU General Public License as published by     #
+# the Free Software Foundation; either version 2 of the License, or        #
+# (at your option) any later version.                                      #
+#                                                                          #
+# IPFire is distributed in the hope that it will be useful,                #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of           #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
+# GNU General Public License for more details.                             #
+#                                                                          #
+# You should have received a copy of the GNU General Public License        #
+# along with IPFire; if not, write to the Free Software                    #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA #
+#                                                                          #
+# Copyright (C) 2012 IPFire Team <info@ipfire.org>                         #
+#                                                                          #
+############################################################################
+
+CONFIG_FILE="/var/ipfire/ethernet/vlans"
+
+# Skip immediately if no configuration file has been found.
+[ -e "${CONFIG_FILE}" ] || exit 0
+
+eval $(readhash ${CONFIG_FILE})
+
+# This is start or stop.
+action=${1}
+
+for interface in green0 blue0 orange0; do
+       case "${interface}" in
+               green*)
+                       PARENT_DEV=${GREEN_PARENT_DEV}
+                       VLAN_ID=${GREEN_VLAN_ID}
+                       MAC_ADDRESS=${GREEN_MAC_ADDRESS}
+                       ;;
+               blue*)
+                       PARENT_DEV=${BLUE_PARENT_DEV}
+                       VLAN_ID=${BLUE_VLAN_ID}
+                       MAC_ADDRESS=${BLUE_MAC_ADDRESS}
+                       ;;
+               orange*)
+                       PARENT_DEV=${ORANGE_PARENT_DEV}
+                       VLAN_ID=${ORANGE_VLAN_ID}
+                       MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
+                       ;;
+       esac
+
+       case "${action}" in
+               start)
+                       # Check if the interface does already exists.
+                       # If so, we skip creating it.
+                       if [ -d "/sys/class/net/${interface}" ]; then
+                               echo "Interface ${interface} already exists."
+                               continue
+                       fi
+
+                       # Check if the parent interface exists.
+                       if [ -z "${PARENT_DEV}" ] || [ ! -d "/sys/class/net/${PARENT_DEV}" ]; then
+                               echo "${interface}: Parent device is not set or does not exist: ${PARENT_DEV}"
+                               continue
+                       fi
+
+                       if [ -z "${VLAN_ID}" ]; then
+                               echo "${interface}: You did not set the VLAN ID."
+                               continue
+                       fi
+
+                       echo "Creating VLAN interface ${interface}..."
+                       vconfig add ${PARENT_DEV} ${VLAN_ID}
+                       ip link set ${PARENT_DEV}.${VLAN_ID} name ${interface}
+
+                       if [ -n "${MAC_ADDRESS}" ]; then
+                               ip link set ${interface} address ${MAC_ADDRESS}
+                       fi
+
+                       # Bring up the parent device.
+                       ip link set ${PARENT_DEV} up
+                       ;;
+
+               stop)
+                       if [ ! -e "/proc/net/vlan/${interface}" ]; then
+                               echo "${interface} is not a VLAN interface. Skipping."
+                               continue
+                       fi
+
+                       echo "Removing VLAN interface ${interface}..."
+                       ip link set ${interface} down
+                       vconfig rem ${interface}
+                       ;;
+               
+               *)
+                       echo "Invalid action: ${action}"
+                       exit 1
+                       ;;
+       esac
+done