From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 2/3] netlink: Avoid left-over bytes in request on MTU configuration Date: Wed, 23 Feb 2022 11:04:58 +0100 Message-ID: <20220223100459.1035628-2-sbrivio@redhat.com> In-Reply-To: <20220223100459.1035628-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1565116983520688531==" --===============1565116983520688531== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When nl_link() configures the MTU, it shouldn't send extra bytes, otherwise we'll get a kernel warning: netlink: 4 bytes leftover after parsing attributes in process `pasta'. Signed-off-by: Stefano Brivio --- netlink.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/netlink.c b/netlink.c index 532868d..a530f3f 100644 --- a/netlink.c +++ b/netlink.c @@ -479,13 +479,16 @@ next: void nl_link(int ns, unsigned int ifi, void *mac, int up, int mtu) { int change =3D !MAC_IS_ZERO(mac) || up || mtu; - struct { + struct req_t { struct nlmsghdr nlh; struct ifinfomsg ifm; struct rtattr rta; union { unsigned char mac[ETH_ALEN]; - unsigned int mtu; + struct { + unsigned int mtu; + uint8_t end; + } mtu; } set; } req =3D { .nlh.nlmsg_type =3D change ? RTM_NEWLINK : RTM_GETLINK, @@ -513,8 +516,8 @@ void nl_link(int ns, unsigned int ifi, void *mac, int up,= int mtu) } =20 if (mtu) { - req.nlh.nlmsg_len =3D sizeof(req); - req.set.mtu =3D mtu; + req.nlh.nlmsg_len =3D offsetof(struct req_t, set.mtu.end); + req.set.mtu.mtu =3D mtu; req.rta.rta_type =3D IFLA_MTU; req.rta.rta_len =3D RTA_LENGTH(sizeof(unsigned int)); nl_req(ns, buf, &req, req.nlh.nlmsg_len); --=20 2.34.1 --===============1565116983520688531==--