New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openwrt] Improve multiple ip address output #59

Closed
nemesisdesign opened this Issue Jan 26, 2017 · 8 comments

Comments

Projects
None yet
2 participants
@nemesisdesign
Member

nemesisdesign commented Jan 26, 2017

Such NetJSON DeviceConfiguration having 1 ipv4 and 1 ipv6 for each interface:

{
    "interfaces": [
        {
            "bridge_members": [
                "eth0.1"
            ],
            "type": "bridge",
            "name": "lan",
            "addresses": [
                {
                    "proto": "static",
                    "family": "ipv4",
                    "mask": 24,
                    "address": "10.40.0.11",
                    "gateway": "10.40.0.9"
                },
                {
                    "proto": "static",
                    "family": "ipv6",
                    "mask": 64,
                    "address": "2001:4c00:893b:fede::1"
                }
            ]
        },
        {
            "type": "ethernet",
            "name": "eth0.24",
            "network": "vlan24",
            "description": "NanoBeam AC verso DiegoApriliana",
            "addresses": [
                {
                    "proto": "static",
                    "family": "ipv4",
                    "mask": 16,
                    "address": "172.16.40.24"
                },
                {
                    "proto": "static",
                    "family": "ipv6",
                    "mask": 128,
                    "address": "2001:4c00:893b:1:40::24"
                }
            ]
        },
        {
            "type": "ethernet",
            "name": "eth0.31",
            "network": "vlan31",
            "description": "NanoBeam AC verso RDP",
            "addresses": [
                {
                    "proto": "static",
                    "family": "ipv4",
                    "mask": 16,
                    "address": "172.16.40.31"
                },
                {
                    "proto": "static",
                    "family": "ipv6",
                    "mask": 128,
                    "address": "2001:4c00:893b:1:40::31"
                }
            ]
        }
    ]
}

generates this UCI output, which is quite messy:

config interface 'lan'
	option ifname 'eth0.1'
	option ipaddr '10.40.0.11'
	option netmask '255.255.255.0'
	option type 'bridge'
	option proto 'static'
	option gateway '10.40.0.9'

config interface 'lan_2'
	option ifname 'br-lan'
	option ip6addr '2001:4c00:893b:fede::1/64'
	option proto 'static'

config interface 'vlan24'
	option description 'NanoBeam AC verso DiegoApriliana'
	option ifname 'eth0.24'
	option ipaddr '172.16.40.24'
	option netmask '255.255.0.0'
	option proto 'static'

config interface 'vlan24_2'
	option description 'NanoBeam AC verso DiegoApriliana'
	option ifname 'eth0.24'
	option ip6addr '2001:4c00:893b:1:40::24/128'
	option proto 'static'

config interface 'vlan31'
	option description 'NanoBeam AC verso RDP'
	option ifname 'eth0.31'
	option ipaddr '172.16.40.31'
	option netmask '255.255.0.0'
	option proto 'static'

config interface 'vlan31_2'
	option description 'NanoBeam AC verso RDP'
	option ifname 'eth0.31'
	option ip6addr '2001:4c00:893b:1:40::31/128'
	option proto 'static'

The following cleaner output would be preferable:

config interface 'lan'
	option ifname 'eth0.1'
	option ipaddr '10.40.0.11'
	option ip6addr '2001:4c00:893b:fede::1/64'
	option netmask '255.255.255.0'
	option type 'bridge'
	option proto 'static'
	option gateway '10.40.0.9'

config interface 'vlan24'
	option description 'NanoBeam AC verso DiegoApriliana'
	option ifname 'eth0.24'
	option ipaddr '172.16.40.24'
	option ip6addr '2001:4c00:893b:1:40::24/128'
	option netmask '255.255.0.0'
	option proto 'static'

config interface 'vlan31'
	option description 'NanoBeam AC verso RDP'
	option ifname 'eth0.31'
	option ipaddr '172.16.40.31'
	option ip6addr '2001:4c00:893b:1:40::31/128'
	option netmask '255.255.0.0'
	option proto 'static'

This issue has lower priority because it's a clean-up task, the generated configuration works anyway, even if ugly.

@ritwickdsouza

This comment has been minimized.

Member

ritwickdsouza commented Mar 31, 2017

Working on it.

@ritwickdsouza

This comment has been minimized.

Member

ritwickdsouza commented Mar 31, 2017

https://github.com/openwisp/netjsonconfig/blob/master/netjsonconfig/backends/openwrt/renderers.py#L98

Is there any other condition when counter becomes greater than 1 ?

@ritwickdsouza

This comment has been minimized.

Member

ritwickdsouza commented Mar 31, 2017

So the expected output for that should be this ?

package network
config interface 'eth0_1'
    option auto '1'
    option ifname 'eth0.1'
    option ipaddr '192.168.1.1'
    option ip6addr 'fd87::1/128'
    option netmask '255.255.255.0'
    option proto 'static'
config interface 'eth0_1_2'
    option auto '1'
    option ifname 'eth0.1'
    option ipaddr '192.168.2.1'
    option ip6addr 'fd87::1/128'
    option netmask '255.255.255.0'
    option proto 'static'
@nemesisdesign

This comment has been minimized.

Member

nemesisdesign commented Apr 1, 2017

@ritwickdsouza no, OpenWRT has a way to specify multiple ip addresses on a single config interface directive.

I need to test something before giving you precise directions on this one.

@ritwickdsouza

This comment has been minimized.

Member

ritwickdsouza commented Apr 1, 2017

Alright. Let me know once your testing is done.

@nemesisdesign

This comment has been minimized.

Member

nemesisdesign commented Apr 1, 2017

@ritwickdsouza I suggest you to announce the result of your work on the mailing list (and on social media if you use any). In the announcement, you could ask the community to help us testing it before releasing it. It's not guaranteed that somebody may help, but you never know :-)

@nemesisdesign

This comment has been minimized.

Member

nemesisdesign commented May 29, 2017

@ritwickdsouza I have been able to work on this issue. It was quite hard, in retrospective I believe it was a good choice to suggest you to work on something else.

You can see my solution in 179659c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment