blob: 309cd267be4faf589927478c39615e1eef144fd6 [file] [log] [blame]
Patrick McHardyf01ffbd2007-12-17 22:38:49 -08001#ifndef _NF_LOG_H
2#define _NF_LOG_H
3
Eric Leblondca735b32009-03-16 14:54:21 +01004#include <linux/netfilter.h>
Liping Zhangff107d22016-09-25 16:35:56 +08005#include <linux/netfilter/nf_log.h>
Eric Leblondca735b32009-03-16 14:54:21 +01006
Liping Zhangff107d22016-09-25 16:35:56 +08007/* Log tcp sequence, tcp options, ip options and uid owning local socket */
8#define NF_LOG_DEFAULT_MASK 0x0f
Patrick McHardyf01ffbd2007-12-17 22:38:49 -08009
Vishwanath Pai76435072016-06-21 14:58:46 -040010/* This flag indicates that copy_len field in nf_loginfo is set */
11#define NF_LOG_F_COPY_LEN 0x1
12
Pablo Neira Ayuso59628152014-06-18 19:24:30 +020013enum nf_log_type {
14 NF_LOG_TYPE_LOG = 0,
15 NF_LOG_TYPE_ULOG,
16 NF_LOG_TYPE_MAX
17};
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080018
19struct nf_loginfo {
20 u_int8_t type;
21 union {
22 struct {
Vishwanath Pai76435072016-06-21 14:58:46 -040023 /* copy_len will be used iff you set
24 * NF_LOG_F_COPY_LEN in flags
25 */
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080026 u_int32_t copy_len;
27 u_int16_t group;
28 u_int16_t qthreshold;
Vishwanath Pai76435072016-06-21 14:58:46 -040029 u_int16_t flags;
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080030 } ulog;
31 struct {
32 u_int8_t level;
33 u_int8_t logflags;
34 } log;
35 } u;
36};
37
Hans Schillstrom8cdb46d2013-05-15 01:23:45 +000038typedef void nf_logfn(struct net *net,
39 u_int8_t pf,
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080040 unsigned int hooknum,
41 const struct sk_buff *skb,
42 const struct net_device *in,
43 const struct net_device *out,
44 const struct nf_loginfo *li,
45 const char *prefix);
46
47struct nf_logger {
Pablo Neira Ayuso59628152014-06-18 19:24:30 +020048 char *name;
49 enum nf_log_type type;
50 nf_logfn *logfn;
51 struct module *me;
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080052};
53
54/* Function to register/unregister log function. */
Eric Leblondca735b32009-03-16 14:54:21 +010055int nf_log_register(u_int8_t pf, struct nf_logger *logger);
56void nf_log_unregister(struct nf_logger *logger);
57
Gao Feng779994f2016-08-29 18:25:28 +080058int nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger);
Gao feng30e0c6a2013-03-24 23:50:40 +000059void nf_log_unset(struct net *net, const struct nf_logger *logger);
60
61int nf_log_bind_pf(struct net *net, u_int8_t pf,
62 const struct nf_logger *logger);
63void nf_log_unbind_pf(struct net *net, u_int8_t pf);
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080064
Pablo Neira Ayusofab40852014-06-18 19:38:25 +020065int nf_logger_find_get(int pf, enum nf_log_type type);
66void nf_logger_put(int pf, enum nf_log_type type);
Pablo Neira Ayuso960649d2014-06-23 00:28:18 +020067void nf_logger_request_module(int pf, enum nf_log_type type);
Pablo Neira Ayusofab40852014-06-18 19:38:25 +020068
69#define MODULE_ALIAS_NF_LOGGER(family, type) \
70 MODULE_ALIAS("nf-logger-" __stringify(family) "-" __stringify(type))
71
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080072/* Calls the registered backend logging function */
Gao feng30e0c6a2013-03-24 23:50:40 +000073__printf(8, 9)
74void nf_log_packet(struct net *net,
75 u_int8_t pf,
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080076 unsigned int hooknum,
77 const struct sk_buff *skb,
78 const struct net_device *in,
79 const struct net_device *out,
Patrick McHardy7b2f9632007-12-17 22:39:08 -080080 const struct nf_loginfo *li,
Joe Perchesb9075fa2011-10-31 17:11:33 -070081 const char *fmt, ...);
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080082
Pablo Neira Ayuso4017a7e2015-03-02 01:10:28 +010083__printf(8, 9)
84void nf_log_trace(struct net *net,
85 u_int8_t pf,
86 unsigned int hooknum,
87 const struct sk_buff *skb,
88 const struct net_device *in,
89 const struct net_device *out,
90 const struct nf_loginfo *li,
91 const char *fmt, ...);
92
Pablo Neira Ayuso27fd8d902014-06-19 12:37:58 +020093struct nf_log_buf;
94
95struct nf_log_buf *nf_log_buf_open(void);
96__printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...);
97void nf_log_buf_close(struct nf_log_buf *m);
98
Pablo Neira Ayuso83e96d42014-06-19 20:47:14 +020099/* common logging functions */
100int nf_log_dump_udp_header(struct nf_log_buf *m, const struct sk_buff *skb,
101 u8 proto, int fragment, unsigned int offset);
102int nf_log_dump_tcp_header(struct nf_log_buf *m, const struct sk_buff *skb,
103 u8 proto, int fragment, unsigned int offset,
104 unsigned int logflags);
105void nf_log_dump_sk_uid_gid(struct nf_log_buf *m, struct sock *sk);
106void nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
107 unsigned int hooknum, const struct sk_buff *skb,
108 const struct net_device *in,
109 const struct net_device *out,
110 const struct nf_loginfo *loginfo,
111 const char *prefix);
112
Patrick McHardyf01ffbd2007-12-17 22:38:49 -0800113#endif /* _NF_LOG_H */