netlink: Avoid left-over bytes in request on MTU configuration
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 <sbrivio@redhat.com>
This commit is contained in:
parent
08b7a2ec38
commit
ed58ad1a59
1 changed files with 7 additions and 4 deletions
|
@ -479,13 +479,16 @@ next:
|
||||||
void nl_link(int ns, unsigned int ifi, void *mac, int up, int mtu)
|
void nl_link(int ns, unsigned int ifi, void *mac, int up, int mtu)
|
||||||
{
|
{
|
||||||
int change = !MAC_IS_ZERO(mac) || up || mtu;
|
int change = !MAC_IS_ZERO(mac) || up || mtu;
|
||||||
struct {
|
struct req_t {
|
||||||
struct nlmsghdr nlh;
|
struct nlmsghdr nlh;
|
||||||
struct ifinfomsg ifm;
|
struct ifinfomsg ifm;
|
||||||
struct rtattr rta;
|
struct rtattr rta;
|
||||||
union {
|
union {
|
||||||
unsigned char mac[ETH_ALEN];
|
unsigned char mac[ETH_ALEN];
|
||||||
|
struct {
|
||||||
unsigned int mtu;
|
unsigned int mtu;
|
||||||
|
uint8_t end;
|
||||||
|
} mtu;
|
||||||
} set;
|
} set;
|
||||||
} req = {
|
} req = {
|
||||||
.nlh.nlmsg_type = change ? RTM_NEWLINK : RTM_GETLINK,
|
.nlh.nlmsg_type = change ? RTM_NEWLINK : RTM_GETLINK,
|
||||||
|
@ -513,8 +516,8 @@ void nl_link(int ns, unsigned int ifi, void *mac, int up, int mtu)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtu) {
|
if (mtu) {
|
||||||
req.nlh.nlmsg_len = sizeof(req);
|
req.nlh.nlmsg_len = offsetof(struct req_t, set.mtu.end);
|
||||||
req.set.mtu = mtu;
|
req.set.mtu.mtu = mtu;
|
||||||
req.rta.rta_type = IFLA_MTU;
|
req.rta.rta_type = IFLA_MTU;
|
||||||
req.rta.rta_len = RTA_LENGTH(sizeof(unsigned int));
|
req.rta.rta_len = RTA_LENGTH(sizeof(unsigned int));
|
||||||
nl_req(ns, buf, &req, req.nlh.nlmsg_len);
|
nl_req(ns, buf, &req, req.nlh.nlmsg_len);
|
||||||
|
|
Loading…
Reference in a new issue