From 00b22bb18b4e5aab9c7b4635c043d0ffbcf4707e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 27 Oct 2021 17:12:03 -0400 Subject: [PATCH] Improve autosense of other nics --- confluent_server/confluent/netutil.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/confluent_server/confluent/netutil.py b/confluent_server/confluent/netutil.py index a7a46f62..2952938c 100644 --- a/confluent_server/confluent/netutil.py +++ b/confluent_server/confluent/netutil.py @@ -244,9 +244,23 @@ class NetManager(object): myattribs['current_nic'] = True myattribs['ipv6_address'] = '{0}/{1}'.format(ipv6addr, addr[2]) if '/' not in myattribs.get('ipv6_address', '/'): + ipn = socket.inet_pton(socket.AF_INET6, myattribs['ipv6_address']) + plen = 64 + for addr in get_my_addresses(): + if addr[0] != socket.AF_INET6: + continue + if ipn_on_same_subnet(addr[0], ipn, addr[1], addr[2]): + plen = addr[2] myattribs['ipv6_address'] += '/64' if '/' not in myattribs.get('ipv4_address', '/'): - myattribs['ipv4_address'] += '/16' + ipn = socket.inet_pton(socket.AF_INET, myattribs['ipv4_address']) + plen = 16 + for addr in get_my_addresses(): + if addr[0] != socket.AF_INET: + continue + if ipn_on_same_subnet(addr[0], ipn, addr[1], addr[2]): + plen = addr[2] + myattribs['ipv4_address'] += '/'.format(plen) if 'current_nic' not in myattribs: myattribs['current_nic'] = False