Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== Netfilter/IPVS updates for net-next The following patchset contains Netfilter/IPVS updates for your net-next tree. Basically, a new extension for ip6tables, simplification work of nf_tables that saves us 500 LoC, allow raw table registration before defragmentation, conversion of the SNMP helper to use the ASN.1 code generator, unique 64-bit handle for all nf_tables objects and fixes to address fallout from previous nf-next batch. More specifically, they are: 1) Seven patches to remove family abstraction layer (struct nft_af_info) in nf_tables, this simplifies our codebase and it saves us 64 bytes per net namespace. 2) Add IPv6 segment routing header matching for ip6tables, from Ahmed Abdelsalam. 3) Allow to register iptable_raw table before defragmentation, some people do not want to waste cycles on defragmenting traffic that is going to be dropped, hence add a new module parameter to enable this behaviour in iptables and ip6tables. From Subash Abhinov Kasiviswanathan. This patch needed a couple of follow up patches to get things tidy from Arnd Bergmann. 4) SNMP helper uses the ASN.1 code generator, from Taehee Yoo. Several patches for this helper to prepare this change are also part of this patch series. 5) Add 64-bit handles to uniquely objects in nf_tables, from Harsha Sharma. 6) Remove log message that several netfilter subsystems print at boot/load time. 7) Restore x_tables module autoloading, that got broken in a previous patch to allow singleton NAT hook callback registration per hook spot, from Florian Westphal. Moreover, return EBUSY to report that the singleton NAT hook slot is already in instead. 8) Several fixes for the new nf_tables flowtable representation, including incorrect error check after nf_tables_flowtable_lookup(), missing Kconfig dependencies that lead to build breakage and missing initialization of priority and hooknum in flowtable object. 9) Missing NETFILTER_FAMILY_ARP dependency in Kconfig for the clusterip target. This is due to recent updates in the core to shrink the hook array size and compile it out if no specific family is enabled via .config file. Patch from Florian Westphal. 10) Remove duplicated include header files, from Wei Yongjun. 11) Sparse warning fix for the NFPROTO_INET handling from the core due to missing static function definition, also from Wei Yongjun. 12) Restore ICMPv6 Parameter Problem error reporting when defragmentation fails, from Subash Abhinov Kasiviswanathan. 13) Remove obsolete owner field initialization from struct file_operations, patch from Alexey Dobriyan. 14) Use boolean datatype where needed in the Netfilter codebase, from Gustavo A. R. Silva. 15) Remove double semicolon in dynset nf_tables expression, from Luis de Bethencourt. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
@@ -79,8 +79,9 @@ config NF_TABLES_ARP
|
||||
endif # NF_TABLES
|
||||
|
||||
config NF_FLOW_TABLE_IPV4
|
||||
select NF_FLOW_TABLE
|
||||
tristate "Netfilter flow table IPv4 module"
|
||||
depends on NF_CONNTRACK && NF_TABLES
|
||||
select NF_FLOW_TABLE
|
||||
help
|
||||
This option adds the flow table IPv4 support.
|
||||
|
||||
@@ -157,6 +158,7 @@ config NF_NAT_SNMP_BASIC
|
||||
depends on NF_CONNTRACK_SNMP
|
||||
depends on NETFILTER_ADVANCED
|
||||
default NF_NAT && NF_CONNTRACK_SNMP
|
||||
select ASN1
|
||||
---help---
|
||||
|
||||
This module implements an Application Layer Gateway (ALG) for
|
||||
@@ -342,6 +344,7 @@ config IP_NF_TARGET_CLUSTERIP
|
||||
depends on NF_CONNTRACK_IPV4
|
||||
depends on NETFILTER_ADVANCED
|
||||
select NF_CONNTRACK_MARK
|
||||
select NETFILTER_FAMILY_ARP
|
||||
help
|
||||
The CLUSTERIP target allows you to build load-balancing clusters of
|
||||
network servers without having a dedicated load-balancing
|
||||
|
@@ -27,9 +27,15 @@ obj-$(CONFIG_NF_REJECT_IPV4) += nf_reject_ipv4.o
|
||||
# NAT helpers (nf_conntrack)
|
||||
obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o
|
||||
obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o
|
||||
|
||||
nf_nat_snmp_basic-y := nf_nat_snmp_basic-asn1.o nf_nat_snmp_basic_main.o
|
||||
nf_nat_snmp_basic-y : nf_nat_snmp_basic-asn1.h nf_nat_snmp_basic-asn1.c
|
||||
obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o
|
||||
clean-files := nf_nat_snmp_basic-asn1.c nf_nat_snmp_basic-asn1.h
|
||||
|
||||
obj-$(CONFIG_NF_NAT_MASQUERADE_IPV4) += nf_nat_masquerade_ipv4.o
|
||||
|
||||
|
||||
# NAT protocols (nf_nat)
|
||||
obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o
|
||||
|
||||
|
@@ -1656,7 +1656,6 @@ static int __init arp_tables_init(void)
|
||||
if (ret < 0)
|
||||
goto err4;
|
||||
|
||||
pr_info("arp_tables: (C) 2002 David S. Miller\n");
|
||||
return 0;
|
||||
|
||||
err4:
|
||||
|
@@ -1939,7 +1939,6 @@ static int __init ip_tables_init(void)
|
||||
if (ret < 0)
|
||||
goto err5;
|
||||
|
||||
pr_info("(C) 2000-2006 Netfilter Core Team\n");
|
||||
return 0;
|
||||
|
||||
err5:
|
||||
|
@@ -3,6 +3,7 @@
|
||||
*
|
||||
* Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
|
||||
*/
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
#include <linux/module.h>
|
||||
#include <linux/netfilter_ipv4/ip_tables.h>
|
||||
#include <linux/slab.h>
|
||||
@@ -12,6 +13,10 @@
|
||||
|
||||
static int __net_init iptable_raw_table_init(struct net *net);
|
||||
|
||||
static bool raw_before_defrag __read_mostly;
|
||||
MODULE_PARM_DESC(raw_before_defrag, "Enable raw table before defrag");
|
||||
module_param(raw_before_defrag, bool, 0000);
|
||||
|
||||
static const struct xt_table packet_raw = {
|
||||
.name = "raw",
|
||||
.valid_hooks = RAW_VALID_HOOKS,
|
||||
@@ -21,6 +26,15 @@ static const struct xt_table packet_raw = {
|
||||
.table_init = iptable_raw_table_init,
|
||||
};
|
||||
|
||||
static const struct xt_table packet_raw_before_defrag = {
|
||||
.name = "raw",
|
||||
.valid_hooks = RAW_VALID_HOOKS,
|
||||
.me = THIS_MODULE,
|
||||
.af = NFPROTO_IPV4,
|
||||
.priority = NF_IP_PRI_RAW_BEFORE_DEFRAG,
|
||||
.table_init = iptable_raw_table_init,
|
||||
};
|
||||
|
||||
/* The work comes in here from netfilter.c. */
|
||||
static unsigned int
|
||||
iptable_raw_hook(void *priv, struct sk_buff *skb,
|
||||
@@ -34,15 +48,19 @@ static struct nf_hook_ops *rawtable_ops __read_mostly;
|
||||
static int __net_init iptable_raw_table_init(struct net *net)
|
||||
{
|
||||
struct ipt_replace *repl;
|
||||
const struct xt_table *table = &packet_raw;
|
||||
int ret;
|
||||
|
||||
if (raw_before_defrag)
|
||||
table = &packet_raw_before_defrag;
|
||||
|
||||
if (net->ipv4.iptable_raw)
|
||||
return 0;
|
||||
|
||||
repl = ipt_alloc_initial_table(&packet_raw);
|
||||
repl = ipt_alloc_initial_table(table);
|
||||
if (repl == NULL)
|
||||
return -ENOMEM;
|
||||
ret = ipt_register_table(net, &packet_raw, repl, rawtable_ops,
|
||||
ret = ipt_register_table(net, table, repl, rawtable_ops,
|
||||
&net->ipv4.iptable_raw);
|
||||
kfree(repl);
|
||||
return ret;
|
||||
@@ -63,8 +81,15 @@ static struct pernet_operations iptable_raw_net_ops = {
|
||||
static int __init iptable_raw_init(void)
|
||||
{
|
||||
int ret;
|
||||
const struct xt_table *table = &packet_raw;
|
||||
|
||||
rawtable_ops = xt_hook_ops_alloc(&packet_raw, iptable_raw_hook);
|
||||
if (raw_before_defrag) {
|
||||
table = &packet_raw_before_defrag;
|
||||
|
||||
pr_info("Enabling raw table before defrag\n");
|
||||
}
|
||||
|
||||
rawtable_ops = xt_hook_ops_alloc(table, iptable_raw_hook);
|
||||
if (IS_ERR(rawtable_ops))
|
||||
return PTR_ERR(rawtable_ops);
|
||||
|
||||
|
@@ -78,6 +78,8 @@ static unsigned int ipv4_conntrack_defrag(void *priv,
|
||||
if (skb_nfct(skb) && !nf_ct_is_template((struct nf_conn *)skb_nfct(skb)))
|
||||
return NF_ACCEPT;
|
||||
#endif
|
||||
if (skb->_nfct == IP_CT_UNTRACKED)
|
||||
return NF_ACCEPT;
|
||||
#endif
|
||||
/* Gather fragments. */
|
||||
if (ip_is_fragment(ip_hdr(skb))) {
|
||||
|
177
net/ipv4/netfilter/nf_nat_snmp_basic.asn1
Normal file
177
net/ipv4/netfilter/nf_nat_snmp_basic.asn1
Normal file
@@ -0,0 +1,177 @@
|
||||
Message ::=
|
||||
SEQUENCE {
|
||||
version
|
||||
INTEGER ({snmp_version}),
|
||||
|
||||
community
|
||||
OCTET STRING,
|
||||
|
||||
pdu
|
||||
PDUs
|
||||
}
|
||||
|
||||
|
||||
ObjectName ::=
|
||||
OBJECT IDENTIFIER
|
||||
|
||||
ObjectSyntax ::=
|
||||
CHOICE {
|
||||
simple
|
||||
SimpleSyntax,
|
||||
|
||||
application-wide
|
||||
ApplicationSyntax
|
||||
}
|
||||
|
||||
SimpleSyntax ::=
|
||||
CHOICE {
|
||||
integer-value
|
||||
INTEGER,
|
||||
|
||||
string-value
|
||||
OCTET STRING,
|
||||
|
||||
objectID-value
|
||||
OBJECT IDENTIFIER
|
||||
}
|
||||
|
||||
ApplicationSyntax ::=
|
||||
CHOICE {
|
||||
ipAddress-value
|
||||
IpAddress,
|
||||
|
||||
counter-value
|
||||
Counter32,
|
||||
|
||||
timeticks-value
|
||||
TimeTicks,
|
||||
|
||||
arbitrary-value
|
||||
Opaque,
|
||||
|
||||
big-counter-value
|
||||
Counter64,
|
||||
|
||||
unsigned-integer-value
|
||||
Unsigned32
|
||||
}
|
||||
|
||||
IpAddress ::=
|
||||
[APPLICATION 0]
|
||||
IMPLICIT OCTET STRING OPTIONAL ({snmp_helper})
|
||||
|
||||
Counter32 ::=
|
||||
[APPLICATION 1]
|
||||
IMPLICIT INTEGER OPTIONAL
|
||||
|
||||
Unsigned32 ::=
|
||||
[APPLICATION 2]
|
||||
IMPLICIT INTEGER OPTIONAL
|
||||
|
||||
Gauge32 ::= Unsigned32 OPTIONAL
|
||||
|
||||
TimeTicks ::=
|
||||
[APPLICATION 3]
|
||||
IMPLICIT INTEGER OPTIONAL
|
||||
|
||||
Opaque ::=
|
||||
[APPLICATION 4]
|
||||
IMPLICIT OCTET STRING OPTIONAL
|
||||
|
||||
Counter64 ::=
|
||||
[APPLICATION 6]
|
||||
IMPLICIT INTEGER OPTIONAL
|
||||
|
||||
PDUs ::=
|
||||
CHOICE {
|
||||
get-request
|
||||
GetRequest-PDU,
|
||||
|
||||
get-next-request
|
||||
GetNextRequest-PDU,
|
||||
|
||||
get-bulk-request
|
||||
GetBulkRequest-PDU,
|
||||
|
||||
response
|
||||
Response-PDU,
|
||||
|
||||
set-request
|
||||
SetRequest-PDU,
|
||||
|
||||
inform-request
|
||||
InformRequest-PDU,
|
||||
|
||||
snmpV2-trap
|
||||
SNMPv2-Trap-PDU,
|
||||
|
||||
report
|
||||
Report-PDU
|
||||
}
|
||||
|
||||
GetRequest-PDU ::=
|
||||
[0] IMPLICIT PDU OPTIONAL
|
||||
|
||||
GetNextRequest-PDU ::=
|
||||
[1] IMPLICIT PDU OPTIONAL
|
||||
|
||||
Response-PDU ::=
|
||||
[2] IMPLICIT PDU OPTIONAL
|
||||
|
||||
SetRequest-PDU ::=
|
||||
[3] IMPLICIT PDU OPTIONAL
|
||||
|
||||
-- [4] is obsolete
|
||||
|
||||
GetBulkRequest-PDU ::=
|
||||
[5] IMPLICIT PDU OPTIONAL
|
||||
|
||||
InformRequest-PDU ::=
|
||||
[6] IMPLICIT PDU OPTIONAL
|
||||
|
||||
SNMPv2-Trap-PDU ::=
|
||||
[7] IMPLICIT PDU OPTIONAL
|
||||
|
||||
Report-PDU ::=
|
||||
[8] IMPLICIT PDU OPTIONAL
|
||||
|
||||
PDU ::=
|
||||
SEQUENCE {
|
||||
request-id
|
||||
INTEGER,
|
||||
|
||||
error-status
|
||||
INTEGER,
|
||||
|
||||
error-index
|
||||
INTEGER,
|
||||
|
||||
variable-bindings
|
||||
VarBindList
|
||||
}
|
||||
|
||||
|
||||
VarBind ::=
|
||||
SEQUENCE {
|
||||
name
|
||||
ObjectName,
|
||||
|
||||
CHOICE {
|
||||
value
|
||||
ObjectSyntax,
|
||||
|
||||
unSpecified
|
||||
NULL,
|
||||
|
||||
noSuchObject
|
||||
[0] IMPLICIT NULL,
|
||||
|
||||
noSuchInstance
|
||||
[1] IMPLICIT NULL,
|
||||
|
||||
endOfMibView
|
||||
[2] IMPLICIT NULL
|
||||
}
|
||||
}
|
||||
|
||||
VarBindList ::= SEQUENCE OF VarBind
|
File diff suppressed because it is too large
Load Diff
235
net/ipv4/netfilter/nf_nat_snmp_basic_main.c
Normal file
235
net/ipv4/netfilter/nf_nat_snmp_basic_main.c
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* nf_nat_snmp_basic.c
|
||||
*
|
||||
* Basic SNMP Application Layer Gateway
|
||||
*
|
||||
* This IP NAT module is intended for use with SNMP network
|
||||
* discovery and monitoring applications where target networks use
|
||||
* conflicting private address realms.
|
||||
*
|
||||
* Static NAT is used to remap the networks from the view of the network
|
||||
* management system at the IP layer, and this module remaps some application
|
||||
* layer addresses to match.
|
||||
*
|
||||
* The simplest form of ALG is performed, where only tagged IP addresses
|
||||
* are modified. The module does not need to be MIB aware and only scans
|
||||
* messages at the ASN.1/BER level.
|
||||
*
|
||||
* Currently, only SNMPv1 and SNMPv2 are supported.
|
||||
*
|
||||
* More information on ALG and associated issues can be found in
|
||||
* RFC 2962
|
||||
*
|
||||
* The ASB.1/BER parsing code is derived from the gxsnmp package by Gregory
|
||||
* McLean & Jochen Friedrich, stripped down for use in the kernel.
|
||||
*
|
||||
* Copyright (c) 2000 RP Internet (www.rpi.net.au).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: James Morris <jmorris@intercode.com.au>
|
||||
*
|
||||
* Copyright (c) 2006-2010 Patrick McHardy <kaber@trash.net>
|
||||
*/
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/udp.h>
|
||||
#include <net/checksum.h>
|
||||
#include <net/udp.h>
|
||||
|
||||
#include <net/netfilter/nf_nat.h>
|
||||
#include <net/netfilter/nf_conntrack_expect.h>
|
||||
#include <net/netfilter/nf_conntrack_helper.h>
|
||||
#include <linux/netfilter/nf_conntrack_snmp.h>
|
||||
#include "nf_nat_snmp_basic-asn1.h"
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
|
||||
MODULE_DESCRIPTION("Basic SNMP Application Layer Gateway");
|
||||
MODULE_ALIAS("ip_nat_snmp_basic");
|
||||
|
||||
#define SNMP_PORT 161
|
||||
#define SNMP_TRAP_PORT 162
|
||||
|
||||
static DEFINE_SPINLOCK(snmp_lock);
|
||||
|
||||
struct snmp_ctx {
|
||||
unsigned char *begin;
|
||||
__sum16 *check;
|
||||
__be32 from;
|
||||
__be32 to;
|
||||
};
|
||||
|
||||
static void fast_csum(struct snmp_ctx *ctx, unsigned char offset)
|
||||
{
|
||||
unsigned char s[12] = {0,};
|
||||
int size;
|
||||
|
||||
if (offset & 1) {
|
||||
memcpy(&s[1], &ctx->from, 4);
|
||||
memcpy(&s[7], &ctx->to, 4);
|
||||
s[0] = ~0;
|
||||
s[1] = ~s[1];
|
||||
s[2] = ~s[2];
|
||||
s[3] = ~s[3];
|
||||
s[4] = ~s[4];
|
||||
s[5] = ~0;
|
||||
size = 12;
|
||||
} else {
|
||||
memcpy(&s[0], &ctx->from, 4);
|
||||
memcpy(&s[4], &ctx->to, 4);
|
||||
s[0] = ~s[0];
|
||||
s[1] = ~s[1];
|
||||
s[2] = ~s[2];
|
||||
s[3] = ~s[3];
|
||||
size = 8;
|
||||
}
|
||||
*ctx->check = csum_fold(csum_partial(s, size,
|
||||
~csum_unfold(*ctx->check)));
|
||||
}
|
||||
|
||||
int snmp_version(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *data, size_t datalen)
|
||||
{
|
||||
if (*(unsigned char *)data > 1)
|
||||
return -ENOTSUPP;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int snmp_helper(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *data, size_t datalen)
|
||||
{
|
||||
struct snmp_ctx *ctx = (struct snmp_ctx *)context;
|
||||
__be32 *pdata = (__be32 *)data;
|
||||
|
||||
if (*pdata == ctx->from) {
|
||||
pr_debug("%s: %pI4 to %pI4\n", __func__,
|
||||
(void *)&ctx->from, (void *)&ctx->to);
|
||||
|
||||
if (*ctx->check)
|
||||
fast_csum(ctx, (unsigned char *)data - ctx->begin);
|
||||
*pdata = ctx->to;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int snmp_translate(struct nf_conn *ct, int dir, struct sk_buff *skb)
|
||||
{
|
||||
struct iphdr *iph = ip_hdr(skb);
|
||||
struct udphdr *udph = (struct udphdr *)((__be32 *)iph + iph->ihl);
|
||||
u16 datalen = ntohs(udph->len) - sizeof(struct udphdr);
|
||||
char *data = (unsigned char *)udph + sizeof(struct udphdr);
|
||||
struct snmp_ctx ctx;
|
||||
int ret;
|
||||
|
||||
if (dir == IP_CT_DIR_ORIGINAL) {
|
||||
ctx.from = ct->tuplehash[dir].tuple.src.u3.ip;
|
||||
ctx.to = ct->tuplehash[!dir].tuple.dst.u3.ip;
|
||||
} else {
|
||||
ctx.from = ct->tuplehash[!dir].tuple.src.u3.ip;
|
||||
ctx.to = ct->tuplehash[dir].tuple.dst.u3.ip;
|
||||
}
|
||||
|
||||
if (ctx.from == ctx.to)
|
||||
return NF_ACCEPT;
|
||||
|
||||
ctx.begin = (unsigned char *)udph + sizeof(struct udphdr);
|
||||
ctx.check = &udph->check;
|
||||
ret = asn1_ber_decoder(&nf_nat_snmp_basic_decoder, &ctx, data, datalen);
|
||||
if (ret < 0) {
|
||||
nf_ct_helper_log(skb, ct, "parser failed\n");
|
||||
return NF_DROP;
|
||||
}
|
||||
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
|
||||
/* We don't actually set up expectations, just adjust internal IP
|
||||
* addresses if this is being NATted
|
||||
*/
|
||||
static int help(struct sk_buff *skb, unsigned int protoff,
|
||||
struct nf_conn *ct,
|
||||
enum ip_conntrack_info ctinfo)
|
||||
{
|
||||
int dir = CTINFO2DIR(ctinfo);
|
||||
unsigned int ret;
|
||||
const struct iphdr *iph = ip_hdr(skb);
|
||||
const struct udphdr *udph = (struct udphdr *)((__be32 *)iph + iph->ihl);
|
||||
|
||||
/* SNMP replies and originating SNMP traps get mangled */
|
||||
if (udph->source == htons(SNMP_PORT) && dir != IP_CT_DIR_REPLY)
|
||||
return NF_ACCEPT;
|
||||
if (udph->dest == htons(SNMP_TRAP_PORT) && dir != IP_CT_DIR_ORIGINAL)
|
||||
return NF_ACCEPT;
|
||||
|
||||
/* No NAT? */
|
||||
if (!(ct->status & IPS_NAT_MASK))
|
||||
return NF_ACCEPT;
|
||||
|
||||
/* Make sure the packet length is ok. So far, we were only guaranteed
|
||||
* to have a valid length IP header plus 8 bytes, which means we have
|
||||
* enough room for a UDP header. Just verify the UDP length field so we
|
||||
* can mess around with the payload.
|
||||
*/
|
||||
if (ntohs(udph->len) != skb->len - (iph->ihl << 2)) {
|
||||
nf_ct_helper_log(skb, ct, "dropping malformed packet\n");
|
||||
return NF_DROP;
|
||||
}
|
||||
|
||||
if (!skb_make_writable(skb, skb->len)) {
|
||||
nf_ct_helper_log(skb, ct, "cannot mangle packet");
|
||||
return NF_DROP;
|
||||
}
|
||||
|
||||
spin_lock_bh(&snmp_lock);
|
||||
ret = snmp_translate(ct, dir, skb);
|
||||
spin_unlock_bh(&snmp_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct nf_conntrack_expect_policy snmp_exp_policy = {
|
||||
.max_expected = 0,
|
||||
.timeout = 180,
|
||||
};
|
||||
|
||||
static struct nf_conntrack_helper snmp_trap_helper __read_mostly = {
|
||||
.me = THIS_MODULE,
|
||||
.help = help,
|
||||
.expect_policy = &snmp_exp_policy,
|
||||
.name = "snmp_trap",
|
||||
.tuple.src.l3num = AF_INET,
|
||||
.tuple.src.u.udp.port = cpu_to_be16(SNMP_TRAP_PORT),
|
||||
.tuple.dst.protonum = IPPROTO_UDP,
|
||||
};
|
||||
|
||||
static int __init nf_nat_snmp_basic_init(void)
|
||||
{
|
||||
BUG_ON(nf_nat_snmp_hook != NULL);
|
||||
RCU_INIT_POINTER(nf_nat_snmp_hook, help);
|
||||
|
||||
return nf_conntrack_helper_register(&snmp_trap_helper);
|
||||
}
|
||||
|
||||
static void __exit nf_nat_snmp_basic_fini(void)
|
||||
{
|
||||
RCU_INIT_POINTER(nf_nat_snmp_hook, NULL);
|
||||
synchronize_rcu();
|
||||
nf_conntrack_helper_unregister(&snmp_trap_helper);
|
||||
}
|
||||
|
||||
module_init(nf_nat_snmp_basic_init);
|
||||
module_exit(nf_nat_snmp_basic_fini);
|
@@ -27,40 +27,6 @@ nft_do_chain_arp(void *priv,
|
||||
return nft_do_chain(&pkt, priv);
|
||||
}
|
||||
|
||||
static struct nft_af_info nft_af_arp __read_mostly = {
|
||||
.family = NFPROTO_ARP,
|
||||
.nhooks = NF_ARP_NUMHOOKS,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int nf_tables_arp_init_net(struct net *net)
|
||||
{
|
||||
net->nft.arp = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
|
||||
if (net->nft.arp== NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(net->nft.arp, &nft_af_arp, sizeof(nft_af_arp));
|
||||
|
||||
if (nft_register_afinfo(net, net->nft.arp) < 0)
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
err:
|
||||
kfree(net->nft.arp);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static void nf_tables_arp_exit_net(struct net *net)
|
||||
{
|
||||
nft_unregister_afinfo(net, net->nft.arp);
|
||||
kfree(net->nft.arp);
|
||||
}
|
||||
|
||||
static struct pernet_operations nf_tables_arp_net_ops = {
|
||||
.init = nf_tables_arp_init_net,
|
||||
.exit = nf_tables_arp_exit_net,
|
||||
};
|
||||
|
||||
static const struct nf_chain_type filter_arp = {
|
||||
.name = "filter",
|
||||
.type = NFT_CHAIN_T_DEFAULT,
|
||||
@@ -76,22 +42,11 @@ static const struct nf_chain_type filter_arp = {
|
||||
|
||||
static int __init nf_tables_arp_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = nft_register_chain_type(&filter_arp);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = register_pernet_subsys(&nf_tables_arp_net_ops);
|
||||
if (ret < 0)
|
||||
nft_unregister_chain_type(&filter_arp);
|
||||
|
||||
return ret;
|
||||
return nft_register_chain_type(&filter_arp);
|
||||
}
|
||||
|
||||
static void __exit nf_tables_arp_exit(void)
|
||||
{
|
||||
unregister_pernet_subsys(&nf_tables_arp_net_ops);
|
||||
nft_unregister_chain_type(&filter_arp);
|
||||
}
|
||||
|
||||
@@ -100,4 +55,4 @@ module_exit(nf_tables_arp_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
|
||||
MODULE_ALIAS_NFT_FAMILY(3); /* NFPROTO_ARP */
|
||||
MODULE_ALIAS_NFT_CHAIN(3, "filter"); /* NFPROTO_ARP */
|
||||
|
@@ -30,40 +30,6 @@ static unsigned int nft_do_chain_ipv4(void *priv,
|
||||
return nft_do_chain(&pkt, priv);
|
||||
}
|
||||
|
||||
static struct nft_af_info nft_af_ipv4 __read_mostly = {
|
||||
.family = NFPROTO_IPV4,
|
||||
.nhooks = NF_INET_NUMHOOKS,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int nf_tables_ipv4_init_net(struct net *net)
|
||||
{
|
||||
net->nft.ipv4 = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
|
||||
if (net->nft.ipv4 == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(net->nft.ipv4, &nft_af_ipv4, sizeof(nft_af_ipv4));
|
||||
|
||||
if (nft_register_afinfo(net, net->nft.ipv4) < 0)
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
err:
|
||||
kfree(net->nft.ipv4);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static void nf_tables_ipv4_exit_net(struct net *net)
|
||||
{
|
||||
nft_unregister_afinfo(net, net->nft.ipv4);
|
||||
kfree(net->nft.ipv4);
|
||||
}
|
||||
|
||||
static struct pernet_operations nf_tables_ipv4_net_ops = {
|
||||
.init = nf_tables_ipv4_init_net,
|
||||
.exit = nf_tables_ipv4_exit_net,
|
||||
};
|
||||
|
||||
static const struct nf_chain_type filter_ipv4 = {
|
||||
.name = "filter",
|
||||
.type = NFT_CHAIN_T_DEFAULT,
|
||||
@@ -85,22 +51,11 @@ static const struct nf_chain_type filter_ipv4 = {
|
||||
|
||||
static int __init nf_tables_ipv4_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = nft_register_chain_type(&filter_ipv4);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = register_pernet_subsys(&nf_tables_ipv4_net_ops);
|
||||
if (ret < 0)
|
||||
nft_unregister_chain_type(&filter_ipv4);
|
||||
|
||||
return ret;
|
||||
return nft_register_chain_type(&filter_ipv4);
|
||||
}
|
||||
|
||||
static void __exit nf_tables_ipv4_exit(void)
|
||||
{
|
||||
unregister_pernet_subsys(&nf_tables_ipv4_net_ops);
|
||||
nft_unregister_chain_type(&filter_ipv4);
|
||||
}
|
||||
|
||||
@@ -109,4 +64,4 @@ module_exit(nf_tables_ipv4_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
|
||||
MODULE_ALIAS_NFT_FAMILY(AF_INET);
|
||||
MODULE_ALIAS_NFT_CHAIN(AF_INET, "filter");
|
||||
|
Reference in New Issue
Block a user