f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/***
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2013 Tom Gundersen <teg@jklm.no>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen***/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich#include "dhcp-lease-internal.h"
cf0fbc49e67b55f8d346fc94de28c90113505297Thomas Hindoe Paaboel Andersen#include "network-internal.h"
cf0fbc49e67b55f8d346fc94de28c90113505297Thomas Hindoe Paaboel Andersen#include "networkd.h"
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersenstatic void test_deserialize_in_addr(void) {
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen _cleanup_free_ struct in_addr *addresses = NULL;
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen _cleanup_free_ struct in6_addr *addresses6 = NULL;
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen struct in_addr a, b, c;
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen struct in6_addr d, e, f;
a2ba62c719224a4b47751623ca5e8b0333f49721Lennart Poettering int size;
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen const char *addresses_string = "192.168.0.1 0:0:0:0:0:FFFF:204.152.189.116 192.168.0.2 ::1 192.168.0.3 1:0:0:0:0:0:0:8";
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET, "0:0:0:0:0:FFFF:204.152.189.116", &a) == 0);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET6, "192.168.0.1", &d) == 0);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET, "192.168.0.1", &a) == 1);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET, "192.168.0.2", &b) == 1);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET, "192.168.0.3", &c) == 1);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET6, "0:0:0:0:0:FFFF:204.152.189.116", &d) == 1);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET6, "::1", &e) == 1);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(inet_pton(AF_INET6, "1:0:0:0:0:0:0:8", &f) == 1);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen
a2ba62c719224a4b47751623ca5e8b0333f49721Lennart Poettering assert_se((size = deserialize_in_addrs(&addresses, addresses_string)) >= 0);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(size == 3);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(!memcmp(&a, &addresses[0], sizeof(struct in_addr)));
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(!memcmp(&b, &addresses[1], sizeof(struct in_addr)));
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(!memcmp(&c, &addresses[2], sizeof(struct in_addr)));
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen
a2ba62c719224a4b47751623ca5e8b0333f49721Lennart Poettering assert_se((size = deserialize_in6_addrs(&addresses6, addresses_string)) >= 0);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(size == 3);
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(!memcmp(&d, &addresses6[0], sizeof(struct in6_addr)));
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(!memcmp(&e, &addresses6[1], sizeof(struct in6_addr)));
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen assert_se(!memcmp(&f, &addresses6[2], sizeof(struct in6_addr)));
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen}
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovichstatic void test_deserialize_dhcp_routes(void) {
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich size_t size, allocated;
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich {
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich _cleanup_free_ struct sd_dhcp_route *routes = NULL;
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, "") >= 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(size == 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich }
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich {
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich /* no errors */
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich _cleanup_free_ struct sd_dhcp_route *routes = NULL;
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich const char *routes_string = "192.168.0.0/16,192.168.0.1 10.1.2.0/24,10.1.2.1 0.0.0.0/0,10.0.1.1";
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, routes_string) >= 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(size == 3);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[0].dst_addr.s_addr == inet_addr("192.168.0.0"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[0].gw_addr.s_addr == inet_addr("192.168.0.1"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[0].dst_prefixlen == 16);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[1].dst_addr.s_addr == inet_addr("10.1.2.0"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[1].gw_addr.s_addr == inet_addr("10.1.2.1"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[1].dst_prefixlen == 24);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[2].dst_addr.s_addr == inet_addr("0.0.0.0"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[2].gw_addr.s_addr == inet_addr("10.0.1.1"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[2].dst_prefixlen == 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich }
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich {
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich /* error in second word */
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich _cleanup_free_ struct sd_dhcp_route *routes = NULL;
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich const char *routes_string = "192.168.0.0/16,192.168.0.1 10.1.2.0#24,10.1.2.1 0.0.0.0/0,10.0.1.1";
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, routes_string) >= 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(size == 2);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[0].dst_addr.s_addr == inet_addr("192.168.0.0"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[0].gw_addr.s_addr == inet_addr("192.168.0.1"));
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(routes[0].dst_prefixlen == 16);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
5bb14c8651b017983bb9cbd1444969c7a1bda14eTom Gundersen assert_se(routes[1].dst_addr.s_addr == inet_addr("0.0.0.0"));
5bb14c8651b017983bb9cbd1444969c7a1bda14eTom Gundersen assert_se(routes[1].gw_addr.s_addr == inet_addr("10.0.1.1"));
5bb14c8651b017983bb9cbd1444969c7a1bda14eTom Gundersen assert_se(routes[1].dst_prefixlen == 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich }
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich {
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich /* error in every word */
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich _cleanup_free_ struct sd_dhcp_route *routes = NULL;
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich const char *routes_string = "192.168.0.0/55,192.168.0.1 10.1.2.0#24,10.1.2.1 0.0.0.0/0,10.0.1.X";
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, routes_string) >= 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich assert_se(size == 0);
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich }
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich}
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersenstatic int test_load_config(Manager *manager) {
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen int r;
7c99d940c11e4da1863a218b6b70dd16e65b7518Tom Gundersen/* TODO: should_reload, is false if the config dirs do not exist, so
7c99d940c11e4da1863a218b6b70dd16e65b7518Tom Gundersen * so we can't do this test here, move it to a test for paths_check_timestamps
7c99d940c11e4da1863a218b6b70dd16e65b7518Tom Gundersen * directly
7c99d940c11e4da1863a218b6b70dd16e65b7518Tom Gundersen *
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen * assert_se(network_should_reload(manager) == true);
7c99d940c11e4da1863a218b6b70dd16e65b7518Tom Gundersen*/
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen r = manager_load_config(manager);
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen if (r == -EPERM)
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen return r;
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen assert_se(r >= 0);
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen assert_se(manager_should_reload(manager) == false);
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen return 0;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen}
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstatic void test_network_get(Manager *manager, struct udev_device *loopback) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Network *network;
505f8da7325591defe5f751f328bd26915267602Tom Gundersen const struct ether_addr mac = {};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen /* let's assume that the test machine does not have a .network file
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen that applies to the loopback device... */
505f8da7325591defe5f751f328bd26915267602Tom Gundersen assert_se(network_get(manager, loopback, "lo", &mac, &network) == -ENOENT);
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen assert_se(!network);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen}
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersenstatic void test_address_equality(void) {
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen _cleanup_address_free_ Address *a1 = NULL, *a2 = NULL;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
f0213e3796b4dd66e546e2de4d677db319f9171bTom Gundersen assert_se(address_new(&a1) >= 0);
f0213e3796b4dd66e546e2de4d677db319f9171bTom Gundersen assert_se(address_new(&a2) >= 0);
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(NULL, NULL));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(!address_equal(a1, NULL));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(!address_equal(NULL, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a1->family = AF_INET;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(!address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a2->family = AF_INET;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(inet_pton(AF_INET, "192.168.3.9", &a1->in_addr.in));
3ac8e5433f20bfb5e12b918252643106a2de52afTom Gundersen assert_se(!address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(inet_pton(AF_INET, "192.168.3.9", &a2->in_addr.in));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(a1, a2));
3ac8e5433f20bfb5e12b918252643106a2de52afTom Gundersen assert_se(inet_pton(AF_INET, "192.168.3.10", &a1->in_addr_peer.in));
3ac8e5433f20bfb5e12b918252643106a2de52afTom Gundersen assert_se(address_equal(a1, a2));
3ac8e5433f20bfb5e12b918252643106a2de52afTom Gundersen assert_se(inet_pton(AF_INET, "192.168.3.11", &a2->in_addr_peer.in));
3ac8e5433f20bfb5e12b918252643106a2de52afTom Gundersen assert_se(address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a1->prefixlen = 10;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(!address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a2->prefixlen = 10;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a1->family = AF_INET6;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(!address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a2->family = AF_INET6;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::2", &a1->in_addr.in6));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::2", &a2->in_addr.in6));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen a2->prefixlen = 8;
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::1", &a2->in_addr.in6));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen assert_se(!address_equal(a1, a2));
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen}
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint main(void) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen _cleanup_manager_free_ Manager *manager = NULL;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct udev *udev;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct udev_device *loopback;
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen int r;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
09bee74d7a5f266b175baa19892fa84a9da51d7fTom Gundersen test_deserialize_in_addr();
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich test_deserialize_dhcp_routes();
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen test_address_equality();
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen assert_se(manager_new(&manager) >= 0);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen r = test_load_config(manager);
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen if (r == -EPERM)
5347925a59530bd4e6616eb8c8d43a02c3e14c46Tom Gundersen return EXIT_TEST_SKIP;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen udev = udev_new();
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen assert_se(udev);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen assert_se(loopback);
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen assert_se(udev_device_get_ifindex(loopback) == 1);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen test_network_get(manager, loopback);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
505f8da7325591defe5f751f328bd26915267602Tom Gundersen assert_se(manager_rtnl_enumerate_links(manager) >= 0);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen udev_device_unref(loopback);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen udev_unref(udev);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen}