Assumptions:
- The computer has both wired and WiFi adapters
- The wired connection is the uplink to the switch/router
- There is an existing DHCP server somewhere on the wired network
- The wireless interface will be set up as an access point, not a client. You need other packages and configuration to make that work (hint: ebtables)
- The wired interface is enp3s0, the wireless interface is wlan0 and the bridge is named br0. Substitute as necessary.
- Enable CONFIG_BRIDGE in your kernel config (module is okay)
Code: Select all
emerge bridge-utils wpa_supplicant
Code: Select all
emerge dhcpcd
Code: Select all
# The bridge will take the ip address, so the individual interfaces don't need any
config_enp3s0="null"
config_wlan0="null"
modules_wlan0="wpa_supplicant"
wpa_supplicant_wlan0="-b br0"
# Set up an Ethernet bridge--only add the wired interface initially
bridge_br0="enp3s0"
# Use DHCP to get the IP address for the bridge. Could be static or APIPA also.
config_br0="dhcp"
# Ensure the wired interface is up/started before creating the bridge
rc_net_br0_need="net.enp3s0"
# In case DHCP fails
fallback_br0="192.168.X.Y/24"
fallback_routes_br0="default via 192.168.X.Z"
# Assign mac to bridge if necessary
#mac_br0="aa:bb:cc:dd:ee:ff"
# You may want to add this otherwise other services which depend on net may not start because they're waiting for wlan0
rc_net_wlan0_provide="!net"
# Use the new method to configure bridge parameters
stp_state_br0="1"
# Want this to be 0 but it seems to want a minimum of 200
#forward_delay_br0="0"
# Want this to be 2 but minimum seems to be 100
hello_time_br0="100"
# This doesn't work because it tries to add wlan0 to the bridge before wpa_supplicant runs and you get Operation not supported
#bridge_add_wlan0="br0"
# So instead we use the postup script to add wlan0 to the bridge after it is up
postup() {
if [[ ${IFACE} = "wlan0" ]]; then
ebegin "Adding ${IFACE} to bridge";
/sbin/brctl addif br0 wlan0
eend $?
fi
return 0;
}Now create and add the network services to the appropriate runlevels.
Code: Select all
ln -s /etc/init.d/net.lo /etc/init.d/net.enp3s0
ln -s /etc/init.d/net.lo /etc/init.d/net.wlan0
ln -s /etc/init.d/net.lo /etc/init.d/net.br0
rc-update add net.br0 default
rc-update add net.wlan0 defaultNext, set up the access point. Here is the essential configuration to create an access point using wpa_supplicant (network security is WPA2 pre-shared key with AES) :
Code: Select all
ctrl_interface=/var/run/wpa_supplicant
eapol_version=1
ap_scan=1
fast_reauth=1
network={
ssid="Bridge Test"
psk="Shared Key"
key_mgmt=WPA-PSK
proto=WPA2
group=CCMP
priority=10
# These next two lines put the interface in access point mode on channel 11
mode=2
frequency=2462
}Usage:
Simply reboot, or just stop all the net.* services (except net.lo) and then start net.br0 and net.wlan0. /etc/init.d/net.br0 will bring up net.enp30, inherit its MAC address and request an address from the DHCP server. Then /etc/init.d/wlan0 will start and create the access point, and will then be added to the bridge. If the MAC address of the wireless interface is numerically lower than that of the wired interface (as it is in my case), the bridge will assume that MAC address. I don't believe this is a problem, however, because dhcpcd caches the MAC address it used to request the lease and (I believe) it will re-use that when renewing the lease. If it is a problem, you can always manually assign a MAC address to the bridge using the mac_br0="..." directive as commented out in the /etc/conf.d/net example above.
For testing different wireless access point settings, it is sufficient to just restart /etc/init.d/wlan0
This Ubuntu forum post was helpful in getting me pointed in the right direction: http://ubuntuforums.org/showthread.php?t=1692292
Edit: Added proto=WPA2 (alias for RSN) to /etc/wpa_supplicant/wpa_supplicant.conf to force WPA2 operation


