xref: /illumos-gate/usr/src/test/os-tests/tests/mac/mac_ktest_common.h (revision fcdb3229a31dd4ff700c69238814e326aad49098)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2025 Oxide Computer Compnay
14  */
15 
16 #ifndef _MAC_KTEST_COMMON_H
17 #define	_MAC_KTEST_COMMON_H
18 
19 #ifdef	__cplusplus
20 extern "C" {
21 #endif
22 
23 #include <sys/stdbool.h>
24 #include <sys/types.h>
25 #include <sys/types32.h>
26 
27 typedef struct snoop_pkt_hdr {
28 	uint32_t		sph_origlen;
29 	uint32_t		sph_msglen;
30 	uint32_t		sph_totlen;
31 	uint32_t		sph_drops;
32 #if defined(_LP64)
33 	struct timeval32	sph_timestamp;
34 #else
35 #error	"ktest is expected to be 64-bit for now"
36 #endif
37 } snoop_pkt_hdr_t;
38 
39 typedef struct snoop_file_hdr {
40 	char		sfh_magic[8];
41 	uint32_t	sfh_vers;
42 	uint32_t	sfh_mac_type;
43 } snoop_file_hdr_t;
44 
45 typedef struct pkt_cap_iter {
46 	int		pci_fd;
47 	const char	*pci_base;
48 	size_t		pci_map_sz;
49 	size_t		pci_sz;
50 	size_t		pci_offset;
51 } pkt_cap_iter_t;
52 
53 extern pkt_cap_iter_t *pkt_cap_open(int);
54 extern void pkt_cap_close(pkt_cap_iter_t *);
55 extern void pkt_cap_reset(pkt_cap_iter_t *);
56 extern bool pkt_cap_next(pkt_cap_iter_t *, const void **, uint_t *);
57 
58 struct payload_opts {
59 	uint_t		po_padding;
60 	boolean_t	po_cksum_partial;
61 	boolean_t	po_cksum_full;
62 	boolean_t	po_cksum_ipv4;
63 	boolean_t	po_split_ether;
64 	uint_t		po_split_manual;
65 	uint_t		po_mss;
66 };
67 
68 extern char *build_payload(const void *, uint_t, const void *, uint_t,
69     const struct payload_opts *, size_t *);
70 extern char *serialize_pkt_chain(pkt_cap_iter_t *iter, uint_t *sizep);
71 
72 #ifdef	__cplusplus
73 }
74 #endif
75 
76 #endif /* _MAC_KTEST_COMMON_H */
77