From a4703f2a060a81397da497b85bc135187f0f89e9 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 9 Apr 2013 09:51:26 +0200 Subject: pcap_io: introduce init_once helper that is called with priviledges When using netsniff-ng with dropping priviledges, we have to introduce another pcap helper function that is called once before we drop the priviledges. In this function we have to invoke the disc I/O scheduler policy, because it needs priviledges. Otherwise netsniff-ng will fail with "Failed to set io prio for pid" on startup, since we're not root anymore. Reported-by: Doug Burks Signed-off-by: Daniel Borkmann --- pcap_mm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pcap_mm.c') diff --git a/pcap_mm.c b/pcap_mm.c index f3b3fd0..28b0469 100644 --- a/pcap_mm.c +++ b/pcap_mm.c @@ -148,10 +148,13 @@ static void __pcap_mm_prepare_access_rd(int fd) ptr_va_curr = ptr_va_start + sizeof(struct pcap_filehdr); } -static int pcap_mm_prepare_access(int fd, enum pcap_mode mode, bool jumbo) +static void pcap_mm_init_once(void) { set_ioprio_be(); +} +static int pcap_mm_prepare_access(int fd, enum pcap_mode mode, bool jumbo) +{ switch (mode) { case PCAP_MODE_RD: __pcap_mm_prepare_access_rd(fd); @@ -187,6 +190,7 @@ static void pcap_mm_prepare_close(int fd, enum pcap_mode mode) } const struct pcap_file_ops pcap_mm_ops = { + .init_once_pcap = pcap_mm_init_once, .pull_fhdr_pcap = pcap_generic_pull_fhdr, .push_fhdr_pcap = pcap_generic_push_fhdr, .prepare_access_pcap = pcap_mm_prepare_access, -- cgit v1.2.3-54-g00ecf