aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--pif.c21
-rw-r--r--pif.h19
3 files changed, 42 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d14b029..af4fa87 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,8 @@ FLAGS += -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)
PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c flow.c icmp.c \
igmp.c isolation.c lineread.c log.c mld.c ndp.c netlink.c packet.c \
- passt.c pasta.c pcap.c port_fwd.c tap.c tcp.c tcp_splice.c udp.c util.c
+ passt.c pasta.c pcap.c pif.c port_fwd.c tap.c tcp.c tcp_splice.c udp.c \
+ util.c
QRAP_SRCS = qrap.c
SRCS = $(PASST_SRCS) $(QRAP_SRCS)
diff --git a/pif.c b/pif.c
new file mode 100644
index 0000000..ebf01cc
--- /dev/null
+++ b/pif.c
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright Red Hat
+ * Author: David Gibson <david@gibson.dropbear.id.au>
+ *
+ * Passt/pasta interface types and IDs
+ */
+
+#include <stdint.h>
+#include <assert.h>
+
+#include "util.h"
+#include "pif.h"
+
+const char *pif_type_str[] = {
+ [PIF_NONE] = "<none>",
+ [PIF_HOST] = "HOST",
+ [PIF_TAP] = "TAP",
+ [PIF_SPLICE] = "SPLICE",
+};
+static_assert(ARRAY_SIZE(pif_type_str) == PIF_NUM_TYPES,
+ "pif_type_str[] doesn't match enum pif_type");
diff --git a/pif.h b/pif.h
index a705f2c..ca85b34 100644
--- a/pif.h
+++ b/pif.h
@@ -22,6 +22,25 @@ enum pif_type {
PIF_TAP,
/* Namespace socket interface for splicing */
PIF_SPLICE,
+
+ PIF_NUM_TYPES,
};
+#define PIF_NAMELEN 8
+
+extern const char *pif_type_str[];
+
+static inline const char *pif_type(enum pif_type pt)
+{
+ if (pt < PIF_NUM_TYPES)
+ return pif_type_str[pt];
+ else
+ return "?";
+}
+
+static inline const char *pif_name(uint8_t pif)
+{
+ return pif_type(pif);
+}
+
#endif /* PIF_H */