use of org.eclipse.kura.net.route.RouteConfigIP6 in project kura by eclipse.
the class RouteServiceImpl method removeStaticRoute.
@Override
public void removeStaticRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String iface) throws Exception {
RouteConfig tmpRoute = null;
StringBuffer command = new StringBuffer();
command.append("route del -net " + destination.getHostAddress() + " ");
if (netmask != null) {
command.append("netmask " + netmask.getHostAddress() + " ");
}
if (gateway != null) {
if (gateway.getHostAddress().compareTo("127.0.0.1") != 0) {
command.append("gw " + gateway.getHostAddress() + " ");
}
}
if (iface != null) {
command.append("dev " + iface + " ");
}
SafeProcess proc = null;
try {
s_logger.debug("Executing command: {}", command.toString());
proc = ProcessUtil.exec(command.toString());
proc.waitFor();
if (proc.exitValue() != 0) {
s_logger.error("Error removing static Route");
throw new Exception("Error removing Static Route");
}
} catch (IOException e) {
s_logger.error("Error executing command: route -n");
throw e;
} finally {
if (proc != null) {
ProcessUtil.destroy(proc);
}
}
if (destination instanceof IP4Address) {
tmpRoute = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, iface, -1);
} else if (destination instanceof IP6Address) {
tmpRoute = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, iface, -1);
}
s_logger.info("Static route removed successfully");
s_logger.debug(tmpRoute.getDescription());
}
use of org.eclipse.kura.net.route.RouteConfigIP6 in project kura by eclipse.
the class RouteServiceImpl method addStaticRoute.
@Override
public void addStaticRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String iface, int metric) throws Exception {
RouteConfig tmpRoute = null;
StringBuffer command = new StringBuffer();
command.append("route add -net " + destination.getHostAddress() + " ");
if (netmask != null) {
command.append("netmask " + netmask.getHostAddress() + " ");
}
if (gateway != null) {
if (gateway.getHostAddress().compareTo("0.0.0.0") != 0 && gateway.getHostAddress().compareTo("127.0.0.1") != 0) {
command.append("gw " + gateway.getHostAddress() + " ");
}
}
if (iface != null) {
command.append("dev " + iface + " ");
}
if (metric != 0 && metric != -1) {
command.append("metric " + metric);
}
SafeProcess proc = null;
try {
s_logger.debug("Executing command: {}", command.toString());
proc = ProcessUtil.exec(command.toString());
proc.waitFor();
if (proc.exitValue() != 0) {
s_logger.error("Error adding static Route: " + command.toString());
throw new Exception("Error adding Static Route");
}
} catch (IOException e) {
s_logger.error("Error executing command: route -n");
throw e;
} finally {
if (proc != null) {
ProcessUtil.destroy(proc);
}
}
if (destination instanceof IP4Address) {
tmpRoute = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, iface, -1);
} else if (destination instanceof IP6Address) {
tmpRoute = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, iface, -1);
}
s_logger.info("Static route added successfully");
s_logger.debug(tmpRoute.getDescription());
}
use of org.eclipse.kura.net.route.RouteConfigIP6 in project kura by eclipse.
the class RouteFile method findRoute.
private RouteConfig findRoute(Properties props, int index) {
RouteConfig route = null;
IPAddress dest = null;
IPAddress gw = null;
IPAddress mask = null;
if (!props.containsKey("ADDRESS" + index)) {
return null;
}
try {
dest = IPAddress.parseHostAddress((String) props.get("ADDRESS" + index));
gw = IPAddress.parseHostAddress((String) props.get("GATEWAY" + index));
mask = IPAddress.parseHostAddress((String) props.get("NETMASK" + index));
} catch (UnknownHostException e) {
e.printStackTrace();
}
if (dest != null && gw != null && mask != null) {
if (dest instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) dest, (IP4Address) gw, (IP4Address) mask, this.interfaceName, -1);
} else if (dest instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) dest, (IP6Address) gw, (IP6Address) mask, this.interfaceName, -1);
}
}
return route;
}
use of org.eclipse.kura.net.route.RouteConfigIP6 in project kura by eclipse.
the class RouteFile method removeRoute.
public boolean removeRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String iface) {
RouteConfig route = null;
if (destination instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, this.interfaceName, -1);
} else if (destination instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, this.interfaceName, -1);
}
int index = routeIndex(route);
if (index != -1) {
this.routes.remove(index);
storeFile();
return true;
}
return false;
}
use of org.eclipse.kura.net.route.RouteConfigIP6 in project kura by eclipse.
the class RouteFile method addRoute.
public boolean addRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String ifaceName) {
RouteConfig route = null;
if (destination instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, ifaceName, -1);
} else if (destination instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, ifaceName, -1);
}
if (routeIndex(route) != -1) {
return false;
}
this.routes.add(route);
storeFile();
return true;
}
Aggregations