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