diff options
author | Paolo Abeni <pabeni@redhat.com> | 2017-09-13 17:54:52 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-09-15 08:41:02 +0200 |
commit | 443d97581b9b715b8f40ae35fdeaf272caa296a4 (patch) | |
tree | b558429433a627ec9c03f348bcdd668fa4568686 /trafgen.c | |
parent | 285ac73006e2e4af6e0e4cb0eaa178b13cdcba8f (diff) |
trafgen: fix packet socket initialization with multiple CPUs
The commit 78c13b71e196 ("trafgen: Allow to generate packets
to output pcap file") introduced a regression when output is
a network device and multiple CPU are in use: the packet
socket is created before fork() and thus the socket is shared
among all the processes: all of them except the first will
fail while setting the tx_ring.
Fix it splitting the io open() helper in a create() op,
called before forking, and the open() op called by each process.
Fixes: 78c13b71e196 ("trafgen: Allow to generate packets to output pcap file")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen.c')
-rw-r--r-- | trafgen.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -977,6 +977,7 @@ static void main_loop(struct ctx *ctx, char *confname, bool slow, fflush(stdout); } + dev_io_open(ctx->dev_out); if (dev_io_is_netdev(ctx->dev_out) && ctx->qdisc_path == false) set_sock_qdisc_bypass(dev_io_fd_get(ctx->dev_out), ctx->verbose); @@ -1266,12 +1267,13 @@ int main(int argc, char **argv) xlockme(); if (ctx.pcap_in) { - ctx.dev_in = dev_io_open(ctx.pcap_in, DEV_IO_IN); + ctx.dev_in = dev_io_create(ctx.pcap_in, DEV_IO_IN); if (!ctx.dev_in) panic("Failed to open input device\n"); + dev_io_open(ctx.dev_in); } - ctx.dev_out = dev_io_open(ctx.device, DEV_IO_OUT); + ctx.dev_out = dev_io_create(ctx.device, DEV_IO_OUT); if (!ctx.dev_out) panic("Failed to open output device\n"); |