Skip to content

Commit 4f8d105

Browse files
committed
[openwrt] Added support for "ip6gw" option #86
- updated tests - updated docs Closes #86
1 parent 2ffe2de commit 4f8d105

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

docs/source/backends/openwrt.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Code example:
5555
"type": "ethernet",
5656
"addresses": [
5757
{
58-
"address": "192.168.1.1",
58+
"address": "192.168.1.2",
59+
"gateway": "192.168.1.1",
5960
"mask": 24,
6061
"proto": "static",
6162
"family": "ipv4"
@@ -67,8 +68,9 @@ Code example:
6768
"family": "ipv4"
6869
},
6970
{
70-
"address": "fd87::1",
71-
"mask": 128,
71+
"address": "fd87::2",
72+
"gateway": "fd87::1",
73+
"mask": 64,
7274
"proto": "static",
7375
"family": "ipv6"
7476
}
@@ -83,9 +85,11 @@ Will return the following output::
8385
package network
8486

8587
config interface 'eth0_1'
88+
option gateway '192.168.1.1'
8689
option ifname 'eth0.1'
87-
option ip6addr 'fd87::1/128'
88-
list ipaddr '192.168.1.1/24'
90+
option ip6addr 'fd87::2/64'
91+
option ip6gw 'fd87::1'
92+
list ipaddr '192.168.1.2/24'
8993
list ipaddr '192.168.2.1/24'
9094
option proto 'static'
9195

netjsonconfig/backends/openwrt/converters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def __get_addresses(self, interface):
126126
address['proto'] = 'dhcp' if family == 'ipv4' else 'dhcpv6'
127127
dhcp.append(self.__del_address_keys(address))
128128
continue
129+
if 'gateway' in address:
130+
uci_key = 'gateway' if family == 'ipv4' else 'ip6gw'
131+
interface[uci_key] = address['gateway']
129132
# static
130133
address_key = 'ipaddr' if family == 'ipv4' else 'ip6addr'
131134
static.setdefault(address_key, [])
@@ -178,7 +181,7 @@ def __get_interface(self, interface, uci_name):
178181
del interface['addresses']
179182
return interface
180183

181-
_address_keys = ['address', 'mask', 'family']
184+
_address_keys = ['address', 'mask', 'family', 'gateway']
182185

183186
def __del_address_keys(self, address):
184187
"""

tests/openwrt/test_network.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,28 @@ def test_multiple_ip(self):
4444
"autostart": True,
4545
"addresses": [
4646
{
47-
"address": "192.168.1.1",
47+
"address": "192.168.1.2",
48+
"gateway": "192.168.1.1",
4849
"mask": 24,
4950
"proto": "static",
5051
"family": "ipv4"
5152
},
5253
{
53-
"address": "192.168.2.1",
54+
"address": "192.168.2.3",
5455
"mask": 24,
5556
"proto": "static",
5657
"family": "ipv4"
5758
},
5859
{
59-
"address": "fd87::1",
60-
"mask": 128,
60+
"address": "fd87::2",
61+
"gateway": "fd87::1",
62+
"mask": 64,
6163
"proto": "static",
6264
"family": "ipv6"
6365
},
6466
{
65-
"address": "fd87::2",
66-
"mask": 128,
67+
"address": "fd87::3",
68+
"mask": 64,
6769
"proto": "static",
6870
"family": "ipv6"
6971
}
@@ -75,11 +77,13 @@ def test_multiple_ip(self):
7577
7678
config interface 'eth0_1'
7779
option auto '1'
80+
option gateway '192.168.1.1'
7881
option ifname 'eth0.1'
79-
list ip6addr 'fd87::1/128'
80-
list ip6addr 'fd87::2/128'
81-
list ipaddr '192.168.1.1/24'
82-
list ipaddr '192.168.2.1/24'
82+
list ip6addr 'fd87::2/64'
83+
list ip6addr 'fd87::3/64'
84+
option ip6gw 'fd87::1'
85+
list ipaddr '192.168.1.2/24'
86+
list ipaddr '192.168.2.3/24'
8387
option proto 'static'
8488
""")
8589
self.assertEqual(o.render(), expected)

0 commit comments

Comments
 (0)