From 74bf32ff9a672008017c23696c0eb7e9e02e6198 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 3 Jul 2017 17:01:43 +0200 Subject: [PATCH] core: ppp: use a different unit for each activation We can't tell pppd to create an interface with a given name, so we use the name generated by kernel and rename the interface afterwards. A race condition can happen during the rename: NM receives the interface name from pppd, but in the meantime the interface could be deleted and another one with that name could appear. In this case we would rename the wrong interface. Using a changing unit index, we ensure that interfaces created by NM don't race with each others. There is still the chance to race with externally-created interfaces, but I guess this is not easily solvable since the pppd plugin does not expose the ifindex. When the specified unit is already in use, the kernel selects another one. --- src/ppp/nm-ppp-manager.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index fec7ce375f..06703366f3 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -678,6 +678,7 @@ create_pppd_cmd_line (NMPPPManager *self, const char *pppd_binary = NULL; NMCmdLine *cmd; gboolean ppp_debug; + static int unit; g_return_val_if_fail (setting != NULL, NULL); @@ -842,6 +843,15 @@ create_pppd_cmd_line (NMPPPManager *self, nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN); + if (pppoe && nm_setting_pppoe_get_parent (pppoe)) { + /* The PPP interface is going to be renamed, so pass a + * different unit each time so that activations don't + * race with each others. */ + nm_cmd_line_add_string (cmd, "unit"); + nm_cmd_line_add_int (cmd, unit); + unit = unit < G_MAXINT ? unit + 1 : 0; + } + return cmd; }