ip: Router ID included in flow hash
[vpp.git] / src / vnet / ip / ip_api.c
index 448b36c..3bf404b 100644 (file)
@@ -45,6 +45,7 @@
 #include <vnet/ip/reass/ip6_sv_reass.h>
 #include <vnet/ip/reass/ip6_full_reass.h>
 #include <vnet/ip/ip_table.h>
+#include <vnet/ip/ip_container_proxy.h>
 
 #include <vnet/vnet_msg_enum.h>
 
 
 #include <vnet/format_fns.h>
 
-#define foreach_ip_api_msg                                              \
-_(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable)     \
-_(IP_TABLE_DUMP, ip_table_dump)                                         \
-_(IP_ROUTE_DUMP, ip_route_dump)                                         \
-_(IP_MTABLE_DUMP, ip_mtable_dump)                                       \
-_(IP_MROUTE_DUMP, ip_mroute_dump)                                       \
-_(IP_MROUTE_ADD_DEL, ip_mroute_add_del)                                 \
-_(MFIB_SIGNAL_DUMP, mfib_signal_dump)                                   \
-_(IP_ADDRESS_DUMP, ip_address_dump)                                     \
-_(IP_UNNUMBERED_DUMP, ip_unnumbered_dump)                               \
-_(IP_DUMP, ip_dump)                                                     \
-_(IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin)                       \
-_(IP_TABLE_REPLACE_END, ip_table_replace_end)                           \
-_(IP_TABLE_FLUSH, ip_table_flush)                                       \
-_(IP_ROUTE_ADD_DEL, ip_route_add_del)                                   \
-_(IP_ROUTE_LOOKUP, ip_route_lookup)                                     \
-_(IP_TABLE_ADD_DEL, ip_table_add_del)                                   \
-_(IP_PUNT_POLICE, ip_punt_police)                                       \
-_(IP_PUNT_REDIRECT, ip_punt_redirect)                                   \
-_(SET_IP_FLOW_HASH,set_ip_flow_hash)                                    \
-_(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del)               \
-_(IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump)                     \
-_(IOAM_ENABLE, ioam_enable)                                             \
-_(IOAM_DISABLE, ioam_disable)                                           \
-_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,                               \
-  ip_source_and_port_range_check_add_del)                               \
-_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,                     \
-  ip_source_and_port_range_check_interface_add_del)                     \
- _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,                             \
-   sw_interface_ip6_set_link_local_address)                             \
-_(IP_REASSEMBLY_SET, ip_reassembly_set)                                 \
-_(IP_REASSEMBLY_GET, ip_reassembly_get)                                 \
-_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable)           \
-_(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
+#define foreach_ip_api_msg                                                    \
+  _ (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable)        \
+  _ (IP_TABLE_DUMP, ip_table_dump)                                            \
+  _ (IP_ROUTE_DUMP, ip_route_dump)                                            \
+  _ (IP_MTABLE_DUMP, ip_mtable_dump)                                          \
+  _ (IP_MROUTE_DUMP, ip_mroute_dump)                                          \
+  _ (IP_MROUTE_ADD_DEL, ip_mroute_add_del)                                    \
+  _ (MFIB_SIGNAL_DUMP, mfib_signal_dump)                                      \
+  _ (IP_ADDRESS_DUMP, ip_address_dump)                                        \
+  _ (IP_UNNUMBERED_DUMP, ip_unnumbered_dump)                                  \
+  _ (IP_DUMP, ip_dump)                                                        \
+  _ (IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin)                          \
+  _ (IP_TABLE_REPLACE_END, ip_table_replace_end)                              \
+  _ (IP_TABLE_FLUSH, ip_table_flush)                                          \
+  _ (IP_ROUTE_ADD_DEL, ip_route_add_del)                                      \
+  _ (IP_ROUTE_LOOKUP, ip_route_lookup)                                        \
+  _ (IP_TABLE_ADD_DEL, ip_table_add_del)                                      \
+  _ (IP_PUNT_POLICE, ip_punt_police)                                          \
+  _ (IP_PUNT_REDIRECT, ip_punt_redirect)                                      \
+  _ (SET_IP_FLOW_HASH, set_ip_flow_hash)                                      \
+  _ (SET_IP_FLOW_HASH_V2, set_ip_flow_hash_v2)                                \
+  _ (SET_IP_FLOW_HASH_ROUTER_ID, set_ip_flow_hash_router_id)                  \
+  _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del)                  \
+  _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump)                        \
+  _ (IOAM_ENABLE, ioam_enable)                                                \
+  _ (IOAM_DISABLE, ioam_disable)                                              \
+  _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,                                  \
+     ip_source_and_port_range_check_add_del)                                  \
+  _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,                        \
+     ip_source_and_port_range_check_interface_add_del)                        \
+  _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,                                 \
+     sw_interface_ip6_set_link_local_address)                                 \
+  _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS,                                 \
+     sw_interface_ip6_get_link_local_address)                                 \
+  _ (IP_REASSEMBLY_SET, ip_reassembly_set)                                    \
+  _ (IP_REASSEMBLY_GET, ip_reassembly_get)                                    \
+  _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable)              \
+  _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
 
 static void
   vl_api_sw_interface_ip6_enable_disable_t_handler
@@ -153,17 +158,17 @@ vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (fib_table, ip4_main.fibs,
-  ({
+  pool_foreach (fib_table, ip4_main.fibs)
+   {
     send_ip_table_details(am, reg, mp->context, fib_table);
-  }));
-  pool_foreach (fib_table, ip6_main.fibs,
-  ({
+  }
+  pool_foreach (fib_table, ip6_main.fibs)
+   {
     /* don't send link locals */
     if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
       continue;
     send_ip_table_details(am, reg, mp->context, fib_table);
-  }));
+  }
   /* *INDENT-ON* */
 }
 
@@ -293,14 +298,14 @@ vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (mfib_table, ip4_main.mfibs,
-  ({
+  pool_foreach (mfib_table, ip4_main.mfibs)
+   {
       send_ip_mtable_details (reg, mp->context, mfib_table);
-  }));
-  pool_foreach (mfib_table, ip6_main.mfibs,
-  ({
+  }
+  pool_foreach (mfib_table, ip6_main.mfibs)
+   {
       send_ip_mtable_details (reg, mp->context, mfib_table);
-  }));
+  }
   /* *INDENT-ON* */
 }
 
@@ -949,8 +954,8 @@ vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
   else
     {
       /* *INDENT-OFF* */
-      pool_foreach (si, im->sw_interfaces,
-      ({
+      pool_foreach (si, im->sw_interfaces)
+       {
         if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
           {
             send_ip_unnumbered_details(am, reg,
@@ -958,7 +963,7 @@ vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
                                        si->unnumbered_sw_if_index,
                                        mp->context);
           }
-      }));
+      }
       /* *INDENT-ON* */
     }
 
@@ -984,10 +989,10 @@ vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
   sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
   _vec_len (sorted_sis) = 0;
   /* *INDENT-OFF* */
-  pool_foreach (si, im->sw_interfaces,
-  ({
+  pool_foreach (si, im->sw_interfaces)
+   {
     vec_add1 (sorted_sis, si[0]);
-  }));
+  }
   /* *INDENT-ON* */
 
   vec_foreach (si, sorted_sis)
@@ -1007,7 +1012,7 @@ vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
 }
 
 static void
-set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
+vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t *mp)
 {
   vl_api_set_ip_flow_hash_reply_t *rmp;
   int rv;
@@ -1017,41 +1022,41 @@ set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
   table_id = ntohl (mp->vrf_id);
 
 #define _(a,b) if (mp->a) flow_hash_config |= b;
-  foreach_flow_hash_bit;
+  foreach_flow_hash_bit_v1;
 #undef _
 
-  rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
+  rv = ip_flow_hash_set ((mp->is_ipv6 ? AF_IP6 : AF_IP4), table_id,
+                        flow_hash_config);
 
   REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
 }
 
 static void
-set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
+vl_api_set_ip_flow_hash_v2_t_handler (vl_api_set_ip_flow_hash_v2_t *mp)
 {
-  vl_api_set_ip_flow_hash_reply_t *rmp;
+  vl_api_set_ip_flow_hash_v2_reply_t *rmp;
+  ip_address_family_t af;
   int rv;
-  u32 table_id;
-  flow_hash_config_t flow_hash_config = 0;
 
-  table_id = ntohl (mp->vrf_id);
+  rv = ip_address_family_decode (mp->af, &af);
 
-#define _(a,b) if (mp->a) flow_hash_config |= b;
-  foreach_flow_hash_bit;
-#undef _
+  if (!rv)
+    rv = ip_flow_hash_set (af, htonl (mp->table_id),
+                          htonl (mp->flow_hash_config));
 
-  rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
-
-  REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
+  REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_V2_REPLY);
 }
 
-
 static void
-vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
+vl_api_set_ip_flow_hash_router_id_t_handler (
+  vl_api_set_ip_flow_hash_router_id_t *mp)
 {
-  if (mp->is_ipv6 == 0)
-    set_ip4_flow_hash (mp);
-  else
-    set_ip6_flow_hash (mp);
+  vl_api_set_ip_flow_hash_router_id_reply_t *rmp;
+  int rv = 0;
+
+  ip_flow_hash_router_id_set (ntohl (mp->router_id));
+
+  REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_ROUTER_ID_REPLY);
 }
 
 void
@@ -1362,6 +1367,30 @@ static void
   REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
 }
 
+static void
+vl_api_sw_interface_ip6_get_link_local_address_t_handler (
+  vl_api_sw_interface_ip6_get_link_local_address_t *mp)
+{
+  vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp;
+  const ip6_address_t *ip = NULL;
+  int rv = 0;
+
+  VALIDATE_SW_IF_INDEX (mp);
+
+  ip = ip6_get_link_local_address (ntohl (mp->sw_if_index));
+  if (NULL == ip)
+    rv = VNET_API_ERROR_IP6_NOT_ENABLED;
+
+  BAD_SW_IF_INDEX_LABEL;
+  /* clang-format off */
+  REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY,
+  ({
+    if (!rv)
+      ip6_address_encode (ip, rmp->ip);
+  }))
+  /* clang-format on */
+}
+
 static void
 vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
 {
@@ -1428,8 +1457,8 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
 
       /* Shut down interfaces in this FIB / clean out intfc routes */
       /* *INDENT-OFF* */
-      pool_foreach (si, im->sw_interfaces,
-      ({
+      pool_foreach (si, im->sw_interfaces)
+       {
         if (fib_index == fib_table_get_index_for_sw_if_index (fproto,
                                                               si->sw_if_index))
           {
@@ -1437,7 +1466,7 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
             flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
             vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags);
           }
-      }));
+      }
       /* *INDENT-ON* */
 
       fib_table_flush (fib_index, fproto, FIB_SOURCE_API);