* Copyright(c) 2019 Intel Corporation
*/
-#include <rte_string_fns.h>
#include <getopt.h>
#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/socket.h>
#include <rte_cycles.h>
#include <rte_errno.h>
}
}
+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)
{
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;
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)
{
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;
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;
}
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);
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;
}
return -ret;
}
}
- printf("AVG LPM add %lu\n",
+ printf("AVG LPM add %"PRIu64"\n",
(rte_rdtsc_precise() - start) / j);
i += j;
}
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;
}
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;
}
}
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);
}
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;
}
return -ret;
}
}
- printf("AVG LPM add %lu\n",
+ printf("AVG LPM add %"PRIu64"\n",
(rte_rdtsc_precise() - start) / j);
i += j;
}
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;
}
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;
}