OSF update: netlink logging
Hello, Harald.
Hello, all.
This patches add possibility to log OSF events through netlink. I've stolen NETLINK_NFLOG and mcast group 1 in OSF module from ipt_ULOG, so you can't use ipt_ULOG and ipt_osf at the same time(or you will catch some unusal events in ulogd/osfd).
Patchset also adds missing diffs for
Some "smart" hardware/software changes MSS while doing NAT/DSL, so make additional compare with "good" MSS value(predefined 1460). Kudos to Michal Zalewski and Mike Frantzen.
Whitespace cleanup.
Packets from outside(loopback is outside too) may have equal to fingerprint ttl, not necessarily lesser.
If we have timestamp option, do not compare it with one from fingerprint.
(For now it is always 0).
ip->ttl must be less than finger's ttl if fingerprint is valid.
and probably others.
Patchset is against latest pom-ng/userspace.
Please test and apply.
For testing i also attach trivial osfd.c.
Signature · 1 line
Evgeniy Polaykov ( s0mbre )
netfilter/patch-o-matic-ng/osf/linux/include/linux/netfilter_ipv4/ipt_osf.h +22 -4
@@ -26,14 +26,25 @@#define MAXDETLEN 64#define IPT_OSF_GENRE 1 -#define IPT_OSF_SMART 2 +#define IPT_OSF_SMART 2#define IPT_OSF_LOG 4 +#define IPT_OSF_NETLINK 8 -#define IPT_OSF_LOGLEVEL_ALL 0 +#define IPT_OSF_LOGLEVEL_ALL 0#define IPT_OSF_LOGLEVEL_FIRST 1#include <linux/list.h> +#ifndef __KERNEL__ +#include <netinet/ip.h> +#include <netinet/tcp.h> + +struct list_head +{ +struct list_head *prev, *next; +}; +#endif +struct ipt_osf_info {char genre[MAXGENRELEN ];
@@ -59,8 +70,6 @@struct osf_wc wc; }; -#ifdef __KERNEL__ -struct osf_finger {struct list_head flist;
@@ -78,6 +87,15 @@struct osf_opt opt[MAX_IPOPTLEN ];/* In case it is all NOP or EOL */ }; + +struct ipt_osf_nlmsg +{ +struct osf_finger f; +struct iphdr ip; +struct tcphdr tcp; +}; + +#ifdef __KERNEL__/* Defines for IANA option kinds */
netfilter/userspace/extensions/libipt_osf.c +11 -3
@@ -31,9 +31,9 @@#include <ctype.h> #include <iptables.h> -#include <linux/netfilter_ipv4/ipt_osf.h> +#include <linux/netfilter_ipv4/ipt_osf.h> -#define IPTABLES_VERSION "1.2.6a"/* It looks like FIXME */ +#define IPTABLES_VERSION "1.2.7a"/* Permanent FIXME */ static void help (void ) {
@@ -42,7 +42,8 @@"--smart Use some smart extensions to determine OS (do not use TTL).\n" "--log level Log all(or only first) determined genres even if " "they do not match desired one. " -"Level may be 0(all) or 1(only first entry).\n" , +"Level may be 0(all) or 1(only first entry).\n" +"--netlink Log through netlink(NETLINK_NFLOG).\n" , IPTABLES_VERSION); }
@@ -51,6 +52,7 @@ { .name = "genre", .has_arg = 1, .flag = 0, .val = '1' }, { .name = "smart", .has_arg = 0, .flag = 0, .val = '2' }, { .name = "log", .has_arg = 1, .flag = 0, .val = '3' }, + { .name = "netlink", .has_arg = 0, .flag = 0, .val = '4' }, { .name = 0 } };
@@ -101,6 +103,12 @@ *flags |=IPT_OSF_LOG ; info->loglevel =atoi (argv[optind-1 ]); info->flags |=IPT_OSF_LOG ; +break ; +case '4' :/* --netlink */ +if (*flags &IPT_OSF_NETLINK ) +exit_error (PARAMETER_PROBLEM ,"Can't specify multiple smart parameter" ); + *flags |=IPT_OSF_NETLINK ; + info->flags |=IPT_OSF_NETLINK ;break ;default :return 0 ;
#include <asm/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "osf/ipt_osf.h"
#ifndef NIPQUAD
#define NIPQUAD(addr) \ ((unsigned char *)&addr)[0], \ ((unsigned char *)&addr)[1], \ ((unsigned char *)&addr)[2], \ ((unsigned char *)&addr)[3]
#endif
int main()
{
int s;
char buf[1024];
int len;
struct nlmsghdr *reply;
struct sockaddr_nl l_local;
struct ipt_osf_nlmsg *data;
memset(buf, 0, sizeof(buf));
s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_NFLOG);
if (s == -1)
{
perror("socket");
return -1;
}
l_local.nl_family = AF_NETLINK;
l_local.nl_groups = 1;
l_local.nl_pid = getpid();
if (bind(s, (struct sockaddr *)&l_local, sizeof(struct sockaddr_nl)) == -1)
{
perror("bind");
close(s);
return -1;
}
while (1)
{
len = recv(s, buf, sizeof(buf), 0);
if (len == -1)
{
perror("recv buf");
close(s);
return -1;
}
reply = (struct nlmsghdr *)buf;
printf("first nlmsghdr received: len=%d\n", len);
printf("nlsmsghdr: len=%d, type=%d, flags=%d, seq=%d, pid=%d, sender_pid=%d\n",
reply->nlmsg_len, reply->nlmsg_type,
reply->nlmsg_flags, reply->nlmsg_seq, reply->nlmsg_pid,
getpid());
switch (reply->nlmsg_type)
{
case NLMSG_ERROR:
printf("Error message received.\n");
break;
case NLMSG_DONE:
data = (struct ipt_osf_nlmsg *)NLMSG_DATA(reply);
printf("%s [%s:%s:%s] : %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u hops=%d\n",
data->f.genre, data->f.version,
data->f.subtype, data->f.details,
NIPQUAD(data->ip.saddr), ntohs(data->tcp.source),
NIPQUAD(data->ip.daddr), ntohs(data->tcp.dest),
data->f.ttl - data->ip.ttl);
break;
}
}
close(s);
return 0;
}netfilter/patch-o-matic-ng/osf/linux/net/ipv4/netfilter/ipt_osf.c +150 -24
292 lines not on this page · raw message