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 59 struct 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 87 extern const npf_mbufops_t npftest_mbufops; 88 extern const npf_ifops_t npftest_ifops; 89 90 struct mbuf * npfkern_m_get(npf_t *, unsigned, size_t); 91 size_t npfkern_m_length(const struct mbuf *); 92 void npfkern_m_freem(struct mbuf *); 93 94 void npf_test_init(int (*)(int, const char *, void *), 95 const char *(*)(int, const void *, char *, socklen_t), 96 long (*)(void)); 97 void npf_test_fini(void); 98 int npf_test_load(const void *, size_t, bool); 99 ifnet_t * npf_test_addif(const char *, bool, bool); 100 ifnet_t * npf_test_getif(const char *); 101 102 int npf_test_statetrack(const void *, size_t, ifnet_t *, 103 bool, int64_t *); 104 void npf_test_conc(bool, unsigned); 105 106 struct mbuf * mbuf_getwithdata(const void *, size_t); 107 struct mbuf * mbuf_construct_ether(int); 108 struct mbuf * mbuf_construct(int); 109 struct mbuf * mbuf_construct6(int); 110 void * mbuf_return_hdrs(struct mbuf *, bool, struct ip **); 111 void * mbuf_return_hdrs6(struct mbuf *, struct ip6_hdr **); 112 void mbuf_icmp_append(struct mbuf *, struct mbuf *); 113 114 struct mbuf * mbuf_get_pkt(int, int, const char *, const char *, int, int); 115 npf_cache_t * get_cached_pkt(struct mbuf *, const char *); 116 void put_cached_pkt(npf_cache_t *); 117 118 bool npf_nbuf_test(bool); 119 bool npf_bpf_test(bool); 120 bool npf_table_test(bool, void *, size_t); 121 bool npf_state_test(bool); 122 123 bool npf_rule_test(bool); 124 bool npf_nat_test(bool); 125 bool npf_gc_test(bool); 126 127 int npf_inet_pton(int, const char *, void *); 128 const char * npf_inet_ntop(int, const void *, char *, socklen_t); 129 130 #endif 131