mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Rocco Yue <rocco.yue@mediatek.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	David Ahern <dsahern@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, rocco.yue@gmail.com,
	chao.song@mediatek.com, zhuoliang.zhang@mediatek.com
Subject: Re: [PATCH net-next v3] ipv6: add IFLA_INET6_RA_MTU to expose mtu value in the RA message
Date: Mon, 9 Aug 2021 16:43:58 -0600	[thread overview]
Message-ID: <c0a6f817-0225-c863-722c-19c798daaa4b@gmail.com> (raw)
In-Reply-To: <20210809140109.32595-1-rocco.yue@mediatek.com>

On 8/9/21 8:01 AM, Rocco Yue wrote:
> @@ -6129,6 +6136,66 @@ static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
>  		__ipv6_ifa_notify(event, ifp);
>  }
>  
> +static inline size_t inet6_iframtu_msgsize(void)
> +{
> +	return NLMSG_ALIGN(sizeof(struct ifinfomsg))
> +	     + nla_total_size(IFNAMSIZ)	/* IFLA_IFNAME */
> +	     + nla_total_size(4);	/* IFLA_INET6_RA_MTU */
> +}
> +
> +static int inet6_fill_iframtu(struct sk_buff *skb, struct inet6_dev *idev)
> +{
> +	struct net_device *dev = idev->dev;
> +	struct ifinfomsg *hdr;
> +	struct nlmsghdr *nlh;
> +
> +	nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*hdr), 0);
> +	if (!nlh)
> +		return -EMSGSIZE;
> +
> +	hdr = nlmsg_data(nlh);
> +	hdr->ifi_family = AF_INET6;
> +	hdr->__ifi_pad = 0;
> +	hdr->ifi_index = dev->ifindex;
> +	hdr->ifi_flags = dev_get_flags(dev);
> +	hdr->ifi_change = 0;
> +
> +	if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
> +	    nla_put_u32(skb, IFLA_INET6_RA_MTU, idev->ra_mtu))
> +		goto nla_put_failure;
> +
> +	nlmsg_end(skb, nlh);
> +	return 0;
> +
> +nla_put_failure:
> +	nlmsg_cancel(skb, nlh);
> +	return -EMSGSIZE;
> +}
> +
> +void inet6_iframtu_notify(struct inet6_dev *idev)
> +{
> +	struct sk_buff *skb;
> +	struct net *net = dev_net(idev->dev);
> +	int err = -ENOBUFS;
> +
> +	skb = nlmsg_new(inet6_iframtu_msgsize(), GFP_ATOMIC);
> +	if (!skb)
> +		goto errout;
> +
> +	err = inet6_fill_iframtu(skb, idev);
> +	if (err < 0) {
> +		/* -EMSGSIZE implies BUG in inet6_iframtu_msgsize() */
> +		WARN_ON(err == -EMSGSIZE);
> +		kfree_skb(skb);
> +		goto errout;
> +	}
> +	rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFINFO, NULL, GFP_ATOMIC);
> +	return;
> +errout:
> +	if (err < 0)
> +		rtnl_set_sk_err(net, RTNLGRP_IPV6_IFINFO, err);
> +}

pretty sure you don't need to build a new notify function.

> +
>  #ifdef CONFIG_SYSCTL
>  
>  static int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
> diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
> index c467c6419893..a04164cbd77f 100644
> --- a/net/ipv6/ndisc.c
> +++ b/net/ipv6/ndisc.c
> @@ -1496,6 +1496,12 @@ static void ndisc_router_discovery(struct sk_buff *skb)
>  		memcpy(&n, ((u8 *)(ndopts.nd_opts_mtu+1))+2, sizeof(mtu));
>  		mtu = ntohl(n);
>  
> +		if (in6_dev->ra_mtu != mtu) {
> +			in6_dev->ra_mtu = mtu;
> +			inet6_iframtu_notify(in6_dev);
> +			ND_PRINTK(2, info, "update ra_mtu to %d\n", in6_dev->ra_mtu);
> +		}
> +
>  		if (mtu < IPV6_MIN_MTU || mtu > skb->dev->mtu) {
>  			ND_PRINTK(2, warn, "RA: invalid mtu: %d\n", mtu);
>  		} else if (in6_dev->cnf.mtu6 != mtu) {

Since this MTU is getting reported via af_info infrastructure,
rtmsg_ifinfo should be sufficient.

From there use 'ip monitor' to make sure you are not generating multiple
notifications; you may only need this on the error path.

  parent reply	other threads:[~2021-08-09 22:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 14:01 Rocco Yue
2021-08-09 20:53 ` Jakub Kicinski
2021-08-09 22:43 ` David Ahern [this message]
2021-08-10 12:33   ` Rocco Yue
2021-08-11 13:56     ` David Ahern
2021-08-11 18:05       ` David Ahern
2021-08-13  8:07         ` Rocco Yue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0a6f817-0225-c863-722c-19c798daaa4b@gmail.com \
    --to=dsahern@gmail.com \
    --cc=chao.song@mediatek.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=rocco.yue@gmail.com \
    --cc=rocco.yue@mediatek.com \
    --cc=yoshfuji@linux-ipv6.org \
    --cc=zhuoliang.zhang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®