1/*
2 * Public Domain.
3 */
4
5#ifndef _LIB_NPF_TEST_H_
6#define _LIB_NPF_TEST_H_
7
8#ifdef _KERNEL
9#include <sys/types.h>
10#include <sys/mbuf.h>
11
12#include <netinet/in_systm.h>
13#include <netinet/in.h>
14#include <netinet6/in6.h>
15
16#include <netinet/ip.h>
17#include <netinet/ip6.h>
18#include <netinet/tcp.h>
19#include <netinet/udp.h>
20#include <netinet/ip_icmp.h>
21
22#include <net/if.h>
23#include <net/if_ether.h>
24#include <net/ethertypes.h>
25#endif
26
27#define	IFNAME_DUMMY	"npftest999"
28
29/* Test interfaces and IP addresses. */
30#define	IFNAME_EXT	"npftest0"
31#define	IFNAME_INT	"npftest1"
32#define	IFNAME_TEST	"npftest2"
33
34#define	LOCAL_IP1	"10.1.1.1"
35#define	LOCAL_IP2	"10.1.1.2"
36#define	LOCAL_IP3	"10.1.1.3"
37
38/* Note: RFC 5737 compliant addresses. */
39#define	PUB_IP1		"192.0.2.1"
40#define	PUB_IP2		"192.0.2.2"
41#define	PUB_IP3		"192.0.2.3"
42
43#define	REMOTE_IP1	"192.0.2.101"
44#define	REMOTE_IP2	"192.0.2.102"
45#define	REMOTE_IP3	"192.0.2.103"
46#define	REMOTE_IP4	"192.0.2.104"
47
48#define	LOCAL_IP6	"fd01:203:405:1::1234"
49#define	REMOTE_IP6	"2001:db8:fefe::1010"
50#define	EXPECTED_IP6	"2001:db8:1:d550::1234"
51
52#define	NET_A_IP1	"10.100.7.126"
53#define	NET_B_IP1	"10.255.7.126"
54
55#if defined(_NPF_STANDALONE)
56
57#define	MLEN		512
58
59struct mbuf {
60	unsigned	m_flags;
61	int		m_type;
62	unsigned	m_len;
63	void *		m_next;
64	struct {
65		int	len;
66	} m_pkthdr;
67	void *		m_data;
68	unsigned char	m_data0[MLEN];
69};
70
71#define	MT_FREE			0
72#define	M_UNWRITABLE(m, l)	false
73#define	M_NOWAIT		0x00001
74#define M_PKTHDR		0x00002
75
76#define	m_get(x, y)		npfkern_m_get(NULL, 0, MLEN)
77#define	m_gethdr(x, y)		npfkern_m_get(NULL, M_PKTHDR, MLEN)
78#define	m_length(m)		npfkern_m_length(m)
79#define	m_freem(m)		npfkern_m_freem(m)
80#define	mtod(m, t)		((t)((m)->m_data))
81
82#endif
83
84#define	CHECK_TRUE(x)	\
85    if (!(x)) { printf("FAIL: %s line %d\n", __func__, __LINE__); return 0; }
86
87extern const npf_mbufops_t	npftest_mbufops;
88extern const npf_ifops_t	npftest_ifops;
89
90struct mbuf *	npfkern_m_get(npf_t *, unsigned, size_t);
91size_t		npfkern_m_length(const struct mbuf *);
92void		npfkern_m_freem(struct mbuf *);
93
94void		npf_test_init(int (*)(int, const char *, void *),
95		    const char *(*)(int, const void *, char *, socklen_t),
96		    long (*)(void));
97void		npf_test_fini(void);
98int		npf_test_load(const void *, size_t, bool);
99ifnet_t *	npf_test_addif(const char *, bool, bool);
100ifnet_t *	npf_test_getif(const char *);
101
102int		npf_test_statetrack(const void *, size_t, ifnet_t *,
103		    bool, int64_t *);
104void		npf_test_conc(bool, unsigned);
105
106struct mbuf *	mbuf_getwithdata(const void *, size_t);
107struct mbuf *	mbuf_construct_ether(int);
108struct mbuf *	mbuf_construct(int);
109struct mbuf *	mbuf_construct6(int);
110void *		mbuf_return_hdrs(struct mbuf *, bool, struct ip **);
111void *		mbuf_return_hdrs6(struct mbuf *, struct ip6_hdr **);
112void		mbuf_icmp_append(struct mbuf *, struct mbuf *);
113
114struct mbuf *	mbuf_get_pkt(int, int, const char *, const char *, int, int);
115npf_cache_t *	get_cached_pkt(struct mbuf *, const char *);
116void		put_cached_pkt(npf_cache_t *);
117
118bool		npf_nbuf_test(bool);
119bool		npf_bpf_test(bool);
120bool		npf_table_test(bool, void *, size_t);
121bool		npf_state_test(bool);
122
123bool		npf_rule_test(bool);
124bool		npf_nat_test(bool);
125bool		npf_gc_test(bool);
126
127int		npf_inet_pton(int, const char *, void *);
128const char *	npf_inet_ntop(int, const void *, char *, socklen_t);
129
130#endif
131