Merge tag 'perf-tools-fixes-for-v6.4-1-2023-05-20' of git://git.kernel.org/pub/scm...
[linux-block.git] / net / netfilter / nfnetlink_queue.c
CommitLineData
d2912cb1 1// SPDX-License-Identifier: GPL-2.0-only
7af4cc3f
HW
2/*
3 * This is a module which is used for queueing packets and communicating with
67137f3c 4 * userspace via nfnetlink.
7af4cc3f
HW
5 *
6 * (C) 2005 by Harald Welte <laforge@netfilter.org>
4ad9d4fa 7 * (C) 2007 by Patrick McHardy <kaber@trash.net>
7af4cc3f
HW
8 *
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>
7af4cc3f 12 */
5191d70f
AS
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
7af4cc3f
HW
16#include <linux/module.h>
17#include <linux/skbuff.h>
18#include <linux/init.h>
19#include <linux/spinlock.h>
5a0e3ad6 20#include <linux/slab.h>
7af4cc3f
HW
21#include <linux/notifier.h>
22#include <linux/netdevice.h>
23#include <linux/netfilter.h>
838ab636 24#include <linux/proc_fs.h>
7af4cc3f
HW
25#include <linux/netfilter_ipv4.h>
26#include <linux/netfilter_ipv6.h>
c737b7c4 27#include <linux/netfilter_bridge.h>
7af4cc3f
HW
28#include <linux/netfilter/nfnetlink.h>
29#include <linux/netfilter/nfnetlink_queue.h>
b7bd1809 30#include <linux/netfilter/nf_conntrack_common.h>
7af4cc3f 31#include <linux/list.h>
28c1b6df 32#include <linux/cgroup-defs.h>
7af4cc3f 33#include <net/sock.h>
83111e7f 34#include <net/tcp_states.h>
c01cd429 35#include <net/netfilter/nf_queue.h>
e8179610 36#include <net/netns/generic.h>
7af4cc3f 37
60063497 38#include <linux/atomic.h>
7af4cc3f 39
1109a90c 40#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
fbcd923c
HW
41#include "../bridge/br_private.h"
42#endif
43
5da773a3
FW
44#if IS_ENABLED(CONFIG_NF_CONNTRACK)
45#include <net/netfilter/nf_conntrack.h>
46#endif
47
7af4cc3f
HW
48#define NFQNL_QMAX_DEFAULT 1024
49
9cefbbc9
FW
50/* We're using struct nlattr which has 16bit nla_len. Note that nla_len
51 * includes the header length. Thus, the maximum packet length that we
52 * support is 65531 bytes. We send truncated packets if the specified length
53 * is larger than that. Userspace can check for presence of NFQA_CAP_LEN
54 * attribute to detect truncation.
55 */
56#define NFQNL_MAX_COPY_RANGE (0xffff - NLA_HDRLEN)
57
7af4cc3f
HW
58struct nfqnl_instance {
59 struct hlist_node hlist; /* global list of queues */
9872bec7 60 struct rcu_head rcu;
7af4cc3f 61
cc6bc448 62 u32 peer_portid;
7af4cc3f
HW
63 unsigned int queue_maxlen;
64 unsigned int copy_range;
7af4cc3f
HW
65 unsigned int queue_dropped;
66 unsigned int queue_user_dropped;
67
7af4cc3f
HW
68
69 u_int16_t queue_num; /* number of this queue */
70 u_int8_t copy_mode;
fdb694a0 71 u_int32_t flags; /* Set using NFQA_CFG_FLAGS */
c463ac97
ED
72/*
73 * Following fields are dirtied for each queued packet,
74 * keep them in same cache line if possible.
75 */
886bc503 76 spinlock_t lock ____cacheline_aligned_in_smp;
c463ac97 77 unsigned int queue_total;
5863702a 78 unsigned int id_sequence; /* 'sequence' of pkt ids */
7af4cc3f
HW
79 struct list_head queue_list; /* packets in queue */
80};
81
02f014d8 82typedef int (*nfqnl_cmpfn)(struct nf_queue_entry *, unsigned long);
7af4cc3f 83
c7d03a00 84static unsigned int nfnl_queue_net_id __read_mostly;
7af4cc3f 85
7af4cc3f 86#define INSTANCE_BUCKETS 16
e8179610
G
87struct nfnl_queue_net {
88 spinlock_t instances_lock;
89 struct hlist_head instance_table[INSTANCE_BUCKETS];
90};
91
92static struct nfnl_queue_net *nfnl_queue_pernet(struct net *net)
93{
94 return net_generic(net, nfnl_queue_net_id);
95}
7af4cc3f
HW
96
97static inline u_int8_t instance_hashfn(u_int16_t queue_num)
98{
1cdb0905 99 return ((queue_num >> 8) ^ queue_num) % INSTANCE_BUCKETS;
7af4cc3f
HW
100}
101
102static struct nfqnl_instance *
e8179610 103instance_lookup(struct nfnl_queue_net *q, u_int16_t queue_num)
7af4cc3f
HW
104{
105 struct hlist_head *head;
7af4cc3f
HW
106 struct nfqnl_instance *inst;
107
e8179610 108 head = &q->instance_table[instance_hashfn(queue_num)];
b67bfe0d 109 hlist_for_each_entry_rcu(inst, head, hlist) {
7af4cc3f
HW
110 if (inst->queue_num == queue_num)
111 return inst;
112 }
113 return NULL;
114}
115
7af4cc3f 116static struct nfqnl_instance *
cc6bc448 117instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid)
7af4cc3f 118{
baab2ce7 119 struct nfqnl_instance *inst;
9872bec7 120 unsigned int h;
baab2ce7 121 int err;
7af4cc3f 122
e8179610
G
123 spin_lock(&q->instances_lock);
124 if (instance_lookup(q, queue_num)) {
baab2ce7 125 err = -EEXIST;
7af4cc3f 126 goto out_unlock;
baab2ce7 127 }
7af4cc3f 128
10dfdc69 129 inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
baab2ce7
PM
130 if (!inst) {
131 err = -ENOMEM;
7af4cc3f 132 goto out_unlock;
baab2ce7 133 }
7af4cc3f 134
7af4cc3f 135 inst->queue_num = queue_num;
15e47304 136 inst->peer_portid = portid;
7af4cc3f 137 inst->queue_maxlen = NFQNL_QMAX_DEFAULT;
9cefbbc9 138 inst->copy_range = NFQNL_MAX_COPY_RANGE;
7af4cc3f 139 inst->copy_mode = NFQNL_COPY_NONE;
181a46a5 140 spin_lock_init(&inst->lock);
7af4cc3f
HW
141 INIT_LIST_HEAD(&inst->queue_list);
142
baab2ce7
PM
143 if (!try_module_get(THIS_MODULE)) {
144 err = -EAGAIN;
7af4cc3f 145 goto out_free;
baab2ce7 146 }
7af4cc3f 147
9872bec7 148 h = instance_hashfn(queue_num);
e8179610 149 hlist_add_head_rcu(&inst->hlist, &q->instance_table[h]);
7af4cc3f 150
e8179610 151 spin_unlock(&q->instances_lock);
7af4cc3f 152
7af4cc3f
HW
153 return inst;
154
155out_free:
156 kfree(inst);
157out_unlock:
e8179610 158 spin_unlock(&q->instances_lock);
baab2ce7 159 return ERR_PTR(err);
7af4cc3f
HW
160}
161
b43d8d85
PM
162static void nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn,
163 unsigned long data);
7af4cc3f
HW
164
165static void
9872bec7 166instance_destroy_rcu(struct rcu_head *head)
7af4cc3f 167{
9872bec7
PM
168 struct nfqnl_instance *inst = container_of(head, struct nfqnl_instance,
169 rcu);
7af4cc3f 170
b43d8d85 171 nfqnl_flush(inst, NULL, 0);
9872bec7 172 kfree(inst);
7af4cc3f
HW
173 module_put(THIS_MODULE);
174}
175
9872bec7 176static void
7af4cc3f
HW
177__instance_destroy(struct nfqnl_instance *inst)
178{
9872bec7
PM
179 hlist_del_rcu(&inst->hlist);
180 call_rcu(&inst->rcu, instance_destroy_rcu);
7af4cc3f
HW
181}
182
9872bec7 183static void
e8179610 184instance_destroy(struct nfnl_queue_net *q, struct nfqnl_instance *inst)
7af4cc3f 185{
e8179610 186 spin_lock(&q->instances_lock);
9872bec7 187 __instance_destroy(inst);
e8179610 188 spin_unlock(&q->instances_lock);
7af4cc3f
HW
189}
190
7af4cc3f 191static inline void
02f014d8 192__enqueue_entry(struct nfqnl_instance *queue, struct nf_queue_entry *entry)
7af4cc3f 193{
0ac41e81 194 list_add_tail(&entry->list, &queue->queue_list);
7af4cc3f
HW
195 queue->queue_total++;
196}
197
97d32cf9
FW
198static void
199__dequeue_entry(struct nfqnl_instance *queue, struct nf_queue_entry *entry)
200{
201 list_del(&entry->list);
202 queue->queue_total--;
203}
204
02f014d8 205static struct nf_queue_entry *
b43d8d85 206find_dequeue_entry(struct nfqnl_instance *queue, unsigned int id)
7af4cc3f 207{
02f014d8 208 struct nf_queue_entry *entry = NULL, *i;
601e68e1 209
7af4cc3f 210 spin_lock_bh(&queue->lock);
b43d8d85
PM
211
212 list_for_each_entry(i, &queue->queue_list, list) {
213 if (i->id == id) {
214 entry = i;
215 break;
216 }
217 }
218
97d32cf9
FW
219 if (entry)
220 __dequeue_entry(queue, entry);
b43d8d85 221
7af4cc3f
HW
222 spin_unlock_bh(&queue->lock);
223
224 return entry;
225}
226
368982cd
PNA
227static void nfqnl_reinject(struct nf_queue_entry *entry, unsigned int verdict)
228{
285c8a7a 229 const struct nf_ct_hook *ct_hook;
368982cd
PNA
230 int err;
231
232 if (verdict == NF_ACCEPT ||
ad18d7bf 233 verdict == NF_REPEAT ||
368982cd
PNA
234 verdict == NF_STOP) {
235 rcu_read_lock();
236 ct_hook = rcu_dereference(nf_ct_hook);
237 if (ct_hook) {
238 err = ct_hook->update(entry->state.net, entry->skb);
239 if (err < 0)
240 verdict = NF_DROP;
241 }
242 rcu_read_unlock();
243 }
244 nf_reinject(entry, verdict);
245}
246
7af4cc3f 247static void
b43d8d85 248nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn, unsigned long data)
7af4cc3f 249{
02f014d8 250 struct nf_queue_entry *entry, *next;
b43d8d85 251
7af4cc3f 252 spin_lock_bh(&queue->lock);
b43d8d85
PM
253 list_for_each_entry_safe(entry, next, &queue->queue_list, list) {
254 if (!cmpfn || cmpfn(entry, data)) {
255 list_del(&entry->list);
256 queue->queue_total--;
368982cd 257 nfqnl_reinject(entry, NF_DROP);
b43d8d85
PM
258 }
259 }
7af4cc3f
HW
260 spin_unlock_bh(&queue->lock);
261}
262
496e4ae7
FW
263static int
264nfqnl_put_packet_info(struct sk_buff *nlskb, struct sk_buff *packet,
265 bool csum_verify)
7237190d
FW
266{
267 __u32 flags = 0;
268
269 if (packet->ip_summed == CHECKSUM_PARTIAL)
270 flags = NFQA_SKB_CSUMNOTREADY;
496e4ae7
FW
271 else if (csum_verify)
272 flags = NFQA_SKB_CSUM_NOTVERIFIED;
273
7237190d
FW
274 if (skb_is_gso(packet))
275 flags |= NFQA_SKB_GSO;
276
277 return flags ? nla_put_be32(nlskb, NFQA_SKB_INFO, htonl(flags)) : 0;
278}
279
08c0cad6
VG
280static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)
281{
282 const struct cred *cred;
283
a8399231 284 if (!sk_fullsock(sk))
08c0cad6
VG
285 return 0;
286
287 read_lock_bh(&sk->sk_callback_lock);
288 if (sk->sk_socket && sk->sk_socket->file) {
289 cred = sk->sk_socket->file->f_cred;
290 if (nla_put_be32(skb, NFQA_UID,
291 htonl(from_kuid_munged(&init_user_ns, cred->fsuid))))
292 goto nla_put_failure;
293 if (nla_put_be32(skb, NFQA_GID,
294 htonl(from_kgid_munged(&init_user_ns, cred->fsgid))))
295 goto nla_put_failure;
296 }
297 read_unlock_bh(&sk->sk_callback_lock);
298 return 0;
299
300nla_put_failure:
301 read_unlock_bh(&sk->sk_callback_lock);
302 return -1;
303}
304
28c1b6df
ES
305static int nfqnl_put_sk_classid(struct sk_buff *skb, struct sock *sk)
306{
307#if IS_ENABLED(CONFIG_CGROUP_NET_CLASSID)
308 if (sk && sk_fullsock(sk)) {
309 u32 classid = sock_cgroup_classid(&sk->sk_cgrp_data);
310
311 if (classid && nla_put_be32(skb, NFQA_CGROUP_CLASSID, htonl(classid)))
312 return -1;
313 }
314#endif
315 return 0;
316}
317
ef493bd9
RK
318static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata)
319{
320 u32 seclen = 0;
321#if IS_ENABLED(CONFIG_NETWORK_SECMARK)
322 if (!skb || !sk_fullsock(skb->sk))
323 return 0;
324
325 read_lock_bh(&skb->sk->sk_callback_lock);
326
327 if (skb->secmark)
328 security_secid_to_secctx(skb->secmark, secdata, &seclen);
329
330 read_unlock_bh(&skb->sk->sk_callback_lock);
331#endif
332 return seclen;
333}
334
15824ab2
SB
335static u32 nfqnl_get_bridge_size(struct nf_queue_entry *entry)
336{
337 struct sk_buff *entskb = entry->skb;
338 u32 nlalen = 0;
339
340 if (entry->state.pf != PF_BRIDGE || !skb_mac_header_was_set(entskb))
341 return 0;
342
343 if (skb_vlan_tag_present(entskb))
344 nlalen += nla_total_size(nla_total_size(sizeof(__be16)) +
345 nla_total_size(sizeof(__be16)));
346
347 if (entskb->network_header > entskb->mac_header)
348 nlalen += nla_total_size((entskb->network_header -
349 entskb->mac_header));
350
351 return nlalen;
352}
353
354static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb)
355{
356 struct sk_buff *entskb = entry->skb;
357
358 if (entry->state.pf != PF_BRIDGE || !skb_mac_header_was_set(entskb))
359 return 0;
360
361 if (skb_vlan_tag_present(entskb)) {
362 struct nlattr *nest;
363
ae0be8de 364 nest = nla_nest_start(skb, NFQA_VLAN);
15824ab2
SB
365 if (!nest)
366 goto nla_put_failure;
367
368 if (nla_put_be16(skb, NFQA_VLAN_TCI, htons(entskb->vlan_tci)) ||
369 nla_put_be16(skb, NFQA_VLAN_PROTO, entskb->vlan_proto))
370 goto nla_put_failure;
371
372 nla_nest_end(skb, nest);
373 }
374
375 if (entskb->mac_header < entskb->network_header) {
376 int len = (int)(entskb->network_header - entskb->mac_header);
377
378 if (nla_put(skb, NFQA_L2HDR, len, skb_mac_header(entskb)))
379 goto nla_put_failure;
380 }
381
382 return 0;
383
384nla_put_failure:
385 return -1;
386}
387
7af4cc3f 388static struct sk_buff *
74332687 389nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
5863702a
ED
390 struct nf_queue_entry *entry,
391 __be32 **packet_id_ptr)
7af4cc3f 392{
7af4cc3f 393 size_t size;
c5b0db32 394 size_t data_len = 0, cap_len = 0;
af2806f8 395 unsigned int hlen = 0;
7af4cc3f 396 struct sk_buff *skb;
5863702a
ED
397 struct nlattr *nla;
398 struct nfqnl_msg_packet_hdr *pmsg;
7af4cc3f 399 struct nlmsghdr *nlh;
3e4ead4f
JJ
400 struct sk_buff *entskb = entry->skb;
401 struct net_device *indev;
402 struct net_device *outdev;
9cb01766 403 struct nf_conn *ct = NULL;
b43c2793 404 enum ip_conntrack_info ctinfo = 0;
285c8a7a 405 const struct nfnl_ct_hook *nfnl_ct;
496e4ae7 406 bool csum_verify;
ef493bd9
RK
407 char *secdata = NULL;
408 u32 seclen = 0;
80fcec67 409 ktime_t tstamp;
7af4cc3f 410
7e59b3fe 411 size = nlmsg_total_size(sizeof(struct nfgenmsg))
df6fb868
PM
412 + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
413 + nla_total_size(sizeof(u_int32_t)) /* ifindex */
414 + nla_total_size(sizeof(u_int32_t)) /* ifindex */
1109a90c 415#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
df6fb868
PM
416 + nla_total_size(sizeof(u_int32_t)) /* ifindex */
417 + nla_total_size(sizeof(u_int32_t)) /* ifindex */
fbcd923c 418#endif
df6fb868 419 + nla_total_size(sizeof(u_int32_t)) /* mark */
8b541364 420 + nla_total_size(sizeof(u_int32_t)) /* priority */
df6fb868 421 + nla_total_size(sizeof(struct nfqnl_msg_packet_hw))
7237190d 422 + nla_total_size(sizeof(u_int32_t)) /* skbinfo */
28c1b6df
ES
423#if IS_ENABLED(CONFIG_CGROUP_NET_CLASSID)
424 + nla_total_size(sizeof(u_int32_t)) /* classid */
425#endif
ae08ce00
ED
426 + nla_total_size(sizeof(u_int32_t)); /* cap_len */
427
80fcec67
MKL
428 tstamp = skb_tstamp_cond(entskb, false);
429 if (tstamp)
ae08ce00 430 size += nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp));
7af4cc3f 431
15824ab2
SB
432 size += nfqnl_get_bridge_size(entry);
433
1d1de89b
DM
434 if (entry->state.hook <= NF_INET_FORWARD ||
435 (entry->state.hook == NF_INET_POST_ROUTING && entskb->sk == NULL))
496e4ae7
FW
436 csum_verify = !skb_csum_unnecessary(entskb);
437 else
438 csum_verify = false;
439
1d1de89b 440 outdev = entry->state.out;
3e4ead4f 441
14cd5d4a 442 switch ((enum nfqnl_config_mode)READ_ONCE(queue->copy_mode)) {
7af4cc3f
HW
443 case NFQNL_COPY_META:
444 case NFQNL_COPY_NONE:
7af4cc3f 445 break;
601e68e1 446
7af4cc3f 447 case NFQNL_COPY_PACKET:
00bd1cc2
FW
448 if (!(queue->flags & NFQA_CFG_F_GSO) &&
449 entskb->ip_summed == CHECKSUM_PARTIAL &&
c463ac97 450 skb_checksum_help(entskb))
e7dfb09a 451 return NULL;
c463ac97 452
14cd5d4a 453 data_len = READ_ONCE(queue->copy_range);
9cefbbc9 454 if (data_len > entskb->len)
3e4ead4f 455 data_len = entskb->len;
601e68e1 456
af2806f8
TG
457 hlen = skb_zerocopy_headlen(entskb);
458 hlen = min_t(unsigned int, hlen, data_len);
ae08ce00 459 size += sizeof(struct nlattr) + hlen;
6ee584be 460 cap_len = entskb->len;
7af4cc3f 461 break;
7af4cc3f
HW
462 }
463
8e662164
AB
464 nfnl_ct = rcu_dereference(nfnl_ct_hook);
465
83ace77f 466#if IS_ENABLED(CONFIG_NF_CONNTRACK)
b7bd1809 467 if (queue->flags & NFQA_CFG_F_CONNTRACK) {
a4b4766c 468 if (nfnl_ct != NULL) {
83ace77f 469 ct = nf_ct_get(entskb, &ctinfo);
b7bd1809 470 if (ct != NULL)
a4b4766c 471 size += nfnl_ct->build_size(ct);
b7bd1809
PNA
472 }
473 }
83ace77f 474#endif
7af4cc3f 475
08c0cad6 476 if (queue->flags & NFQA_CFG_F_UID_GID) {
7e59b3fe 477 size += (nla_total_size(sizeof(u_int32_t)) /* uid */
08c0cad6
VG
478 + nla_total_size(sizeof(u_int32_t))); /* gid */
479 }
480
ef493bd9
RK
481 if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) {
482 seclen = nfqnl_get_sk_secctx(entskb, &secdata);
483 if (seclen)
484 size += nla_total_size(seclen);
485 }
486
c5b0db32 487 skb = alloc_skb(size, GFP_ATOMIC);
36d5fe6a
ZK
488 if (!skb) {
489 skb_tx_error(entskb);
77c1c03c 490 goto nlmsg_failure;
36d5fe6a 491 }
601e68e1 492
19c28b13
PNA
493 nlh = nfnl_msg_put(skb, 0, 0,
494 nfnl_msg_type(NFNL_SUBSYS_QUEUE, NFQNL_MSG_PACKET),
495 0, entry->state.pf, NFNETLINK_V0,
496 htons(queue->queue_num));
3da07c0c 497 if (!nlh) {
36d5fe6a 498 skb_tx_error(entskb);
3da07c0c 499 kfree_skb(skb);
77c1c03c 500 goto nlmsg_failure;
3da07c0c 501 }
7af4cc3f 502
5863702a
ED
503 nla = __nla_reserve(skb, NFQA_PACKET_HDR, sizeof(*pmsg));
504 pmsg = nla_data(nla);
505 pmsg->hw_protocol = entskb->protocol;
1d1de89b 506 pmsg->hook = entry->state.hook;
5863702a 507 *packet_id_ptr = &pmsg->packet_id;
7af4cc3f 508
1d1de89b 509 indev = entry->state.in;
3e4ead4f 510 if (indev) {
1109a90c 511#if !IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
a447189e
DM
512 if (nla_put_be32(skb, NFQA_IFINDEX_INDEV, htonl(indev->ifindex)))
513 goto nla_put_failure;
fbcd923c 514#else
1d1de89b 515 if (entry->state.pf == PF_BRIDGE) {
fbcd923c 516 /* Case 1: indev is physical input device, we need to
601e68e1 517 * look for bridge group (when called from
fbcd923c 518 * netfilter_bridge) */
a447189e
DM
519 if (nla_put_be32(skb, NFQA_IFINDEX_PHYSINDEV,
520 htonl(indev->ifindex)) ||
fbcd923c 521 /* this is the bridge group "brX" */
f350a0a8 522 /* rcu_read_lock()ed by __nf_queue */
a447189e
DM
523 nla_put_be32(skb, NFQA_IFINDEX_INDEV,
524 htonl(br_port_get_rcu(indev)->br->dev->ifindex)))
525 goto nla_put_failure;
fbcd923c 526 } else {
c737b7c4
FW
527 int physinif;
528
fbcd923c
HW
529 /* Case 2: indev is bridge group, we need to look for
530 * physical device (when called from ipv4) */
a447189e
DM
531 if (nla_put_be32(skb, NFQA_IFINDEX_INDEV,
532 htonl(indev->ifindex)))
533 goto nla_put_failure;
c737b7c4
FW
534
535 physinif = nf_bridge_get_physinif(entskb);
536 if (physinif &&
a447189e 537 nla_put_be32(skb, NFQA_IFINDEX_PHYSINDEV,
c737b7c4 538 htonl(physinif)))
a447189e 539 goto nla_put_failure;
fbcd923c
HW
540 }
541#endif
7af4cc3f
HW
542 }
543
3e4ead4f 544 if (outdev) {
1109a90c 545#if !IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
a447189e
DM
546 if (nla_put_be32(skb, NFQA_IFINDEX_OUTDEV, htonl(outdev->ifindex)))
547 goto nla_put_failure;
fbcd923c 548#else
1d1de89b 549 if (entry->state.pf == PF_BRIDGE) {
fbcd923c 550 /* Case 1: outdev is physical output device, we need to
601e68e1 551 * look for bridge group (when called from
fbcd923c 552 * netfilter_bridge) */
a447189e
DM
553 if (nla_put_be32(skb, NFQA_IFINDEX_PHYSOUTDEV,
554 htonl(outdev->ifindex)) ||
fbcd923c 555 /* this is the bridge group "brX" */
f350a0a8 556 /* rcu_read_lock()ed by __nf_queue */
a447189e
DM
557 nla_put_be32(skb, NFQA_IFINDEX_OUTDEV,
558 htonl(br_port_get_rcu(outdev)->br->dev->ifindex)))
559 goto nla_put_failure;
fbcd923c 560 } else {
c737b7c4
FW
561 int physoutif;
562
fbcd923c
HW
563 /* Case 2: outdev is bridge group, we need to look for
564 * physical output device (when called from ipv4) */
a447189e
DM
565 if (nla_put_be32(skb, NFQA_IFINDEX_OUTDEV,
566 htonl(outdev->ifindex)))
567 goto nla_put_failure;
c737b7c4
FW
568
569 physoutif = nf_bridge_get_physoutif(entskb);
570 if (physoutif &&
a447189e 571 nla_put_be32(skb, NFQA_IFINDEX_PHYSOUTDEV,
c737b7c4 572 htonl(physoutif)))
a447189e 573 goto nla_put_failure;
fbcd923c
HW
574 }
575#endif
7af4cc3f
HW
576 }
577
a447189e
DM
578 if (entskb->mark &&
579 nla_put_be32(skb, NFQA_MARK, htonl(entskb->mark)))
580 goto nla_put_failure;
7af4cc3f 581
8b541364
ND
582 if (entskb->priority &&
583 nla_put_be32(skb, NFQA_PRIORITY, htonl(entskb->priority)))
584 goto nla_put_failure;
585
2c38de4c 586 if (indev && entskb->dev &&
ebb966d3
IG
587 skb_mac_header_was_set(entskb) &&
588 skb_mac_header_len(entskb) != 0) {
7af4cc3f 589 struct nfqnl_msg_packet_hw phw;
e4d091d7
DC
590 int len;
591
592 memset(&phw, 0, sizeof(phw));
593 len = dev_parse_header(entskb, phw.hw_addr);
b95cce35
SH
594 if (len) {
595 phw.hw_addrlen = htons(len);
a447189e
DM
596 if (nla_put(skb, NFQA_HWADDR, sizeof(phw), &phw))
597 goto nla_put_failure;
b95cce35 598 }
7af4cc3f
HW
599 }
600
15824ab2
SB
601 if (nfqnl_put_bridge(entry, skb) < 0)
602 goto nla_put_failure;
603
80fcec67 604 if (entry->state.hook <= NF_INET_FORWARD && tstamp) {
7af4cc3f 605 struct nfqnl_msg_packet_timestamp ts;
80fcec67 606 struct timespec64 kts = ktime_to_timespec64(tstamp);
b28b1e82
PNA
607
608 ts.sec = cpu_to_be64(kts.tv_sec);
609 ts.usec = cpu_to_be64(kts.tv_nsec / NSEC_PER_USEC);
7af4cc3f 610
a447189e
DM
611 if (nla_put(skb, NFQA_TIMESTAMP, sizeof(ts), &ts))
612 goto nla_put_failure;
7af4cc3f
HW
613 }
614
08c0cad6
VG
615 if ((queue->flags & NFQA_CFG_F_UID_GID) && entskb->sk &&
616 nfqnl_put_sk_uidgid(skb, entskb->sk) < 0)
617 goto nla_put_failure;
618
28c1b6df
ES
619 if (nfqnl_put_sk_classid(skb, entskb->sk) < 0)
620 goto nla_put_failure;
621
ef493bd9
RK
622 if (seclen && nla_put(skb, NFQA_SECCTX, seclen, secdata))
623 goto nla_put_failure;
624
a4b4766c 625 if (ct && nfnl_ct->build(skb, ct, ctinfo, NFQA_CT, NFQA_CT_INFO) < 0)
ae08ce00
ED
626 goto nla_put_failure;
627
7f87712c
FW
628 if (cap_len > data_len &&
629 nla_put_be32(skb, NFQA_CAP_LEN, htonl(cap_len)))
ae08ce00
ED
630 goto nla_put_failure;
631
496e4ae7 632 if (nfqnl_put_packet_info(skb, entskb, csum_verify))
7237190d
FW
633 goto nla_put_failure;
634
7af4cc3f 635 if (data_len) {
df6fb868 636 struct nlattr *nla;
7af4cc3f 637
ae08ce00
ED
638 if (skb_tailroom(skb) < sizeof(*nla) + hlen)
639 goto nla_put_failure;
7af4cc3f 640
4df864c1 641 nla = skb_put(skb, sizeof(*nla));
df6fb868 642 nla->nla_type = NFQA_PAYLOAD;
ae08ce00 643 nla->nla_len = nla_attr_size(data_len);
7af4cc3f 644
36d5fe6a
ZK
645 if (skb_zerocopy(skb, entskb, data_len, hlen))
646 goto nla_put_failure;
7af4cc3f 647 }
601e68e1 648
ae08ce00 649 nlh->nlmsg_len = skb->len;
77c1c03c
LZ
650 if (seclen)
651 security_release_secctx(secdata, seclen);
7af4cc3f
HW
652 return skb;
653
df6fb868 654nla_put_failure:
36d5fe6a 655 skb_tx_error(entskb);
a6729955 656 kfree_skb(skb);
e87cc472 657 net_err_ratelimited("nf_queue: error creating packet message\n");
77c1c03c
LZ
658nlmsg_failure:
659 if (seclen)
660 security_release_secctx(secdata, seclen);
7af4cc3f
HW
661 return NULL;
662}
663
5da773a3
FW
664static bool nf_ct_drop_unconfirmed(const struct nf_queue_entry *entry)
665{
666#if IS_ENABLED(CONFIG_NF_CONNTRACK)
667 static const unsigned long flags = IPS_CONFIRMED | IPS_DYING;
668 const struct nf_conn *ct = (void *)skb_nfct(entry->skb);
669
670 if (ct && ((ct->status & flags) == IPS_DYING))
671 return true;
672#endif
673 return false;
674}
675
7af4cc3f 676static int
a5fedd43
FW
677__nfqnl_enqueue_packet(struct net *net, struct nfqnl_instance *queue,
678 struct nf_queue_entry *entry)
7af4cc3f 679{
7af4cc3f 680 struct sk_buff *nskb;
f1585086 681 int err = -ENOBUFS;
5863702a 682 __be32 *packet_id_ptr;
fdb694a0 683 int failopen = 0;
7af4cc3f 684
74332687 685 nskb = nfqnl_build_packet_message(net, queue, entry, &packet_id_ptr);
f1585086
FW
686 if (nskb == NULL) {
687 err = -ENOMEM;
0ef0f465 688 goto err_out;
f1585086 689 }
7af4cc3f 690 spin_lock_bh(&queue->lock);
601e68e1 691
5da773a3
FW
692 if (nf_ct_drop_unconfirmed(entry))
693 goto err_out_free_nskb;
694
7af4cc3f 695 if (queue->queue_total >= queue->queue_maxlen) {
fdb694a0
KK
696 if (queue->flags & NFQA_CFG_F_FAIL_OPEN) {
697 failopen = 1;
698 err = 0;
699 } else {
700 queue->queue_dropped++;
701 net_warn_ratelimited("nf_queue: full at %d entries, dropping packets(s)\n",
702 queue->queue_total);
703 }
7af4cc3f
HW
704 goto err_out_free_nskb;
705 }
5863702a
ED
706 entry->id = ++queue->id_sequence;
707 *packet_id_ptr = htonl(entry->id);
7af4cc3f
HW
708
709 /* nfnetlink_unicast will either free the nskb or add it to a socket */
ee921183 710 err = nfnetlink_unicast(nskb, net, queue->peer_portid);
0ef0f465 711 if (err < 0) {
93140113
PNA
712 if (queue->flags & NFQA_CFG_F_FAIL_OPEN) {
713 failopen = 1;
714 err = 0;
715 } else {
716 queue->queue_user_dropped++;
717 }
7af4cc3f
HW
718 goto err_out_unlock;
719 }
720
721 __enqueue_entry(queue, entry);
722
723 spin_unlock_bh(&queue->lock);
0ef0f465 724 return 0;
7af4cc3f
HW
725
726err_out_free_nskb:
601e68e1 727 kfree_skb(nskb);
7af4cc3f
HW
728err_out_unlock:
729 spin_unlock_bh(&queue->lock);
fdb694a0 730 if (failopen)
368982cd 731 nfqnl_reinject(entry, NF_ACCEPT);
0ef0f465 732err_out:
f1585086 733 return err;
7af4cc3f
HW
734}
735
a5fedd43
FW
736static struct nf_queue_entry *
737nf_queue_entry_dup(struct nf_queue_entry *e)
738{
739 struct nf_queue_entry *entry = kmemdup(e, e->size, GFP_ATOMIC);
c3873070
FW
740
741 if (!entry)
742 return NULL;
743
744 if (nf_queue_entry_get_refs(entry))
745 return entry;
746
747 kfree(entry);
748 return NULL;
a5fedd43
FW
749}
750
1109a90c 751#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
a5fedd43
FW
752/* When called from bridge netfilter, skb->data must point to MAC header
753 * before calling skb_gso_segment(). Else, original MAC header is lost
754 * and segmented skbs will be sent to wrong destination.
755 */
756static void nf_bridge_adjust_skb_data(struct sk_buff *skb)
757{
c4b0e771 758 if (nf_bridge_info_get(skb))
a5fedd43
FW
759 __skb_push(skb, skb->network_header - skb->mac_header);
760}
761
762static void nf_bridge_adjust_segmented_data(struct sk_buff *skb)
763{
c4b0e771 764 if (nf_bridge_info_get(skb))
a5fedd43
FW
765 __skb_pull(skb, skb->network_header - skb->mac_header);
766}
767#else
768#define nf_bridge_adjust_skb_data(s) do {} while (0)
769#define nf_bridge_adjust_segmented_data(s) do {} while (0)
770#endif
771
a5fedd43
FW
772static int
773__nfqnl_enqueue_packet_gso(struct net *net, struct nfqnl_instance *queue,
774 struct sk_buff *skb, struct nf_queue_entry *entry)
775{
776 int ret = -ENOMEM;
777 struct nf_queue_entry *entry_seg;
778
779 nf_bridge_adjust_segmented_data(skb);
780
781 if (skb->next == NULL) { /* last packet, no need to copy entry */
782 struct sk_buff *gso_skb = entry->skb;
783 entry->skb = skb;
784 ret = __nfqnl_enqueue_packet(net, queue, entry);
785 if (ret)
786 entry->skb = gso_skb;
787 return ret;
788 }
789
a8305bff 790 skb_mark_not_on_list(skb);
a5fedd43
FW
791
792 entry_seg = nf_queue_entry_dup(entry);
793 if (entry_seg) {
794 entry_seg->skb = skb;
795 ret = __nfqnl_enqueue_packet(net, queue, entry_seg);
796 if (ret)
dd3cc111 797 nf_queue_entry_free(entry_seg);
a5fedd43
FW
798 }
799 return ret;
800}
801
802static int
803nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
804{
805 unsigned int queued;
806 struct nfqnl_instance *queue;
2670ee77 807 struct sk_buff *skb, *segs, *nskb;
a5fedd43 808 int err = -ENOBUFS;
9dff2c96 809 struct net *net = entry->state.net;
a5fedd43
FW
810 struct nfnl_queue_net *q = nfnl_queue_pernet(net);
811
e2361cb9 812 /* rcu_read_lock()ed by nf_hook_thresh */
a5fedd43
FW
813 queue = instance_lookup(q, queuenum);
814 if (!queue)
815 return -ESRCH;
816
817 if (queue->copy_mode == NFQNL_COPY_NONE)
818 return -EINVAL;
819
a5fedd43
FW
820 skb = entry->skb;
821
1d1de89b 822 switch (entry->state.pf) {
a5fedd43
FW
823 case NFPROTO_IPV4:
824 skb->protocol = htons(ETH_P_IP);
825 break;
826 case NFPROTO_IPV6:
827 skb->protocol = htons(ETH_P_IPV6);
828 break;
829 }
830
7b8dfe28
PNA
831 if ((queue->flags & NFQA_CFG_F_GSO) || !skb_is_gso(skb))
832 return __nfqnl_enqueue_packet(net, queue, entry);
833
a5fedd43
FW
834 nf_bridge_adjust_skb_data(skb);
835 segs = skb_gso_segment(skb, 0);
836 /* Does not use PTR_ERR to limit the number of error codes that can be
ed78d09d 837 * returned by nf_queue. For instance, callers rely on -ESRCH to
a5fedd43
FW
838 * mean 'ignore this hook'.
839 */
330966e5 840 if (IS_ERR_OR_NULL(segs))
a5fedd43
FW
841 goto out_err;
842 queued = 0;
843 err = 0;
2670ee77 844 skb_list_walk_safe(segs, segs, nskb) {
a5fedd43
FW
845 if (err == 0)
846 err = __nfqnl_enqueue_packet_gso(net, queue,
847 segs, entry);
848 if (err == 0)
849 queued++;
850 else
851 kfree_skb(segs);
2670ee77 852 }
a5fedd43
FW
853
854 if (queued) {
855 if (err) /* some segments are already queued */
dd3cc111 856 nf_queue_entry_free(entry);
a5fedd43
FW
857 kfree_skb(skb);
858 return 0;
859 }
860 out_err:
861 nf_bridge_adjust_segmented_data(skb);
862 return err;
863}
864
7af4cc3f 865static int
99a63d36 866nfqnl_mangle(void *data, unsigned int data_len, struct nf_queue_entry *e, int diff)
7af4cc3f 867{
e2b58a67 868 struct sk_buff *nskb;
7af4cc3f 869
d8a585d7 870 if (diff < 0) {
99a63d36
FW
871 unsigned int min_len = skb_transport_offset(e->skb);
872
873 if (data_len < min_len)
874 return -EINVAL;
875
d8a585d7
PM
876 if (pskb_trim(e->skb, data_len))
877 return -ENOMEM;
878 } else if (diff > 0) {
7af4cc3f
HW
879 if (data_len > 0xFFFF)
880 return -EINVAL;
881 if (diff > skb_tailroom(e->skb)) {
9a732ed6
AE
882 nskb = skb_copy_expand(e->skb, skb_headroom(e->skb),
883 diff, GFP_ATOMIC);
5191d70f 884 if (!nskb)
e2b58a67 885 return -ENOMEM;
e2b58a67
PM
886 kfree_skb(e->skb);
887 e->skb = nskb;
7af4cc3f
HW
888 }
889 skb_put(e->skb, diff);
890 }
2cf6bffc 891 if (skb_ensure_writable(e->skb, data_len))
7af4cc3f 892 return -ENOMEM;
27d7ff46 893 skb_copy_to_linear_data(e->skb, data, data_len);
e7dfb09a 894 e->skb->ip_summed = CHECKSUM_NONE;
7af4cc3f
HW
895 return 0;
896}
897
7af4cc3f
HW
898static int
899nfqnl_set_mode(struct nfqnl_instance *queue,
900 unsigned char mode, unsigned int range)
901{
c5de0dfd 902 int status = 0;
7af4cc3f
HW
903
904 spin_lock_bh(&queue->lock);
c5de0dfd
PM
905 switch (mode) {
906 case NFQNL_COPY_NONE:
907 case NFQNL_COPY_META:
908 queue->copy_mode = mode;
909 queue->copy_range = 0;
910 break;
911
912 case NFQNL_COPY_PACKET:
913 queue->copy_mode = mode;
9cefbbc9
FW
914 if (range == 0 || range > NFQNL_MAX_COPY_RANGE)
915 queue->copy_range = NFQNL_MAX_COPY_RANGE;
c5de0dfd
PM
916 else
917 queue->copy_range = range;
918 break;
919
920 default:
921 status = -EINVAL;
922
923 }
7af4cc3f
HW
924 spin_unlock_bh(&queue->lock);
925
926 return status;
927}
928
929static int
02f014d8 930dev_cmp(struct nf_queue_entry *entry, unsigned long ifindex)
7af4cc3f 931{
c4b0e771
FW
932#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
933 int physinif, physoutif;
934
935 physinif = nf_bridge_get_physinif(entry->skb);
936 physoutif = nf_bridge_get_physoutif(entry->skb);
937
938 if (physinif == ifindex || physoutif == ifindex)
939 return 1;
940#endif
1d1de89b
DM
941 if (entry->state.in)
942 if (entry->state.in->ifindex == ifindex)
7af4cc3f 943 return 1;
1d1de89b
DM
944 if (entry->state.out)
945 if (entry->state.out->ifindex == ifindex)
7af4cc3f 946 return 1;
c737b7c4 947
7af4cc3f
HW
948 return 0;
949}
950
951/* drop all packets with either indev or outdev == ifindex from all queue
952 * instances */
953static void
e8179610 954nfqnl_dev_drop(struct net *net, int ifindex)
7af4cc3f
HW
955{
956 int i;
e8179610 957 struct nfnl_queue_net *q = nfnl_queue_pernet(net);
601e68e1 958
9872bec7 959 rcu_read_lock();
7af4cc3f 960
9872bec7 961 for (i = 0; i < INSTANCE_BUCKETS; i++) {
7af4cc3f 962 struct nfqnl_instance *inst;
e8179610 963 struct hlist_head *head = &q->instance_table[i];
7af4cc3f 964
b67bfe0d 965 hlist_for_each_entry_rcu(inst, head, hlist)
b43d8d85 966 nfqnl_flush(inst, dev_cmp, ifindex);
7af4cc3f
HW
967 }
968
9872bec7 969 rcu_read_unlock();
7af4cc3f
HW
970}
971
7af4cc3f
HW
972static int
973nfqnl_rcv_dev_event(struct notifier_block *this,
974 unsigned long event, void *ptr)
975{
351638e7 976 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
7af4cc3f
HW
977
978 /* Drop any packets associated with the downed device */
979 if (event == NETDEV_DOWN)
e8179610 980 nfqnl_dev_drop(dev_net(dev), dev->ifindex);
7af4cc3f
HW
981 return NOTIFY_DONE;
982}
983
984static struct notifier_block nfqnl_dev_notifier = {
985 .notifier_call = nfqnl_rcv_dev_event,
986};
987
26888dfd 988static void nfqnl_nf_hook_drop(struct net *net)
8405a8ff
EB
989{
990 struct nfnl_queue_net *q = nfnl_queue_pernet(net);
991 int i;
992
87029970
FW
993 /* This function is also called on net namespace error unwind,
994 * when pernet_ops->init() failed and ->exit() functions of the
995 * previous pernet_ops gets called.
996 *
997 * This may result in a call to nfqnl_nf_hook_drop() before
998 * struct nfnl_queue_net was allocated.
999 */
1000 if (!q)
1001 return;
1002
8405a8ff
EB
1003 for (i = 0; i < INSTANCE_BUCKETS; i++) {
1004 struct nfqnl_instance *inst;
1005 struct hlist_head *head = &q->instance_table[i];
1006
26888dfd 1007 hlist_for_each_entry_rcu(inst, head, hlist)
039b40ee 1008 nfqnl_flush(inst, NULL, 0);
8405a8ff 1009 }
8405a8ff
EB
1010}
1011
7af4cc3f
HW
1012static int
1013nfqnl_rcv_nl_event(struct notifier_block *this,
1014 unsigned long event, void *ptr)
1015{
1016 struct netlink_notify *n = ptr;
e8179610 1017 struct nfnl_queue_net *q = nfnl_queue_pernet(n->net);
7af4cc3f 1018
dee5817e 1019 if (event == NETLINK_URELEASE && n->protocol == NETLINK_NETFILTER) {
7af4cc3f
HW
1020 int i;
1021
15e47304 1022 /* destroy all instances for this portid */
e8179610 1023 spin_lock(&q->instances_lock);
9872bec7 1024 for (i = 0; i < INSTANCE_BUCKETS; i++) {
b67bfe0d 1025 struct hlist_node *t2;
7af4cc3f 1026 struct nfqnl_instance *inst;
e8179610 1027 struct hlist_head *head = &q->instance_table[i];
7af4cc3f 1028
b67bfe0d 1029 hlist_for_each_entry_safe(inst, t2, head, hlist) {
e8179610 1030 if (n->portid == inst->peer_portid)
7af4cc3f
HW
1031 __instance_destroy(inst);
1032 }
1033 }
e8179610 1034 spin_unlock(&q->instances_lock);
7af4cc3f
HW
1035 }
1036 return NOTIFY_DONE;
1037}
1038
1039static struct notifier_block nfqnl_rtnl_notifier = {
1040 .notifier_call = nfqnl_rcv_nl_event,
1041};
1042
8d45ff22
SB
1043static const struct nla_policy nfqa_vlan_policy[NFQA_VLAN_MAX + 1] = {
1044 [NFQA_VLAN_TCI] = { .type = NLA_U16},
1045 [NFQA_VLAN_PROTO] = { .type = NLA_U16},
1046};
1047
5bf75853
PM
1048static const struct nla_policy nfqa_verdict_policy[NFQA_MAX+1] = {
1049 [NFQA_VERDICT_HDR] = { .len = sizeof(struct nfqnl_msg_verdict_hdr) },
1050 [NFQA_MARK] = { .type = NLA_U32 },
1051 [NFQA_PAYLOAD] = { .type = NLA_UNSPEC },
9cb01766 1052 [NFQA_CT] = { .type = NLA_UNSPEC },
bd077937 1053 [NFQA_EXP] = { .type = NLA_UNSPEC },
8d45ff22 1054 [NFQA_VLAN] = { .type = NLA_NESTED },
98eee88b 1055 [NFQA_PRIORITY] = { .type = NLA_U32 },
838ab636
HW
1056};
1057
97d32cf9
FW
1058static const struct nla_policy nfqa_verdict_batch_policy[NFQA_MAX+1] = {
1059 [NFQA_VERDICT_HDR] = { .len = sizeof(struct nfqnl_msg_verdict_hdr) },
1060 [NFQA_MARK] = { .type = NLA_U32 },
98eee88b 1061 [NFQA_PRIORITY] = { .type = NLA_U32 },
97d32cf9
FW
1062};
1063
e8179610 1064static struct nfqnl_instance *
cc6bc448 1065verdict_instance_lookup(struct nfnl_queue_net *q, u16 queue_num, u32 nlportid)
97d32cf9
FW
1066{
1067 struct nfqnl_instance *queue;
1068
e8179610 1069 queue = instance_lookup(q, queue_num);
97d32cf9
FW
1070 if (!queue)
1071 return ERR_PTR(-ENODEV);
1072
15e47304 1073 if (queue->peer_portid != nlportid)
97d32cf9
FW
1074 return ERR_PTR(-EPERM);
1075
1076 return queue;
1077}
1078
1079static struct nfqnl_msg_verdict_hdr*
1080verdicthdr_get(const struct nlattr * const nfqa[])
1081{
1082 struct nfqnl_msg_verdict_hdr *vhdr;
1083 unsigned int verdict;
1084
1085 if (!nfqa[NFQA_VERDICT_HDR])
1086 return NULL;
1087
1088 vhdr = nla_data(nfqa[NFQA_VERDICT_HDR]);
c6675233
FW
1089 verdict = ntohl(vhdr->verdict) & NF_VERDICT_MASK;
1090 if (verdict > NF_MAX_VERDICT || verdict == NF_STOLEN)
97d32cf9
FW
1091 return NULL;
1092 return vhdr;
1093}
1094
1095static int nfq_id_after(unsigned int id, unsigned int max)
1096{
1097 return (int)(id - max) > 0;
1098}
1099
797d4980
PNA
1100static int nfqnl_recv_verdict_batch(struct sk_buff *skb,
1101 const struct nfnl_info *info,
1102 const struct nlattr * const nfqa[])
97d32cf9 1103{
797d4980 1104 struct nfnl_queue_net *q = nfnl_queue_pernet(info->net);
ef4b65e5 1105 u16 queue_num = ntohs(info->nfmsg->res_id);
97d32cf9 1106 struct nf_queue_entry *entry, *tmp;
97d32cf9
FW
1107 struct nfqnl_msg_verdict_hdr *vhdr;
1108 struct nfqnl_instance *queue;
797d4980 1109 unsigned int verdict, maxid;
97d32cf9 1110 LIST_HEAD(batch_list);
e8179610
G
1111
1112 queue = verdict_instance_lookup(q, queue_num,
1113 NETLINK_CB(skb).portid);
97d32cf9
FW
1114 if (IS_ERR(queue))
1115 return PTR_ERR(queue);
1116
1117 vhdr = verdicthdr_get(nfqa);
1118 if (!vhdr)
1119 return -EINVAL;
1120
1121 verdict = ntohl(vhdr->verdict);
1122 maxid = ntohl(vhdr->id);
1123
1124 spin_lock_bh(&queue->lock);
1125
1126 list_for_each_entry_safe(entry, tmp, &queue->queue_list, list) {
1127 if (nfq_id_after(entry->id, maxid))
1128 break;
1129 __dequeue_entry(queue, entry);
1130 list_add_tail(&entry->list, &batch_list);
1131 }
1132
1133 spin_unlock_bh(&queue->lock);
1134
1135 if (list_empty(&batch_list))
1136 return -ENOENT;
1137
1138 list_for_each_entry_safe(entry, tmp, &batch_list, list) {
1139 if (nfqa[NFQA_MARK])
1140 entry->skb->mark = ntohl(nla_get_be32(nfqa[NFQA_MARK]));
368982cd 1141
98eee88b
ND
1142 if (nfqa[NFQA_PRIORITY])
1143 entry->skb->priority = ntohl(nla_get_be32(nfqa[NFQA_PRIORITY]));
1144
368982cd 1145 nfqnl_reinject(entry, verdict);
97d32cf9
FW
1146 }
1147 return 0;
1148}
1149
285c8a7a 1150static struct nf_conn *nfqnl_ct_parse(const struct nfnl_ct_hook *nfnl_ct,
b7bd1809
PNA
1151 const struct nlmsghdr *nlh,
1152 const struct nlattr * const nfqa[],
1153 struct nf_queue_entry *entry,
1154 enum ip_conntrack_info *ctinfo)
1155{
83ace77f 1156#if IS_ENABLED(CONFIG_NF_CONNTRACK)
b7bd1809
PNA
1157 struct nf_conn *ct;
1158
83ace77f 1159 ct = nf_ct_get(entry->skb, ctinfo);
b7bd1809
PNA
1160 if (ct == NULL)
1161 return NULL;
1162
a4b4766c 1163 if (nfnl_ct->parse(nfqa[NFQA_CT], ct) < 0)
b7bd1809
PNA
1164 return NULL;
1165
1166 if (nfqa[NFQA_EXP])
a4b4766c 1167 nfnl_ct->attach_expect(nfqa[NFQA_EXP], ct,
b7bd1809
PNA
1168 NETLINK_CB(entry->skb).portid,
1169 nlmsg_report(nlh));
1170 return ct;
83ace77f
FW
1171#else
1172 return NULL;
1173#endif
b7bd1809
PNA
1174}
1175
8d45ff22
SB
1176static int nfqa_parse_bridge(struct nf_queue_entry *entry,
1177 const struct nlattr * const nfqa[])
1178{
1179 if (nfqa[NFQA_VLAN]) {
1180 struct nlattr *tb[NFQA_VLAN_MAX + 1];
1181 int err;
1182
8cb08174
JB
1183 err = nla_parse_nested_deprecated(tb, NFQA_VLAN_MAX,
1184 nfqa[NFQA_VLAN],
1185 nfqa_vlan_policy, NULL);
8d45ff22
SB
1186 if (err < 0)
1187 return err;
1188
1189 if (!tb[NFQA_VLAN_TCI] || !tb[NFQA_VLAN_PROTO])
1190 return -EINVAL;
1191
82eea4cf
MM
1192 __vlan_hwaccel_put_tag(entry->skb,
1193 nla_get_be16(tb[NFQA_VLAN_PROTO]),
1194 ntohs(nla_get_be16(tb[NFQA_VLAN_TCI])));
8d45ff22
SB
1195 }
1196
1197 if (nfqa[NFQA_L2HDR]) {
1198 int mac_header_len = entry->skb->network_header -
1199 entry->skb->mac_header;
1200
1201 if (mac_header_len != nla_len(nfqa[NFQA_L2HDR]))
1202 return -EINVAL;
1203 else if (mac_header_len > 0)
1204 memcpy(skb_mac_header(entry->skb),
1205 nla_data(nfqa[NFQA_L2HDR]),
1206 mac_header_len);
1207 }
1208
1209 return 0;
1210}
1211
797d4980
PNA
1212static int nfqnl_recv_verdict(struct sk_buff *skb, const struct nfnl_info *info,
1213 const struct nlattr * const nfqa[])
7af4cc3f 1214{
797d4980 1215 struct nfnl_queue_net *q = nfnl_queue_pernet(info->net);
ef4b65e5 1216 u_int16_t queue_num = ntohs(info->nfmsg->res_id);
285c8a7a 1217 const struct nfnl_ct_hook *nfnl_ct;
7af4cc3f 1218 struct nfqnl_msg_verdict_hdr *vhdr;
797d4980 1219 enum ip_conntrack_info ctinfo;
7af4cc3f 1220 struct nfqnl_instance *queue;
02f014d8 1221 struct nf_queue_entry *entry;
8c88f87c 1222 struct nf_conn *ct = NULL;
797d4980 1223 unsigned int verdict;
8d45ff22 1224 int err;
7af4cc3f 1225
00a3101f
LZ
1226 queue = verdict_instance_lookup(q, queue_num,
1227 NETLINK_CB(skb).portid);
97d32cf9
FW
1228 if (IS_ERR(queue))
1229 return PTR_ERR(queue);
7af4cc3f 1230
97d32cf9
FW
1231 vhdr = verdicthdr_get(nfqa);
1232 if (!vhdr)
84a797dd 1233 return -EINVAL;
7af4cc3f 1234
7af4cc3f
HW
1235 verdict = ntohl(vhdr->verdict);
1236
b43d8d85 1237 entry = find_dequeue_entry(queue, ntohl(vhdr->id));
84a797dd
ED
1238 if (entry == NULL)
1239 return -ENOENT;
7af4cc3f 1240
8e662164
AB
1241 /* rcu lock already held from nfnl->call_rcu. */
1242 nfnl_ct = rcu_dereference(nfnl_ct_hook);
1243
bd077937 1244 if (nfqa[NFQA_CT]) {
a4b4766c 1245 if (nfnl_ct != NULL)
797d4980
PNA
1246 ct = nfqnl_ct_parse(nfnl_ct, info->nlh, nfqa, entry,
1247 &ctinfo);
bd077937 1248 }
9cb01766 1249
8d45ff22
SB
1250 if (entry->state.pf == PF_BRIDGE) {
1251 err = nfqa_parse_bridge(entry, nfqa);
1252 if (err < 0)
1253 return err;
1254 }
1255
df6fb868 1256 if (nfqa[NFQA_PAYLOAD]) {
8c88f87c
PNA
1257 u16 payload_len = nla_len(nfqa[NFQA_PAYLOAD]);
1258 int diff = payload_len - entry->skb->len;
1259
df6fb868 1260 if (nfqnl_mangle(nla_data(nfqa[NFQA_PAYLOAD]),
8c88f87c 1261 payload_len, entry, diff) < 0)
7af4cc3f 1262 verdict = NF_DROP;
8c88f87c 1263
b7bd1809 1264 if (ct && diff)
a4b4766c 1265 nfnl_ct->seq_adjust(entry->skb, ct, ctinfo, diff);
7af4cc3f
HW
1266 }
1267
df6fb868 1268 if (nfqa[NFQA_MARK])
ea3a66ff 1269 entry->skb->mark = ntohl(nla_get_be32(nfqa[NFQA_MARK]));
601e68e1 1270
98eee88b
ND
1271 if (nfqa[NFQA_PRIORITY])
1272 entry->skb->priority = ntohl(nla_get_be32(nfqa[NFQA_PRIORITY]));
1273
368982cd 1274 nfqnl_reinject(entry, verdict);
7af4cc3f
HW
1275 return 0;
1276}
1277
797d4980
PNA
1278static int nfqnl_recv_unsupp(struct sk_buff *skb, const struct nfnl_info *info,
1279 const struct nlattr * const cda[])
7af4cc3f
HW
1280{
1281 return -ENOTSUPP;
1282}
1283
5bf75853
PM
1284static const struct nla_policy nfqa_cfg_policy[NFQA_CFG_MAX+1] = {
1285 [NFQA_CFG_CMD] = { .len = sizeof(struct nfqnl_msg_config_cmd) },
1286 [NFQA_CFG_PARAMS] = { .len = sizeof(struct nfqnl_msg_config_params) },
ba062ebb
ED
1287 [NFQA_CFG_QUEUE_MAXLEN] = { .type = NLA_U32 },
1288 [NFQA_CFG_MASK] = { .type = NLA_U32 },
1289 [NFQA_CFG_FLAGS] = { .type = NLA_U32 },
838ab636
HW
1290};
1291
e3ac5298 1292static const struct nf_queue_handler nfqh = {
d4ef3835
AS
1293 .outfn = nfqnl_enqueue_packet,
1294 .nf_hook_drop = nfqnl_nf_hook_drop,
bbd86b9f
HW
1295};
1296
a6555365
PNA
1297static int nfqnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,
1298 const struct nlattr * const nfqa[])
7af4cc3f 1299{
a6555365 1300 struct nfnl_queue_net *q = nfnl_queue_pernet(info->net);
ef4b65e5 1301 u_int16_t queue_num = ntohs(info->nfmsg->res_id);
9872bec7 1302 struct nfqnl_msg_config_cmd *cmd = NULL;
a6555365 1303 struct nfqnl_instance *queue;
60d2c7f9 1304 __u32 flags = 0, mask = 0;
838ab636 1305 int ret = 0;
7af4cc3f 1306
9872bec7
PM
1307 if (nfqa[NFQA_CFG_CMD]) {
1308 cmd = nla_data(nfqa[NFQA_CFG_CMD]);
1309
0360ae41 1310 /* Obsolete commands without queue context */
9872bec7 1311 switch (cmd->command) {
0360ae41
FW
1312 case NFQNL_CFG_CMD_PF_BIND: return 0;
1313 case NFQNL_CFG_CMD_PF_UNBIND: return 0;
9872bec7 1314 }
9872bec7
PM
1315 }
1316
60d2c7f9
KM
1317 /* Check if we support these flags in first place, dependencies should
1318 * be there too not to break atomicity.
1319 */
1320 if (nfqa[NFQA_CFG_FLAGS]) {
1321 if (!nfqa[NFQA_CFG_MASK]) {
1322 /* A mask is needed to specify which flags are being
1323 * changed.
1324 */
1325 return -EINVAL;
1326 }
1327
1328 flags = ntohl(nla_get_be32(nfqa[NFQA_CFG_FLAGS]));
1329 mask = ntohl(nla_get_be32(nfqa[NFQA_CFG_MASK]));
1330
1331 if (flags >= NFQA_CFG_F_MAX)
1332 return -EOPNOTSUPP;
1333
1334#if !IS_ENABLED(CONFIG_NETWORK_SECMARK)
1335 if (flags & mask & NFQA_CFG_F_SECCTX)
1336 return -EOPNOTSUPP;
1337#endif
71b2e5f5
KM
1338 if ((flags & mask & NFQA_CFG_F_CONNTRACK) &&
1339 !rcu_access_pointer(nfnl_ct_hook)) {
1340#ifdef CONFIG_MODULES
1341 nfnl_unlock(NFNL_SUBSYS_QUEUE);
1342 request_module("ip_conntrack_netlink");
1343 nfnl_lock(NFNL_SUBSYS_QUEUE);
1344 if (rcu_access_pointer(nfnl_ct_hook))
1345 return -EAGAIN;
1346#endif
1347 return -EOPNOTSUPP;
1348 }
60d2c7f9
KM
1349 }
1350
9872bec7 1351 rcu_read_lock();
e8179610 1352 queue = instance_lookup(q, queue_num);
15e47304 1353 if (queue && queue->peer_portid != NETLINK_CB(skb).portid) {
a3c8e7fd 1354 ret = -EPERM;
9872bec7 1355 goto err_out_unlock;
a3c8e7fd
PM
1356 }
1357
9872bec7 1358 if (cmd != NULL) {
7af4cc3f
HW
1359 switch (cmd->command) {
1360 case NFQNL_CFG_CMD_BIND:
9872bec7
PM
1361 if (queue) {
1362 ret = -EBUSY;
1363 goto err_out_unlock;
1364 }
e8179610
G
1365 queue = instance_create(q, queue_num,
1366 NETLINK_CB(skb).portid);
baab2ce7
PM
1367 if (IS_ERR(queue)) {
1368 ret = PTR_ERR(queue);
9872bec7
PM
1369 goto err_out_unlock;
1370 }
7af4cc3f
HW
1371 break;
1372 case NFQNL_CFG_CMD_UNBIND:
9872bec7
PM
1373 if (!queue) {
1374 ret = -ENODEV;
1375 goto err_out_unlock;
1376 }
e8179610 1377 instance_destroy(q, queue);
17bc6b48 1378 goto err_out_unlock;
7af4cc3f 1379 case NFQNL_CFG_CMD_PF_BIND:
7af4cc3f 1380 case NFQNL_CFG_CMD_PF_UNBIND:
7af4cc3f
HW
1381 break;
1382 default:
cd21f0ac 1383 ret = -ENOTSUPP;
21c3c971 1384 goto err_out_unlock;
7af4cc3f 1385 }
7af4cc3f
HW
1386 }
1387
60d2c7f9
KM
1388 if (!queue) {
1389 ret = -ENODEV;
1390 goto err_out_unlock;
1391 }
1392
df6fb868 1393 if (nfqa[NFQA_CFG_PARAMS]) {
60d2c7f9
KM
1394 struct nfqnl_msg_config_params *params =
1395 nla_data(nfqa[NFQA_CFG_PARAMS]);
7af4cc3f
HW
1396
1397 nfqnl_set_mode(queue, params->copy_mode,
1398 ntohl(params->copy_range));
1399 }
1400
df6fb868 1401 if (nfqa[NFQA_CFG_QUEUE_MAXLEN]) {
60d2c7f9 1402 __be32 *queue_maxlen = nla_data(nfqa[NFQA_CFG_QUEUE_MAXLEN]);
a3c8e7fd 1403
829e17a1
EL
1404 spin_lock_bh(&queue->lock);
1405 queue->queue_maxlen = ntohl(*queue_maxlen);
1406 spin_unlock_bh(&queue->lock);
1407 }
1408
fdb694a0 1409 if (nfqa[NFQA_CFG_FLAGS]) {
fdb694a0
KK
1410 spin_lock_bh(&queue->lock);
1411 queue->flags &= ~mask;
1412 queue->flags |= flags & mask;
1413 spin_unlock_bh(&queue->lock);
1414 }
1415
9872bec7
PM
1416err_out_unlock:
1417 rcu_read_unlock();
838ab636 1418 return ret;
7af4cc3f
HW
1419}
1420
7c8d4cb4 1421static const struct nfnl_callback nfqnl_cb[NFQNL_MSG_MAX] = {
50f2db9e
PNA
1422 [NFQNL_MSG_PACKET] = {
1423 .call = nfqnl_recv_unsupp,
1424 .type = NFNL_CB_RCU,
1425 .attr_count = NFQA_MAX,
1426 },
1427 [NFQNL_MSG_VERDICT] = {
1428 .call = nfqnl_recv_verdict,
1429 .type = NFNL_CB_RCU,
1430 .attr_count = NFQA_MAX,
1431 .policy = nfqa_verdict_policy
1432 },
1433 [NFQNL_MSG_CONFIG] = {
1434 .call = nfqnl_recv_config,
1435 .type = NFNL_CB_MUTEX,
1436 .attr_count = NFQA_CFG_MAX,
1437 .policy = nfqa_cfg_policy
1438 },
1439 [NFQNL_MSG_VERDICT_BATCH] = {
1440 .call = nfqnl_recv_verdict_batch,
1441 .type = NFNL_CB_RCU,
1442 .attr_count = NFQA_MAX,
1443 .policy = nfqa_verdict_batch_policy
1444 },
7af4cc3f
HW
1445};
1446
7c8d4cb4 1447static const struct nfnetlink_subsystem nfqnl_subsys = {
7af4cc3f
HW
1448 .name = "nf_queue",
1449 .subsys_id = NFNL_SUBSYS_QUEUE,
1450 .cb_count = NFQNL_MSG_MAX,
7af4cc3f
HW
1451 .cb = nfqnl_cb,
1452};
1453
838ab636
HW
1454#ifdef CONFIG_PROC_FS
1455struct iter_state {
e8179610 1456 struct seq_net_private p;
838ab636
HW
1457 unsigned int bucket;
1458};
1459
1460static struct hlist_node *get_first(struct seq_file *seq)
1461{
1462 struct iter_state *st = seq->private;
e8179610
G
1463 struct net *net;
1464 struct nfnl_queue_net *q;
838ab636
HW
1465
1466 if (!st)
1467 return NULL;
1468
e8179610
G
1469 net = seq_file_net(seq);
1470 q = nfnl_queue_pernet(net);
838ab636 1471 for (st->bucket = 0; st->bucket < INSTANCE_BUCKETS; st->bucket++) {
e8179610
G
1472 if (!hlist_empty(&q->instance_table[st->bucket]))
1473 return q->instance_table[st->bucket].first;
838ab636
HW
1474 }
1475 return NULL;
1476}
1477
1478static struct hlist_node *get_next(struct seq_file *seq, struct hlist_node *h)
1479{
1480 struct iter_state *st = seq->private;
e8179610 1481 struct net *net = seq_file_net(seq);
838ab636
HW
1482
1483 h = h->next;
1484 while (!h) {
e8179610
G
1485 struct nfnl_queue_net *q;
1486
838ab636
HW
1487 if (++st->bucket >= INSTANCE_BUCKETS)
1488 return NULL;
1489
e8179610
G
1490 q = nfnl_queue_pernet(net);
1491 h = q->instance_table[st->bucket].first;
838ab636
HW
1492 }
1493 return h;
1494}
1495
1496static struct hlist_node *get_idx(struct seq_file *seq, loff_t pos)
1497{
1498 struct hlist_node *head;
1499 head = get_first(seq);
1500
1501 if (head)
1502 while (pos && (head = get_next(seq, head)))
1503 pos--;
1504 return pos ? NULL : head;
1505}
1506
e8179610
G
1507static void *seq_start(struct seq_file *s, loff_t *pos)
1508 __acquires(nfnl_queue_pernet(seq_file_net(s))->instances_lock)
838ab636 1509{
e8179610
G
1510 spin_lock(&nfnl_queue_pernet(seq_file_net(s))->instances_lock);
1511 return get_idx(s, *pos);
838ab636
HW
1512}
1513
1514static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
1515{
1516 (*pos)++;
1517 return get_next(s, v);
1518}
1519
1520static void seq_stop(struct seq_file *s, void *v)
e8179610 1521 __releases(nfnl_queue_pernet(seq_file_net(s))->instances_lock)
838ab636 1522{
e8179610 1523 spin_unlock(&nfnl_queue_pernet(seq_file_net(s))->instances_lock);
838ab636
HW
1524}
1525
1526static int seq_show(struct seq_file *s, void *v)
1527{
1528 const struct nfqnl_instance *inst = v;
1529
6b46f7b7 1530 seq_printf(s, "%5u %6u %5u %1u %5u %5u %5u %8u %2d\n",
e71456ae
SRRH
1531 inst->queue_num,
1532 inst->peer_portid, inst->queue_total,
1533 inst->copy_mode, inst->copy_range,
1534 inst->queue_dropped, inst->queue_user_dropped,
1535 inst->id_sequence, 1);
861fb107 1536 return 0;
838ab636
HW
1537}
1538
56b3d975 1539static const struct seq_operations nfqnl_seq_ops = {
838ab636
HW
1540 .start = seq_start,
1541 .next = seq_next,
1542 .stop = seq_stop,
1543 .show = seq_show,
1544};
838ab636
HW
1545#endif /* PROC_FS */
1546
e8179610 1547static int __net_init nfnl_queue_net_init(struct net *net)
7af4cc3f 1548{
e8179610
G
1549 unsigned int i;
1550 struct nfnl_queue_net *q = nfnl_queue_pernet(net);
601e68e1 1551
838ab636 1552 for (i = 0; i < INSTANCE_BUCKETS; i++)
e8179610
G
1553 INIT_HLIST_HEAD(&q->instance_table[i]);
1554
1555 spin_lock_init(&q->instances_lock);
1556
1557#ifdef CONFIG_PROC_FS
c3506372
CH
1558 if (!proc_create_net("nfnetlink_queue", 0440, net->nf.proc_netfilter,
1559 &nfqnl_seq_ops, sizeof(struct iter_state)))
e8179610
G
1560 return -ENOMEM;
1561#endif
1562 return 0;
1563}
1564
1565static void __net_exit nfnl_queue_net_exit(struct net *net)
1566{
613d0776
VA
1567 struct nfnl_queue_net *q = nfnl_queue_pernet(net);
1568 unsigned int i;
1569
e778f56e 1570#ifdef CONFIG_PROC_FS
e8179610 1571 remove_proc_entry("nfnetlink_queue", net->nf.proc_netfilter);
e778f56e 1572#endif
613d0776
VA
1573 for (i = 0; i < INSTANCE_BUCKETS; i++)
1574 WARN_ON_ONCE(!hlist_empty(&q->instance_table[i]));
e8179610
G
1575}
1576
1577static struct pernet_operations nfnl_queue_net_ops = {
dc3ee32e
EB
1578 .init = nfnl_queue_net_init,
1579 .exit = nfnl_queue_net_exit,
dc3ee32e
EB
1580 .id = &nfnl_queue_net_id,
1581 .size = sizeof(struct nfnl_queue_net),
e8179610
G
1582};
1583
1584static int __init nfnetlink_queue_init(void)
1585{
3bfe0498
FR
1586 int status;
1587
1588 status = register_pernet_subsys(&nfnl_queue_net_ops);
1589 if (status < 0) {
5191d70f 1590 pr_err("failed to register pernet ops\n");
3bfe0498
FR
1591 goto out;
1592 }
838ab636 1593
7af4cc3f
HW
1594 netlink_register_notifier(&nfqnl_rtnl_notifier);
1595 status = nfnetlink_subsys_register(&nfqnl_subsys);
1596 if (status < 0) {
5191d70f 1597 pr_err("failed to create netlink socket\n");
7af4cc3f
HW
1598 goto cleanup_netlink_notifier;
1599 }
1600
4e6577de
GF
1601 status = register_netdevice_notifier(&nfqnl_dev_notifier);
1602 if (status < 0) {
5191d70f 1603 pr_err("failed to register netdevice notifier\n");
4e6577de
GF
1604 goto cleanup_netlink_subsys;
1605 }
1606
87029970
FW
1607 nf_register_queue_handler(&nfqh);
1608
7af4cc3f
HW
1609 return status;
1610
4e6577de
GF
1611cleanup_netlink_subsys:
1612 nfnetlink_subsys_unregister(&nfqnl_subsys);
7af4cc3f
HW
1613cleanup_netlink_notifier:
1614 netlink_unregister_notifier(&nfqnl_rtnl_notifier);
639e077b 1615 unregister_pernet_subsys(&nfnl_queue_net_ops);
3bfe0498 1616out:
7af4cc3f
HW
1617 return status;
1618}
1619
65b4b4e8 1620static void __exit nfnetlink_queue_fini(void)
7af4cc3f 1621{
87029970 1622 nf_unregister_queue_handler();
32292a7f 1623 unregister_netdevice_notifier(&nfqnl_dev_notifier);
32292a7f
PM
1624 nfnetlink_subsys_unregister(&nfqnl_subsys);
1625 netlink_unregister_notifier(&nfqnl_rtnl_notifier);
3bfe0498 1626 unregister_pernet_subsys(&nfnl_queue_net_ops);
67137f3c
JDB
1627
1628 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7af4cc3f
HW
1629}
1630
1631MODULE_DESCRIPTION("netfilter packet queue handler");
1632MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
1633MODULE_LICENSE("GPL");
1634MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_QUEUE);
1635
65b4b4e8
AM
1636module_init(nfnetlink_queue_init);
1637module_exit(nfnetlink_queue_fini);