]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
charon-nm: Use configured interface name if available
authorTobias Brunner <tobias@strongswan.org>
Fri, 23 Jun 2023 10:13:31 +0000 (12:13 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 26 Jul 2023 13:07:36 +0000 (15:07 +0200)
If connection.interface-name is configured, we use that instead of the
randomly generated name.

References strongswan/strongswan#1747

src/charon-nm/nm/nm_service.c

index 43e6eb73b34e22e83583a306bc0655e4b84b8a41..8570ef0e3e04f47dcdd02692152938e09206f02a 100644 (file)
@@ -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 */