8static char *
iface =
"ovpn-dummy0";
13 printf(
"CMD: ip link set %s %s\n",
iface, up ?
"up" :
"down");
15 return net_iface_up(NULL,
iface, up);
21 return net_iface_new(NULL, name, type, NULL);
28 int ret = net_iface_type(NULL, name, ret_type);
31 assert_string_equal(type, ret_type);
40 return net_iface_del(NULL, name);
46 printf(
"CMD: ip link set %s mtu %d\n",
iface, mtu);
48 return net_iface_mtu_set(NULL,
iface, mtu);
57 ret = inet_pton(AF_INET, addr_str, &addr);
65 printf(
"CMD: ip addr add %s/%d dev %s broadcast +\n", addr_str, prefixlen,
iface);
67 return net_addr_v4_add(NULL,
iface, &addr, prefixlen);
76 ret = inet_pton(AF_INET6, addr_str, &addr);
82 printf(
"CMD: ip -6 addr add %s/%d dev %s\n", addr_str, prefixlen,
iface);
84 return net_addr_v6_add(NULL,
iface, &addr, prefixlen);
98 ret = inet_pton(AF_INET, dst_str, &dst);
106 printf(
"CMD: ip route add %s/%d dev %s", dst_str, prefixlen,
iface);
109 printf(
" metric %d", metric);
113 return net_route_v4_add(NULL, &dst, prefixlen, NULL,
iface, 0, metric);
122 if (!dst_str || !gw_str)
127 ret = inet_pton(AF_INET, dst_str, &dst);
133 ret = inet_pton(AF_INET, gw_str, &gw);
142 printf(
"CMD: ip route add %s/%d dev %s via %s", dst_str, prefixlen,
iface, gw_str);
145 printf(
" metric %d", metric);
149 return net_route_v4_add(NULL, &dst, prefixlen, &gw,
iface, 0, metric);
163 ret = inet_pton(AF_INET6, dst_str, &dst);
169 printf(
"CMD: ip -6 route add %s/%d dev %s", dst_str, prefixlen,
iface);
172 printf(
" metric %d", metric);
176 return net_route_v6_add(NULL, &dst, prefixlen, NULL,
iface, 0, metric);
182 struct in6_addr dst, gw;
185 if (!dst_str || !gw_str)
190 ret = inet_pton(AF_INET6, dst_str, &dst);
196 ret = inet_pton(AF_INET6, gw_str, &gw);
202 printf(
"CMD: ip -6 route add %s/%d dev %s via %s", dst_str, prefixlen,
iface, gw_str);
205 printf(
" metric %d", metric);
209 return net_route_v6_add(NULL, &dst, prefixlen, &gw,
iface, 0, metric);
215 printf(
"Usage: %s <0-8>\n", name);
230 if (strcmp(
argv[1],
"test") == 0)
240 test = atoi(
argv[1]);
276 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__iface_mtu_set(int mtu)
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__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)