ipaddress: do not add ifa_flags when not necessary
Subsystems (2)
PATCH 1/1 ipaddress: do not add ifa_flags when not necessary
commit 37c9b94ed21d5779acc23d89a4 (add support for extended ifa_flags) introduced a regression:
# ./ip/ip addr add 192.168.0.1/24 dev eth0 RTNETLINK answers: Invalid argument
This is due to old kernels don't support IFA_FLAGS flag, it should be skipped if we don't use this feature at all.
---
ip/ipaddress.c +4 -2
@@ -1398,8 +1398,10 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) } argc--; argv++; } - req.ifa.ifa_flags = ifa_flags; -addattr32 (&req.n,sizeof (req),IFA_FLAGS , ifa_flags); +if (ifa_flags) { + req.ifa.ifa_flags = ifa_flags; +addattr32 (&req.n,sizeof (req),IFA_FLAGS , ifa_flags); + }if (d ==NULL ) {fprintf (stderr,"Not enough information: \"dev\" argument is required.\n" );
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Thu, 3 Apr 2014 23:05:03 -0700
Quoted 6 lines
commit
37c9b94ed21d5779acc23d89a4(add support for extendedifa_flags) introduced a regression:# ./ip/ip addr add 192.168.0.1/24 dev eth0 RTNETLINK answers: Invalid argument
Quoted 6 lines
This is due to old kernels don't support
IFA_FLAGSflag, it should be skipped if we don't use this feature at all.Cc Jiri Pirko <[email protected]>Cc Stephen Hemminger <[email protected]>Signed-off-by Cong Wang <[email protected]>
Your patch doesn't really fully fix the problem.
If the kernel rejects because of presence of the IFA_FLAGS attribute, it will do so for all such cases.
Therefore the guard you need is not whether ifa_flags is NULL, but whether a large enough flag bit is set such that IFA_FLAGS is required.
IFA_FLAGS was added because ifa.ifa_flags is too small for the new values we needed to add.
Quoted 18 lines · David Miller
From: Cong Wang <[email protected]>
Date: Thu, 3 Apr 2014 23:05:03 -0700Quoted 6 lines
commit
37c9b94ed21d5779acc23d89a4(add support for extendedifa_flags) introduced a regression:# ./ip/ip addr add 192.168.0.1/24 dev eth0 RTNETLINK answers: Invalid argumentQuoted 6 lines
This is due to old kernels don't support
IFA_FLAGSflag, it should be skipped if we don't use this feature at all.Cc Jiri Pirko <[email protected]>Cc Stephen Hemminger <[email protected]>Signed-off-by Cong Wang <[email protected]>Your patch doesn't really fully fix the problem.
Quoted 8 lines
If the kernel rejects because of presence of the
IFA_FLAGSattribute, it will do so for all such cases.Therefore the guard you need is not whether
ifa_flagsis NULL, but whether a large enough flag bit is set such thatIFA_FLAGSis required.
IFA_FLAGSwas added because ifa.ifa_flags is too small for the new values we needed to add.
Right, we should use IFA_FLAGS only when ifa_flags > 0xFF.
Thanks!