[PATCH] ppp: add IFLA_PPP_UNIT netlink attribute

Martin Olivier <[email protected]> Wed, 11 Mar 2026 08:35:26 +0100
Newsgroups org.kernel.vger.linux-ppp,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <PAWP192MB2411A5E7D3BE1B55E155A92F9747A@PAWP192MB2411.EURP192.PROD.OUTLOOK.COM>
Currently, the PPP rtnetlink API allows creating a new network interface
with a custom ifname, but it lacks the ability to specify a custom PPP
unit id.

Setting a specific unit id is currently only possible with the
PPPIOCNEWUNIT ioctl. If a user-space program also requires a custom
interface name, it must create the interface first with PPPIOCNEWUNIT
and then rename it.

Resolve this by introducing the IFLA_PPP_UNIT netlink attribute. This
allows user-space programs to atomically request both a custom ifname
and a specific PPP unit id during the RTM_NEWLINK creation process,
eliminating the post-creation renaming for this use case.

Signed-off-by: Martin Olivier <[email protected]>
---
 drivers/net/ppp/ppp_generic.c      | 7 +++++++
 include/uapi/linux/if_link.h       | 1 +
 tools/include/uapi/linux/if_link.h | 1 +
 3 files changed, 9 insertions(+)

diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index e9b41777be80..57d0124b9f37 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -1292,6 +1292,7 @@ static int ppp_dev_configure(struct net *src_net, struct net_device *dev,
 
 static const struct nla_policy ppp_nl_policy[IFLA_PPP_MAX + 1] = {
 	[IFLA_PPP_DEV_FD]	= { .type = NLA_S32 },
+	[IFLA_PPP_UNIT]		= { .type = NLA_S32 },
 };
 
 static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -1305,6 +1306,9 @@ static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[],
 	if (nla_get_s32(data[IFLA_PPP_DEV_FD]) < 0)
 		return -EBADF;
 
+	if (data[IFLA_PPP_UNIT] && nla_get_s32(data[IFLA_PPP_UNIT]) < 0)
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -1326,6 +1330,9 @@ static int ppp_nl_newlink(struct net_device *dev,
 	if (!file)
 		return -EBADF;
 
+	if (data[IFLA_PPP_UNIT])
+		conf.unit = nla_get_s32(data[IFLA_PPP_UNIT]);
+
 	/* rtnl_lock is already held here, but ppp_create_interface() locks
 	 * ppp_mutex before holding rtnl_lock. Using mutex_trylock() avoids
 	 * possible deadlock due to lock order inversion, at the cost of
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index e9b5f79e1ee1..40523cd01a8b 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -1477,6 +1477,7 @@ enum {
 enum {
 	IFLA_PPP_UNSPEC,
 	IFLA_PPP_DEV_FD,
+	IFLA_PPP_UNIT,
 	__IFLA_PPP_MAX
 };
 #define IFLA_PPP_MAX (__IFLA_PPP_MAX - 1)
diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h
index 7e46ca4cd31b..150a582ae498 100644
--- a/tools/include/uapi/linux/if_link.h
+++ b/tools/include/uapi/linux/if_link.h
@@ -1465,6 +1465,7 @@ enum {
 enum {
 	IFLA_PPP_UNSPEC,
 	IFLA_PPP_DEV_FD,
+	IFLA_PPP_UNIT,
 	__IFLA_PPP_MAX
 };
 #define IFLA_PPP_MAX (__IFLA_PPP_MAX - 1)
-- 
2.51.0