xref: /openbmc/linux/include/net/netfilter/nf_log.h (revision 23c2b932)
1 #ifndef _NF_LOG_H
2 #define _NF_LOG_H
3 
4 #include <linux/netfilter.h>
5 
6 /* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will
7  * disappear once iptables is replaced with pkttables.  Please DO NOT use them
8  * for any new code! */
9 #define NF_LOG_TCPSEQ		0x01	/* Log TCP sequence numbers */
10 #define NF_LOG_TCPOPT		0x02	/* Log TCP options */
11 #define NF_LOG_IPOPT		0x04	/* Log IP options */
12 #define NF_LOG_UID		0x08	/* Log UID owning local socket */
13 #define NF_LOG_MASK		0x0f
14 
15 enum nf_log_type {
16 	NF_LOG_TYPE_LOG		= 0,
17 	NF_LOG_TYPE_ULOG,
18 	NF_LOG_TYPE_MAX
19 };
20 
21 struct nf_loginfo {
22 	u_int8_t type;
23 	union {
24 		struct {
25 			u_int32_t copy_len;
26 			u_int16_t group;
27 			u_int16_t qthreshold;
28 		} ulog;
29 		struct {
30 			u_int8_t level;
31 			u_int8_t logflags;
32 		} log;
33 	} u;
34 };
35 
36 typedef void nf_logfn(struct net *net,
37 		      u_int8_t pf,
38 		      unsigned int hooknum,
39 		      const struct sk_buff *skb,
40 		      const struct net_device *in,
41 		      const struct net_device *out,
42 		      const struct nf_loginfo *li,
43 		      const char *prefix);
44 
45 struct nf_logger {
46 	char			*name;
47 	enum nf_log_type	type;
48 	nf_logfn 		*logfn;
49 	struct module		*me;
50 };
51 
52 /* Function to register/unregister log function. */
53 int nf_log_register(u_int8_t pf, struct nf_logger *logger);
54 void nf_log_unregister(struct nf_logger *logger);
55 
56 void nf_log_set(struct net *net, u_int8_t pf,
57 		const struct nf_logger *logger);
58 void nf_log_unset(struct net *net, const struct nf_logger *logger);
59 
60 int nf_log_bind_pf(struct net *net, u_int8_t pf,
61 		   const struct nf_logger *logger);
62 void nf_log_unbind_pf(struct net *net, u_int8_t pf);
63 
64 int nf_logger_find_get(int pf, enum nf_log_type type);
65 void nf_logger_put(int pf, enum nf_log_type type);
66 void nf_logger_request_module(int pf, enum nf_log_type type);
67 
68 #define MODULE_ALIAS_NF_LOGGER(family, type) \
69 	MODULE_ALIAS("nf-logger-" __stringify(family) "-" __stringify(type))
70 
71 /* Calls the registered backend logging function */
72 __printf(8, 9)
73 void nf_log_packet(struct net *net,
74 		   u_int8_t pf,
75 		   unsigned int hooknum,
76 		   const struct sk_buff *skb,
77 		   const struct net_device *in,
78 		   const struct net_device *out,
79 		   const struct nf_loginfo *li,
80 		   const char *fmt, ...);
81 
82 __printf(8, 9)
83 void nf_log_trace(struct net *net,
84 		  u_int8_t pf,
85 		  unsigned int hooknum,
86 		  const struct sk_buff *skb,
87 		  const struct net_device *in,
88 		  const struct net_device *out,
89 		  const struct nf_loginfo *li,
90 		  const char *fmt, ...);
91 
92 struct nf_log_buf;
93 
94 struct nf_log_buf *nf_log_buf_open(void);
95 __printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...);
96 void nf_log_buf_close(struct nf_log_buf *m);
97 
98 /* common logging functions */
99 int nf_log_dump_udp_header(struct nf_log_buf *m, const struct sk_buff *skb,
100 			   u8 proto, int fragment, unsigned int offset);
101 int nf_log_dump_tcp_header(struct nf_log_buf *m, const struct sk_buff *skb,
102 			   u8 proto, int fragment, unsigned int offset,
103 			   unsigned int logflags);
104 void nf_log_dump_sk_uid_gid(struct nf_log_buf *m, struct sock *sk);
105 void nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
106 			       unsigned int hooknum, const struct sk_buff *skb,
107 			       const struct net_device *in,
108 			       const struct net_device *out,
109 			       const struct nf_loginfo *loginfo,
110 			       const char *prefix);
111 
112 #endif /* _NF_LOG_H */
113