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>
This commit is contained in:
David Gibson 2023-11-30 13:02:20 +11:00 committed by Stefano Brivio
parent 460064d262
commit cf83988e96
3 changed files with 42 additions and 1 deletions

View file

@ -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 \ 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 \ 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 QRAP_SRCS = qrap.c
SRCS = $(PASST_SRCS) $(QRAP_SRCS) SRCS = $(PASST_SRCS) $(QRAP_SRCS)

21
pif.c Normal file
View file

@ -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");

19
pif.h
View file

@ -22,6 +22,25 @@ enum pif_type {
PIF_TAP, PIF_TAP,
/* Namespace socket interface for splicing */ /* Namespace socket interface for splicing */
PIF_SPLICE, 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 */ #endif /* PIF_H */