1
0
Fork 0
mirror of https://passt.top/passt synced 2025-06-05 15:35:34 +02:00

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 <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-05-21 11:14:51 +02:00
parent 8ce188ecb0
commit 19d254bbbb
6 changed files with 114 additions and 44 deletions

14
pcap.c
View file

@ -20,6 +20,10 @@
#include <time.h>
#include <net/ethernet.h>
#include <unistd.h>
#include <net/if.h>
#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));
}