summaryrefslogtreecommitdiffstats
path: root/libnetutils
diff options
context:
space:
mode:
authorErik Kline <ek@google.com>2016-03-30 18:57:13 +0900
committerErik Kline <ek@google.com>2016-03-31 16:00:40 +0900
commite3a769529bbdb9fc2bb583c051329df13c7acf20 (patch)
tree2e40933e072a4f272ee26839edfabafef3b797eb /libnetutils
parent0b5556b5f08ce4db68496a63dd819020f99cbf33 (diff)
downloadcore-e3a769529bbdb9fc2bb583c051329df13c7acf20.tar.gz
core-e3a769529bbdb9fc2bb583c051329df13c7acf20.tar.bz2
core-e3a769529bbdb9fc2bb583c051329df13c7acf20.zip
Set IFA_BROADCAST during IPv4 RTM_NEWADDRs
Bug: 27194345 Bug: 27732412 Bug: 27786864 Change-Id: I5a5b41422bbaab4582c268c213b788f61cb0e169 (cherry picked from commit 06cb8e92034274c6f803e97a17cd07fedf99bde5)
Diffstat (limited to 'libnetutils')
-rw-r--r--libnetutils/ifc_utils.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 85ff070a7..eae32ce36 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -267,10 +267,12 @@ int ifc_act_on_address(int action, const char *name, const char *address,
struct {
struct nlmsghdr n;
struct ifaddrmsg r;
- // Allow for IPv6 address, headers, and padding.
+ // Allow for IPv6 address, headers, IPv4 broadcast addr and padding.
char attrbuf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
NLMSG_ALIGN(sizeof(struct rtattr)) +
- NLMSG_ALIGN(INET6_ADDRLEN)];
+ NLMSG_ALIGN(INET6_ADDRLEN) +
+ NLMSG_ALIGN(sizeof(struct rtattr)) +
+ NLMSG_ALIGN(INET_ADDRLEN)];
} req;
struct rtattr *rta;
struct nlmsghdr *nh;
@@ -325,6 +327,16 @@ int ifc_act_on_address(int action, const char *name, const char *address,
req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(addrlen);
memcpy(RTA_DATA(rta), addr, addrlen);
+ // Add an explicit IFA_BROADCAST for IPv4 RTM_NEWADDRs.
+ if (ss.ss_family == AF_INET && action == RTM_NEWADDR) {
+ rta = (struct rtattr *) (((char *) &req) + NLMSG_ALIGN(req.n.nlmsg_len));
+ rta->rta_type = IFA_BROADCAST;
+ rta->rta_len = RTA_LENGTH(addrlen);
+ req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(addrlen);
+ ((struct in_addr *)addr)->s_addr |= htonl((1<<(32-prefixlen))-1);
+ memcpy(RTA_DATA(rta), addr, addrlen);
+ }
+
s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
if (s < 0) {
return -errno;