Discussion:
[OpenWrt-Devel] [PATCH] macvlan interfaces with uci
Johannes Schlatow
2010-08-09 19:36:45 UTC
Permalink
This patch adds support for macvlan interfaces to uci.
* ifname pattern is ethXvY, where ethX is the physical interface, Y is arbitrary
* you can specify a mac address
* dependencies: kmod-macvlan, ip

e.g.:

$ uci show network.dmz
network.dmz=interface
network.dmz.proto=dhcp
network.dmz.ifname=eth0v2
network.dmz.macaddr=01:23:45:67:89:ab

Signed-off-by: Johannes Schlatow <***@googlemail.com>

---

Index: package/base-files/files/lib/network/config.sh
===================================================================
--- package/base-files/files/lib/network/config.sh (revision 22530)
+++ package/base-files/files/lib/network/config.sh (working copy)
@@ -66,6 +66,22 @@
return 1
}

+add_macvlan() {
+ local vif="${1%v*}"
+ local config=$2
+ + [ "$1" = "$vif" ] || ifconfig "$1" >/dev/null 2>/dev/null || [ ! -x /usr/sbin/ip ] || {
+ ifconfig "$vif" up 2>/dev/null >/dev/null || add_macvlan "$vif" "$config"
+ config_get macaddr $config macaddr
+ [ -z "$macaddr" ] || {
+ macaddr="address $macaddr "
+ }
+ $DEBUG ip link add link "$vif" name "$1" "$macaddr"type macvlan
+ return 0
+ }
+ return 1
+}
+
# add dns entries if they are not in resolv.conf yet
add_dns() {
local cfg="$1"; shift
@@ -154,6 +170,7 @@

# Setup VLAN interfaces
add_vlan "$iface" && return 1
+ add_macvlan "$iface" "$config" && return 1
ifconfig "$iface" 2>/dev/null >/dev/null || return 0

# Setup bridging
Felix Fietkau
2010-08-09 20:01:49 UTC
Permalink
Post by Johannes Schlatow
This patch adds support for macvlan interfaces to uci.
* ifname pattern is ethXvY, where ethX is the physical interface, Y is arbitrary
* you can specify a mac address
* dependencies: kmod-macvlan, ip
$ uci show network.dmz
network.dmz=interface
network.dmz.proto=dhcp
network.dmz.ifname=eth0v2
network.dmz.macaddr=01:23:45:67:89:ab
I don't like the arbitrary naming pattern and the config format
ambiguities that it introduces. Could you please change the config
format to make the distinction between macvlan and other stuff more
clear, and also allow the user to specify macvlan interface name and
base interface name separately.

- Felix
Hamish Guthrie
2010-08-09 20:10:20 UTC
Permalink
Hi Felix,

Did you get my mail earlier from my Sony acct regarding the patch I was
proposing to commit?

Unfortunately, I do not have access to that email acct from home.

Regards

Hamish
Johannes Schlatow
2010-08-09 23:58:29 UTC
Permalink
Post by Felix Fietkau
Post by Johannes Schlatow
This patch adds support for macvlan interfaces to uci.
* ifname pattern is ethXvY, where ethX is the physical interface, Y is arbitrary
* you can specify a mac address
* dependencies: kmod-macvlan, ip
$ uci show network.dmz
network.dmz=interface
network.dmz.proto=dhcp
network.dmz.ifname=eth0v2
network.dmz.macaddr=01:23:45:67:89:ab
I don't like the arbitrary naming pattern and the config format
ambiguities that it introduces. Could you please change the config
format to make the distinction between macvlan and other stuff more
clear, and also allow the user to specify macvlan interface name and
base interface name separately.
- Felix
Okay. I suppose you would expect something like this:

$ uci show network.dmz
network.dmz.proto=dhcp
network.dmz.ifname=myvlan0
network.dmz.type=macvlan
network.dmz.basedev=eth0
network.dmz.macaddr=01:23:45:67:89:ab

---

Index: package/base-files/files/lib/network/config.sh
===================================================================
--- package/base-files/files/lib/network/config.sh (revision 22530)
+++ package/base-files/files/lib/network/config.sh (working copy)
@@ -154,11 +154,30 @@

# Setup VLAN interfaces
add_vlan "$iface" && return 1
- ifconfig "$iface" 2>/dev/null >/dev/null || return 0

- # Setup bridging
local iftype
config_get iftype "$config" type
+
+ [ "$iftype" = "macvlan" ] && {
+ local macaddr
+ local basedev
+
+ config_get macaddr "$config" macaddr
+ config_get basedev "$config" basedev
+
+ [ -z "$macaddr" ] || {
+ macaddr="address $macaddr "
+ }
+
+ [ -z "$basedev" ] || {
+ $DEBUG ip link add link ${basedev} name ${iface} ${macaddr}type macvlan
+ return 1
+ }
+ }
+
+ ifconfig "$iface" 2>/dev/null >/dev/null || return 0
+
+ # Setup bridging
case "$iftype" in
bridge)
local macaddr
Johannes Schlatow
2010-08-10 17:05:35 UTC
Permalink
Post by Johannes Schlatow
Post by Felix Fietkau
Post by Johannes Schlatow
This patch adds support for macvlan interfaces to uci.
* ifname pattern is ethXvY, where ethX is the physical interface, Y is arbitrary
* you can specify a mac address
* dependencies: kmod-macvlan, ip
$ uci show network.dmz
network.dmz=interface
network.dmz.proto=dhcp
network.dmz.ifname=eth0v2
network.dmz.macaddr=01:23:45:67:89:ab
I don't like the arbitrary naming pattern and the config format
ambiguities that it introduces. Could you please change the config
format to make the distinction between macvlan and other stuff more
clear, and also allow the user to specify macvlan interface name and
base interface name separately.
- Felix
$ uci show network.dmz
network.dmz.proto=dhcp
network.dmz.ifname=myvlan0
network.dmz.type=macvlan
network.dmz.basedev=eth0
network.dmz.macaddr=01:23:45:67:89:ab
---
Index: package/base-files/files/lib/network/config.sh
===================================================================
--- package/base-files/files/lib/network/config.sh (revision 22530)
+++ package/base-files/files/lib/network/config.sh (working copy)
@@ -154,11 +154,30 @@
# Setup VLAN interfaces
add_vlan "$iface" && return 1
- ifconfig "$iface" 2>/dev/null >/dev/null || return 0
- # Setup bridging
local iftype
config_get iftype "$config" type
+
+ [ "$iftype" = "macvlan" ] && {
+ local macaddr
+ local basedev
+
+ config_get macaddr "$config" macaddr
+ config_get basedev "$config" basedev
+
+ [ -z "$macaddr" ] || {
+ macaddr="address $macaddr "
+ }
+
+ [ -z "$basedev" ] || {
+ $DEBUG ip link add link ${basedev} name ${iface} ${macaddr}type macvlan
+ return 1
+ }
+ }
+
+ ifconfig "$iface" 2>/dev/null >/dev/null || return 0
+
+ # Setup bridging
case "$iftype" in
bridge)
local macaddr
I just realized, that there are two issues with this patch. Firstly, the return statement after 'ip link..' has to be 'return 0' instead of 'return 1'. Secondly, the interfaces are not created during boot, because ifup needs to be called for this. A few lines in /etc/config/network:boot() will fix this.

Sorry for that. I think in the future I shouldn't propose a patch on 2.00 am ;)
I could email the appropriate patches, if you like to add this feature to OpenWrt.

/Johannes

Loading...