]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
Worked on networking stuff.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 4 Mar 2009 12:58:34 +0000 (13:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 4 Mar 2009 12:58:34 +0000 (13:58 +0100)
Added help to network command.
Some more important changes.

src/initscripts/networking/functions
src/initscripts/networking/hooks/ethernet
src/initscripts/networking/hooks/vlan
src/initscripts/networking/net-hotplug
src/initscripts/networking/port
src/initscripts/networking/zone
src/network/network

index 5dd1bec52a79993d05f6c208ec3bf37cd51b93da..ba0c74757c447bb083066de810477cf402c8f090 100644 (file)
@@ -53,19 +53,24 @@ function get_device_by_mac_and_vid() {
        local i
        local VID
        local DEVICE
-       for i in $(cat /proc/net/vlan/config 2>/dev/null); do
-               awk -F'|' '{ print $2 $3 }' | read DEVICE VID PARENT
-               if [ -n "${VID}" ] || [ -n "${DEVICE}" ]; then
-                       continue
-               fi
-               if [ "${vid}" = "${VID}" ] && [ "$(macify ${PARENT})" = "${mac}" ]; then
-                       echo "${DEVICE}"
-                       return 0
-               fi
-       done
+       grep '|' < /proc/net/vlan/config 2>/dev/null | sed "s/|//g" | \
+               while read DEVICE VID PARENT; do
+                       if [ "${vid}" = "${VID}" ] && [ "$(macify ${PARENT})" = "${mac}" ]; then
+                               echo "${DEVICE}"
+                               return 0
+                       fi
+               done
        return 1
 }
 
+function get_device() {
+       if [ ${#@} -gt 1 ]; then
+               get_device_by_mac_and_vid $@
+       else
+               get_device_by_mac $@
+       fi
+}
+
 function get_mac_by_device() {
        local device
        device=$1
@@ -76,6 +81,10 @@ function get_mac_by_device() {
        return 1
 }
 
+function get_mac() {
+       get_mac_by_device $@
+}
+
 function devicify() {
        local device
        local mac
@@ -135,7 +144,23 @@ function bridge_devices() {
 }
 
 function zone_add_port() {
-       brctl addif ${1} ${2}
+       local zone
+       local port
+
+       zone=${1}
+       port=${2}
+
+       brctl addif ${zone} ${port}
+}
+
+function zone_del_port() {
+       local zone
+       local port
+
+       zone=${1}
+       port=${2}
+
+       brctl delif ${zone} ${port}
 }
 
 function all_zones() {
index 72842d16598fc696a3f1025efbdf24e6a9b1db23..8823f9959e8268bf1883f6cb9709629029c31fdf 100644 (file)
@@ -41,8 +41,16 @@ EOF
                        ${CONFIG_PORTS}/${port}/ethernet
        ;;
 
+       attach)
+               zone_add_port ${ZONE} $(get_device ${port})
+       ;;
+
+       detach)
+               zone_del_port ${ZONE} $(get_device ${port})
+       ;;
+
        *)
-               echo "Usage: ${0} [interface] {up|down|add|remove}"
+               echo "Usage: ${0} [interface] {up|down|add|remove|attach|detach}"
                exit 1
        ;;
 esac
index 907c72f0d3e1cfff131720fc8f5646ce297b9725..3647882e0dfe543d4318edc1c9d0570a29f22b32 100644 (file)
@@ -21,16 +21,20 @@ device=$(devicify ${port})
 
 case "${2}" in
        up)
-               modprobe 8021q
-               MESSAGE="Adding VLAN ${ID} to port ${port}..."
-               vconfig add ${device} ${ID} &>/dev/null
-               evaluate_retval
+               if ! get_device ${port} ${ID}; then
+                       modprobe 8021q
+                       MESSAGE="Adding VLAN ${ID} to port ${port}..."
+                       vconfig add ${device} ${ID} &>/dev/null
+                       evaluate_retval
+               fi
        ;;
 
        down)
-               MESSAGE="Removing VLAN ${ID} from port ${port}..."
-               vconfig rem ${device} ${ID} &>/dev/null
-               evaluate_retval
+               if get_device ${port} ${ID}; then
+                       MESSAGE="Removing VLAN ${ID} from port ${port}..."
+                       vconfig rem ${device} ${ID} &>/dev/null
+                       evaluate_retval
+               fi
        ;;
 
        add)
@@ -44,13 +48,23 @@ EOF
        ;;
 
        remove)
+               # Should we do this here? What about detaching?
+               CONFIG=${CONFIG_ZONES}/${ZONE}/port-${port}-vlan-${ID} ${0} ${port} down
                rm -f \
                        ${CONFIG_PORTS}/${port}/vlan-${ID} \
                        ${CONFIG_ZONES}/${ZONE}/port-${port}-vlan-${ID}
        ;;
 
+       attach)
+               zone_add_port ${ZONE} $(get_device ${port} ${ID})
+       ;;
+       
+       detach)
+               zone_del_port ${ZONE} $(get_device ${port} ${ID})
+       ;;
+
        *)
-               echo "Usage: ${0} [interface] {up|down|add|remove}"
+               echo "Usage: ${0} [interface] {up|down|add|remove|attach|detach}"
                exit 1
        ;;
 esac
index fd79681e5e59e1b9f69016484ea1f168080b7cc6..405eff231188102571f78e88575fda27109a723d 100644 (file)
@@ -25,9 +25,7 @@ if [ "$INTERFACE" = "" ]; then
        exit 1
 fi
 
-MAC=$(get_mac_by_device ${INTERFACE})
-
-logger -t net "Received uevent for $INTERFACE ($ACTION)."
+MAC=$(get_mac ${INTERFACE})
 
 case $ACTION in
        add|register)
@@ -46,12 +44,8 @@ case $ACTION in
                        # interfaces that are registered then brought up
                        *)
                                export IN_HOTPLUG=1
-                               for file in ${NETWORK_DEVICES}/*/*; do
-                                       if [ "$(basename ${file})" = "${MAC}" ]; then
-                                               /etc/init.d/networking/ifup ${file}
-                                               exit $?
-                                       fi
-                               done
+                               /etc/init.d/networking/port ${MAC} up
+                               # XXX Walk through zones here?
                                ;;
                esac
                ;;
@@ -64,12 +58,7 @@ case $ACTION in
                                ;;
                        *)
                                export IN_HOTPLUG=1
-                               for file in ${NETWORK_DEVICES}/*/*; do
-                                       if [ "$(basename ${file})" = "${MAC}" ]; then
-                                               /etc/init.d/networking/ifdown ${file}
-                                               exit $?
-                                       fi
-                               done
+                               : # Nothing to do here at the moment
                                ;;
                esac
                ;;
index f2b7e611b6610e435b6e479f072881a952643c62..f85556be20cfbdab2fcba07368fd568a32f8b3b2 100644 (file)
@@ -43,8 +43,6 @@ for arg in ${@-$(find ${CONFIG_PORTS}/${port}/)}; do
        hooks="${hooks} ${CONFIG_PORTS}/${port}/${arg}"
 done
 
-echo "DEBUG: hooks: $hooks"
-
 # Getting zone variable
 #local zone
 #if [ -z "$ZONE" ]; then
index 54e06c41b74506eb2601c9b3a81bd3ba8a267fbf..a8b5cd6a8ff08eefa377a270def36f59ea06d58b 100644 (file)
@@ -28,24 +28,30 @@ action=$2
 case "$action" in
        up)
                message="Bringing up zone ${zone}..."
-               
+
                # Check if bridge already exists
                zone_status=`brctl show 2>/dev/null`
                if ! echo "${zone_status}" | grep -q "^${zone}"; then
-                       #/etc/init.d/networking/hooks pre-up ${CONFIG_ZONES}/${zone}
-
                        # Create and bring up the zone
                        brctl addbr ${zone} || failed=1
                        ip link set ${zone} up || failed=1
                        (exit ${failed})
                        evaluate_retval standard
 
+                       # When we boot, we should bring up every port
                        [ "${IN_BOOT}" = "1" ] && \
                                for port in ${CONFIG_ZONES}/${zone}/port-*; do
-                                       #port=$(readlink ${port})
                                        ZONE=${zone} /etc/init.d/networking/port ${port} up
                                done
 
+                       # Attach ports
+                       for config in ${CONFIG_ZONES}/${zone}/port-*; do
+                               port=${config##*/}; port=${port#port-}; port=${port%%-*}
+                               echo "DEBUG: port $port"
+                               ZONE=${zone} CONFIG=${config} \
+                                       /etc/init.d/networking/port ${port} attach
+                       done
+
                        ###/etc/init.d/networking/hooks post-up ${CONFIG_ZONES}/${zone}
                else
                        log_warning_msg
@@ -60,11 +66,12 @@ case "$action" in
                zone_status=`brctl show 2>/dev/null`
                if echo "${zone_status}" | grep -q "^${zone}"; then
                        #/etc/init.d/networking/hooks pre-down ${CONFIG_ZONES}/${zone}
-                       # remove devices
 
-                       for port in ${CONFIG_ZONES}/${zone}/port-*; do
-                               brctl delif ${zone} ${port##*/}
-                               /etc/init.d/networking/port ${port} down
+                       # Detach ports
+                       for config in ${CONFIG_ZONES}/${zone}/port-*; do
+                               port=${file#port-}; port=${port%%-*}
+                               ZONE=${zone} CONFIG=${config} \
+                                       /etc/init.d/networking/port ${port} detach
                        done
 
                        # Bring down the zone and delete it
@@ -72,8 +79,6 @@ case "$action" in
                        brctl delbr ${zone} || failed=1
                        (exit ${failed})
                        evaluate_retval standard
-
-                       #/etc/init.d/networking/hooks post-down ${CONFIG_ZONES}/${zone}
                else
                        log_warning_msg
                        message="Zone ${zone} does not exist."
index 59422f60121af43156e07ac56cec168a1a9cb135..a0faf0b0ccf45dcc09b637a58596d5123479bed8 100644 (file)
@@ -29,8 +29,91 @@ ERROR="\\033[1;31m"
 . /etc/init.d/networking/functions
 
 function usage() {
-       echo "Usage $0 - TODO"
-       _exit $1
+       echo -e "${BOLD}Usage $0${NORMAL}\n"
+       case "$1" in
+               main|"")
+                       echo    "This script will help you configuring your network."
+                       echo    "You should know that there are two different things:"
+                       echo
+                       echo    "    zone: A group of ports."
+                       echo    "    port: Connection to somewhere."
+                       echo
+                       echo    "    $0 [global flags] <port|zone> ... or"
+                       echo    "    $0 [global flags] <cmd line options...>"
+                       echo
+                       echo -e "${BOLD}Global flags:${NORMAL}"
+                       echo    "    --verbose -v  - Turn on verbose mode."
+                       echo    "    --debug   -d  - Turn on debug mode."
+                       echo
+                       echo -e "${BOLD}Command line options:${NORMAL}"
+                       echo    "    help          - Prints this help message."
+                       echo    "    start         - Starts the whole network."
+                       echo    "    stop          - Stops the whole network."
+                       echo    "    restart       - Restarts the whole network."
+                       echo    "    reload        - Reloads the whole network."
+                       echo
+                       echo    "    zone - Run \"$0 zone help\" for more information."
+                       echo    "    port - Run \"$0 port help\" for more information."
+                       echo
+                       ;;
+               port)
+                       echo -e "${BOLD}Port Configuration:${NORMAL}"
+                       echo
+                       echo    "    $0 [global options] port <command> ..."
+                       echo
+                       echo -e "${BOLD}Commands:${NORMAL}"
+                       echo -e "    ${BOLD}show:${NORMAL}"
+                       echo    "        Displays information about a given port."
+                       echo
+                       echo    "        Requires a \"port\"."
+                       echo    "        Example: $0 port show 00:11:22:33:44:55"
+                       echo    "                 $0 port show black0"
+                       echo
+                       ;;
+               zone)
+                       echo -e "${BOLD}Zone Configuration:${NORMAL}"
+                       echo
+                       echo    "    $0 [global options] zone <command> ..."
+                       echo
+                       echo -e "${BOLD}Commands:${NORMAL}"
+                       echo -e "    ${BOLD}show:${NORMAL}"
+                       echo    "        Displays information about a given zone."
+                       echo
+                       echo    "        Requires a \"zone\"."
+                       echo    "        Example: $0 zone show green0"
+                       echo
+                       echo -e "    ${BOLD}add:${NORMAL}"
+                       echo    "        Adds a new zone."
+                       echo
+                       echo    "        Requires a \"zone\"."
+                       echo    "        Example: $0 zone add green0"
+                       echo
+                       echo -e "    ${BOLD}del:${NORMAL}"
+                       echo    "        Deletes a zone."
+                       echo
+                       echo    "        Requires a \"zone\"."
+                       echo    "        Example: $0 zone del green0"
+                       echo
+                       echo -e "    ${BOLD}addport:${NORMAL}"
+                       echo    "        Adds a port to a zone."
+                       echo
+                       echo    "        Requires a \"zone\" and \"port\"."
+                       echo    "        Example: $0 zone addport green0"
+                       echo
+                       echo    "        You may also pass a hook and its parameters:"
+                       echo    "            $0 zone addport green0 black0 vlan 10"
+                       echo
+                       echo -e "    ${BOLD}delport:${NORMAL}"
+                       echo    "        Deletes a port from a zone."
+                       echo
+                       echo    "        Requires a \"zone\" and \"port\"."
+                       echo    "        Example: $0 zone delport green0"
+                       echo
+                       echo    "        You may also pass a hook and its parameters:"
+                       echo    "            $0 zone delport green0 black0 vlan 10"
+                       echo
+       esac
+       _exit ${2-1}
 }
 
 function debug() {
@@ -246,7 +329,7 @@ while [ "$#" -gt 0 ]; do
                        vecho "${BOLD}Verbose mode is enabled.${NORMAL}"
                        ;;
                help|-h|--help)
-                       usage 0
+                       usage main 0
                        ;;
                start|stop|restart|reload)
                        exec /etc/init.d/network $arg
@@ -259,6 +342,9 @@ while [ "$#" -gt 0 ]; do
                                        port_show $@
                                        _exit $?
                                        ;;
+                               help)
+                                       usage port 0
+                                       ;;
                        esac
                        ;;
                zone|zo|z)
@@ -285,10 +371,12 @@ while [ "$#" -gt 0 ]; do
                                        port_del $@
                                        _exit $?
                                        ;;
+                               help)
+                                       usage zone 0
+                                       ;;
                        esac
                        ;;
-               *)
-                       usage
-                       ;;
        esac
 done
+
+usage main