From f907e02d5e4ab6c0e30b6421456f5e68db2dca73 Mon Sep 17 00:00:00 2001 From: Augusto Bott Date: Sun, 10 Jul 2011 20:38:08 -0300 Subject: [PATCH] Routing is now multi-LAN aware (static routes and Zebra/RIP, if enabled) --- release/src/router/httpd/tomato.c | 8 ++- release/src/router/nvram/defaults.c | 40 ++++++++++++++ release/src/router/rc/network.c | 15 ++++-- release/src/router/rc/services.c | 67 ++++++++++++++++++++--- release/src/router/www/advanced-routing.asp | 82 +++++++++++++++++++++++++---- 5 files changed, 190 insertions(+), 22 deletions(-) diff --git a/release/src/router/httpd/tomato.c b/release/src/router/httpd/tomato.c index c1935238e6..ec2c618549 100644 --- a/release/src/router/httpd/tomato.c +++ b/release/src/router/httpd/tomato.c @@ -737,7 +737,7 @@ static const nvset_t nvset_list[] = { { "wan_ifnameX", V_TEXT(0,8) }, { "lan_ifnames", V_TEXT(0,64) }, { "manual_boot_nv", V_01 }, - { "trunk_vlan_so",V_01 }, + { "trunk_vlan_so", V_01 }, // advanced-mac { "mac_wan", V_LENGTH(0, 17) }, @@ -752,6 +752,12 @@ static const nvset_t nvset_list[] = { { "dr_setting", V_RANGE(0, 3) }, { "dr_lan_tx", V_LENGTH(0, 32) }, { "dr_lan_rx", V_LENGTH(0, 32) }, + { "dr_lan1_tx", V_LENGTH(0, 32) }, + { "dr_lan1_rx", V_LENGTH(0, 32) }, + { "dr_lan2_tx", V_LENGTH(0, 32) }, + { "dr_lan2_rx", V_LENGTH(0, 32) }, + { "dr_lan3_tx", V_LENGTH(0, 32) }, + { "dr_lan3_rx", V_LENGTH(0, 32) }, { "dr_wan_tx", V_LENGTH(0, 32) }, { "dr_wan_rx", V_LENGTH(0, 32) }, #endif diff --git a/release/src/router/nvram/defaults.c b/release/src/router/nvram/defaults.c index 1a1cc79323..a19f19c67e 100644 --- a/release/src/router/nvram/defaults.c +++ b/release/src/router/nvram/defaults.c @@ -61,6 +61,16 @@ const defaults_t defaults[] = { { "lan_gateway", "0.0.0.0" }, // LAN Gateway { "wl_wds_enable", "0" }, // WDS Enable (0|1) + { "lan1_ipaddr", "" }, + { "lan1_netmask", "" }, + { "lan1_stp", "0" }, + { "lan2_ipaddr", "" }, + { "lan2_netmask", "" }, + { "lan2_stp", "0" }, + { "lan3_ipaddr", "" }, + { "lan3_netmask", "" }, + { "lan3_stp", "0" }, + // WAN H/W parameters //! { "wan_ifname", "" }, // WAN interface name //! { "wan_ifnames", "" }, // WAN interface names @@ -103,6 +113,21 @@ const defaults_t defaults[] = { { "wan_routes", "" }, { "wan_msroutes", "" }, + { "dhcp1_start", "" }, + { "dhcp1_num", "" }, + { "dhcpd1_startip", "" }, + { "dhcpd1_endip", "" }, + { "dhcp1_lease", "0" }, + { "dhcp2_start", "" }, + { "dhcp2_num", "" }, + { "dhcpd2_startip", "" }, + { "dhcpd2_endip", "" }, + { "dhcp2_lease", "0" }, + { "dhcp3_start", "" }, + { "dhcp3_num", "" }, + { "dhcpd3_startip", "" }, + { "dhcpd3_endip", "" }, + { "dhcp3_lease", "0" }, // PPPoE parameters { "pppoe_ifname", "" }, // PPPoE enslaved interface @@ -405,10 +430,19 @@ const defaults_t defaults[] = { { "dr_setting", "0" }, // [ Disable | WAN | LAN | Both ] { "dr_lan_tx", "0" }, // Dynamic-Routing LAN out { "dr_lan_rx", "0" }, // Dynamic-Routing LAN in + { "dr_lan1_tx", "0" }, // Dynamic-Routing LAN out + { "dr_lan1_rx", "0" }, // Dynamic-Routing LAN in + { "dr_lan2_tx", "0" }, // Dynamic-Routing LAN out + { "dr_lan2_rx", "0" }, // Dynamic-Routing LAN in + { "dr_lan3_tx", "0" }, // Dynamic-Routing LAN out + { "dr_lan3_rx", "0" }, // Dynamic-Routing LAN in { "dr_wan_tx", "0" }, // Dynamic-Routing WAN out { "dr_wan_rx", "0" }, // Dynamic-Routing WAN in #endif +// advanced-vlan + { "trunk_vlan_so", "0" }, // VLAN trunk support override + // advanced-wireless { "wl_txant", "3" }, { "wl_txpwr", "42" }, @@ -910,6 +944,12 @@ const defaults_t if_generic[] = { const defaults_t if_vlan[] = { { "lan_ifname", "br0" }, { "lan_ifnames", "vlan0 eth1 eth2 eth3" }, + { "lan1_ifname", "" }, + { "lan1_ifnames", "" }, + { "lan2_ifname", "" }, + { "lan2_ifnames", "" }, + { "lan3_ifname", "" }, + { "lan3_ifnames", "" }, { "wan_ifname", "vlan1" }, { "wan_ifnames", "vlan1" }, { NULL, NULL } diff --git a/release/src/router/rc/network.c b/release/src/router/rc/network.c index 96791a3633..4917cf388d 100644 --- a/release/src/router/rc/network.c +++ b/release/src/router/rc/network.c @@ -563,7 +563,11 @@ void start_lan(void) // Get current LAN hardware address strlcpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); - if (ioctl(sfd, SIOCGIFHWADDR, &ifr) == 0) nvram_set("lan_hwaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); + strcpy(tmp,"lan"); + strcat(tmp,bridge); + strcat(tmp, "_hwaddr"); +// if (ioctl(sfd, SIOCGIFHWADDR, &ifr) == 0) nvram_set("lan_hwaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); + if (ioctl(sfd, SIOCGIFHWADDR, &ifr) == 0) nvram_set(tmp, ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); // Set initial QoS mode for LAN ports set_et_qos_mode(sfd); @@ -674,8 +678,13 @@ void do_static_routes(int add) p = buf; while ((q = strsep(&p, ">")) != NULL) { if (vstrsep(q, "<", &dest, &gateway, &mask, &metric, &ifname) != 5) continue; - ifname = nvram_safe_get((*ifname == 'L') ? "lan_ifname" : - ((*ifname == 'W') ? "wan_iface" : "wan_ifname")); +// ifname = nvram_safe_get((*ifname == 'L') ? "lan_ifname" : +// ((*ifname == 'W') ? "wan_iface" : "wan_ifname")); + ifname = nvram_safe_get(((strcmp(ifname,"LAN")==0) ? "lan_ifname" : + ((strcmp(ifname,"LAN1")==0) ? "lan1_ifname" : + ((strcmp(ifname,"LAN2")==0) ? "lan2_ifname" : + ((strcmp(ifname,"LAN3")==0) ? "lan3_ifname" : + ((*ifname == 'W') ? "wan_iface" : "wan_ifname")))))); if (add) { for (r = 3; r >= 0; --r) { if (route_add(ifname, atoi(metric) + 1, dest, gateway, mask) == 0) break; diff --git a/release/src/router/rc/services.c b/release/src/router/rc/services.c index eff64ef329..6edc95c702 100644 --- a/release/src/router/rc/services.c +++ b/release/src/router/rc/services.c @@ -843,10 +843,21 @@ void start_zebra(void) char *lan_tx = nvram_safe_get("dr_lan_tx"); char *lan_rx = nvram_safe_get("dr_lan_rx"); + char *lan1_tx = nvram_safe_get("dr_lan1_tx"); + char *lan1_rx = nvram_safe_get("dr_lan1_rx"); + char *lan2_tx = nvram_safe_get("dr_lan2_tx"); + char *lan2_rx = nvram_safe_get("dr_lan2_rx"); + char *lan3_tx = nvram_safe_get("dr_lan3_tx"); + char *lan3_rx = nvram_safe_get("dr_lan3_rx"); char *wan_tx = nvram_safe_get("dr_wan_tx"); char *wan_rx = nvram_safe_get("dr_wan_rx"); - if ((*lan_tx == '0') && (*lan_rx == '0') && (*wan_tx == '0') && (*wan_rx == '0')) { +// if ((*lan_tx == '0') && (*lan_rx == '0') && (*wan_tx == '0') && (*wan_rx == '0')) { + if ((*lan_tx == '0') && (*lan_rx == '0') && + (*lan1_tx == '0') && (*lan1_rx == '0') && + (*lan2_tx == '0') && (*lan2_rx == '0') && + (*lan3_tx == '0') && (*lan3_rx == '0') && + (*wan_tx == '0') && (*wan_rx == '0')) { return; } @@ -858,10 +869,20 @@ void start_zebra(void) // if ((fp = fopen("/etc/ripd.conf", "w")) != NULL) { char *lan_ifname = nvram_safe_get("lan_ifname"); + char *lan1_ifname = nvram_safe_get("lan1_ifname"); + char *lan2_ifname = nvram_safe_get("lan2_ifname"); + char *lan3_ifname = nvram_safe_get("lan3_ifname"); char *wan_ifname = nvram_safe_get("wan_ifname"); fprintf(fp, "router rip\n"); - fprintf(fp, "network %s\n", lan_ifname); + if(strcmp(lan_ifname,"")!=0) + fprintf(fp, "network %s\n", lan_ifname); + if(strcmp(lan1_ifname,"")!=0) + fprintf(fp, "network %s\n", lan1_ifname); + if(strcmp(lan2_ifname,"")!=0) + fprintf(fp, "network %s\n", lan2_ifname); + if(strcmp(lan3_ifname,"")!=0) + fprintf(fp, "network %s\n", lan3_ifname); fprintf(fp, "network %s\n", wan_ifname); fprintf(fp, "redistribute connected\n"); //fprintf(fp, "redistribute static\n"); @@ -869,17 +890,47 @@ void start_zebra(void) // 43011: modify by zg 2006.10.18 for cdrouter3.3 item 173(cdrouter_rip_30) bug // fprintf(fp, "redistribute kernel\n"); // 1.11: removed, redistributes indirect -- zzz - fprintf(fp, "interface %s\n", lan_ifname); - if (*lan_tx != '0') fprintf(fp, "ip rip send version %s\n", lan_tx); - if (*lan_rx != '0') fprintf(fp, "ip rip receive version %s\n", lan_rx); - + if(strcmp(lan_ifname,"")!=0) { + fprintf(fp, "interface %s\n", lan_ifname); + if (*lan_tx != '0') fprintf(fp, "ip rip send version %s\n", lan_tx); + if (*lan_rx != '0') fprintf(fp, "ip rip receive version %s\n", lan_rx); + } + if(strcmp(lan1_ifname,"")!=0) { + fprintf(fp, "interface %s\n", lan1_ifname); + if (*lan1_tx != '0') fprintf(fp, "ip rip send version %s\n", lan1_tx); + if (*lan1_rx != '0') fprintf(fp, "ip rip receive version %s\n", lan1_rx); + } + if(strcmp(lan2_ifname,"")!=0) { + fprintf(fp, "interface %s\n", lan2_ifname); + if (*lan2_tx != '0') fprintf(fp, "ip rip send version %s\n", lan2_tx); + if (*lan2_rx != '0') fprintf(fp, "ip rip receive version %s\n", lan2_rx); + } + if(strcmp(lan3_ifname,"")!=0) { + fprintf(fp, "interface %s\n", lan3_ifname); + if (*lan3_tx != '0') fprintf(fp, "ip rip send version %s\n", lan3_tx); + if (*lan3_rx != '0') fprintf(fp, "ip rip receive version %s\n", lan3_rx); + } fprintf(fp, "interface %s\n", wan_ifname); if (*wan_tx != '0') fprintf(fp, "ip rip send version %s\n", wan_tx); if (*wan_rx != '0') fprintf(fp, "ip rip receive version %s\n", wan_rx); fprintf(fp, "router rip\n"); - if (*lan_tx == '0') fprintf(fp, "distribute-list private out %s\n", lan_ifname); - if (*lan_rx == '0') fprintf(fp, "distribute-list private in %s\n", lan_ifname); + if(strcmp(lan_ifname,"")!=0) { + if (*lan_tx == '0') fprintf(fp, "distribute-list private out %s\n", lan_ifname); + if (*lan_rx == '0') fprintf(fp, "distribute-list private in %s\n", lan_ifname); + } + if(strcmp(lan1_ifname,"")!=0) { + if (*lan1_tx == '0') fprintf(fp, "distribute-list private out %s\n", lan1_ifname); + if (*lan1_rx == '0') fprintf(fp, "distribute-list private in %s\n", lan1_ifname); + } + if(strcmp(lan2_ifname,"")!=0) { + if (*lan2_tx == '0') fprintf(fp, "distribute-list private out %s\n", lan2_ifname); + if (*lan2_rx == '0') fprintf(fp, "distribute-list private in %s\n", lan2_ifname); + } + if(strcmp(lan3_ifname,"")!=0) { + if (*lan3_tx == '0') fprintf(fp, "distribute-list private out %s\n", lan3_ifname); + if (*lan3_rx == '0') fprintf(fp, "distribute-list private in %s\n", lan3_ifname); + } if (*wan_tx == '0') fprintf(fp, "distribute-list private out %s\n", wan_ifname); if (*wan_rx == '0') fprintf(fp, "distribute-list private in %s\n", wan_ifname); fprintf(fp, "access-list private deny any\n"); diff --git a/release/src/router/www/advanced-routing.asp b/release/src/router/www/advanced-routing.asp index c213124e05..8e77a746c4 100644 --- a/release/src/router/www/advanced-routing.asp +++ b/release/src/router/www/advanced-routing.asp @@ -45,7 +45,7 @@ + -- 2.11.4.GIT