Skip to contentSkip to conversation

mctp: emit RTM_NEWADDR and RTM_DELADDR

PATCH Superseded Matt Johnston 2 participants 3 messages Dec 15, 2021 – Dec 20, 2021

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Matt Johnston

author maintainer
#0 lore raw

PATCH v2 1/1 mctp: emit RTM_NEWADDR and RTM_DELADDR

Userspace can receive notification of MCTP address changes via RTNLGRP_MCTP_IFADDR rtnetlink multicast group.

---

v2: Simplify error return path, fix local variable ordering

I've left req_skb as-is rather than passing portid, as noted it keeps callers tidier.

 include/uapi/linux/rtnetlink.h |  2 ++
 net/mctp/device.c              | 51 ++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 5 deletions(-)
include/uapi/linux/rtnetlink.h +2 -0
index 5888492a5257..93d934cc4613 100644
@@ -754,6 +754,8 @@ enum rtnetlink_groups {
 #define RTNLGRP_NEXTHOP		RTNLGRP_NEXTHOP
 	RTNLGRP_BRVLAN,
 #define RTNLGRP_BRVLAN		RTNLGRP_BRVLAN
+	RTNLGRP_MCTP_IFADDR,
+#define RTNLGRP_MCTP_IFADDR	RTNLGRP_MCTP_IFADDR
 	__RTNLGRP_MAX
 };
 #define RTNLGRP_MAX	(__RTNLGRP_MAX - 1)
net/mctp/device.c +46 -5

88 lines not on this page · raw message

Signature · 1 line
2.32.0
maintainer
#1 lore raw
Quoted 10 lines · On Wed, 15 Dec 2021 13:32:50 +0800 Matt Johnston wrote:

Userspace can receive notification of MCTP address changes via RTNLGRP_MCTP_IFADDR rtnetlink multicast group.

---

v2: Simplify error return path, fix local variable ordering

I've left req_skb as-is rather than passing portid, as noted it keeps callers tidier.

Sorry for late review.

net/mctp/device.c struct mctp_dev *mctp_dev_get_rtnl(const struct net_device *dev) · line 42

Quoted 7 lines
net/mctp/device.c +5 -2
-static int mctp_fill_addrinfo(struct sk_buff *skb, struct netlink_callback *cb,
-			      struct mctp_dev *mdev, mctp_eid_t eid)
+static int mctp_addrinfo_size(void)
+{
+	return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+		+ nla_total_size(4) // IFA_LOCAL
+		+ nla_total_size(4) // IFA_ADDRESS

why 4? The attributes are u8, no?

Quoted 12 lines
net/mctp/device.c +7 -0
+		;
+}
@@ -127,6 +141,30 @@ static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb)
 	return skb->len;
 }
 
+static void mctp_addr_notify(struct mctp_dev *mdev, mctp_eid_t eid, int msg_type,
+			     struct sk_buff *req_skb, struct nlmsghdr *req_nlh)
+{
+	u32 portid = NETLINK_CB(req_skb).portid;
+	struct net *net = dev_net(mdev->dev);

net/mctp/device.c static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb) · line 158

Quoted 10 lines
net/mctp/device.c +10 -0
+	struct sk_buff *skb;
+	int rc = -ENOBUFS;
+
+	skb = nlmsg_new(mctp_addrinfo_size(), GFP_KERNEL);
+	if (!skb)
+		goto out;
+
+	rc = mctp_fill_addrinfo(skb, mdev, eid, msg_type,
+				portid, req_nlh->nlmsg_seq, 0);
+	if (rc < 0)

How about a customary WARN_ON_ONCE(rc == -EMSGSIZE) here?

Quoted 8 lines
net/mctp/device.c +8 -0
+		goto out;
+
+	rtnl_notify(skb, net, portid, RTNLGRP_MCTP_IFADDR, req_nlh, GFP_KERNEL);
+	return;
+out:
+	kfree_skb(skb);
+	rtnl_set_sk_err(net, RTNLGRP_MCTP_IFADDR, rc);
+}
author maintainer
#2 lore raw
Quoted 9 lines · Jakub Kicinski

return NLMSG_ALIGN(sizeof(struct ifaddrmsg))

net/mctp/device.c struct mctp_dev *mctp_dev_get_rtnl(const struct net_device *dev) · line 42

Quoted 2 lines
net/mctp/device.c +2 -0
+		+ nla_total_size(4) // IFA_LOCAL
+		+ nla_total_size(4) // IFA_ADDRESS

why 4? The attributes are u8, no?

net/mctp/device.c static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb) · line 158

Quoted 1 line
net/mctp/device.c +1 -0
+	if (rc < 0)

How about a customary WARN_ON_ONCE(rc == -EMSGSIZE) here?

Thanks for the review Jakub. Size 4 is a mistake, I'll send v3.

Cheers,
Matt

Quoted 1 line