Skip to content

Commit 967019b

Browse files
Merge pull request #304 from asterfusion/feature/support_cgnat
CGNAT merge to main
2 parents 623815c + a575a3e commit 967019b

36 files changed

Lines changed: 14512 additions & 135 deletions

ET2500/vpp-24.02/src/plugins/acl/sess_mgmt_node.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,26 @@ send_one_worker_interrupt (vlib_main_t * vm, acl_main_t * am,
378378
}
379379
}
380380

381+
/*
382+
* Ensure that an in-progress interface cleanup gets another chance to run.
383+
*
384+
* Do not rely on interrupt_is_pending here: this is the recovery path for a
385+
* cleanup whose software state and VLIB interrupt state may have diverged.
386+
* Setting the VLIB interrupt-pending bit again is idempotent.
387+
*/
388+
static void
389+
ensure_worker_cleaner_interrupt (acl_main_t * am, int thread_index)
390+
{
391+
acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
392+
393+
/* Publish the cleanup request before notifying the target thread. */
394+
CLIB_MEMORY_BARRIER ();
395+
pw->interrupt_is_pending = 1;
396+
vlib_node_set_interrupt_pending (
397+
vlib_get_main_by_index (thread_index),
398+
acl_fa_worker_session_cleaner_process_node.index);
399+
}
400+
381401
void
382402
aclp_post_session_change_request (acl_main_t * am, u32 target_thread,
383403
u32 target_session, u32 request_type)
@@ -715,12 +735,9 @@ acl_fa_session_cleaner_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
715735
"ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %u",
716736
"i4",
717737
(u32) (pw0 - am->per_worker_data));
718-
vlib_process_suspend (vm, 0.0001);
719-
if (pw0->interrupt_is_needed)
720-
{
721-
send_one_worker_interrupt (vm, am,
722-
(pw0 - am->per_worker_data));
723-
}
738+
ensure_worker_cleaner_interrupt (
739+
am, pw0 - am->per_worker_data);
740+
vlib_process_suspend (vm, 0.001);
724741
}
725742
if (pw0->clear_in_process)
726743
{
@@ -765,12 +782,9 @@ acl_fa_session_cleaner_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
765782
"ACL_FA_NODE_CLEAN: waiting for my cleaning cycle to finish on %u",
766783
"i4",
767784
(u32) (pw0 - am->per_worker_data));
768-
vlib_process_suspend (vm, 0.0001);
769-
if (pw0->interrupt_is_needed)
770-
{
771-
send_one_worker_interrupt (vm, am,
772-
(pw0 - am->per_worker_data));
773-
}
785+
ensure_worker_cleaner_interrupt (
786+
am, pw0 - am->per_worker_data);
787+
vlib_process_suspend (vm, 0.001);
774788
}
775789
}
776790
acl_log_info ("ACL_FA_NODE_CLEAN: cleaning done");
@@ -962,3 +976,5 @@ VLIB_REGISTER_NODE (acl_fa_session_cleaner_process_node, static) = {
962976
* eval: (c-set-style "gnu")
963977
* End:
964978
*/
979+
980+

ET2500/vpp-24.02/src/plugins/dns/dns.c

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,37 +2524,61 @@ VLIB_CLI_COMMAND (show_dns_cache_command) =
25242524
/* *INDENT-ON* */
25252525

25262526
static clib_error_t *
2527-
dns_enable_disable_command_fn (vlib_main_t *vm, unformat_input_t *input,
2528-
vlib_cli_command_t *cmd)
2527+
dns_enable_disable_common (vlib_main_t *vm, u32 enable_disable)
25292528
{
25302529
dns_main_t *dm = &dns_main;
2531-
u32 enable_disable;
25322530
int rv;
25332531

2534-
enable_disable = 0;
2535-
2536-
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2537-
{
2538-
if (unformat (input, "enable"))
2539-
enable_disable = 1;
2540-
else if (unformat (input, "disable"))
2541-
enable_disable = 0;
2542-
else
2543-
return clib_error_return (0, "unknown input `%U'",
2544-
format_unformat_error, input);
2545-
}
2546-
25472532
rv = dns_enable_disable (vm, dm, enable_disable);
25482533
if (rv)
25492534
return clib_error_return (0, "%U", format_vnet_api_errno, rv);
25502535

25512536
return 0;
25522537
}
25532538

2554-
VLIB_CLI_COMMAND (dns_enable_disable_command) = {
2539+
static clib_error_t *
2540+
dns_enable_command_fn (vlib_main_t *vm, unformat_input_t *input,
2541+
vlib_cli_command_t *cmd)
2542+
{
2543+
if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2544+
return clib_error_return (0, "unknown input `%U'",
2545+
format_unformat_error, input);
2546+
2547+
return dns_enable_disable_common (vm, 1);
2548+
}
2549+
2550+
static clib_error_t *
2551+
dns_disable_command_fn (vlib_main_t *vm, unformat_input_t *input,
2552+
vlib_cli_command_t *cmd)
2553+
{
2554+
if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2555+
return clib_error_return (0, "unknown input `%U'",
2556+
format_unformat_error, input);
2557+
2558+
return dns_enable_disable_common (vm, 0);
2559+
}
2560+
2561+
/*
2562+
* "dns" deliberately has no function of its own. If it had one, the CLI
2563+
* dispatcher would fall back to running it whenever a failing sub-command
2564+
* (e.g. "dns cache") returns an error, silently toggling name resolution
2565+
* with already-consumed input.
2566+
*/
2567+
VLIB_CLI_COMMAND (dns_command) = {
25552568
.path = "dns",
25562569
.short_help = "dns [enable][disable]",
2557-
.function = dns_enable_disable_command_fn,
2570+
};
2571+
2572+
VLIB_CLI_COMMAND (dns_enable_command) = {
2573+
.path = "dns enable",
2574+
.short_help = "dns enable",
2575+
.function = dns_enable_command_fn,
2576+
};
2577+
2578+
VLIB_CLI_COMMAND (dns_disable_command) = {
2579+
.path = "dns disable",
2580+
.short_help = "dns disable",
2581+
.function = dns_disable_command_fn,
25582582
};
25592583

25602584
static clib_error_t *
@@ -2684,6 +2708,9 @@ dns_cache_add_del_command_fn (vlib_main_t * vm,
26842708
{
26852709
if (unformat (input, "%v", &name))
26862710
{
2711+
/* The cache hash uses strlen/strcmp, so the key must be
2712+
* a NULL-terminated C string */
2713+
dns_terminate_c_string (&name);
26872714
rv = dns_delete_by_name (dm, name);
26882715
switch (rv)
26892716
{
@@ -2715,13 +2742,17 @@ dns_cache_add_del_command_fn (vlib_main_t * vm,
27152742
/* Note: dns_add_static_entry consumes the name vector if OK... */
27162743
if (unformat (input, "%U", unformat_dns_reply, &dns_reply_data, &name))
27172744
{
2745+
/* The cache hash uses strlen/strcmp, so the key must be
2746+
* a NULL-terminated C string */
2747+
dns_terminate_c_string (&name);
27182748
rv = dns_add_static_entry (dm, name, dns_reply_data);
27192749
switch (rv)
27202750
{
27212751
case VNET_API_ERROR_ENTRY_ALREADY_EXISTS:
2752+
error = clib_error_return (0, "%v already in the cache...", name);
27222753
vec_free (name);
27232754
vec_free (dns_reply_data);
2724-
return clib_error_return (0, "%v already in the cache...", name);
2755+
return error;
27252756
case 0:
27262757
return 0;
27272758

ET2500/vpp-24.02/src/plugins/gre/gre.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,34 @@ gre_build_rewrite (vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type,
288288
return (rewrite);
289289
}
290290

291+
/**
292+
* Return a pointer to the inner header, i.e. just past the GRE header,
293+
* accounting for the optional GRE fields (checksum, key and sequence
294+
* number) as indicated by the GRE header flags (RFC 1701 / RFC 2784).
295+
* Note: routing information (deprecated by RFC 2784 and never generated
296+
* by VPP) is variable length and not accounted for here.
297+
*/
298+
static_always_inline void *
299+
gre_fixup_inner (const gre_header_t *gre)
300+
{
301+
/* work in network byte order: the flags masks are compile-time
302+
* constants, so no byte-order conversion is emitted at runtime */
303+
const u16 flags = gre->flags_and_version;
304+
uword offset = sizeof (gre_header_t);
305+
306+
/* the checksum and reserved/offset fields are present if either the
307+
* checksum or the routing flag is set */
308+
if (PREDICT_FALSE (flags & clib_host_to_net_u16 (GRE_FLAGS_CHECKSUM |
309+
GRE_FLAGS_ROUTING)))
310+
offset += 4;
311+
if (PREDICT_FALSE (flags & clib_host_to_net_u16 (GRE_FLAGS_KEY)))
312+
offset += sizeof (gre_key_t);
313+
if (PREDICT_FALSE (flags & clib_host_to_net_u16 (GRE_FLAGS_SEQUENCE)))
314+
offset += 4;
315+
316+
return ((void *) ((const u8 *) gre + offset));
317+
}
318+
291319
static void
292320
gre44_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b0,
293321
const void *data)
@@ -302,7 +330,7 @@ gre44_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b0,
302330
* that was applied at the midchain node */
303331
ip0->ip4.length =
304332
clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
305-
tunnel_encap_fixup_4o4 (flags, (ip4_header_t *) (ip0 + 1), &ip0->ip4);
333+
tunnel_encap_fixup_4o4 (flags, gre_fixup_inner (&ip0->gre), &ip0->ip4);
306334
ip0->ip4.checksum = ip4_header_checksum (&ip0->ip4);
307335
}
308336

@@ -320,7 +348,7 @@ gre64_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b0,
320348
* that was applied at the midchain node */
321349
ip0->ip4.length =
322350
clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
323-
tunnel_encap_fixup_6o4 (flags, (ip6_header_t *) (ip0 + 1), &ip0->ip4);
351+
tunnel_encap_fixup_6o4 (flags, gre_fixup_inner (&ip0->gre), &ip0->ip4);
324352
ip0->ip4.checksum = ip4_header_checksum (&ip0->ip4);
325353
}
326354

@@ -352,7 +380,7 @@ gre46_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b0,
352380
* at the midchain node */
353381
ip0->ip6.payload_length = clib_host_to_net_u16 (
354382
vlib_buffer_length_in_chain (vm, b0) - sizeof (ip0->ip6));
355-
tunnel_encap_fixup_4o6 (flags, b0, (ip4_header_t *) (ip0 + 1), &ip0->ip6);
383+
tunnel_encap_fixup_4o6 (flags, b0, gre_fixup_inner (&ip0->gre), &ip0->ip6);
356384
}
357385

358386
static void
@@ -369,7 +397,7 @@ gre66_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b0,
369397
* at the midchain node */
370398
ip0->ip6.payload_length = clib_host_to_net_u16 (
371399
vlib_buffer_length_in_chain (vm, b0) - sizeof (ip0->ip6));
372-
tunnel_encap_fixup_6o6 (flags, (ip6_header_t *) (ip0 + 1), &ip0->ip6);
400+
tunnel_encap_fixup_6o6 (flags, gre_fixup_inner (&ip0->gre), &ip0->ip6);
373401
}
374402

375403
static void

0 commit comments

Comments
 (0)