• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
4  */
5 
6 #ifndef TST_NET_H_
7 #define TST_NET_H_
8 
9 #include <arpa/inet.h>
10 #include <netdb.h>
11 #include <netinet/in.h>
12 #include <netinet/ip.h>
13 #include <sys/types.h>
14 
15 void tst_get_in_addr(const char *ip_str, struct in_addr *ip);
16 void tst_get_in6_addr(const char *ip_str, struct in6_addr *ip6);
17 
18 /*
19  * Find valid connection address for a given bound socket
20  */
21 socklen_t tst_get_connect_address(int sock, struct sockaddr_storage *addr);
22 
23 /*
24  * Initialize AF_INET/AF_INET6 socket address structure with address and port
25  */
26 void tst_init_sockaddr_inet(struct sockaddr_in *sa, const char *ip_str, uint16_t port);
27 void tst_init_sockaddr_inet_bin(struct sockaddr_in *sa, uint32_t ip_val, uint16_t port);
28 void tst_init_sockaddr_inet6(struct sockaddr_in6 *sa, const char *ip_str, uint16_t port);
29 void tst_init_sockaddr_inet6_bin(struct sockaddr_in6 *sa, const struct in6_addr *ip_val, uint16_t port);
30 
31 void safe_getaddrinfo(const char *file, const int lineno, const char *src_addr,
32 					  const char *port, const struct addrinfo *hints,
33 					  struct addrinfo **addr_info);
34 
35 /*
36  * Create new network namespace for netdevice/socket tests. A test which calls
37  * tst_setup_netns() must declare the following entries in its struct tst_test:
38  *
39  * .needs_kconfigs = (const char *[]) {
40  *	"CONFIG_USER_NS=y",
41  *	"CONFIG_NET_NS=y",
42  *	NULL
43  * },
44  * .save_restore = (const struct tst_path_val[]) {
45  *	{"/proc/sys/user/max_user_namespaces", "1024", TST_SR_SKIP},
46  *	{}
47  * },
48  */
49 void tst_setup_netns(void);
50 
51 #endif /* TST_NET_H_ */
52