1 // SPDX-License-Identifier: GPL-2.0-only
3 * This is a module which is used for queueing packets and communicating with
4 * userspace via nfnetlink.
6 * (C) 2005 by Harald Welte <laforge@netfilter.org>
7 * (C) 2007 by Patrick McHardy <kaber@trash.net>
9 * Based on the old ipv4-only ip_queue.c:
10 * (C) 2000-2002 James Morris <jmorris@intercode.com.au>
11 * (C) 2003-2005 Netfilter Core Team <coreteam@netfilter.org>
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/module.h>
17 #include <linux/skbuff.h>
18 #include <linux/init.h>
19 #include <linux/spinlock.h>
20 #include <linux/slab.h>
21 #include <linux/notifier.h>
22 #include <linux/netdevice.h>
23 #include <linux/netfilter.h>
24 #include <linux/proc_fs.h>
25 #include <linux/netfilter_ipv4.h>
26 #include <linux/netfilter_ipv6.h>
27 #include <linux/netfilter_bridge.h>
28 #include <linux/netfilter/nfnetlink.h>
29 #include <linux/netfilter/nfnetlink_queue.h>
30 #include <linux/netfilter/nf_conntrack_common.h>
31 #include <linux/list.h>
33 #include <net/tcp_states.h>
34 #include <net/netfilter/nf_queue.h>
35 #include <net/netns/generic.h>
37 #include <linux/atomic.h>
39 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
40 #include "../bridge/br_private.h"
43 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
44 #include <net/netfilter/nf_conntrack.h>
47 #define NFQNL_QMAX_DEFAULT 1024
49 /* We're using struct nlattr which has 16bit nla_len. Note that nla_len
50 * includes the header length. Thus, the maximum packet length that we
51 * support is 65531 bytes. We send truncated packets if the specified length
52 * is larger than that. Userspace can check for presence of NFQA_CAP_LEN
53 * attribute to detect truncation.
55 #define NFQNL_MAX_COPY_RANGE (0xffff - NLA_HDRLEN)
57 struct nfqnl_instance
{
58 struct hlist_node hlist
; /* global list of queues */
62 unsigned int queue_maxlen
;
63 unsigned int copy_range
;
64 unsigned int queue_dropped
;
65 unsigned int queue_user_dropped
;
68 u_int16_t queue_num
; /* number of this queue */
70 u_int32_t flags
; /* Set using NFQA_CFG_FLAGS */
72 * Following fields are dirtied for each queued packet,
73 * keep them in same cache line if possible.
75 spinlock_t lock ____cacheline_aligned_in_smp
;
76 unsigned int queue_total
;
77 unsigned int id_sequence
; /* 'sequence' of pkt ids */
78 struct list_head queue_list
; /* packets in queue */
81 typedef int (*nfqnl_cmpfn
)(struct nf_queue_entry
*, unsigned long);
83 static unsigned int nfnl_queue_net_id __read_mostly
;
85 #define INSTANCE_BUCKETS 16
86 struct nfnl_queue_net
{
87 spinlock_t instances_lock
;
88 struct hlist_head instance_table
[INSTANCE_BUCKETS
];
91 static struct nfnl_queue_net
*nfnl_queue_pernet(struct net
*net
)
93 return net_generic(net
, nfnl_queue_net_id
);
96 static inline u_int8_t
instance_hashfn(u_int16_t queue_num
)
98 return ((queue_num
>> 8) ^ queue_num
) % INSTANCE_BUCKETS
;
101 static struct nfqnl_instance
*
102 instance_lookup(struct nfnl_queue_net
*q
, u_int16_t queue_num
)
104 struct hlist_head
*head
;
105 struct nfqnl_instance
*inst
;
107 head
= &q
->instance_table
[instance_hashfn(queue_num
)];
108 hlist_for_each_entry_rcu(inst
, head
, hlist
) {
109 if (inst
->queue_num
== queue_num
)
115 static struct nfqnl_instance
*
116 instance_create(struct nfnl_queue_net
*q
, u_int16_t queue_num
, u32 portid
)
118 struct nfqnl_instance
*inst
;
122 spin_lock(&q
->instances_lock
);
123 if (instance_lookup(q
, queue_num
)) {
128 inst
= kzalloc(sizeof(*inst
), GFP_ATOMIC
);
134 inst
->queue_num
= queue_num
;
135 inst
->peer_portid
= portid
;
136 inst
->queue_maxlen
= NFQNL_QMAX_DEFAULT
;
137 inst
->copy_range
= NFQNL_MAX_COPY_RANGE
;
138 inst
->copy_mode
= NFQNL_COPY_NONE
;
139 spin_lock_init(&inst
->lock
);
140 INIT_LIST_HEAD(&inst
->queue_list
);
142 if (!try_module_get(THIS_MODULE
)) {
147 h
= instance_hashfn(queue_num
);
148 hlist_add_head_rcu(&inst
->hlist
, &q
->instance_table
[h
]);
150 spin_unlock(&q
->instances_lock
);
157 spin_unlock(&q
->instances_lock
);
161 static void nfqnl_flush(struct nfqnl_instance
*queue
, nfqnl_cmpfn cmpfn
,
165 instance_destroy_rcu(struct rcu_head
*head
)
167 struct nfqnl_instance
*inst
= container_of(head
, struct nfqnl_instance
,
170 nfqnl_flush(inst
, NULL
, 0);
172 module_put(THIS_MODULE
);
176 __instance_destroy(struct nfqnl_instance
*inst
)
178 hlist_del_rcu(&inst
->hlist
);
179 call_rcu(&inst
->rcu
, instance_destroy_rcu
);
183 instance_destroy(struct nfnl_queue_net
*q
, struct nfqnl_instance
*inst
)
185 spin_lock(&q
->instances_lock
);
186 __instance_destroy(inst
);
187 spin_unlock(&q
->instances_lock
);
191 __enqueue_entry(struct nfqnl_instance
*queue
, struct nf_queue_entry
*entry
)
193 list_add_tail(&entry
->list
, &queue
->queue_list
);
194 queue
->queue_total
++;
198 __dequeue_entry(struct nfqnl_instance
*queue
, struct nf_queue_entry
*entry
)
200 list_del(&entry
->list
);
201 queue
->queue_total
--;
204 static struct nf_queue_entry
*
205 find_dequeue_entry(struct nfqnl_instance
*queue
, unsigned int id
)
207 struct nf_queue_entry
*entry
= NULL
, *i
;
209 spin_lock_bh(&queue
->lock
);
211 list_for_each_entry(i
, &queue
->queue_list
, list
) {
219 __dequeue_entry(queue
, entry
);
221 spin_unlock_bh(&queue
->lock
);
226 static void nfqnl_reinject(struct nf_queue_entry
*entry
, unsigned int verdict
)
228 struct nf_ct_hook
*ct_hook
;
231 if (verdict
== NF_ACCEPT
||
232 verdict
== NF_REPEAT
||
233 verdict
== NF_STOP
) {
235 ct_hook
= rcu_dereference(nf_ct_hook
);
237 err
= ct_hook
->update(entry
->state
.net
, entry
->skb
);
243 nf_reinject(entry
, verdict
);
247 nfqnl_flush(struct nfqnl_instance
*queue
, nfqnl_cmpfn cmpfn
, unsigned long data
)
249 struct nf_queue_entry
*entry
, *next
;
251 spin_lock_bh(&queue
->lock
);
252 list_for_each_entry_safe(entry
, next
, &queue
->queue_list
, list
) {
253 if (!cmpfn
|| cmpfn(entry
, data
)) {
254 list_del(&entry
->list
);
255 queue
->queue_total
--;
256 nfqnl_reinject(entry
, NF_DROP
);
259 spin_unlock_bh(&queue
->lock
);
263 nfqnl_put_packet_info(struct sk_buff
*nlskb
, struct sk_buff
*packet
,
268 if (packet
->ip_summed
== CHECKSUM_PARTIAL
)
269 flags
= NFQA_SKB_CSUMNOTREADY
;
270 else if (csum_verify
)
271 flags
= NFQA_SKB_CSUM_NOTVERIFIED
;
273 if (skb_is_gso(packet
))
274 flags
|= NFQA_SKB_GSO
;
276 return flags
? nla_put_be32(nlskb
, NFQA_SKB_INFO
, htonl(flags
)) : 0;
279 static int nfqnl_put_sk_uidgid(struct sk_buff
*skb
, struct sock
*sk
)
281 const struct cred
*cred
;
283 if (!sk_fullsock(sk
))
286 read_lock_bh(&sk
->sk_callback_lock
);
287 if (sk
->sk_socket
&& sk
->sk_socket
->file
) {
288 cred
= sk
->sk_socket
->file
->f_cred
;
289 if (nla_put_be32(skb
, NFQA_UID
,
290 htonl(from_kuid_munged(&init_user_ns
, cred
->fsuid
))))
291 goto nla_put_failure
;
292 if (nla_put_be32(skb
, NFQA_GID
,
293 htonl(from_kgid_munged(&init_user_ns
, cred
->fsgid
))))
294 goto nla_put_failure
;
296 read_unlock_bh(&sk
->sk_callback_lock
);
300 read_unlock_bh(&sk
->sk_callback_lock
);
304 static u32
nfqnl_get_sk_secctx(struct sk_buff
*skb
, char **secdata
)
307 #if IS_ENABLED(CONFIG_NETWORK_SECMARK)
308 if (!skb
|| !sk_fullsock(skb
->sk
))
311 read_lock_bh(&skb
->sk
->sk_callback_lock
);
314 security_secid_to_secctx(skb
->secmark
, secdata
, &seclen
);
316 read_unlock_bh(&skb
->sk
->sk_callback_lock
);
321 static u32
nfqnl_get_bridge_size(struct nf_queue_entry
*entry
)
323 struct sk_buff
*entskb
= entry
->skb
;
326 if (entry
->state
.pf
!= PF_BRIDGE
|| !skb_mac_header_was_set(entskb
))
329 if (skb_vlan_tag_present(entskb
))
330 nlalen
+= nla_total_size(nla_total_size(sizeof(__be16
)) +
331 nla_total_size(sizeof(__be16
)));
333 if (entskb
->network_header
> entskb
->mac_header
)
334 nlalen
+= nla_total_size((entskb
->network_header
-
335 entskb
->mac_header
));
340 static int nfqnl_put_bridge(struct nf_queue_entry
*entry
, struct sk_buff
*skb
)
342 struct sk_buff
*entskb
= entry
->skb
;
344 if (entry
->state
.pf
!= PF_BRIDGE
|| !skb_mac_header_was_set(entskb
))
347 if (skb_vlan_tag_present(entskb
)) {
350 nest
= nla_nest_start(skb
, NFQA_VLAN
);
352 goto nla_put_failure
;
354 if (nla_put_be16(skb
, NFQA_VLAN_TCI
, htons(entskb
->vlan_tci
)) ||
355 nla_put_be16(skb
, NFQA_VLAN_PROTO
, entskb
->vlan_proto
))
356 goto nla_put_failure
;
358 nla_nest_end(skb
, nest
);
361 if (entskb
->mac_header
< entskb
->network_header
) {
362 int len
= (int)(entskb
->network_header
- entskb
->mac_header
);
364 if (nla_put(skb
, NFQA_L2HDR
, len
, skb_mac_header(entskb
)))
365 goto nla_put_failure
;
374 static struct sk_buff
*
375 nfqnl_build_packet_message(struct net
*net
, struct nfqnl_instance
*queue
,
376 struct nf_queue_entry
*entry
,
377 __be32
**packet_id_ptr
)
380 size_t data_len
= 0, cap_len
= 0;
381 unsigned int hlen
= 0;
384 struct nfqnl_msg_packet_hdr
*pmsg
;
385 struct nlmsghdr
*nlh
;
386 struct sk_buff
*entskb
= entry
->skb
;
387 struct net_device
*indev
;
388 struct net_device
*outdev
;
389 struct nf_conn
*ct
= NULL
;
390 enum ip_conntrack_info ctinfo
;
391 struct nfnl_ct_hook
*nfnl_ct
;
393 char *secdata
= NULL
;
396 size
= nlmsg_total_size(sizeof(struct nfgenmsg
))
397 + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr
))
398 + nla_total_size(sizeof(u_int32_t
)) /* ifindex */
399 + nla_total_size(sizeof(u_int32_t
)) /* ifindex */
400 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
401 + nla_total_size(sizeof(u_int32_t
)) /* ifindex */
402 + nla_total_size(sizeof(u_int32_t
)) /* ifindex */
404 + nla_total_size(sizeof(u_int32_t
)) /* mark */
405 + nla_total_size(sizeof(struct nfqnl_msg_packet_hw
))
406 + nla_total_size(sizeof(u_int32_t
)) /* skbinfo */
407 + nla_total_size(sizeof(u_int32_t
)); /* cap_len */
410 size
+= nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp
));
412 size
+= nfqnl_get_bridge_size(entry
);
414 if (entry
->state
.hook
<= NF_INET_FORWARD
||
415 (entry
->state
.hook
== NF_INET_POST_ROUTING
&& entskb
->sk
== NULL
))
416 csum_verify
= !skb_csum_unnecessary(entskb
);
420 outdev
= entry
->state
.out
;
422 switch ((enum nfqnl_config_mode
)READ_ONCE(queue
->copy_mode
)) {
423 case NFQNL_COPY_META
:
424 case NFQNL_COPY_NONE
:
427 case NFQNL_COPY_PACKET
:
428 if (!(queue
->flags
& NFQA_CFG_F_GSO
) &&
429 entskb
->ip_summed
== CHECKSUM_PARTIAL
&&
430 skb_checksum_help(entskb
))
433 data_len
= READ_ONCE(queue
->copy_range
);
434 if (data_len
> entskb
->len
)
435 data_len
= entskb
->len
;
437 hlen
= skb_zerocopy_headlen(entskb
);
438 hlen
= min_t(unsigned int, hlen
, data_len
);
439 size
+= sizeof(struct nlattr
) + hlen
;
440 cap_len
= entskb
->len
;
444 nfnl_ct
= rcu_dereference(nfnl_ct_hook
);
446 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
447 if (queue
->flags
& NFQA_CFG_F_CONNTRACK
) {
448 if (nfnl_ct
!= NULL
) {
449 ct
= nf_ct_get(entskb
, &ctinfo
);
451 size
+= nfnl_ct
->build_size(ct
);
456 if (queue
->flags
& NFQA_CFG_F_UID_GID
) {
457 size
+= (nla_total_size(sizeof(u_int32_t
)) /* uid */
458 + nla_total_size(sizeof(u_int32_t
))); /* gid */
461 if ((queue
->flags
& NFQA_CFG_F_SECCTX
) && entskb
->sk
) {
462 seclen
= nfqnl_get_sk_secctx(entskb
, &secdata
);
464 size
+= nla_total_size(seclen
);
467 skb
= alloc_skb(size
, GFP_ATOMIC
);
469 skb_tx_error(entskb
);
473 nlh
= nfnl_msg_put(skb
, 0, 0,
474 nfnl_msg_type(NFNL_SUBSYS_QUEUE
, NFQNL_MSG_PACKET
),
475 0, entry
->state
.pf
, NFNETLINK_V0
,
476 htons(queue
->queue_num
));
478 skb_tx_error(entskb
);
483 nla
= __nla_reserve(skb
, NFQA_PACKET_HDR
, sizeof(*pmsg
));
484 pmsg
= nla_data(nla
);
485 pmsg
->hw_protocol
= entskb
->protocol
;
486 pmsg
->hook
= entry
->state
.hook
;
487 *packet_id_ptr
= &pmsg
->packet_id
;
489 indev
= entry
->state
.in
;
491 #if !IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
492 if (nla_put_be32(skb
, NFQA_IFINDEX_INDEV
, htonl(indev
->ifindex
)))
493 goto nla_put_failure
;
495 if (entry
->state
.pf
== PF_BRIDGE
) {
496 /* Case 1: indev is physical input device, we need to
497 * look for bridge group (when called from
498 * netfilter_bridge) */
499 if (nla_put_be32(skb
, NFQA_IFINDEX_PHYSINDEV
,
500 htonl(indev
->ifindex
)) ||
501 /* this is the bridge group "brX" */
502 /* rcu_read_lock()ed by __nf_queue */
503 nla_put_be32(skb
, NFQA_IFINDEX_INDEV
,
504 htonl(br_port_get_rcu(indev
)->br
->dev
->ifindex
)))
505 goto nla_put_failure
;
509 /* Case 2: indev is bridge group, we need to look for
510 * physical device (when called from ipv4) */
511 if (nla_put_be32(skb
, NFQA_IFINDEX_INDEV
,
512 htonl(indev
->ifindex
)))
513 goto nla_put_failure
;
515 physinif
= nf_bridge_get_physinif(entskb
);
517 nla_put_be32(skb
, NFQA_IFINDEX_PHYSINDEV
,
519 goto nla_put_failure
;
525 #if !IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
526 if (nla_put_be32(skb
, NFQA_IFINDEX_OUTDEV
, htonl(outdev
->ifindex
)))
527 goto nla_put_failure
;
529 if (entry
->state
.pf
== PF_BRIDGE
) {
530 /* Case 1: outdev is physical output device, we need to
531 * look for bridge group (when called from
532 * netfilter_bridge) */
533 if (nla_put_be32(skb
, NFQA_IFINDEX_PHYSOUTDEV
,
534 htonl(outdev
->ifindex
)) ||
535 /* this is the bridge group "brX" */
536 /* rcu_read_lock()ed by __nf_queue */
537 nla_put_be32(skb
, NFQA_IFINDEX_OUTDEV
,
538 htonl(br_port_get_rcu(outdev
)->br
->dev
->ifindex
)))
539 goto nla_put_failure
;
543 /* Case 2: outdev is bridge group, we need to look for
544 * physical output device (when called from ipv4) */
545 if (nla_put_be32(skb
, NFQA_IFINDEX_OUTDEV
,
546 htonl(outdev
->ifindex
)))
547 goto nla_put_failure
;
549 physoutif
= nf_bridge_get_physoutif(entskb
);
551 nla_put_be32(skb
, NFQA_IFINDEX_PHYSOUTDEV
,
553 goto nla_put_failure
;
559 nla_put_be32(skb
, NFQA_MARK
, htonl(entskb
->mark
)))
560 goto nla_put_failure
;
562 if (indev
&& entskb
->dev
&&
563 skb_mac_header_was_set(entskb
) &&
564 skb_mac_header_len(entskb
) != 0) {
565 struct nfqnl_msg_packet_hw phw
;
568 memset(&phw
, 0, sizeof(phw
));
569 len
= dev_parse_header(entskb
, phw
.hw_addr
);
571 phw
.hw_addrlen
= htons(len
);
572 if (nla_put(skb
, NFQA_HWADDR
, sizeof(phw
), &phw
))
573 goto nla_put_failure
;
577 if (nfqnl_put_bridge(entry
, skb
) < 0)
578 goto nla_put_failure
;
580 if (entry
->state
.hook
<= NF_INET_FORWARD
&& entskb
->tstamp
) {
581 struct nfqnl_msg_packet_timestamp ts
;
582 struct timespec64 kts
= ktime_to_timespec64(entskb
->tstamp
);
584 ts
.sec
= cpu_to_be64(kts
.tv_sec
);
585 ts
.usec
= cpu_to_be64(kts
.tv_nsec
/ NSEC_PER_USEC
);
587 if (nla_put(skb
, NFQA_TIMESTAMP
, sizeof(ts
), &ts
))
588 goto nla_put_failure
;
591 if ((queue
->flags
& NFQA_CFG_F_UID_GID
) && entskb
->sk
&&
592 nfqnl_put_sk_uidgid(skb
, entskb
->sk
) < 0)
593 goto nla_put_failure
;
595 if (seclen
&& nla_put(skb
, NFQA_SECCTX
, seclen
, secdata
))
596 goto nla_put_failure
;
598 if (ct
&& nfnl_ct
->build(skb
, ct
, ctinfo
, NFQA_CT
, NFQA_CT_INFO
) < 0)
599 goto nla_put_failure
;
601 if (cap_len
> data_len
&&
602 nla_put_be32(skb
, NFQA_CAP_LEN
, htonl(cap_len
)))
603 goto nla_put_failure
;
605 if (nfqnl_put_packet_info(skb
, entskb
, csum_verify
))
606 goto nla_put_failure
;
611 if (skb_tailroom(skb
) < sizeof(*nla
) + hlen
)
612 goto nla_put_failure
;
614 nla
= skb_put(skb
, sizeof(*nla
));
615 nla
->nla_type
= NFQA_PAYLOAD
;
616 nla
->nla_len
= nla_attr_size(data_len
);
618 if (skb_zerocopy(skb
, entskb
, data_len
, hlen
))
619 goto nla_put_failure
;
622 nlh
->nlmsg_len
= skb
->len
;
624 security_release_secctx(secdata
, seclen
);
628 skb_tx_error(entskb
);
630 net_err_ratelimited("nf_queue: error creating packet message\n");
633 security_release_secctx(secdata
, seclen
);
637 static bool nf_ct_drop_unconfirmed(const struct nf_queue_entry
*entry
)
639 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
640 static const unsigned long flags
= IPS_CONFIRMED
| IPS_DYING
;
641 const struct nf_conn
*ct
= (void *)skb_nfct(entry
->skb
);
643 if (ct
&& ((ct
->status
& flags
) == IPS_DYING
))
650 __nfqnl_enqueue_packet(struct net
*net
, struct nfqnl_instance
*queue
,
651 struct nf_queue_entry
*entry
)
653 struct sk_buff
*nskb
;
655 __be32
*packet_id_ptr
;
658 nskb
= nfqnl_build_packet_message(net
, queue
, entry
, &packet_id_ptr
);
663 spin_lock_bh(&queue
->lock
);
665 if (nf_ct_drop_unconfirmed(entry
))
666 goto err_out_free_nskb
;
668 if (queue
->queue_total
>= queue
->queue_maxlen
) {
669 if (queue
->flags
& NFQA_CFG_F_FAIL_OPEN
) {
673 queue
->queue_dropped
++;
674 net_warn_ratelimited("nf_queue: full at %d entries, dropping packets(s)\n",
677 goto err_out_free_nskb
;
679 entry
->id
= ++queue
->id_sequence
;
680 *packet_id_ptr
= htonl(entry
->id
);
682 /* nfnetlink_unicast will either free the nskb or add it to a socket */
683 err
= nfnetlink_unicast(nskb
, net
, queue
->peer_portid
);
685 if (queue
->flags
& NFQA_CFG_F_FAIL_OPEN
) {
689 queue
->queue_user_dropped
++;
694 __enqueue_entry(queue
, entry
);
696 spin_unlock_bh(&queue
->lock
);
702 spin_unlock_bh(&queue
->lock
);
704 nfqnl_reinject(entry
, NF_ACCEPT
);
709 static struct nf_queue_entry
*
710 nf_queue_entry_dup(struct nf_queue_entry
*e
)
712 struct nf_queue_entry
*entry
= kmemdup(e
, e
->size
, GFP_ATOMIC
);
717 if (nf_queue_entry_get_refs(entry
))
724 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
725 /* When called from bridge netfilter, skb->data must point to MAC header
726 * before calling skb_gso_segment(). Else, original MAC header is lost
727 * and segmented skbs will be sent to wrong destination.
729 static void nf_bridge_adjust_skb_data(struct sk_buff
*skb
)
731 if (nf_bridge_info_get(skb
))
732 __skb_push(skb
, skb
->network_header
- skb
->mac_header
);
735 static void nf_bridge_adjust_segmented_data(struct sk_buff
*skb
)
737 if (nf_bridge_info_get(skb
))
738 __skb_pull(skb
, skb
->network_header
- skb
->mac_header
);
741 #define nf_bridge_adjust_skb_data(s) do {} while (0)
742 #define nf_bridge_adjust_segmented_data(s) do {} while (0)
746 __nfqnl_enqueue_packet_gso(struct net
*net
, struct nfqnl_instance
*queue
,
747 struct sk_buff
*skb
, struct nf_queue_entry
*entry
)
750 struct nf_queue_entry
*entry_seg
;
752 nf_bridge_adjust_segmented_data(skb
);
754 if (skb
->next
== NULL
) { /* last packet, no need to copy entry */
755 struct sk_buff
*gso_skb
= entry
->skb
;
757 ret
= __nfqnl_enqueue_packet(net
, queue
, entry
);
759 entry
->skb
= gso_skb
;
763 skb_mark_not_on_list(skb
);
765 entry_seg
= nf_queue_entry_dup(entry
);
767 entry_seg
->skb
= skb
;
768 ret
= __nfqnl_enqueue_packet(net
, queue
, entry_seg
);
770 nf_queue_entry_free(entry_seg
);
776 nfqnl_enqueue_packet(struct nf_queue_entry
*entry
, unsigned int queuenum
)
779 struct nfqnl_instance
*queue
;
780 struct sk_buff
*skb
, *segs
, *nskb
;
782 struct net
*net
= entry
->state
.net
;
783 struct nfnl_queue_net
*q
= nfnl_queue_pernet(net
);
785 /* rcu_read_lock()ed by nf_hook_thresh */
786 queue
= instance_lookup(q
, queuenum
);
790 if (queue
->copy_mode
== NFQNL_COPY_NONE
)
795 switch (entry
->state
.pf
) {
797 skb
->protocol
= htons(ETH_P_IP
);
800 skb
->protocol
= htons(ETH_P_IPV6
);
804 if ((queue
->flags
& NFQA_CFG_F_GSO
) || !skb_is_gso(skb
))
805 return __nfqnl_enqueue_packet(net
, queue
, entry
);
807 nf_bridge_adjust_skb_data(skb
);
808 segs
= skb_gso_segment(skb
, 0);
809 /* Does not use PTR_ERR to limit the number of error codes that can be
810 * returned by nf_queue. For instance, callers rely on -ESRCH to
811 * mean 'ignore this hook'.
813 if (IS_ERR_OR_NULL(segs
))
817 skb_list_walk_safe(segs
, segs
, nskb
) {
819 err
= __nfqnl_enqueue_packet_gso(net
, queue
,
828 if (err
) /* some segments are already queued */
829 nf_queue_entry_free(entry
);
834 nf_bridge_adjust_segmented_data(skb
);
839 nfqnl_mangle(void *data
, int data_len
, struct nf_queue_entry
*e
, int diff
)
841 struct sk_buff
*nskb
;
844 if (pskb_trim(e
->skb
, data_len
))
846 } else if (diff
> 0) {
847 if (data_len
> 0xFFFF)
849 if (diff
> skb_tailroom(e
->skb
)) {
850 nskb
= skb_copy_expand(e
->skb
, skb_headroom(e
->skb
),
857 skb_put(e
->skb
, diff
);
859 if (skb_ensure_writable(e
->skb
, data_len
))
861 skb_copy_to_linear_data(e
->skb
, data
, data_len
);
862 e
->skb
->ip_summed
= CHECKSUM_NONE
;
867 nfqnl_set_mode(struct nfqnl_instance
*queue
,
868 unsigned char mode
, unsigned int range
)
872 spin_lock_bh(&queue
->lock
);
874 case NFQNL_COPY_NONE
:
875 case NFQNL_COPY_META
:
876 queue
->copy_mode
= mode
;
877 queue
->copy_range
= 0;
880 case NFQNL_COPY_PACKET
:
881 queue
->copy_mode
= mode
;
882 if (range
== 0 || range
> NFQNL_MAX_COPY_RANGE
)
883 queue
->copy_range
= NFQNL_MAX_COPY_RANGE
;
885 queue
->copy_range
= range
;
892 spin_unlock_bh(&queue
->lock
);
898 dev_cmp(struct nf_queue_entry
*entry
, unsigned long ifindex
)
900 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
901 int physinif
, physoutif
;
903 physinif
= nf_bridge_get_physinif(entry
->skb
);
904 physoutif
= nf_bridge_get_physoutif(entry
->skb
);
906 if (physinif
== ifindex
|| physoutif
== ifindex
)
910 if (entry
->state
.in
->ifindex
== ifindex
)
912 if (entry
->state
.out
)
913 if (entry
->state
.out
->ifindex
== ifindex
)
919 /* drop all packets with either indev or outdev == ifindex from all queue
922 nfqnl_dev_drop(struct net
*net
, int ifindex
)
925 struct nfnl_queue_net
*q
= nfnl_queue_pernet(net
);
929 for (i
= 0; i
< INSTANCE_BUCKETS
; i
++) {
930 struct nfqnl_instance
*inst
;
931 struct hlist_head
*head
= &q
->instance_table
[i
];
933 hlist_for_each_entry_rcu(inst
, head
, hlist
)
934 nfqnl_flush(inst
, dev_cmp
, ifindex
);
941 nfqnl_rcv_dev_event(struct notifier_block
*this,
942 unsigned long event
, void *ptr
)
944 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
946 /* Drop any packets associated with the downed device */
947 if (event
== NETDEV_DOWN
)
948 nfqnl_dev_drop(dev_net(dev
), dev
->ifindex
);
952 static struct notifier_block nfqnl_dev_notifier
= {
953 .notifier_call
= nfqnl_rcv_dev_event
,
956 static void nfqnl_nf_hook_drop(struct net
*net
)
958 struct nfnl_queue_net
*q
= nfnl_queue_pernet(net
);
961 /* This function is also called on net namespace error unwind,
962 * when pernet_ops->init() failed and ->exit() functions of the
963 * previous pernet_ops gets called.
965 * This may result in a call to nfqnl_nf_hook_drop() before
966 * struct nfnl_queue_net was allocated.
971 for (i
= 0; i
< INSTANCE_BUCKETS
; i
++) {
972 struct nfqnl_instance
*inst
;
973 struct hlist_head
*head
= &q
->instance_table
[i
];
975 hlist_for_each_entry_rcu(inst
, head
, hlist
)
976 nfqnl_flush(inst
, NULL
, 0);
981 nfqnl_rcv_nl_event(struct notifier_block
*this,
982 unsigned long event
, void *ptr
)
984 struct netlink_notify
*n
= ptr
;
985 struct nfnl_queue_net
*q
= nfnl_queue_pernet(n
->net
);
987 if (event
== NETLINK_URELEASE
&& n
->protocol
== NETLINK_NETFILTER
) {
990 /* destroy all instances for this portid */
991 spin_lock(&q
->instances_lock
);
992 for (i
= 0; i
< INSTANCE_BUCKETS
; i
++) {
993 struct hlist_node
*t2
;
994 struct nfqnl_instance
*inst
;
995 struct hlist_head
*head
= &q
->instance_table
[i
];
997 hlist_for_each_entry_safe(inst
, t2
, head
, hlist
) {
998 if (n
->portid
== inst
->peer_portid
)
999 __instance_destroy(inst
);
1002 spin_unlock(&q
->instances_lock
);
1007 static struct notifier_block nfqnl_rtnl_notifier
= {
1008 .notifier_call
= nfqnl_rcv_nl_event
,
1011 static const struct nla_policy nfqa_vlan_policy
[NFQA_VLAN_MAX
+ 1] = {
1012 [NFQA_VLAN_TCI
] = { .type
= NLA_U16
},
1013 [NFQA_VLAN_PROTO
] = { .type
= NLA_U16
},
1016 static const struct nla_policy nfqa_verdict_policy
[NFQA_MAX
+1] = {
1017 [NFQA_VERDICT_HDR
] = { .len
= sizeof(struct nfqnl_msg_verdict_hdr
) },
1018 [NFQA_MARK
] = { .type
= NLA_U32
},
1019 [NFQA_PAYLOAD
] = { .type
= NLA_UNSPEC
},
1020 [NFQA_CT
] = { .type
= NLA_UNSPEC
},
1021 [NFQA_EXP
] = { .type
= NLA_UNSPEC
},
1022 [NFQA_VLAN
] = { .type
= NLA_NESTED
},
1025 static const struct nla_policy nfqa_verdict_batch_policy
[NFQA_MAX
+1] = {
1026 [NFQA_VERDICT_HDR
] = { .len
= sizeof(struct nfqnl_msg_verdict_hdr
) },
1027 [NFQA_MARK
] = { .type
= NLA_U32
},
1030 static struct nfqnl_instance
*
1031 verdict_instance_lookup(struct nfnl_queue_net
*q
, u16 queue_num
, u32 nlportid
)
1033 struct nfqnl_instance
*queue
;
1035 queue
= instance_lookup(q
, queue_num
);
1037 return ERR_PTR(-ENODEV
);
1039 if (queue
->peer_portid
!= nlportid
)
1040 return ERR_PTR(-EPERM
);
1045 static struct nfqnl_msg_verdict_hdr
*
1046 verdicthdr_get(const struct nlattr
* const nfqa
[])
1048 struct nfqnl_msg_verdict_hdr
*vhdr
;
1049 unsigned int verdict
;
1051 if (!nfqa
[NFQA_VERDICT_HDR
])
1054 vhdr
= nla_data(nfqa
[NFQA_VERDICT_HDR
]);
1055 verdict
= ntohl(vhdr
->verdict
) & NF_VERDICT_MASK
;
1056 if (verdict
> NF_MAX_VERDICT
|| verdict
== NF_STOLEN
)
1061 static int nfq_id_after(unsigned int id
, unsigned int max
)
1063 return (int)(id
- max
) > 0;
1066 static int nfqnl_recv_verdict_batch(struct sk_buff
*skb
,
1067 const struct nfnl_info
*info
,
1068 const struct nlattr
* const nfqa
[])
1070 struct nfnl_queue_net
*q
= nfnl_queue_pernet(info
->net
);
1071 u16 queue_num
= ntohs(info
->nfmsg
->res_id
);
1072 struct nf_queue_entry
*entry
, *tmp
;
1073 struct nfqnl_msg_verdict_hdr
*vhdr
;
1074 struct nfqnl_instance
*queue
;
1075 unsigned int verdict
, maxid
;
1076 LIST_HEAD(batch_list
);
1078 queue
= verdict_instance_lookup(q
, queue_num
,
1079 NETLINK_CB(skb
).portid
);
1081 return PTR_ERR(queue
);
1083 vhdr
= verdicthdr_get(nfqa
);
1087 verdict
= ntohl(vhdr
->verdict
);
1088 maxid
= ntohl(vhdr
->id
);
1090 spin_lock_bh(&queue
->lock
);
1092 list_for_each_entry_safe(entry
, tmp
, &queue
->queue_list
, list
) {
1093 if (nfq_id_after(entry
->id
, maxid
))
1095 __dequeue_entry(queue
, entry
);
1096 list_add_tail(&entry
->list
, &batch_list
);
1099 spin_unlock_bh(&queue
->lock
);
1101 if (list_empty(&batch_list
))
1104 list_for_each_entry_safe(entry
, tmp
, &batch_list
, list
) {
1105 if (nfqa
[NFQA_MARK
])
1106 entry
->skb
->mark
= ntohl(nla_get_be32(nfqa
[NFQA_MARK
]));
1108 nfqnl_reinject(entry
, verdict
);
1113 static struct nf_conn
*nfqnl_ct_parse(struct nfnl_ct_hook
*nfnl_ct
,
1114 const struct nlmsghdr
*nlh
,
1115 const struct nlattr
* const nfqa
[],
1116 struct nf_queue_entry
*entry
,
1117 enum ip_conntrack_info
*ctinfo
)
1119 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
1122 ct
= nf_ct_get(entry
->skb
, ctinfo
);
1126 if (nfnl_ct
->parse(nfqa
[NFQA_CT
], ct
) < 0)
1130 nfnl_ct
->attach_expect(nfqa
[NFQA_EXP
], ct
,
1131 NETLINK_CB(entry
->skb
).portid
,
1139 static int nfqa_parse_bridge(struct nf_queue_entry
*entry
,
1140 const struct nlattr
* const nfqa
[])
1142 if (nfqa
[NFQA_VLAN
]) {
1143 struct nlattr
*tb
[NFQA_VLAN_MAX
+ 1];
1146 err
= nla_parse_nested_deprecated(tb
, NFQA_VLAN_MAX
,
1148 nfqa_vlan_policy
, NULL
);
1152 if (!tb
[NFQA_VLAN_TCI
] || !tb
[NFQA_VLAN_PROTO
])
1155 __vlan_hwaccel_put_tag(entry
->skb
,
1156 nla_get_be16(tb
[NFQA_VLAN_PROTO
]),
1157 ntohs(nla_get_be16(tb
[NFQA_VLAN_TCI
])));
1160 if (nfqa
[NFQA_L2HDR
]) {
1161 int mac_header_len
= entry
->skb
->network_header
-
1162 entry
->skb
->mac_header
;
1164 if (mac_header_len
!= nla_len(nfqa
[NFQA_L2HDR
]))
1166 else if (mac_header_len
> 0)
1167 memcpy(skb_mac_header(entry
->skb
),
1168 nla_data(nfqa
[NFQA_L2HDR
]),
1175 static int nfqnl_recv_verdict(struct sk_buff
*skb
, const struct nfnl_info
*info
,
1176 const struct nlattr
* const nfqa
[])
1178 struct nfnl_queue_net
*q
= nfnl_queue_pernet(info
->net
);
1179 u_int16_t queue_num
= ntohs(info
->nfmsg
->res_id
);
1180 struct nfqnl_msg_verdict_hdr
*vhdr
;
1181 enum ip_conntrack_info ctinfo
;
1182 struct nfqnl_instance
*queue
;
1183 struct nf_queue_entry
*entry
;
1184 struct nfnl_ct_hook
*nfnl_ct
;
1185 struct nf_conn
*ct
= NULL
;
1186 unsigned int verdict
;
1189 queue
= verdict_instance_lookup(q
, queue_num
,
1190 NETLINK_CB(skb
).portid
);
1192 return PTR_ERR(queue
);
1194 vhdr
= verdicthdr_get(nfqa
);
1198 verdict
= ntohl(vhdr
->verdict
);
1200 entry
= find_dequeue_entry(queue
, ntohl(vhdr
->id
));
1204 /* rcu lock already held from nfnl->call_rcu. */
1205 nfnl_ct
= rcu_dereference(nfnl_ct_hook
);
1207 if (nfqa
[NFQA_CT
]) {
1208 if (nfnl_ct
!= NULL
)
1209 ct
= nfqnl_ct_parse(nfnl_ct
, info
->nlh
, nfqa
, entry
,
1213 if (entry
->state
.pf
== PF_BRIDGE
) {
1214 err
= nfqa_parse_bridge(entry
, nfqa
);
1219 if (nfqa
[NFQA_PAYLOAD
]) {
1220 u16 payload_len
= nla_len(nfqa
[NFQA_PAYLOAD
]);
1221 int diff
= payload_len
- entry
->skb
->len
;
1223 if (nfqnl_mangle(nla_data(nfqa
[NFQA_PAYLOAD
]),
1224 payload_len
, entry
, diff
) < 0)
1228 nfnl_ct
->seq_adjust(entry
->skb
, ct
, ctinfo
, diff
);
1231 if (nfqa
[NFQA_MARK
])
1232 entry
->skb
->mark
= ntohl(nla_get_be32(nfqa
[NFQA_MARK
]));
1234 nfqnl_reinject(entry
, verdict
);
1238 static int nfqnl_recv_unsupp(struct sk_buff
*skb
, const struct nfnl_info
*info
,
1239 const struct nlattr
* const cda
[])
1244 static const struct nla_policy nfqa_cfg_policy
[NFQA_CFG_MAX
+1] = {
1245 [NFQA_CFG_CMD
] = { .len
= sizeof(struct nfqnl_msg_config_cmd
) },
1246 [NFQA_CFG_PARAMS
] = { .len
= sizeof(struct nfqnl_msg_config_params
) },
1247 [NFQA_CFG_QUEUE_MAXLEN
] = { .type
= NLA_U32
},
1248 [NFQA_CFG_MASK
] = { .type
= NLA_U32
},
1249 [NFQA_CFG_FLAGS
] = { .type
= NLA_U32
},
1252 static const struct nf_queue_handler nfqh
= {
1253 .outfn
= nfqnl_enqueue_packet
,
1254 .nf_hook_drop
= nfqnl_nf_hook_drop
,
1257 static int nfqnl_recv_config(struct sk_buff
*skb
, const struct nfnl_info
*info
,
1258 const struct nlattr
* const nfqa
[])
1260 struct nfnl_queue_net
*q
= nfnl_queue_pernet(info
->net
);
1261 u_int16_t queue_num
= ntohs(info
->nfmsg
->res_id
);
1262 struct nfqnl_msg_config_cmd
*cmd
= NULL
;
1263 struct nfqnl_instance
*queue
;
1264 __u32 flags
= 0, mask
= 0;
1267 if (nfqa
[NFQA_CFG_CMD
]) {
1268 cmd
= nla_data(nfqa
[NFQA_CFG_CMD
]);
1270 /* Obsolete commands without queue context */
1271 switch (cmd
->command
) {
1272 case NFQNL_CFG_CMD_PF_BIND
: return 0;
1273 case NFQNL_CFG_CMD_PF_UNBIND
: return 0;
1277 /* Check if we support these flags in first place, dependencies should
1278 * be there too not to break atomicity.
1280 if (nfqa
[NFQA_CFG_FLAGS
]) {
1281 if (!nfqa
[NFQA_CFG_MASK
]) {
1282 /* A mask is needed to specify which flags are being
1288 flags
= ntohl(nla_get_be32(nfqa
[NFQA_CFG_FLAGS
]));
1289 mask
= ntohl(nla_get_be32(nfqa
[NFQA_CFG_MASK
]));
1291 if (flags
>= NFQA_CFG_F_MAX
)
1294 #if !IS_ENABLED(CONFIG_NETWORK_SECMARK)
1295 if (flags
& mask
& NFQA_CFG_F_SECCTX
)
1298 if ((flags
& mask
& NFQA_CFG_F_CONNTRACK
) &&
1299 !rcu_access_pointer(nfnl_ct_hook
)) {
1300 #ifdef CONFIG_MODULES
1301 nfnl_unlock(NFNL_SUBSYS_QUEUE
);
1302 request_module("ip_conntrack_netlink");
1303 nfnl_lock(NFNL_SUBSYS_QUEUE
);
1304 if (rcu_access_pointer(nfnl_ct_hook
))
1312 queue
= instance_lookup(q
, queue_num
);
1313 if (queue
&& queue
->peer_portid
!= NETLINK_CB(skb
).portid
) {
1315 goto err_out_unlock
;
1319 switch (cmd
->command
) {
1320 case NFQNL_CFG_CMD_BIND
:
1323 goto err_out_unlock
;
1325 queue
= instance_create(q
, queue_num
,
1326 NETLINK_CB(skb
).portid
);
1327 if (IS_ERR(queue
)) {
1328 ret
= PTR_ERR(queue
);
1329 goto err_out_unlock
;
1332 case NFQNL_CFG_CMD_UNBIND
:
1335 goto err_out_unlock
;
1337 instance_destroy(q
, queue
);
1338 goto err_out_unlock
;
1339 case NFQNL_CFG_CMD_PF_BIND
:
1340 case NFQNL_CFG_CMD_PF_UNBIND
:
1344 goto err_out_unlock
;
1350 goto err_out_unlock
;
1353 if (nfqa
[NFQA_CFG_PARAMS
]) {
1354 struct nfqnl_msg_config_params
*params
=
1355 nla_data(nfqa
[NFQA_CFG_PARAMS
]);
1357 nfqnl_set_mode(queue
, params
->copy_mode
,
1358 ntohl(params
->copy_range
));
1361 if (nfqa
[NFQA_CFG_QUEUE_MAXLEN
]) {
1362 __be32
*queue_maxlen
= nla_data(nfqa
[NFQA_CFG_QUEUE_MAXLEN
]);
1364 spin_lock_bh(&queue
->lock
);
1365 queue
->queue_maxlen
= ntohl(*queue_maxlen
);
1366 spin_unlock_bh(&queue
->lock
);
1369 if (nfqa
[NFQA_CFG_FLAGS
]) {
1370 spin_lock_bh(&queue
->lock
);
1371 queue
->flags
&= ~mask
;
1372 queue
->flags
|= flags
& mask
;
1373 spin_unlock_bh(&queue
->lock
);
1381 static const struct nfnl_callback nfqnl_cb
[NFQNL_MSG_MAX
] = {
1382 [NFQNL_MSG_PACKET
] = {
1383 .call
= nfqnl_recv_unsupp
,
1384 .type
= NFNL_CB_RCU
,
1385 .attr_count
= NFQA_MAX
,
1387 [NFQNL_MSG_VERDICT
] = {
1388 .call
= nfqnl_recv_verdict
,
1389 .type
= NFNL_CB_RCU
,
1390 .attr_count
= NFQA_MAX
,
1391 .policy
= nfqa_verdict_policy
1393 [NFQNL_MSG_CONFIG
] = {
1394 .call
= nfqnl_recv_config
,
1395 .type
= NFNL_CB_MUTEX
,
1396 .attr_count
= NFQA_CFG_MAX
,
1397 .policy
= nfqa_cfg_policy
1399 [NFQNL_MSG_VERDICT_BATCH
] = {
1400 .call
= nfqnl_recv_verdict_batch
,
1401 .type
= NFNL_CB_RCU
,
1402 .attr_count
= NFQA_MAX
,
1403 .policy
= nfqa_verdict_batch_policy
1407 static const struct nfnetlink_subsystem nfqnl_subsys
= {
1409 .subsys_id
= NFNL_SUBSYS_QUEUE
,
1410 .cb_count
= NFQNL_MSG_MAX
,
1414 #ifdef CONFIG_PROC_FS
1416 struct seq_net_private p
;
1417 unsigned int bucket
;
1420 static struct hlist_node
*get_first(struct seq_file
*seq
)
1422 struct iter_state
*st
= seq
->private;
1424 struct nfnl_queue_net
*q
;
1429 net
= seq_file_net(seq
);
1430 q
= nfnl_queue_pernet(net
);
1431 for (st
->bucket
= 0; st
->bucket
< INSTANCE_BUCKETS
; st
->bucket
++) {
1432 if (!hlist_empty(&q
->instance_table
[st
->bucket
]))
1433 return q
->instance_table
[st
->bucket
].first
;
1438 static struct hlist_node
*get_next(struct seq_file
*seq
, struct hlist_node
*h
)
1440 struct iter_state
*st
= seq
->private;
1441 struct net
*net
= seq_file_net(seq
);
1445 struct nfnl_queue_net
*q
;
1447 if (++st
->bucket
>= INSTANCE_BUCKETS
)
1450 q
= nfnl_queue_pernet(net
);
1451 h
= q
->instance_table
[st
->bucket
].first
;
1456 static struct hlist_node
*get_idx(struct seq_file
*seq
, loff_t pos
)
1458 struct hlist_node
*head
;
1459 head
= get_first(seq
);
1462 while (pos
&& (head
= get_next(seq
, head
)))
1464 return pos
? NULL
: head
;
1467 static void *seq_start(struct seq_file
*s
, loff_t
*pos
)
1468 __acquires(nfnl_queue_pernet(seq_file_net(s
))->instances_lock
)
1470 spin_lock(&nfnl_queue_pernet(seq_file_net(s
))->instances_lock
);
1471 return get_idx(s
, *pos
);
1474 static void *seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
1477 return get_next(s
, v
);
1480 static void seq_stop(struct seq_file
*s
, void *v
)
1481 __releases(nfnl_queue_pernet(seq_file_net(s
))->instances_lock
)
1483 spin_unlock(&nfnl_queue_pernet(seq_file_net(s
))->instances_lock
);
1486 static int seq_show(struct seq_file
*s
, void *v
)
1488 const struct nfqnl_instance
*inst
= v
;
1490 seq_printf(s
, "%5u %6u %5u %1u %5u %5u %5u %8u %2d\n",
1492 inst
->peer_portid
, inst
->queue_total
,
1493 inst
->copy_mode
, inst
->copy_range
,
1494 inst
->queue_dropped
, inst
->queue_user_dropped
,
1495 inst
->id_sequence
, 1);
1499 static const struct seq_operations nfqnl_seq_ops
= {
1505 #endif /* PROC_FS */
1507 static int __net_init
nfnl_queue_net_init(struct net
*net
)
1510 struct nfnl_queue_net
*q
= nfnl_queue_pernet(net
);
1512 for (i
= 0; i
< INSTANCE_BUCKETS
; i
++)
1513 INIT_HLIST_HEAD(&q
->instance_table
[i
]);
1515 spin_lock_init(&q
->instances_lock
);
1517 #ifdef CONFIG_PROC_FS
1518 if (!proc_create_net("nfnetlink_queue", 0440, net
->nf
.proc_netfilter
,
1519 &nfqnl_seq_ops
, sizeof(struct iter_state
)))
1525 static void __net_exit
nfnl_queue_net_exit(struct net
*net
)
1527 struct nfnl_queue_net
*q
= nfnl_queue_pernet(net
);
1530 #ifdef CONFIG_PROC_FS
1531 remove_proc_entry("nfnetlink_queue", net
->nf
.proc_netfilter
);
1533 for (i
= 0; i
< INSTANCE_BUCKETS
; i
++)
1534 WARN_ON_ONCE(!hlist_empty(&q
->instance_table
[i
]));
1537 static void nfnl_queue_net_exit_batch(struct list_head
*net_exit_list
)
1542 static struct pernet_operations nfnl_queue_net_ops
= {
1543 .init
= nfnl_queue_net_init
,
1544 .exit
= nfnl_queue_net_exit
,
1545 .exit_batch
= nfnl_queue_net_exit_batch
,
1546 .id
= &nfnl_queue_net_id
,
1547 .size
= sizeof(struct nfnl_queue_net
),
1550 static int __init
nfnetlink_queue_init(void)
1554 status
= register_pernet_subsys(&nfnl_queue_net_ops
);
1556 pr_err("failed to register pernet ops\n");
1560 netlink_register_notifier(&nfqnl_rtnl_notifier
);
1561 status
= nfnetlink_subsys_register(&nfqnl_subsys
);
1563 pr_err("failed to create netlink socket\n");
1564 goto cleanup_netlink_notifier
;
1567 status
= register_netdevice_notifier(&nfqnl_dev_notifier
);
1569 pr_err("failed to register netdevice notifier\n");
1570 goto cleanup_netlink_subsys
;
1573 nf_register_queue_handler(&nfqh
);
1577 cleanup_netlink_subsys
:
1578 nfnetlink_subsys_unregister(&nfqnl_subsys
);
1579 cleanup_netlink_notifier
:
1580 netlink_unregister_notifier(&nfqnl_rtnl_notifier
);
1581 unregister_pernet_subsys(&nfnl_queue_net_ops
);
1586 static void __exit
nfnetlink_queue_fini(void)
1588 nf_unregister_queue_handler();
1589 unregister_netdevice_notifier(&nfqnl_dev_notifier
);
1590 nfnetlink_subsys_unregister(&nfqnl_subsys
);
1591 netlink_unregister_notifier(&nfqnl_rtnl_notifier
);
1592 unregister_pernet_subsys(&nfnl_queue_net_ops
);
1594 rcu_barrier(); /* Wait for completion of call_rcu()'s */
1597 MODULE_DESCRIPTION("netfilter packet queue handler");
1598 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
1599 MODULE_LICENSE("GPL");
1600 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_QUEUE
);
1602 module_init(nfnetlink_queue_init
);
1603 module_exit(nfnetlink_queue_fini
);