aboutsummaryrefslogtreecommitdiff
path: root/net/macvlan.sh
blob: 86a659c420a936a5175253dc3f6c9b205cc2c302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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.

macvlan_depend()
{
	program ip
	after interface
	before dhcp macchanger
}

_is_macvlan()
{
	[ -n "$(export RC_SVCNAME="net.${IFACE}"; service_get_value macvlan)" ]
}

macvlan_pre_start()
{
	# MAC-VLAN needs an existing interface to link to
	local macvlan=
	eval macvlan=\$macvlan_${IFVAR}
	[ -z "${macvlan}" ] && return 0

	case " ${MODULES} " in
		*" ifconfig "*)
				eerror "sys-apps/iproute2 is required to configure MACVLANs"
				return 1 ;;
	esac

	# 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 && _up && 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 $?
}