Commit graph

14 commits

Author SHA1 Message Date
Elliott Hughes
2ddb20d29d Remove a few glibc #if hacks.
We've updated the corresponding glibc headers so we don't need these
hacks any more.

Bug: http://b/318541070
Test: treehugger
Change-Id: Ic1974f30f9edb2589cc93041822706bc89909882
2024-01-04 16:44:57 -08:00
Elliott Hughes
95646e6666 Add ASSERT_ERRNO and EXPECT_ERRNO (and use them).
We've talked about this many times in the past, but partners struggle to
understand "expected 38, got 22" in these contexts, and I always have to
go and check the header files just to be sure I'm sure.

I actually think the glibc geterrorname_np() function (which would
return "ENOSYS" rather than "Function not implemented") would be more
helpful, but I'll have to go and implement that first, and then come
back.

Being forced to go through all our errno assertions did also make me
want to use a more consistent style for our ENOSYS assertions in
particular --- there's a particularly readable idiom, and I'll also come
back and move more of those checks to the most readable idiom.

I've added a few missing `errno = 0`s before tests, and removed a few
stray `errno = 0`s from tests that don't actually make assertions about
errno, since I had to look at every single reference to errno anyway.

Test: treehugger
Change-Id: Iba7c56f2adc30288c3e00ade106635e515e88179
2023-09-21 14:15:59 -07:00
Elliott Hughes
22950687ee Fix ifaddrs error handling.
An NLMSG_ERROR packet includes an errno value that we should use. Also report
failures to create a socket immediately, rather than falling through to the
send and reporting EBADF.

Bug: http://b/32145516
Bug: http://b/31038971
Test: bionic ifaddr tests on ryu (with broken kernel) and flounder
Change-Id: I84c480c5b75077eb90d40426a9d66d7bffbd3d51
2016-10-14 14:35:26 -07:00
Elliott Hughes
bf97770a86 Rewrite ifaddrs#getifaddrs_INET.
The old implementation was unnecessarily complex, and using the wrong ioctl
for point-to-point destination addresses.

Bug: http://b/27313259
Change-Id: I9cabd17e414ce42b115037a3f828d79843f604f9
2016-02-29 17:58:54 -08:00
Elliott Hughes
7dac8b8aab Fix scope ids for link-local IPv6 addresses from getifaddrs(3).
Bug: http://b/27219454
Change-Id: I7a166ff5553565f7afdab18dd2c703af4d475ab4
2016-02-17 14:38:09 -08:00
Elliott Hughes
2d5e21f00d Fix ifaddrs#getifaddrs_INET flakiness.
The interface name wasn't being nul-terminated for the ioctl. Also clean up
the code a bit to give more useful diagnostics on failure.

Bug: http://b/26887941
Change-Id: I30c6bdc1a32733971a27ed1fb7db9d8239b6262b
2016-02-03 07:42:33 -08:00
Elliott Hughes
89f4e09d8d Merge "Implement if_nameindex(3)/if_freenameindex(3)." 2016-01-19 17:24:16 +00:00
Elliott Hughes
ed57b98758 Implement if_nameindex(3)/if_freenameindex(3).
This is just a subset of the recently-implemented getifaddrs(3), though if
we want to handle interfaces (such as "rmnet_*") that don't have an address,
we need to either expose ifaddrs_storage and keep track of which interfaces
we've already seen (which is pretty messy), or refactor the netlink code so
we can reuse it and just extract the information we need for if_nameindex(3).
This patch goes the latter route.

Also clean up if_nametoindex(3) and if_indextoname(3).

Change-Id: I5ffc5df0bab62286cdda2e7af06f032c767119a8
2016-01-18 12:07:38 -08:00
Yi Kong
64b481c29b Add more tests for getifaddrs(3)
This adds the following two checks:

* getifaddrs sees the same list of interfaces as /sys/class/net.
* IPv4 addresses we get from netdevice(7) agrees with results from
  getifaddrs.

Change-Id: I2f6d79d0b5cde6d98a0f671d1623b6b2bc75b60f
2016-01-14 15:39:26 +00:00
Elliott Hughes
5d84373c69 Add a getifaddrs(3) debugging tool.
...disguised as a test, because that's the easiest way to keep an eye on it.

Change-Id: Iec2531183790d12aec561d27645e5d400f69efbf
2016-01-12 08:45:16 -08:00
Yi Kong
fdb2963e0a Handle AF_PACKET in getifaddr(3).
Also fix a bug where we were mutating the address/broadcast address
of an existing entry rather than the new entry, and use 'const' to
ensure we don't make that mistake again.

Change-Id: I31c127a5d21879b52c85cd0f7ed2e66554a21e39
2016-01-08 19:18:44 -08:00
Elliott Hughes
9cddb482b4 Revert "Revert "Implement getifaddrs(3)/freeifaddrs(3).""
This reverts commit 76814a8250.

This differs from the original in fixing the GCC -Werror build:

  bionic/libc/bionic/ifaddrs.cpp: In function 'void __handle_netlink_response(ifaddrs**, nlmsghdr*)':
  bionic/libc/bionic/ifaddrs.cpp:113:62: error: use of old-style cast [-Werror=old-style-cast]
       ifinfomsg* ifi = reinterpret_cast<ifinfomsg*>(NLMSG_DATA(hdr));

This appears to be a GCC bug; the GCC command-line correctly uses -isystem,
and manually adding #pragma GCC system_header doesn't help. So just turn the
warning off for GCC for now. We won't need to worry about building with GCC
soon anyway.

Bug: http://b/26238832
Change-Id: I01615bd335edf11baf487b1c83a9157cd780f4a1
2016-01-04 13:00:39 -08:00
Yi Kong
76814a8250 Revert "Implement getifaddrs(3)/freeifaddrs(3)."
Werror build broken. Revert while working on a fix.

This reverts commit 0945ed5cc5.

Change-Id: I67edab7a7a3b9aa673ce9d14aa95380f947838a1
2015-12-22 17:47:54 +00:00
Elliott Hughes
0945ed5cc5 Implement getifaddrs(3)/freeifaddrs(3).
Time to dust off the old libcore implementation from gingerbread and add it
to bionic. Unlike the original, this actually looks at both RTM_NEWLINK and
RTM_NEWADDR.

Bug: http://b/26238832
Change-Id: I7bb4b432deb766065b66b9c9ff36ed68249aba82
2015-12-19 14:49:09 -08:00