summaryrefslogtreecommitdiffstats
path: root/src/shared/local-addresses.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-031-2/+2
| | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* local-addresses: set ifindex when dump addresses on an interfaceYu Watanabe2021-05-251-1/+1
|
* sd-netlink: do not set route type and table by default for RTM_GETROUTE or ↵Yu Watanabe2021-05-251-0/+8
| | | | friends
* sd-netlink: do not enable dump flag by default for RTM_GETADDR messageYu Watanabe2021-05-251-0/+4
|
* alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()Lennart Poettering2021-05-191-12/+10
| | | | | | | | | | | | | | | | | | | | | | | | We recently started making more use of malloc_usable_size() and rely on it (see the string_erase() story). Given that we don't really support sytems where malloc_usable_size() cannot be trusted beyond statistics anyway, let's go fully in and rework GREEDY_REALLOC() on top of it: instead of passing around and maintaining the currenly allocated size everywhere, let's just derive it automatically from malloc_usable_size(). I am mostly after this for the simplicity this brings. It also brings minor efficiency improvements I guess, but things become so much nicer to look at if we can avoid these allocation size variables everywhere. Note that the malloc_usable_size() man page says relying on it wasn't "good programming practice", but I think it does this for reasons that don't apply here: the greedy realloc logic specifically doesn't rely on the returned extra size, beyond the fact that it is equal or larger than what was requested. (This commit was supposed to be a quick patch btw, but apparently we use the greedy realloc stuff quite a bit across the codebase, so this ends up touching *a*lot* of code.)
* local-addresses: wrap long commentYu Watanabe2021-05-081-3/+4
| | | | Follow-up for 54e6f97bc9931679aa9b895546621b15e0f464a4.
* local-addresses: add helper for determining local "outbound" IP addressesLennart Poettering2021-04-231-2/+183
| | | | | | | | | | | | | | | This adds a small helper, similar in style to local_addresses() and local_gateways() that determines the local "outbound" addresses. What's an "outbound" address supposed to be? The local IP addresses that are the most likely used for outbound communication. It's determined by using connect() towards the default gws on an UDP socket, and then reading the address of the socket this caused it to be bound to. This is not the "public" or "external" IP address of the local system, and is not supposed to be. It's just the local IP addresses that are likely the ones going to be used by the local IP stack for communication with other hosts.
* local-addresses: fix use of uninitialized valueDavid Tardon2021-03-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This can happen if ifi fails to be read from the netlink message and the error is ENODATA. Fixes the following valgrind message when running netstat: ==164141== Conditional jump or move depends on uninitialised value(s) ==164141== at 0x524AE60: address_compare (local-addresses.c:29) ==164141== by 0x48BCC78: msort_with_tmp.part.0 (msort.c:105) ==164141== by 0x48BC9E4: msort_with_tmp (msort.c:45) ==164141== by 0x48BC9E4: msort_with_tmp.part.0 (msort.c:53) ==164141== by 0x48BCF85: msort_with_tmp (msort.c:45) ==164141== by 0x48BCF85: qsort_r (msort.c:297) ==164141== by 0x52500FC: UnknownInlinedFun (sort-util.h:47) ==164141== by 0x52500FC: local_gateways.constprop.0 (local-addresses.c:310) ==164141== by 0x5251C05: _nss_myhostname_gethostbyaddr2_r (nss-myhostname.c:456) ==164141== by 0x5252006: _nss_myhostname_gethostbyaddr_r (nss-myhostname.c:500) ==164141== by 0x498E7FE: gethostbyaddr_r@@GLIBC_2.2.5 (getXXbyYY_r.c:274) ==164141== by 0x498E560: gethostbyaddr (getXXbyYY.c:135) ==164141== by 0x121353: INET_rresolve.constprop.0 (inet.c:212) ==164141== by 0x1135B9: INET_sprint (inet.c:261) ==164141== by 0x121BFC: addr_do_one.constprop.0.isra.0 (netstat.c:1156)
* local-addresses: make returning accumulated list optionalLennart Poettering2020-12-031-10/+8
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* util: make local_gateways() support RT_VIA and RT_MULTIPATHYu Watanabe2020-10-071-29/+86
| | | | Then, `networkctl status` correctly shows gateways.
* local-addresses: filter out any routing tables but the main oneLennart Poettering2019-07-241-1/+7
| | | | Fixes: #13132
* netlink: move local-addresses.[ch] to src/sharedLennart Poettering2019-07-241-0/+254
This code is not part of the public API of sd-netlink, nor used by it internally and hence should not be in the sd-netlink directory. Also, move the test case for it to src/test/.