On 10/22/2011 01:54 AM, Ben Pfaff wrote:
On Thu, Oct 20, 2011 at 01:08:57PM +0200, Frank wrote:
Is there a good way to with some kind of hook to add ip addresses to
interfaces defined via ovs-vsctl and set interfaces links up?
One way to do it would be to add a init script to run after
openvswitch-switch.
udev is another way.
I'm sure that there are still other ways, too.
I see openvswitch does not store/remember ip addressing, (default) route
and interface administrative link states (up/down) in it's conf.db. This
is by design, I suppose. When configuring a physical switch, you
generally assign an ip address and default route to the management vlan
on the switch for administrative access. Why doesn't ovs support this?
Or am I missing something obvious?
I tried to create examples to implement both of the udev and init-script
suggestions.
First of all, the udev way. When open-vswitch creates a network
interface, we can trigger a rule in udev that executes a script to setup
the device ('abusing' ifup/down, instead of re-inventing something alike)...
/etc/udev/rules.d/openvswitch.rules
------------------------------------------------------------------
KERNEL=="br*", SUBSYSTEM=="net", RUN+="/usr/local/sbin/ovs-udev %k"
KERNEL=="vlan*", SUBSYSTEM=="net", RUN+="/usr/local/sbin/ovs-udev %k"
------------------------------------------------------------------
/usr/local/sbin/ovs-udev
------------------------------------------------------------------
#!/bin/sh
logger -t ovs-udev "$ACTION $1"
case $ACTION in
add)
ifup --force $1 | logger -t ovs-udev
;;
remove)
# hm, this won't ever work, because this script gets
# called after the device is already removed...
ifdown --force $1 | logger -t ovs-udev
;;
esac
exit 0
------------------------------------------------------------------
/etc/network/interfaces:
------------------------------------------------------------------
auto eth0
iface eth0 inet manual
up ip link set up dev eth0
down ip link set down dev eth0
iface br0 inet manual
up ip link set up dev br0
down ip link set down dev br0
iface vlan5 inet manual
up ip link set up dev vlan5
up ip addr add 10.140.5.20/24 brd + dev vlan5
up ip route add default via 10.140.5.1 dev vlan5
down ip addr del 10.140.5.20/24 dev vlan5
down ip link set down dev vlan5
------------------------------------------------------------------
When re-adding e.g. the vlan5 device, using `ovs-vsctl del-port br0
vlan5` and `ovs-vsctl add-port br0 vlan5 tag=5 -- set interface vlan5
type=internal`, the address and default route re-appear, and syslog shows:
Oct 22 20:26:24 lw-dom0 ovs-vsctl: 00001|vsctl|INFO|Called as ovs-vsctl
del-port br0 vlan5
Oct 22 20:26:24 lw-dom0 ovs-udev: remove vlan5
Oct 22 20:26:37 lw-dom0 ovs-vsctl: 00001|vsctl|INFO|Called as ovs-vsctl
add-port br0 vlan5 tag=5 -- set interface vlan5 type=internal
Oct 22 20:26:37 lw-dom0 kernel: [ 277.495356] device vlan5 entered
promiscuous mode
Oct 22 20:26:37 lw-dom0 ovs-udev: add vlan5
Oct 22 20:26:37 lw-dom0 ovs-udev: Set name-type for VLAN subsystem.
Should be visible in /proc/net/vlan/config
After a reboot:
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP
qlen 1000
link/ether 00:1f:29:00:62:d6 brd ff:ff:ff:ff:ff:ff
inet6 fe80::21f:29ff:fe00:62d6/64 scope link
valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc noqueue
state UNKNOWN
link/ether 00:1f:29:00:62:d6 brd ff:ff:ff:ff:ff:ff
inet6 fe80::21f:29ff:fe00:62d6/64 scope link
valid_lft forever preferred_lft forever
4: vlan5: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc
noqueue state UNKNOWN
link/ether 00:23:20:ad:0c:2f brd ff:ff:ff:ff:ff:ff
inet 10.140.5.20/24 brd 10.140.5.255 scope global vlan5
inet6 fe80::223:20ff:fead:c2f/64 scope link
valid_lft forever preferred_lft forever
# ip r
10.140.5.0/24 dev vlan5 proto kernel scope link src 10.140.5.20
default via 10.140.5.1 dev vlan5
# ovs-vsctl show
edd713d0-c28e-48e9-a36a-0459c7268f47
Bridge "br0"
Port "vlan5"
tag: 5
Interface "vlan5"
type: internal
Port "br0"
Interface "br0"
type: internal
Port "eth0"
Interface "eth0"
ovs_version: "1.2.1+build0"
Benefits of this approach:
- settings re-appear after removing/re-adding a brX or vlanY. no
ifupdown headaches here!
Drawbacks of this approach:
- the 'remove' udev hook gets called *after* the device is gone, so
essentially the ifdown part will always fail if you put commands like ip
addr del in it. (Or we juist couldn't care less, because the kernel will
cleanup the assigned ip address (and route) anyway if we remove the
interface entirely...
- when doing a shutdown of the OS, ifdown gets called multiple times.
Nice, but does not feel nice enough to me.
Second option: re-ordering init-scripts. By default, in Debian Squeeze,
openvswitch-switch depends on $network to be start, so networking cannot
depend on openvswitch-switch to be started, creating a dependency loop.
When trying anything to alter this, dependency hell immediately starts
to unfold.
Or we could just stop (ab)using ifupdown, (I never liked it anyway, and
never used its config directives).
Taking the udev-way of doing things as a basis and improving the above
could be an idea. The configuration of eth0 can stay in
/etc/network/interfaces, but the configuration of interfaces which are
part of ovs needs to go somewhere else, albeit being configurable. Why
not persist them in ovs conf.db?
Any ideas?
Hans van Kranenburg
Mendix
_______________________________________________
discuss mailing list
discuss@openvswitch.org
http://openvswitch.org/mailman/listinfo/discuss