diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2021-05-21 11:14:51 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2021-05-21 11:14:51 +0200 |
commit | 19d254bbbb3ab319d15891ff7287f5182980c105 (patch) | |
tree | 160fbdecfe6b6e255e05236590325260be51cfd4 /pcap.c | |
parent | 8ce188ecb0a0d19874f8c0e663d5d8adffa50d43 (diff) | |
download | passt-19d254bbbb3ab319d15891ff7287f5182980c105.tar passt-19d254bbbb3ab319d15891ff7287f5182980c105.tar.gz passt-19d254bbbb3ab319d15891ff7287f5182980c105.tar.bz2 passt-19d254bbbb3ab319d15891ff7287f5182980c105.tar.lz passt-19d254bbbb3ab319d15891ff7287f5182980c105.tar.xz passt-19d254bbbb3ab319d15891ff7287f5182980c105.tar.zst passt-19d254bbbb3ab319d15891ff7287f5182980c105.zip |
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>
Diffstat (limited to 'pcap.c')
-rw-r--r-- | pcap.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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)); } |