am 84300120: am 051c2907: Make the test more robust with an unreachable rule

* commit '843001203ecf95ce403bc5e9154087fe77f404b6':
  Make the test more robust with an unreachable rule
diff --git a/tests/net_test/iproute.py b/tests/net_test/iproute.py
index f3560c6..9468ff0 100644
--- a/tests/net_test/iproute.py
+++ b/tests/net_test/iproute.py
@@ -293,8 +293,9 @@
     Args:
       version: An integer, 4 or 6.
       is_add: True to add a rule, False to delete it.
-      table: The table to add/delete the rule from.
+      table: If nonzero, rule looks up this table. If 0, it returns ENETUNREACH.
       match_nlattr: A blob of struct nlattrs that express the match condition.
+        If None, match everything.
       priority: An integer, the priority.
 
     Raises:
@@ -303,11 +304,14 @@
     """
     # Create a struct rtmsg specifying the table and the given match attributes.
     family = self._AddressFamily(version)
+    rule_type = RTN_UNICAST if table else RTN_UNREACHABLE
     rtmsg = RTMsg((family, 0, 0, 0, RT_TABLE_UNSPEC,
-                   RTPROT_STATIC, RT_SCOPE_UNIVERSE, RTN_UNICAST, 0)).Pack()
+                   RTPROT_STATIC, RT_SCOPE_UNIVERSE, rule_type, 0)).Pack()
     rtmsg += self._NlAttrU32(FRA_PRIORITY, priority)
-    rtmsg += match_nlattr
-    rtmsg += self._NlAttrU32(FRA_TABLE, table)
+    if match_nlattr:
+      rtmsg += match_nlattr
+    if table:
+      rtmsg += self._NlAttrU32(FRA_TABLE, table)
 
     # Create a netlink request containing the rtmsg.
     command = RTM_NEWRULE if is_add else RTM_DELRULE
@@ -326,6 +330,9 @@
               self._NlAttrU32(EXPERIMENTAL_FRA_UID_END, end))
     return self._Rule(version, is_add, table, nlattr, priority)
 
+  def UnreachableRule(self, version, is_add, priority):
+    return self._Rule(version, is_add, None, None, priority=priority)
+
   def _GetRTMsg(self, data):
     """Parses a RTMsg into a header and a dictionary of attributes."""
     # Parse the netlink and rtmsg headers.
diff --git a/tests/net_test/mark_test.py b/tests/net_test/mark_test.py
index e6751c5..fcdb16d 100755
--- a/tests/net_test/mark_test.py
+++ b/tests/net_test/mark_test.py
@@ -482,6 +482,9 @@
       cls.SendRA(netid)
       cls._RunSetupCommands(netid, True)
 
+    for version in [4, 6]:
+      cls.iproute.UnreachableRule(version, True, 1000)
+
     # Uncomment to look around at interface and rule configuration while
     # running in the background. (Once the test finishes running, all the
     # interfaces and rules are gone.)
@@ -489,6 +492,12 @@
 
   @classmethod
   def tearDownClass(cls):
+    for version in [4, 6]:
+      try:
+        cls.iproute.UnreachableRule(version, False, 1000)
+      except IOError:
+        pass
+
     for netid in cls.tuns:
       cls._RunSetupCommands(netid, False)
       cls.tuns[netid].close()