From: "Jorge Boncompte [DTI2]" Subject: Re: [PATCH] xx_nat_proto_gre: gre_key returns wrong pointer Date: Thu, 26 Apr 2007 19:34:29 +0200 Message-ID: <101c01c78829$24a70230$061010ac@intranet.dti2.net> References: <00c501c7829e$6209edd0$061010ac@intranet.dti2.net> <462DFD1D.1060706@trash.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_1019_01C78839.E8073B90" To: Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: netfilter-devel-bounces@lists.netfilter.org Errors-To: netfilter-devel-bounces@lists.netfilter.org List-Id: netfilter-devel.vger.kernel.org This is a multi-part message in MIME format. ------=_NextPart_000_1019_01C78839.E8073B90 Content-Type: text/plain; format=flowed; charset="iso-8859-15"; reply-type=original Content-Transfer-Encoding: 7bit ----- Original Message ----- From: "Patrick McHardy" To: "Jorge Boncompte [DTI2]" Cc: Sent: Tuesday, April 24, 2007 2:50 PM Subject: Re: [PATCH] xx_nat_proto_gre: gre_key returns wrong pointer > Good catch. I think what it should do is not touch the key/checksum of > version 0 GRE packets at all since the intention is to behave identical > to nf_conntrack_proto_generic/nf_nat_proto_unknown in that case. > > Its a bit more complicated to do this because we also need to avoid > altering the tuple in gre_unique_tuple. If you want to give it a try > please go ahead, otherwise I can look into it. Hi, Patrick take a look at this patch when you have time please. I tested it and behaves correctly, I can run one and only one GRE tunnel though a NATing box and PPTP still works too, if you try with a second tunnel from different host by the fact of not modifying the tuple it does not work as the comment in get_unique_tuple says. diff -uNr linux-2.6.21.orig/include/linux/netfilter/nf_conntrack_proto_gre.h linux-2.6.21/include/linux/netfilter/nf_conntrack_proto_gre.h --- linux-2.6.21.orig/include/linux/netfilter/nf_conntrack_proto_gre.h 2007-04-26 18:10:56.000000000 +0200 +++ linux-2.6.21/include/linux/netfilter/nf_conntrack_proto_gre.h 2007-04-26 18:53:58.000000000 +0200 @@ -87,24 +87,6 @@ /* delete keymap entries */ void nf_ct_gre_keymap_destroy(struct nf_conn *ct); -/* get pointer to gre key, if present */ -static inline __be32 *gre_key(struct gre_hdr *greh) -{ - if (!greh->key) - return NULL; - if (greh->csum || greh->routing) - return (__be32 *)(greh+sizeof(*greh)+4); - return (__be32 *)(greh+sizeof(*greh)); -} - -/* get pointer ot gre csum, if present */ -static inline __sum16 *gre_csum(struct gre_hdr *greh) -{ - if (!greh->csum) - return NULL; - return (__sum16 *)(greh+sizeof(*greh)); -} - extern void nf_ct_gre_keymap_flush(void); extern void nf_nat_need_gre(void); diff -uNr linux-2.6.21.orig/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h linux-2.6.21/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h --- linux-2.6.21.orig/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h 2007-04-26 18:10:56.000000000 +0200 +++ linux-2.6.21/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h 2007-04-26 18:54:39.000000000 +0200 @@ -90,25 +90,6 @@ /* delete keymap entries */ void ip_ct_gre_keymap_destroy(struct ip_conntrack *ct); - -/* get pointer to gre key, if present */ -static inline __be32 *gre_key(struct gre_hdr *greh) -{ - if (!greh->key) - return NULL; - if (greh->csum || greh->routing) - return (__be32 *) (greh+sizeof(*greh)+4); - return (__be32 *) (greh+sizeof(*greh)); -} - -/* get pointer ot gre csum, if present */ -static inline __sum16 *gre_csum(struct gre_hdr *greh) -{ - if (!greh->csum) - return NULL; - return (__sum16 *) (greh+sizeof(*greh)); -} - #endif /* __KERNEL__ */ #endif /* _CONNTRACK_PROTO_GRE_H */ diff -uNr linux-2.6.21.orig/net/ipv4/netfilter/ip_nat_proto_gre.c linux-2.6.21/net/ipv4/netfilter/ip_nat_proto_gre.c --- linux-2.6.21.orig/net/ipv4/netfilter/ip_nat_proto_gre.c 2007-04-26 18:10:57.000000000 +0200 +++ linux-2.6.21/net/ipv4/netfilter/ip_nat_proto_gre.c 2007-04-26 19:01:02.000000000 +0200 @@ -70,6 +70,11 @@ __be16 *keyptr; unsigned int min, i, range_size; + /* If there is no master conntrack we are not PPTP, + do not change tuples */ + if (!conntrack->master) + return 0; + if (maniptype == IP_NAT_MANIP_SRC) keyptr = &tuple->src.u.gre.key; else @@ -122,18 +127,9 @@ if (maniptype == IP_NAT_MANIP_DST) { /* key manipulation is always dest */ switch (greh->version) { - case 0: - if (!greh->key) { - DEBUGP("can't nat GRE w/o key\n"); - break; - } - if (greh->csum) { - /* FIXME: Never tested this code... */ - nf_proto_csum_replace4(gre_csum(greh), *pskb, - *(gre_key(greh)), - tuple->dst.u.gre.key, 0); - } - *(gre_key(greh)) = tuple->dst.u.gre.key; + case GRE_VERSION_1701: + /* FIXME: We do not currently NAT any GREv0 packets */ + /* try to behave like "ip_nat_proto_unknown" */ break; case GRE_VERSION_PPTP: DEBUGP("call_id -> 0x%04x\n", diff -uNr linux-2.6.21.orig/net/ipv4/netfilter/nf_nat_proto_gre.c linux-2.6.21/net/ipv4/netfilter/nf_nat_proto_gre.c --- linux-2.6.21.orig/net/ipv4/netfilter/nf_nat_proto_gre.c 2007-04-26 18:11:11.000000000 +0200 +++ linux-2.6.21/net/ipv4/netfilter/nf_nat_proto_gre.c 2007-04-26 19:01:25.000000000 +0200 @@ -72,6 +72,11 @@ __be16 *keyptr; unsigned int min, i, range_size; + /* If there is no master conntrack we are not PPTP, + do not change tuples */ + if (!conntrack->master) + return 0; + if (maniptype == IP_NAT_MANIP_SRC) keyptr = &tuple->src.u.gre.key; else @@ -122,18 +127,9 @@ if (maniptype != IP_NAT_MANIP_DST) return 1; switch (greh->version) { - case 0: - if (!greh->key) { - DEBUGP("can't nat GRE w/o key\n"); - break; - } - if (greh->csum) { - /* FIXME: Never tested this code... */ - nf_proto_csum_replace4(gre_csum(greh), *pskb, - *(gre_key(greh)), - tuple->dst.u.gre.key, 0); - } - *(gre_key(greh)) = tuple->dst.u.gre.key; + case GRE_VERSION_1701: + /* FIXME: We do not currently NAT any GREv0 packets */ + /* try to behave like "nf_nat_proto_unknown" */ break; case GRE_VERSION_PPTP: DEBUGP("call_id -> 0x%04x\n", ntohs(tuple->dst.u.gre.key)); -Jorge =============================================================== Jorge Boncompte - Ingenieria y Gestion de RED DTI2 - Desarrollo de la Tecnologia de las Comunicaciones -------------------------------------------------------------- C/ Abogado Enriquez Barrios, 5 14004 CORDOBA (SPAIN) Tlf: +34 957 761395 / FAX: +34 957 450380 ============================================================== - Sin pistachos no hay Rock & Roll... - Without wicker a basket cannot be made. ============================================================== ------=_NextPart_000_1019_01C78839.E8073B90 Content-Type: application/octet-stream; name="nat-proto-gre-patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="nat-proto-gre-patch" diff -uNr -X /root/diff-no-incluir = linux-2.6.21.orig/include/linux/netfilter/nf_conntrack_proto_gre.h = linux-2.6.21/include/linux/netfilter/nf_conntrack_proto_gre.h=0A= --- linux-2.6.21.orig/include/linux/netfilter/nf_conntrack_proto_gre.h = 2007-04-26 18:10:56.000000000 +0200=0A= +++ linux-2.6.21/include/linux/netfilter/nf_conntrack_proto_gre.h = 2007-04-26 18:53:58.000000000 +0200=0A= @@ -87,24 +87,6 @@=0A= /* delete keymap entries */=0A= void nf_ct_gre_keymap_destroy(struct nf_conn *ct);=0A= =0A= -/* get pointer to gre key, if present */=0A= -static inline __be32 *gre_key(struct gre_hdr *greh)=0A= -{=0A= - if (!greh->key)=0A= - return NULL;=0A= - if (greh->csum || greh->routing)=0A= - return (__be32 *)(greh+sizeof(*greh)+4);=0A= - return (__be32 *)(greh+sizeof(*greh));=0A= -}=0A= -=0A= -/* get pointer ot gre csum, if present */=0A= -static inline __sum16 *gre_csum(struct gre_hdr *greh)=0A= -{=0A= - if (!greh->csum)=0A= - return NULL;=0A= - return (__sum16 *)(greh+sizeof(*greh));=0A= -}=0A= -=0A= extern void nf_ct_gre_keymap_flush(void);=0A= extern void nf_nat_need_gre(void);=0A= =0A= diff -uNr -X /root/diff-no-incluir = linux-2.6.21.orig/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h = linux-2.6.21/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h=0A= --- = linux-2.6.21.orig/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h = 2007-04-26 18:10:56.000000000 +0200=0A= +++ linux-2.6.21/include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h = 2007-04-26 18:54:39.000000000 +0200=0A= @@ -90,25 +90,6 @@=0A= /* delete keymap entries */=0A= void ip_ct_gre_keymap_destroy(struct ip_conntrack *ct);=0A= =0A= -=0A= -/* get pointer to gre key, if present */=0A= -static inline __be32 *gre_key(struct gre_hdr *greh)=0A= -{=0A= - if (!greh->key)=0A= - return NULL;=0A= - if (greh->csum || greh->routing)=0A= - return (__be32 *) (greh+sizeof(*greh)+4);=0A= - return (__be32 *) (greh+sizeof(*greh));=0A= -}=0A= -=0A= -/* get pointer ot gre csum, if present */=0A= -static inline __sum16 *gre_csum(struct gre_hdr *greh)=0A= -{=0A= - if (!greh->csum)=0A= - return NULL;=0A= - return (__sum16 *) (greh+sizeof(*greh));=0A= -}=0A= -=0A= #endif /* __KERNEL__ */=0A= =0A= #endif /* _CONNTRACK_PROTO_GRE_H */=0A= diff -uNr -X /root/diff-no-incluir = linux-2.6.21.orig/net/ipv4/netfilter/ip_nat_proto_gre.c = linux-2.6.21/net/ipv4/netfilter/ip_nat_proto_gre.c=0A= --- linux-2.6.21.orig/net/ipv4/netfilter/ip_nat_proto_gre.c 2007-04-26 = 18:10:57.000000000 +0200=0A= +++ linux-2.6.21/net/ipv4/netfilter/ip_nat_proto_gre.c 2007-04-26 = 19:01:02.000000000 +0200=0A= @@ -70,6 +70,11 @@=0A= __be16 *keyptr;=0A= unsigned int min, i, range_size;=0A= =0A= + /* If there is no master conntrack we are not PPTP,=0A= + do not change tuples */=0A= + if (!conntrack->master)=0A= + return 0;=0A= + =0A= if (maniptype =3D=3D IP_NAT_MANIP_SRC)=0A= keyptr =3D &tuple->src.u.gre.key;=0A= else=0A= @@ -122,18 +127,9 @@=0A= if (maniptype =3D=3D IP_NAT_MANIP_DST) {=0A= /* key manipulation is always dest */=0A= switch (greh->version) {=0A= - case 0:=0A= - if (!greh->key) {=0A= - DEBUGP("can't nat GRE w/o key\n");=0A= - break;=0A= - }=0A= - if (greh->csum) {=0A= - /* FIXME: Never tested this code... */=0A= - nf_proto_csum_replace4(gre_csum(greh), *pskb,=0A= - *(gre_key(greh)),=0A= - tuple->dst.u.gre.key, 0);=0A= - }=0A= - *(gre_key(greh)) =3D tuple->dst.u.gre.key;=0A= + case GRE_VERSION_1701:=0A= + /* FIXME: We do not currently NAT any GREv0 packets */=0A= + /* try to behave like "ip_nat_proto_unknown" */=0A= break;=0A= case GRE_VERSION_PPTP:=0A= DEBUGP("call_id -> 0x%04x\n",=0A= diff -uNr -X /root/diff-no-incluir = linux-2.6.21.orig/net/ipv4/netfilter/nf_nat_proto_gre.c = linux-2.6.21/net/ipv4/netfilter/nf_nat_proto_gre.c=0A= --- linux-2.6.21.orig/net/ipv4/netfilter/nf_nat_proto_gre.c 2007-04-26 = 18:11:11.000000000 +0200=0A= +++ linux-2.6.21/net/ipv4/netfilter/nf_nat_proto_gre.c 2007-04-26 = 19:01:25.000000000 +0200=0A= @@ -72,6 +72,11 @@=0A= __be16 *keyptr;=0A= unsigned int min, i, range_size;=0A= =0A= + /* If there is no master conntrack we are not PPTP,=0A= + do not change tuples */=0A= + if (!conntrack->master)=0A= + return 0;=0A= + =0A= if (maniptype =3D=3D IP_NAT_MANIP_SRC)=0A= keyptr =3D &tuple->src.u.gre.key;=0A= else=0A= @@ -122,18 +127,9 @@=0A= if (maniptype !=3D IP_NAT_MANIP_DST)=0A= return 1;=0A= switch (greh->version) {=0A= - case 0:=0A= - if (!greh->key) {=0A= - DEBUGP("can't nat GRE w/o key\n");=0A= - break;=0A= - }=0A= - if (greh->csum) {=0A= - /* FIXME: Never tested this code... */=0A= - nf_proto_csum_replace4(gre_csum(greh), *pskb,=0A= - *(gre_key(greh)),=0A= - tuple->dst.u.gre.key, 0);=0A= - }=0A= - *(gre_key(greh)) =3D tuple->dst.u.gre.key;=0A= + case GRE_VERSION_1701:=0A= + /* FIXME: We do not currently NAT any GREv0 packets */=0A= + /* try to behave like "nf_nat_proto_unknown" */=0A= break;=0A= case GRE_VERSION_PPTP:=0A= DEBUGP("call_id -> 0x%04x\n", ntohs(tuple->dst.u.gre.key));=0A= ------=_NextPart_000_1019_01C78839.E8073B90--