/* pdumpq - Pcap Dump for Linux/Netfilter QUEUE * * Copyright (C) 2001 Ian Jones * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include int main (int argc, char **argv) { int read; char inbuf[2048]; v.rotate = MAX_ROTATE; v.mcount = 0; #ifdef POLICY v.policy = POLICY; #else v.policy = NF_DROP; #endif /* POLICY */ #ifdef MAIL v.mail = 0; v.timer = Q_TIME; v.maxq = MAX_Q; #endif /* MAIL */ umask (0077); cmdline (argc, argv); set_signals (); if (v.daemon) detach (); ipq_init (); if (!open_file (v.dumpfile)) crash ("opening dump file:pdumpq"); for (;;) { read = ipq_read (v.h, inbuf, 2048, 0); sigprocmask (SIG_BLOCK, &v.sa.sa_mask, 0); /* hold signals */ /* ignore non-pkt messages */ if (read > 0 && (ipq_message_type (inbuf) == IPQM_PACKET)) { register int i; int markmatch; ipq_packet_msg_t *m = ipq_get_packet (inbuf); if (!m) continue; if (v.mcount) { markmatch = 0; for (i = 0; i < v.mcount; i++) { if (v.marks[i] == m->mark) { process_pkt (m, v.verdicts[i]); markmatch = 1; } } if (!markmatch) ipq_set_verdict (v.h, m->packet_id, v.policy, 0, NULL); } else process_pkt (m, v.policy); } #ifdef MAIL if (v.mail && queue->flush == 1) mail (); #endif /* MAIL */ read = 0; sigprocmask (SIG_UNBLOCK, &v.sa.sa_mask, 0); } }