ip: add enable ip4 api

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 <otroan@employees.org>
This commit is contained in:
Ole Troan 2024-11-22 09:22:20 +01:00 committed by Damjan Marion
parent 82b3cc1826
commit 18eedde9f2
4 changed files with 78 additions and 0 deletions

View 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
*/

View 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)

View 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,

View 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)
{