Patch for better ip_dynaddr for 2.2.19

Martin Devera (devik@cdi.cz)
Tue, 24 Jul 2001 20:56:44 +0200 (CEST)


I'm sorry that it is for old 2.2.x but I have 2.2.19 router
as MASQ box for our microwave line. I setup automatic backup
via ISDN but I find that masq connections stops working when
ISDN gets dialed.
It is because routing is changed and maddr field is bad in
ip_masq struct.
There is existing solution: sysctl_ip_dynaddr. But it replaces
maddr only on connections where no reply was recieved from outside.
It is true for machine connected via diald for example but when
changing LIVE route it simply doesn't work.
I patched 3 files with very short patch. It allows you to add
4 to sysctl_ip_dynaddr flag and it skips no-reply test.
It works well now.
Patched version is bacward compatible and there is no speed
penalty (well almost).
What about 2.2.20 inclusion ? It this correct place to send patch to ?

devik

--------
diff -ru linux/net/ipv4/ip_masq.c gate2/net/ipv4/ip_masq.c
--- linux/net/ipv4/ip_masq.c Sun Mar 25 18:37:41 2001
+++ gate2/net/ipv4/ip_masq.c Tue Jul 24 20:05:21 2001
@@ -50,6 +50,7 @@
* Kai Bankett : do not toss other IP protos in proto_doff()
* Dan Kegel : pointed correct NAT behavior for UDP streams
* Julian Anastasov : use daddr and dport as hash keys
+ * Martin Devera : extended sysctl_ip_dynaddr functionality
*
*/

@@ -1236,9 +1237,9 @@
* in this tunnel and routing iface address has changed...
* "You are welcome, diald".
*/
- if ( sysctl_ip_dynaddr && ms->flags & IP_MASQ_F_NO_REPLY && maddr != ms->maddr) {
-
- if (sysctl_ip_dynaddr > 1) {
+ if ( sysctl_ip_dynaddr && (sysctl_ip_dynaddr & 4 ||
+ ms->flags & IP_MASQ_F_NO_REPLY) && maddr != ms->maddr) {
+ if ((sysctl_ip_dynaddr & 3) > 1) {
IP_MASQ_INFO( "ip_fw_masquerade(): change masq.addr from %d.%d.%d.%d to %d.%d.%d.%d\n",
NIPQUAD(ms->maddr),NIPQUAD(maddr));
}
@@ -1527,9 +1528,9 @@
* in this tunnel and routing iface address has changed...
* "You are welcome, diald".
*/
- if ( sysctl_ip_dynaddr && ms->flags & IP_MASQ_F_NO_REPLY && maddr != ms->maddr) {
-
- if (sysctl_ip_dynaddr > 1) {
+ if ( sysctl_ip_dynaddr && (sysctl_ip_dynaddr & 4 ||
+ ms->flags & IP_MASQ_F_NO_REPLY) && maddr != ms->maddr) {
+ if ((sysctl_ip_dynaddr & 3) > 1) {
IP_MASQ_INFO( "ip_fw_masq_icmp(): change masq.addr %d.%d.%d.%d to %d.%d.%d.%d",
NIPQUAD(ms->maddr), NIPQUAD(maddr));
}
diff -ru linux/net/ipv4/tcp_ipv4.c gate2/net/ipv4/tcp_ipv4.c
--- linux/net/ipv4/tcp_ipv4.c Sun Mar 25 18:37:41 2001
+++ gate2/net/ipv4/tcp_ipv4.c Tue Jul 24 20:12:06 2001
@@ -1889,7 +1889,7 @@
}

if (new_saddr != sk->saddr) {
- if (sysctl_ip_dynaddr > 1) {
+ if ((sysctl_ip_dynaddr & 3) > 1) {
printk(KERN_INFO "tcp_v4_rebuild_header(): shifting sk->saddr "
"from %d.%d.%d.%d to %d.%d.%d.%d\n",
NIPQUAD(sk->saddr),
--- linux/Documentation/networking/ip_dynaddr.txt Sun Mar 25 18:31:57 2001
+++ gate2/Documentation/networking/ip_dynaddr.txt Tue Jul 24 20:44:42 2001
@@ -23,6 +23,12 @@
# echo 2 > /proc/sys/net/ipv4/ip_dynaddr
To disable (default)
# echo 0 > /proc/sys/net/ipv4/ip_dynaddr
+ To always rewrite MASQ connections instead only when no reply
+ packet is recieved (needed to be able to change routing, for
+ example when doing backup-line) add 4 to flag, like:
+ # echo 5 > /proc/sys/net/ipv4/ip_dynaddr
+ or
+ # echo 6 > /proc/sys/net/ipv4/ip_dynaddr

Enjoy!

---------------

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