X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=listener.lsp;h=388486f6a14d5badcd5ff10e392fbc58d1facf60;hb=219ac38b36dd119573d0ad0dcf10cf29cbc1743f;hp=bd823f2fc7c2faf31a9a88a9ff9085fff534c770;hpb=05a9c528d8aee0373f52fa1bc72250e7f3625e76;p=rrq%2Fhourglass.git diff --git a/listener.lsp b/listener.lsp index bd823f2..388486f 100644 --- a/listener.lsp +++ b/listener.lsp @@ -11,9 +11,7 @@ (signal 2 (fn (x) (exit 0))) # The following is for Devuan GNU+Linux -(constant 'LIBC (exists file? '("/lib/x86_64-linux-gnu/libc.so.6" - "/lib/i386-linux-gnu/libc.so.6" - ))) +(constant 'LIBC SITE:libc) (import LIBC "ioctl" "int" "int" "long" "void*" ) (import LIBC "perror" "void" "char*" ) (import LIBC "ntohl" "int" "int" ) @@ -31,18 +29,23 @@ (if (null? a) v (nil? v) true (null? (1 a)) v (a 1)))) # Set logging mode. -(constant 'listener-log-ip (mainarg "-l" nil)) - # Open the tap named by "-t tapX" on the command line, or "tap0" byt # default. Then make a TUNSETIFF call to initialize it (as # IFF_TAP|IFF_NO_PI). -(constant 'IFNAME (mainarg "-t" "tap0") 'IFD (open "/dev/net/tun" "u") ) +(constant + 'listener-log-ip SITE:listener.log.ip + 'IFNAME SITE:listener.tap + 'PORTS SITE:listener.ports + 'IFD (open SITE:tundev "u") + 'ACTNAMEFMT "%d%02d%02d-network.dat" + 'ACTDIR SITE:listener.activity.dir + 'ACTFILEFMT (format "%s/%s" ACTDIR ACTNAMEFMT ) +) (unless (number? IFD) (die "open")) (unless (zero? (ioctl IFD 0x400454ca (pack "s16 u s22" IFNAME 0x1002 ""))) (die (string "set " IFNAME))) # The TCP ports of interest -(constant 'PORTS '(80 443)) # Set up for optional tracking of IP addresses (define counter:counter nil) @@ -67,12 +70,13 @@ # This funcion collates all given ips, and it extends the log line # with the list of ips used during the minute. (setf next-mark 0 packet-count 0) + (define (mark-active t) ; buffer (when listener-log-ip (track-data)) (inc packet-count) ;(write-line 2 (string (list t packet-count ports (counter)))) (when (>= t next-mark) - (let ((d (format "activity/%d%02d%02d-network.dat" (0 3 (date-list t)))) + (let ((d (format ACTFILEFMT (0 3 (date-list t)))) (c (map string (counter)))) (append-file d (string t " " packet-count " " (join c " ") "\n")) (setf next-mark (+ t 60) packet-count 0) @@ -112,8 +116,8 @@ (define (udp-handler) ; buffer ihl (let ((ports (map ntohs (unpack "uu" ((+ ihl 14) buffer))))) - (when (intersect ports PORTS) (mark-active (date-value))))) - + (when PORTS (intersect ports PORTS) (mark-active (date-value))))) + # Handle an IPv4 packet. It recognises the IPv4 protocol concerned, # and dispatches to the associated handler, if any. (define (ipv4-handler) ; buffer