[PATCH net-next v2] ppp: add IFLA_PPP_UNIT netlink attribute

From: Martin Olivier

Date: Fri Mar 13 2026 - 21:18:08 EST


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 <martin.olivier@xxxxxxx>
---
Changes in v2:
- use nl policy to set IFLA_PPP_UNIT min allowed value instead of a manual check in ppp_nl_validate()
- use of nla_get_s32_default() to collect IFLA_PPP_UNIT value
Link to v1: https://lore.kernel.org/netdev/PAWP192MB2411A5E7D3BE1B55E155A92F9747A@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
---
drivers/net/ppp/ppp_generic.c | 3 ++-
include/uapi/linux/if_link.h | 1 +
tools/include/uapi/linux/if_link.h | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index e9b41777be80..3d5d5fe8bad3 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] = NLA_POLICY_MIN(NLA_S32, 0),
};

static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -1316,7 +1317,6 @@ static int ppp_nl_newlink(struct net_device *dev,
struct nlattr **data = params->data;
struct nlattr **tb = params->tb;
struct ppp_config conf = {
- .unit = -1,
.ifname_is_set = true,
};
struct file *file;
@@ -1342,6 +1342,7 @@ static int ppp_nl_newlink(struct net_device *dev,
}

conf.file = file;
+ conf.unit = nla_get_s32_default(data[IFLA_PPP_UNIT], -1);

/* Don't use device name generated by the rtnetlink layer when ifname
* isn't specified. Let ppp_dev_configure() set the device name using
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