commit:     1f76981467f9bbf1f2e22eb154fbb133ba333773
Author:     Sergey Popov <admin <AT> pinkbyte <DOT> ru>
AuthorDate: Tue Jan 24 09:18:21 2017 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Tue Jan 24 13:45:52 2017 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1f769814

Support for creating interfaces through iproute2 link command

Original idea and patch by Joseph Glanville <joseph.glanville <AT> 
orionvm.com.au>
https://gist.github.com/josephglanville/2757336

 net/iproute2.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 32ea5a4..55c9592 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -392,6 +392,20 @@ iproute2_pre_start()
                eend $? || return 1
                _up
        fi
+       local link=
+       eval link=\$iplink_${IFVAR}
+       if [ -n "${link}" ]; then
+               local ipproto=''
+               [ "${tunnel##mode ip6gre}" != "${tunnel}" ] && ipproto='-6'
+               [ "${tunnel##mode ip6gretap}" != "${tunnel}" ] && ipproto='-6'
+               [ "${tunnel##mode ip6tnl}" != "${tunnel}" ] && ipproto='-6'
+
+               ebegin "Creating interface ${IFVAR}"
+               veinfo ip ${ipproto} link add "${IFACE}" ${link}
+               ip ${ipproto} link add "${IFACE}" ${link}
+               eend $? || return 1
+               _up
+       fi
 
        # MTU support
        local mtu=
@@ -417,6 +431,13 @@ iproute2_pre_start()
        return 0
 }
 
+_iproute2_link_delete() {
+       ebegin "Destroying interface $1"
+       veinfo ip link del dev "$1"
+       ip link del dev "$1"
+       eend $?
+}
+
 _iproute2_ipv6_tentative()
 {
        [ -n "$(LC_ALL=C ip -family inet6 addr show dev ${IFACE} tentative)" ] 
&& return 0
@@ -499,6 +520,8 @@ iproute2_post_stop()
                        ip tunnel del "${IFACE}"
                        eend $?
                fi
+               [ -n "$(ip link show "${IFACE}" type gretap 2>/dev/null)" ] && 
_iproute2_link_delete "${IFACE}"
+               [ -n "$(ip link show "${IFACE}" type vxlan 2>/dev/null)" ] && 
_iproute2_link_delete "${IFACE}"
        fi
 }
 

Reply via email to