Simplify code that parses ifa_flags.
When parsing an RTM_NEWADDR or RTM_DELADDR, ifaddr is always present (unless the message is invalid). So ifaddr->ifa_flags is always known before any attributes are parsed. Bug: 155005831 Test: atest NetworkStackNextIntegrationTests:IpClientIntegrationTest continues to apss Change-Id: Id1998faccca7d81c1b7f3e85e4912aa22919e94a
This commit is contained in:
parent
3991ca5657
commit
c00d57d353
1 changed files with 4 additions and 6 deletions
|
|
@ -180,7 +180,7 @@ bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
|
||||||
struct ifa_cacheinfo *cacheinfo = nullptr;
|
struct ifa_cacheinfo *cacheinfo = nullptr;
|
||||||
char addrstr[INET6_ADDRSTRLEN] = "";
|
char addrstr[INET6_ADDRSTRLEN] = "";
|
||||||
char ifname[IFNAMSIZ] = "";
|
char ifname[IFNAMSIZ] = "";
|
||||||
uint32_t flags = 0;
|
uint32_t flags;
|
||||||
|
|
||||||
if (!checkRtNetlinkLength(nh, sizeof(*ifaddr)))
|
if (!checkRtNetlinkLength(nh, sizeof(*ifaddr)))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -195,6 +195,9 @@ bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
|
||||||
// For log messages.
|
// For log messages.
|
||||||
const char *msgtype = rtMessageName(type);
|
const char *msgtype = rtMessageName(type);
|
||||||
|
|
||||||
|
// First 8 bits of flags. In practice will always be overridden when parsing IFA_FLAGS below.
|
||||||
|
flags = ifaddr->ifa_flags;
|
||||||
|
|
||||||
struct rtattr *rta;
|
struct rtattr *rta;
|
||||||
int len = IFA_PAYLOAD(nh);
|
int len = IFA_PAYLOAD(nh);
|
||||||
for (rta = IFA_RTA(ifaddr); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
|
for (rta = IFA_RTA(ifaddr); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
|
||||||
|
|
@ -231,10 +234,6 @@ bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
|
||||||
SLOGD("Unknown ifindex %d in %s", ifaddr->ifa_index, msgtype);
|
SLOGD("Unknown ifindex %d in %s", ifaddr->ifa_index, msgtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First 8 bits of flags. In practice will always be overridden by the IFA_FLAGS below,
|
|
||||||
// because that always appears after IFA_ADDRESS. But just in case, support both orders.
|
|
||||||
flags = (flags & 0xffffff00) | ifaddr->ifa_flags;
|
|
||||||
|
|
||||||
} else if (rta->rta_type == IFA_CACHEINFO) {
|
} else if (rta->rta_type == IFA_CACHEINFO) {
|
||||||
// Address lifetime information.
|
// Address lifetime information.
|
||||||
if (maybeLogDuplicateAttribute(cacheinfo, "IFA_CACHEINFO", msgtype))
|
if (maybeLogDuplicateAttribute(cacheinfo, "IFA_CACHEINFO", msgtype))
|
||||||
|
|
@ -249,7 +248,6 @@ bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
|
||||||
cacheinfo = (struct ifa_cacheinfo *) RTA_DATA(rta);
|
cacheinfo = (struct ifa_cacheinfo *) RTA_DATA(rta);
|
||||||
|
|
||||||
} else if (rta->rta_type == IFA_FLAGS) {
|
} else if (rta->rta_type == IFA_FLAGS) {
|
||||||
// In practice IFA_FLAGS is always after IFA_ADDRESS, so this will overwrite the flags.
|
|
||||||
flags = *(uint32_t*)RTA_DATA(rta);
|
flags = *(uint32_t*)RTA_DATA(rta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue