Skip to contentSkip to conversation

examples/exception_path: add FreeBSD support

PATCH Applied Tiwei Bie 3 participants 3 messages May 19, 2017 – Jun 5, 2017

lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

PATCH 1/1 examples/exception_path: add FreeBSD support

---
 examples/exception_path/Makefile |  9 ---------
 examples/exception_path/main.c   | 28 +++++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 10 deletions(-)
examples/exception_path/Makefile +0 -9
index 4b6e07175..76706c124 100644
@@ -38,13 +38,6 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc
 
 include $(RTE_SDK)/mk/rte.vars.mk
 
-ifneq ($(CONFIG_RTE_EXEC_ENV),"linuxapp")
-$(info This application can only operate in a linuxapp environment, \
-please change the definition of the RTE_TARGET environment variable)
-all:
-clean:
-else
-
 # binary name
 APP = exception_path
 
@@ -55,5 +48,3 @@ CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 
 include $(RTE_SDK)/mk/rte.extapp.mk
-
-endif
examples/exception_path/main.c +27 -1
index 89bf1cc06..fe30e0703 100644
@@ -42,8 +42,10 @@
 #include <getopt.h>
 
 #include <netinet/in.h>
-#include <linux/if.h>
+#include <net/if.h>
+#ifdef RTE_EXEC_ENV_LINUXAPP
 #include <linux/if_tun.h>
+#endif
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
@@ -182,6 +184,7 @@ signal_handler(int signum)
 	}
 }
 
+#ifdef RTE_EXEC_ENV_LINUXAPP
 /*
  * Create a tap network interface, or use existing one with same name.
  * If name[0]='\0' then a name is automatically assigned and returned in name.
@@ -214,6 +217,29 @@ static int tap_create(char *name)
 
 	return fd;
 }
+#else
+/*
+ * Find a free tap network interface, or create a new one.
+ * The name is automatically assigned and returned in name.
+ */
+static int tap_create(char *name)
+{
+	int i, fd = -1;
+	char devname[PATH_MAX];
+
+	for (i = 0; i < 255; i++) {
+		snprintf(devname, sizeof(devname), "/dev/tap%d", i);
+		fd = open(devname, O_RDWR);
+		if (fd >= 0 || errno != EBUSY)
+			break;
+	}
+
+	if (name)
+		snprintf(name, IFNAMSIZ, "tap%d", i);
+
+	return fd;
+}
+#endif
 
 /* Main processing loop */
 static int
Signature · 1 line
2.12.1
#2 lore raw

19/05/2017 12:57, Bruce Richardson:

Quoted 10 lines · Tiwei Bie
Quoted 6 lines
---
 examples/exception_path/Makefile |  9 ---------
 examples/exception_path/main.c   | 28 +++++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 10 deletions(-)

Tested compilation with both gcc5 and clang on FreeBSD 10.1.

Applied, thanks