aboutsummaryrefslogtreecommitdiffstats
path: root/extras/strongswan/vpp_sswan
diff options
context:
space:
mode:
authorGabriel Oginski <gabrielx.oginski@intel.com>2023-07-06 09:18:45 +0000
committerFan Zhang <fanzhang.oss@gmail.com>2023-07-19 02:31:21 +0000
commit73d82d1273a358d119ee8905cfd401a3f16ae655 (patch)
tree9dde3142ddb004e42c06bfb4047ff13b5f11c965 /extras/strongswan/vpp_sswan
parentf72a32a1e45580bdab843fc1b3fb37c5fa7996dc (diff)
vpp-swan: fix function to get sw_if_index
In the current implementation there is a bug in the function responsible for getting software interface index by the name of the interface. Incorrect function is used to send the API message, also the handler with replied message is incorrect. The fix changes function to send dump message and also adds handler with replied message in the correct way. Type: fix Signed-off-by: Gabriel Oginski <gabrielx.oginski@intel.com> Change-Id: Id1a3ba2ce7e92d216907f344431b9e2acb1d5572
Diffstat (limited to 'extras/strongswan/vpp_sswan')
-rw-r--r--extras/strongswan/vpp_sswan/kernel_vpp_ipsec.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/extras/strongswan/vpp_sswan/kernel_vpp_ipsec.c b/extras/strongswan/vpp_sswan/kernel_vpp_ipsec.c
index 38d39512b31..a48bd573938 100644
--- a/extras/strongswan/vpp_sswan/kernel_vpp_ipsec.c
+++ b/extras/strongswan/vpp_sswan/kernel_vpp_ipsec.c
@@ -669,10 +669,14 @@ get_sw_if_index (char *interface)
{
char *out = NULL;
int out_len, name_filter_len = 0, msg_len = 0;
- vl_api_sw_interface_dump_t *mp;
- vl_api_sw_interface_details_t *rmp;
+ int num, i;
+ vl_api_sw_interface_dump_t *mp = NULL;
+ vl_api_sw_interface_details_t *rmp = NULL;
uint32_t sw_if_index = ~0;
+ if (interface == NULL)
+ goto error;
+
name_filter_len = strlen (interface);
msg_len = sizeof (*mp) + name_filter_len;
mp = vl_msg_api_alloc (msg_len);
@@ -683,7 +687,7 @@ get_sw_if_index (char *interface)
mp->name_filter.length = htonl (name_filter_len);
memcpy ((char *) mp->name_filter.buf, interface, name_filter_len);
- if (vac->send (vac, (char *) mp, msg_len, &out, &out_len))
+ if (vac->send_dump (vac, (char *) mp, msg_len, &out, &out_len))
{
goto error;
}
@@ -691,14 +695,27 @@ get_sw_if_index (char *interface)
{
goto error;
}
+ num = out_len / sizeof (*rmp);
rmp = (vl_api_sw_interface_details_t *) out;
- sw_if_index = ntohl (rmp->sw_if_index);
+ for (i = 0; i < num; i++)
+ {
+ if (strlen (rmp->interface_name) &&
+ streq (interface, rmp->interface_name))
+ {
+ sw_if_index = ntohl (rmp->sw_if_index);
+ break;
+ }
+ rmp += 1;
+ }
error:
- free (out);
- vl_msg_api_free (mp);
+ if (out)
+ free (out);
+ if (mp)
+ vl_msg_api_free (mp);
return sw_if_index;
}
+
/**
* (Un)-install a security policy database
*/