Hi,
THE ISSUE
When I unplug the ethernet cable, OpenWrt doesn't automatically detect the lost connection to drop the IP addr. There are kernel messages notifying that the link state changed but that's all.
I need to make the IP addr drop.
A PART OF THE SOLUTION
So I catch the link state change by polling it with the command
swconfig dev rt305x port 4 get link
When caught, I need to update ifconfig to drop the IP addr.
WHERE IT STARTS FUZZLING ME
To do that I set the iface down and that should drop the IP addr. It works from time to time but not always.
Here is an example:
I have this configuration for /etc/config/network
:
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option type 'bridge'
option ifname 'eth0.1'
option proto 'static'
option netmask '255.255.255.0'
option ipaddr '192.168.252.1'
config device 'lan_dev'
option name 'eth0.1'
option macaddr '1a:2b:3c:4d:5e:6f'
config interface 'wan'
option type 'bridge'
option ifname 'eth0.2'
option proto 'dhcp'
config device 'wan_dev'
option name 'eth0.2'
option macaddr '1a:2b:3c:4d:5e:6f'
config switch
option name 'rt305x'
option reset '1'
option enable_vlan '1'
config switch_vlan
option device 'rt305x'
option vlan '1'
option ports '0 1 2 3 6t'
config switch_vlan
option device 'rt305x'
option vlan '2'
option ports '4 6t'
And the ouput of ifconfig
for br-wan
is:
br-lan Link encap:Ethernet HWaddr 1A:2B:3C:4D:5E:6F
inet addr:192.168.252.1 Bcast:192.168.252.255 Mask:255.255.255.0
inet6 addr: fe80::182b:3cff:fe4d:5e6f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:2158 (2.1 KiB)
br-wan Link encap:Ethernet HWaddr 1A:2B:3C:4D:5E:6F
inet addr:192.168.167.12 Bcast:192.168.167.255 Mask:255.255.255.0
inet6 addr: fe80::182b:3cff:fe4d:5e6f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3908 (3.8 KiB) TX bytes:1937 (1.8 KiB)
eth0 Link encap:Ethernet HWaddr 5E:D3:4B:CE:E7:D6
inet6 addr: fe80::5cd3:4bff:fece:e7d6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20257 errors:0 dropped:0 overruns:0 frame:0
TX packets:4804 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2273842 (2.1 MiB) TX bytes:386092 (377.0 KiB)
Interrupt:5
eth0.1 Link encap:Ethernet HWaddr 1A:2B:3C:4D:5E:6F
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:2158 (2.1 KiB)
eth0.2 Link encap:Ethernet HWaddr 1A:2B:3C:4D:5E:6F
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3908 (3.8 KiB) TX bytes:1937 (1.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:196 errors:0 dropped:0 overruns:0 frame:0
TX packets:196 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13861 (13.5 KiB) TX bytes:13861 (13.5 KiB)
wlan0 Link encap:Ethernet HWaddr 1A:2B:3C:4D:5E:6F
inet6 addr: fe80::182b:3cff:fe4d:5e6f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:2206 (2.1 KiB)
But when I set iface eth0.2 down (and thus br-wan):
root@OpenWrt:/# ip link set eth0.2 down
[61913.989411] br-wan: port 1(eth0.2) entered disabled state
we can see in the ifconfig
output that eth0.2 has disappeared but br-wan doesn't always drop the IP addr.
I need the IP addr to appear/disappear for br-wan. So removing the bridge type for wan is not an option.