Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
netfilter: nf_nat_snmp_basic: use asn1 decoder library
Browse files Browse the repository at this point in the history
The basic SNMP ALG parse snmp ASN.1 payload
however, since 2012 linux kernel provide ASN.1 decoder library.
If we use ASN.1 decoder in the /lib/asn1_decoder.c, we can remove
about 1000 line of ASN.1 parsing routine.

To use asn1_decoder.c, we should write mib file(nf_nat_snmp_basic.asn1)
then /script/asn1_compiler.c makes *-asn1.c and *-asn1.h file
at the compiletime.(nf_nat_snmp_basic-asn1.c, nf_nat_snmp_basic-asn1.h)
The nf_nat_snmp_basic.asn1 is made by RFC1155, RFC1157, RFC1902, RFC1905,
RFC2578, RFC3416. of course that mib file supports only the basic SNMP ALG.

Previous SNMP ALG mangles only first octet of IPv4 address.
but after this patch, the SNMP ALG mangles whole IPv4 Address.
And SNMPv3 is not supported.

I tested with snmp commands such ans snmpd, snmpwalk, snmptrap.

Signed-off-by: Taehee Yoo <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
TaeheeYoo authored and ummakynes committed Jan 19, 2018
1 parent bea588b commit cc2d586
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 1,192 deletions.
1 change: 1 addition & 0 deletions net/ipv4/netfilter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -158,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
Expand Down
6 changes: 6 additions & 0 deletions net/ipv4/netfilter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
177 changes: 177 additions & 0 deletions net/ipv4/netfilter/nf_nat_snmp_basic.asn1
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit cc2d586

Please sign in to comment.