aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorStef Simoens <stef.simoens@scarlet.be>2011-09-27 16:55:22 -0500
committerWilliam Hubbs <williamh@gentoo.org>2011-10-26 11:28:39 -0500
commitf94e8836333f6dea142d9a7b29610fcc8d6b12a3 (patch)
treef5d47602839bb2fe0a82e35c1f921539bd0f8985 /net
parentb1da4dcb9913d6d28fa39c60dcf9c867c39486ef (diff)
Add macvlan support
X-Gentoo-Bug: 384029 X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=384029
Diffstat (limited to 'net')
-rw-r--r--net/Makefile2
-rw-r--r--net/macvlan.sh69
2 files changed, 70 insertions, 1 deletions
diff --git a/net/Makefile b/net/Makefile
index 664800df..e87d3ddd 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -13,7 +13,7 @@ SRCS-Linux= iwconfig.sh.in
INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
- vlan.sh
+ vlan.sh macvlan.sh
SRCS-NetBSD=
INC-NetBSD= ifwatchd.sh
diff --git a/net/macvlan.sh b/net/macvlan.sh
new file mode 100644
index 00000000..92bcf1f8
--- /dev/null
+++ b/net/macvlan.sh
@@ -0,0 +1,69 @@
+# 2011-09-22 Stef Simoens <stef@bgs.org>
+# based on vlan.sh & tuntap.sh
+# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
+# All rights reserved. Released under the 2-clause BSD license.
+
+_ip()
+{
+ if [ -x /bin/ip ]; then
+ echo /bin/ip
+ else
+ echo /sbin/ip
+ fi
+}
+
+macvlan_depend()
+{
+ program $(_ip)
+ after interface
+ before dhcp macchanger
+}
+
+_is_macvlan()
+{
+ [ -n "$(export RC_SVCNAME="net.${IFACE}"; service_get_value macvlan)" ]
+}
+
+_check_macvlan()
+{
+ if [ ! -d /sys/module/macvlan ]; then
+ modprobe macvlan
+ if [ ! -d /sys/module/macvlan ]; then
+ eerror "MAC-VLAN support is not present in this kernel"
+ return 1
+ fi
+ fi
+}
+
+macvlan_pre_start()
+{
+ # MAC-VLAN needs an existing interface to link to
+ local macvlan=
+ eval macvlan=\$macvlan_${IFVAR}
+ [ -z "${macvlan}" ] && return 0
+
+ _check_macvlan || return 1
+
+ # optional mode, default to "private"
+ local mode=
+ eval mode=\$mode_${IFVAR}
+ [ -z "${mode}" ] && mode="private"
+
+ ebegin "Creating MAC-VLAN ${IFACE} to ${macvlan}"
+ e="$(ip link add link "${macvlan}" name "${IFACE}" type macvlan mode "${mode}" 2>&1 1>/dev/null)"
+ if [ -n "${e}" ]; then
+ eend 1 "${e}"
+ else
+ eend 0 && service_set_value macvlan "${macvlan}"
+ fi
+}
+
+
+macvlan_post_stop()
+{
+ _is_macvlan || return 0
+
+ ebegin "Removing MAC-VLAN ${IFACE}"
+ ip link delete "${IFACE}" type macvlan >/dev/null
+ eend $?
+}