-
-
Couldn't load subscription status.
- Fork 79
[fix/change] Bridge VLAN filtering parsing raises exception #356 #363
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
Conversation
26bac47 to
1f609a8
Compare
tests/openwrt/test_interfaces_dsa.py
Outdated
| "name": "br-lan.1", | ||
| "mtu": 1500, | ||
| "mac": "61:4A:A0:D7:3F:0E", | ||
| "network": "if_br_lan_1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify the need for this change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe with the changes we discussed it won't be needed to change this line (just for the sake of changing as few lines to tests as possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works fine, I think we should mention in the docs the possibility of overriding the automatically generated VLANs with one example, what do you think?
I have some more questions below.
| if "device" in interface_name: | ||
| interface_name = interface_name.replace("device", "int") | ||
| else: | ||
| interface_name = f"int_{interface_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "int" refer to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, let's update this example:
https://netjsonconfig.openwisp.org/en/1.1.1/backends/openwrt.html#using-vlan-filtering-on-a-bridge
To demonstrate the overriding and set a static IP / DHCP.
| ".name": uci_vlan[".name"], | ||
| # To avoid conflicts, auto-generated interfaces are prefixed with "if" | ||
| # because UCI does not support multiple blocks with the same name. | ||
| ".name": f"if_{uci_name}_{vid}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
| ".name": f"if_{uci_name}_{vid}", | |
| ".name": f"{uci_name}_{vid}", |
tests/openwrt/test_interfaces_dsa.py
Outdated
| "name": "br-lan.1", | ||
| "mtu": 1500, | ||
| "mac": "61:4A:A0:D7:3F:0E", | ||
| "network": "if_br_lan_1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe with the changes we discussed it won't be needed to change this line (just for the sake of changing as few lines to tests as possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing also has a couple issues:
- the UCI name of device objects doesn't match expectations:
device_int_switchinstead ofdevice_switch - the UCI name of bridge-vlan objects also doesn't match expectations:
int_switch_100which should have beenswitch_100but I am suggesting to usevlan_switch_100instead for consistency - same for interface objects:
if_int_switch_100while it should have beenif_switch_100but I am suggesting to just go withswitch_100(for consistency with current norms)
ee9115a to
c96a3ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did another round of testing, here's my findings.
In the original config I see:
config interface 'jail'
option device 'br-lan.80'
option ifname 'jail'
option proto 'dhcp'
After importing and generating again I see:
config interface 'br_lan_80'
option device 'br-lan.80'
option proto 'none'
I'd expect:
config interface 'br_lan_80'
option device 'br-lan.80'
option proto 'dhcp'
This seems to happen because another interface definition overrides it:
config interface 'vlan_br_lan_80'
option device 'br-lan.80'
option proto 'none'
How hard would it be to merge multiple definitions of the same interface (as long as the UCI names are different) instead of overriding?
Eg:
- dhcp client + proto none (no address) = dhcp client
- static ip setup + different static ip setup = 2 ip address objects
- dhcp + static ip = 2 ip address object (1 dhcp and 1 static)
This would be consistent with what we're doing when we convert from NetJSON to UCI.
I also see something that doesn't seem to make sense:
config interface 'vlan_br_lan_80'
option device 'br-lan.80'
list ports 'lan1:t'
list ports 'lan4:t'
list ports 'lan6:u'
option vlan '80'
option proto 'none'
I was expecting:
config bridge-vlan 'vlan_br_lan_80'
option device 'br-lan.80'
list ports 'lan1:t'
list ports 'lan4:t'
list ports 'lan6:u'
option vlan '80'
|
I have tested the changes to parse the configuration tarball provided in the issue description. It generates the following netjson {
"interfaces": [
{
"name": "br-lan",
"type": "bridge",
"vlan_filtering": [
{
"vlan": 100,
"ports": [
{
"ifname": "lan1",
"tagging": "u",
"primary_vid": false
},
{
"ifname": "lan2",
"tagging": "u",
"primary_vid": false
},
{
"ifname": "lan3",
"tagging": "u",
"primary_vid": false
},
{
"ifname": "lan4",
"tagging": "u",
"primary_vid": false
}
]
},
{
"vlan": 178,
"ports": [
{
"ifname": "lan1",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan2",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan3",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan4",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan5",
"tagging": "u",
"primary_vid": false
}
]
},
{
"vlan": 80,
"ports": [
{
"ifname": "lan1",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan4",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan6",
"tagging": "u",
"primary_vid": false
}
]
},
{
"vlan": 70,
"ports": [
{
"ifname": "lan1",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan4",
"tagging": "t",
"primary_vid": false
},
{
"ifname": "lan7",
"tagging": "u",
"primary_vid": false
}
]
}
],
"bridge_members": [
"lan1",
"lan2",
"lan3",
"lan4",
"lan5",
"lan6",
"lan7"
]
},
{
"network": "debug",
"name": "lan8",
"type": "ethernet",
"addresses": [
{
"address": "192.168.1.1",
"mask": 24,
"proto": "static",
"family": "ipv4"
}
]
},
{
"name": "br-lan.178",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4"
}
]
},
{
"name": "br-lan.80",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4"
}
]
},
{
"name": "br-lan.70",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4"
}
]
}
],
"type": "DeviceConfiguration"
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result looks very solid now, thanks @pandafy 👏
Checklist
Reference to Existing Issue
Fixes #356
Fixes #357