Skip to content

Commit eaf4ba1

Browse files
committed
[airos] updated aaa section configuration
many functions are now splitted for the interface mode and can be found in the radius module or the aaa module
1 parent d203d8e commit eaf4ba1

3 files changed

Lines changed: 143 additions & 63 deletions

File tree

netjsonconfig/backends/airos/aaa.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33

44
def ap_none(interface):
5+
"""
6+
Returns the configuration for ``aaa``
7+
when in ``access_point`` mode without authentication
8+
"""
59
return {}
610

711

812
def ap_psk(interface):
13+
"""
14+
Returns the configuration for ``aaa``
15+
when in ``access_point`` mode with psk authentication
16+
"""
917
result = {
1018
'devname': radio(interface),
1119
'driver': 'madwifi',
1220
'ssid': ssid(interface),
1321
'wpa': {
1422
'1.pairwise': 'CCMP',
15-
'key': [
16-
{
17-
'mgmt': 'WPA-PSK',
18-
}
19-
],
23+
'key': [{'mgmt': 'WPA-PSK'}],
2024
'mode': 2,
2125
'psk': psk(interface),
2226
}
@@ -25,14 +29,35 @@ def ap_psk(interface):
2529

2630

2731
def ap_eap(interface):
28-
return {}
32+
"""
33+
Return the configuration for ``aaa``
34+
when in ``access_point`` mode with eap authentication
35+
"""
36+
return {
37+
'devname': radio(interface),
38+
'driver': 'madwifi',
39+
'ssid': ssid(interface),
40+
'wpa': {
41+
'1.pairwise': 'CCMP',
42+
'key': [{'mgmt': 'WPA-EAP'}],
43+
'mode': 2,
44+
},
45+
}
2946

3047

3148
def sta_none(interface):
49+
"""
50+
Return the configuration for ``aaa``
51+
when in station mode without authentication
52+
"""
3253
return {}
3354

3455

3556
def sta_psk(interface):
57+
"""
58+
Return the configuration for ``aaa``
59+
when in station mode with psk authentication
60+
"""
3661
return {
3762
'wpa': {
3863
'psk': psk(interface),
@@ -41,6 +66,10 @@ def sta_psk(interface):
4166

4267

4368
def sta_eap(interface):
69+
"""
70+
Return the configuration for ``aaa``
71+
when in station mode with eap authentication
72+
"""
4473
return {}
4574

4675

@@ -61,6 +90,9 @@ def sta_eap(interface):
6190

6291

6392
def profile_from_interface(interface):
93+
"""
94+
Returns the ``aaa`` configuration for interface
95+
"""
6496
profile = _profile.copy()
6597
profile.update(
6698
_profile_from_mode[mode(interface)][protocol(interface)](interface)
@@ -79,7 +111,7 @@ def profile_from_interface(interface):
79111
'status': 'enabled',
80112
},
81113
'wpa2_enterprise': {
82-
'status': '',
114+
'status': 'enabled',
83115
},
84116
},
85117
'station': {
@@ -90,13 +122,16 @@ def profile_from_interface(interface):
90122
'status': 'disabled',
91123
},
92124
'wpa2_enterprise': {
93-
'status': '',
125+
'status': 'disabled',
94126
},
95127
}
96128
}
97129

98130

99131
def status_from_interface(interface):
132+
"""
133+
Returns ``aaa.status`` from interface
134+
"""
100135
status = _status.copy()
101136
status.update(
102137
_status_from_mode[mode(interface)][protocol(interface)]
@@ -106,12 +141,12 @@ def status_from_interface(interface):
106141

107142
def bridge_devname(wireless_interface, bridge_interface):
108143
"""
109-
when in ``access_point`` with ``wpa2_personal`` authentication set also the
144+
when in ``access_point`` with authentication set also the
110145
bridge interface name
111146
112147
TODO: check if in ``netmode=router`` this happens again
113148
"""
114-
if mode(wireless_interface) == 'access_point' and protocol(wireless_interface) == 'wpa2_personal':
149+
if mode(wireless_interface) == 'access_point' and protocol(wireless_interface) != 'none':
115150
return {
116151
'br': {
117152
'devname': bridge_interface['name'],

netjsonconfig/backends/airos/converters.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ def wireless(self):
5151
"""
5252
return wireless(get_copy(self.netjson, 'interfaces', []))
5353

54-
@property
55-
def radius(self):
56-
original = get_copy(self.netjson, 'radius', {})
57-
return original
58-
5954
def to_intermediate(self):
6055
base = {}
6156
result = []

netjsonconfig/backends/airos/radius.py

Lines changed: 98 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,109 @@
1-
from .interface import mode, protocol
1+
from .interface import encryption, mode, protocol
22

3-
_radius = {
4-
'radius': {
5-
'acct': [
6-
{
7-
'port': 1813,
8-
'status': 'disabled',
9-
}
10-
],
11-
'auth': [
12-
{
13-
'port': 1812,
14-
},
15-
],
16-
},
17-
'status': 'disabled',
3+
def ap_authentication(interface):
4+
"""
5+
Returns the ``radius.auth`` dict for ``access_point`` interface
6+
"""
7+
result = {}
8+
proto = protocol(interface)
9+
if proto == 'wpa2_personal':
10+
result.update({
11+
'status': 'disabled',
12+
})
13+
elif proto == 'wpa2_enterprise':
14+
enc = encryption(interface)
15+
result.update({
16+
'ip': enc.get('server', ''),
17+
'port': enc.get('port', 1812),
18+
'secret': enc.get('key',''),
19+
'status': 'enabled',
20+
})
21+
return result
22+
23+
24+
def sta_authentication(interface):
25+
"""
26+
Returns the ``radius.auth`` dict for ``station`` interface
27+
"""
28+
result = {}
29+
return result
30+
31+
32+
_authentication_from_mode = {
33+
'access_point': ap_authentication,
34+
'station': sta_authentication,
1835
}
1936

20-
_radius_from_mode = {
21-
'access_point': {
22-
'none': {},
23-
'wpa2_personal': {
24-
'radius': {
25-
'auth': [{
26-
'port': 1812,
27-
'status': 'disabled',
28-
}],
29-
'acct': [
30-
{
31-
'port': 1813,
32-
'status': 'disabled',
33-
}
34-
],
35-
'macacl': {
36-
'status': 'disabled',
37-
},
38-
},
39-
'status': 'enabled',
40-
},
41-
'wpa2_enterprise': {},
42-
},
43-
'station': {
44-
'none': {},
45-
'wpa2_personal': {},
46-
'wpa2_enterprise': {},
37+
38+
def authentication(interface):
39+
"""
40+
returns the ``radius.auth`` dict
41+
"""
42+
result = {
43+
'port': 1812,
4744
}
45+
mod = mode(interface)
46+
result.update(_authentication_from_mode[mode(interface)](interface))
47+
return result
48+
49+
50+
def ap_accounting(interface):
51+
result = {}
52+
if protocol(interface) == 'wpa2_enterprise':
53+
enc = encryption(interface)
54+
result.update({
55+
'port': enc.get('acct_server_port', 1813),
56+
'ip': enc.get('acct_server', ''),
57+
'status': 'enabled',
58+
})
59+
return result
60+
61+
def sta_accounting(interface):
62+
return {}
63+
64+
65+
_accounting_from_mode = {
66+
'access_point': ap_accounting,
67+
'station': sta_accounting,
4868
}
4969

5070

71+
def accounting(interface):
72+
"""
73+
Returns the ``radius.acct`` dict
74+
"""
75+
result = {
76+
'port': 1813,
77+
'status': 'disabled',
78+
}
79+
result.update(_accounting_from_mode[mode(interface)](interface))
80+
return result
81+
82+
83+
5184
def radius_from_interface(interface):
52-
radius = _radius.copy()
53-
radius.update(
54-
_radius_from_mode[mode(interface)][protocol(interface)]
55-
)
56-
return radius
85+
"""
86+
Return the ``radius`` configuration for
87+
section ``aaa``
88+
"""
89+
result = {
90+
'radius': {
91+
'auth': [
92+
authentication(interface),
93+
],
94+
'acct': [
95+
accounting(interface),
96+
],
97+
}
98+
}
99+
if protocol(interface) != 'none' and mode(interface) != 'station':
100+
result['radius'].update({
101+
'macacl': {
102+
'status': 'disabled',
103+
},
104+
})
105+
106+
return result
57107

58108

59109
__all__ = [

0 commit comments

Comments
 (0)