ip: add enable ip4 api 69/41869/6
authorOle Troan <[email protected]>
Fri, 22 Nov 2024 08:22:20 +0000 (09:22 +0100)
committerDamjan Marion <[email protected]>
Tue, 10 Dec 2024 13:03:54 +0000 (13:03 +0000)
A philosophical question. Do an interface have to have an IPv4 address
to process IPv4 packets? For ICMP error generation it's sufficient that
it has an address available on the node.

More concretely this patch is to allow an extern DHCP client to process
IP packets before it configures an address on the interface, without
having to have an node early in the ip4-unicast feature-arc like
ip4-dhcp-client-detect to intercept the packets.

Type: improvement
Change-Id: I780c579eec28ba564cf8417fbcc87e7a7876fdd2
Signed-off-by: Ole Troan <[email protected]>
src/vnet/ip/ip.api
src/vnet/ip/ip46_cli.c
src/vnet/ip/ip_api.c
src/vnet/ip/ip_test.c

index fc7d758..be151bd 100644 (file)
@@ -446,6 +446,20 @@ autoreply define sw_interface_ip6_enable_disable
   bool enable;                 /* set to true if enable */
 };
 
+/** \brief IPv4 interface enable / disable request
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param sw_if_index - interface used to reach neighbor
+    @param enable - if non-zero enable ip4 on interface, else disable
+*/
+autoendian autoreply define sw_interface_ip4_enable_disable
+{
+  u32 client_index;
+  u32 context;
+  vl_api_interface_index_t sw_if_index;
+  bool enable;                 /* set to true if enable */
+};
+
 /** \brief Dump IP multicast fib table
     @param client_index - opaque cookie to identify the sender
 */
index e3da279..022c417 100644 (file)
@@ -292,6 +292,45 @@ VLIB_CLI_COMMAND (set_reassembly_command, static) = {
     .function = set_reassembly_command_fn,
 };
 
+static clib_error_t *
+enable_ip4_interface_cmd (vlib_main_t *vm, unformat_input_t *input,
+                         vlib_cli_command_t *cmd)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  clib_error_t *error = NULL;
+  u32 sw_if_index;
+
+  sw_if_index = ~0;
+
+  if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+    {
+      vnet_feature_enable_disable ("ip4-unicast", "ip4-not-enabled",
+                                  sw_if_index, 0, 0, 0);
+
+      vnet_feature_enable_disable ("ip4-multicast", "ip4-not-enabled",
+                                  sw_if_index, 0, 0, 0);
+    }
+  else
+    {
+      error = clib_error_return (0, "unknown interface\n'",
+                                format_unformat_error, input);
+    }
+  return error;
+}
+
+/*?
+ * This command is used to enable IPv4 on a given interface.
+ *
+ * @cliexpar
+ * Example of how enable IPv4 on a given interface:
+ * @cliexcmd{enable ip4 interface GigabitEthernet2/0/0}
+?*/
+VLIB_CLI_COMMAND (enable_ip4_interface_command, static) = {
+  .path = "enable ip4 interface",
+  .function = enable_ip4_interface_cmd,
+  .short_help = "enable ip4 interface <interface>",
+};
+
 /* Dummy init function to get us linked in. */
 static clib_error_t *
 ip4_cli_init (vlib_main_t * vm)
index 1f025fa..e7133a5 100644 (file)
@@ -73,6 +73,26 @@ static void
   REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
 }
 
+static void
+vl_api_sw_interface_ip4_enable_disable_t_handler (
+  vl_api_sw_interface_ip4_enable_disable_t *mp)
+{
+  vl_api_sw_interface_ip4_enable_disable_reply_t *rmp;
+  int rv = 0;
+
+  VALIDATE_SW_IF_INDEX_END (mp);
+
+  vnet_feature_enable_disable ("ip4-unicast", "ip4-not-enabled",
+                              mp->sw_if_index, mp->enable, 0, 0);
+
+  vnet_feature_enable_disable ("ip4-multicast", "ip4-not-enabled",
+                              mp->sw_if_index, mp->enable, 0, 0);
+
+  BAD_SW_IF_INDEX_LABEL;
+
+  REPLY_MACRO_END (VL_API_SW_INTERFACE_IP4_ENABLE_DISABLE_REPLY);
+}
+
 static void
 send_ip_table_details (vpe_api_main_t * am,
                       vl_api_registration_t * reg,
index 0d1c710..1e803dd 100644 (file)
@@ -1324,6 +1324,11 @@ api_sw_interface_ip6_enable_disable (vat_main_t *vam)
   return ret;
 }
 
+static int
+api_sw_interface_ip4_enable_disable (vat_main_t *vam)
+{
+  return -1;
+}
 static int
 api_set_ip_flow_hash_v2 (vat_main_t *vat)
 {