ipsec: User can choose the UDP source port
[vpp.git] / src / vnet / ipsec / ipsec.c
index 95e322e..0ef9067 100644 (file)
@@ -124,6 +124,61 @@ ipsec_add_node (vlib_main_t * vm, const char *node_name,
   *out_next_index = vlib_node_add_next (vm, prev_node->index, node->index);
 }
 
+void
+ipsec_add_feature (const char *arc_name,
+                  const char *node_name, u32 * out_feature_index)
+{
+  u8 arc;
+
+  arc = vnet_get_feature_arc_index (arc_name);
+  ASSERT (arc != (u8) ~ 0);
+  *out_feature_index = vnet_get_feature_index (arc, node_name);
+}
+
+void
+ipsec_unregister_udp_port (u16 port)
+{
+  ipsec_main_t *im = &ipsec_main;
+  u32 n_regs;
+  uword *p;
+
+  p = hash_get (im->udp_port_registrations, port);
+
+  ASSERT (p);
+
+  n_regs = p[0];
+
+  if (0 == --n_regs)
+    {
+      udp_unregister_dst_port (vlib_get_main (), port, 1);
+      hash_unset (im->udp_port_registrations, port);
+    }
+  else
+    {
+      hash_unset (im->udp_port_registrations, port);
+      hash_set (im->udp_port_registrations, port, n_regs);
+    }
+}
+
+void
+ipsec_register_udp_port (u16 port)
+{
+  ipsec_main_t *im = &ipsec_main;
+  u32 n_regs;
+  uword *p;
+
+  p = hash_get (im->udp_port_registrations, port);
+
+  n_regs = (p ? p[0] : 0);
+
+  if (0 == n_regs++)
+    udp_register_dst_port (vlib_get_main (), port,
+                          ipsec4_tun_input_node.index, 1);
+
+  hash_unset (im->udp_port_registrations, port);
+  hash_set (im->udp_port_registrations, port, n_regs);
+}
+
 u32
 ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im,
                           const char *name,