diff options
author | Erik Kline | 2016-03-31 02:08:08 -0500 |
---|---|---|
committer | android-build-merger | 2016-03-31 02:08:08 -0500 |
commit | 012d35b7f046f42d97dadd831c8201ecda2daa55 (patch) | |
tree | 32b9627ac752f70b6760e3e3cbe4fcee6018b6f4 /libnetutils | |
parent | 79b5cd7a522b7d7de3958111fbae01798ec63177 (diff) | |
parent | d70991477392eb94c77c1680483cabd26befb50a (diff) | |
download | platform-system-core-012d35b7f046f42d97dadd831c8201ecda2daa55.tar.gz platform-system-core-012d35b7f046f42d97dadd831c8201ecda2daa55.tar.xz platform-system-core-012d35b7f046f42d97dadd831c8201ecda2daa55.zip |
Merge "Set IFA_BROADCAST during IPv4 RTM_NEWADDRs"
am: d709914
* commit 'd70991477392eb94c77c1680483cabd26befb50a':
Set IFA_BROADCAST during IPv4 RTM_NEWADDRs
Change-Id: Id3b47656b716b2adfa531f857c4fa0cb325a971d
Diffstat (limited to 'libnetutils')
-rw-r--r-- | libnetutils/ifc_utils.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index e0a9f7f88..f9f62f8ce 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c | |||
@@ -259,10 +259,12 @@ int ifc_act_on_address(int action, const char *name, const char *address, | |||
259 | struct { | 259 | struct { |
260 | struct nlmsghdr n; | 260 | struct nlmsghdr n; |
261 | struct ifaddrmsg r; | 261 | struct ifaddrmsg r; |
262 | // Allow for IPv6 address, headers, and padding. | 262 | // Allow for IPv6 address, headers, IPv4 broadcast addr and padding. |
263 | char attrbuf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + | 263 | char attrbuf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + |
264 | NLMSG_ALIGN(sizeof(struct rtattr)) + | 264 | NLMSG_ALIGN(sizeof(struct rtattr)) + |
265 | NLMSG_ALIGN(INET6_ADDRLEN)]; | 265 | NLMSG_ALIGN(INET6_ADDRLEN) + |
266 | NLMSG_ALIGN(sizeof(struct rtattr)) + | ||
267 | NLMSG_ALIGN(INET_ADDRLEN)]; | ||
266 | } req; | 268 | } req; |
267 | struct rtattr *rta; | 269 | struct rtattr *rta; |
268 | struct nlmsghdr *nh; | 270 | struct nlmsghdr *nh; |
@@ -317,6 +319,16 @@ int ifc_act_on_address(int action, const char *name, const char *address, | |||
317 | req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(addrlen); | 319 | req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(addrlen); |
318 | memcpy(RTA_DATA(rta), addr, addrlen); | 320 | memcpy(RTA_DATA(rta), addr, addrlen); |
319 | 321 | ||
322 | // Add an explicit IFA_BROADCAST for IPv4 RTM_NEWADDRs. | ||
323 | if (ss.ss_family == AF_INET && action == RTM_NEWADDR) { | ||
324 | rta = (struct rtattr *) (((char *) &req) + NLMSG_ALIGN(req.n.nlmsg_len)); | ||
325 | rta->rta_type = IFA_BROADCAST; | ||
326 | rta->rta_len = RTA_LENGTH(addrlen); | ||
327 | req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(addrlen); | ||
328 | ((struct in_addr *)addr)->s_addr |= htonl((1<<(32-prefixlen))-1); | ||
329 | memcpy(RTA_DATA(rta), addr, addrlen); | ||
330 | } | ||
331 | |||
320 | s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); | 332 | s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); |
321 | if (s < 0) { | 333 | if (s < 0) { |
322 | return -errno; | 334 | return -errno; |