Skip to content
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

[bug:openwrt] Creating VLAN 802.1q interface without "network" field #335

Open
pandafy opened this issue Jan 9, 2025 · 2 comments
Open
Labels

Comments

@pandafy
Copy link
Member

pandafy commented Jan 9, 2025

Describe the bug
Creating VLAN 802.1q field with a blank interface will generate an invalid configuration.

Steps To Reproduce

Try generating OpenWrt configuration using the following NetJSON

{
            "type": "8021q",
            "name": "br-wifi",
            "network": "",
            "disabled": false,
            "vid": 200,
            "ingress_qos_mapping": [],
            "egress_qos_mapping": []
}

Generated Configuration

config device 'device_'
	option ifname 'br-wifi'
	option name 'br-wifi.200'
	option type '8021q'
	option vid '200'

config interface ''
	option device 'br-wifi.200'
	option enabled '1'
	option proto 'none'
@pandafy pandafy added the bug label Jan 9, 2025
@shwetd19
Copy link

Hey @pandafy @nemesifier , I've analyzed the problem and have a proposed solution.

Issue Analysis

The bug occurs when creating an 802.1q VLAN interface with an empty network field. The current behavior generates an invalid OpenWrt configuration by creating an interface section with an empty name (config interface ''), which is not a valid UCI configuration.

Current Behavior

When the network field is an empty string, the converter still creates an interface section but with an empty name, resulting in:

config interface ''    # <-- This is invalid
    option device 'br-wifi.200'
    option enabled '1'
    option proto 'none'

Expected Behavior

When the network field is empty or not specified, we should only create the device configuration without generating an associated interface section, resulting in:

config device 'device_'
    option ifname 'br-wifi'
    option name 'br-wifi.200'
    option type '8021q'
    option vid '200'

Proposed Solution

We should modify the converter to only generate the interface section when the network field has a valid value. Here's a proposed code change:

def render_interface(self, interface, **kwargs):
    network = interface.get('network')
    # Only generate interface section if network field has a value
    if not network:
        return self._render_device_config(interface)
    
    # Rest of the existing interface rendering code
    ...

This change ensures we maintain backward compatibility while fixing the invalid configuration generation.

Would you like me to prepare a pull request with this fix? Please let me know if you need any clarification or have questions about the proposed solution.

@nemesifier
Copy link
Member

@shwetd19 yes go ahead, no need to ask for permission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants