Merge remote-tracking branch 'goog/mirror-m-wireless-internal-release'
diff --git a/Android.mk b/Android.mk
index 216ee3a..108451c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -11,6 +11,9 @@
 	if-linux.c if-linux-wireless.c lpf.c \
 	platform-linux.c compat/closefrom.c ifaddrs.c ipv6rs.c
 
+# Clang complains about configure.c's comparing array with null.
+LOCAL_CFLAGS += -Wno-tautological-pointer-compare
+LOCAL_CLANG_CFLAGS := -Wno-error=duplicate-decl-specifier
 LOCAL_SHARED_LIBRARIES := libc libcutils libnetutils
 LOCAL_MODULE = dhcpcd
 include $(BUILD_EXECUTABLE)
@@ -55,5 +58,6 @@
 LOCAL_MODULE := dhcpcd_test
 LOCAL_CFLAGS := -Wall -Werror -Wunused-parameter
 LOCAL_SRC_FILES := dhcpcd_test.cpp dhcp.c common.c
+LOCAL_CLANG_CFLAGS := -Wno-error=duplicate-decl-specifier
 LOCAL_MODULE_TAGS := eng tests
 include $(BUILD_NATIVE_TEST)
diff --git a/NOTICE b/NOTICE
index 69987c8..73598aa 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,5 +1,5 @@
 dhcpcd - DHCP client daemon
-Copyright 2006-2008 Roy Marples <roy@marples.name>
+Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
 All rights reserved
 
 Redistribution and use in source and binary forms, with or without
diff --git a/dhcpcd-hooks/25-static-routes.conf b/dhcpcd-hooks/25-static-routes.conf
new file mode 100755
index 0000000..c6b7c4a
--- /dev/null
+++ b/dhcpcd-hooks/25-static-routes.conf
@@ -0,0 +1,61 @@
+# Set dhcp.<iface>.routeN.dest and dhcp.<iface>.routeN.via properties with
+# the static routes provided by the DHCP server.
+
+# CAUTION
+#
+# Placing this in the hooks directory will allow DHCP servers to push static
+# routes to ALL of the interfaces that use the directory.
+#
+# To avoid this, create separate dhcpcd configurations, one for the interfaces
+# that should accept static routes and another for the interfaces that should
+# not accept static routes routes.
+
+# Add this script in the hooks directory only for the interfaces that should
+# accept static routes.
+#
+# Add "nooption classless_static_routes, static_routes" to the dhcpcd.conf
+# file for the interfaces that should not accept static routes. Do not add the
+# script to the hooks directory.
+
+next_set_interface=1
+
+set_route_props_from_list()
+{
+    while [[ $# -ge 2 ]]; do
+        setprop dhcp.${interface}.route${next_set_interface}.dest $1
+        shift
+        setprop dhcp.${interface}.route${next_set_interface}.via $1
+        shift
+        next_set_interface=$(($next_set_interface + 1))
+    done
+}
+
+unset_route_props()
+{
+    next_clear_interface=1
+    while [[ ! -z "$(getprop dhcp.${interface}.route${next_clear_interface}.dest)" ]]; do
+      setprop dhcp.${interface}.route${next_clear_interface}.dest ""
+      setprop dhcp.${interface}.route${next_clear_interface}.via ""
+      next_clear_interface=$(($next_clear_interface + 1))
+    done
+    while [[ ! -z "$(getprop dhcp.${interface}.route${next_clear_interface}.via)" ]]; do
+      setprop dhcp.${interface}.route${next_clear_interface}.dest ""
+      setprop dhcp.${interface}.route${next_clear_interface}.via ""
+      next_clear_interface=$(($next_clear_interface + 1))
+    done
+}
+
+set_route_props()
+{
+    unset_route_props
+    if [[ ! -z "${new_classless_static_routes}" ]]; then
+        set_route_props_from_list ${new_classless_static_routes}
+    else
+        set_route_props_from_list ${new_static_routes}
+    fi
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)       set_route_props;;
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP)                unset_route_props;;
+esac
diff --git a/if-linux.c b/if-linux.c
index 9355359..3d0bcad 100644
--- a/if-linux.c
+++ b/if-linux.c
@@ -40,13 +40,6 @@
 # define IFLA_WIRELESS (IFLA_MASTER + 1)
 #endif
 
-/* For some reason, glibc doesn't include newer flags from linux/if.h
- * However, we cannot include linux/if.h directly as it conflicts
- * with the glibc version. D'oh! */
-#ifndef IFF_LOWER_UP
-#define IFF_LOWER_UP	0x10000		/* driver signals L1 up		*/
-#endif
-
 #include <errno.h>
 #include <ctype.h>
 #include <stddef.h>
@@ -61,6 +54,15 @@
 #include "dhcp.h"
 #include "net.h"
 
+/* ANDROID change, moved this below all includes. */
+/* For some reason, glibc doesn't include newer flags from linux/if.h
+ * However, we cannot include linux/if.h directly as it conflicts
+ * with the glibc version. D'oh! */
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000		/* driver signals L1 up		*/
+#endif
+/* End of ANDROID change */
+
 static int sock_fd;
 static struct sockaddr_nl sock_nl;
 
diff --git a/ifaddrs.c b/ifaddrs.c
index 0554ee7..c36fd64 100644
--- a/ifaddrs.c
+++ b/ifaddrs.c
@@ -20,6 +20,7 @@
 #include "ifaddrs.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <dirent.h>
diff --git a/showlease.c b/showlease.c
index 50f96df..1257337 100644
--- a/showlease.c
+++ b/showlease.c
@@ -1,7 +1,9 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #include "dhcp.h"
 #include "config.h"