summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-04-22 19:26:11 +0300
committerTobias Klauser <tklauser@distanz.ch>2015-04-22 21:58:21 +0200
commit56d79391b748563cc5075b9d31fe199db8a2d093 (patch)
tree9718b110636556ac844637009e71606e61182eec
parentc69c838def37d46008e85fdc2f817fc9fd70c4d5 (diff)
netsniff-ng: Don't set IO prio when reading pcap file
It allows to read pcap file for users who have no permissions to set process IO prio. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Acked-by: Daniel Borkmann <borkmann@iogearbox.net> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--netsniff-ng.c6
-rw-r--r--pcap_io.h2
-rw-r--r--pcap_mm.c5
-rw-r--r--pcap_rw.c5
-rw-r--r--pcap_sg.c5
5 files changed, 13 insertions, 10 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 4ad8b19..ee9dc38 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -228,7 +228,7 @@ static void pcap_to_xmit(struct ctx *ctx)
}
if (__pcap_io->init_once_pcap)
- __pcap_io->init_once_pcap();
+ __pcap_io->init_once_pcap(true);
ret = __pcap_io->pull_fhdr_pcap(fd, &ctx->magic, &ctx->link_type);
if (ret)
@@ -567,7 +567,7 @@ static void read_pcap(struct ctx *ctx)
}
if (__pcap_io->init_once_pcap)
- __pcap_io->init_once_pcap();
+ __pcap_io->init_once_pcap(false);
ret = __pcap_io->pull_fhdr_pcap(fd, &ctx->magic, &ctx->link_type);
if (ret)
@@ -963,7 +963,7 @@ static void recv_only_or_dump(struct ctx *ctx)
ifflags = device_enter_promiscuous_mode(ctx->device_in);
if (dump_to_pcap(ctx) && __pcap_io->init_once_pcap)
- __pcap_io->init_once_pcap();
+ __pcap_io->init_once_pcap(true);
drop_privileges(ctx->enforce, ctx->uid, ctx->gid);
diff --git a/pcap_io.h b/pcap_io.h
index c3fc951..35faa51 100644
--- a/pcap_io.h
+++ b/pcap_io.h
@@ -122,7 +122,7 @@ enum pcap_mode {
};
struct pcap_file_ops {
- void (*init_once_pcap)(void);
+ void (*init_once_pcap)(bool enforce_prio);
int (*pull_fhdr_pcap)(int fd, uint32_t *magic, uint32_t *linktype);
int (*push_fhdr_pcap)(int fd, uint32_t magic, uint32_t linktype);
int (*prepare_access_pcap)(int fd, enum pcap_mode mode, bool jumbo);
diff --git a/pcap_mm.c b/pcap_mm.c
index 5b3cfcb..f7b248e 100644
--- a/pcap_mm.c
+++ b/pcap_mm.c
@@ -148,9 +148,10 @@ static void __pcap_mm_prepare_access_rd(int fd)
ptr_va_curr = ptr_va_start + sizeof(struct pcap_filehdr);
}
-static void pcap_mm_init_once(void)
+static void pcap_mm_init_once(bool enforce_prio)
{
- set_ioprio_be();
+ if (enforce_prio)
+ set_ioprio_be();
}
static int pcap_mm_prepare_access(int fd, enum pcap_mode mode, bool jumbo)
diff --git a/pcap_rw.c b/pcap_rw.c
index 5a739da..b6be922 100644
--- a/pcap_rw.c
+++ b/pcap_rw.c
@@ -57,9 +57,10 @@ static ssize_t pcap_rw_read(int fd, pcap_pkthdr_t *phdr, enum pcap_type type,
return hdrsize + hdrlen;
}
-static void pcap_rw_init_once(void)
+static void pcap_rw_init_once(bool enforce_prio)
{
- set_ioprio_rt();
+ if (enforce_prio)
+ set_ioprio_rt();
}
static void pcap_rw_fsync(int fd)
diff --git a/pcap_sg.c b/pcap_sg.c
index 9d07656..80c2c5d 100644
--- a/pcap_sg.c
+++ b/pcap_sg.c
@@ -145,9 +145,10 @@ static void pcap_sg_fsync(int fd)
fdatasync(fd);
}
-static void pcap_sg_init_once(void)
+static void pcap_sg_init_once(bool enforce_prio)
{
- set_ioprio_rt();
+ if (enforce_prio)
+ set_ioprio_rt();
}
static int pcap_sg_prepare_access(int fd, enum pcap_mode mode, bool jumbo)