Skip to contentSkip to conversation

tproxy: added IPv6 support to the socket match

DISCUSSION Geert Uytterhoeven 3 participants 3 messages Oct 28, 2010 – Oct 29, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 24 lines · Linux Kernel Mailing List

Gitweb:     http://git.kernel.org/linus/b64c9256a9b76fc9f059f71bd08ba88fb0cbba2e
Commit:     b64c9256a9b76fc9f059f71bd08ba88fb0cbba2e
Parent:     6ad7889327a5ee6ab4220bd34e4428c7d0de0f32
Author:     Balazs Scheidler <[email protected]>
AuthorDate: Thu Oct 21 16:19:42 2010 +0200
Committer:  Patrick McHardy <[email protected]>
CommitDate: Thu Oct 21 16:19:42 2010 +0200

   tproxy: added IPv6 support to the socket match

   The ICMP extraction bits were contributed by Harry Mason.

---
 net/netfilter/xt_socket.c |  165 ++++++++++++++++++++++++++++++++++++++++++---

 1 files changed, 154 insertions(+), 11 deletions(-)
net/netfilter/xt_socket.c +0 -0
index 266faa0..2dbd4c8 100644
 

net/netfilter/xt_socket.c

Quoted 10 lines
net/netfilter/xt_socket.c +10 -0
+static bool
+socket_mt6_v1(const struct sk_buff *skb, struct xt_action_param *par)
+{
+       struct ipv6hdr *iph = ipv6_hdr(skb);
+       struct udphdr _hdr, *hp = NULL;
+       struct sock *sk;
+       struct in6_addr *daddr, *saddr;
+       __be16 dport, sport;
+       int thoff;
+       u8 tproto;

tproto is unsigned...

Quoted 3 lines

+       const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo; +
+       tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);

but ipv6_find_hdr() returns int, and negative values for errors...

Quoted 1 line

+       if (tproto < 0) {

which it can never catch.

Quoted 3 lines

+               pr_debug("unable to find transport header in IPv6 packet, dropping\n");
+               return NF_DROP;
+       }

net/netfilter/xt_socket.c:256: warning: comparison is always false due to limited range of data type

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw

From: Geert Uytterhoeven <[email protected]>
Date: Thu, 28 Oct 2010 20:51:43 +0200

Quoted 9 lines
Quoted 1 line

+       u8 tproto;

tproto is unsigned...

Quoted 3 lines

+       const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo; +
+       tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);

but ipv6_find_hdr() returns int, and negative values for errors...

Thanks Geert, I'll fix it like so:

--------------------
netfilter: xt_socket: Make tproto signed in socket_mt6_v1().

Otherwise error indications from ipv6_find_hdr() won't be noticed.

This required making the protocol argument to extract_icmp6_fields() signed too.

---
 net/netfilter/xt_socket.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
net/netfilter/xt_socket.c +3 -4
index d94a858..00d6ae8 100644
@@ -195,7 +195,7 @@ socket_mt4_v1(const struct sk_buff *skb, struct xt_action_param *par)
 static int
 extract_icmp6_fields(const struct sk_buff *skb,
 		     unsigned int outside_hdrlen,
-		     u8 *protocol,
+		     int *protocol,
 		     struct in6_addr **raddr,
 		     struct in6_addr **laddr,
 		     __be16 *rport,
@@ -252,8 +252,7 @@ socket_mt6_v1(const struct sk_buff *skb, struct xt_action_param *par)
 	struct sock *sk;
 	struct in6_addr *daddr, *saddr;
 	__be16 dport, sport;
-	int thoff;
-	u8 tproto;
+	int thoff, tproto;
 	const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo;
 
 	tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);
@@ -305,7 +304,7 @@ socket_mt6_v1(const struct sk_buff *skb, struct xt_action_param *par)
 			sk = NULL;
 	}
 
-	pr_debug("proto %hhu %pI6:%hu -> %pI6:%hu "
+	pr_debug("proto %hhd %pI6:%hu -> %pI6:%hu "
 		 "(orig %pI6:%hu) sock %p\n",
 		 tproto, saddr, ntohs(sport),
 		 daddr, ntohs(dport),
Signature · 6 lines
1.7.3.2

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Am 28.10.2010 22:00, schrieb David Miller:

Quoted 18 lines

From: Geert Uytterhoeven <[email protected]>
Date: Thu, 28 Oct 2010 20:51:43 +0200

Quoted 9 lines
Quoted 1 line

+ u8 tproto;

tproto is unsigned...

Review

Quoted 3 lines
(quoted diff) +3 -0
+       const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo;
+
+       tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);

but ipv6_find_hdr() returns int, and negative values for errors...

Thanks Geert, I'll fix it like so:

--------------------
netfilter: xt_socket: Make tproto signed in socket_mt6_v1().

Quoted 7 lines

Otherwise error indications from ipv6_find_hdr() won't be noticed.

This required making the protocol argument to extract_icmp6_fields() signed too.

Thanks for taking care of this Dave.