xref: /netbsd-src/usr.sbin/npf/npftest/libnpftest/npf_test.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: npf_test.h,v 1.16 2016/12/26 23:05:05 christos Exp $	*/
2 
3 /*
4  * Public Domain.
5  */
6 
7 #ifndef _LIB_NPF_TEST_H_
8 #define _LIB_NPF_TEST_H_
9 
10 #ifdef _KERNEL
11 #include <sys/types.h>
12 #include <sys/mbuf.h>
13 
14 #include <netinet/in_systm.h>
15 #include <netinet/in.h>
16 #include <netinet6/in6.h>
17 
18 #include <netinet/ip.h>
19 #include <netinet/ip6.h>
20 #include <netinet/tcp.h>
21 #include <netinet/udp.h>
22 #include <netinet/ip_icmp.h>
23 
24 #include <net/if.h>
25 #include <net/if_ether.h>
26 #include <net/ethertypes.h>
27 #endif
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 
47 #define	LOCAL_IP6	"fd01:203:405:1::1234"
48 #define	REMOTE_IP6	"2001:db8:fefe::1010"
49 #define	EXPECTED_IP6	"2001:db8:1:d550::1234"
50 
51 #if defined(_NPF_STANDALONE)
52 
53 #define	MLEN		512
54 
55 struct mbuf {
56 	unsigned	m_flags;
57 	int		m_type;
58 	unsigned	m_len;
59 	void *		m_next;
60 	struct {
61 		int	len;
62 	} m_pkthdr;
63 	char *		m_data;
64 	char		m_data0[MLEN];
65 };
66 
67 
68 #define	MT_FREE			0
69 #define	M_UNWRITABLE(m, l)	false
70 #define	M_NOWAIT		0x00001
71 #define M_PKTHDR		0x00002
72 
73 #define	m_get(x, y)		npfkern_m_get(0, MLEN)
74 #define	m_gethdr(x, y)		npfkern_m_get(M_PKTHDR, MLEN)
75 #define	m_length(m)		npfkern_m_length(m)
76 #define	m_freem(m)		npfkern_m_freem(m)
77 #define	mtod(m, t)		((t)((m)->m_data))
78 
79 #endif
80 
81 const npf_mbufops_t	npftest_mbufops;
82 
83 struct mbuf *	npfkern_m_get(int, int);
84 size_t		npfkern_m_length(const struct mbuf *);
85 void		npfkern_m_freem(struct mbuf *);
86 
87 void		npf_test_init(int (*)(int, const char *, void *),
88 		    const char *(*)(int, const void *, char *, socklen_t),
89 		    long (*)(void));
90 void		npf_test_fini(void);
91 int		npf_test_load(const void *);
92 ifnet_t *	npf_test_addif(const char *, bool, bool);
93 ifnet_t *	npf_test_getif(const char *);
94 
95 int		npf_test_statetrack(const void *, size_t, ifnet_t *,
96 		    bool, int64_t *);
97 void		npf_test_conc(bool, unsigned);
98 
99 struct mbuf *	mbuf_getwithdata(const void *, size_t);
100 struct mbuf *	mbuf_construct_ether(int);
101 struct mbuf *	mbuf_construct(int);
102 struct mbuf *	mbuf_construct6(int);
103 void *		mbuf_return_hdrs(struct mbuf *, bool, struct ip **);
104 void *		mbuf_return_hdrs6(struct mbuf *, struct ip6_hdr **);
105 void		mbuf_icmp_append(struct mbuf *, struct mbuf *);
106 
107 bool		npf_nbuf_test(bool);
108 bool		npf_bpf_test(bool);
109 bool		npf_table_test(bool, void *, size_t);
110 bool		npf_state_test(bool);
111 
112 bool		npf_rule_test(bool);
113 bool		npf_nat_test(bool);
114 
115 int		npf_inet_pton(int, const char *, void *);
116 const char *	npf_inet_ntop(int, const void *, char *, socklen_t);
117 
118 #endif
119