10static char *
iface =
"ovpn-dummy0";
15 printf(
"CMD: ip link set %s %s\n",
iface, up ?
"up" :
"down");
17 return net_iface_up(NULL,
iface, up);
23 return net_iface_new(NULL, name, type, NULL);
30 int ret = net_iface_type(NULL, name, ret_type);
33 assert_string_equal(type, ret_type);
42 return net_iface_del(NULL, name);
48 printf(
"CMD: ip link set %s mtu %u\n",
iface, mtu);
50 return net_iface_mtu_set(NULL,
iface, mtu);
59 ret = inet_pton(AF_INET, addr_str, &addr);
67 printf(
"CMD: ip addr add %s/%d dev %s broadcast +\n", addr_str, prefixlen,
iface);
69 return net_addr_v4_add(NULL,
iface, &addr, prefixlen);
78 ret = inet_pton(AF_INET6, addr_str, &addr);
84 printf(
"CMD: ip -6 addr add %s/%d dev %s\n", addr_str, prefixlen,
iface);
86 return net_addr_v6_add(NULL,
iface, &addr, prefixlen);
100 ret = inet_pton(AF_INET, dst_str, &dst);
108 printf(
"CMD: ip route add %s/%d dev %s", dst_str, prefixlen,
iface);
111 printf(
" metric %d", metric);
115 return net_route_v4_add(NULL, &dst, prefixlen, NULL,
iface, 0, metric);
124 if (!dst_str || !gw_str)
129 ret = inet_pton(AF_INET, dst_str, &dst);
135 ret = inet_pton(AF_INET, gw_str, &gw);
144 printf(
"CMD: ip route add %s/%d dev %s via %s", dst_str, prefixlen,
iface, gw_str);
147 printf(
" metric %d", metric);
151 return net_route_v4_add(NULL, &dst, prefixlen, &gw,
iface, 0, metric);
165 ret = inet_pton(AF_INET6, dst_str, &dst);
171 printf(
"CMD: ip -6 route add %s/%d dev %s", dst_str, prefixlen,
iface);
174 printf(
" metric %d", metric);
178 return net_route_v6_add(NULL, &dst, prefixlen, NULL,
iface, 0, metric);
184 struct in6_addr dst, gw;
187 if (!dst_str || !gw_str)
192 ret = inet_pton(AF_INET6, dst_str, &dst);
198 ret = inet_pton(AF_INET6, gw_str, &gw);
204 printf(
"CMD: ip -6 route add %s/%d dev %s via %s", dst_str, prefixlen,
iface, gw_str);
207 printf(
" metric %d", metric);
211 return net_route_v6_add(NULL, &dst, prefixlen, &gw,
iface, 0, metric);
217 printf(
"Usage: %s <0-9>\n", name);
232 if (strcmp(
argv[1],
"test") == 0)
242 test = atoi(
argv[1]);
281 printf(
"invalid test: %d\n", test);
#define IFACE_TYPE_LEN_MAX
static int net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_str, int metric)
static int net__addr_v6_add(const char *addr_str, int prefixlen)
static int net__route_v4_add(const char *dst_str, int prefixlen, int metric)
static int net__iface_del(const char *name)
static int net__iface_new(const char *name, const char *type)
static int net__route_v4_add_gw(const char *dst_str, int prefixlen, const char *gw_str, int metric)
static int net__route_v6_add(const char *dst_str, int prefixlen, int metric)
static int net__iface_mtu_set(uint32_t mtu)
static int net__addr_v4_add(const char *addr_str, int prefixlen)
static int net__iface_type(const char *name, const char *type)
static int net__iface_up(bool up)
int route_tests(void)
Runs the route.c unit tests, returns the number of failures.