pnat: expose binding_index over API 91/42791/3
authorBartlomiej Leszak <[email protected]>
Sun, 13 Apr 2025 18:09:05 +0000 (20:09 +0200)
committerOle Tr�an <[email protected]>
Tue, 29 Apr 2025 07:06:21 +0000 (07:06 +0000)
Type: improvement

VPP pnat is internally holding mapping between interface and pnat rule.
This is used by vppctl to delete rules. However querying this is not
possible over API, which makes it impossible to delete a rule w/o
keeping external cache of such mappings.

Change-Id: I3662bfb2caddbac0e1755068bdf7cb965c8acedb
Signed-off-by: Bartlomiej Leszak <[email protected]>
src/plugins/nat/pnat/pnat.api
src/plugins/nat/pnat/pnat_api.c

index de555c4..82c2de4 100644 (file)
@@ -165,6 +165,23 @@ define pnat_interfaces_details
   vl_api_pnat_mask_t lookup_mask[2]; /* PNAT_ATTACHMENT_POINT_MAX */
 };
 
+
+autoendian define pnat_flow_lookup
+{
+    u32 client_index;
+    u32 context;
+    vl_api_interface_index_t sw_if_index;
+    vl_api_pnat_attachment_point_t attachment;
+    vl_api_pnat_match_tuple_t match;
+};
+
+autoendian define pnat_flow_lookup_reply
+{
+    u32 context;
+    i32 retval;
+    u32 binding_index;
+};
+
 counters pnat {
   none {
     severity info;
index a4e7ff1..f627307 100644 (file)
@@ -93,6 +93,20 @@ static void vl_api_pnat_binding_del_t_handler(vl_api_pnat_binding_del_t *mp) {
     REPLY_MACRO_END(VL_API_PNAT_BINDING_DEL_REPLY);
 }
 
+static void vl_api_pnat_flow_lookup_t_handler(vl_api_pnat_flow_lookup_t *mp) {
+    pnat_main_t *pm = &pnat_main;
+    vl_api_pnat_flow_lookup_reply_t *rmp;
+    u32 binding_index;
+    int rv = 0;
+    binding_index =
+        pnat_flow_lookup(mp->sw_if_index, mp->attachment, &mp->match);
+    if (binding_index == ~0) {
+        rv = -1;
+    }
+    REPLY_MACRO2_END(VL_API_PNAT_FLOW_LOOKUP_REPLY,
+                     ({ rmp->binding_index = binding_index; }));
+}
+
 /*
  * Workaround for a bug in vppapigen that doesn't register the endian handler
  * for _details messages. When that's fixed it should be possible to use