Skip to content

Commit

Permalink
Merge 5e5d025 into 307e426
Browse files Browse the repository at this point in the history
  • Loading branch information
okraits committed Aug 17, 2020
2 parents 307e426 + 5e5d025 commit 8ed7cb3
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 13 deletions.
10 changes: 10 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,16 @@
Change log
==========

Version 0.9.0 [unreleased]
--------------------------

- [change] **Potentially backward incompatible**:
added support for dialup interfaces (ppp, pppoe, pppoa,
3g, qmi, ncm, wwan, pptp, 6in4, aiccu or l2tp) to openwrt backend.
This change is backward incompatible if the same type of configuration
was achieved using a workaround, in these cases the configuration
will have to be upgraded to use the new format.

Version 0.8.2 [2020-08-17]
--------------------------

Expand Down
75 changes: 72 additions & 3 deletions docs/source/backends/openwrt.rst
Expand Up @@ -288,11 +288,12 @@ The network interface settings reside in the ``interfaces`` key of the
`NetJSON interface objects <http://netjson.org/rfc.html#interfaces1>`_
(see the link for the detailed specification).

There are 3 main type of interfaces:
There are 4 main types of interfaces:

* **network interfaces**: may be of type ``ethernet``, ``virtual``, ``loopback`` or ``other``
* **wireless interfaces**: must be of type ``wireless``
* **bridge interfaces**: must be of type ``bridge``
* **dialup interfaces**: must be of type ``dialup``

Interface object extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -376,7 +377,12 @@ Will be rendered as follows::

package network

config interface 'eth0' option ifname 'eth0' option ip6addr 'fdb4:5f35:e8fd::1/48' option ipaddr '10.27.251.1' option netmask '255.255.255.0' option proto 'static'
config interface 'eth0'
option ifname 'eth0'
option ip6addr 'fdb4:5f35:e8fd::1/48'
option ipaddr '10.27.251.1'
option netmask '255.255.255.0'
option proto 'static'

DNS servers and search domains
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -431,7 +437,22 @@ Will return the following UCI output::

package network

config interface 'eth0' option dns '10.11.12.13 8.8.8.8' option dns_search 'openwisp.org netjson.org' option ifname 'eth0' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option proto 'static' config interface 'eth1' option dns_search 'openwisp.org netjson.org' option ifname 'eth1' option proto 'dhcp' config interface 'eth1_31' option ifname 'eth1.31' option proto 'none'
config interface 'eth0'
option dns '10.11.12.13 8.8.8.8'
option dns_search 'openwisp.org netjson.org'
option ifname 'eth0'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
option proto 'static'

config interface 'eth1'
option dns_search 'openwisp.org netjson.org'
option ifname 'eth1'
option proto 'dhcp'

config interface 'eth1_31'
option ifname 'eth1.31'
option proto 'none'

DHCP ipv6 ethernet interface
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1190,6 +1211,54 @@ UCI Output::
option password 'test-password'
option ssid 'enterprise-client'

Dialup settings
---------------

Interfaces of type ``dialup`` contain a few options that are specific to dialup connections.

The ``OpenWrt`` backend NetJSON extensions for dialup interfaces:

+--------------+---------+-----------+------------------------------------------------------------------------------------------------------------+
| key name | type | default | allowed values |
+==============+=========+===========+============================================================================================================+
| ``proto`` | string | ``pppoe`` | ``3g``, ``6in4``, ``aiccu``, ``l2tp``, ``ncm``, ``ppp``, ``pppoa``, ``pppoe``, ``pptp``, ``qmi``, ``wwan`` |
+--------------+---------+-----------+------------------------------------------------------------------------------------------------------------+
| ``password`` | string | ``""`` | |
+--------------+---------+-----------+------------------------------------------------------------------------------------------------------------+
| ``username`` | string | ``""`` | |
+--------------+---------+-----------+------------------------------------------------------------------------------------------------------------+

Dialup interface example
~~~~~~~~~~~~~~~~~~~~~~~~

The following *configuration dictionary*:

.. code-block:: python
{
"interfaces": [
{
"name": "dsl0",
"network": "xdsl",
"proto": "pppoe",
"password": "jf93nf82o023$",
"username": "dsluser",
"mtu": 1448
}
]
}
Will be rendered as follows::

package network

config interface 'xdsl'
option ifname 'dsl0'
option proto 'pppoe'
option username 'dsluser'
option password 'jf93nf82o023$'
option mtu '1448'

Radio settings
--------------

Expand Down
12 changes: 11 additions & 1 deletion netjsonconfig/backends/openwrt/converters/interfaces.py
Expand Up @@ -248,7 +248,8 @@ def __netjson_addresses(self, interface):
return interface
if proto not in ['static', 'dhcp', 'dhcpv6', 'none']:
interface['proto'] = proto
interface['type'] = 'other'
interface['type'] = self.__get_special_interface_type(interface)

addresses = []
ipv4 = interface.pop('ipaddr', [])
ipv6 = interface.pop('ip6addr', [])
Expand All @@ -272,6 +273,15 @@ def __netjson_addresses(self, interface):
interface['addresses'] = addresses
return interface

def __get_special_interface_type(self, interface):
username = interface.get('username', False)
password = interface.get('password', False)

if username and password:
return 'dialup'

return 'other'

def __netjson_address(self, address, interface):
ip = ip_interface(address)
family = 'ipv{0}'.format(ip.version)
Expand Down
48 changes: 48 additions & 0 deletions netjsonconfig/backends/openwrt/schema.py
Expand Up @@ -112,6 +112,51 @@
}
]
},
"dialup_interface": {
"title": "Dialup interface",
"required": ["proto", "username", "password"],
"allOf": [
{
"properties": {
"type": {
"type": "string",
"enum": ["dialup"],
"default": "dialup",
"propertyOrder": 1,
},
"proto": {
"type": "string",
"enum": [
"3g",
"6in4",
"aiccu",
"l2tp",
"ncm",
"ppp",
"pppoa",
"pppoe",
"pptp",
"qmi",
"wwan",
],
"default": "pppoe",
"propertyOrder": 8,
},
"username": {
"type": "string",
"description": "username for authentication in protocols like PPPoE",
"propertyOrder": 9,
},
"password": {
"type": "string",
"description": "password for authentication in protocols like PPPoE",
"propertyOrder": 10,
},
}
},
{"$ref": "#/definitions/interface_settings"},
],
},
"base_radio_settings": {
"properties": {
"driver": {
Expand Down Expand Up @@ -165,6 +210,9 @@
"timezone": {"enum": list(timezones.keys()), "default": "UTC"}
}
},
"interfaces": {
"items": {"oneOf": [{"$ref": "#/definitions/dialup_interface"}]}
},
"routes": {
"items": {
"properties": {
Expand Down
42 changes: 42 additions & 0 deletions tests/openwrt/test_dialup.py
@@ -0,0 +1,42 @@
import unittest

from netjsonconfig import OpenWrt
from netjsonconfig.utils import _TabsMixin


class TestDialup(unittest.TestCase, _TabsMixin):
maxDiff = None

_dialup_interface_netjson = {
"interfaces": [
{
"mtu": 1448,
"network": "xdsl",
"type": "dialup",
"name": "dsl0",
"password": "jf93nf82o023$",
"username": "dsluser",
"proto": "pppoe",
},
]
}

_dialup_interface_uci = """package network
config interface 'xdsl'
option ifname 'dsl0'
option mtu '1448'
option password 'jf93nf82o023$'
option proto 'pppoe'
option username 'dsluser'
"""

def test_render_dialup_interface(self):
result = OpenWrt(self._dialup_interface_netjson).render()
expected = self._tabs(self._dialup_interface_uci)
self.assertEqual(result, expected)

def test_parse_dialup_interface(self):
result = OpenWrt(native=self._dialup_interface_uci).config
expected = self._dialup_interface_netjson
self.assertDictEqual(result, expected)
14 changes: 5 additions & 9 deletions tests/openwrt/test_interfaces.py
Expand Up @@ -601,25 +601,21 @@ def test_parse_custom_proto(self):
native = self._tabs(
"""package network
config interface 'ppp0'
config interface 'custom_if0'
option device '/dev/usb/modem1'
option ifname 'ppp0'
option ifname 'custom_if0'
option ipv6 '1'
option keepalive '3'
option password 'pwd0123'
option proto 'ppp'
option username 'user1'
option proto 'custom'
"""
)
expected = {
"interfaces": [
{
"name": "ppp0",
"name": "custom_if0",
"type": "other",
"proto": "ppp",
"proto": "custom",
"device": "/dev/usb/modem1",
"username": "user1",
"password": "pwd0123",
"keepalive": '3',
"ipv6": '1',
}
Expand Down

0 comments on commit 8ed7cb3

Please sign in to comment.