I am doing some weird things and I need someone to tell me if what I am doing is wrong:
I am developing portable desktop scale systems around a CC100. Network port X2 (br1) is always attached to a WAGO WAP 758-919 in AccessPoint mode providing DHCP. Port X1 (br0) is usually attached to a router and talks to the internet, but in some cases I need to connect two of these (CC100) devices together directly via X1 and create an ad-hoc network to exchange UDP broadcast messages between them with Node-Red.
I can send messages between devices IF I manually set their IP address. To automate this I modified the /etc/udhcpc.script adding this case to the end:
# DHCP failed to get a lease - no router/DHCP server available.
# Assign a deterministic link-local IP (169.254.x.x) based on the
# interface's MAC address so devices can still reach each other
# directly without a router (e.g. in portable/field deployments).
# The last 2 hex digits of the MAC are used as the final octet,
# making the address unique per device (up to 256 devices conflict-free).
logger -t "udhcpc-script" "DHCP failed on $interface, assigning link-local..."
MAC=$(cat /sys/class/net/$interface/address | tr -d ':')
LAST=${MAC#??????????}
DEC=$((0x$LAST))
ip addr flush dev "$interface"
ip addr add 169.254.1.$DEC/16 dev "$interface"
;;
This does what I want it to do but I am worried I have unknowingly broken something else. Have I gone off the rails?