RE: IP Masq weirdness

Joseph Gooch (mrwizard@psu.edu)
Fri, 22 Oct 1999 02:10:39 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0020_01BF1C32.A376FD10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

After looking at the masq code again, and some help from Dan Drown, I have a
patch here.

If I broke a cardinal kernel coding rule please let me know :) This works
for me at the moment, but who knows what i broke.

Thanks guys.
Joe

------=_NextPart_000_0020_01BF1C32.A376FD10
Content-Type: application/octet-stream;
name="masq.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="masq.patch"

diff -ru linux-2.2.13-vanilla/net/ipv4/ip_forward.c =
linux-2.2.13-masqfix/net/ipv4/ip_forward.c=0A=
--- linux-2.2.13-vanilla/net/ipv4/ip_forward.c Sun Mar 21 10:22:00 1999=0A=
+++ linux-2.2.13-masqfix/net/ipv4/ip_forward.c Fri Oct 22 01:36:53 1999=0A=
@@ -10,6 +10,8 @@=0A=
* Authors: see ip.c=0A=
*=0A=
* Fixes:=0A=
+ * Joseph Gooch : Changed inet_select_addr to ip_masq_select_addr=0A=
+ * : It's only used for that anyway.=0A=
* Many : Split from ip.c , see ip_input.c for =0A=
* history.=0A=
* Dave Gregorich : NULL ip_rt_put fix for multicast =0A=
@@ -176,7 +178,7 @@=0A=
(icmph->type=3D=3DICMP_TIME_EXCEEDED))=0A=
{=0A=
#endif=0A=
- maddr =3D inet_select_addr(dev2, rt->rt_gateway, RT_SCOPE_UNIVERSE);=0A=
+ maddr =3D ip_masq_select_addr(dev2, rt->rt_gateway, =
RT_SCOPE_UNIVERSE);=0A=
fw_res =3D ip_fw_masq_icmp(&skb, maddr);=0A=
if (fw_res < 0) {=0A=
kfree_skb(skb);=0A=
@@ -187,7 +189,7 @@=0A=
/* ICMP matched - skip firewall */=0A=
goto skip_call_fw_firewall;=0A=
#ifdef CONFIG_IP_MASQUERADE_ICMP=0A=
- }=0A=
+ }=0A=
#endif =0A=
}=0A=
if (rt->rt_flags&RTCF_MASQ)=0A=
@@ -226,7 +228,7 @@=0A=
=0A=
if (maddr =3D=3D 0)=0A=
#endif=0A=
- maddr =3D inet_select_addr(dev2, rt->rt_gateway, RT_SCOPE_UNIVERSE);=0A=
+ maddr =3D ip_masq_select_addr(dev2, rt->rt_gateway, =
RT_SCOPE_UNIVERSE);=0A=
=0A=
if (ip_fw_masquerade(&skb, maddr) < 0) {=0A=
kfree_skb(skb);=0A=
diff -ru linux-2.2.13-vanilla/net/ipv4/ip_masq.c =
linux-2.2.13-masqfix/net/ipv4/ip_masq.c=0A=
--- linux-2.2.13-vanilla/net/ipv4/ip_masq.c Fri Oct 22 01:43:54 1999=0A=
+++ linux-2.2.13-masqfix/net/ipv4/ip_masq.c Fri Oct 22 01:45:19 1999=0A=
@@ -10,6 +10,8 @@=0A=
* See ip_fw.c for original log=0A=
*=0A=
* Fixes:=0A=
+ * Joseph Gooch : Modified ip_masq_select_addr to do a route table =
lookup=0A=
+ * (help by Dan Drown) : to choose the proper local address.=0A=
* Juan Jose Ciarlante : Modularized application masquerading (see =
ip_masq_app.c)=0A=
* Juan Jose Ciarlante : New struct ip_masq_seq that holds output/input =
delta seq.=0A=
* Juan Jose Ciarlante : Added hashed lookup by proto,maddr,mport and =
proto,saddr,sport=0A=
@@ -2480,7 +2482,16 @@=0A=
*/=0A=
u32 ip_masq_select_addr(struct device *dev, u32 dst, int scope)=0A=
{=0A=
- return inet_select_addr(dev, dst, scope);=0A=
+ struct rtable *rt;=0A=
+ u32 maddr;=0A=
+=0A=
+ if (ip_route_output(&rt, dst, 0, 0, dev->ifindex))=0A=
+ return inet_select_addr(dev, dst, scope); /* Fallback on old method */=0A=
+=0A=
+ /* Route lookup succeeded */=0A=
+ maddr =3D rt->rt_src;=0A=
+ ip_rt_put(rt);=0A=
+ return maddr;=0A=
}=0A=
=0A=
/*=0A=

------=_NextPart_000_0020_01BF1C32.A376FD10--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/