local-addresses.c revision 1d050e1e0a7082e23ee9b31fa0b819cb332b3444
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2008-2011 Lennart Poettering
Copyright 2014 Tom Gundersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-rtnl.h"
#include "rtnl-util.h"
#include "macro.h"
#include "local-addresses.h"
/* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
return -1;
return 1;
return -1;
return 1;
return -1;
return 1;
return -1;
return 1;
return 0;
}
sd_rtnl_message *m;
int r;
if (context)
else {
r = sd_rtnl_open(&rtnl, 0);
if (r < 0)
return r;
}
if (r < 0)
return r;
if (r < 0)
return r;
for (m = reply; m; m = sd_rtnl_message_next(m)) {
struct local_address *a;
unsigned char flags;
r = sd_rtnl_message_get_errno(m);
if (r < 0)
return r;
r = sd_rtnl_message_get_type(m, &type);
if (r < 0)
return r;
if (type != RTM_NEWADDR)
continue;
r = sd_rtnl_message_addr_get_ifindex(m, &ifi);
if (r < 0)
return r;
continue;
r = sd_rtnl_message_addr_get_family(m, &family);
if (r < 0)
return r;
continue;
r = sd_rtnl_message_addr_get_flags(m, &flags);
if (r < 0)
return r;
if (flags & IFA_F_DEPRECATED)
continue;
return -ENOMEM;
r = sd_rtnl_message_addr_get_scope(m, &a->scope);
if (r < 0)
return r;
continue;
switch (family) {
case AF_INET:
if (r < 0) {
if (r < 0)
continue;
}
break;
case AF_INET6:
if (r < 0) {
if (r < 0)
continue;
}
break;
default:
continue;
}
n_list++;
};
if (n_list > 0)
return (int) n_list;
}
sd_rtnl_message *m = NULL;
int r;
if (context)
else {
r = sd_rtnl_open(&rtnl, 0);
if (r < 0)
return r;
}
if (r < 0)
return r;
r = sd_rtnl_message_request_dump(req, true);
if (r < 0)
return r;
if (r < 0)
return r;
for (m = reply; m; m = sd_rtnl_message_next(m)) {
struct local_address *a;
int family;
r = sd_rtnl_message_get_errno(m);
if (r < 0)
return r;
r = sd_rtnl_message_get_type(m, &type);
if (r < 0)
return r;
if (type != RTM_NEWROUTE)
continue;
/* We only care for default routes */
r = sd_rtnl_message_route_get_dst_len(m, &dst_len);
if (r < 0)
return r;
if (dst_len != 0)
continue;
r = sd_rtnl_message_route_get_src_len(m, &src_len);
if (r < 0)
return r;
if (src_len != 0)
continue;
if (r < 0)
return r;
continue;
r = sd_rtnl_message_route_get_family(m, &family);
if (r < 0)
return r;
continue;
return -ENOMEM;
switch (family) {
case AF_INET:
if (r < 0)
continue;
break;
case AF_INET6:
if (r < 0)
continue;
break;
default:
continue;
}
n_list++;
}
if (n_list > 0)
return (int) n_list;
}