diff options
author | Ole Troan <otroan@employees.org> | 2023-09-08 11:32:33 +0200 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2023-09-19 14:16:28 +0000 |
commit | a05f93a9e53d0ade8669122592f7aae231adfffc (patch) | |
tree | f461424ea4ab65e4b9e66cd600a85600a6cf0e4e /src/plugins/npt66/npt66.c | |
parent | ae036d3b7d911788a9ead084bf89dd72c763d9f1 (diff) |
npt66: ensure feature is not configured multiple times
If the control agent enabled a binding on an interface multiple times,
we would add the node in the feature arc multiple times.
Type: fix
Change-Id: I2ca247db0a0211f5fa3974a18ca4fcae8485cb12
Signed-off-by: Ole Troan <otroan@employees.org>
Diffstat (limited to 'src/plugins/npt66/npt66.c')
-rw-r--r-- | src/plugins/npt66/npt66.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/plugins/npt66/npt66.c b/src/plugins/npt66/npt66.c index e3cbbbd1a7b..277fce496fc 100644 --- a/src/plugins/npt66/npt66.c +++ b/src/plugins/npt66/npt66.c @@ -49,17 +49,24 @@ npt66_binding_add_del (u32 sw_if_index, ip6_address_t *internal, int external_plen, bool is_add) { npt66_main_t *nm = &npt66_main; + int rv = 0; + + /* Currently limited to a single binding per interface */ + npt66_binding_t *b = npt66_interface_by_sw_if_index (sw_if_index); if (is_add) { - + bool configure_feature = false; /* Ensure prefix lengths are less than or equal to a /64 */ if (internal_plen > 64 || external_plen > 64) return VNET_API_ERROR_INVALID_VALUE; - /* Create a binding entry */ - npt66_binding_t *b; - pool_get_zero (nm->bindings, b); + /* Create a binding entry (or update existing) */ + if (!b) + { + pool_get_zero (nm->bindings, b); + configure_feature = true; + } b->internal = *internal; b->internal_plen = internal_plen; b->external = *external; @@ -78,6 +85,9 @@ npt66_binding_add_del (u32 sw_if_index, ip6_address_t *internal, delta = ip_csum_sub_even (delta, b->internal.as_u64[1]); delta = ip_csum_fold (delta); b->delta = delta; + + if (configure_feature) + rv = npt66_feature_enable_disable (sw_if_index, is_add); } else { @@ -87,11 +97,9 @@ npt66_binding_add_del (u32 sw_if_index, ip6_address_t *internal, return VNET_API_ERROR_NO_SUCH_ENTRY; nm->interface_by_sw_if_index[sw_if_index] = ~0; pool_put (nm->bindings, b); + rv = npt66_feature_enable_disable (sw_if_index, is_add); } - /* Enable feature on interface */ - int rv = npt66_feature_enable_disable (sw_if_index, is_add); - return rv; } |