Skip to contentSkip to conversation

add nf_log handler

PATCH In review Harald Welte 2 participants 2 messages Mar 29, 2004 – Mar 30, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add nf_log handler

Hi Dave!

This is a patch adding a generic packet logging interface called 'nf_log'. The idea is that anybody wanting to log a packet calls a common function, which in turn dispatches that call to a 'logging handler'. Currently ipt_LOG and ipt_ULOG can both register as such a handler.

This is neccessarry especially for the upcoming 'TRACE' target that would allow you to trace a packet while iterating through all netfilter/iptables modules.

Author: Jozsef Kadlecsik

Please submit,

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
include/linux/netfilter.h +18 -0
diff -Nru --exclude-from /sunbeam/home/laforge/scripts/dontdiff linux-2.6.5-rc2-nfsubmit/include/linux/netfilter.h linux-2.6.5-rc2-nflog/include/linux/netfilter.h
@@ -99,6 +99,24 @@
 
 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
 
+typedef void nf_logfn(unsigned int hooknum,
+		      const struct sk_buff *skb,
+		      const struct net_device *in,
+		      const struct net_device *out,
+		      const char *prefix);
+
+/* Function to register/unregister log function. */
+int nf_log_register(int pf, nf_logfn *logfn);
+void nf_log_unregister(int pf, nf_logfn *logfn);
+
+/* Calls the registered backend logging function */
+void nf_log_packet(int pf,
+		   unsigned int hooknum,
+		   const struct sk_buff *skb,
+		   const struct net_device *in,
+		   const struct net_device *out,
+		   const char *fmt, ...);
+                   
 /* Activate hook; either okfn or kfree_skb called, unless a hook
    returns NF_STOLEN (in which case, it's up to the hook to deal with
    the consequences).
include/linux/netfilter_ipv4/ip_logging.h +20 -0
diff -Nru --exclude-from /sunbeam/home/laforge/scripts/dontdiff linux-2.6.5-rc2-nfsubmit/include/linux/netfilter_ipv4/ip_logging.h linux-2.6.5-rc2-nflog/include/linux/netfilter_ipv4/ip_logging.h
@@ -0,0 +1,20 @@
+/* IPv4 macros for the internal logging interface. */
+#ifndef __IP_LOGGING_H
+#define __IP_LOGGING_H
+
+#ifdef __KERNEL__
+#include <linux/socket.h>
+#include <linux/netfilter_logging.h>
+
+#define nf_log_ip_packet(pskb,hooknum,in,out,fmt,args...) \
+	nf_log_packet(AF_INET,pskb,hooknum,in,out,fmt,##args)
+
+#define nf_log_ip(pfh,len,fmt,args...) \
+	nf_log(AF_INET,pfh,len,fmt,##args)
+
+#define nf_ip_log_register(logging) nf_log_register(AF_INET,logging)
+#define nf_ip_log_unregister(logging) nf_log_unregister(AF_INET,logging)
+	
+#endif /*__KERNEL__*/
+
+#endif /*__IP_LOGGING_H*/
include/linux/netfilter_ipv4/ipt_ULOG.h +3 -0
diff -Nru --exclude-from /sunbeam/home/laforge/scripts/dontdiff linux-2.6.5-rc2-nfsubmit/include/linux/netfilter_ipv4/ipt_ULOG.h linux-2.6.5-rc2-nflog/include/linux/netfilter_ipv4/ipt_ULOG.h
@@ -11,6 +11,9 @@
 #define NETLINK_NFLOG 	5
 #endif
 
+#define ULOG_DEFAULT_NLGROUP	1
+#define ULOG_DEFAULT_QTHRESHOLD	1
+
 #define ULOG_MAC_LEN	80
 #define ULOG_PREFIX_LEN	32
 
include/linux/netfilter_ipv6/ip6_logging.h +20 -0
diff -Nru --exclude-from /sunbeam/home/laforge/scripts/dontdiff linux-2.6.5-rc2-nfsubmit/include/linux/netfilter_ipv6/ip6_logging.h linux-2.6.5-rc2-nflog/include/linux/netfilter_ipv6/ip6_logging.h
@@ -0,0 +1,20 @@
+/* IPv6 macros for the nternal logging interface. */
+#ifndef __IP6_LOGGING_H
+#define __IP6_LOGGING_H
+
+#ifdef __KERNEL__
+#include <linux/socket.h>
+#include <linux/netfilter_logging.h>
+
+#define nf_log_ip6_packet(pskb,hooknum,in,out,fmt,args...) \
+	nf_log_packet(AF_INET6,pskb,hooknum,in,out,fmt,##args)
+
+#define nf_log_ip6(pfh,len,fmt,args...) \
+	nf_log(AF_INET6,pfh,len,fmt,##args)
+
+#define nf_ip6_log_register(logging) nf_log_register(AF_INET6,logging)
+#define nf_ip6_log_unregister(logging) nf_log_unregister(AF_INET6,logging)
+	
+#endif /*__KERNEL__*/
+
+#endif /*__IP6_LOGGING_H*/
include/linux/netfilter_logging.h +33 -0
diff -Nru --exclude-from /sunbeam/home/laforge/scripts/dontdiff linux-2.6.5-rc2-nfsubmit/include/linux/netfilter_logging.h linux-2.6.5-rc2-nflog/include/linux/netfilter_logging.h
@@ -0,0 +1,33 @@
+/* Internal logging interface, which relies on the real 
+   LOG target modules */
+#ifndef __LINUX_NETFILTER_LOGGING_H
+#define __LINUX_NETFILTER_LOGGING_H
+
+#ifdef __KERNEL__
+#include <asm/atomic.h>
+
+struct nf_logging_t {
+	void (*nf_log_packet)(struct sk_buff **pskb,
+			      unsigned int hooknum,
+			      const struct net_device *in,
+			      const struct net_device *out,
+			      const char *prefix);
+	void (*nf_log)(char *pfh, size_t len,
+		       const char *prefix);
+};
+
+extern void nf_log_register(int pf, const struct nf_logging_t *logging);
+extern void nf_log_unregister(int pf, const struct nf_logging_t *logging);
+
+extern void nf_log_packet(int pf,
+			  struct sk_buff **pskb,
+			  unsigned int hooknum,
+			  const struct net_device *in,
+			  const struct net_device *out,
+			  const char *fmt, ...);
+extern void nf_log(int pf,
+		   char *pfh, size_t len,
+		   const char *fmt, ...);
+#endif /*__KERNEL__*/
+
+#endif /*__LINUX_NETFILTER_LOGGING_H*/
net/core/netfilter.c +68 -0

82 lines not on this page · raw message

net/ipv4/netfilter/ipt_LOG.c +60 -20

136 lines not on this page · raw message

net/ipv4/netfilter/ipt_ULOG.c +57 -20

150 lines not on this page · raw message

net/ipv6/netfilter/ip6t_LOG.c +64 -23

156 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · On Mon, 29 Mar 2004 12:58:31 +0200 Harald Welte <[email protected]> wrote:

This is a patch adding a generic packet logging interface called 'nf_log'.

Applied for 2.6.6