5

A while back I asked a question about setting my Raspberry Pi up with a bridged network connection - Wired to wireless bridge in Linux - and the answer I got worked well.

Now, I had to start all over again with the Raspberry Pi and used the setup described. But it would not incorporate the wlan0 device in the bridge stating:

 can't add wlan0 to br0: Operation not supported

But if I run

/usr/bin/hostapd /etc/hostapd/hostapd.conf

Then the wlan0 device is successfully added to the bridge. Could someone explain what is happening here and how I can fully automate the adding of wlan0 to the bridge?

The USB device is using the ath9k_htc driver.

As per request: /etc/network/interfaces and /etc/hostapd/hostapd.conf were based on the answer referred to above (though I had moved on to WPA and stopped using WEP), now look like this (following the answer below):

auto lo
iface lo inet loopback
iface eth0 inet static
address 0.0.0.0
iface wlan0 inet static
address 0.0.0.0

auto br0
iface br0 inet dhcp
    bridge_ports eth0
    pre-up ip link set eth0 down
    pre-up ip link set wlan0 down
    pre-up brctl addbr br0
    pre-up brctl addif br0 eth0
    pre-up ip addr flush dev eth0
    post-down ip link set eth0 down
    post-down ip link set wlan0 down
    post-down ip link set br0 down
    post-down brctl delif br0 eth0 wlan0
    post-down brctl delbr br0

and

interface=wlan0
bridge=br0
driver=nl80211
auth_algs=1
macaddr_acl=0
ignore_broadcast_ssid=0
logger_syslog=-1
logger_syslog_level=0
hw_mode=g
ssid=SSID
channel=11
wpa=2
wpa_passphrase=PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ctrl_interface=/var/run/hostapd
ieee80211n=1
1
  • Post your current /etc/network/interfaces and /etc/hostapd/hostapd.conf
    – BatchyX
    Mar 3, 2013 at 22:14

2 Answers 2

6

This is that simple: hostapd adds your interface to the bridge specified by bridge= after it has turned wlan0 in AP mode. Adding your interface in a bridge before hostapd is running is not possible, because your interface is still in the default managed mode.

Don't tell ifupdown (via /etc/network/interfaces) to add wlan0 to your bridge and let hostapd do it instead:

bridge-ports eth0 # no wlan0 here.

Oh, your /etc/network/interfaces is so much bloated. You don't need to fiddle that much with brctl.

auto lo
iface lo inet loopback

# If you don't need to configure eth0, don't add a stanza for eth0.

iface wlan0 inet manual
    # hostapd has ifupdown hooks in /etc/network/if-*.d/, just like bridge-utils
    hostapd /etc/hostapd/hostapd.conf

auto br0
iface br0 inet dhcp
    # This will run dhcp on eth0, then proceed to create an AP.

    # bridge-ports already handles creating the bridge, adding the ports and
    # upping them (with ifconfig and ioctls :-( )
    bridge_ports eth0

    # After the bridge is set up with only eth0, up the interface using
    # the previously defined stanza.  hostapd will add wlan0 to the bridge
    # using the modern rtnetlink API.
    post-up ifup wlan0

    # When preparing to down, destroy the AP (and remove it from the bridge)
    # before the bridge is downed.
    pre-down ifdown wlan0
2
  • OK, this works. Though I am not sure why the old setup stopped working. Thanks very much though. Mar 4, 2013 at 23:05
  • Are you sure it is "bridge-ports" and not "bridge_ports"? All the examples use the latter and I have not been able to find a reference to the former other than here. Unless the former is the older version of the latter. – Chiwda 1 hour ago
    – Chiwda
    Mar 31, 2020 at 9:47
-1

Normally these interfaces cannot be bridged, since the WiFi link-layer header does not have a separate source (or destination) address field – it's assumed that it will always be the same as the transmitting (or receiving) device's address. This means that a WiFi device cannot act as a bridge.

I'm guessing hostapd switches the interface to "4addr" mode, in which the headers contain all four addresses. If you have iw installed, run:

iw dev wlan0 set 4addr on
2
  • 1
    This is an AP. Of course an AP interface can be bridged, it's called an ESS, and this is why there is a third address (DA) in a 802.11 packet. You don't need 4address mode in this case.
    – BatchyX
    Mar 3, 2013 at 22:02
  • 1
    yes, my point is I bridged this perfectly well in the past, now it's seeming to behave oddly. Mar 3, 2013 at 23:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .