Dump all the correct routing tables.

The list of tables is maintained in /data/misc/net/rt_tables by netd.

Change-Id: I55475c08c5e43bcf61af916210e680c47480ac32
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c
index 670e09c..3b19f59 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.c
@@ -593,3 +593,22 @@
 void play_sound(const char* path) {
     run_command(NULL, 5, "/system/bin/stagefright", "-o", "-a", path, NULL);
 }
+
+void dump_route_tables() {
+    const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
+    dump_file("RT_TABLES", RT_TABLES_PATH);
+    FILE* fp = fopen(RT_TABLES_PATH, "r");
+    if (!fp) {
+        printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno));
+        return;
+    }
+    char table[16];
+    // Each line has an integer (the table number), a space, and a string (the table name). We only
+    // need the table number. It's a 32-bit unsigned number, so max 10 chars. Skip the table name.
+    // Add a fixed max limit so this doesn't go awry.
+    for (int i = 0; i < 64 && fscanf(fp, " %10s %*s", table) == 1; ++i) {
+        run_command("ROUTE TABLE IPv4", 10, "ip", "-4", "route", "show", "table", table, NULL);
+        run_command("ROUTE TABLE IPv6", 10, "ip", "-6", "route", "show", "table", table, NULL);
+    }
+    fclose(fp);
+}