Skip to content

Commit

Permalink
parse-nm: add support for virtual-ethernets
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloegea authored and slyon committed Aug 14, 2023
1 parent f30abdb commit 2bea2b4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/parse-nm.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type_from_str(const char* type_str)
return NETPLAN_DEF_TYPE_BOND;
else if (!g_strcmp0(type_str, "dummy")) /* wokeignore:rule=dummy */
return NETPLAN_DEF_TYPE_DUMMY; /* wokeignore:rule=dummy */
else if (!g_strcmp0(type_str, "veth"))
return NETPLAN_DEF_TYPE_VETH;
else if (!g_strcmp0(type_str, "vlan"))
return NETPLAN_DEF_TYPE_VLAN;
else if ( !g_strcmp0(type_str, "wireguard")
Expand Down Expand Up @@ -674,6 +676,23 @@ netplan_parser_load_keyfile(NetplanParser* npp, const char* filename, GError** e
parse_tunnels(kf, nd);
}

/* Handle veths */
if (nd_type == NETPLAN_DEF_TYPE_VETH) {
g_autofree gchar* veth_peer = g_key_file_get_string(kf, "veth", "peer", NULL);
if (!veth_peer) {
g_warning("netplan: Keyfile: cannot find veth.peer");
return FALSE;
} else {
/*
* Generate a placeholder interface to be the VETH's peer.
* It's required because Network Manager allows the creation of
* VETHs connections with a non-existing peer.
*/
nd->veth_peer_link = netplan_netdef_new(npp, veth_peer, NETPLAN_DEF_TYPE_NM_PLACEHOLDER_, NETPLAN_BACKEND_NM);
_kf_clear_key(kf, "veth", "peer");
}
}

/* remove supported values from passthrough, which have been handled */
if ( nd_type == NETPLAN_DEF_TYPE_ETHERNET
|| nd_type == NETPLAN_DEF_TYPE_WIFI
Expand All @@ -682,6 +701,7 @@ netplan_parser_load_keyfile(NetplanParser* npp, const char* filename, GError** e
|| nd_type == NETPLAN_DEF_TYPE_BOND
|| 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_TUNNEL && nd->tunnel.mode != NETPLAN_TUNNEL_MODE_UNKNOWN))
_kf_clear_key(kf, "connection", "type");

Expand Down
36 changes: 36 additions & 0 deletions tests/parser/test_keyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,3 +1894,39 @@ def test_keyfile_ethernet_random_cloned_mac_address(self):
ethernet.cloned-mac-address: "random"
ipv4.dns-search: ""
'''.format(UUID, UUID)})

def test_veth_pair(self):
self.generate_from_keyfile('''[connection]
id=veth-peer1
uuid={}
type=veth
interface-name=veth-peer1
[veth]
peer=veth-peer2
[ipv4]
method=auto\n'''.format(UUID))
self.assert_netplan({UUID: '''network:
version: 2
virtual-ethernets:
NM-{}:
renderer: NetworkManager
dhcp4: true
peer: "veth-peer2"
networkmanager:
uuid: "{}"
name: "veth-peer1"
passthrough:
connection.interface-name: "veth-peer1"
'''.format(UUID, UUID)})

def test_veth_without_peer(self):
self.generate_from_keyfile('''[connection]
id=veth-peer1
uuid={}
type=veth
interface-name=veth-peer1
[ipv4]
method=auto\n'''.format(UUID), expect_fail=True)

0 comments on commit 2bea2b4

Please sign in to comment.