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