Skip to content

Commit fdb694a

Browse files
krkumarummakynes
authored andcommitted
netfilter: Add fail-open support
Implement a new "fail-open" mode where packets are not dropped upon queue-full condition. This mode can be enabled/disabled per queue using netlink NFQA_CFG_FLAGS & NFQA_CFG_MASK attributes. Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com> Signed-off-by: Vivek Kashyap <vivk@us.ibm.com> Signed-off-by: Sridhar Samudrala <samudrala@us.ibm.com>
1 parent 68c07cb commit fdb694a

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

include/linux/netfilter/nfnetlink_queue.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ enum nfqnl_attr_config {
8484
NFQA_CFG_CMD, /* nfqnl_msg_config_cmd */
8585
NFQA_CFG_PARAMS, /* nfqnl_msg_config_params */
8686
NFQA_CFG_QUEUE_MAXLEN, /* __u32 */
87+
NFQA_CFG_MASK, /* identify which flags to change */
88+
NFQA_CFG_FLAGS, /* value of these flags (__u32) */
8789
__NFQA_CFG_MAX
8890
};
8991
#define NFQA_CFG_MAX (__NFQA_CFG_MAX-1)
9092

93+
/* Flags for NFQA_CFG_FLAGS */
94+
#define NFQA_CFG_F_FAIL_OPEN (1 << 0)
95+
9196
#endif /* _NFNETLINK_QUEUE_H */

net/netfilter/nfnetlink_queue.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct nfqnl_instance {
5252

5353
u_int16_t queue_num; /* number of this queue */
5454
u_int8_t copy_mode;
55+
u_int32_t flags; /* Set using NFQA_CFG_FLAGS */
5556
/*
5657
* Following fields are dirtied for each queued packet,
5758
* keep them in same cache line if possible.
@@ -406,6 +407,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
406407
struct nfqnl_instance *queue;
407408
int err = -ENOBUFS;
408409
__be32 *packet_id_ptr;
410+
int failopen = 0;
409411

410412
/* rcu_read_lock()ed by nf_hook_slow() */
411413
queue = instance_lookup(queuenum);
@@ -431,9 +433,14 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
431433
goto err_out_free_nskb;
432434
}
433435
if (queue->queue_total >= queue->queue_maxlen) {
434-
queue->queue_dropped++;
435-
net_warn_ratelimited("nf_queue: full at %d entries, dropping packets(s)\n",
436-
queue->queue_total);
436+
if (queue->flags & NFQA_CFG_F_FAIL_OPEN) {
437+
failopen = 1;
438+
err = 0;
439+
} else {
440+
queue->queue_dropped++;
441+
net_warn_ratelimited("nf_queue: full at %d entries, dropping packets(s)\n",
442+
queue->queue_total);
443+
}
437444
goto err_out_free_nskb;
438445
}
439446
entry->id = ++queue->id_sequence;
@@ -455,6 +462,8 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
455462
kfree_skb(nskb);
456463
err_out_unlock:
457464
spin_unlock_bh(&queue->lock);
465+
if (failopen)
466+
nf_reinject(entry, NF_ACCEPT);
458467
err_out:
459468
return err;
460469
}
@@ -858,6 +867,31 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
858867
spin_unlock_bh(&queue->lock);
859868
}
860869

870+
if (nfqa[NFQA_CFG_FLAGS]) {
871+
__u32 flags, mask;
872+
873+
if (!queue) {
874+
ret = -ENODEV;
875+
goto err_out_unlock;
876+
}
877+
878+
if (!nfqa[NFQA_CFG_MASK]) {
879+
/* A mask is needed to specify which flags are being
880+
* changed.
881+
*/
882+
ret = -EINVAL;
883+
goto err_out_unlock;
884+
}
885+
886+
flags = ntohl(nla_get_be32(nfqa[NFQA_CFG_FLAGS]));
887+
mask = ntohl(nla_get_be32(nfqa[NFQA_CFG_MASK]));
888+
889+
spin_lock_bh(&queue->lock);
890+
queue->flags &= ~mask;
891+
queue->flags |= flags & mask;
892+
spin_unlock_bh(&queue->lock);
893+
}
894+
861895
err_out_unlock:
862896
rcu_read_unlock();
863897
return ret;

0 commit comments

Comments
 (0)