ipv6: add IFLA_INET6_RA_MTU to expose mtu value
authorRocco Yue <rocco.yue@mediatek.com>
Fri, 27 Aug 2021 15:04:12 +0000 (23:04 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 28 Aug 2021 00:29:18 +0000 (17:29 -0700)
commit49b99da2c9ce13ffcd93fe3a0f5670791c1d76f7
tree961d50c7c7821c8cf0cb427d209ef1a53174ab4b
parent0975d8b4bfa011b2943c53d3c169277f5e3cf799
ipv6: add IFLA_INET6_RA_MTU to expose mtu value

The kernel provides a "/proc/sys/net/ipv6/conf/<iface>/mtu"
file, which can temporarily record the mtu value of the last
received RA message when the RA mtu value is lower than the
interface mtu, but this proc has following limitations:

(1) when the interface mtu (/sys/class/net/<iface>/mtu) is
updeated, mtu6 (/proc/sys/net/ipv6/conf/<iface>/mtu) will
be updated to the value of interface mtu;
(2) mtu6 (/proc/sys/net/ipv6/conf/<iface>/mtu) only affect
ipv6 connection, and not affect ipv4.

Therefore, when the mtu option is carried in the RA message,
there will be a problem that the user sometimes cannot obtain
RA mtu value correctly by reading mtu6.

After this patch set, if a RA message carries the mtu option,
you can send a netlink msg which nlmsg_type is RTM_GETLINK,
and then by parsing the attribute of IFLA_INET6_RA_MTU to
get the mtu value carried in the RA message received on the
inet6 device. In addition, you can also get a link notification
when ra_mtu is updated so it doesn't have to poll.

In this way, if the MTU values that the device receives from
the network in the PCO IPv4 and the RA IPv6 procedures are
different, the user can obtain the correct ipv6 ra_mtu value
and compare the value of ra_mtu and ipv4 mtu, then the device
can use the lower MTU value for both IPv4 and IPv6.

Signed-off-by: Rocco Yue <rocco.yue@mediatek.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20210827150412.9267-1-rocco.yue@mediatek.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/if_inet6.h
include/uapi/linux/if_link.h
net/ipv6/addrconf.c
net/ipv6/ndisc.c
tools/include/uapi/linux/if_link.h