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

RFC: New "networkmanager.passthrough" structure #522

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

daniloegea
Copy link
Collaborator

@daniloegea daniloegea commented Sep 30, 2024

Description

This PR proposes a new format for the networkmanager.passthrough section. The new format was a suggestion from the LP#2080301 bug reporter. It addresses the problem reported in the bug and is future proof against similar problems.

The main problem with the currently used format is that it's ambiguous. The keyfile [group].key=value format is encoded as a string separated by dots. As dots can be used in the key name, it becomes tricky to separate what is the group and what is the key name. A different character could be used but we could eventually hit the same problem.

Arguably we could do something like [group-name-between-brackets]key-name: value. Brackets are forbidden in group names (I think?!). But it still would be a change in the format so I opted for turning each entry into mappings.

Here is how it looks like:

  nm-devices:
    NM-4bf69677-e326-49b4-8e37-2acf3074f6c7:
      renderer: NetworkManager
      networkmanager:
        uuid: "4bf69677-e326-49b4-8e37-2acf3074f6c7"
        name: "tuntap7"
        passthrough:
          connection:
            type: "tun"
            autoconnect: "false"
            interface-name: "tuntap7"
          proxy: {}
          tun: {}
          ipv4:
            method: "manual"
            address1: "4.3.2.1/24,1.2.3.254"
            dns: "1.2.3.254;4.3.2.254;"
          ipv6:
            addr-gen-mode: "default"
            method: "manual"
            address1: "1:2:3::4/64,1:2:3::abcd"
            dns: "1:2:3::abcd;abcd:3:2::1;"

With the integration of netplan and Network Manager on Ubuntu, tweaking the passthrough configuration might be necessary every now and then due to things missing in netplan. This format makes it easier to do that.

The old format is still accepted for backwards compatibility. The parser still accepts it but will emit the new format. So YAMLs generated by Network Manager will be updated if the user modifies the connection and it will still work with existing YAMLs if they are never updated.

IMPORTANT: the datalist data structure was replaced with hash tables. This will make the order in which elements are added to keyfiles unpredictable. I'm not 100% sure that ordering would cause problems with configuration from the passthrough section. My main motivation to drop datalists is that GQuarks might leak memory. We hit this issue in our config_fuzzer test due to the number of GQuarks needed when a big number of entries are added to the datalist.

A couple of Network Manager autopkgtests are failing due to the change in the structure and will need to be fixed as well.

I understand it's a big change and we might decide to not merge it so I made it an RFC.

Checklist

  • Runs make check successfully.
  • Retains code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

@daniloegea daniloegea force-pushed the nm_passthrough branch 4 times, most recently from 30a2144 to 5dd0b9e Compare October 1, 2024 11:07
The networkmanager.passthrough section stores raw keyfile information
using a format that can be tricky to interpret. It will concatenate the
group and key names separated by dots. Unfortunately, Network Manager
accepts multiple dots in the middle of both the group and key names.
Because of that it's hard, if even possible, to determine where the
strings must be split.

Ex:
networkmanager:
  passthrough:
    group_name.key_name: value1
    group_name.key_name1: value2

The new format stores the same information in YAML mappings. By using
this format, parsing the group and key names is not needed anymore.

Ex:
networkmanager:
  passthrough:
    group_name:
      key_name1: value1
      key_name2: value2

The datalist data structure was replaced by hash tables. The entire
passthrough section is represented by a hash table indexed by the group
name. Each entry is also a hash table representing all the key/value
entries and it's indexed by the key name.
Now that the datalist was replaced with hash tables, run the generator
with --ignore-errors against the entire dataset. The datalist was
leaking memory and causing ASAN to crash the test.

Also limit the value of path-cost to avoid triggering a g_assert(v <
G_MACUINT).
Now it will generate a mix of old and new formats in the passthrough
section.
When --ignore-errors is used, some netdefs might arrive at the NM config
writers in a bad state. In such cases we just skip them.

Found with config_fuzzer.
@daniloegea daniloegea changed the title WIP: New "networkmanager.passthrough" structure RFC: New "networkmanager.passthrough" structure Oct 1, 2024
@daniloegea daniloegea added the RFC Request for comment (don't merge yet) label Oct 1, 2024
@daniloegea daniloegea marked this pull request as ready for review October 1, 2024 15:15
@daniloegea daniloegea requested a review from slyon October 1, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for comment (don't merge yet)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant