From 19d254bbbb3ab319d15891ff7287f5182980c105 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Fri, 21 May 2021 11:14:51 +0200 Subject: passt: Add support for multiple instances in different network namespaces ...sharing the same filesystem. Instead of a fixed path for the UNIX domain socket, passt now uses a path with a counter, probing for existing instances, and picking the first free one. The demo script is updated accordingly -- it can now be started several times to create multiple namespaces with an instance of passt each, with addressing reflecting separate subnets, and NDP proxying between them. Signed-off-by: Stefano Brivio --- pcap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'pcap.c') diff --git a/pcap.c b/pcap.c index 2767b53..8dd647a 100644 --- a/pcap.c +++ b/pcap.c @@ -20,6 +20,10 @@ #include #include #include +#include + +#include "passt.h" +#include "util.h" #ifdef DEBUG @@ -77,9 +81,9 @@ void pcap(char *pkt, size_t len) write(pcap_fd, pkt, len); } -void pcap_init(void) +void pcap_init(int sock_index) { - char name[] = PCAP_PREFIX PCAP_ISO8601_STR ".pcap"; + char name[] = PCAP_PREFIX PCAP_ISO8601_STR STR(UNIX_SOCK_MAX) ".pcap"; struct timeval tv; struct tm *tm; @@ -88,6 +92,10 @@ void pcap_init(void) strftime(name + strlen(PCAP_PREFIX), sizeof(PCAP_ISO8601_STR) - 1, PCAP_ISO8601_FORMAT, tm); + snprintf(name + strlen(PCAP_PREFIX) + strlen(PCAP_ISO8601_STR), + sizeof(name) - strlen(PCAP_PREFIX) - strlen(PCAP_ISO8601_STR), + "_%i.pcap", sock_index); + pcap_fd = open(name, O_WRONLY | O_CREAT | O_APPEND | O_DSYNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (pcap_fd == -1) { @@ -95,6 +103,8 @@ void pcap_init(void) return; } + info("Saving packet capture at %s", name); + write(pcap_fd, &pcap_hdr, sizeof(pcap_hdr)); } -- cgit v1.2.3