Skip to contentSkip to conversation

real-time monitor question

DISCUSSION Jeffrey D. Brower 2 participants 6 messages Aug 4, 2003 – Aug 6, 2003

lore
Share & tools
lore
#0 lore raw

Greetings All,

I need to get something that I think is probably quite simple from the firewall - but I don't have a clue how to exactly accomplish this. If you can help, please do!

I have a circuit board (hooked up to a box running netfilter/iptables) which counts and displays the data sent to it via the parallel port. The object is to display, in real-time, the packets on each interface that are accepted and denied on a packet by packet basis.

I trust netfilter and I don't want to interfere with its operation in any way and try to duplicate it's logic anywhere and it looks like the userspace options might force me to do this to get what I need, but I don't really know if it will or even if this is an option. I am not eager to actually queue packets myself - since I am sure to not be nearly as efficient.

I found a gnumonks.org project called ulogd that seems like it _could_ be a solution for me but I know nothing about it, including if I can get ACCEPT and DENY, by interface, by packet, buffered from it.

It seemed to me that I can jump to tables for ACCEPT1 - ACCEPTn and the same for DENY1 - DENYn for each of the interfaces and use the log function in some way - but using the log for each packet seems nightmarish to me.

It occurs to me that there might be something I can do with the /proc files.

It also seems to me that any program I write that gets the info from the firewall might have to do a sleep to await the logic in the board to process and so I might have to buffer the information from the firewall to avoid slowing it down or do some kind of round-robin sort of stack as long as the stack is larger than the potential input flood. It may be that I do not need to actually keep track of every single solitary ACCEPT but I surely need every DENY.

I learn best by example, and I can not find any examples of this anywhere - but I know people do monitoring. I have been in the Docs and I have looked in the archives of this list (but they are not searchable). If you can help me understand what I need to do - please help!

Jeff

#1 lore raw

Hi Jeffrey,

Quoted 11 lines

I have a circuit board (hooked up to a box running netfilter/iptables) which counts and displays the data sent to it via the parallel port. The object is to display, in real-time, the packets on each interface that are accepted and denied on a packet by packet basis.

I trust netfilter and I don't want to interfere with its operation in any way and try to duplicate it's logic anywhere and it looks like the userspace options might force me to do this to get what I need, but I don't really know if it will or even if this is an option. I am not eager to actually queue packets myself - since I am sure to not be nearly as efficient.

Quoted 3 lines

I found a gnumonks.org project called ulogd that seems like it _could_ be a solution for me but I know nothing about it, including if I can get ACCEPT and DENY, by interface, by packet, buffered from it.

I think that ulogd, and the ULOG target which feeds it, are the best solution in this case.

Quoted 3 lines

It seemed to me that I can jump to tables for ACCEPT1 - ACCEPTn and the same for DENY1 - DENYn for each of the interfaces and use the log function in some way - but using the log for each packet seems nightmarish to me.

Why is that? It seems to be the best way to distinguish between packets being dropped in different places. If you only want a graph of ALL packets accepted and ALL packets dropped, then just create a couple of chains:

  iptables -N my_accept
  iptables -A my_accept -j ULOG --ulog-prefix "ACCEPT"
  iptables -A my_accept -j ACCEPT

  iptables -N my_drop
  iptables -A my_drop -j ULOG --ulog-prefix "DROP"
  iptables -A my_drop -j DROP

Then you can change ACCEPT and DROP in your firewall rules to my_accept and my_drop resppectively. From your user-space application, which could most easily be based on ulogd, you can read the log prefix of each packet you receive to determine whether that packet was accepted or dropped.

Quoted 1 line

It occurs to me that there might be something I can do with the /proc files.

As far as I know there are no counters of ACCEPTed/DROPped packets in /proc, but you could run "iptables -L -n -v" and parse the output to see the number of packets dropped at each rule.

Quoted 7 lines

It also seems to me that any program I write that gets the info from the firewall might have to do a sleep to await the logic in the board to process and so I might have to buffer the information from the firewall to avoid slowing it down or do some kind of round-robin sort of stack as long as the stack is larger than the potential input flood. It may be that I do not need to actually keep track of every single solitary ACCEPT but I surely need every DENY.

Maybe have a process which fork()s with either end of a pipe(). One process reads from Netfilter and writes to the pipe every so often (with a non-blocking write), while the other process reads from the pipe and writes to the hardware.

Hope this helps!

Cheers, Chris.

Signature · 4 lines
   ___ __     _
 / __// / ,__(_)_  | Chris Wilson -- UNIX Firewall Lead Developer |
/ (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk |
\ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
#2 lore raw
Quoted 2 lines

I think that ulogd, and the ULOG target which feeds it, are the best solution in this case.

Based on that statement I got more deeply into the ULOG and it looks good. I found an extention in the CVS called ulogd_OPRINT.c which (although I can not find the documentation on its use) LOOKS like it is almost exactly what I need. Can it be that my solution could be as simple as replacing the _output_print() function with my own function that prints to the circuit board?

Quoted 2 lines

Why is that? It seems to be the best way to distinguish between packets being dropped in different places.

I was really refering to the horrors of a huge syslog as each packet gets logged and reading that log file to drive the circuit board and all the maintenance nightmares with it.

Quoted 10 lines

If you only want a graph of ALL packets
accepted and ALL packets dropped, then just create a couple of chains:

  iptables -N my_accept
  iptables -A my_accept -j ULOG --ulog-prefix "ACCEPT"
  iptables -A my_accept -j ACCEPT

  iptables -N my_drop
  iptables -A my_drop -j ULOG --ulog-prefix "DROP"
  iptables -A my_drop -j DROP

This confused me until I realized that the ULOG returns the packets for further processing. I had (in error) thought that I would have to deal with the packet resolution in userspace.

Quoted 1 line
Quoted 1 line

It occurs to me that there might be something I can do with the /proc

files.

Quoted 2 lines

As far as I know there are no counters of ACCEPTed/DROPped packets in

/proc

Another suggestion that I got kind of steered me toward lookng at bytes rather than packets and I wonder if I can't just read one of the /proc files to see the number of bytes accepted and denyed - the assumption being that I could log bytes to the board and let the log files watch for connections keeping the size of the log file down while still presenting a real-time interface for the operator via the circuit board. As I understand it, I can read a /proc file 10 times a second with little impact on the system (as bizzare as that sounds to me).

Quoted 1 line

but you could run "iptables -L -n -v" and parse the output to see the

number of

Quoted 1 line

packets dropped at each rule.

seems like a lot of overhead.

Quoted 4 lines

Maybe have a process which fork()s with either end of a pipe(). One process reads from Netfilter and writes to the pipe every so often (with a non-blocking write), while the other process reads from the pipe and writes to the hardware.

Never having done a fork(), nor a pipe() nor reads from Netfilter - this sounds like a lot of fun to me (but like a heck of a learning curve). It sounds like what I envisioned, but I wonder if the pipe won't get stuffed too fast and halt the input side causing lost packets, etc. It really seems like this exactly what I need to code in the _output_print() function of the ulogd_OPRINT.c program - but again, how do I keep it from over-running the pipe?

Quoted 1 line

Hope this helps!

Yes it did.

#3 lore raw

Hi Jeffrey,

Quoted 6 lines

Based on that statement I got more deeply into the ULOG and it looks good. I found an extention in the CVS called ulogd_OPRINT.c which (although I can not find the documentation on its use) LOOKS like it is almost exactly what I need. Can it be that my solution could be as simple as replacing the _output_print() function with my own function that prints to the circuit board?

It could certainly be that easy, but I'm not familiar with the code in question.

Quoted 3 lines

Another suggestion that I got kind of steered me toward lookng at bytes rather than packets and I wonder if I can't just read one of the /proc files to see the number of bytes accepted and denyed

Unfortunately I don't think there are any counters for this either in /proc. You would still have to use libiptc or parse the output of iptables -L -n -v.

Quoted 4 lines

Never having done a fork(), nor a pipe() nor reads from Netfilter - this sounds like a lot of fun to me (but like a heck of a learning curve). It sounds like what I envisioned, but I wonder if the pipe won't get stuffed too fast and halt the input side causing lost packets, etc.

If you set the O_NONBLOCK option on your end of the pipe, then if the pipe is full the operating system will just return an EAGAIN error immediately, instead of waiting for the pipe to empty. In any case, it doesn't matter much if the input process blocks, since packet processing will continue anyway without interference from your process.

Cheers, Chris.

Signature · 4 lines
   ___ __     _
 / __// / ,__(_)_  | Chris Wilson -- UNIX Firewall Lead Developer |
/ (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk |
\ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
#5 lore raw
In reply to Jeffrey D. Brower

Hi Jeffrey,

Quoted 2 lines

Let me be sure I understand all my input from the list: (1) By setting the O_NONBLOCK option on my end of the pipe

By the way, you would have both ends of this particular pipe, since its purpose is to isolate the part of your application which reads from Netfilter, from the part which writes to the display. It may not even be necessary since, as you say:

Quoted 2 lines

all I would loose would be the information on the packets that hit while the pipe is full

Yes, I believe so.

Quoted 2 lines

(2) but the packets that hit while the pipe was full would process correctly anyway

Yes, it's my understanding that with the ULOG target, unlike QUEUE, Netfilter will not wait for your application, or even care what it does, as far as the processing of the packet which hit the ULOG target is concerned.

Quoted 3 lines

(3) the input process can block and the output process nonblock so that the packet filter can run full speed and I can potentially not miss anything since the input side blocks and give me more time.

Yes, that's right.

Quoted 2 lines

Do you know if ULOG can send an entry once a second with a summary of # of packets that hit rules which would give me fewer reads on the pipe?

As far as I know, it cannot.

Cheers, Chris.

Signature · 4 lines
   ___ __     _
 / __// / ,__(_)_  | Chris Wilson -- UNIX Firewall Lead Developer |
/ (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk |
\ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
#4 lore raw
In reply to Chris Wilson

Hi Chris,

You are a big help again! Thanks for your replies.

Quoted 5 lines

If you set the O_NONBLOCK option on your end of the pipe, then if the pipe is full the operating system will just return an EAGAIN error immediately, instead of waiting for the pipe to empty. In any case, it doesn't matter much if the input process blocks, since packet processing will continue anyway without interference from your process.

Very cool. I would want to continue processing packets even if my process was falling behind so that works for me.

Let me be sure I understand all my input from the list: (1) By setting the O_NONBLOCK option on my end of the pipe, all I would loose would be the information on the packets that hit while the pipe is full, (2) but the packets that hit while the pipe was full would process correctly anyway, and (3) the input process can block and the output process nonblock so that the packet filter can run full speed and I can potentially not miss anything since the input side blocks and give me more time.

Do you know if ULOG can send an entry once a second with a summary of # of packets that hit rules which would give me fewer reads on the pipe?

Jeff