]> git.pld-linux.org Git - packages/lxc.git/blame - lxc_macvlan
Version: 1.1.3, merged macvlan with lxc-net scripts
[packages/lxc.git] / lxc_macvlan
CommitLineData
1dd4bfdd
LG
1#!/bin/bash
2
3# additional macvlan interface for lxc
4
5# TODO: add additional iptables rules / ipv6 / ip_forward
6
7
8macvlan_test_config(){
9
10 # check if all required configurations have been set
11 # Source any configurable options
12 test ! -r /etc/sysconfig/lxc_macvlan ||
13 . /etc/sysconfig/lxc_macvlan
14
15 # Tests for data provided in /etc/sysconfig/lxc_macvlan
16 if [ -z "$MACVLAN_DEV" ]; then
17 echo "MACVLAN_DEV not set is /etc/sysconfig/lxc_macvlan"
18 exit 6
19 fi
20
21 if [ -z "$MACVLAN_NAME" ]; then
22 echo "MACVLAN_NAME not set is /etc/sysconfig/lxc_macvlan"
23 exit 6
24 fi
25
26 if [ -z "$MACVLAN_ADDRESS" ]; then
27 echo "MACVLAN_ADDRESS not set is /etc/sysconfig/lxc_macvlan"
28 exit 6
29 fi
30}
31
32macvlan_gen_default_hwaddr(){
33 # If not defined MACVLAN_HWADDRESS, calculate it from MACVLAN_ADDRESS
34 echo $MACVLAN_ADDRESS | awk -F "/" '{print $1}' | awk -F "." '{ printf "00:16:3e:%x:%x:%x\n", $2, $3, $4 }'
35}
36
37macvlan_start() {
38 echo "LXC macvlan interface start"
39 echo 1 > /proc/sys/net/ipv4/ip_forward
40 macvlan_test_config
41
42 set -e
43 if [ -z "$MACVLAN_HWADDRESS" ]; then
44 MACVLAN_HWADDRESS=`macvlan_gen_default_hwaddr`
45 fi
46 ip link add link $MACVLAN_DEV name $MACVLAN_NAME address $MACVLAN_HWADDRESS type macvlan mode bridge
47 ip link set $MACVLAN_NAME up
48 ip address add $MACVLAN_ADDRESS brd + dev $MACVLAN_NAME
49}
50
51macvlan_stop() {
52 echo "LXC macvlan interface stop"
53 macvlan_test_config
54
55 set -e
56 ip link set $MACVLAN_NAME down
57 ip link del $MACVLAN_NAME
58}
59
60macvlan_status() {
61 echo "LXC macvlan interface status"
62 macvlan_test_config
63
64 set -e
65 ip addr show $MACVLAN_NAME
66}
This page took 0.053262 seconds and 4 git commands to generate.