summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-wireless.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-22 16:00:39 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-22 16:00:39 +0100
commitf90abbe3062a1d687c797ff2f2ffde048430d350 (patch)
tree3d83f14443ba525313b38cb97e377130e86531ee /src/conf_mode/interfaces-wireless.py
parent5f7ca76cb46b86a6f9adcbebe995a54972fa5abf (diff)
downloadvyos-1x-f90abbe3062a1d687c797ff2f2ffde048430d350.tar.gz
vyos-1x-f90abbe3062a1d687c797ff2f2ffde048430d350.zip
wireless: T2151: calculate locally administered MAC address per SSID
According to http://wiki.stocksy.co.uk/wiki/Multiple_SSIDs_with_hostapd every SSID served by access-point should run on its own, locally administered MAC address. Take the phy's interface MAC address as base and calculate a per interface locally administered MAC address.
Diffstat (limited to 'src/conf_mode/interfaces-wireless.py')
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 6528e57f1..40d8912cc 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -22,10 +22,12 @@ from sys import exit
from stat import S_IRWXU,S_IRGRP,S_IXGRP,S_IROTH,S_IXOTH
from pwd import getpwnam
from grp import getgrnam
+from re import findall
from subprocess import Popen, PIPE
from psutil import pid_exists
from netifaces import interfaces
+from netaddr import *
from vyos.ifconfig import EthernetIf
from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
@@ -1329,6 +1331,26 @@ def verify(wifi):
return None
def generate(wifi):
+
+ if not wifi['mac']:
+ # http://wiki.stocksy.co.uk/wiki/Multiple_SSIDs_with_hostapd
+ # generate locally administered MAC address from used phy interface
+ with open('/sys/class/ieee80211/{}/addresses'.format(wifi['phy']), 'r') as f:
+ tmp = EUI(f.read().rstrip()).value
+ # mask last nibble from the MAC address
+ tmp &= 0xfffffffffff0
+ # set locally administered bit in MAC address
+ tmp |= 0x020000000000
+ # we now need to add an offset to our MAC address indicating this
+ # subinterfaces index
+ tmp += int(findall(r'\d+', wifi['intf'])[0])
+
+ # convert integer to "real" MAC address representation
+ mac = EUI(hex(tmp).split('x')[-1])
+ # change dialect to use : as delimiter instead of -
+ mac.dialect = mac_unix_expanded
+ wifi['mac'] = str(mac)
+
pid = 0
# always stop hostapd service first before reconfiguring it
pidfile = get_pid('hostapd', wifi['intf'])