Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd98679

Browse files
mroethkesmlng
authored andcommitted
tests: add test for prefix removal
1 parent 9705bda commit dd98679

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

tests/test_pfx.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,25 @@ static void pfx_table_test(void)
330330
printf("pfx_table_test successful\n");
331331
}
332332

333+
static void create_ip4_pfx_record(struct pfx_record *pfx, uint32_t asn,
334+
const char *ip, uint8_t min_mask_len,
335+
uint8_t max_mask_len)
336+
{
337+
pfx->asn = asn;
338+
pfx->min_len = min_mask_len;
339+
pfx->max_len = max_mask_len;
340+
assert(!lrtr_ip_str_to_addr(ip, &pfx->prefix));
341+
}
342+
333343
static void add_ip4_pfx_record(struct pfx_table *pfxt, uint32_t asn,
334344
const char *ip, uint8_t min_mask_len,
335345
uint8_t max_mask_len)
336346
{
337347
struct pfx_record pfx;
338348
enum pfxv_state val_res;
339349

340-
pfx.asn = asn;
341-
pfx.min_len = min_mask_len;
342-
pfx.max_len = max_mask_len;
350+
create_ip4_pfx_record(&pfx, asn, ip, min_mask_len, max_mask_len);
343351

344-
assert(!lrtr_ip_str_to_addr(ip, &pfx.prefix));
345352
assert(pfx_table_add(pfxt, &pfx) == PFX_SUCCESS);
346353

347354
assert(pfx_table_validate(pfxt, pfx.asn, &pfx.prefix, pfx.min_len,
@@ -363,12 +370,35 @@ static void test_issue99(void)
363370
pfx_table_free(&pfxt);
364371
}
365372

373+
static void test_issue152(void)
374+
{
375+
struct pfx_table pfxt;
376+
struct pfx_record *records = calloc(6, sizeof(struct pfx_record));
377+
378+
pfx_table_init(&pfxt, NULL);
379+
create_ip4_pfx_record(&records[0], 1, "89.18.183.0", 24, 24);
380+
create_ip4_pfx_record(&records[1], 2, "109.164.0.0", 17, 25);
381+
create_ip4_pfx_record(&records[2], 3, "185.131.60.0", 22, 24);
382+
create_ip4_pfx_record(&records[3], 4, "185.146.28.0", 22, 22);
383+
create_ip4_pfx_record(&records[4], 5, "212.5.51.0", 24, 24);
384+
create_ip4_pfx_record(&records[5], 6, "213.175.86.0", 24, 24);
385+
386+
for (size_t i = 0; i < 6; i++)
387+
assert(pfx_table_add(&pfxt, &records[i]) == PFX_SUCCESS);
388+
389+
for (size_t i = 0; i < 6; i++)
390+
assert(pfx_table_remove(&pfxt, &records[i]) == PFX_SUCCESS);
391+
392+
free(records);
393+
}
394+
366395
int main(void)
367396
{
368397
pfx_table_test();
369398
remove_src_test();
370399
mass_test();
371400
test_issue99();
401+
test_issue152();
372402

373403
return EXIT_SUCCESS;
374404
}

0 commit comments

Comments
 (0)