Пример #1
0
  public int addTunnel(String vipa, String ifName, String ANAddress, int AnTsa) {
    int port = realPortManager.getport(ifName + ANAddress);

    String[] par =
        new String[] {
          "-a",
          "tun",
          "-S",
          vipa,
          "-D",
          Module.getVipaFix(),
          "-i",
          ifName,
          "-d",
          ANAddress,
          "-l",
          "" + port,
          "-r",
          "" + AnTsa
        };

    //		System.err.println("YYYYYY__" + "-a"+ " " +"tun"+ " " +"-S" + " " + vipa+ " " +"-D"+ " "
    // +Module.getVipaFix()+ " " +"-i"+ " " +ifName+ " " +"-d"+ " " +ANAddress+ " " +"-l"+ " "
    // +""+port+ " " +"-r"+ " " +""+AnTsa);

    // TODO PROVA
    //		par[0] = "upmtconf " + par[0];
    //		result = Shell.executeRootCommand(par);

    //		result = Module.upmtconf(par); // chiamata tramite JNI
    result =
        Module.upmtconf(
            par, false); // se impostata a true chiamata a JNI altrimenti chiamata di sistema

    //		System.err.println(result);

    int localTid = Module.getUpmtParameter(result, "TID");
    if (localTid == 0) {
      printLog("TUNNEL NON CREATO", Log.LEVEL_HIGH);
      return 0;
    }

    localTidTable.put(ifName + ":" + ANAddress, new Integer(localTid));
    UPMTClient.addRMETunnelsToGUI(ANAddress);
    tidToANTable.put(new Integer(localTid), ANAddress);

    return localTid;
  }
Пример #2
0
  /**
   * Signal UPMT module to control a network interface<br>
   * it is not yet sure if this interface can be used (i.e. if it provides connectivity towards any
   * AN or fixed host)
   *
   * @param ifName - The name of the interface to be controlled
   * @param defaultGW - The default GateWay for ifName
   */
  public void addInterface(String ifName, InterfaceInfo newIf) {
    // #ifndef ANDROID
    Shell.executeCommand(
        new String[] {
          "ip",
          "route",
          "add",
          newIf.prefix + "/" + newIf.netmask,
          "dev",
          ifName,
          "table",
          "upmt0_table"
        });
    // #else
    //				result = Shell.executeRootCommand(new String[]{"ip", "route", "add", newIf.prefix +"/" +
    // newIf.netmask, "dev", ifName, "table", "upmt0_table"});
    // #endif

    // #ifndef ANDROID
    result = Shell.executeCommand(new String[] {"route", "del", "default", "dev", ifName});
    result =
        Shell.executeCommand(
            new String[] {"route", "add", "default", "gw", newIf.defaultGw, "dev", ifName});
    // #else
    //				result = Shell.executeRootCommand(new String[]{"ip", "route", "del", "default", "dev",
    // ifName});
    //				result = Shell.executeRootCommand(new String[]{"route", "add", "default", "gw",
    // newIf.defaultGw, "dev", ifName});
    // #endif

    // TODO PROVA ANDROID
    //		result = Shell.executeRootCommand(new String[]{"upmtconf", "-a", "dev", "-i", ifName});
    result = Module.upmtconf(new String[] {"-a", "dev", "-i", ifName});

    int mark = Module.getUpmtParameter(result, "Mark");

    // XXX MARCO: if for any possible reason mark is not returned, abort everything or retry
    // because in this case the tunnel over this interface wouldn't work at all TODO
    // This is actually a much bigger problem. addInterface (as many other functions in this
    // program)
    // should check all return values and itself should return something, or throw exceptions....
    // TODO

    if (!addTable(ifName)) printLog(ifName + " already present in rt_tables", Log.LEVEL_HIGH);
    ;

    result =
        Shell.executeCommand(
            new String[] {"sh", "-c", "ip rule | grep " + (rtTablesIndex - 1) + ":"});

    // #ifndef ANDROID
    if (result.length() == 0) {
      result =
          Shell.executeCommand(
              new String[] {
                "ip",
                "rule",
                "add",
                "fwmark",
                mark + "",
                "priority",
                "" + (rtTablesIndex - 1),
                "table",
                ifName + "_table"
              });
      this.markTable.put(ifName, "" + (rtTablesIndex - 1));
    }

    // #else
    //				if(result.length()==0) result = Shell.executeRootCommand(new
    // String[]{"ip","rule","add","fwmark",mark+"","priority",""+(rtTablesIndex-1),"table",ifName+"_table"});
    // #endif
    else {
      printLog("ip rule already present (prio:" + (rtTablesIndex - 1) + ")", Log.LEVEL_HIGH);
    }

    // Shell.executeCommand(new String[] {"sudo","ip","rule", "add","default", "dev", "ifName",
    // "table", ifName.trim()+"_table"});

    // #ifndef ANDROID
    result = Shell.executeCommand(new String[] {"ip", "route", "show", "table", ifName + "_table"});
    if (result.length() == 0) {
      result =
          Shell.executeCommand(
              new String[] {
                "ip",
                "route",
                "add",
                "default",
                "via",
                newIf.defaultGw,
                "dev",
                ifName,
                "table",
                ifName + "_table"
              });
    }

    // #else
    //				result = Shell.executeRootCommand(new String[]{"ip", "route", "show", "table",
    // ifName+"_table"});
    //
    //				if(result.length()==0) result = Shell.executeRootCommand(new String[]{"ip", "route",
    // "add", "default", "via", newIf.defaultGw, "dev", ifName, "table", ifName+"_table"});
    // #endif
    else {
      printLog("ip route already present (table:" + ifName + "_table)", Log.LEVEL_HIGH);
    }

    // #ifndef ANDROID
    result =
        Shell.executeCommand(
            new String[] {"sh", "-c", "echo 0 > /proc/sys/net/ipv4/conf/" + ifName + "/rp_filter"});
    // #else
    //				result = Shell.executeRootCommand(new String[]{"echo 0 >
    // /proc/sys/net/ipv4/conf/"+ifName+"/rp_filter"});
    // #endif
  }