Skip to content

Fix usage of mac address patterns in schema.py to allow using variables #238

Open

Description

@lpalgarvio

Hello,
Everytime i try to add a variable to BSSID field on a WiFi interface configured as station,
It breaks the JSON configuration after/during saving.

ie,

        {
            "wireless": {
                "network": [
                    "lan"
                ],
                "mode": "station",
                "radio": "radio1",
                "ssid": "{{wireless_wlan0sta_ssid}}",
                "bssid": "00:11:22:33:44:55",
                "wds": true,
                "encryption": {
                    "protocol": "wpa2_personal",
                    "key": "{{wireless_wlan0sta_key}}",
                    "cipher": "ccmp",
                    "ieee80211w": "1"
                }
            },
            "type": "wireless",
            "name": "radio1sta",
            "network": "wlan1sta"
        },

becomes

        {
            "type": "ethernet",
            "name": "radio1sta",
            "network": "wlan1sta",
            "wireless": {
                "network": [
                    "lan"
                ],
                "mode": "station",
                "radio": "radio1",
                "ssid": "{{wireless_wlan1sta_ssid}}",
                "bssid": "{{wireless_wlan1sta_bsid}}",
                "wds": true,
                "encryption": {
                    "protocol": "wpa2_personal",
                    "key": "{{wireless_wlan1sta_key}}",
                    "cipher": "ccmp",
                    "ieee80211w": "1"
                }
            }
        }

I haven't looked at the code but i can try make a PR sometime later if i find the issue

Activity

  1. nemesifier commented on Jun 19, 2022

    @nemesifier
    Member

    @lpalgarvio I am not sure I understood this, I shall try asap.

  2. lpalgarvio commented on Jun 20, 2022

    @lpalgarvio
    ContributorAuthor

    @lpalgarvio I am not sure I understood this, I shall try asap.

    What i mean to explain is that if you write the first configuration via UI or paste it and then save it,
    when you open the template again it will be changed to the second.

    The templating is broken when a variable is used on the bssid field.

  3. lpalgarvio commented on Jun 20, 2022

    @lpalgarvio
    ContributorAuthor

    The cause is likely this:

            "bssid_wireless_property": {
                "properties": {
                    "bssid": {
                        "type": "string",
                        "title": "BSSID",
                        "pattern": MAC_PATTERN_BLANK,
                        "maxLength": 17,
                        "propertyOrder": 4,
                    },
                }
            },
    

    the pattern and maxLength being used there will probably not allow for a variable.
    Not sure that's possible without refactoring, but should allow either macaddress or variable with macaddress.

    Other places where this can be a problem:

                    "mac": {
                        "type": "string",
                        "title": "MAC address",
                        "description": "if specified overrides default macaddress for this interface",
                        "pattern": MAC_PATTERN_BLANK,  # can be empty
                        "maxLength": 17,
                        "propertyOrder": 3,
                    },
    
            "ssid_wireless_property": {
                "required": ["ssid"],
                "properties": {
                    "ssid": {
                        "type": "string",
                        "title": "SSID",
                        "maxLength": 32,
                        "propertyOrder": 3,
                    } 
                },
            },
    
            "adhoc_wireless_settings": {
                "title": "Adhoc",
                "allOf": [
                    {
                        "required": ["bssid"],
                        "properties": {
                            "mode": {"enum": ["adhoc"]},
                            "bssid": {"pattern": MAC_PATTERN, "minLength": 17},
                        },
                    },
                    {"$ref": "#/definitions/base_wireless_settings"},
                    {"$ref": "#/definitions/ssid_wireless_property"},
                    {"$ref": "#/definitions/bssid_wireless_property"},
                    {"$ref": "#/definitions/encryption_wireless_property_mesh"},
                ],
            },
    

    Maybe we can just fix the formula here:

    MAC_PATTERN = '([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})'
    MAC_PATTERN_BLANK = '^({0}|)$'.format(MAC_PATTERN)
    

    and remove maxLength.

  4. lpalgarvio commented on Jun 20, 2022

    @lpalgarvio
    ContributorAuthor

    The new regex expression suggests this will work fine:

    https://regex101.com/
    ([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([{]{2}.*[}]{2})|(\s)

    Test cases (first is a blank line):

    
    EE:08:6A:A6:8D:D0
    EE-08-6A-A6-8D-D0
    {{wireless_wlan0sta_bssid}}
    
  5. changed the title [-]WiFi Station BSSID does not accept variable properly[/-] [+]Fix usage of mac address patterns in schema.py to allow using variables[/+] on Jun 20, 2022
  6. added 2 commits that reference this issue on Jun 20, 2022
    05b361a
    9b1a5fd
  7. lpalgarvio commented on Jun 20, 2022

    @lpalgarvio
    ContributorAuthor

    @lpalgarvio I am not sure I understood this, I shall try asap.

    PR provided :)

  8. lpalgarvio commented on Jun 20, 2022

    @lpalgarvio
    ContributorAuthor

    intended result
    image

  9. added 2 commits that reference this issue on Jul 26, 2022
    d25fe1b
    a446f78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions