Home | History | Annotate | Line # | Download | only in libnpftest
      1   1.1     rmind /*
      2  1.11     rmind  * NPF tableset tests.
      3   1.1     rmind  *
      4   1.1     rmind  * Public Domain.
      5   1.1     rmind  */
      6   1.1     rmind 
      7   1.9  christos #ifdef _KERNEL
      8   1.1     rmind #include <sys/types.h>
      9  1.11     rmind #include <sys/kmem.h>
     10   1.9  christos #endif
     11   1.9  christos 
     12   1.9  christos #ifdef __linux__
     13   1.9  christos #include <endian.h>
     14   1.9  christos #else
     15   1.9  christos #include <sys/endian.h>
     16   1.9  christos #endif
     17   1.1     rmind 
     18   1.1     rmind #include "npf_impl.h"
     19   1.1     rmind #include "npf_test.h"
     20   1.1     rmind 
     21   1.1     rmind static const char *ip_list[] = {
     22   1.1     rmind 	"192.168.1.1",
     23   1.1     rmind 	"10.0.0.1",
     24   1.1     rmind 	"192.168.2.1",
     25   1.1     rmind 	"10.1.0.1",
     26   1.1     rmind 	"192.168.100.253",
     27   1.1     rmind 	"10.0.5.1",
     28   1.1     rmind 	"192.168.128.127",
     29   1.1     rmind 	"10.0.0.2",
     30   1.1     rmind };
     31   1.1     rmind 
     32  1.11     rmind static const uint8_t ip6_list[][16] = {
     33   1.5     rmind 	{
     34  1.11     rmind 		0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     35  1.11     rmind 		0x02, 0xa0, 0xc0, 0xff, 0xfe, 0x10, 0x12, 0x34
     36   1.5     rmind 	},
     37   1.5     rmind 	{
     38  1.11     rmind 		0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     39  1.11     rmind 		0x02, 0xa0, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00,
     40   1.5     rmind 	},
     41   1.5     rmind 	{
     42  1.11     rmind 		0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     43  1.11     rmind 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     44   1.5     rmind 	},
     45   1.5     rmind 	{
     46  1.11     rmind 		0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     47  1.11     rmind 		0x02, 0xa0, 0xc0, 0xff, 0xfe, 0x10, 0x12, 0x30
     48   1.5     rmind 	}
     49   1.4     rmind };
     50   1.4     rmind 
     51  1.11     rmind #define	IPSET_TID		0
     52  1.11     rmind #define	IPSET_NAME		"ipset-table"
     53  1.11     rmind 
     54  1.11     rmind #define	LPM_TID			1
     55  1.11     rmind #define	LPM_NAME		"lpm-table"
     56  1.11     rmind 
     57  1.11     rmind #define	CDB_TID			2
     58  1.11     rmind #define	CDB_NAME		"cdb-table"
     59  1.11     rmind 
     60  1.11     rmind #define	IFADDR_TID		3
     61  1.11     rmind #define	IFADDR_NAME		".ifaddr-eth0"
     62  1.11     rmind 
     63  1.11     rmind ///////////////////////////////////////////////////////////////////////////
     64  1.11     rmind 
     65  1.11     rmind static bool
     66  1.11     rmind check_ip4(const npf_addr_t *addr, const char *ipstr)
     67  1.11     rmind {
     68  1.11     rmind 	npf_addr_t addr_storage, *test_addr = &addr_storage;
     69  1.11     rmind 	const int alen = sizeof(struct in_addr);
     70  1.11     rmind 	test_addr->word32[0] = inet_addr(ipstr);
     71  1.11     rmind 	return memcmp(addr, test_addr, alen) == 0;
     72  1.11     rmind }
     73  1.11     rmind 
     74  1.11     rmind static bool
     75  1.11     rmind ip4list_insert_lookup(npf_table_t *t, unsigned i)
     76  1.11     rmind {
     77  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
     78  1.11     rmind 	const int alen = sizeof(struct in_addr);
     79  1.11     rmind 	int error;
     80   1.9  christos 
     81  1.11     rmind 	addr->word32[0] = inet_addr(ip_list[i]);
     82  1.11     rmind 	error = npf_table_insert(t, alen, addr, NPF_NO_NETMASK);
     83  1.11     rmind 	CHECK_TRUE(error == 0);
     84  1.11     rmind 	error = npf_table_lookup(t, alen, addr);
     85  1.11     rmind 	CHECK_TRUE(error == 0);
     86  1.11     rmind 	return true;
     87  1.11     rmind }
     88   1.1     rmind 
     89   1.6     rmind static bool
     90  1.11     rmind fill_with_ip4(npf_tableset_t *tblset)
     91   1.6     rmind {
     92  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
     93   1.6     rmind 	const int alen = sizeof(struct in_addr);
     94   1.6     rmind 	const int nm = NPF_NO_NETMASK;
     95   1.6     rmind 
     96   1.6     rmind 	for (unsigned i = 0; i < __arraycount(ip_list); i++) {
     97   1.7     rmind 		npf_table_t *t;
     98   1.6     rmind 		int error;
     99   1.6     rmind 
    100   1.9  christos 		addr->word32[0] = inet_addr(ip_list[i]);
    101   1.6     rmind 
    102  1.11     rmind 		t = npf_tableset_getbyname(tblset, IPSET_NAME);
    103   1.7     rmind 		error = npf_table_insert(t, alen, addr, nm);
    104  1.11     rmind 		CHECK_TRUE(error == 0);
    105   1.7     rmind 		error = npf_table_insert(t, alen, addr, nm);
    106  1.11     rmind 		CHECK_TRUE(error != 0); // duplicate
    107   1.6     rmind 
    108  1.11     rmind 		t = npf_tableset_getbyname(tblset, LPM_NAME);
    109   1.7     rmind 		error = npf_table_insert(t, alen, addr, nm);
    110  1.11     rmind 		CHECK_TRUE(error == 0);
    111   1.7     rmind 		error = npf_table_insert(t, alen, addr, nm);
    112  1.11     rmind 		CHECK_TRUE(error != 0); // duplicate
    113  1.11     rmind 	}
    114  1.11     rmind 	return true;
    115  1.11     rmind }
    116  1.11     rmind 
    117  1.11     rmind static bool
    118  1.11     rmind verify_ip4(npf_tableset_t *tblset)
    119  1.11     rmind {
    120  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    121  1.11     rmind 	const size_t alen = sizeof(struct in_addr);
    122  1.11     rmind 	const int nm = NPF_NO_NETMASK;
    123  1.11     rmind 	npf_table_t *t;
    124  1.11     rmind 	int error;
    125  1.11     rmind 
    126  1.11     rmind 	/* Attempt to add duplicates - should fail. */
    127  1.11     rmind 	addr->word32[0] = inet_addr(ip_list[0]);
    128  1.11     rmind 
    129  1.11     rmind 	t = npf_tableset_getbyname(tblset, IPSET_NAME);
    130  1.11     rmind 	error = npf_table_insert(t, alen, addr, nm);
    131  1.11     rmind 	CHECK_TRUE(error != 0);
    132  1.11     rmind 
    133  1.11     rmind 	t = npf_tableset_getbyname(tblset, LPM_NAME);
    134  1.11     rmind 	error = npf_table_insert(t, alen, addr, nm);
    135  1.11     rmind 	CHECK_TRUE(error != 0);
    136  1.11     rmind 
    137  1.11     rmind 	/* Match (validate) each IP entry. */
    138  1.11     rmind 	for (unsigned i = 0; i < __arraycount(ip_list); i++) {
    139  1.11     rmind 		addr->word32[0] = inet_addr(ip_list[i]);
    140  1.11     rmind 
    141  1.11     rmind 		t = npf_tableset_getbyname(tblset, IPSET_NAME);
    142  1.11     rmind 		error = npf_table_lookup(t, alen, addr);
    143  1.11     rmind 		CHECK_TRUE(error == 0);
    144  1.11     rmind 
    145  1.11     rmind 		t = npf_tableset_getbyname(tblset, LPM_NAME);
    146  1.11     rmind 		error = npf_table_lookup(t, alen, addr);
    147  1.11     rmind 		CHECK_TRUE(error == 0);
    148   1.6     rmind 	}
    149  1.11     rmind 	return true;
    150   1.6     rmind }
    151   1.6     rmind 
    152  1.11     rmind static bool
    153  1.11     rmind clear_ip4(npf_tableset_t *tblset)
    154   1.1     rmind {
    155   1.1     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    156  1.11     rmind 	const int alen = sizeof(struct in_addr);
    157   1.4     rmind 	const int nm = NPF_NO_NETMASK;
    158  1.10     rmind 
    159  1.11     rmind 	for (unsigned i = 0; i < __arraycount(ip_list); i++) {
    160  1.11     rmind 		npf_table_t *t;
    161  1.11     rmind 		int error;
    162  1.11     rmind 
    163  1.11     rmind 		addr->word32[0] = inet_addr(ip_list[i]);
    164  1.11     rmind 
    165  1.11     rmind 		t = npf_tableset_getbyname(tblset, IPSET_NAME);
    166  1.11     rmind 		error = npf_table_remove(t, alen, addr, nm);
    167  1.11     rmind 		CHECK_TRUE(error == 0);
    168  1.11     rmind 
    169  1.11     rmind 		error = npf_table_remove(t, alen, addr, nm);
    170  1.11     rmind 		CHECK_TRUE(error != 0);
    171  1.11     rmind 
    172  1.11     rmind 		t = npf_tableset_getbyname(tblset, LPM_NAME);
    173  1.11     rmind 		error = npf_table_remove(t, alen, addr, nm);
    174  1.11     rmind 		CHECK_TRUE(error == 0);
    175  1.11     rmind 
    176  1.11     rmind 		error = npf_table_remove(t, alen, addr, nm);
    177  1.11     rmind 		CHECK_TRUE(error != 0);
    178  1.11     rmind 	}
    179  1.11     rmind 	return true;
    180  1.11     rmind }
    181  1.11     rmind 
    182  1.11     rmind ///////////////////////////////////////////////////////////////////////////
    183   1.1     rmind 
    184  1.11     rmind static bool
    185  1.11     rmind test_basic(npf_tableset_t *tblset)
    186  1.11     rmind {
    187  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    188  1.11     rmind 	const int alen = sizeof(struct in_addr);
    189  1.11     rmind 	npf_table_t *t;
    190  1.11     rmind 	int error;
    191   1.1     rmind 
    192  1.11     rmind 	/* Basic IP set. */
    193  1.11     rmind 	t = npf_table_create(IPSET_NAME, IPSET_TID, NPF_TABLE_IPSET, NULL, 0);
    194  1.11     rmind 	CHECK_TRUE(t != NULL);
    195  1.11     rmind 	error = npf_tableset_insert(tblset, t);
    196  1.11     rmind 	CHECK_TRUE(error == 0);
    197   1.1     rmind 
    198   1.1     rmind 	/* Check for double-insert. */
    199  1.11     rmind 	error = npf_tableset_insert(tblset, t);
    200  1.11     rmind 	CHECK_TRUE(error != 0);
    201   1.1     rmind 
    202  1.11     rmind 	/* Longest-prefix match (LPM). */
    203  1.11     rmind 	t = npf_table_create(LPM_NAME, LPM_TID, NPF_TABLE_LPM, NULL, 0);
    204  1.11     rmind 	CHECK_TRUE(t != NULL);
    205  1.11     rmind 	error = npf_tableset_insert(tblset, t);
    206  1.11     rmind 	CHECK_TRUE(error == 0);
    207  1.11     rmind 
    208  1.11     rmind 	/* Table for interface addresses. */
    209  1.11     rmind 	t = npf_table_create(IFADDR_NAME, IFADDR_TID, NPF_TABLE_IFADDR, NULL, 0);
    210  1.11     rmind 	CHECK_TRUE(t != NULL);
    211  1.11     rmind 	error = npf_tableset_insert(tblset, t);
    212  1.11     rmind 	CHECK_TRUE(error == 0);
    213   1.8     rmind 
    214  1.11     rmind 	/*
    215  1.11     rmind 	 * Attempt to match some non-existing entries - should fail.
    216  1.11     rmind 	 */
    217   1.9  christos 	addr->word32[0] = inet_addr(ip_list[0]);
    218   1.2     rmind 
    219  1.11     rmind 	t = npf_tableset_getbyname(tblset, IPSET_NAME);
    220   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    221  1.11     rmind 	CHECK_TRUE(error != 0);
    222   1.2     rmind 
    223  1.11     rmind 	t = npf_tableset_getbyname(tblset, LPM_NAME);
    224   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    225  1.11     rmind 	CHECK_TRUE(error != 0);
    226   1.2     rmind 
    227  1.11     rmind 	return true;
    228  1.11     rmind }
    229   1.1     rmind 
    230  1.11     rmind static bool
    231  1.11     rmind test_nocopy(npf_tableset_t *tblset)
    232  1.11     rmind {
    233  1.11     rmind 	const int alen = sizeof(struct in_addr);
    234  1.11     rmind 	const char *tables[] = { IPSET_NAME, LPM_NAME, IFADDR_NAME };
    235  1.11     rmind 	npf_addr_t *addr, lookup_addr;
    236  1.11     rmind 
    237  1.11     rmind 	for (unsigned i = 0; i < __arraycount(tables); i++) {
    238  1.11     rmind 		npf_table_t *t;
    239  1.11     rmind 		int error;
    240  1.11     rmind 
    241  1.11     rmind 		addr = kmem_zalloc(sizeof(npf_addr_t), KM_SLEEP);
    242  1.11     rmind 		assert(addr != NULL);
    243  1.11     rmind 		addr->word32[0] = inet_addr("172.16.90.10");
    244   1.1     rmind 
    245  1.11     rmind 		t = npf_tableset_getbyname(tblset, tables[i]);
    246  1.11     rmind 		(void)npf_table_flush(t);
    247   1.1     rmind 
    248  1.11     rmind 		error = npf_table_insert(t, alen, addr, NPF_NO_NETMASK);
    249  1.11     rmind 		CHECK_TRUE(error == 0);
    250   1.1     rmind 
    251  1.11     rmind 		memcpy(&lookup_addr, addr, alen);
    252  1.11     rmind 		memset(addr, 0xa5, alen); // explicit memset
    253   1.1     rmind 
    254  1.11     rmind 		error = npf_table_lookup(t, alen, &lookup_addr);
    255  1.11     rmind 		CHECK_TRUE(error == 0);
    256   1.1     rmind 
    257  1.11     rmind 		CHECK_TRUE(*(volatile unsigned char *)addr == 0xa5);
    258  1.11     rmind 		kmem_free(addr, sizeof(npf_addr_t));
    259   1.1     rmind 	}
    260  1.11     rmind 	return true;
    261  1.11     rmind }
    262  1.11     rmind 
    263  1.11     rmind static bool
    264  1.11     rmind test_ip6(npf_tableset_t *tblset)
    265  1.11     rmind {
    266  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    267  1.11     rmind 	const size_t alen = sizeof(struct in6_addr);
    268  1.11     rmind 	const int nm = NPF_NO_NETMASK;
    269  1.11     rmind 	npf_table_t *t;
    270  1.11     rmind 	int error;
    271   1.1     rmind 
    272   1.4     rmind 	/* IPv6 addresses. */
    273   1.4     rmind 	memcpy(addr, ip6_list[0], sizeof(ip6_list[0]));
    274   1.4     rmind 
    275  1.11     rmind 	t = npf_tableset_getbyname(tblset, IPSET_NAME);
    276   1.7     rmind 	error = npf_table_insert(t, alen, addr, nm);
    277  1.11     rmind 	CHECK_TRUE(error == 0);
    278   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    279  1.11     rmind 	CHECK_TRUE(error == 0);
    280   1.7     rmind 	error = npf_table_remove(t, alen, addr, nm);
    281  1.11     rmind 	CHECK_TRUE(error == 0);
    282   1.4     rmind 
    283  1.11     rmind 	t = npf_tableset_getbyname(tblset, LPM_NAME);
    284   1.7     rmind 	error = npf_table_insert(t, alen, addr, nm);
    285  1.11     rmind 	CHECK_TRUE(error == 0);
    286   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    287  1.11     rmind 	CHECK_TRUE(error == 0);
    288   1.7     rmind 	error = npf_table_remove(t, alen, addr, nm);
    289  1.11     rmind 	CHECK_TRUE(error == 0);
    290  1.11     rmind 
    291  1.11     rmind 	return true;
    292  1.11     rmind }
    293  1.11     rmind 
    294  1.11     rmind static bool
    295  1.11     rmind test_lpm_masks4(npf_tableset_t *tblset)
    296  1.11     rmind {
    297  1.11     rmind 	npf_table_t *t = npf_tableset_getbyname(tblset, LPM_NAME);
    298  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    299  1.11     rmind 	const size_t alen = sizeof(struct in_addr);
    300  1.11     rmind 	int error;
    301  1.11     rmind 
    302  1.11     rmind 	addr->word32[0] = inet_addr("172.16.90.0");
    303  1.11     rmind 	error = npf_table_insert(t, alen, addr, 25);
    304  1.11     rmind 	CHECK_TRUE(error == 0);
    305  1.11     rmind 
    306  1.11     rmind 	addr->word32[0] = inet_addr("172.16.90.126");
    307  1.11     rmind 	error = npf_table_lookup(t, alen, addr);
    308  1.11     rmind 	CHECK_TRUE(error == 0);
    309  1.11     rmind 
    310  1.11     rmind 	addr->word32[0] = inet_addr("172.16.90.128");
    311  1.11     rmind 	error = npf_table_lookup(t, alen, addr);
    312  1.11     rmind 	CHECK_TRUE(error != 0);
    313  1.11     rmind 
    314  1.11     rmind 	return true;
    315  1.11     rmind }
    316  1.11     rmind 
    317  1.11     rmind static bool
    318  1.11     rmind test_lpm_masks6(npf_tableset_t *tblset)
    319  1.11     rmind {
    320  1.11     rmind 	npf_table_t *t = npf_tableset_getbyname(tblset, LPM_NAME);
    321  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    322  1.11     rmind 	const size_t alen = sizeof(struct in6_addr);
    323  1.11     rmind 	int error;
    324   1.4     rmind 
    325   1.4     rmind 	/*
    326  1.11     rmind 	 * 96
    327   1.4     rmind 	 */
    328   1.4     rmind 	memcpy(addr, ip6_list[1], sizeof(ip6_list[1]));
    329   1.7     rmind 	error = npf_table_insert(t, alen, addr, 96);
    330  1.11     rmind 	CHECK_TRUE(error == 0);
    331   1.4     rmind 
    332   1.4     rmind 	memcpy(addr, ip6_list[0], sizeof(ip6_list[0]));
    333   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    334  1.11     rmind 	CHECK_TRUE(error == 0);
    335   1.4     rmind 
    336   1.4     rmind 	memcpy(addr, ip6_list[1], sizeof(ip6_list[1]));
    337   1.7     rmind 	error = npf_table_remove(t, alen, addr, 96);
    338  1.11     rmind 	CHECK_TRUE(error == 0);
    339   1.4     rmind 
    340  1.11     rmind 	/*
    341  1.11     rmind 	 * 32
    342  1.11     rmind 	 */
    343   1.4     rmind 	memcpy(addr, ip6_list[2], sizeof(ip6_list[2]));
    344   1.7     rmind 	error = npf_table_insert(t, alen, addr, 32);
    345  1.11     rmind 	CHECK_TRUE(error == 0);
    346   1.4     rmind 
    347   1.4     rmind 	memcpy(addr, ip6_list[0], sizeof(ip6_list[0]));
    348   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    349  1.11     rmind 	CHECK_TRUE(error == 0);
    350   1.4     rmind 
    351   1.4     rmind 	memcpy(addr, ip6_list[2], sizeof(ip6_list[2]));
    352   1.7     rmind 	error = npf_table_remove(t, alen, addr, 32);
    353  1.11     rmind 	CHECK_TRUE(error == 0);
    354   1.4     rmind 
    355  1.11     rmind 	/*
    356  1.11     rmind 	 * 126
    357  1.11     rmind 	 */
    358   1.4     rmind 	memcpy(addr, ip6_list[3], sizeof(ip6_list[3]));
    359   1.7     rmind 	error = npf_table_insert(t, alen, addr, 126);
    360  1.11     rmind 	CHECK_TRUE(error == 0);
    361   1.4     rmind 
    362   1.4     rmind 	memcpy(addr, ip6_list[0], sizeof(ip6_list[0]));
    363   1.7     rmind 	error = npf_table_lookup(t, alen, addr);
    364  1.11     rmind 	CHECK_TRUE(error != 0);
    365   1.4     rmind 
    366   1.4     rmind 	memcpy(addr, ip6_list[3], sizeof(ip6_list[3]));
    367   1.7     rmind 	error = npf_table_remove(t, alen, addr, 126);
    368  1.11     rmind 	CHECK_TRUE(error == 0);
    369   1.4     rmind 
    370  1.11     rmind 	return true;
    371  1.11     rmind }
    372   1.4     rmind 
    373  1.11     rmind static bool
    374  1.11     rmind test_const_table(npf_tableset_t *tblset, void *blob, size_t size)
    375  1.11     rmind {
    376  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    377  1.11     rmind 	const int alen = sizeof(struct in_addr);
    378  1.11     rmind 	npf_table_t *t;
    379  1.11     rmind 	int error;
    380   1.1     rmind 
    381  1.11     rmind 	t = npf_table_create(CDB_NAME, CDB_TID, NPF_TABLE_CONST, blob, size);
    382  1.11     rmind 	CHECK_TRUE(t != NULL);
    383   1.1     rmind 
    384  1.11     rmind 	error = npf_tableset_insert(tblset, t);
    385  1.11     rmind 	CHECK_TRUE(error == 0);
    386   1.1     rmind 
    387   1.9  christos 	addr->word32[0] = inet_addr(ip_list[0]);
    388  1.11     rmind 	error = npf_table_lookup(t, alen, addr);
    389  1.11     rmind 	CHECK_TRUE(error == 0);
    390   1.8     rmind 
    391  1.11     rmind 	for (unsigned i = 1; i < __arraycount(ip_list) - 1; i++) {
    392   1.9  christos 		addr->word32[0] = inet_addr(ip_list[i]);
    393  1.11     rmind 		error = npf_table_lookup(t, alen, addr);
    394  1.11     rmind 		CHECK_TRUE(error != 0);
    395   1.8     rmind 	}
    396  1.11     rmind 	return true;
    397  1.11     rmind }
    398  1.11     rmind 
    399  1.11     rmind static bool
    400  1.11     rmind test_ifaddr_table(npf_tableset_t *tblset)
    401  1.11     rmind {
    402  1.11     rmind 	npf_addr_t addr_storage, *addr = &addr_storage;
    403  1.11     rmind 	npf_table_t *t = npf_tableset_getbyname(tblset, IFADDR_NAME);
    404  1.11     rmind 	int error;
    405  1.11     rmind 	bool ok;
    406  1.11     rmind 
    407  1.11     rmind 	/* Two IPv4 addresses. */
    408  1.11     rmind 	ok = ip4list_insert_lookup(t, 0);
    409  1.11     rmind 	CHECK_TRUE(ok);
    410  1.11     rmind 
    411  1.11     rmind 	ok = ip4list_insert_lookup(t, 1);
    412  1.11     rmind 	CHECK_TRUE(ok);
    413  1.11     rmind 
    414  1.11     rmind 	/* And one IPv6 address. */
    415  1.11     rmind 	memcpy(addr, ip6_list[0], sizeof(ip6_list[0]));
    416  1.11     rmind 	error = npf_table_insert(t, sizeof(struct in6_addr), addr, NPF_NO_NETMASK);
    417  1.11     rmind 	CHECK_TRUE(error == 0);
    418  1.11     rmind 
    419  1.11     rmind 	/*
    420  1.11     rmind 	 * Get IPv4 addresses.
    421  1.11     rmind 	 */
    422  1.11     rmind 	addr = npf_table_getsome(t, sizeof(struct in_addr), 0);
    423  1.11     rmind 	ok = check_ip4(addr, "192.168.1.1");
    424  1.11     rmind 	CHECK_TRUE(ok);
    425  1.11     rmind 
    426  1.11     rmind 	addr = npf_table_getsome(t, sizeof(struct in_addr), 1);
    427  1.11     rmind 	ok = check_ip4(addr, "10.0.0.1");
    428  1.11     rmind 	CHECK_TRUE(ok);
    429  1.11     rmind 
    430  1.11     rmind 	addr = npf_table_getsome(t, sizeof(struct in_addr), 2);
    431  1.11     rmind 	ok = check_ip4(addr, "192.168.1.1");
    432  1.11     rmind 	CHECK_TRUE(ok);
    433  1.11     rmind 
    434  1.11     rmind 	return true;
    435  1.11     rmind }
    436  1.11     rmind 
    437  1.11     rmind static void
    438  1.11     rmind test_ipset_gc(npf_tableset_t *tblset)
    439  1.11     rmind {
    440  1.11     rmind 	npf_table_t *t = npf_tableset_getbyname(tblset, IPSET_NAME);
    441  1.11     rmind 	npf_t *npf = npf_getkernctx();
    442  1.11     rmind 
    443  1.11     rmind 	npf_config_enter(npf);
    444  1.11     rmind 	npf_table_gc(npf, t);
    445  1.11     rmind 	npf_table_flush(t);
    446  1.11     rmind 	npf_config_exit(npf);
    447  1.11     rmind }
    448  1.11     rmind 
    449  1.11     rmind bool
    450  1.11     rmind npf_table_test(bool verbose, void *blob, size_t size)
    451  1.11     rmind {
    452  1.11     rmind 	npf_tableset_t *tblset;
    453  1.11     rmind 	bool ok;
    454  1.11     rmind 
    455  1.11     rmind 	(void)verbose;
    456  1.11     rmind 
    457  1.11     rmind 	tblset = npf_tableset_create(4);
    458  1.11     rmind 	CHECK_TRUE(tblset != NULL);
    459  1.11     rmind 
    460  1.11     rmind 	ok = test_basic(tblset);
    461  1.11     rmind 	CHECK_TRUE(ok);
    462  1.11     rmind 
    463  1.11     rmind 	/*
    464  1.11     rmind 	 * Fill IPSET and LPM tables with IPv4 addresses.
    465  1.11     rmind 	 * Keep them in the table during the other tests.
    466  1.11     rmind 	 */
    467  1.11     rmind 	ok = fill_with_ip4(tblset);
    468  1.11     rmind 	CHECK_TRUE(ok);
    469  1.11     rmind 
    470  1.11     rmind 	ok = verify_ip4(tblset);
    471  1.11     rmind 	CHECK_TRUE(ok);
    472  1.11     rmind 
    473  1.11     rmind 	ok = test_ip6(tblset);
    474  1.11     rmind 	CHECK_TRUE(ok);
    475  1.11     rmind 
    476  1.11     rmind 	ok = test_lpm_masks4(tblset);
    477  1.11     rmind 	CHECK_TRUE(ok);
    478  1.11     rmind 
    479  1.11     rmind 	ok = test_lpm_masks6(tblset);
    480  1.11     rmind 	CHECK_TRUE(ok);
    481  1.11     rmind 
    482  1.11     rmind 	ok = test_const_table(tblset, blob, size);
    483  1.11     rmind 	CHECK_TRUE(ok);
    484  1.11     rmind 
    485  1.11     rmind 	ok = test_ifaddr_table(tblset);
    486  1.11     rmind 	CHECK_TRUE(ok);
    487  1.11     rmind 
    488  1.11     rmind 	/*
    489  1.11     rmind 	 * Remove the above IPv4 addresses -- they must have been untouched.
    490  1.11     rmind 	 */
    491  1.11     rmind 	ok = clear_ip4(tblset);
    492  1.11     rmind 	CHECK_TRUE(ok);
    493  1.11     rmind 
    494  1.11     rmind 	ok = test_nocopy(tblset);
    495  1.11     rmind 	CHECK_TRUE(ok);
    496  1.11     rmind 
    497  1.11     rmind 	test_ipset_gc(tblset);
    498   1.8     rmind 
    499   1.1     rmind 	npf_tableset_destroy(tblset);
    500  1.11     rmind 	return true;
    501   1.1     rmind }
    502