diff mbox series

[3/4] app/testfib: get rid of libresolv dependency

Message ID 1583757743-375198-4-git-send-email-vladimir.medvedkin@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers show
Series app/testfib: testfib app various fixes | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Medvedkin, Vladimir March 9, 2020, 12:42 p.m. UTC
Get rid of using inet_net_pton(). Implement it internally in the app.

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test-fib/Makefile |  2 --
 app/test-fib/main.c   | 85 +++++++++++++++++++++++++--------------------------
 2 files changed, 41 insertions(+), 46 deletions(-)
diff mbox series

Patch

diff --git a/app/test-fib/Makefile b/app/test-fib/Makefile
index 78b45fe..9da34eb 100644
--- a/app/test-fib/Makefile
+++ b/app/test-fib/Makefile
@@ -11,8 +11,6 @@  CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -DALLOW_EXPERIMENTAL_API
 
-LDFLAGS += -lresolv
-
 # all source are stored in SRCS-y
 SRCS-y := main.c
 
diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index 7fd3420..5fb67f3 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -2,14 +2,10 @@ 
  * 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>
@@ -444,46 +440,12 @@  gen_rnd_lookup_tbl(int af)
 }
 
 static int
-parse_rt_4(FILE *f)
-{
-	int ret, i, j = 0;
-	char *s, *sp, *in[RT_NUM];
-	static const char *dlm = " \t\n";
-	int string_tok_nb = RTE_DIM(in);
-	struct rt_rule_4 *rt;
-
-	rt = (struct rt_rule_4 *)config.rt;
-
-	while (fgets(line, sizeof(line), f) != NULL) {
-		s = line;
-		for (i = 0; i != string_tok_nb; i++) {
-			in[i] = strtok_r(s, dlm, &sp);
-			if (in[i] == NULL)
-				return -EINVAL;
-			s = NULL;
-		}
-
-		ret = inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr,
-			sizeof(rt[j].addr));
-		if (ret == -1)
-			return -errno;
-
-		rt[j].addr = rte_be_to_cpu_32(rt[j].addr);
-		rt[j].depth = ret;
-		config.nb_routes_per_depth[ret]++;
-		GET_CB_FIELD(in[RT_NEXTHOP], rt[j].nh, 0,
-				UINT32_MAX, 0);
-		j++;
-	}
-	return 0;
-}
-
-static int
-__inet_net_pton6(char *prefix, uint8_t *addr)
+_inet_net_pton(int af, char *prefix, void *addr)
 {
 	const char *dlm = "/";
 	char *s, *sp;
 	int ret, depth;
+	unsigned max_depth;
 
 	if ((prefix == NULL) || (addr == NULL))
 		return -EINVAL;
@@ -492,17 +454,52 @@  __inet_net_pton6(char *prefix, uint8_t *addr)
 	if (s == NULL)
 		return -EINVAL;
 
-	ret = inet_pton(AF_INET6, s, addr);
+	ret = inet_pton(af, s, addr);
 	if (ret != 1)
 		return -errno;
 
 	s = strtok_r(NULL, dlm, &sp);
-	GET_CB_FIELD(s, depth, 0, 128, 0);
+	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)
+{
+	int ret, i, j = 0;
+	char *s, *sp, *in[RT_NUM];
+	static const char *dlm = " \t\n";
+	int string_tok_nb = RTE_DIM(in);
+	struct rt_rule_4 *rt;
+
+	rt = (struct rt_rule_4 *)config.rt;
+
+	while (fgets(line, sizeof(line), f) != NULL) {
+		s = line;
+		for (i = 0; i != string_tok_nb; i++) {
+			in[i] = strtok_r(s, dlm, &sp);
+			if (in[i] == NULL)
+				return -EINVAL;
+			s = NULL;
+		}
+
+		ret = _inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr);
+		if (ret == -1)
+			return -errno;
+
+		rt[j].addr = rte_be_to_cpu_32(rt[j].addr);
+		rt[j].depth = ret;
+		config.nb_routes_per_depth[ret]++;
+		GET_CB_FIELD(in[RT_NEXTHOP], rt[j].nh, 0,
+				UINT32_MAX, 0);
+		j++;
+	}
+	return 0;
+}
+
+static int
 parse_rt_6(FILE *f)
 {
 	int ret, i, j = 0;
@@ -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;