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 /* Test interfaces and IP addresses. */ 28 #define IFNAME_EXT "npftest0" 29 #define IFNAME_INT "npftest1" 30 #define IFNAME_TEST "npftest2" 31 32 #define LOCAL_IP1 "10.1.1.1" 33 #define LOCAL_IP2 "10.1.1.2" 34 #define LOCAL_IP3 "10.1.1.3" 35 36 /* Note: RFC 5737 compliant addresses. */ 37 #define PUB_IP1 "192.0.2.1" 38 #define PUB_IP2 "192.0.2.2" 39 #define PUB_IP3 "192.0.2.3" 40 41 #define REMOTE_IP1 "192.0.2.101" 42 #define REMOTE_IP2 "192.0.2.102" 43 #define REMOTE_IP3 "192.0.2.103" 44 #define REMOTE_IP4 "192.0.2.104" 45 46 #define LOCAL_IP6 "fd01:203:405:1::1234" 47 #define REMOTE_IP6 "2001:db8:fefe::1010" 48 #define EXPECTED_IP6 "2001:db8:1:d550::1234" 49 50 #define NET_A_IP1 "10.100.7.126" 51 #define NET_B_IP1 "10.255.7.126" 52 53 #if defined(_NPF_STANDALONE) 54 55 #define MLEN 512 56 57 struct mbuf { 58 unsigned m_flags; 59 int m_type; 60 unsigned m_len; 61 void * m_next; 62 struct { 63 int len; 64 } m_pkthdr; 65 void * m_data; 66 unsigned char m_data0[MLEN]; 67 }; 68 69 #define MT_FREE 0 70 #define M_UNWRITABLE(m, l) false 71 #define M_NOWAIT 0x00001 72 #define M_PKTHDR 0x00002 73 74 #define m_get(x, y) npfkern_m_get(0, MLEN) 75 #define m_gethdr(x, y) npfkern_m_get(M_PKTHDR, MLEN) 76 #define m_length(m) npfkern_m_length(m) 77 #define m_freem(m) npfkern_m_freem(m) 78 #define mtod(m, t) ((t)((m)->m_data)) 79 80 #endif 81 82 const npf_mbufops_t npftest_mbufops; 83 84 struct mbuf * npfkern_m_get(int, int); 85 size_t npfkern_m_length(const struct mbuf *); 86 void npfkern_m_freem(struct mbuf *); 87 88 void npf_test_init(int (*)(int, const char *, void *), 89 const char *(*)(int, const void *, char *, socklen_t), 90 long (*)(void)); 91 void npf_test_fini(void); 92 int npf_test_load(const void *, size_t, bool); 93 ifnet_t * npf_test_addif(const char *, bool, bool); 94 ifnet_t * npf_test_getif(const char *); 95 96 int npf_test_statetrack(const void *, size_t, ifnet_t *, 97 bool, int64_t *); 98 void npf_test_conc(bool, unsigned); 99 100 struct mbuf * mbuf_getwithdata(const void *, size_t); 101 struct mbuf * mbuf_construct_ether(int); 102 struct mbuf * mbuf_construct(int); 103 struct mbuf * mbuf_construct6(int); 104 void * mbuf_return_hdrs(struct mbuf *, bool, struct ip **); 105 void * mbuf_return_hdrs6(struct mbuf *, struct ip6_hdr **); 106 void mbuf_icmp_append(struct mbuf *, struct mbuf *); 107 108 bool npf_nbuf_test(bool); 109 bool npf_bpf_test(bool); 110 bool npf_table_test(bool, void *, size_t); 111 bool npf_state_test(bool); 112 113 bool npf_rule_test(bool); 114 bool npf_conn_test(bool); 115 bool npf_nat_test(bool); 116 117 int npf_inet_pton(int, const char *, void *); 118 const char * npf_inet_ntop(int, const void *, char *, socklen_t); 119 120 #endif 121