From 0b4246c76c37d45666f1a5b739bb3d1e1a371ea8 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Tue, 3 Dec 2013 12:04:58 -0600 Subject: Add macvlan connection support --- docs/examples/macvlan-dhcp | 10 ++++++++++ docs/examples/macvlan-static | 16 ++++++++++++++++ docs/netctl.profile.5.txt | 21 +++++++++++++++++++++ src/lib/connections/macvlan | 31 +++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 docs/examples/macvlan-dhcp create mode 100644 docs/examples/macvlan-static create mode 100644 src/lib/connections/macvlan diff --git a/docs/examples/macvlan-dhcp b/docs/examples/macvlan-dhcp new file mode 100644 index 0000000..cacbc68 --- /dev/null +++ b/docs/examples/macvlan-dhcp @@ -0,0 +1,10 @@ +Description='Virtual LAN with a static MAC on interface eth0 using DHCP' +Interface=mac0 +Connection=macvlan +# The variable name is plural, but needs precisely one interface +BindsToInterfaces=eth0 +# MACVAN Mode +Mode="bride" +# Optional static MAC Address for MACVLAN interface +MACAddress="12:34:56:78:9a:bc" +IP=dhcp diff --git a/docs/examples/macvlan-static b/docs/examples/macvlan-static new file mode 100644 index 0000000..9fa1e59 --- /dev/null +++ b/docs/examples/macvlan-static @@ -0,0 +1,16 @@ +Description='Virtual LAN with random MAC address on interface eth0' +Interface=mac0 +Connection=macvlan +# The variable name is plural, but needs precisely one interface +BindsToInterfaces=eth0 +# MACVAN Mode +Mode="bridge" +# Optional static MAC Address for MACVLAN interface +MACAddress="" +IP=static +Address="192.168.0.100/24" +Gateway="192.168.0.1" +DNS=("192.168.0.2") +Hostname="myhost" +DNSDomain="mydomain.com" +DNSSearch="mydomain.com" diff --git a/docs/netctl.profile.5.txt b/docs/netctl.profile.5.txt index 9bdbb91..d1b6447 100644 --- a/docs/netctl.profile.5.txt +++ b/docs/netctl.profile.5.txt @@ -54,6 +54,8 @@ AVAILABLE CONNECTION TYPES For TUN/TAP interfaces. +vlan+:: For VLANs on ethernet-like connections. ++macvlan+:: + For MACVLANs on ethernet-like connections. GENERAL OPTIONS @@ -458,6 +460,25 @@ type must set a vlan identifier using 'VLANID='. See *ip*(8) for details. +OPTIONS FOR `macvlan' CONNECTIONS +--------------------------------- +The name of the macvlan interface is specified in 'Interface'. The +underlying physical interface is specified in 'BindsToInterfaces'. +Hence, for macvlan profiles, 'BindsToInterfaces' contains the name of a +single network interface. + +All options for connections of the `ethernet' type are understood for +connections of the `macvlan' type. Next to the *ip options*, the +following are understood for connections of the `macvlan' type: + +'Mode=':: + Either `bridge', `vepa', `private', or `passthru'. See *ip*(8) for + details. + +'MACAddress=':: + Optional static MAC address for the `macvlan' type link. + + SPECIAL QUOTING RULES --------------------- Configuration files for *wpa_supplicant* use non-standard quoting. diff --git a/src/lib/connections/macvlan b/src/lib/connections/macvlan new file mode 100644 index 0000000..11e7017 --- /dev/null +++ b/src/lib/connections/macvlan @@ -0,0 +1,31 @@ +# Contributed by: Walter F Dworak + +. "$CONN_DIR/ethernet" + +macvlan_up() { + if [[ ${#BindsToInterfaces[@]} -ne 1 ]]; then + report_error "No unique physical device for MACVLAN interface '$Interface' specified" + return 1 + fi + if is_interface "$Interface"; then + report_error "Interface '$Interface' already exists" + return 1 + elif [[ $Mode != @(bridge|passthru|private|vepa) ]]; then + report_error "Invalid mode '$Mode' for MACVLAN interface '$Interface'" + return 1 + else + bring_interface_up "$BindsToInterfaces" + interface_add macvlan "$Interface" "$BindsToInterfaces" mode "$Mode" + if [[ $MACAddress ]]; then + ip link set dev "$Interface" address "$MACAddress" || return 1 + fi + fi + ethernet_up +} + +macvlan_down() { + ethernet_down + interface_delete "$Interface" +} + +# vim: ft=sh ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b