इस तुलना का शेष भाग लोड हो रहा है।

nf_tables_api.c

बनाया गया Diff कभी समाप्त नहीं होता
1 हटाया गया
1068 लाइनें
3 जोड़े गए
1070 लाइनें
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-License-Identifier: GPL-2.0-only
/*
/*
* Copyright (c) 2007-2009 Patrick McHardy <kaber@trash.net>
* Copyright (c) 2007-2009 Patrick McHardy <kaber@trash.net>
*
*
* Development of this code funded by Astaro AG (http://www.astaro.com/)
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
*/


#include <linux/module.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/list.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <linux/netlink.h>
#include <linux/netlink.h>
#include <linux/vmalloc.h>
#include <linux/vmalloc.h>
#include <linux/rhashtable.h>
#include <linux/rhashtable.h>
#include <linux/netfilter.h>
#include <linux/netfilter.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nf_tables.h>
#include <linux/netfilter/nf_tables.h>
#include <net/netfilter/nf_flow_table.h>
#include <net/netfilter/nf_flow_table.h>
#include <net/netfilter/nf_tables_core.h>
#include <net/netfilter/nf_tables_core.h>
#include <net/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables_offload.h>
#include <net/netfilter/nf_tables_offload.h>
#include <net/net_namespace.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/sock.h>


#define NFT_MODULE_AUTOLOAD_LIMIT (MODULE_NAME_LEN - sizeof("nft-expr-255-"))
#define NFT_MODULE_AUTOLOAD_LIMIT (MODULE_NAME_LEN - sizeof("nft-expr-255-"))


static LIST_HEAD(nf_tables_expressions);
static LIST_HEAD(nf_tables_expressions);
static LIST_HEAD(nf_tables_objects);
static LIST_HEAD(nf_tables_objects);
static LIST_HEAD(nf_tables_flowtables);
static LIST_HEAD(nf_tables_flowtables);
static LIST_HEAD(nf_tables_destroy_list);
static LIST_HEAD(nf_tables_destroy_list);
static DEFINE_SPINLOCK(nf_tables_destroy_list_lock);
static DEFINE_SPINLOCK(nf_tables_destroy_list_lock);
static u64 table_handle;
static u64 table_handle;


enum {
enum {
NFT_VALIDATE_SKIP = 0,
NFT_VALIDATE_SKIP = 0,
NFT_VALIDATE_NEED,
NFT_VALIDATE_NEED,
NFT_VALIDATE_DO,
NFT_VALIDATE_DO,
};
};


static struct rhltable nft_objname_ht;
static struct rhltable nft_objname_ht;


static u32 nft_chain_hash(const void *data, u32 len, u32 seed);
static u32 nft_chain_hash(const void *data, u32 len, u32 seed);
static u32 nft_chain_hash_obj(const void *data, u32 len, u32 seed);
static u32 nft_chain_hash_obj(const void *data, u32 len, u32 seed);
static int nft_chain_hash_cmp(struct rhashtable_compare_arg *, const void *);
static int nft_chain_hash_cmp(struct rhashtable_compare_arg *, const void *);


static u32 nft_objname_hash(const void *data, u32 len, u32 seed);
static u32 nft_objname_hash(const void *data, u32 len, u32 seed);
static u32 nft_objname_hash_obj(const void *data, u32 len, u32 seed);
static u32 nft_objname_hash_obj(const void *data, u32 len, u32 seed);
static int nft_objname_hash_cmp(struct rhashtable_compare_arg *, const void *);
static int nft_objname_hash_cmp(struct rhashtable_compare_arg *, const void *);


static const struct rhashtable_params nft_chain_ht_params = {
static const struct rhashtable_params nft_chain_ht_params = {
.head_offset = offsetof(struct nft_chain, rhlhead),
.head_offset = offsetof(struct nft_chain, rhlhead),
.key_offset = offsetof(struct nft_chain, name),
.key_offset = offsetof(struct nft_chain, name),
.hashfn = nft_chain_hash,
.hashfn = nft_chain_hash,
.obj_hashfn = nft_chain_hash_obj,
.obj_hashfn = nft_chain_hash_obj,
.obj_cmpfn = nft_chain_hash_cmp,
.obj_cmpfn = nft_chain_hash_cmp,
.automatic_shrinking = true,
.automatic_shrinking = true,
};
};


static const struct rhashtable_params nft_objname_ht_params = {
static const struct rhashtable_params nft_objname_ht_params = {
.head_offset = offsetof(struct nft_object, rhlhead),
.head_offset = offsetof(struct nft_object, rhlhead),
.key_offset = offsetof(struct nft_object, key),
.key_offset = offsetof(struct nft_object, key),
.hashfn = nft_objname_hash,
.hashfn = nft_objname_hash,
.obj_hashfn = nft_objname_hash_obj,
.obj_hashfn = nft_objname_hash_obj,
.obj_cmpfn = nft_objname_hash_cmp,
.obj_cmpfn = nft_objname_hash_cmp,
.automatic_shrinking = true,
.automatic_shrinking = true,
};
};


static void nft_validate_state_update(struct net *net, u8 new_validate_state)
static void nft_validate_state_update(struct net *net, u8 new_validate_state)
{
{
switch (net->nft.validate_state) {
switch (net->nft.validate_state) {
case NFT_VALIDATE_SKIP:
case NFT_VALIDATE_SKIP:
WARN_ON_ONCE(new_validate_state == NFT_VALIDATE_DO);
WARN_ON_ONCE(new_validate_state == NFT_VALIDATE_DO);
break;
break;
case NFT_VALIDATE_NEED:
case NFT_VALIDATE_NEED:
break;
break;
case NFT_VALIDATE_DO:
case NFT_VALIDATE_DO:
if (new_validate_state == NFT_VALIDATE_NEED)
if (new_validate_state == NFT_VALIDATE_NEED)
return;
return;
}
}


net->nft.validate_state = new_validate_state;
net->nft.validate_state = new_validate_state;
}
}
static void nf_tables_trans_destroy_work(struct work_struct *w);
static void nf_tables_trans_destroy_work(struct work_struct *w);
static DECLARE_WORK(trans_destroy_work, nf_tables_trans_destroy_work);
static DECLARE_WORK(trans_destroy_work, nf_tables_trans_destroy_work);


static void nft_ctx_init(struct nft_ctx *ctx,
static void nft_ctx_init(struct nft_ctx *ctx,
struct net *net,
struct net *net,
const struct sk_buff *skb,
const struct sk_buff *skb,
const struct nlmsghdr *nlh,
const struct nlmsghdr *nlh,
u8 family,
u8 family,
struct nft_table *table,
struct nft_table *table,
struct nft_chain *chain,
struct nft_chain *chain,
const struct nlattr * const *nla)
const struct nlattr * const *nla)
{
{
ctx->net = net;
ctx->net = net;
ctx->family = family;
ctx->family = family;
ctx->level = 0;
ctx->level = 0;
ctx->table = table;
ctx->table = table;
ctx->chain = chain;
ctx->chain = chain;
ctx->nla = nla;
ctx->nla = nla;