/***
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-netlink.h"
#include "alloc-util.h"
#include "local-addresses.h"
#include "macro.h"
#include "netlink-util.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;
}
int r;
if (context)
else {
r = sd_netlink_open(&rtnl);
if (r < 0)
return r;
}
if (r < 0)
return r;
if (r < 0)
return r;
for (m = reply; m; m = sd_netlink_message_next(m)) {
struct local_address *a;
unsigned char flags;
r = sd_netlink_message_get_errno(m);
if (r < 0)
return r;
r = sd_netlink_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_netlink_message *m = NULL;
int r;
if (context)
else {
r = sd_netlink_open(&rtnl);
if (r < 0)
return r;
}
if (r < 0)
return r;
r = sd_netlink_message_request_dump(req, true);
if (r < 0)
return r;
if (r < 0)
return r;
for (m = reply; m; m = sd_netlink_message_next(m)) {
struct local_address *a;
int family;
r = sd_netlink_message_get_errno(m);
if (r < 0)
return r;
r = sd_netlink_message_get_type(m, &type);
if (r < 0)
return r;
if (type != RTM_NEWROUTE)
continue;
/* We only care for default routes */
if (r < 0)
return r;
if (dst_len != 0)
continue;
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;
}