[Javanetsim-cvs] javaNetSim/core CommandProcessor.java, 1.9, 1.10 CommandsTree.java, 1.6, 1.7
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2008-09-10 21:35:53
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv24306/core Modified Files: CommandProcessor.java CommandsTree.java Log Message: "ip route " command was fixed Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CommandProcessor.java 17 Nov 2007 21:38:57 -0000 1.9 --- CommandProcessor.java 10 Sep 2008 21:35:37 -0000 1.10 *************** *** 2,6 **** * CommandProcessor.java * ! * Created on 11 Îêòÿáðü 2007 ã., 20:42 * * To change this template, choose Tools | Template Manager --- 2,6 ---- * CommandProcessor.java * ! * Created on 11 ������� 2007 �., 20:42 * * To change this template, choose Tools | Template Manager *************** *** 21,24 **** --- 21,26 ---- import core.protocolsuite.tcp_ip.UDP_session; import core.protocolsuite.tcp_ip.jnSocket; + + import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; *************** *** 1102,1116 **** } //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if(add){ ! device.getACL().addACL(iacl, iline, action, ip, mask, log); ! } ! else{ ! if(iline==-1){ ! device.getACL().removeACL(iacl, action, ip, mask); } else{ ! device.getACL().removeACL(iacl, iline); } } } else{ --- 1104,1123 ---- } //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if(IPV4Address.validateDecIP(ip) && IPV4Address.validateDecSubnetMask(mask, ip)){ ! if(add){ ! device.getACL().addACL(iacl, iline, action, ip, mask, log); } else{ ! if(iline==-1){ ! device.getACL().removeACL(iacl, action, ip, mask); ! } ! else{ ! device.getACL().removeACL(iacl, iline); ! } } } + else{ + out += "error: invalid IP address or subnet mask\n"; + } } else{ *************** *** 1251,1271 **** //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if(port >= 0){ ! if(port==0 || (protocol == AccessListEngine.access_list.TCP || protocol == AccessListEngine.access_list.UDP)){ ! if(add){ ! device.getACL().addACL(iacl, iline, action, protocol, ip1, mask1, ip2, mask2, port, log); ! } ! else{ ! if(iline==-1){ ! device.getACL().removeACL(iacl, action, protocol, ip1, mask1, ip2, mask2, port); } else{ ! device.getACL().removeACL(iacl, iline); } } } else{ ! out += "error: invalid parameter 'eq "+port+"'\n"; ! port = -1; } } --- 1258,1284 ---- //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if(port >= 0){ ! if(IPV4Address.validateDecIP(ip1) && IPV4Address.validateDecSubnetMask(mask1, ip1) && ! IPV4Address.validateDecIP(ip2) && IPV4Address.validateDecSubnetMask(mask2, ip2)){ ! if(port==0 || (protocol == AccessListEngine.access_list.TCP || protocol == AccessListEngine.access_list.UDP)){ ! if(add){ ! device.getACL().addACL(iacl, iline, action, protocol, ip1, mask1, ip2, mask2, port, log); } else{ ! if(iline==-1){ ! device.getACL().removeACL(iacl, action, protocol, ip1, mask1, ip2, mask2, port); ! } ! else{ ! device.getACL().removeACL(iacl, iline); ! } } } + else{ + out += "error: invalid parameter 'eq "+port+"'\n"; + port = -1; + } } else{ ! out += "error: invalid IP address or subnet mask\n"; } } *************** *** 1585,1606 **** public ip_nat_inside_destination_list_CommandClass(){ modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); ! call_params = "<1-2699 | WORD> pool <pool> [overload]"; ! no_call_params = "<1-2699 | WORD> pool <pool>"; } public String call(Vector<String> params){ ! String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); ! device.getConfig().add(""); ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! return out; } public String no_call(Vector<String> params){ String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); } else{ --- 1598,1640 ---- public ip_nat_inside_destination_list_CommandClass(){ modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); ! call_params = "<1-2699> pool <pool> [overload]"; ! no_call_params = "<1-2699> pool <pool>"; } public String call(Vector<String> params){ ! return parse(params, true); } public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ String out = ""; ! if(params.size()==3 || params.size()==4){ ! try{ ! int iacl = Integer.parseInt(params.get(0)); ! if(iacl>=1 && iacl<=2699){ ! if(params.get(1).equalsIgnoreCase("pool")){ ! String poolname = params.get(2); ! boolean overload = false; ! if(params.size()==4){ ! overload = params.get(3).equalsIgnoreCase("overload"); ! } ! if(add){ ! //nat.inside.dest.list.add(iacl,poolname,overload); ! } ! else{ ! //nat.inside.dest.list.remove(iacl,poolname); ! } ! } ! else{ ! out += "error: invalid parameter '"+params.get(1)+"'\n"; ! } ! } ! else{ ! out += "error: invalid ACL name '"+params.get(0)+"', ACL name must be number from 1 to 2699\n"; ! } ! } ! catch(NumberFormatException e){ ! out += "error: invalid ACL name '"+params.get(0)+"', ACL name must be number from 1 to 2699\n"; ! } } else{ *************** *** 1613,1634 **** public ip_nat_inside_source_list_CommandClass(){ modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); ! call_params = "<1-2699 | WORD> (pool <pool>|interface <interface>) overload"; ! no_call_params = "<1-2699 | WORD> (pool <pool>|interface <interface>)"; } public String call(Vector<String> params){ ! String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); ! device.getConfig().add(""); ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! return out; } public String no_call(Vector<String> params){ String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); } else{ --- 1647,1689 ---- public ip_nat_inside_source_list_CommandClass(){ modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); ! call_params = "<1-2699> (pool <pool>|interface <interface>) overload"; ! no_call_params = "<1-2699> (pool <pool>|interface <interface>)"; } public String call(Vector<String> params){ ! return parse(params, true); } public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ String out = ""; ! if(params.size()==3 || params.size()==4){ ! try{ ! int iacl = Integer.parseInt(params.get(0)); ! if(iacl>=1 && iacl<=2699){ ! if(params.get(1).equalsIgnoreCase("pool")){ ! String poolname = params.get(2); ! boolean overload = false; ! if(params.size()==4){ ! overload = params.get(3).equalsIgnoreCase("overload"); ! } ! if(add){ ! //nat.inside.src.list.add(iacl,poolname,overload); ! } ! else{ ! //nat.inside.src.list.remove(iacl,poolname); ! } ! } ! else{ ! out += "error: invalid parameter '"+params.get(1)+"'\n"; ! } ! } ! else{ ! out += "error: invalid ACL name '"+params.get(0)+"', ACL name must be number from 1 to 2699\n"; ! } ! } ! catch(NumberFormatException e){ ! out += "error: invalid ACL name '"+params.get(0)+"', ACL name must be number from 1 to 2699\n"; ! } } else{ *************** *** 1645,1662 **** } public String call(Vector<String> params){ ! String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); ! device.getConfig().add(""); ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! return out; } public String no_call(Vector<String> params){ String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); } else{ --- 1700,1756 ---- } public String call(Vector<String> params){ ! return parse(params, true); } public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ + int IP_protocol = 0; + int TCP_protocol = 1; + int UDP_protocol = 2; + String out = ""; ! if(params.size()==3 || params.size()==5){ ! try{ ! String sprotocol = params.get(0); ! int protocol = -1; ! int local_port = 0; ! int global_port = 0; ! String local_ip = ""; ! String global_ip = ""; ! if(sprotocol.equalsIgnoreCase("ip")){ ! protocol = IP_protocol; ! } ! else if(sprotocol.equalsIgnoreCase("tcp")){ ! protocol = TCP_protocol; ! } ! else if(sprotocol.equalsIgnoreCase("udp")){ ! protocol = UDP_protocol; ! } ! if(params.size()==3){ ! local_ip = params.get(1); ! global_ip = params.get(2); ! } ! else if(params.size()==5 && (protocol==TCP_protocol || protocol==UDP_protocol)){ ! local_ip = params.get(1); ! local_port = Integer.parseInt(params.get(2)); ! global_ip = params.get(3); ! global_port = Integer.parseInt(params.get(4)); ! if(local_port<=0 || global_port<=0 || local_port>65535 || global_port>65535){ ! throw new NumberFormatException(); ! } ! } ! if(IPV4Address.validateDecIP(local_ip) && IPV4Address.validateDecIP(global_ip)){ ! if(add){ ! //nat.inside.src.static.add(protocol, local_ip, local_port, global_ip, global_port); ! } ! else{ ! //nat.inside.src.static.remove(protocol, local_ip, local_port, global_ip, global_port); ! } ! } ! } ! catch(NumberFormatException e){ ! out += "error: invalid port number\n"; ! } } else{ *************** *** 1673,1690 **** } public String call(Vector<String> params){ ! String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); ! device.getConfig().add(""); ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! return out; } public String no_call(Vector<String> params){ String out = ""; ! if(params.size()>=3){ ! device.getConfig().remove("^"); } else{ --- 1767,1789 ---- } public String call(Vector<String> params){ ! return parse(params, true); } public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ String out = ""; ! if(params.size()==3){ ! String poolname = params.get(0); ! String low_ip = params.get(1); ! String high_ip = params.get(2); ! if(IPV4Address.validateDecIP(low_ip) && IPV4Address.validateDecIP(high_ip)){ ! if(add){ ! //nat.pool.add(poolname, low_ip, high_ip); ! } ! else{ ! //nat.pool.remove(poolname, low_ip, high_ip); ! } ! } } else{ *************** *** 1724,1729 **** } else{ ! device.addRoute(new Route_entry(params.get(0), params.get(2), params.get(1), params.get(3), 0)); ! out+="Route added.\n"; } } --- 1823,1847 ---- } else{ ! try { ! String iface = null; ! if(params.size()==4) iface = params.get(3); ! else{ ! IPV4Address gw = new IPV4Address(params.get(2)); ! ArrayList<?> ifaces = device.getAllInterfacesNames(); ! boolean found = false; ! for(int i=0; i<ifaces.size() && !found; i++){ ! iface = (String) ifaces.get(i); ! gw.setCustomSubnetMask(device.getSubnetMask(iface)); ! found = gw.compareToSubnet(device.getIPAddress(iface)); ! } ! } ! device.addRoute(new Route_entry(params.get(0), params.get(2), params.get(1), iface, 0)); ! out+="Route added.\n"; ! } catch (InvalidIPAddressException e) { ! out+="error: invalid gateway ip address.\n"; ! } catch (InvalidSubnetMaskException e) { ! out+="internal error: invalid subnet mask!\n"; ! e.printStackTrace(); ! } } } Index: CommandsTree.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandsTree.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CommandsTree.java 17 Nov 2007 21:38:58 -0000 1.6 --- CommandsTree.java 10 Sep 2008 21:35:37 -0000 1.7 *************** *** 2,6 **** * CommandsTree.java * ! * Created on 5 Îêòÿáðü 2007 ã., 19:36 * * To change this template, choose Tools | Template Manager --- 2,6 ---- * CommandsTree.java * ! * Created on 5 ������� 2007 �., 19:36 * * To change this template, choose Tools | Template Manager *************** *** 312,320 **** vprms.add(cmds[i]); } ! if(cmds[0].equalsIgnoreCase("no")){ ! result = func.no_call(vprms); } ! else{ ! result = func.call(vprms); } } --- 312,325 ---- vprms.add(cmds[i]); } ! try{ ! if(cmds[0].equalsIgnoreCase("no")){ ! result = func.no_call(vprms); ! } ! else{ ! result = func.call(vprms); ! } } ! catch(Exception e){ ! result = "Fatal error was occur. Please contact to developer.\nAdditional info: "+e.toString()+"\n"; } } |