]> git.ipfire.org Git - people/stevee/network.git/blame - src/functions/functions.macvlan
Use autotools.
[people/stevee/network.git] / src / functions / functions.macvlan
CommitLineData
ab5a37b4
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 IPFire Network Development Team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22MACVLAN_PORT_INTERFIX="mv"
23
24function macvlan_create() {
25 local device=${1}
26 assert isset device
27
28 local parent=${2}
29 assert isset parent
30
31 local address=${3}
32 assert ismac address
33
34 # Check if the parent device exists.
35 if ! device_exists ${parent}; then
36 log ERROR "macvlan: parent device '${parent}' does not exist"
37 return ${EXIT_ERROR}
38 fi
39
40 # Check if the device we want to create does not already exist.
41 if device_exists ${device}; then
42 log ERROR "macvlan: device '${device}' already exists"
43 return ${EXIT_ERROR}
44 fi
45
46 # The macvlan device cannot be created, when the parent device
47 # is attached to a bridge. So we detach the parent device and
48 # reattach it again.
49 local bridge
50 if device_is_bridge_attached ${parent}; then
51 bridge=$(device_get_bridge ${parent})
52
53 # Detach the parent device.
54 bridge_detach_device ${bridge} ${parent}
55 fi
56
57 # Actually create the device.
58 cmd_quiet ip link add link ${parent} name ${device} address ${address} \
59 type macvlan
60 local ret=$?
61
62 if [ ${ret} -eq ${EXIT_OK} ]; then
63 log DEBUG "macvlan device '${device}' has been created"
64 else
65 log ERROR "Could not create macvlan device '${device}': ${ret}"
66 fi
67
68 # Re-attach device.
69 if isset bridge; then
70 bridge_attach_device ${bridge} ${parent}
71 fi
72
73 return ${ret}
74}
75
76function macvlan_remove() {
77 local device=${1}
78 assert isset device
79
80 device_delete ${device}
81}