Add getmtu and setmtu interface commands

Bug: 9372485

Change-Id: I0dfa6b1f973426d67f976a9c79be8de90e3d9c19
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/InterfaceController.cpp b/InterfaceController.cpp
index 0d8f121..c305be9 100644
--- a/InterfaceController.cpp
+++ b/InterfaceController.cpp
@@ -46,6 +46,8 @@
 
 const char ipv6_proc_path[] = "/proc/sys/net/ipv6/conf";
 
+const char sys_net_path[] = "/sys/class/net";
+
 InterfaceController::InterfaceController()
 	: sendCommand_(NULL) {
 	// Initial IPv6 settings.
@@ -163,3 +165,26 @@
 	closedir(dir);
 	return 0;
 }
+
+int InterfaceController::getMtu(const char *interface, int *mtu)
+{
+	char buf[16];
+	int size = sizeof(buf);
+	char *path;
+	asprintf(&path, "%s/%s/mtu", sys_net_path, interface);
+	int success = readFile(path, buf, &size);
+	if (!success && mtu)
+		*mtu = atoi(buf);
+	free(path);
+	return success;
+
+}
+
+int InterfaceController::setMtu(const char *interface, const char *mtu)
+{
+	char *path;
+	asprintf(&path, "%s/%s/mtu", sys_net_path, interface);
+	int success = writeFile(path, mtu, strlen(mtu));
+	free(path);
+	return success;
+}