Linux Audio

Check our new training course

Loading...
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __NETWORK_HELPERS_H
  3#define __NETWORK_HELPERS_H
  4#include <arpa/inet.h>
  5#include <sys/socket.h>
  6#include <sys/types.h>
  7#include <linux/types.h>
  8typedef __u16 __sum16;
  9#include <linux/if_ether.h>
 10#include <linux/if_packet.h>
 11#include <linux/ip.h>
 12#include <linux/ipv6.h>
 13#include <linux/ethtool.h>
 14#include <linux/sockios.h>
 15#include <linux/err.h>
 16#include <netinet/tcp.h>
 17#include <bpf/bpf_endian.h>
 18#include <net/if.h>
 19
 20#define MAGIC_VAL 0x1234
 21#define NUM_ITER 100000
 22#define VIP_NUM 5
 23#define MAGIC_BYTES 123
 24
 25struct network_helper_opts {
 
 26	int timeout_ms;
 27	int proto;
 28	/* +ve: Passed to listen() as-is.
 29	 *   0: Default when the test does not set
 30	 *      a particular value during the struct init.
 31	 *      It is changed to 1 before passing to listen().
 32	 *      Most tests only have one on-going connection.
 33	 * -ve: It is changed to 0 before passing to listen().
 34	 *      It is useful to force syncookie without
 35	 *	changing the "tcp_syncookies" sysctl from 1 to 2.
 36	 */
 37	int backlog;
 38	int (*post_socket_cb)(int fd, void *opts);
 39	void *cb_opts;
 40};
 41
 42/* ipv4 test vector */
 43struct ipv4_packet {
 44	struct ethhdr eth;
 45	struct iphdr iph;
 46	struct tcphdr tcp;
 47} __packed;
 48extern struct ipv4_packet pkt_v4;
 49
 50/* ipv6 test vector */
 51struct ipv6_packet {
 52	struct ethhdr eth;
 53	struct ipv6hdr iph;
 54	struct tcphdr tcp;
 55} __packed;
 56extern struct ipv6_packet pkt_v6;
 57
 58int settimeo(int fd, int timeout_ms);
 59int start_server_str(int family, int type, const char *addr_str, __u16 port,
 60		     const struct network_helper_opts *opts);
 61int start_server(int family, int type, const char *addr, __u16 port,
 62		 int timeout_ms);
 
 
 63int *start_reuseport_server(int family, int type, const char *addr_str,
 64			    __u16 port, int timeout_ms,
 65			    unsigned int nr_listens);
 66int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
 67		      const struct network_helper_opts *opts);
 68void free_fds(int *fds, unsigned int nr_close_fds);
 69int client_socket(int family, int type,
 70		  const struct network_helper_opts *opts);
 71int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
 72		    const struct network_helper_opts *opts);
 73int connect_to_addr_str(int family, int type, const char *addr_str, __u16 port,
 74			const struct network_helper_opts *opts);
 75int connect_to_fd(int server_fd, int timeout_ms);
 76int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts);
 77int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms);
 78int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
 79		     int timeout_ms);
 80int make_sockaddr(int family, const char *addr_str, __u16 port,
 81		  struct sockaddr_storage *addr, socklen_t *len);
 82char *ping_command(int family);
 83int get_socket_local_port(int sock_fd);
 84int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 85int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 86
 87struct nstoken;
 88/**
 89 * open_netns() - Switch to specified network namespace by name.
 90 *
 91 * Returns token with which to restore the original namespace
 92 * using close_netns().
 93 */
 94struct nstoken *open_netns(const char *name);
 95void close_netns(struct nstoken *token);
 96int send_recv_data(int lfd, int fd, uint32_t total_bytes);
 97int make_netns(const char *name);
 98int remove_netns(const char *name);
 99
100static __u16 csum_fold(__u32 csum)
101{
102	csum = (csum & 0xffff) + (csum >> 16);
103	csum = (csum & 0xffff) + (csum >> 16);
104
105	return (__u16)~csum;
106}
107
108static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
109					__u32 len, __u8 proto,
110					__wsum csum)
111{
112	__u64 s = csum;
113
114	s += (__u32)saddr;
115	s += (__u32)daddr;
116	s += htons(proto + len);
117	s = (s & 0xffffffff) + (s >> 32);
118	s = (s & 0xffffffff) + (s >> 32);
119
120	return csum_fold((__u32)s);
121}
122
123static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
124				      const struct in6_addr *daddr,
125					__u32 len, __u8 proto,
126					__wsum csum)
127{
128	__u64 s = csum;
129	int i;
130
131	for (i = 0; i < 4; i++)
132		s += (__u32)saddr->s6_addr32[i];
133	for (i = 0; i < 4; i++)
134		s += (__u32)daddr->s6_addr32[i];
135	s += htons(proto + len);
136	s = (s & 0xffffffff) + (s >> 32);
137	s = (s & 0xffffffff) + (s >> 32);
138
139	return csum_fold((__u32)s);
140}
141
142struct tmonitor_ctx;
143
144#ifdef TRAFFIC_MONITOR
145struct tmonitor_ctx *traffic_monitor_start(const char *netns, const char *test_name,
146					   const char *subtest_name);
147void traffic_monitor_stop(struct tmonitor_ctx *ctx);
148#else
149static inline struct tmonitor_ctx *traffic_monitor_start(const char *netns, const char *test_name,
150							 const char *subtest_name)
151{
152	return NULL;
153}
154
155static inline void traffic_monitor_stop(struct tmonitor_ctx *ctx)
156{
157}
158#endif
159
160#endif
v6.2
 1/* SPDX-License-Identifier: GPL-2.0 */
 2#ifndef __NETWORK_HELPERS_H
 3#define __NETWORK_HELPERS_H
 
 4#include <sys/socket.h>
 5#include <sys/types.h>
 6#include <linux/types.h>
 7typedef __u16 __sum16;
 8#include <linux/if_ether.h>
 9#include <linux/if_packet.h>
10#include <linux/ip.h>
11#include <linux/ipv6.h>
 
 
 
12#include <netinet/tcp.h>
13#include <bpf/bpf_endian.h>
 
14
15#define MAGIC_VAL 0x1234
16#define NUM_ITER 100000
17#define VIP_NUM 5
18#define MAGIC_BYTES 123
19
20struct network_helper_opts {
21	const char *cc;
22	int timeout_ms;
23	bool must_fail;
 
 
 
 
 
 
 
 
 
 
 
 
24};
25
26/* ipv4 test vector */
27struct ipv4_packet {
28	struct ethhdr eth;
29	struct iphdr iph;
30	struct tcphdr tcp;
31} __packed;
32extern struct ipv4_packet pkt_v4;
33
34/* ipv6 test vector */
35struct ipv6_packet {
36	struct ethhdr eth;
37	struct ipv6hdr iph;
38	struct tcphdr tcp;
39} __packed;
40extern struct ipv6_packet pkt_v6;
41
42int settimeo(int fd, int timeout_ms);
 
 
43int start_server(int family, int type, const char *addr, __u16 port,
44		 int timeout_ms);
45int start_mptcp_server(int family, const char *addr, __u16 port,
46		       int timeout_ms);
47int *start_reuseport_server(int family, int type, const char *addr_str,
48			    __u16 port, int timeout_ms,
49			    unsigned int nr_listens);
 
 
50void free_fds(int *fds, unsigned int nr_close_fds);
 
 
 
 
 
 
51int connect_to_fd(int server_fd, int timeout_ms);
52int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts);
53int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms);
54int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
55		     int timeout_ms);
56int make_sockaddr(int family, const char *addr_str, __u16 port,
57		  struct sockaddr_storage *addr, socklen_t *len);
58char *ping_command(int family);
 
 
 
59
60struct nstoken;
61/**
62 * open_netns() - Switch to specified network namespace by name.
63 *
64 * Returns token with which to restore the original namespace
65 * using close_netns().
66 */
67struct nstoken *open_netns(const char *name);
68void close_netns(struct nstoken *token);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69#endif