X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=app%2Ftest-fib%2Fmain.c;h=9cf01b16e5a2f89444fac06ec27ad26942c8eb74;hb=fb3ef40fc6096cee94e9c45d381f67143e2239a3;hp=aa83f76851366abd0c68d3df0345619db95abff8;hpb=f1caf7f859d7c7e08ee69e998b572880c70bad29;p=dpdk.git diff --git a/app/test-fib/main.c b/app/test-fib/main.c index aa83f76851..9cf01b16e5 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -2,14 +2,10 @@ * Copyright(c) 2019 Intel Corporation */ -#include #include #include -#include -#include -#include -#include #include +#include #include #include @@ -443,6 +439,32 @@ gen_rnd_lookup_tbl(int af) } } +static int +_inet_net_pton(int af, char *prefix, void *addr) +{ + const char *dlm = "/"; + char *s, *sp; + int ret, depth; + unsigned int max_depth; + + if ((prefix == NULL) || (addr == NULL)) + return -EINVAL; + + s = strtok_r(prefix, dlm, &sp); + if (s == NULL) + return -EINVAL; + + ret = inet_pton(af, s, addr); + if (ret != 1) + return -errno; + + s = strtok_r(NULL, dlm, &sp); + max_depth = (af == AF_INET) ? 32 : 128; + GET_CB_FIELD(s, depth, 0, max_depth, 0); + + return depth; +} + static int parse_rt_4(FILE *f) { @@ -463,8 +485,7 @@ parse_rt_4(FILE *f) s = NULL; } - ret = inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr, - sizeof(rt[j].addr)); + ret = _inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr); if (ret == -1) return -errno; @@ -478,30 +499,6 @@ parse_rt_4(FILE *f) return 0; } -static int -__inet_net_pton6(char *prefix, uint8_t *addr) -{ - const char *dlm = "/"; - char *s, *sp; - int ret, depth; - - if ((prefix == NULL) || (addr == NULL)) - return -EINVAL; - - s = strtok_r(prefix, dlm, &sp); - if (s == NULL) - return -EINVAL; - - ret = inet_pton(AF_INET6, s, addr); - if (ret != 1) - return -errno; - - s = strtok_r(NULL, dlm, &sp); - GET_CB_FIELD(s, depth, 0, 128, 0); - - return depth; -} - static int parse_rt_6(FILE *f) { @@ -522,7 +519,7 @@ parse_rt_6(FILE *f) s = NULL; } - ret = __inet_net_pton6(in[RT_PREFIX], rt[j].addr); + ret = _inet_net_pton(AF_INET6, in[RT_PREFIX], rt[j].addr); if (ret < 0) return ret; @@ -546,6 +543,8 @@ parse_lookup(FILE *f, int af) while (fgets(line, sizeof(line), f) != NULL) { s = strtok(line, " \t\n"); + if (s == NULL) + return -EINVAL; ret = inet_pton(af, s, &tbl[i]); if (ret != 1) return -EINVAL; @@ -790,7 +789,7 @@ dump_rt_4(struct rt_rule_4 *rt) } for (i = 0; i < config.nb_routes; i++) - fprintf(f, NIPQUAD_FMT"/%d %lu\n", NIPQUAD(rt[i].addr), + fprintf(f, NIPQUAD_FMT"/%d %"PRIu64"\n", NIPQUAD(rt[i].addr), rt[i].depth, rt[i].nh); fclose(f); @@ -858,7 +857,8 @@ run_v4(void) return -ret; } } - printf("AVG FIB add %lu\n", (rte_rdtsc_precise() - start) / j); + printf("AVG FIB add %"PRIu64"\n", + (rte_rdtsc_precise() - start) / j); i += j; } @@ -885,7 +885,7 @@ run_v4(void) return -ret; } } - printf("AVG LPM add %lu\n", + printf("AVG LPM add %"PRIu64"\n", (rte_rdtsc_precise() - start) / j); i += j; } @@ -939,7 +939,7 @@ run_v4(void) for (j = 0; j < (config.nb_routes - i) / k; j++) rte_fib_delete(fib, rt[i + j].addr, rt[i + j].depth); - printf("AVG FIB delete %lu\n", + printf("AVG FIB delete %"PRIu64"\n", (rte_rdtsc_precise() - start) / j); i += j; } @@ -951,7 +951,7 @@ run_v4(void) rte_lpm_delete(lpm, rt[i + j].addr, rt[i + j].depth); - printf("AVG LPM delete %lu\n", + printf("AVG LPM delete %"PRIu64"\n", (rte_rdtsc_precise() - start) / j); i += j; } @@ -973,7 +973,7 @@ dump_rt_6(struct rt_rule_6 *rt) } for (i = 0; i < config.nb_routes; i++) { - fprintf(f, NIPQUAD6_FMT"/%d %lu\n", NIPQUAD6(rt[i].addr), + fprintf(f, NIPQUAD6_FMT"/%d %"PRIu64"\n", NIPQUAD6(rt[i].addr), rt[i].depth, rt[i].nh); } @@ -1036,7 +1036,8 @@ run_v6(void) return -ret; } } - printf("AVG FIB add %lu\n", (rte_rdtsc_precise() - start) / j); + printf("AVG FIB add %"PRIu64"\n", + (rte_rdtsc_precise() - start) / j); i += j; } @@ -1063,7 +1064,7 @@ run_v6(void) return -ret; } } - printf("AVG LPM add %lu\n", + printf("AVG LPM add %"PRIu64"\n", (rte_rdtsc_precise() - start) / j); i += j; } @@ -1121,7 +1122,7 @@ run_v6(void) for (j = 0; j < (config.nb_routes - i) / k; j++) rte_fib6_delete(fib, rt[i + j].addr, rt[i + j].depth); - printf("AVG FIB delete %lu\n", + printf("AVG FIB delete %"PRIu64"\n", (rte_rdtsc_precise() - start) / j); i += j; } @@ -1133,7 +1134,7 @@ run_v6(void) rte_lpm6_delete(lpm, rt[i + j].addr, rt[i + j].depth); - printf("AVG LPM delete %lu\n", + printf("AVG LPM delete %"PRIu64"\n", (rte_rdtsc_precise() - start) / j); i += j; }