2 * \author Edward Fjellskål <edward.fjellskaal@redpill-linpro.com>
3 * \author Kacper Wysocki <comotion@krutt.org>
6 //#include "../common.h"
9 #include "../sys_func.h" // u_ntop
12 #include "log_stdout.h"
17 output_plugin
*log_output
[LOG_MAX
];
19 /* set up function pointers for logging */
20 int init_logging(int logtype
, const char *file
, int flags
)
23 output_plugin
*log_fun
;
27 log_fun
= init_log_file();
30 log_fun
= init_log_stdout();
33 log_fun
= init_log_fifo();
35 /* these types are coming !*/
41 fprintf(stderr
,"whoops! init_logging\n");
44 log_output
[n_outputs
++] = log_fun
;
46 rc
= log_fun
->init(log_fun
, file
, flags
);
56 /* magic logging function - iterate over all loggers */
57 // note... this breaks anywhere non-GNU!
58 #define log_foo(func, all, count, ...) \
61 for(_i = 0; _i < (count) ; _i++) { \
62 output_plugin* _p = (all)[_i]; \
63 if(_p && _p -> func) \
64 _p -> func(_p, ##__VA_ARGS__); \
71 log_foo(denit
, log_output
, n_outputs
);
74 void log_asset_arp (asset
*masset
)
77 static char ip_addr_s
[INET6_ADDRSTRLEN
];
78 inet_ntop(AF_INET
, &masset
->ip_addr
.s6_addr32
[0], ip_addr_s
, INET_ADDRSTRLEN
+ 1 );
79 dlog("[*] added mac address to asset: %s\n",ip_addr_s
);
81 log_foo(arp
, log_output
, n_outputs
, masset
);
84 void log_asset_os (asset
*main
, os_asset
*os
, connection
*cxt
)
87 static char ip_addr_s
[INET6_ADDRSTRLEN
];
88 u_ntop(main
->ip_addr
, main
->af
, ip_addr_s
);
90 dlog("[%lu] Incoming asset, %s: %s:%u [%s]\n",
91 os
->last_seen
, (char*)bdata(os
->detection
),ip_addr_s
,ntohs(os
->port
),(char*)bdata(os
->raw_fp
));
94 log_foo(os
, log_output
, n_outputs
, main
, os
, cxt
);
97 void log_asset_service (asset
*main
, serv_asset
*service
, connection
*cxt
)
100 static char ip_addr_s
[INET6_ADDRSTRLEN
];
101 u_ntop(main
->ip_addr
, main
->af
, ip_addr_s
);
102 if (service
->role
== SC_SERVER
) {
103 fprintf(stderr
, "[*] new service: %s:%d %s\n",ip_addr_s
,ntohs(service
->port
),(char *)bdata(service
->application
));
105 fprintf(stderr
, "[*] new client: %s:%d %s\n",ip_addr_s
,ntohs(service
->port
),(char *)bdata(service
->application
));
108 log_foo(service
, log_output
, n_outputs
, main
, service
, cxt
);
112 /* log_connection(cxt, fd): write cxt to fd, with the following format:
113 ** startsec|id|start time|end time|total time|proto|src|sport|dst|dport|s_packets|s_bytes|d_packets|d_bytes|s_flags|d_flags
117 * question is only whether to dump ip address as int or human readable
119 //asprintf(&cxtfname, "%s/stats.%s.%ld", dpath, dev, tstamp);
120 //cxtFile = fopen(cxtfname, "w");
122 void log_connection(connection
*cxt
, FILE* fd
, int outputmode
)
124 char stime
[80], ltime
[80];
126 uint32_t s_ip_t
, d_ip_t
;
127 static char src_s
[INET6_ADDRSTRLEN
];
128 static char dst_s
[INET6_ADDRSTRLEN
];
129 strftime(stime
, 80, "%F %H:%M:%S", gmtime(&cxt
->start_time
));
130 strftime(ltime
, 80, "%F %H:%M:%S", gmtime(&cxt
->last_pkt_time
));
132 tot_time
= cxt
->last_pkt_time
- cxt
->start_time
;
133 if ( cxt
->af
== AF_INET
) {
134 s_ip_t
= ntohl(cxt
->s_ip
.s6_addr32
[0]);
135 d_ip_t
= ntohl(cxt
->d_ip
.s6_addr32
[0]);
138 fprintf(fd
, "%ld%09ju|%s|%s|%ld|%u|",
139 cxt
->start_time
, cxt
->cxid
, stime
, ltime
, tot_time
,
141 if(outputmode
|| cxt
->af
== AF_INET6
) {
142 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->s_ip
: (void*) cxt
->s_ip
.s6_addr32
), src_s
, INET6_ADDRSTRLEN
))
144 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->d_ip
: (void*) cxt
->d_ip
.s6_addr32
), dst_s
, INET6_ADDRSTRLEN
))
146 fprintf(fd
, "%s|%u|%s|%u|",
147 src_s
, ntohs(cxt
->s_port
),
148 dst_s
, ntohs(cxt
->d_port
));
150 fprintf(fd
, "%u|%u|%u|%u|",
151 s_ip_t
, ntohs(cxt
->s_port
),
152 d_ip_t
, ntohs(cxt
->d_port
));
154 fprintf(fd
, "%ju|%ju|",
155 cxt
->s_total_pkts
, cxt
->s_total_bytes
);
156 fprintf(fd
, "%ju|%ju|%u|%u",
157 cxt
->d_total_pkts
, cxt
->d_total_bytes
,
158 cxt
->s_tcpFlags
, cxt
->d_tcpFlags
);
159 // hack to distinguish output paths
161 switch (outputmode
) {
172 if(o
) fprintf(fd
, "|%s", o
);