2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-01-03 20:02:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
#include <linux/netfilter.h>
|
|
|
|
#include <linux/netfilter/nf_tables.h>
|
|
|
|
#include <net/netfilter/nf_tables.h>
|
2019-09-08 17:32:05 +00:00
|
|
|
#include <net/netfilter/nf_tables_offload.h>
|
2017-05-19 16:29:41 +00:00
|
|
|
#include <net/netfilter/nf_dup_netdev.h>
|
2016-01-03 20:02:18 +00:00
|
|
|
|
2016-11-28 10:40:06 +00:00
|
|
|
static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
if (skb_mac_header_was_set(skb))
|
|
|
|
skb_push(skb, skb->mac_len);
|
|
|
|
|
|
|
|
skb->dev = dev;
|
2020-10-21 10:55:52 +00:00
|
|
|
skb->tstamp = 0;
|
2016-11-28 10:40:06 +00:00
|
|
|
dev_queue_xmit(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
dev = dev_get_by_index_rcu(nft_net(pkt), oif);
|
|
|
|
if (!dev) {
|
|
|
|
kfree_skb(pkt->skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nf_do_netdev_egress(pkt->skb, dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nf_fwd_netdev_egress);
|
|
|
|
|
2016-01-03 20:02:18 +00:00
|
|
|
void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2016-11-03 09:56:26 +00:00
|
|
|
dev = dev_get_by_index_rcu(nft_net(pkt), oif);
|
2016-01-03 20:02:18 +00:00
|
|
|
if (dev == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
skb = skb_clone(pkt->skb, GFP_ATOMIC);
|
2016-11-28 10:40:06 +00:00
|
|
|
if (skb)
|
|
|
|
nf_do_netdev_egress(skb, dev);
|
2016-01-03 20:02:18 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nf_dup_netdev_egress);
|
|
|
|
|
2019-09-08 17:32:05 +00:00
|
|
|
int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,
|
|
|
|
struct nft_flow_rule *flow,
|
|
|
|
enum flow_action_id id, int oif)
|
|
|
|
{
|
|
|
|
struct flow_action_entry *entry;
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
/* nft_flow_rule_destroy() releases the reference on this device. */
|
|
|
|
dev = dev_get_by_index(ctx->net, oif);
|
|
|
|
if (!dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
entry = &flow->rule->action.entries[ctx->num_actions++];
|
|
|
|
entry->id = id;
|
|
|
|
entry->dev = dev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nft_fwd_dup_netdev_offload);
|
|
|
|
|
2016-01-03 20:02:18 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
|