diff options
-rw-r--r-- | include/net/netfilter/nf_log.h | 20 | ||||
-rw-r--r-- | net/ipv4/netfilter/nf_log_ipv4.c | 14 | ||||
-rw-r--r-- | net/ipv6/netfilter/nf_log_ipv6.c | 14 | ||||
-rw-r--r-- | net/netfilter/nf_log.c | 41 | ||||
-rw-r--r-- | net/netfilter/nfnetlink_log.c | 3 | ||||
-rw-r--r-- | net/netfilter/xt_LOG.c | 22 |
6 files changed, 73 insertions, 41 deletions
diff --git a/include/net/netfilter/nf_log.h b/include/net/netfilter/nf_log.h index bba354e78f49..b82dd19b8f26 100644 --- a/include/net/netfilter/nf_log.h +++ b/include/net/netfilter/nf_log.h | |||
@@ -61,6 +61,12 @@ int nf_log_bind_pf(struct net *net, u_int8_t pf, | |||
61 | const struct nf_logger *logger); | 61 | const struct nf_logger *logger); |
62 | void nf_log_unbind_pf(struct net *net, u_int8_t pf); | 62 | void nf_log_unbind_pf(struct net *net, u_int8_t pf); |
63 | 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 | |||
67 | #define MODULE_ALIAS_NF_LOGGER(family, type) \ | ||
68 | MODULE_ALIAS("nf-logger-" __stringify(family) "-" __stringify(type)) | ||
69 | |||
64 | /* Calls the registered backend logging function */ | 70 | /* Calls the registered backend logging function */ |
65 | __printf(8, 9) | 71 | __printf(8, 9) |
66 | void nf_log_packet(struct net *net, | 72 | void nf_log_packet(struct net *net, |
@@ -78,20 +84,6 @@ struct nf_log_buf *nf_log_buf_open(void); | |||
78 | __printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...); | 84 | __printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...); |
79 | void nf_log_buf_close(struct nf_log_buf *m); | 85 | void nf_log_buf_close(struct nf_log_buf *m); |
80 | 86 | ||
81 | void nf_log_ip_packet(struct net *net, u_int8_t pf, | ||
82 | unsigned int hooknum, const struct sk_buff *skb, | ||
83 | const struct net_device *in, | ||
84 | const struct net_device *out, | ||
85 | const struct nf_loginfo *loginfo, | ||
86 | const char *prefix); | ||
87 | |||
88 | void nf_log_ip6_packet(struct net *net, u_int8_t pf, | ||
89 | unsigned int hooknum, const struct sk_buff *skb, | ||
90 | const struct net_device *in, | ||
91 | const struct net_device *out, | ||
92 | const struct nf_loginfo *loginfo, | ||
93 | const char *prefix); | ||
94 | |||
95 | /* common logging functions */ | 87 | /* common logging functions */ |
96 | int nf_log_dump_udp_header(struct nf_log_buf *m, const struct sk_buff *skb, | 88 | int nf_log_dump_udp_header(struct nf_log_buf *m, const struct sk_buff *skb, |
97 | u8 proto, int fragment, unsigned int offset); | 89 | u8 proto, int fragment, unsigned int offset); |
diff --git a/net/ipv4/netfilter/nf_log_ipv4.c b/net/ipv4/netfilter/nf_log_ipv4.c index 7e69a401a29e..078bdca1b607 100644 --- a/net/ipv4/netfilter/nf_log_ipv4.c +++ b/net/ipv4/netfilter/nf_log_ipv4.c | |||
@@ -306,12 +306,12 @@ fallback: | |||
306 | nf_log_buf_add(m, " "); | 306 | nf_log_buf_add(m, " "); |
307 | } | 307 | } |
308 | 308 | ||
309 | void nf_log_ip_packet(struct net *net, u_int8_t pf, | 309 | static void nf_log_ip_packet(struct net *net, u_int8_t pf, |
310 | unsigned int hooknum, const struct sk_buff *skb, | 310 | unsigned int hooknum, const struct sk_buff *skb, |
311 | const struct net_device *in, | 311 | const struct net_device *in, |
312 | const struct net_device *out, | 312 | const struct net_device *out, |
313 | const struct nf_loginfo *loginfo, | 313 | const struct nf_loginfo *loginfo, |
314 | const char *prefix) | 314 | const char *prefix) |
315 | { | 315 | { |
316 | struct nf_log_buf *m; | 316 | struct nf_log_buf *m; |
317 | 317 | ||
@@ -334,7 +334,6 @@ void nf_log_ip_packet(struct net *net, u_int8_t pf, | |||
334 | 334 | ||
335 | nf_log_buf_close(m); | 335 | nf_log_buf_close(m); |
336 | } | 336 | } |
337 | EXPORT_SYMBOL_GPL(nf_log_ip_packet); | ||
338 | 337 | ||
339 | static struct nf_logger nf_ip_logger __read_mostly = { | 338 | static struct nf_logger nf_ip_logger __read_mostly = { |
340 | .name = "nf_log_ipv4", | 339 | .name = "nf_log_ipv4", |
@@ -383,3 +382,4 @@ module_exit(nf_log_ipv4_exit); | |||
383 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | 382 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
384 | MODULE_DESCRIPTION("Netfilter IPv4 packet logging"); | 383 | MODULE_DESCRIPTION("Netfilter IPv4 packet logging"); |
385 | MODULE_LICENSE("GPL"); | 384 | MODULE_LICENSE("GPL"); |
385 | MODULE_ALIAS_NF_LOGGER(AF_INET, 0); | ||
diff --git a/net/ipv6/netfilter/nf_log_ipv6.c b/net/ipv6/netfilter/nf_log_ipv6.c index 804060946d2b..7b17a0be93e7 100644 --- a/net/ipv6/netfilter/nf_log_ipv6.c +++ b/net/ipv6/netfilter/nf_log_ipv6.c | |||
@@ -338,12 +338,12 @@ fallback: | |||
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | void nf_log_ip6_packet(struct net *net, u_int8_t pf, | 341 | static void nf_log_ip6_packet(struct net *net, u_int8_t pf, |
342 | unsigned int hooknum, const struct sk_buff *skb, | 342 | unsigned int hooknum, const struct sk_buff *skb, |
343 | const struct net_device *in, | 343 | const struct net_device *in, |
344 | const struct net_device *out, | 344 | const struct net_device *out, |
345 | const struct nf_loginfo *loginfo, | 345 | const struct nf_loginfo *loginfo, |
346 | const char *prefix) | 346 | const char *prefix) |
347 | { | 347 | { |
348 | struct nf_log_buf *m; | 348 | struct nf_log_buf *m; |
349 | 349 | ||
@@ -366,7 +366,6 @@ void nf_log_ip6_packet(struct net *net, u_int8_t pf, | |||
366 | 366 | ||
367 | nf_log_buf_close(m); | 367 | nf_log_buf_close(m); |
368 | } | 368 | } |
369 | EXPORT_SYMBOL_GPL(nf_log_ip6_packet); | ||
370 | 369 | ||
371 | static struct nf_logger nf_ip6_logger __read_mostly = { | 370 | static struct nf_logger nf_ip6_logger __read_mostly = { |
372 | .name = "nf_log_ipv6", | 371 | .name = "nf_log_ipv6", |
@@ -415,3 +414,4 @@ module_exit(nf_log_ipv6_exit); | |||
415 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | 414 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
416 | MODULE_DESCRIPTION("Netfilter IPv4 packet logging"); | 415 | MODULE_DESCRIPTION("Netfilter IPv4 packet logging"); |
417 | MODULE_LICENSE("GPL"); | 416 | MODULE_LICENSE("GPL"); |
417 | MODULE_ALIAS_NF_LOGGER(AF_INET6, 0); | ||
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c index 0b6b2c874199..0b2161c689e0 100644 --- a/net/netfilter/nf_log.c +++ b/net/netfilter/nf_log.c | |||
@@ -132,6 +132,41 @@ void nf_log_unbind_pf(struct net *net, u_int8_t pf) | |||
132 | } | 132 | } |
133 | EXPORT_SYMBOL(nf_log_unbind_pf); | 133 | EXPORT_SYMBOL(nf_log_unbind_pf); |
134 | 134 | ||
135 | int nf_logger_find_get(int pf, enum nf_log_type type) | ||
136 | { | ||
137 | struct nf_logger *logger; | ||
138 | int ret = -ENOENT; | ||
139 | |||
140 | logger = loggers[pf][type]; | ||
141 | if (logger == NULL) | ||
142 | request_module("nf-logger-%u-%u", pf, type); | ||
143 | |||
144 | rcu_read_lock(); | ||
145 | logger = rcu_dereference(loggers[pf][type]); | ||
146 | if (logger == NULL) | ||
147 | goto out; | ||
148 | |||
149 | if (logger && try_module_get(logger->me)) | ||
150 | ret = 0; | ||
151 | out: | ||
152 | rcu_read_unlock(); | ||
153 | return ret; | ||
154 | } | ||
155 | EXPORT_SYMBOL_GPL(nf_logger_find_get); | ||
156 | |||
157 | void nf_logger_put(int pf, enum nf_log_type type) | ||
158 | { | ||
159 | struct nf_logger *logger; | ||
160 | |||
161 | BUG_ON(loggers[pf][type] == NULL); | ||
162 | |||
163 | rcu_read_lock(); | ||
164 | logger = rcu_dereference(loggers[pf][type]); | ||
165 | module_put(logger->me); | ||
166 | rcu_read_unlock(); | ||
167 | } | ||
168 | EXPORT_SYMBOL_GPL(nf_logger_put); | ||
169 | |||
135 | void nf_log_packet(struct net *net, | 170 | void nf_log_packet(struct net *net, |
136 | u_int8_t pf, | 171 | u_int8_t pf, |
137 | unsigned int hooknum, | 172 | unsigned int hooknum, |
@@ -146,7 +181,11 @@ void nf_log_packet(struct net *net, | |||
146 | const struct nf_logger *logger; | 181 | const struct nf_logger *logger; |
147 | 182 | ||
148 | rcu_read_lock(); | 183 | rcu_read_lock(); |
149 | logger = rcu_dereference(net->nf.nf_loggers[pf]); | 184 | if (loginfo != NULL) |
185 | logger = rcu_dereference(loggers[pf][loginfo->type]); | ||
186 | else | ||
187 | logger = rcu_dereference(net->nf.nf_loggers[pf]); | ||
188 | |||
150 | if (logger) { | 189 | if (logger) { |
151 | va_start(args, fmt); | 190 | va_start(args, fmt); |
152 | vsnprintf(prefix, sizeof(prefix), fmt, args); | 191 | vsnprintf(prefix, sizeof(prefix), fmt, args); |
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c index 160bb8ea9923..a11c5ff2f720 100644 --- a/net/netfilter/nfnetlink_log.c +++ b/net/netfilter/nfnetlink_log.c | |||
@@ -1106,6 +1106,9 @@ MODULE_DESCRIPTION("netfilter userspace logging"); | |||
1106 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); | 1106 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); |
1107 | MODULE_LICENSE("GPL"); | 1107 | MODULE_LICENSE("GPL"); |
1108 | MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_ULOG); | 1108 | MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_ULOG); |
1109 | MODULE_ALIAS_NF_LOGGER(AF_INET, 1); | ||
1110 | MODULE_ALIAS_NF_LOGGER(AF_INET6, 1); | ||
1111 | MODULE_ALIAS_NF_LOGGER(AF_BRIDGE, 1); | ||
1109 | 1112 | ||
1110 | module_init(nfnetlink_log_init); | 1113 | module_init(nfnetlink_log_init); |
1111 | module_exit(nfnetlink_log_fini); | 1114 | module_exit(nfnetlink_log_fini); |
diff --git a/net/netfilter/xt_LOG.c b/net/netfilter/xt_LOG.c index 5a6bd60e20d6..00eb49196e75 100644 --- a/net/netfilter/xt_LOG.c +++ b/net/netfilter/xt_LOG.c | |||
@@ -39,17 +39,8 @@ log_tg(struct sk_buff *skb, const struct xt_action_param *par) | |||
39 | li.u.log.level = loginfo->level; | 39 | li.u.log.level = loginfo->level; |
40 | li.u.log.logflags = loginfo->logflags; | 40 | li.u.log.logflags = loginfo->logflags; |
41 | 41 | ||
42 | if (par->family == NFPROTO_IPV4) | 42 | nf_log_packet(net, par->family, par->hooknum, skb, par->in, par->out, |
43 | nf_log_ip_packet(net, NFPROTO_IPV4, par->hooknum, skb, par->in, | 43 | &li, loginfo->prefix); |
44 | par->out, &li, loginfo->prefix); | ||
45 | #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) | ||
46 | else if (par->family == NFPROTO_IPV6) | ||
47 | nf_log_ip6_packet(net, NFPROTO_IPV6, par->hooknum, skb, par->in, | ||
48 | par->out, &li, loginfo->prefix); | ||
49 | #endif | ||
50 | else | ||
51 | WARN_ON_ONCE(1); | ||
52 | |||
53 | return XT_CONTINUE; | 44 | return XT_CONTINUE; |
54 | } | 45 | } |
55 | 46 | ||
@@ -70,7 +61,12 @@ static int log_tg_check(const struct xt_tgchk_param *par) | |||
70 | return -EINVAL; | 61 | return -EINVAL; |
71 | } | 62 | } |
72 | 63 | ||
73 | return 0; | 64 | return nf_logger_find_get(par->family, NF_LOG_TYPE_LOG); |
65 | } | ||
66 | |||
67 | static void log_tg_destroy(const struct xt_tgdtor_param *par) | ||
68 | { | ||
69 | nf_logger_put(par->family, NF_LOG_TYPE_LOG); | ||
74 | } | 70 | } |
75 | 71 | ||
76 | static struct xt_target log_tg_regs[] __read_mostly = { | 72 | static struct xt_target log_tg_regs[] __read_mostly = { |
@@ -80,6 +76,7 @@ static struct xt_target log_tg_regs[] __read_mostly = { | |||
80 | .target = log_tg, | 76 | .target = log_tg, |
81 | .targetsize = sizeof(struct xt_log_info), | 77 | .targetsize = sizeof(struct xt_log_info), |
82 | .checkentry = log_tg_check, | 78 | .checkentry = log_tg_check, |
79 | .destroy = log_tg_destroy, | ||
83 | .me = THIS_MODULE, | 80 | .me = THIS_MODULE, |
84 | }, | 81 | }, |
85 | #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) | 82 | #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) |
@@ -89,6 +86,7 @@ static struct xt_target log_tg_regs[] __read_mostly = { | |||
89 | .target = log_tg, | 86 | .target = log_tg, |
90 | .targetsize = sizeof(struct xt_log_info), | 87 | .targetsize = sizeof(struct xt_log_info), |
91 | .checkentry = log_tg_check, | 88 | .checkentry = log_tg_check, |
89 | .destroy = log_tg_destroy, | ||
92 | .me = THIS_MODULE, | 90 | .me = THIS_MODULE, |
93 | }, | 91 | }, |
94 | #endif | 92 | #endif |