Layer 2 auto-discovery of connected device for trelay: not so bad solution

Hi! Based on the this article I setup a working wifi to ethernet bridge for non wifi devices (ex: failing laptop wifi card, projector, printer etc...) on a 2 ports pocket router. Unfortunateley "trelay" requires the mac address of the connected device to be hardcoded within the wireless configuration in order to work. I am looking for a "hotplug" script that could get the mac address of (first) freshly connected ethernet device and copy it to the wireless configuration automatically. So far I have a work in progress script that can manually set the mac and retarts the services.
I don't know yet which hotplug.d section would work for this but also the command that would give me the right information. So far "brctl" works well but it requires a bridge device and trelay does not work with bridges. I am not sure "arp" would work either because the lan & wifi interfaces are "unmanaged" with no ip adresses. What I am looking for is a layer 2 scan command to get the mac address of the connected device. Thanks in advance.

p.s. Of course I could use relayd instead but that would restrict the connection to ipv4 for my old laptop. Also my LAN carries a couple of non-routable packets protocols for musical intruments.

After many more reading and tests, I just could not make it work reliably with hotplugs, so I went for plan C. The router I use is a 2 ports (wan/lan) pocket router (GL.inet-6416). WAN is used as an admin port for configuring the router. LAN is the one being bridge to WIFI. I made a rc.local script that register automatically the MAC of a new device connected to the WAN port on power up. Upon success, the red led flashes for 10 seconds. After that the device can be connected to the LAN port and establish the connection. Of cource, unless a new device is used, there is no need to register the device again.

Here are the meaningfull parts of the configuration

network.@device[1]=device
network.@device[1].type='bridge'
network.@device[1].name='br-adm'
network.@device[1].ports='eth1'
network.adm=interface
network.adm.proto='static'
network.adm.device='br-adm'
network.adm.ipaddr='192.168.222.1'
network.adm.netmask='255.255.255.0'
dhcp.adm=dhcp
dhcp.adm.interface='adm'
dhcp.adm.start='100'
dhcp.adm.limit='150'
dhcp.adm.leasetime='12h'
firewall.@zone[0].name='adm'
firewall.@zone[0].input='ACCEPT'
firewall.@zone[0].output='ACCEPT'
firewall.@zone[0].forward='REJECT'
firewall.@zone[0].network='adm'

network.ethernet=interface
network.ethernet.proto='none'
network.ethernet.device='eth0'

network.wifi=interface
network.wifi.proto='none'

wireless.radio0=wifi-device
wireless.radio0.type='mac80211'
wireless.radio0.path='platform/ahb/18100000.wmac'
wireless.radio0.channel='1'
wireless.radio0.band='2g'
wireless.radio0.htmode='HT20'
wireless.radio0.country='BR'
wireless.radio0.cell_density='0'

wireless.default_radio0=wifi-iface
wireless.default_radio0.device='radio0'
wireless.default_radio0.mode='sta'
wireless.default_radio0.ssid='SSID'
wireless.default_radio0.encryption='psk2'
wireless.default_radio0.key='PASSWORD'
wireless.default_radio0.network='wifi'
wireless.default_radio0.macaddr='00:00:00:00:00:00'

trelay.@trelay[0]=trelay
trelay.@trelay[0].enabled='1'
trelay.@trelay[0].dev1='eth0'
trelay.@trelay[0].dev2='phy0-sta0'

system.led_lan=led
system.led_lan.name='LAN'
system.led_lan.sysfs='green:lan'
system.led_lan.trigger='netdev'
system.led_lan.mode='link tx rx'
system.led_lan.dev='eth0'
system.@led[1]=led
system.@led[1].name='red control'
system.@led[1].sysfs='red:wlan'
system.@led[1].trigger='none'
system.@led[1].delayon='250'
system.@led[1].delayoff='250'


and the rc.local script
sleep 10
brctl showmacs br-adm | tail -n +2 | cut -f 2-3 | while read MAC ISL
do
        if [ $ISL == "no" ]; then
                OLDMAC=`uci show wireless.default_radio0.macaddr | cut -f 2 -d = | sed s/\'//g`
                if [ $OLDMAC != $MAC ]; then
                        uci set wireless.default_radio0.macaddr=$MAC
                        uci commit wireless.default_radio0.macaddr
                        ifdown ethernet; ifup ethernet
                        service trelay restart
                        logger -t trelay "mac updated to $MAC"
                else
                        logger -t trelay "mac $MAC confirmed"
                fi
                #signal du traitement
                uci set system.@led[1].trigger='timer';uci commit system.@led[1];service led reload >/dev/null
                sleep 10
                uci set system.@led[1].trigger='none';uci commit system.@led[1];service led reload >/dev/null
                #le premier trouve est le bon
                break
        fi
done

exit 0

p.s. the advantage of trelay is that all packets are routed: IPV4, IPV6 and non routable proprietary packets. The disadvantage: only one port.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.