session: show session rules does not display ip6 entries

1. Adding an ip6 rule entry
session rule add proto tcp ee80::/10 0 ee80::/10 0 action 2

2. show session rules does not display the entry.
show session rules tcp

3. However, show session rules for a specific entry shows the entry
show session rules tcp ee80::/10 0 ee80::/10 0

Type: fix

Change-Id: I65c881665d3698a2a9452a186ed657eee0bf13e0
Signed-off-by: Steven Luong <sluong@cisco.com>
diff --git a/src/vnet/session/session_lookup.c b/src/vnet/session/session_lookup.c
index ff20bc2..ff6e581 100644
--- a/src/vnet/session/session_lookup.c
+++ b/src/vnet/session/session_lookup.c
@@ -1665,9 +1665,9 @@
       else if (unformat (input, "appns %_%v%_", &ns_id))
 	;
       else if (unformat (input, "scope global"))
-	scope = 1;
+	scope = SESSION_RULE_SCOPE_GLOBAL;
       else if (unformat (input, "scope local"))
-	scope = 2;
+	scope = SESSION_RULE_SCOPE_LOCAL;
       else if (unformat (input, "%U/%d %d %U/%d %d", unformat_ip4_address,
 			 &lcl_ip.ip4, &lcl_plen, &lcl_port,
 			 unformat_ip4_address, &rmt_ip.ip4, &rmt_plen,
@@ -1709,7 +1709,7 @@
       app_ns = app_namespace_get_default ();
     }
 
-  if (scope == 1 || scope == 0)
+  if (scope == SESSION_RULE_SCOPE_GLOBAL || scope == 0)
     {
       fib_proto = is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
       fib_index = is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
@@ -1730,9 +1730,36 @@
 
   vlib_cli_output (vm, "%U rules table", format_transport_proto,
 		   transport_proto);
-  srt = &st->session_rules[transport_proto];
-  session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP4);
-  session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP6);
+  if (scope == SESSION_RULE_SCOPE_LOCAL)
+    {
+      if (st)
+	{
+	  srt = &st->session_rules[transport_proto];
+	  session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP4);
+	  session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP6);
+	}
+    }
+  else
+    {
+      /*
+       * 2 separate session tables for global entries, 1 for ip4 and 1 for ip6
+       */
+      st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4,
+					    app_ns->ip4_fib_index);
+      if (st)
+	{
+	  srt = &st->session_rules[transport_proto];
+	  session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP4);
+	}
+
+      st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6,
+					    app_ns->ip6_fib_index);
+      if (st)
+	{
+	  srt = &st->session_rules[transport_proto];
+	  session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP6);
+	}
+    }
 
   vec_free (ns_id);
   return 0;