Skip to contentSkip to conversation

netfilter: nf_nat_snmp_basic: use asn1 decoder library

PATCH Superseded Taehee Yoo 2 participants 4 messages Dec 25, 2017 – Jan 7, 2018

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH v4 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.

---

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 c11eb17..346c474 100644
@@ -148,6 +148,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

[RFC PATCH] netfilter: nf_nat_snmp_basic: snmp_version() can be static

Fixes: 499b2f89cea8 ("netfilter: nf_nat_snmp_basic: use asn1 decoder library")
Fixes 499b2f89cea8 ("netfilter: nf_nat_snmp_basic: use asn1 decoder library")
---
 nf_nat_snmp_basic_main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_nat_snmp_basic_main.c +2 -2
index b6e2770..b16d3ad 100644
@@ -101,8 +101,8 @@ static void fast_csum(struct snmp_ctx *ctx, unsigned char offset)
 					     ~csum_unfold(*ctx->check)));
 }
 
-int snmp_version(void *context, size_t hdrlen, unsigned char tag,
-		 const void *data, size_t datalen)
+static int snmp_version(void *context, size_t hdrlen, unsigned char tag,
+			const void *data, size_t datalen)
 {
 	if (*(unsigned char *)data > 1)
 		return -ENOTSUPP;
author
#2 lore raw

Re: [RFC PATCH] netfilter: nf_nat_snmp_basic: snmp_version() can be static

2017-12-26 12:25 GMT+09:00 kbuild test robot <[email protected]>:

Quoted 12 lines
Fixes 499b2f89cea8 ("netfilter: nf_nat_snmp_basic: use asn1 decoder library")
---
 nf_nat_snmp_basic_main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_nat_snmp_basic_main.c +0 -0
index b6e2770..b16d3ad 100644

net/ipv4/netfilter/nf_nat_snmp_basic_main.c static void fast_csum(struct snmp_ctx *ctx, unsigned char offset) · line 108

Quoted 10 lines
net/ipv4/netfilter/nf_nat_snmp_basic_main.c +2 -2
@@ -101,8 +101,8 @@ static void fast_csum(struct snmp_ctx *ctx, unsigned char offset)
                                             ~csum_unfold(*ctx->check)));
 }
 
-int snmp_version(void *context, size_t hdrlen, unsigned char tag,
-                const void *data, size_t datalen)
+static int snmp_version(void *context, size_t hdrlen, unsigned char tag,
+                       const void *data, size_t datalen)
 {
        if (*(unsigned char *)data > 1)
                return -ENOTSUPP;

After this RFC, I found wrong code in my V4 patch
that is snmp_version() is not used.
I sent V5 patch that fixed this.

Thank you!

#3 lore raw
In reply to Taehee Yoo
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-rc5 next-20171222]
[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-use-ASN-1-decoder/20171226-091030
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 >>)

Please review and possibly fold the followup patch.

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