Skip to contentSkip to conversation

netfilter: nf_nat_snmp_basic: use asn1 decoder library

PATCH In review Taehee Yoo 2 participants 2 messages Jan 7, 2018 – Jan 8, 2018

Subsystems (2)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH v5 5/5 netfilter: nf_nat_snmp_basic: use asn1 decoder library

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.

---

V5 :
- fix sparse error

V4 :
- rename nf_nat_snmp_basic.c to nf_nat_snmp_basic_main.c to fix compile error

V3 :
- be separated by previous patch.

V2 :
- Add missing nf_nat_snmp_basic.asn1 file

V1 :
- Initial patch

 net/ipv4/netfilter/Kconfig                         |    1 +
 net/ipv4/netfilter/Makefile                        |    6 +
 net/ipv4/netfilter/nf_nat_snmp_basic.asn1          |  177 ++++
 ...f_nat_snmp_basic.c => nf_nat_snmp_basic_main.c} | 1071 ++------------------
 4 files changed, 241 insertions(+), 1014 deletions(-)
 create mode 100644 net/ipv4/netfilter/nf_nat_snmp_basic.asn1
 rename net/ipv4/netfilter/{nf_nat_snmp_basic.c => nf_nat_snmp_basic_main.c} (18%)
net/ipv4/netfilter/Kconfig +1 -0
index cee5104..df55cb1 100644
@@ -149,6 +149,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
net/ipv4/netfilter/Makefile +6 -0
index adcdae3..35b97eb 100644
@@ -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
 
net/ipv4/netfilter/nf_nat_snmp_basic.asn1 new file +177 -0

177 lines not on this page · raw message

net/ipv4/netfilter/nf_nat_snmp_basic_main.c renamed from net/ipv4/netfilter/nf_nat_snmp_basic.c +57 -1014

1,139 lines not on this page · raw message

Signature · 1 line
2.9.3
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Taehee,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on nf-next/master]
[also build test WARNING on v4.15-rc7 next-20180105]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Taehee-Yoo/netfilter-nf_nat_snmp_basic-remove-useless-comment/20180108-110506
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__

sparse warnings: (new ones prefixed by >>)

>> net/ipv4/netfilter/nf_nat_snmp_basic_main.c:222:9: sparse: incompatible types in comparison expression (different address spaces)

net/ipv4/netfilter/nf_nat_snmp_basic_main.c:229:9: sparse: incompatible types in comparison expression (different address spaces)

vim +222 net/ipv4/netfilter/nf_nat_snmp_basic_main.c

218
219 static int __init nf_nat_snmp_basic_init(void)
220 {
221 BUG_ON(nf_nat_snmp_hook != NULL);

 > 222		RCU_INIT_POINTER(nf_nat_snmp_hook, help);

223
224 return nf_conntrack_helper_register(&snmp_trap_helper);
225 }
226

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation