Skip to content

Commit

Permalink
parse-nm: add support for VRF devices
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloegea committed Aug 16, 2023
1 parent 70bff51 commit 3506515
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/parse-nm.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type_from_str(const char* type_str)
return NETPLAN_DEF_TYPE_VETH;
else if (!g_strcmp0(type_str, "vlan"))
return NETPLAN_DEF_TYPE_VLAN;
else if (!g_strcmp0(type_str, "vrf"))
return NETPLAN_DEF_TYPE_VRF;
else if ( !g_strcmp0(type_str, "wireguard")
|| !g_strcmp0(type_str, "vxlan")
|| !g_strcmp0(type_str, "ip-tunnel"))
Expand Down Expand Up @@ -697,6 +699,14 @@ netplan_parser_load_keyfile(NetplanParser* npp, const char* filename, GError** e
}
}

/* Handle VRFs */
if (nd_type == NETPLAN_DEF_TYPE_VRF) {
if (g_key_file_has_key(kf, "vrf", "table", NULL)) {
nd->vrf_table = g_key_file_get_integer(kf, "vrf", "table", NULL);
}
_kf_clear_key(kf, "vrf", "table");
}

/* remove supported values from passthrough, which have been handled */
if ( nd_type == NETPLAN_DEF_TYPE_ETHERNET
|| nd_type == NETPLAN_DEF_TYPE_WIFI
Expand All @@ -706,6 +716,7 @@ netplan_parser_load_keyfile(NetplanParser* npp, const char* filename, GError** e
|| nd_type == NETPLAN_DEF_TYPE_DUMMY /* wokeignore:rule=dummy */
|| nd_type == NETPLAN_DEF_TYPE_VLAN
|| nd_type == NETPLAN_DEF_TYPE_VETH
|| nd_type == NETPLAN_DEF_TYPE_VRF
|| (nd_type == NETPLAN_DEF_TYPE_TUNNEL && nd->tunnel.mode != NETPLAN_TUNNEL_MODE_UNKNOWN))
_kf_clear_key(kf, "connection", "type");

Expand Down
46 changes: 46 additions & 0 deletions tests/parser/test_keyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,3 +1930,49 @@ def test_veth_without_peer(self):
[ipv4]
method=auto\n'''.format(UUID), expect_fail=True)

def test_vrf_basic(self):
self.generate_from_keyfile('''[connection]
id=vrf0
uuid={}
type=vrf
interface-name=vrf0
[vrf]
table=1000
[ipv4]
route1=10.10.0.0/16,10.10.10.1
route1_options=table=1000
method=link-local\n'''.format(UUID))
self.assert_netplan({UUID: '''network:
version: 2
vrfs:
NM-{}:
renderer: NetworkManager
routes:
- to: "10.10.0.0/16"
via: "10.10.10.1"
table: 1000
networkmanager:
uuid: "{}"
name: "vrf0"
passthrough:
connection.interface-name: "vrf0"
'''.format(UUID, UUID)})

def test_vrf_without_table_should_fail(self):
out = self.generate_from_keyfile('''[connection]
id=vrf0
uuid={}
type=vrf
interface-name=vrf0
[vrf]
[ipv4]
route1=10.10.0.0/16,10.10.10.1
route1_options=table=1000
method=link-local\n'''.format(UUID), expect_fail=True)

self.assertIn('missing \'table\' property', out)

0 comments on commit 3506515

Please sign in to comment.