From 9bec4540ed4d47679dd357f8c46972fd59b02f37 Mon Sep 17 00:00:00 2001 From: Fedor Date: Mon, 28 Feb 2011 17:49:40 -0500 Subject: [PATCH] rc: reset iface IP address on wan [re]connect for MASQUERADE to clean up the conntrack entries after getting the WAN IP --- release/src/router/rc/dhcp.c | 1 + release/src/router/rc/firewall.c | 4 +++- release/src/router/rc/init.c | 2 +- release/src/router/rc/interface.c | 13 +++++++++++-- release/src/router/rc/ppp.c | 20 ++++++++++++-------- release/src/router/rc/rc.h | 3 ++- release/src/router/rc/wan.c | 3 +++ 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/release/src/router/rc/dhcp.c b/release/src/router/rc/dhcp.c index 69d8471a68..1dc4a9b40c 100644 --- a/release/src/router/rc/dhcp.c +++ b/release/src/router/rc/dhcp.c @@ -247,6 +247,7 @@ static int bound(char *ifname, int renew) TRACE_PT("wan_routes1=%s\n", nvram_safe_get("wan_routes1")); TRACE_PT("wan_routes2=%s\n", nvram_safe_get("wan_routes2")); + ifconfig(ifname, IFUP, "0.0.0.0", NULL); ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), netmask); if (wan_proto != WP_DHCP) { diff --git a/release/src/router/rc/firewall.c b/release/src/router/rc/firewall.c index 77312f1367..544a6be244 100644 --- a/release/src/router/rc/firewall.c +++ b/release/src/router/rc/firewall.c @@ -1131,7 +1131,6 @@ int start_firewall(void) simple_lock("firewall"); simple_lock("restrictions"); - wanproto = get_wan_proto(); wanup = check_wanup(); f_write_string("/proc/sys/net/ipv4/tcp_syncookies", nvram_get_int("ne_syncookies") ? "1" : "0", 0, 0); @@ -1157,6 +1156,9 @@ int start_firewall(void) f_write_string("/proc/sys/net/ipv4/tcp_rfc1337", "1", 0, 0); f_write_string("/proc/sys/net/ipv4/ip_local_port_range", "1024 65535", 0, 0); + wanproto = get_wan_proto(); + f_write_string("/proc/sys/net/ipv4/ip_dynaddr", (wanproto == WP_DISABLED || wanproto == WP_STATIC) ? "0" : "1", 0, 0); + #ifdef TCONFIG_EMF /* Force IGMPv2 due EMF limitations */ if (nvram_get_int("emf_enable")) { diff --git a/release/src/router/rc/init.c b/release/src/router/rc/init.c index 3011ae6e52..4c76832ef8 100644 --- a/release/src/router/rc/init.c +++ b/release/src/router/rc/init.c @@ -1158,7 +1158,7 @@ static int init_nvram(void) //nvram_set("wl_country_code", "JP"); nvram_set("wan_get_dns", ""); nvram_set("wan_get_domain", ""); - nvram_set("pppoe_pid0", ""); + nvram_set("ppp_get_ip", ""); nvram_set("action_service", ""); nvram_set("jffs2_format", "0"); nvram_set("rrules_radio", "-1"); diff --git a/release/src/router/rc/interface.c b/release/src/router/rc/interface.c index 98cc8957b0..c6621d717a 100644 --- a/release/src/router/rc/interface.c +++ b/release/src/router/rc/interface.c @@ -37,7 +37,7 @@ #include "rc.h" -int ifconfig(const char *name, int flags, const char *addr, const char *netmask) +int _ifconfig(const char *name, int flags, const char *addr, const char *netmask, const char *dstaddr) { int s; struct ifreq ifr; @@ -80,6 +80,15 @@ int ifconfig(const char *name, int flags, const char *addr, const char *netmask) goto ERROR; } + /* Set dst or P-t-P IP address */ + if (dstaddr) { + inet_aton(dstaddr, &in_addr); + sin_addr(&ifr.ifr_dstaddr).s_addr = in_addr.s_addr; + ifr.ifr_dstaddr.sa_family = AF_INET; + if (ioctl(s, SIOCSIFDSTADDR, &ifr) < 0) + goto ERROR; + } + close(s); return 0; @@ -87,7 +96,7 @@ int ifconfig(const char *name, int flags, const char *addr, const char *netmask) close(s); perror(name); return errno; -} +} static int route_manip(int cmd, char *name, int metric, char *dst, char *gateway, char *genmask) { diff --git a/release/src/router/rc/ppp.c b/release/src/router/rc/ppp.c index 8dee3f0d75..a15fbfba93 100644 --- a/release/src/router/rc/ppp.c +++ b/release/src/router/rc/ppp.c @@ -59,11 +59,14 @@ int ipup_main(int argc, char **argv) f_write_string("/tmp/ppp/link", argv[1], 0, 0); + if ((p = getenv("IPREMOTE"))) { + nvram_set("wan_gateway_get", p); + TRACE_PT("IPREMOTE=%s\n", p); + } + if ((value = getenv("IPLOCAL"))) { _dprintf("IPLOCAL=%s\n", value); - ifconfig(wan_ifname, IFUP, value, "255.255.255.255"); - switch (get_wan_proto()) { case WP_PPPOE: nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr")); // store last ip address @@ -73,14 +76,15 @@ int ipup_main(int argc, char **argv) case WP_PPTP: case WP_L2TP: nvram_set("wan_ipaddr_buf", nvram_safe_get("ppp_get_ip")); - nvram_set("ppp_get_ip", value); break; } - } - if ((value = getenv("IPREMOTE"))) { - nvram_set("wan_gateway_get", value); - TRACE_PT("IPREMOTE=%s\n", value); + if (!nvram_match("ppp_get_ip", value)) { + ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); + nvram_set("ppp_get_ip", value); + } + + _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", (p && (*p)) ? p : NULL); } buf[0] = 0; @@ -134,7 +138,7 @@ int ipdown_main(int argc, char **argv) route_add(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0"); } - if ((nvram_get_int("ppp_demand")) && ((proto == WP_PPTP) || (proto == WP_L2TP) || (proto == WP_PPPOE))) { + if (nvram_get_int("ppp_demand")) { killall("listen", SIGKILL); eval("listen", nvram_safe_get("lan_ifname")); } diff --git a/release/src/router/rc/rc.h b/release/src/router/rc/rc.h index b916a289a4..832ebf6a0c 100644 --- a/release/src/router/rc/rc.h +++ b/release/src/router/rc/rc.h @@ -99,7 +99,8 @@ extern int reboothalt_main(int argc, char *argv[]); extern int console_main(int argc, char *argv[]); // interface.c -extern int ifconfig(const char *ifname, int flags, const char *addr, const char *netmask); +extern int _ifconfig(const char *name, int flags, const char *addr, const char *netmask, const char *dstaddr); +#define ifconfig(name, flags, addr, netmask) _ifconfig(name, flags, addr, netmask, NULL) extern int route_add(char *name, int metric, char *dst, char *gateway, char *genmask); extern void route_del(char *name, int metric, char *dst, char *gateway, char *genmask); extern void config_loopback(void); diff --git a/release/src/router/rc/wan.c b/release/src/router/rc/wan.c index 13a619b0ca..5152e80d22 100644 --- a/release/src/router/rc/wan.c +++ b/release/src/router/rc/wan.c @@ -638,6 +638,8 @@ void start_wan(int mode) ifconfig(wan_ifname, IFUP, NULL, NULL); + start_firewall(); + set_host_domain_name(); switch (wan_proto) { @@ -652,6 +654,7 @@ void start_wan(int mode) start_dhcpc(); } else if (wan_proto != WP_DHCP) { + ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); ifconfig(wan_ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask")); p = nvram_safe_get("wan_gateway"); -- 2.11.4.GIT