Skip to content

Commit e4ee5cf

Browse files
committed
NFLOG: IPv4 network addresses writes to syslog (event emitted with)
1 parent 4cce54b commit e4ee5cf

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

src/common.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <fcntl.h>
55
#include <stdio.h>
66
#include <stdlib.h>
7+
#include <stdint.h>
78
#include <string.h>
89
#include <sys/ioctl.h>
910
#include <net/if.h>
@@ -21,12 +22,12 @@
2122
#define VERSION "\ntuninetd 1.3.1\n"
2223

2324
//global vars.
24-
short int debug;
25-
short int status;
26-
unsigned long ts;
27-
unsigned long curts;
25+
extern short int debug;
26+
extern short int status;
27+
extern unsigned long ts;
28+
extern unsigned long curts;
2829

29-
struct globcfg_t {
30+
extern struct globcfg_t {
3031
short int isdaemon;
3132
pid_t pid;
3233
char *cmd_path;

src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#include "main.h"
22

3+
//Global vars --
4+
short int debug;
5+
short int status;
6+
unsigned long ts;
7+
unsigned long curts;
8+
9+
struct globcfg_t globcfg;
10+
// -- Global vars
11+
312
int main(int argc, char *argv[])
413
{
514
curts = time(NULL);

src/xnflog.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,33 @@ static void setnlbufsiz(unsigned int size, struct nflog_handle *h)
2020

2121
static int callback(struct nflog_g_handle *gh, struct nfgenmsg *nfmsg, struct nflog_data *ldata, void *data)
2222
{
23-
if (status == OFF) {
24-
message(INFO, "NFLOG: executing START command...");
25-
switch_guard(ON);
23+
ts = curts;
24+
25+
if (status == ON) {
26+
return 0;
2627
}
2728

28-
ts = curts;
29+
uint8_t *payload;
30+
31+
int payload_fetch_result = nflog_get_payload(ldata, &payload);
32+
33+
if (payload_fetch_result < 0) {
34+
return 0;
35+
}
36+
37+
message(INFO, "NFLOG: executing START command...");
38+
39+
if (payload[0] >> 4 == 4) { //4 bit MSB IP version. IPv4 in this case. TODO: implement for IPv6
40+
message(INFO, "|- IPv4 SRC: %i.%i.%i.%i DST: %i.%i.%i.%i", payload[12], payload[13], payload[14], payload[15], payload[16], payload[17], payload[18], payload[19]);
41+
42+
struct nfulnl_msg_packet_hw *hw = nflog_get_packet_hw(ldata);
43+
44+
if (hw) { //Hardware information only available on inbound or transit packets
45+
message(INFO, "|- HWaddr: %02x:%02x:%02x:%02x:%02x:%02x, DevIndex: %u", hw->hw_addr[0], hw->hw_addr[1], hw->hw_addr[2], hw->hw_addr[3], hw->hw_addr[4], hw->hw_addr[5], nflog_get_indev(ldata));
46+
}
47+
}
48+
49+
switch_guard(ON);
2950

3051
return 0;
3152
}

0 commit comments

Comments
 (0)