iproute2: Build tc and netlink/util libs

For http://b/issue?id=2576057

Change-Id: Ic0a5edbdf6496a1a267634147c3c3eea3b3604ac
Signed-off-by: San Mehat <san@google.com>
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..ba187a6
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,3 @@
+ifneq ($(TARGET_SIMULATOR),true)
+include $(call all-subdir-makefiles)
+endif
diff --git a/lib/Android.mk b/lib/Android.mk
new file mode 100644
index 0000000..daca9cd
--- /dev/null
+++ b/lib/Android.mk
@@ -0,0 +1,63 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := utils.c rt_names.c ll_types.c ll_proto.c ll_addr.c inet_proto.c
+LOCAL_MODULE := libiprouteutil
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+LOCAL_C_INCLUDES := $(KERNEL_HEADERS) external/iproute2/include
+LOCAL_CFLAGS := -O2 -g -W -Wall \
+	-DHAVE_UNISTD_H \
+	-DHAVE_ERRNO_H \
+	-DHAVE_NETINET_IN_H \
+	-DHAVE_SYS_IOCTL_H \
+	-DHAVE_SYS_MMAN_H \
+	-DHAVE_SYS_MOUNT_H \
+	-DHAVE_SYS_PRCTL_H \
+	-DHAVE_SYS_RESOURCE_H \
+	-DHAVE_SYS_SELECT_H \
+	-DHAVE_SYS_STAT_H \
+	-DHAVE_SYS_TYPES_H \
+	-DHAVE_STDLIB_H \
+	-DHAVE_STRDUP \
+	-DHAVE_MMAP \
+	-DHAVE_UTIME_H \
+	-DHAVE_GETPAGESIZE \
+	-DHAVE_LSEEK64 \
+	-DHAVE_LSEEK64_PROTOTYPE \
+	-DHAVE_EXT2_IOCTLS \
+	-DHAVE_LINUX_FD_H \
+	-DHAVE_TYPE_SSIZE_T
+LOCAL_PRELINK_MODULE := false
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ll_map.c libnetlink.c
+LOCAL_MODULE := libnetlink
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+LOCAL_C_INCLUDES := $(KERNEL_HEADERS) external/iproute2/include
+LOCAL_CFLAGS := -O2 -g -W -Wall \
+	-DHAVE_UNISTD_H \
+	-DHAVE_ERRNO_H \
+	-DHAVE_NETINET_IN_H \
+	-DHAVE_SYS_IOCTL_H \
+	-DHAVE_SYS_MMAN_H \
+	-DHAVE_SYS_MOUNT_H \
+	-DHAVE_SYS_PRCTL_H \
+	-DHAVE_SYS_RESOURCE_H \
+	-DHAVE_SYS_SELECT_H \
+	-DHAVE_SYS_STAT_H \
+	-DHAVE_SYS_TYPES_H \
+	-DHAVE_STDLIB_H \
+	-DHAVE_STRDUP \
+	-DHAVE_MMAP \
+	-DHAVE_UTIME_H \
+	-DHAVE_GETPAGESIZE \
+	-DHAVE_LSEEK64 \
+	-DHAVE_LSEEK64_PROTOTYPE \
+	-DHAVE_EXT2_IOCTLS \
+	-DHAVE_LINUX_FD_H \
+	-DHAVE_TYPE_SSIZE_T
+
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/lib/utils.c b/lib/utils.c
index d80f79b..1ad7616 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -302,6 +302,7 @@
 		return 0;
 	}
 
+#ifndef ANDROID
 	if (family == AF_DECnet) {
 		struct dn_naddr dna;
 		addr->family = AF_DECnet;
@@ -312,6 +313,7 @@
 		addr->bitlen = -1;
 		return 0;
 	}
+#endif
 
 	addr->family = AF_INET;
 	if (family != AF_UNSPEC && family != AF_INET)
@@ -524,6 +526,7 @@
 	case AF_INET:
 	case AF_INET6:
 		return inet_ntop(af, addr, buf, buflen);
+#ifndef ANDROID
 	case AF_IPX:
 		return ipx_ntop(af, addr, buf, buflen);
 	case AF_DECnet:
@@ -532,6 +535,7 @@
 		memcpy(dna.a_addr, addr, 2);
 		return dnet_ntop(af, &dna, buf, buflen);
 	}
+#endif
 	default:
 		return "???";
 	}
@@ -702,6 +706,7 @@
 
 int cmdlineno;
 
+#ifndef ANDROID
 /* Like glibc getline but handle continuation lines and comments */
 ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
 {
@@ -746,6 +751,7 @@
 	}
 	return cc;
 }
+#endif
 
 /* split command line into argument vector */
 int makeargs(char *line, char *argv[], int maxargs)
diff --git a/tc/Android.mk b/tc/Android.mk
new file mode 100644
index 0000000..da2b358
--- /dev/null
+++ b/tc/Android.mk
@@ -0,0 +1,20 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES :=  tc.c tc_qdisc.c q_cbq.c tc_util.c tc_class.c tc_core.c m_action.c \
+                    m_estimator.c tc_filter.c tc_monitor.c tc_stab.c tc_cbq.c \
+                    tc_estimator.c
+
+LOCAL_MODULE := tc
+
+LOCAL_SYSTEM_SHARED_LIBRARIES := \
+	libc libm
+
+LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
+
+LOCAL_C_INCLUDES := $(KERNEL_HEADERS) external/iproute2/include
+
+LOCAL_CFLAGS := -O2 -g -W -Wall 
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/tc/tc.c b/tc/tc.c
index 8e362d2..eccd84d 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -182,7 +182,11 @@
 static void usage(void)
 {
 	fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
+#ifdef ANDROID
+			"       tc [-force]\n"
+#else
 			"       tc [-force] -batch filename\n"
+#endif
 	                "where  OBJECT := { qdisc | class | filter | action | monitor }\n"
 	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] }\n");
 }
@@ -214,6 +218,7 @@
 	return -1;
 }
 
+#ifndef ANDROID
 static int batch(const char *name)
 {
 	char *line = NULL;
@@ -257,13 +262,15 @@
 	rtnl_close(&rth);
 	return ret;
 }
-
+#endif
 
 int main(int argc, char **argv)
 {
 	int ret;
+#ifndef ANDROID
 	int do_batching = 0;
 	char *batchfile = NULL;
+#endif
 
 	while (argc > 1) {
 		if (argv[1][0] != '-')
@@ -287,20 +294,23 @@
 			return 0;
 		} else if (matches(argv[1], "-force") == 0) {
 			++force;
+#ifndef ANDROID
 		} else 	if (matches(argv[1], "-batch") == 0) {
 			do_batching = 1;
 			if (argc > 2)
 				batchfile = argv[2];
 			argc--;	argv++;
+#endif
 		} else {
 			fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
 			return -1;
 		}
 		argc--;	argv++;
 	}
-
+#ifndef ANDROID
 	if (do_batching)
 		return batch(batchfile);
+#endif
 
 	if (argc <= 1) {
 		usage();
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 6b3ed1e..cefd241 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -7,6 +7,10 @@
 #include <linux/gen_stats.h>
 #include "tc_core.h"
 
+#ifndef MIN
+#define MIN(x,y)        ((x)<(y)?(x):(y))
+#endif
+
 /* This is the deprecated multiqueue interface */
 #ifndef TCA_PRIO_MAX
 enum