theio
Posts: 13
Joined: Tue May 11, 2021 9:00 am

Attaching a DHCP Server to OVS on Pi 4

Thu May 13, 2021 2:55 pm

So with the help of this thread (viewtopic.php?f=28&t=311596&p=1863941) I've set up a Raspberry Pi 4 as a wifi access point on wlan0, including a DHCP server - under normal conditions, it provides IP addresses to the client devices that are in turn able to reach the internet through it.

And now I want to attach wlan0 (i.e. the AP and the DHCP server for that network) to an OpenVSwitch. I've managed to do so in a way that allows the client devices to connect to the Pi 4's network, but the IP addresses being assigned to the clients aren't being assigned by the Pi - instead of the 192.168.4.X range expected, they're of the 169.254.X.X variety - i.e. arbitrarily assigned by the clients themselves and not by DHCP on the Pi.

Which means that the DHCP server on the Pi isn't working. I presume that OVS is at fault here - how do I retain the functionality of OpenVSwitch but also stop it from interfering with the DHCP server on wlan0?

epoch1970
Posts: 6692
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Attaching a DHCP Server to OVS on Pi 4

Fri May 14, 2021 9:20 pm

The DHCP server on the Pi will want a static address on the interface it listens to.
Check /var/log/syslog and see if dnsmasq (? Your DHCP server) bails out instead of starting up.
I assume you want to configure the static IP address of the OVS bridge in dhcpcd.conf; I’ve never used OVS so I could well be wrong.

In any case, be sure to “denyinterfaces wlan0” (and all other devices that are bridge members) in dhcpcd.conf.
Bridge member interfaces must not have an IP configuration. Only the bridge interface can.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

theio
Posts: 13
Joined: Tue May 11, 2021 9:00 am

Re: Attaching a DHCP Server to OVS on Pi 4

Mon May 17, 2021 8:19 am

epoch1970 wrote:
Fri May 14, 2021 9:20 pm
The DHCP server on the Pi will want a static address on the interface it listens to.
Check /var/log/syslog and see if dnsmasq (? Your DHCP server) bails out instead of starting up.
I assume you want to configure the static IP address of the OVS bridge in dhcpcd.conf; I’ve never used OVS so I could well be wrong.

In any case, be sure to “denyinterfaces wlan0” (and all other devices that are bridge members) in dhcpcd.conf.
Bridge member interfaces must not have an IP configuration. Only the bridge interface can.

Code: Select all

root@raspberrypi:/home/pi# grep dnsmasq /var/log/syslog
May 17 09:05:31 raspberrypi systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
May 17 09:05:31 raspberrypi dnsmasq[807]: dnsmasq: syntax check OK.
May 17 09:05:31 raspberrypi dnsmasq[824]: started, version 2.80 cachesize 150
May 17 09:05:31 raspberrypi dnsmasq[824]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify dumpfile
May 17 09:05:31 raspberrypi dnsmasq[824]: warning: interface wlan0 does not currently exist
May 17 09:05:31 raspberrypi dnsmasq-dhcp[824]: DHCP, IP range 192.168.4.2 -- 192.168.4.20, lease time 1d
May 17 09:05:31 raspberrypi dnsmasq[824]: reading /run/dnsmasq/resolv.conf
May 17 09:05:31 raspberrypi dnsmasq[824]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
May 17 09:05:31 raspberrypi dnsmasq[824]: read /etc/hosts - 5 addresses
May 17 09:05:32 raspberrypi dnsmasq[827]: Too few arguments.
May 17 09:05:32 raspberrypi systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
May 17 09:05:33 raspberrypi dnsmasq[824]: reading /run/dnsmasq/resolv.conf
May 17 09:05:33 raspberrypi dnsmasq[824]: using nameserver 192.168.1.254#53
May 17 09:05:33 raspberrypi dnsmasq[824]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
dnsmasq (which is indeed what I'm using) seems to start, but it is complaining about the absence of wlan0 - which given that wlan0 is being added to OVS before dnsmasq starts up makes sense. I had my suspicions about who needed the static IP, so I'll try "denyinterfaces" and then replace the wlan0 references elsewhere in the AP setup with br0 ones; hopefully, that should work.

epoch1970
Posts: 6692
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Attaching a DHCP Server to OVS on Pi 4

Mon May 17, 2021 8:28 am

I assume you want dnsmasq to be listening on br0 and not especially on wlan0.
What comes out of wlan0 will end in br0 once it is bridged.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

theio
Posts: 13
Joined: Tue May 11, 2021 9:00 am

Re: Attaching a DHCP Server to OVS on Pi 4

Mon May 17, 2021 8:59 am

Well, I made the changes, and I got this:

Code: Select all

root@raspberrypi:/home/pi# grep dnsmasq /var/log/syslog
May 17 09:05:31 raspberrypi systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
May 17 09:05:31 raspberrypi dnsmasq[807]: dnsmasq: syntax check OK.
May 17 09:05:31 raspberrypi dnsmasq[824]: started, version 2.80 cachesize 150
May 17 09:05:31 raspberrypi dnsmasq[824]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify dumpfile
May 17 09:05:31 raspberrypi dnsmasq[824]: warning: interface wlan0 does not currently exist
May 17 09:05:31 raspberrypi dnsmasq-dhcp[824]: DHCP, IP range 192.168.4.2 -- 192.168.4.20, lease time 1d
May 17 09:05:31 raspberrypi dnsmasq[824]: reading /run/dnsmasq/resolv.conf
May 17 09:05:31 raspberrypi dnsmasq[824]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
May 17 09:05:31 raspberrypi dnsmasq[824]: read /etc/hosts - 5 addresses
May 17 09:05:32 raspberrypi dnsmasq[827]: Too few arguments.
May 17 09:05:32 raspberrypi systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
May 17 09:05:33 raspberrypi dnsmasq[824]: reading /run/dnsmasq/resolv.conf
May 17 09:05:33 raspberrypi dnsmasq[824]: using nameserver 192.168.1.254#53
May 17 09:05:33 raspberrypi dnsmasq[824]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
May 17 09:35:27 raspberrypi systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
May 17 09:35:27 raspberrypi dnsmasq[714]: dnsmasq: syntax check OK.
May 17 09:35:27 raspberrypi dnsmasq[733]: started, version 2.80 cachesize 150
May 17 09:35:27 raspberrypi dnsmasq[733]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify dumpfile
May 17 09:35:27 raspberrypi dnsmasq-dhcp[733]: DHCP, IP range 192.168.4.2 -- 192.168.4.20, lease time 1d
May 17 09:35:27 raspberrypi dnsmasq[733]: read /etc/hosts - 5 addresses
May 17 09:35:28 raspberrypi dnsmasq[733]: no servers found in /run/dnsmasq/resolv.conf, will retry
May 17 09:35:28 raspberrypi dnsmasq[734]: Too few arguments.
May 17 09:35:28 raspberrypi dnsmasq[734]: Too few arguments.
May 17 09:35:28 raspberrypi systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
May 17 09:35:32 raspberrypi dnsmasq[733]: reading /run/dnsmasq/resolv.conf
May 17 09:35:32 raspberrypi dnsmasq[733]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
May 17 09:35:35 raspberrypi dnsmasq[733]: reading /run/dnsmasq/resolv.conf
May 17 09:35:35 raspberrypi dnsmasq[733]: using nameserver 192.168.1.254#53
May 17 09:35:35 raspberrypi dnsmasq[733]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
May 17 09:36:27 raspberrypi dnsmasq-dhcp[733]: DHCPDISCOVER(br0) fe:5f:0e:45:46:2f 
May 17 09:36:27 raspberrypi dnsmasq-dhcp[733]: DHCPOFFER(br0) 192.168.4.18 fe:5f:0e:45:46:2f 
May 17 09:36:27 raspberrypi dnsmasq-dhcp[733]: DHCPREQUEST(br0) 192.168.4.18 fe:5f:0e:45:46:2f 
May 17 09:36:27 raspberrypi dnsmasq-dhcp[733]: DHCPACK(br0) 192.168.4.18 fe:5f:0e:45:46:2f raspberrypi
May 17 09:36:28 raspberrypi dnsmasq-dhcp[733]: not giving name raspberrypi to the DHCP lease of 192.168.4.18 because the name exists in /etc/hosts with address 127.0.1.1
May 17 09:36:37 raspberrypi dnsmasq[733]: reading /run/dnsmasq/resolv.conf
May 17 09:36:37 raspberrypi dnsmasq[733]: using nameserver 192.168.1.254#53
May 17 09:36:37 raspberrypi dnsmasq[733]: using nameserver fe80::e675:dcff:fe08:a412%eth0#53
May 17 09:36:37 raspberrypi dnsmasq[733]: ignoring nameserver 192.168.4.1 - local interface
dnsmasq is listening on br0, and hostapd and dhcpcd both refer to br0 too.

Trouble is, wlan0 no longer appears on ifconfig (but it does on ovs-vsctl) and the network that the DHCP is needed for isn't showing for other devices (i.e. they can't connect to it).
epoch1970 wrote: I assume you want dnsmasq to be listening on br0 and not especially on wlan0.
What comes out of wlan0 will end in br0 once it is bridged.
I presume that's what needs to be done, given both what you've said and the fact that the wlan0-oriented setup wasn't leasing DHCP; however, now nothing can go into wlan0 - I did ifconfig wlan0 up but the interface isn't running.

epoch1970
Posts: 6692
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Attaching a DHCP Server to OVS on Pi 4

Mon May 17, 2021 11:00 am

Hmm. Maybe OVS isn't that keen on working with wireless interfaces.
viewtopic.php?t=208716

No idea, I've never used it. Perhaps you could use the linux bridge instead?
Or maybe a linux bridge, an OVS bridge and something like a veth pair to connect them? Seems a bit contrived...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

theio
Posts: 13
Joined: Tue May 11, 2021 9:00 am

Re: Attaching a DHCP Server to OVS on Pi 4

Mon May 17, 2021 2:34 pm

epoch1970 wrote:
Mon May 17, 2021 11:00 am
Hmm. Maybe OVS isn't that keen on working with wireless interfaces.
viewtopic.php?t=208716

No idea, I've never used it. Perhaps you could use the linux bridge instead?
Or maybe a linux bridge, an OVS bridge and something like a veth pair to connect them? Seems a bit contrived...
With the setup that dnsmasq.conf and dhcpcd.conf both referred to br0, and that denyinterfaces=wlan0 was active, but hostapd.conf referred to wlan0; I'm managing a connection with DHCP leasing to the clients.

Unfortunately, this is without password protection, which is a problem, but that's - I hope - a separate issue.

SurferTim
Posts: 2054
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Attaching a DHCP Server to OVS on Pi 4

Mon May 17, 2021 3:13 pm

Did you use "bridge=br0" in hostapd.conf? It's been a while since I used a bridge, but this worked in the past.

Code: Select all

interface=wlan0
bridge=br0
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
My advice applies to RaspiOS only. Please mention if you use another OS.

theio
Posts: 13
Joined: Tue May 11, 2021 9:00 am

Re: Attaching a DHCP Server to OVS on Pi 4

Tue May 18, 2021 12:03 pm

SurferTim wrote:
Mon May 17, 2021 3:13 pm
Did you use "bridge=br0" in hostapd.conf? It's been a while since I used a bridge, but this worked in the past.

Code: Select all

interface=wlan0
bridge=br0
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
I didn't use a bridge previously, but I gave the bridge config a try, and that's making the network stop appearing on my clients, so probably not what I'm wanting.

epoch1970
Posts: 6692
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Attaching a DHCP Server to OVS on Pi 4

Tue May 18, 2021 12:28 pm

An OVS bridge is not the same as a kernel bridge interface. Not the same code.
You can build a bridged AP using the kernel bridge interface.
It seems you cannot with an OVS bridge, I'll let you verify that further.

If you have no particular reason to use an OVS bridge, I'd avise to switch to using the regular kernel bridge and call it a day.
https://www.raspberrypi.org/documentati ... bridged.md

If you're bent on using OVS and it cannot handle a wireless interface (or hostapd can't handle the OVS bridge) as I said you can try having your OVS bridge on one side, a kernel bridge (for wifi) on the other side, and a veth interface pair to connect the two:
- ovs bridge br0: veth0 (and eth0?) as member interfaces
- kernel bridge br1: veth1 and wlan0 as member interfaces
I understand OVS knows what a veth device is. It is a virtual ethernet cable, what you get with the above is the same as 2 network switches linked together; any machine connected to either switch can reach any other machine.

In dhcpcd you should "denyinterfaces br1 veth* wlan0" so that none of these get configured with an IP address. Bridge member interfaces must not be configured and there is no point in giving br1 an address if br0 has one.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Networking and servers”