Re: [PATCH net-next v2] mctp: emit RTM_NEWADDR and RTM_DELADDR
flat view
From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-12-17 19:42:58
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. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> --- 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.
quoted hunk ↗ jump to hunk
-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 hunk ↗ jump to hunk
@@ -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); + 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 hunk ↗ jump to hunk
+ 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); +}