Signed-off-by: Kurt Van Dijck --- ip/ipaddress.c | 19 ++++++++++++++++--- man/man8/ip-address.8.in | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index e9d9c2e5..4a4a87d9 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1542,9 +1542,13 @@ int print_addrinfo(struct nlmsghdr *n, void *arg) if (filter.family && filter.family != ifa->ifa_family) return 0; - if (filter.have_proto && rta_tb[IFA_PROTO] && - filter.proto != rta_getattr_u8(rta_tb[IFA_PROTO])) - return 0; + if (filter.have_proto) { + __u8 proto = rta_tb[IFA_PROTO] ? + rta_getattr_u8(rta_tb[IFA_PROTO]) : IFAPROT_UNSPEC; + + if (filter.proto != proto) + return 0; + } if (ifa_label_match_rta(ifa->ifa_index, rta_tb[IFA_LABEL])) return 0; @@ -1929,6 +1933,15 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo) if ((filter.flags ^ ifa_flags) & filter.flagmask) continue; + if (filter.have_proto) { + __u8 proto = tb[IFA_PROTO] ? + rta_getattr_u8(tb[IFA_PROTO]) : + IFAPROT_UNSPEC; + + if (filter.proto != proto) + continue; + } + if (ifa_label_match_rta(ifa->ifa_index, tb[IFA_LABEL])) continue; diff --git a/man/man8/ip-address.8.in b/man/man8/ip-address.8.in index 79942c1a..55cb7e63 100644 --- a/man/man8/ip-address.8.in +++ b/man/man8/ip-address.8.in @@ -449,8 +449,9 @@ This is an alias for .TP .BI proto " ADDRPROTO" -Only show addresses with a given protocol, or those for which the kernel -response did not include protocol. See the corresponding argument to +Only show addresses with a given protocol. Addresses for which the kernel +response did not include protocol are considered to have protocol 0. See the +corresponding argument to .B ip address add for details about address protocols. -- 2.55.0