summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-rtnl/local-addresses.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-08-12 01:41:42 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-12 01:54:40 +0200
commitee8c45689526ca973407cbb77bce7b96a062c40b (patch)
tree789e44a352ce3a0a5a88af6339117e8deaff0950 /src/libsystemd/sd-rtnl/local-addresses.c
parent1cb5d1f31909c731d93568eb4838cb86e033d783 (diff)
networkd: add minimal client tool "networkd" to query network status
In the long run this should become a full fledged client to networkd (but not before networkd learns bus support). For now, just pull interesting data out of networkd, udev, and rtnl and present it to the user, in a simple but useful output.
Diffstat (limited to 'src/libsystemd/sd-rtnl/local-addresses.c')
-rw-r--r--src/libsystemd/sd-rtnl/local-addresses.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/libsystemd/sd-rtnl/local-addresses.c b/src/libsystemd/sd-rtnl/local-addresses.c
index dd5ccedc9d..c5508856c8 100644
--- a/src/libsystemd/sd-rtnl/local-addresses.c
+++ b/src/libsystemd/sd-rtnl/local-addresses.c
@@ -48,7 +48,7 @@ static int address_compare(const void *_a, const void *_b) {
return 0;
}
-int local_addresses(struct local_address **ret) {
+int local_addresses(sd_rtnl *context, int ifindex, struct local_address **ret) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
_cleanup_free_ struct local_address *list = NULL;
@@ -58,9 +58,13 @@ int local_addresses(struct local_address **ret) {
assert(ret);
- r = sd_rtnl_open(&rtnl, 0);
- if (r < 0)
- return r;
+ if (context)
+ rtnl = sd_rtnl_ref(context);
+ else {
+ r = sd_rtnl_open(&rtnl, 0);
+ if (r < 0)
+ return r;
+ }
r = sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC);
if (r < 0)
@@ -74,6 +78,7 @@ int local_addresses(struct local_address **ret) {
struct local_address *a;
unsigned char flags;
uint16_t type;
+ int ifi;
r = sd_rtnl_message_get_errno(m);
if (r < 0)
@@ -86,6 +91,13 @@ int local_addresses(struct local_address **ret) {
if (type != RTM_NEWADDR)
continue;
+ r = sd_rtnl_message_addr_get_ifindex(m, &ifi);
+ if (r < 0)
+ return r;
+
+ if (ifindex != 0 && ifi != ifindex)
+ continue;
+
r = sd_rtnl_message_addr_get_flags(m, &flags);
if (r < 0)
return r;
@@ -102,7 +114,7 @@ int local_addresses(struct local_address **ret) {
if (r < 0)
return r;
- if (a->scope == RT_SCOPE_HOST || a->scope == RT_SCOPE_NOWHERE)
+ if (ifindex == 0 && (a->scope == RT_SCOPE_HOST || a->scope == RT_SCOPE_NOWHERE))
continue;
r = sd_rtnl_message_addr_get_family(m, &a->family);
@@ -133,9 +145,7 @@ int local_addresses(struct local_address **ret) {
continue;
}
- r = sd_rtnl_message_addr_get_ifindex(m, &a->ifindex);
- if (r < 0)
- return r;
+ a->ifindex = ifi;
n_list++;
};