summaryrefslogtreecommitdiff
path: root/trafgen_dev.c
diff options
context:
space:
mode:
authorPaolo Abeni <pabeni@redhat.com>2017-09-13 17:54:52 +0200
committerTobias Klauser <tklauser@distanz.ch>2017-09-15 08:41:02 +0200
commit443d97581b9b715b8f40ae35fdeaf272caa296a4 (patch)
treeb558429433a627ec9c03f348bcdd668fa4568686 /trafgen_dev.c
parent285ac73006e2e4af6e0e4cb0eaa178b13cdcba8f (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_dev.c')
-rw-r--r--trafgen_dev.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/trafgen_dev.c b/trafgen_dev.c
index f65442f..489da98 100644
--- a/trafgen_dev.c
+++ b/trafgen_dev.c
@@ -242,10 +242,11 @@ static const struct dev_io_ops dev_cfg_ops = {
.close = dev_cfg_close,
};
-struct dev_io *dev_io_open(const char *name, enum dev_io_mode_t mode)
+struct dev_io *dev_io_create(const char *name, enum dev_io_mode_t mode)
{
struct dev_io *dev = xzmalloc(sizeof(struct dev_io));
+ dev->mode = mode;
if (strstr(name, ".pcap")) {
dev->name = xstrdup(name);
dev->ops = &dev_pcap_ops;
@@ -260,16 +261,20 @@ struct dev_io *dev_io_open(const char *name, enum dev_io_mode_t mode)
return NULL;
}
- if (dev->ops->open) {
- if (dev->ops->open(dev, name, mode)) {
- xfree(dev);
- return NULL;
- }
- }
-
return dev;
};
+extern void dev_io_open(struct dev_io *dev)
+{
+ bug_on(!dev);
+ bug_on(!dev->ops);
+
+ if (dev->ops->open)
+ if (dev->ops->open(dev, dev->name, dev->mode))
+ panic("Cannot open io %s mode %d\n", dev->name,
+ dev->mode);
+}
+
int dev_io_write(struct dev_io *dev, struct packet *pkt)
{
bug_on(!dev);