Ethernet network auto-detection workaround

Hi all,

I am interested in automatically selecting an Ethernet connection
profile based on the network to which I'm connected, probably identified
by ARP probes.  I noticed there has been some previous interest in this
feature[1][2] along with TODO implementation notes.[3]  Until/Unless it
is implemented, I came up with a workaround.  I'd appreciate any
thoughts or feedback for issues I may have overlooked or whether it
might be worth sending an MR to add it to nmcli-examples(7).

First, I created a high-priority connection profile from which detection
can be done:

nmcli connection add \
        type ethernet \
        con-name ethdetect \
        connection.autoconnect-priority 100 \
        connection.multi-connect=3 \
        ipv4.method disabled \
        ipv6.method disabled

Then I created a dispatcher.d script to perform the detection and
activate the detected connection profile:


if [ "$2" != up ] || [ "$CONNECTION_ID" != ethdetect ]; then
        exit 0

# Network detection using arping(8)
# Probe for MAC 00:01:02:03:04:05 at address
if arping -q0 -I "$DEVICE_IFACE" -c1 -C1 -t 00:01:02:03:04:05; then
        # MAC/IP found.  Activate an appropriate connection profile.
        exec nmcli connection up myconn1 ifname "$DEVICE_IFACE"

# Network detection using guessnet(8)
# Runs multiple tests concurrently then prints a matched name or default
detected=$(guessnet -d mydefault "$DEVICE_IFACE" <<'GUESSNET_TESTS'
# At home, look for a host with the given IP and MAC address
home peer 00:01:02:03:04:05

# At the university, check for the presence of at least one
# of the following hosts
university peer 05:06:03:02:01:0A
university peer 15:13:B3:A2:2F:CD
# Activate detected connection profile
exec nmcli connection up "$detected" ifname "$DEFICE_IFACE"

After some brief testing, this appears to work well for my purposes.

Thoughts?  Problems?  Worth adding to nmcli-examples(7)?

Thanks for considering,

P.S.  I am not familiar enough with 802.1x to know whether it's possible
to detect from the ethdetect connection state.  If it can be done in a
few lines, I'd be happy to add that to the example.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]