aboutsummaryrefslogtreecommitdiff
path: root/include/tst_netdevice.h
blob: 5e62ba065f4072c7bb8e583450065bf3ca93a51d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright (c) 2021 Linux Test Project
 */

#ifndef TST_NETDEVICE_H
#define TST_NETDEVICE_H

#include "tst_rtnetlink.h"

/* Find device index for given network interface name. */
int tst_netdev_index_by_name(const char *file, const int lineno,
	const char *ifname);
#define NETDEV_INDEX_BY_NAME(ifname) \
	tst_netdev_index_by_name(__FILE__, __LINE__, (ifname))

/* Activate or deactivate network interface */
int tst_netdev_set_state(const char *file, const int lineno,
	const char *ifname, int up);
#define NETDEV_SET_STATE(ifname, up) \
	tst_netdev_set_state(__FILE__, __LINE__, (ifname), (up))

/* Create a connected pair of virtual network devices */
int tst_create_veth_pair(const char *file, const int lineno, int strict,
	const char *ifname1, const char *ifname2);
#define CREATE_VETH_PAIR(ifname1, ifname2) \
	tst_create_veth_pair(__FILE__, __LINE__, 1, (ifname1), (ifname2))

int tst_netdev_add_device(const char *file, const int lineno, int strict,
	const char *ifname, const char *devtype);
#define NETDEV_ADD_DEVICE(ifname, devtype) \
	tst_netdev_add_device(__FILE__, __LINE__, 1, (ifname), (devtype))

int tst_netdev_remove_device(const char *file, const int lineno, int strict,
	const char *ifname);
#define NETDEV_REMOVE_DEVICE(ifname) \
	tst_netdev_remove_device(__FILE__, __LINE__, 1, (ifname))

int tst_netdev_add_address(const char *file, const int lineno, int strict,
	const char *ifname, unsigned int family, const void *address,
	unsigned int prefix, size_t addrlen, unsigned int flags);
#define NETDEV_ADD_ADDRESS(ifname, family, address, prefix, addrlen, flags) \
	tst_netdev_add_address(__FILE__, __LINE__, 1, (ifname), (family), \
		(address), (prefix), (addrlen), (flags))

int tst_netdev_add_address_inet(const char *file, const int lineno, int strict,
	const char *ifname, in_addr_t address, unsigned int prefix,
	unsigned int flags);
#define NETDEV_ADD_ADDRESS_INET(ifname, address, prefix, flags) \
	tst_netdev_add_address_inet(__FILE__, __LINE__, 1, (ifname), \
		(address), (prefix), (flags))

int tst_netdev_remove_address(const char *file, const int lineno, int strict,
	const char *ifname, unsigned int family, const void *address,
	size_t addrlen);
#define NETDEV_REMOVE_ADDRESS(ifname, family, address, addrlen) \
	tst_netdev_remove_address(__FILE__, __LINE__, 1, (ifname), (family), \
		(address), (addrlen))

int tst_netdev_remove_address_inet(const char *file, const int lineno,
	int strict, const char *ifname, in_addr_t address);
#define NETDEV_REMOVE_ADDRESS_INET(ifname, address) \
	tst_netdev_remove_address_inet(__FILE__, __LINE__, 1, (ifname), \
		(address))

int tst_netdev_change_ns_fd(const char *file, const int lineno, int strict,
	const char *ifname, int nsfd);
#define NETDEV_CHANGE_NS_FD(ifname, nsfd) \
	tst_netdev_change_ns_fd(__FILE__, __LINE__, 1, (ifname), (nsfd))

int tst_netdev_change_ns_pid(const char *file, const int lineno, int strict,
	const char *ifname, pid_t nspid);
#define NETDEV_CHANGE_NS_PID(ifname, nspid) \
	tst_netdev_change_ns_pid(__FILE__, __LINE__, 1, (ifname), (nspid))

/*
 * Add new static entry to main routing table. If you specify gateway address,
 * the interface name is optional.
 */
int tst_netdev_add_route(const char *file, const int lineno, int strict,
	const char *ifname, unsigned int family, const void *srcaddr,
	unsigned int srcprefix, size_t srclen, const void *dstaddr,
	unsigned int dstprefix, size_t dstlen, const void *gateway,
	size_t gatewaylen);
#define NETDEV_ADD_ROUTE(ifname, family, srcaddr, srcprefix, srclen, dstaddr, \
	dstprefix, dstlen, gateway, gatewaylen) \
	tst_netdev_add_route(__FILE__, __LINE__, 1, (ifname), (family), \
		(srcaddr), (srcprefix), (srclen), (dstaddr), (dstprefix), \
		(dstlen), (gateway), (gatewaylen))

/*
 * Simplified function for adding IPv4 static route. If you set srcprefix
 * or dstprefix to 0, the corresponding address will be ignored. Interface
 * name is optional if gateway address is non-zero.
 */
int tst_netdev_add_route_inet(const char *file, const int lineno, int strict,
	const char *ifname, in_addr_t srcaddr, unsigned int srcprefix,
	in_addr_t dstaddr, unsigned int dstprefix, in_addr_t gateway);
#define NETDEV_ADD_ROUTE_INET(ifname, srcaddr, srcprefix, dstaddr, dstprefix, \
	gateway) \
	tst_netdev_add_route_inet(__FILE__, __LINE__, 1, (ifname), (srcaddr), \
		(srcprefix), (dstaddr), (dstprefix), (gateway))

/*
 * Remove static entry from main routing table.
 */
int tst_netdev_remove_route(const char *file, const int lineno, int strict,
	const char *ifname, unsigned int family, const void *srcaddr,
	unsigned int srcprefix, size_t srclen, const void *dstaddr,
	unsigned int dstprefix, size_t dstlen, const void *gateway,
	size_t gatewaylen);
#define NETDEV_REMOVE_ROUTE(ifname, family, srcaddr, srcprefix, srclen, \
	dstaddr, dstprefix, dstlen, gateway, gatewaylen) \
	tst_netdev_remove_route(__FILE__, __LINE__, 1, (ifname), (family), \
		(srcaddr), (srcprefix), (srclen), (dstaddr), (dstprefix), \
		(dstlen), (gateway), (gatewaylen))

/*
 * Simplified function for removing IPv4 static route.
 */
int tst_netdev_remove_route_inet(const char *file, const int lineno,
	int strict, const char *ifname, in_addr_t srcaddr,
	unsigned int srcprefix, in_addr_t dstaddr, unsigned int dstprefix,
	in_addr_t gateway);
#define NETDEV_REMOVE_ROUTE_INET(ifname, srcaddr, srcprefix, dstaddr, \
	dstprefix, gateway) \
	tst_netdev_remove_route_inet(__FILE__, __LINE__, 1, (ifname), \
		(srcaddr), (srcprefix), (dstaddr), (dstprefix), (gateway))

/*
 * Add queueing discipline. Network interface name is optional.
 */
int tst_netdev_add_qdisc(const char *file, const int lineno, int strict,
	const char *ifname, unsigned int family, unsigned int parent,
	unsigned int handle, const char *qd_kind,
	const struct tst_rtnl_attr_list *config);
#define NETDEV_ADD_QDISC(ifname, family, parent, handle, qd_kind, config) \
	tst_netdev_add_qdisc(__FILE__, __LINE__, 1, (ifname), (family), \
		(parent), (handle), (qd_kind), (config))

/*
 * Remove queueing discipline.
 */
int tst_netdev_remove_qdisc(const char *file, const int lineno, int strict,
	const char *ifname, unsigned int family, unsigned int parent,
	unsigned int handle, const char *qd_kind);
#define NETDEV_REMOVE_QDISC(ifname, family, parent, handle, qd_kind) \
	tst_netdev_remove_qdisc(__FILE__, __LINE__, 1, (ifname), (family), \
		(parent), (handle), (qd_kind))

/*
 * Add traffic class to queueing discipline. Network interface name is
 * optional.
 */
int tst_netdev_add_traffic_class(const char *file, const int lineno,
	int strict, const char *ifname, unsigned int parent,
	unsigned int handle, const char *qd_kind,
	const struct tst_rtnl_attr_list *config);
#define NETDEV_ADD_TRAFFIC_CLASS(ifname, parent, handle, qd_kind, config) \
	tst_netdev_add_traffic_class(__FILE__, __LINE__, 1, (ifname), \
		(parent), (handle), (qd_kind), (config))

int tst_netdev_remove_traffic_class(const char *file, const int lineno,
	int strict, const char *ifname, unsigned int parent,
	unsigned int handle, const char *qd_kind);
#define NETDEV_REMOVE_TRAFFIC_CLASS(ifname, parent, handle, qd_kind) \
	tst_netdev_remove_traffic_class(__FILE__, __LINE__, 1, (ifname), \
		(parent), (handle), (qd_kind))

/*
 * Add traffic filter to queueing discipline. Protocol should be en ETH_P_*
 * constant in host byte order. Network interface name is optional.
 */
int tst_netdev_add_traffic_filter(const char *file, const int lineno,
	int strict, const char *ifname, unsigned int parent,
	unsigned int handle, unsigned int protocol, unsigned int priority,
	const char *f_kind, const struct tst_rtnl_attr_list *config);
#define NETDEV_ADD_TRAFFIC_FILTER(ifname, parent, handle, protocol, priority, \
	f_kind, config) \
	tst_netdev_add_traffic_filter(__FILE__, __LINE__, 1, (ifname), \
		(parent), (handle), (protocol), (priority), (f_kind), (config))

int tst_netdev_remove_traffic_filter(const char *file, const int lineno,
	int strict, const char *ifname, unsigned int parent,
	unsigned int handle, unsigned int protocol, unsigned int priority,
	const char *f_kind);
#define NETDEV_REMOVE_TRAFFIC_FILTER(ifname, parent, handle, protocol, \
	priority, f_kind) \
	tst_netdev_remove_traffic_filter(__FILE__, __LINE__, 1, (ifname), \
		(parent), (handle), (protocol), (priority), (f_kind))

#endif /* TST_NETDEVICE_H */