aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2013-04-07 12:22:06 -0400
committerDavid S. Miller <davem@davemloft.net>2013-04-07 12:22:06 -0400
commitd16658206a3a9a1cbe2cc062bee9ea7e782293a5 (patch)
treee7374985d7ec3bcfa77616ca449debfefa6849d9 /net/ipv4
parent19952cc4f8f572493293a8caed27c4be89c5fc9d (diff)
parentb8dd6a223eb86d537c2c6d8d28916c1f0ba3ea3c (diff)
Merge branch 'master' of git://1984.lsi.us.es/nf-next
Pablo Neira Ayuso says: ==================== The following patchset contains Netfilter and IPVS updates for your net-next tree, most relevantly they are: * Add net namespace support to NFLOG, ULOG and ebt_ulog and NFQUEUE. The LOG and ebt_log target has been also adapted, but they still depend on the syslog netnamespace that seems to be missing, from Gao Feng. * Don't lose indications of congestion in IPv6 fragmentation handling, from Hannes Frederic Sowa.i * IPVS conversion to use RCU, including some code consolidation patches and optimizations, also some from Julian Anastasov. * cpu fanout support for NFQUEUE, from Holger Eitzenberger. * Better error reporting to userspace when dropping packets from all our _*_[xfrm|route]_me_harder functions, from Patrick McHardy. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/ip_output.c3
-rw-r--r--net/ipv4/netfilter/ip_tables.c9
-rw-r--r--net/ipv4/netfilter/ipt_ULOG.c129
-rw-r--r--net/ipv4/netfilter/nf_conntrack_proto_icmp.c8
4 files changed, 98 insertions, 51 deletions
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 5e12dca7b3dd..147abf5275aa 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -430,8 +430,7 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
430 to->tc_index = from->tc_index; 430 to->tc_index = from->tc_index;
431#endif 431#endif
432 nf_copy(to, from); 432 nf_copy(to, from);
433#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 433#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
434 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
435 to->nf_trace = from->nf_trace; 434 to->nf_trace = from->nf_trace;
436#endif 435#endif
437#if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE) 436#if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 3efcf87400c3..e391db1f056d 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -182,8 +182,7 @@ ipt_get_target_c(const struct ipt_entry *e)
182 return ipt_get_target((struct ipt_entry *)e); 182 return ipt_get_target((struct ipt_entry *)e);
183} 183}
184 184
185#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 185#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
186 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
187static const char *const hooknames[] = { 186static const char *const hooknames[] = {
188 [NF_INET_PRE_ROUTING] = "PREROUTING", 187 [NF_INET_PRE_ROUTING] = "PREROUTING",
189 [NF_INET_LOCAL_IN] = "INPUT", 188 [NF_INET_LOCAL_IN] = "INPUT",
@@ -259,6 +258,7 @@ static void trace_packet(const struct sk_buff *skb,
259 const char *hookname, *chainname, *comment; 258 const char *hookname, *chainname, *comment;
260 const struct ipt_entry *iter; 259 const struct ipt_entry *iter;
261 unsigned int rulenum = 0; 260 unsigned int rulenum = 0;
261 struct net *net = dev_net(in ? in : out);
262 262
263 table_base = private->entries[smp_processor_id()]; 263 table_base = private->entries[smp_processor_id()];
264 root = get_entry(table_base, private->hook_entry[hook]); 264 root = get_entry(table_base, private->hook_entry[hook]);
@@ -271,7 +271,7 @@ static void trace_packet(const struct sk_buff *skb,
271 &chainname, &comment, &rulenum) != 0) 271 &chainname, &comment, &rulenum) != 0)
272 break; 272 break;
273 273
274 nf_log_packet(AF_INET, hook, skb, in, out, &trace_loginfo, 274 nf_log_packet(net, AF_INET, hook, skb, in, out, &trace_loginfo,
275 "TRACE: %s:%s:%s:%u ", 275 "TRACE: %s:%s:%s:%u ",
276 tablename, chainname, comment, rulenum); 276 tablename, chainname, comment, rulenum);
277} 277}
@@ -361,8 +361,7 @@ ipt_do_table(struct sk_buff *skb,
361 t = ipt_get_target(e); 361 t = ipt_get_target(e);
362 IP_NF_ASSERT(t->u.kernel.target); 362 IP_NF_ASSERT(t->u.kernel.target);
363 363
364#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 364#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
365 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
366 /* The packet is traced: log it */ 365 /* The packet is traced: log it */
367 if (unlikely(skb->nf_trace)) 366 if (unlikely(skb->nf_trace))
368 trace_packet(skb, hook, in, out, 367 trace_packet(skb, hook, in, out,
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index e7f8cad11393..8799c836ccaa 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -45,6 +45,7 @@
45#include <linux/netfilter/x_tables.h> 45#include <linux/netfilter/x_tables.h>
46#include <linux/netfilter_ipv4/ipt_ULOG.h> 46#include <linux/netfilter_ipv4/ipt_ULOG.h>
47#include <net/netfilter/nf_log.h> 47#include <net/netfilter/nf_log.h>
48#include <net/netns/generic.h>
48#include <net/sock.h> 49#include <net/sock.h>
49#include <linux/bitops.h> 50#include <linux/bitops.h>
50#include <asm/unaligned.h> 51#include <asm/unaligned.h>
@@ -78,15 +79,23 @@ typedef struct {
78 struct timer_list timer; /* the timer function */ 79 struct timer_list timer; /* the timer function */
79} ulog_buff_t; 80} ulog_buff_t;
80 81
81static ulog_buff_t ulog_buffers[ULOG_MAXNLGROUPS]; /* array of buffers */ 82static int ulog_net_id __read_mostly;
83struct ulog_net {
84 unsigned int nlgroup[ULOG_MAXNLGROUPS];
85 ulog_buff_t ulog_buffers[ULOG_MAXNLGROUPS];
86 struct sock *nflognl;
87 spinlock_t lock;
88};
82 89
83static struct sock *nflognl; /* our socket */ 90static struct ulog_net *ulog_pernet(struct net *net)
84static DEFINE_SPINLOCK(ulog_lock); /* spinlock */ 91{
92 return net_generic(net, ulog_net_id);
93}
85 94
86/* send one ulog_buff_t to userspace */ 95/* send one ulog_buff_t to userspace */
87static void ulog_send(unsigned int nlgroupnum) 96static void ulog_send(struct ulog_net *ulog, unsigned int nlgroupnum)
88{ 97{
89 ulog_buff_t *ub = &ulog_buffers[nlgroupnum]; 98 ulog_buff_t *ub = &ulog->ulog_buffers[nlgroupnum];
90 99
91 pr_debug("ulog_send: timer is deleting\n"); 100 pr_debug("ulog_send: timer is deleting\n");
92 del_timer(&ub->timer); 101 del_timer(&ub->timer);
@@ -103,7 +112,8 @@ static void ulog_send(unsigned int nlgroupnum)
103 NETLINK_CB(ub->skb).dst_group = nlgroupnum + 1; 112 NETLINK_CB(ub->skb).dst_group = nlgroupnum + 1;
104 pr_debug("throwing %d packets to netlink group %u\n", 113 pr_debug("throwing %d packets to netlink group %u\n",
105 ub->qlen, nlgroupnum + 1); 114 ub->qlen, nlgroupnum + 1);
106 netlink_broadcast(nflognl, ub->skb, 0, nlgroupnum + 1, GFP_ATOMIC); 115 netlink_broadcast(ulog->nflognl, ub->skb, 0, nlgroupnum + 1,
116 GFP_ATOMIC);
107 117
108 ub->qlen = 0; 118 ub->qlen = 0;
109 ub->skb = NULL; 119 ub->skb = NULL;
@@ -114,13 +124,16 @@ static void ulog_send(unsigned int nlgroupnum)
114/* timer function to flush queue in flushtimeout time */ 124/* timer function to flush queue in flushtimeout time */
115static void ulog_timer(unsigned long data) 125static void ulog_timer(unsigned long data)
116{ 126{
127 struct ulog_net *ulog = container_of((void *)data,
128 struct ulog_net,
129 nlgroup[*(unsigned int *)data]);
117 pr_debug("timer function called, calling ulog_send\n"); 130 pr_debug("timer function called, calling ulog_send\n");
118 131
119 /* lock to protect against somebody modifying our structure 132 /* lock to protect against somebody modifying our structure
120 * from ipt_ulog_target at the same time */ 133 * from ipt_ulog_target at the same time */
121 spin_lock_bh(&ulog_lock); 134 spin_lock_bh(&ulog->lock);
122 ulog_send(data); 135 ulog_send(ulog, data);
123 spin_unlock_bh(&ulog_lock); 136 spin_unlock_bh(&ulog->lock);
124} 137}
125 138
126static struct sk_buff *ulog_alloc_skb(unsigned int size) 139static struct sk_buff *ulog_alloc_skb(unsigned int size)
@@ -160,6 +173,8 @@ static void ipt_ulog_packet(unsigned int hooknum,
160 size_t size, copy_len; 173 size_t size, copy_len;
161 struct nlmsghdr *nlh; 174 struct nlmsghdr *nlh;
162 struct timeval tv; 175 struct timeval tv;
176 struct net *net = dev_net(in ? in : out);
177 struct ulog_net *ulog = ulog_pernet(net);
163 178
164 /* ffs == find first bit set, necessary because userspace 179 /* ffs == find first bit set, necessary because userspace
165 * is already shifting groupnumber, but we need unshifted. 180 * is already shifting groupnumber, but we need unshifted.
@@ -174,9 +189,9 @@ static void ipt_ulog_packet(unsigned int hooknum,
174 189
175 size = nlmsg_total_size(sizeof(*pm) + copy_len); 190 size = nlmsg_total_size(sizeof(*pm) + copy_len);
176 191
177 ub = &ulog_buffers[groupnum]; 192 ub = &ulog->ulog_buffers[groupnum];
178 193
179 spin_lock_bh(&ulog_lock); 194 spin_lock_bh(&ulog->lock);
180 195
181 if (!ub->skb) { 196 if (!ub->skb) {
182 if (!(ub->skb = ulog_alloc_skb(size))) 197 if (!(ub->skb = ulog_alloc_skb(size)))
@@ -186,7 +201,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
186 /* either the queue len is too high or we don't have 201 /* either the queue len is too high or we don't have
187 * enough room in nlskb left. send it to userspace. */ 202 * enough room in nlskb left. send it to userspace. */
188 203
189 ulog_send(groupnum); 204 ulog_send(ulog, groupnum);
190 205
191 if (!(ub->skb = ulog_alloc_skb(size))) 206 if (!(ub->skb = ulog_alloc_skb(size)))
192 goto alloc_failure; 207 goto alloc_failure;
@@ -260,16 +275,16 @@ static void ipt_ulog_packet(unsigned int hooknum,
260 if (ub->qlen >= loginfo->qthreshold) { 275 if (ub->qlen >= loginfo->qthreshold) {
261 if (loginfo->qthreshold > 1) 276 if (loginfo->qthreshold > 1)
262 nlh->nlmsg_type = NLMSG_DONE; 277 nlh->nlmsg_type = NLMSG_DONE;
263 ulog_send(groupnum); 278 ulog_send(ulog, groupnum);
264 } 279 }
265out_unlock: 280out_unlock:
266 spin_unlock_bh(&ulog_lock); 281 spin_unlock_bh(&ulog->lock);
267 282
268 return; 283 return;
269 284
270alloc_failure: 285alloc_failure:
271 pr_debug("Error building netlink message\n"); 286 pr_debug("Error building netlink message\n");
272 spin_unlock_bh(&ulog_lock); 287 spin_unlock_bh(&ulog->lock);
273} 288}
274 289
275static unsigned int 290static unsigned int
@@ -376,54 +391,43 @@ static struct nf_logger ipt_ulog_logger __read_mostly = {
376 .me = THIS_MODULE, 391 .me = THIS_MODULE,
377}; 392};
378 393
379static int __init ulog_tg_init(void) 394static int __net_init ulog_tg_net_init(struct net *net)
380{ 395{
381 int ret, i; 396 int i;
397 struct ulog_net *ulog = ulog_pernet(net);
382 struct netlink_kernel_cfg cfg = { 398 struct netlink_kernel_cfg cfg = {
383 .groups = ULOG_MAXNLGROUPS, 399 .groups = ULOG_MAXNLGROUPS,
384 }; 400 };
385 401
386 pr_debug("init module\n"); 402 spin_lock_init(&ulog->lock);
387
388 if (nlbufsiz > 128*1024) {
389 pr_warning("Netlink buffer has to be <= 128kB\n");
390 return -EINVAL;
391 }
392
393 /* initialize ulog_buffers */ 403 /* initialize ulog_buffers */
394 for (i = 0; i < ULOG_MAXNLGROUPS; i++) 404 for (i = 0; i < ULOG_MAXNLGROUPS; i++)
395 setup_timer(&ulog_buffers[i].timer, ulog_timer, i); 405 setup_timer(&ulog->ulog_buffers[i].timer, ulog_timer, i);
396 406
397 nflognl = netlink_kernel_create(&init_net, NETLINK_NFLOG, &cfg); 407 ulog->nflognl = netlink_kernel_create(net, NETLINK_NFLOG, &cfg);
398 if (!nflognl) 408 if (!ulog->nflognl)
399 return -ENOMEM; 409 return -ENOMEM;
400 410
401 ret = xt_register_target(&ulog_tg_reg);
402 if (ret < 0) {
403 netlink_kernel_release(nflognl);
404 return ret;
405 }
406 if (nflog) 411 if (nflog)
407 nf_log_register(NFPROTO_IPV4, &ipt_ulog_logger); 412 nf_log_set(net, NFPROTO_IPV4, &ipt_ulog_logger);
408 413
409 return 0; 414 return 0;
410} 415}
411 416
412static void __exit ulog_tg_exit(void) 417static void __net_exit ulog_tg_net_exit(struct net *net)
413{ 418{
414 ulog_buff_t *ub; 419 ulog_buff_t *ub;
415 int i; 420 int i;
416 421 struct ulog_net *ulog = ulog_pernet(net);
417 pr_debug("cleanup_module\n");
418 422
419 if (nflog) 423 if (nflog)
420 nf_log_unregister(&ipt_ulog_logger); 424 nf_log_unset(net, &ipt_ulog_logger);
421 xt_unregister_target(&ulog_tg_reg); 425
422 netlink_kernel_release(nflognl); 426 netlink_kernel_release(ulog->nflognl);
423 427
424 /* remove pending timers and free allocated skb's */ 428 /* remove pending timers and free allocated skb's */
425 for (i = 0; i < ULOG_MAXNLGROUPS; i++) { 429 for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
426 ub = &ulog_buffers[i]; 430 ub = &ulog->ulog_buffers[i];
427 pr_debug("timer is deleting\n"); 431 pr_debug("timer is deleting\n");
428 del_timer(&ub->timer); 432 del_timer(&ub->timer);
429 433
@@ -434,5 +438,50 @@ static void __exit ulog_tg_exit(void)
434 } 438 }
435} 439}
436 440
441static struct pernet_operations ulog_tg_net_ops = {
442 .init = ulog_tg_net_init,
443 .exit = ulog_tg_net_exit,
444 .id = &ulog_net_id,
445 .size = sizeof(struct ulog_net),
446};
447
448static int __init ulog_tg_init(void)
449{
450 int ret;
451 pr_debug("init module\n");
452
453 if (nlbufsiz > 128*1024) {
454 pr_warn("Netlink buffer has to be <= 128kB\n");
455 return -EINVAL;
456 }
457
458 ret = register_pernet_subsys(&ulog_tg_net_ops);
459 if (ret)
460 goto out_pernet;
461
462 ret = xt_register_target(&ulog_tg_reg);
463 if (ret < 0)
464 goto out_target;
465
466 if (nflog)
467 nf_log_register(NFPROTO_IPV4, &ipt_ulog_logger);
468
469 return 0;
470
471out_target:
472 unregister_pernet_subsys(&ulog_tg_net_ops);
473out_pernet:
474 return ret;
475}
476
477static void __exit ulog_tg_exit(void)
478{
479 pr_debug("cleanup_module\n");
480 if (nflog)
481 nf_log_unregister(&ipt_ulog_logger);
482 xt_unregister_target(&ulog_tg_reg);
483 unregister_pernet_subsys(&ulog_tg_net_ops);
484}
485
437module_init(ulog_tg_init); 486module_init(ulog_tg_init);
438module_exit(ulog_tg_exit); 487module_exit(ulog_tg_exit);
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index 5241d997ab75..c2cd63d2d892 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -187,8 +187,8 @@ icmp_error(struct net *net, struct nf_conn *tmpl,
187 icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih); 187 icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih);
188 if (icmph == NULL) { 188 if (icmph == NULL) {
189 if (LOG_INVALID(net, IPPROTO_ICMP)) 189 if (LOG_INVALID(net, IPPROTO_ICMP))
190 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 190 nf_log_packet(net, PF_INET, 0, skb, NULL, NULL,
191 "nf_ct_icmp: short packet "); 191 NULL, "nf_ct_icmp: short packet ");
192 return -NF_ACCEPT; 192 return -NF_ACCEPT;
193 } 193 }
194 194
@@ -196,7 +196,7 @@ icmp_error(struct net *net, struct nf_conn *tmpl,
196 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING && 196 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
197 nf_ip_checksum(skb, hooknum, dataoff, 0)) { 197 nf_ip_checksum(skb, hooknum, dataoff, 0)) {
198 if (LOG_INVALID(net, IPPROTO_ICMP)) 198 if (LOG_INVALID(net, IPPROTO_ICMP))
199 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 199 nf_log_packet(net, PF_INET, 0, skb, NULL, NULL, NULL,
200 "nf_ct_icmp: bad HW ICMP checksum "); 200 "nf_ct_icmp: bad HW ICMP checksum ");
201 return -NF_ACCEPT; 201 return -NF_ACCEPT;
202 } 202 }
@@ -209,7 +209,7 @@ icmp_error(struct net *net, struct nf_conn *tmpl,
209 */ 209 */
210 if (icmph->type > NR_ICMP_TYPES) { 210 if (icmph->type > NR_ICMP_TYPES) {
211 if (LOG_INVALID(net, IPPROTO_ICMP)) 211 if (LOG_INVALID(net, IPPROTO_ICMP))
212 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 212 nf_log_packet(net, PF_INET, 0, skb, NULL, NULL, NULL,
213 "nf_ct_icmp: invalid ICMP type "); 213 "nf_ct_icmp: invalid ICMP type ");
214 return -NF_ACCEPT; 214 return -NF_ACCEPT;
215 } 215 }