From: Tobias Brunner Date: Fri, 23 Jun 2023 10:13:31 +0000 (+0200) Subject: charon-nm: Use configured interface name if available X-Git-Tag: android-2.4.2~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8f8d32494e2945f6f43b7ac46fa5d0491b417ec;p=thirdparty%2Fstrongswan.git charon-nm: Use configured interface name if available If connection.interface-name is configured, we use that instead of the randomly generated name. References strongswan/strongswan#1747 --- diff --git a/src/charon-nm/nm/nm_service.c b/src/charon-nm/nm/nm_service.c index 43e6eb73b3..8570ef0e3e 100644 --- a/src/charon-nm/nm/nm_service.c +++ b/src/charon-nm/nm/nm_service.c @@ -138,7 +138,8 @@ static void delete_interface(NMStrongswanPluginPrivate *priv) /** * Create an XFRM or TUN interface */ -static void create_interface(NMStrongswanPluginPrivate *priv) +static void create_interface(NMStrongswanPluginPrivate *priv, + const char *interface_name) { if (priv->xfrmi_manager) { @@ -148,8 +149,15 @@ static void create_interface(NMStrongswanPluginPrivate *priv) /* allocate a random interface ID */ priv->xfrmi_id = random(); - /* use the interface ID to get a unique name, fine if it's cut off */ - snprintf(name, sizeof(name), "nm-xfrm-%" PRIu32, priv->xfrmi_id); + if (interface_name) + { /* use the preferred interface name if one is provided */ + snprintf(name, sizeof(name), "%s", interface_name); + } + else + { + /* use the interface ID to get a unique name, fine if it's cut off */ + snprintf(name, sizeof(name), "nm-xfrm-%" PRIu32, priv->xfrmi_id); + } mtu = lib->settings->get_int(lib->settings, "charon-nm.mtu", XFRMI_DEFAULT_MTU); @@ -900,7 +908,7 @@ static gboolean connect_(NMVpnServicePlugin *plugin, NMConnection *connection, * for NM etc. to play with... */ delete_interface(priv); - create_interface(priv); + create_interface(priv, nm_setting_connection_get_interface_name(conn)); if (priv->xfrmi_id) { /* set the same mark as for IKE packets on the ESP packets so no routing * loop is created if the TS covers the VPN server's IP */