aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-30 13:02:20 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-12-04 09:51:29 +0100
commitcf83988e967405e898f85bec3da04714b1557397 (patch)
tree4922ca437acfd77605e58918a5faac8082145e9c
parent460064d262114abc809c5e739789722ca9b0d432 (diff)
downloadpasst-cf83988e967405e898f85bec3da04714b1557397.tar
passt-cf83988e967405e898f85bec3da04714b1557397.tar.gz
passt-cf83988e967405e898f85bec3da04714b1557397.tar.bz2
passt-cf83988e967405e898f85bec3da04714b1557397.tar.lz
passt-cf83988e967405e898f85bec3da04714b1557397.tar.xz
passt-cf83988e967405e898f85bec3da04714b1557397.tar.zst
passt-cf83988e967405e898f85bec3da04714b1557397.zip
pif: Add helpers to get the name of a pif
Future debugging will want to identify a specific passt interface. We make a distinction in these helpers between the name of the *type* of pif, and name of the pif itself. For the time being these are always the same thing, since we have at most instance of each type of pif. However, that might change in future. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-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 */