*/
#include "nat_ha.h"
-#include <vnet/udp/udp.h>
+#include <vnet/udp/udp_local.h>
#include <nat/nat.h>
#include <vppinfra/atomics.h>
/* NAT HA settings */
typedef struct nat_ha_main_s
{
+ u8 enabled;
/* local IP address and UDP port */
ip4_address_t src_ip_address;
u16 src_port;
}
void
-nat_ha_init (vlib_main_t * vm, nat_ha_sadd_cb_t sadd_cb,
- nat_ha_sdel_cb_t sdel_cb, nat_ha_sref_cb_t sref_cb)
+nat_ha_enable (nat_ha_sadd_cb_t sadd_cb,
+ nat_ha_sdel_cb_t sdel_cb, nat_ha_sref_cb_t sref_cb)
{
nat_ha_main_t *ha = &nat_ha_main;
- vlib_thread_main_t *tm = vlib_get_thread_main ();
- vlib_thread_registration_t *tr;
- uword *p;
- ha->src_ip_address.as_u32 = 0;
- ha->src_port = 0;
- ha->dst_ip_address.as_u32 = 0;
- ha->dst_port = 0;
- ha->in_resync = 0;
- ha->resync_ack_count = 0;
- ha->resync_ack_missed = 0;
- ha->vlib_main = vm;
ha->sadd_cb = sadd_cb;
ha->sdel_cb = sdel_cb;
ha->sref_cb = sref_cb;
- ha->num_workers = 0;
- vec_validate (ha->per_thread_data, tm->n_vlib_mains - 1);
+
+ ha->enabled = 1;
+}
+
+void
+nat_ha_disable ()
+{
+ nat_ha_main_t *ha = &nat_ha_main;
+ ha->dst_port = 0;
+ ha->enabled = 0;
+}
+
+void
+nat_ha_init (vlib_main_t * vm, u32 num_workers, u32 num_threads)
+{
+ nat_ha_main_t *ha = &nat_ha_main;
+ clib_memset (ha, 0, sizeof (*ha));
+
+ ha->vlib_main = vm;
ha->fq_index = ~0;
- p = hash_get_mem (tm->thread_registrations_by_name, "workers");
- if (p)
- {
- tr = (vlib_thread_registration_t *) p[0];
- if (tr)
- ha->num_workers = tr->count;
- }
+
+ ha->num_workers = num_workers;
+ vec_validate (ha->per_thread_data, num_threads);
#define _(N, s, v) ha->counters[v].name = s; \
ha->counters[v].stat_segment_name = "/nat44/ha/" s; \
nat_ha_event_add (&event, 0, thread_index, 0);
}
+static_always_inline u8
+plugin_enabled ()
+{
+ nat_ha_main_t *ha = &nat_ha_main;
+ return ha->enabled;
+}
+
/* per thread process waiting for interrupt */
static uword
nat_ha_worker_fn (vlib_main_t * vm, vlib_node_runtime_t * rt,
vlib_frame_t * f)
{
u32 thread_index = vm->thread_index;
+
+ if (plugin_enabled () == 0)
+ return 0;
+
/* flush HA NAT data under construction */
nat_ha_event_add (0, 1, thread_index, 0);
/* scan if we need to resend some non-ACKed data */
#define _(sym,str) NAT_HA_HANDOFF_ERROR_##sym,
foreach_nat_ha_handoff_error
#undef _
- NAT44_HANDOFF_N_ERROR,
+ NAT_HA_HANDOFF_N_ERROR,
} nat_ha_handoff_error_t;
static char *nat_ha_handoff_error_strings[] = {
return frame->n_vectors;
}
+int
+nat_ha_resync (u32 client_index, u32 pid,
+ nat_ha_resync_event_cb_t event_callback)
+{
+ return 0;
+}
+
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (nat_ha_handoff_node) = {
.function = nat_ha_handoff_node_fn,