tests: Add VLAN support to the "ip link" stub
authorMartin Schwenke <martin@meltin.net>
Wed, 8 Jul 2015 12:14:51 +0000 (22:14 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Thu, 16 Jul 2015 04:35:20 +0000 (14:35 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(Imported from commit 8e41cb1e4e7b4a7d92628771260649ded4432772)

tests/eventscripts/stubs/ip

index 660ad7e304214b3c45d17ed3e133b04f2bfaa4a6..202175884e50ae00429bb5b01b9db373097a1a9a 100755 (executable)
@@ -23,15 +23,58 @@ ip_link ()
            esac
            ;;
        show) shift ; ip_link_show "$@" ;;
+       add*) shift ; ip_link_add "$@" ;;
        del*) shift ; ip_link_delete "$@" ;;
        *) not_implemented "$*" ;;
     esac
 }
 
+ip_link_add ()
+{
+    _link=""
+    _name=""
+    _type=""
+
+    while [ -n "$1" ] ; do
+       case "$1" in
+           link)
+               _link="$2"
+               shift 2
+               ;;
+           name)
+               _name="$2"
+               shift 2
+               ;;
+           type)
+               if [ "$2" != "vlan" ] ; then
+                   not_implemented "link type $1"
+               fi
+               _type="$2"
+               shift 2
+               ;;
+           id) shift 2 ;;
+           *) not_implemented "$1" ;;
+       esac
+    done
+
+    case "$_type" in
+       vlan)
+           if [ -z "$_name" -o -z "$_link" ] ; then
+               not_implemented "ip link add with null name or link"
+           fi
+
+           mkdir -p "${FAKE_IP_STATE}/interfaces-vlan"
+           echo "$_link" >"${FAKE_IP_STATE}/interfaces-vlan/${_name}"
+           ip_link_set_down "$_name"
+           ;;
+    esac
+}
+
 ip_link_delete ()
 {
     mkdir -p "${FAKE_IP_STATE}/interfaces-deleted"
     touch "${FAKE_IP_STATE}/interfaces-deleted/$1"
+    rm -f "${FAKE_IP_STATE}/interfaces-vlan/$1"
 }
 
 ip_link_set_up ()
@@ -59,6 +102,11 @@ ip_link_show ()
        exit 255
     fi
 
+    if [ -r "${FAKE_IP_STATE}/interfaces-vlan/${dev}" ] ; then
+       read _link <"${FAKE_IP_STATE}/interfaces-vlan/${dev}"
+       dev="${dev}@${_link}"
+    fi
+
     mac=$(echo $dev | md5sum | sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@')
     _state="UP"
     _flags=",UP,LOWER_UP"