aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2014-06-18 13:38:25 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2014-06-27 07:20:13 -0400
commitfab4085f4e248b8a80bb1dadbbacb2bacd8017c3 (patch)
tree4d17c20935c24f77f08fe7807ce5a038d8a2cb13 /net
parent83e96d443b372611adf19e4171d41deb1d8760cf (diff)
netfilter: log: nf_log_packet() as real unified interface
Before this patch, the nf_loginfo parameter specified the logging configuration in case the specified default logger was loaded. This patch updates the semantics of the nf_loginfo parameter in nf_log_packet() which now indicates the logger that you explicitly want to use. Thus, nf_log_packet() is exposed as an unified interface which internally routes the log message to the corresponding logger type by family. The module dependencies are expressed by the new nf_logger_find_get() and nf_logger_put() functions which bump the logger module refcount. Thus, you can not remove logger modules that are used by rules anymore. Another important effect of this change is that the family specific module is only loaded when required. Therefore, xt_LOG and nft_log will just trigger the autoload of the nf_log_{ip,ip6} modules according to the family. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/netfilter/nf_log_ipv4.c14
-rw-r--r--net/ipv6/netfilter/nf_log_ipv6.c14
-rw-r--r--net/netfilter/nf_log.c41
-rw-r--r--net/netfilter/nfnetlink_log.c3
-rw-r--r--net/netfilter/xt_LOG.c22
5 files changed, 67 insertions, 27 deletions
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
309void nf_log_ip_packet(struct net *net, u_int8_t pf, 309static 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}
337EXPORT_SYMBOL_GPL(nf_log_ip_packet);
338 337
339static struct nf_logger nf_ip_logger __read_mostly = { 338static 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);
383MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 382MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
384MODULE_DESCRIPTION("Netfilter IPv4 packet logging"); 383MODULE_DESCRIPTION("Netfilter IPv4 packet logging");
385MODULE_LICENSE("GPL"); 384MODULE_LICENSE("GPL");
385MODULE_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
341void nf_log_ip6_packet(struct net *net, u_int8_t pf, 341static 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}
369EXPORT_SYMBOL_GPL(nf_log_ip6_packet);
370 369
371static struct nf_logger nf_ip6_logger __read_mostly = { 370static 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);
415MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 414MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
416MODULE_DESCRIPTION("Netfilter IPv4 packet logging"); 415MODULE_DESCRIPTION("Netfilter IPv4 packet logging");
417MODULE_LICENSE("GPL"); 416MODULE_LICENSE("GPL");
417MODULE_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}
133EXPORT_SYMBOL(nf_log_unbind_pf); 133EXPORT_SYMBOL(nf_log_unbind_pf);
134 134
135int 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;
151out:
152 rcu_read_unlock();
153 return ret;
154}
155EXPORT_SYMBOL_GPL(nf_logger_find_get);
156
157void 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}
168EXPORT_SYMBOL_GPL(nf_logger_put);
169
135void nf_log_packet(struct net *net, 170void 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");
1106MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 1106MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
1107MODULE_LICENSE("GPL"); 1107MODULE_LICENSE("GPL");
1108MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_ULOG); 1108MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_ULOG);
1109MODULE_ALIAS_NF_LOGGER(AF_INET, 1);
1110MODULE_ALIAS_NF_LOGGER(AF_INET6, 1);
1111MODULE_ALIAS_NF_LOGGER(AF_BRIDGE, 1);
1109 1112
1110module_init(nfnetlink_log_init); 1113module_init(nfnetlink_log_init);
1111module_exit(nfnetlink_log_fini); 1114module_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
67static 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
76static struct xt_target log_tg_regs[] __read_mostly = { 72static 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