Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 1 | #ifndef _NF_LOG_H |
| 2 | #define _NF_LOG_H |
| 3 | |
Eric Leblond | ca735b3 | 2009-03-16 14:54:21 +0100 | [diff] [blame] | 4 | #include <linux/netfilter.h> |
Liping Zhang | ff107d2 | 2016-09-25 16:35:56 +0800 | [diff] [blame] | 5 | #include <linux/netfilter/nf_log.h> |
Eric Leblond | ca735b3 | 2009-03-16 14:54:21 +0100 | [diff] [blame] | 6 | |
Liping Zhang | ff107d2 | 2016-09-25 16:35:56 +0800 | [diff] [blame] | 7 | /* Log tcp sequence, tcp options, ip options and uid owning local socket */ |
| 8 | #define NF_LOG_DEFAULT_MASK 0x0f |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 9 | |
Vishwanath Pai | 7643507 | 2016-06-21 14:58:46 -0400 | [diff] [blame] | 10 | /* This flag indicates that copy_len field in nf_loginfo is set */ |
| 11 | #define NF_LOG_F_COPY_LEN 0x1 |
| 12 | |
Pablo Neira Ayuso | 5962815 | 2014-06-18 19:24:30 +0200 | [diff] [blame] | 13 | enum nf_log_type { |
| 14 | NF_LOG_TYPE_LOG = 0, |
| 15 | NF_LOG_TYPE_ULOG, |
| 16 | NF_LOG_TYPE_MAX |
| 17 | }; |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 18 | |
| 19 | struct nf_loginfo { |
| 20 | u_int8_t type; |
| 21 | union { |
| 22 | struct { |
Vishwanath Pai | 7643507 | 2016-06-21 14:58:46 -0400 | [diff] [blame] | 23 | /* copy_len will be used iff you set |
| 24 | * NF_LOG_F_COPY_LEN in flags |
| 25 | */ |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 26 | u_int32_t copy_len; |
| 27 | u_int16_t group; |
| 28 | u_int16_t qthreshold; |
Vishwanath Pai | 7643507 | 2016-06-21 14:58:46 -0400 | [diff] [blame] | 29 | u_int16_t flags; |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 30 | } ulog; |
| 31 | struct { |
| 32 | u_int8_t level; |
| 33 | u_int8_t logflags; |
| 34 | } log; |
| 35 | } u; |
| 36 | }; |
| 37 | |
Hans Schillstrom | 8cdb46d | 2013-05-15 01:23:45 +0000 | [diff] [blame] | 38 | typedef void nf_logfn(struct net *net, |
| 39 | u_int8_t pf, |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 40 | 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 | |
| 47 | struct nf_logger { |
Pablo Neira Ayuso | 5962815 | 2014-06-18 19:24:30 +0200 | [diff] [blame] | 48 | char *name; |
| 49 | enum nf_log_type type; |
| 50 | nf_logfn *logfn; |
| 51 | struct module *me; |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | /* Function to register/unregister log function. */ |
Eric Leblond | ca735b3 | 2009-03-16 14:54:21 +0100 | [diff] [blame] | 55 | int nf_log_register(u_int8_t pf, struct nf_logger *logger); |
| 56 | void nf_log_unregister(struct nf_logger *logger); |
| 57 | |
Gao Feng | 779994f | 2016-08-29 18:25:28 +0800 | [diff] [blame] | 58 | int nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger); |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 59 | void nf_log_unset(struct net *net, const struct nf_logger *logger); |
| 60 | |
| 61 | int nf_log_bind_pf(struct net *net, u_int8_t pf, |
| 62 | const struct nf_logger *logger); |
| 63 | void nf_log_unbind_pf(struct net *net, u_int8_t pf); |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 64 | |
Pablo Neira Ayuso | fab4085 | 2014-06-18 19:38:25 +0200 | [diff] [blame] | 65 | int nf_logger_find_get(int pf, enum nf_log_type type); |
| 66 | void nf_logger_put(int pf, enum nf_log_type type); |
Pablo Neira Ayuso | 960649d | 2014-06-23 00:28:18 +0200 | [diff] [blame] | 67 | void nf_logger_request_module(int pf, enum nf_log_type type); |
Pablo Neira Ayuso | fab4085 | 2014-06-18 19:38:25 +0200 | [diff] [blame] | 68 | |
| 69 | #define MODULE_ALIAS_NF_LOGGER(family, type) \ |
| 70 | MODULE_ALIAS("nf-logger-" __stringify(family) "-" __stringify(type)) |
| 71 | |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 72 | /* Calls the registered backend logging function */ |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 73 | __printf(8, 9) |
| 74 | void nf_log_packet(struct net *net, |
| 75 | u_int8_t pf, |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 76 | unsigned int hooknum, |
| 77 | const struct sk_buff *skb, |
| 78 | const struct net_device *in, |
| 79 | const struct net_device *out, |
Patrick McHardy | 7b2f963 | 2007-12-17 22:39:08 -0800 | [diff] [blame] | 80 | const struct nf_loginfo *li, |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 81 | const char *fmt, ...); |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 82 | |
Pablo Neira Ayuso | 4017a7e | 2015-03-02 01:10:28 +0100 | [diff] [blame] | 83 | __printf(8, 9) |
| 84 | void 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 Ayuso | 27fd8d90 | 2014-06-19 12:37:58 +0200 | [diff] [blame] | 93 | struct nf_log_buf; |
| 94 | |
| 95 | struct 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, ...); |
| 97 | void nf_log_buf_close(struct nf_log_buf *m); |
| 98 | |
Pablo Neira Ayuso | 83e96d4 | 2014-06-19 20:47:14 +0200 | [diff] [blame] | 99 | /* common logging functions */ |
| 100 | int nf_log_dump_udp_header(struct nf_log_buf *m, const struct sk_buff *skb, |
| 101 | u8 proto, int fragment, unsigned int offset); |
| 102 | int 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); |
| 105 | void nf_log_dump_sk_uid_gid(struct nf_log_buf *m, struct sock *sk); |
| 106 | void 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 McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 113 | #endif /* _NF_LOG_H */ |