VPP-598: tcp stack initial commit
[vpp.git] / src / vnet / bfd / bfd_udp.c
index e1ff8a9..cf05089 100644 (file)
@@ -1,18 +1,35 @@
+/*
+ * Copyright (c) 2011-2016 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #include <vppinfra/types.h>
 #include <vlibmemory/api.h>
 #include <vlib/vlib.h>
 #include <vlib/buffer.h>
 #include <vnet/ip/format.h>
 #include <vnet/ethernet/packet.h>
-#include <vnet/ip/udp_packet.h>
+#include <vnet/udp/udp_packet.h>
+#include <vnet/udp/udp.h>
 #include <vnet/ip/lookup.h>
 #include <vnet/ip/icmp46_packet.h>
 #include <vnet/ip/ip4.h>
 #include <vnet/ip/ip6.h>
-#include <vnet/ip/udp.h>
 #include <vnet/ip/ip6_packet.h>
 #include <vnet/adj/adj.h>
 #include <vnet/adj/adj_nbr.h>
+#include <vnet/dpo/receive_dpo.h>
+#include <vnet/fib/fib_entry.h>
+#include <vnet/fib/fib_table.h>
 #include <vnet/bfd/bfd_debug.h>
 #include <vnet/bfd/bfd_udp.h>
 #include <vnet/bfd/bfd_main.h>
@@ -24,17 +41,183 @@ typedef struct
   /* hashmap - bfd session index by bfd key - used for CLI/API lookup, where
    * discriminator is unknown */
   mhash_t bfd_session_idx_by_bfd_key;
+  /* convenience variable */
+  vnet_main_t *vnet_main;
+  /* flag indicating whether echo_source_sw_if_index holds a valid value */
+  int echo_source_is_set;
+  /* loopback interface used to get echo source ip */
+  u32 echo_source_sw_if_index;
 } bfd_udp_main_t;
 
 static vlib_node_registration_t bfd_udp4_input_node;
 static vlib_node_registration_t bfd_udp6_input_node;
+static vlib_node_registration_t bfd_udp_echo4_input_node;
+static vlib_node_registration_t bfd_udp_echo6_input_node;
 
 bfd_udp_main_t bfd_udp_main;
 
-void
+vnet_api_error_t
+bfd_udp_set_echo_source (u32 sw_if_index)
+{
+  vnet_sw_interface_t *sw_if =
+    vnet_get_sw_interface_safe (bfd_udp_main.vnet_main,
+                               bfd_udp_main.echo_source_sw_if_index);
+  if (sw_if)
+    {
+      bfd_udp_main.echo_source_sw_if_index = sw_if_index;
+      bfd_udp_main.echo_source_is_set = 1;
+      return 0;
+    }
+  return VNET_API_ERROR_BFD_ENOENT;
+}
+
+vnet_api_error_t
+bfd_udp_del_echo_source (u32 sw_if_index)
+{
+  bfd_udp_main.echo_source_sw_if_index = ~0;
+  bfd_udp_main.echo_source_is_set = 0;
+  return 0;
+}
+
+int
+bfd_udp_is_echo_available (bfd_transport_e transport)
+{
+  if (!bfd_udp_main.echo_source_is_set)
+    {
+      return 0;
+    }
+  /*
+   * for the echo to work, we need a loopback interface with at least one
+   * address with netmask length at most 31 (ip4) or 127 (ip6) so that we can
+   * pick an unused address from that subnet
+   */
+  vnet_sw_interface_t *sw_if =
+    vnet_get_sw_interface_safe (bfd_udp_main.vnet_main,
+                               bfd_udp_main.echo_source_sw_if_index);
+  if (sw_if && sw_if->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
+    {
+      if (BFD_TRANSPORT_UDP4 == transport)
+       {
+         ip4_main_t *im = &ip4_main;
+         ip_interface_address_t *ia = NULL;
+          /* *INDENT-OFF* */
+          foreach_ip_interface_address (&im->lookup_main, ia,
+                                        bfd_udp_main.echo_source_sw_if_index,
+                                        0 /* honor unnumbered */, ({
+                                          if (ia->address_length <= 31)
+                                            {
+                                              return 1;
+                                            }
+                                        }));
+          /* *INDENT-ON* */
+       }
+      else if (BFD_TRANSPORT_UDP6 == transport)
+       {
+         ip6_main_t *im = &ip6_main;
+         ip_interface_address_t *ia = NULL;
+          /* *INDENT-OFF* */
+          foreach_ip_interface_address (&im->lookup_main, ia,
+                                        bfd_udp_main.echo_source_sw_if_index,
+                                        0 /* honor unnumbered */, ({
+                                          if (ia->address_length <= 127)
+                                            {
+                                              return 1;
+                                            }
+                                        }));
+          /* *INDENT-ON* */
+       }
+    }
+  return 0;
+}
+
+static u16
+bfd_udp_bs_idx_to_sport (u32 bs_idx)
+{
+  /* The source port MUST be in the range 49152 through 65535. The same UDP
+   * source port number MUST be used for all BFD Control packets associated
+   * with a particular session.  The source port number SHOULD be unique among
+   * all BFD sessions on the system. If more than 16384 BFD sessions are
+   * simultaneously active, UDP source port numbers MAY be reused on
+   * multiple sessions, but the number of distinct uses of the same UDP
+   * source port number SHOULD be minimized.
+   */
+  return 49152 + bs_idx % (65535 - 49152 + 1);
+}
+
+static void
+lol ()
+{
+}
+
+int
+bfd_udp_get_echo_src_ip4 (ip4_address_t * addr)
+{
+  if (!bfd_udp_main.echo_source_is_set)
+    {
+      BFD_ERR ("cannot find ip4 address, echo source not set");
+      return 0;
+    }
+  ip_interface_address_t *ia = NULL;
+  ip4_main_t *im = &ip4_main;
+
+  /* *INDENT-OFF* */
+  foreach_ip_interface_address (
+      &im->lookup_main, ia, bfd_udp_main.echo_source_sw_if_index,
+      0 /* honor unnumbered */, ({
+        ip4_address_t *x =
+            ip_interface_address_get_address (&im->lookup_main, ia);
+        if (ia->address_length <= 31)
+          {
+            addr->as_u32 = clib_host_to_net_u32 (x->as_u32);
+           /*
+            * flip the last bit to get a different address, might be network,
+            * we don't care ...
+            */
+           addr->as_u32 ^= 1;
+            addr->as_u32 = clib_net_to_host_u32 (addr->as_u32);
+            return 1;
+          }
+      }));
+  /* *INDENT-ON* */
+  BFD_ERR ("cannot find ip4 address, no usable address found");
+  return 0;
+}
+
+int
+bfd_udp_get_echo_src_ip6 (ip6_address_t * addr)
+{
+  if (!bfd_udp_main.echo_source_is_set)
+    {
+      BFD_ERR ("cannot find ip6 address, echo source not set");
+      return 0;
+    }
+  ip_interface_address_t *ia = NULL;
+  ip6_main_t *im = &ip6_main;
+
+  /* *INDENT-OFF* */
+  foreach_ip_interface_address (
+      &im->lookup_main, ia, bfd_udp_main.echo_source_sw_if_index,
+      0 /* honor unnumbered */, ({
+        ip6_address_t *x =
+            ip_interface_address_get_address (&im->lookup_main, ia);
+        if (ia->address_length <= 127)
+          {
+            *addr = *x;
+            addr->as_u8[15] ^= 1; /* flip the last bit of the address */
+            lol ();
+            return 1;
+          }
+      }));
+  /* *INDENT-ON* */
+  BFD_ERR ("cannot find ip6 address, no usable address found");
+  return 0;
+}
+
+int
 bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b,
-                       bfd_udp_session_t * bus)
+                       const bfd_session_t * bs, int is_echo)
 {
+  const bfd_udp_session_t *bus = &bs->udp;
   const bfd_udp_key_t *key = &bus->key;
 
   b->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
@@ -52,11 +235,24 @@ bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b,
   headers->ip4.ip_version_and_header_length = 0x45;
   headers->ip4.ttl = 255;
   headers->ip4.protocol = IP_PROTOCOL_UDP;
-  headers->ip4.src_address.as_u32 = key->local_addr.ip4.as_u32;
-  headers->ip4.dst_address.as_u32 = key->peer_addr.ip4.as_u32;
-
-  headers->udp.src_port = clib_host_to_net_u16 (50000);        /* FIXME */
-  headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4);
+  headers->udp.src_port =
+    clib_host_to_net_u16 (bfd_udp_bs_idx_to_sport (bs->bs_idx));
+  if (is_echo)
+    {
+      int rv;
+      if (!(rv = bfd_udp_get_echo_src_ip4 (&headers->ip4.src_address)))
+       {
+         return rv;
+       }
+      headers->ip4.dst_address.as_u32 = key->local_addr.ip4.as_u32;
+      headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd_echo4);
+    }
+  else
+    {
+      headers->ip4.src_address.as_u32 = key->local_addr.ip4.as_u32;
+      headers->ip4.dst_address.as_u32 = key->peer_addr.ip4.as_u32;
+      headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4);
+    }
 
   /* fix ip length, checksum and udp length */
   const u16 ip_length = vlib_buffer_length_in_chain (vm, b);
@@ -66,12 +262,14 @@ bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b,
 
   const u16 udp_length = ip_length - (sizeof (headers->ip4));
   headers->udp.length = clib_host_to_net_u16 (udp_length);
+  return 1;
 }
 
-void
+int
 bfd_add_udp6_transport (vlib_main_t * vm, vlib_buffer_t * b,
-                       bfd_udp_session_t * bus)
+                       const bfd_session_t * bs, int is_echo)
 {
+  const bfd_udp_session_t *bus = &bs->udp;
   const bfd_udp_key_t *key = &bus->key;
 
   b->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
@@ -90,13 +288,28 @@ bfd_add_udp6_transport (vlib_main_t * vm, vlib_buffer_t * b,
     clib_host_to_net_u32 (0x6 << 28);
   headers->ip6.hop_limit = 255;
   headers->ip6.protocol = IP_PROTOCOL_UDP;
-  clib_memcpy (&headers->ip6.src_address, &key->local_addr.ip6,
-              sizeof (headers->ip6.src_address));
-  clib_memcpy (&headers->ip6.dst_address, &key->peer_addr.ip6,
-              sizeof (headers->ip6.dst_address));
+  headers->udp.src_port =
+    clib_host_to_net_u16 (bfd_udp_bs_idx_to_sport (bs->bs_idx));
+  if (is_echo)
+    {
+      int rv;
+      if (!(rv = bfd_udp_get_echo_src_ip6 (&headers->ip6.src_address)))
+       {
+         return rv;
+       }
+      clib_memcpy (&headers->ip6.dst_address, &key->local_addr.ip6,
+                  sizeof (headers->ip6.dst_address));
 
-  headers->udp.src_port = clib_host_to_net_u16 (50000);        /* FIXME */
-  headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd6);
+      headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd_echo6);
+    }
+  else
+    {
+      clib_memcpy (&headers->ip6.src_address, &key->local_addr.ip6,
+                  sizeof (headers->ip6.src_address));
+      clib_memcpy (&headers->ip6.dst_address, &key->peer_addr.ip6,
+                  sizeof (headers->ip6.dst_address));
+      headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd6);
+    }
 
   /* fix ip payload length and udp length */
   const u16 udp_length =
@@ -113,6 +326,7 @@ bfd_add_udp6_transport (vlib_main_t * vm, vlib_buffer_t * b,
     {
       headers->udp.checksum = 0xffff;
     }
+  return 1;
 }
 
 static bfd_session_t *
@@ -148,12 +362,17 @@ bfd_udp_add_session_internal (bfd_udp_main_t * bum, u32 sw_if_index,
                              bfd_session_t ** bs_out)
 {
   /* get a pool entry and if we end up not needing it, give it back */
-  bfd_transport_t t = BFD_TRANSPORT_UDP4;
+  bfd_transport_e t = BFD_TRANSPORT_UDP4;
   if (!ip46_address_is_ip4 (local_addr))
     {
       t = BFD_TRANSPORT_UDP6;
     }
   bfd_session_t *bs = bfd_get_session (bum->bfd_main, t);
+  if (!bs)
+    {
+      bfd_put_session (bum->bfd_main, bs);
+      return VNET_API_ERROR_BFD_EAGAIN;
+    }
   bfd_udp_session_t *bus = &bs->udp;
   memset (bus, 0, sizeof (*bus));
   bfd_udp_key_t *key = &bus->key;
@@ -179,6 +398,21 @@ bfd_udp_add_session_internal (bfd_udp_main_t * bum, u32 sw_if_index,
       BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, VNET_LINK_IP4, %U, %d) "
               "returns %d", format_ip46_address, &key->peer_addr,
               IP46_TYPE_ANY, key->sw_if_index, bus->adj_index);
+
+      fib_prefix_t fib_prefix;
+      memset (&fib_prefix, 0, sizeof (fib_prefix));
+      fib_prefix.fp_len = 0;
+      fib_prefix.fp_proto = FIB_PROTOCOL_IP4;
+      fib_prefix.fp_addr = key->local_addr;
+      u32 fib_index = fib_table_find (FIB_PROTOCOL_IP4, 0);    /* FIXME table id 0? */
+      dpo_id_t dpo = DPO_INVALID;
+      dpo_proto_t dproto;
+      dproto = fib_proto_to_dpo (fib_prefix.fp_proto);
+      receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
+      fib_table_entry_special_dpo_update (fib_index, &fib_prefix,
+                                         FIB_SOURCE_API,
+                                         FIB_ENTRY_FLAG_LOCAL, &dpo);
+      dpo_reset (&dpo);
     }
   else
     {
@@ -200,7 +434,7 @@ bfd_udp_validate_api_input (u32 sw_if_index,
                            const ip46_address_t * peer_addr)
 {
   vnet_sw_interface_t *sw_if =
-    vnet_get_sw_interface (vnet_get_main (), sw_if_index);
+    vnet_get_sw_interface_safe (bfd_udp_main.vnet_main, sw_if_index);
   u8 local_ip_valid = 0;
   ip_interface_address_t *ia = NULL;
   if (!sw_if)
@@ -562,11 +796,10 @@ typedef enum
   BFD_UDP_INPUT_N_NEXT,
 } bfd_udp_input_next_t;
 
-/* Packet counters */
+/* Packet counters - BFD control frames */
 #define foreach_bfd_udp_error(F)           \
   F (NONE, "good bfd packets (processed)") \
-  F (BAD, "invalid bfd packets")           \
-  F (DISABLED, "bfd packets received on disabled interfaces")
+  F (BAD, "invalid bfd packets")
 
 #define F(sym, string) static char BFD_UDP_ERR_##sym##_STR[] = string;
 foreach_bfd_udp_error (F);
@@ -586,9 +819,32 @@ typedef enum
     BFD_UDP_N_ERROR,
 } bfd_udp_error_t;
 
+/* Packet counters - BFD ECHO packets */
+#define foreach_bfd_udp_echo_error(F)           \
+  F (NONE, "good bfd echo packets (processed)") \
+  F (BAD, "invalid bfd echo packets")
+
+#define F(sym, string) static char BFD_UDP_ECHO_ERR_##sym##_STR[] = string;
+foreach_bfd_udp_echo_error (F);
+#undef F
+
+static char *bfd_udp_echo_error_strings[] = {
+#define F(sym, string) BFD_UDP_ECHO_ERR_##sym##_STR,
+  foreach_bfd_udp_echo_error (F)
+#undef F
+};
+
+typedef enum
+{
+#define F(sym, str) BFD_UDP_ECHO_ERROR_##sym,
+  foreach_bfd_udp_echo_error (F)
+#undef F
+    BFD_UDP_ECHO_N_ERROR,
+} bfd_udp_echo_error_t;
+
 static void
-bfd_udp4_find_headers (vlib_buffer_t * b, const ip4_header_t ** ip4,
-                      const udp_header_t ** udp)
+bfd_udp4_find_headers (vlib_buffer_t * b, ip4_header_t ** ip4,
+                      udp_header_t ** udp)
 {
   /* sanity check first */
   const i32 start = vnet_buffer (b)->ip.start_of_ip_header;
@@ -682,8 +938,8 @@ bfd_udp4_scan (vlib_main_t * vm, vlib_node_runtime_t * rt,
         b->current_length, sizeof (*pkt));
       return BFD_UDP_ERROR_BAD;
     }
-  const ip4_header_t *ip4;
-  const udp_header_t *udp;
+  ip4_header_t *ip4;
+  udp_header_t *udp;
   bfd_udp4_find_headers (b, &ip4, &udp);
   if (!ip4 || !udp)
     {
@@ -744,8 +1000,8 @@ bfd_udp4_scan (vlib_main_t * vm, vlib_node_runtime_t * rt,
 }
 
 static void
-bfd_udp6_find_headers (vlib_buffer_t * b, const ip6_header_t ** ip6,
-                      const udp_header_t ** udp)
+bfd_udp6_find_headers (vlib_buffer_t * b, ip6_header_t ** ip6,
+                      udp_header_t ** udp)
 {
   /* sanity check first */
   const i32 start = vnet_buffer (b)->ip.start_of_ip_header;
@@ -824,8 +1080,8 @@ bfd_udp6_scan (vlib_main_t * vm, vlib_node_runtime_t * rt,
         b->current_length, sizeof (*pkt));
       return BFD_UDP_ERROR_BAD;
     }
-  const ip6_header_t *ip6;
-  const udp_header_t *udp;
+  ip6_header_t *ip6;
+  udp_header_t *udp;
   bfd_udp6_find_headers (b, &ip6, &udp);
   if (!ip6 || !udp)
     {
@@ -945,7 +1201,8 @@ bfd_udp_input (vlib_main_t * vm, vlib_node_runtime_t * rt,
          const bfd_pkt_t *pkt = vlib_buffer_get_current (b0);
          if (bfd_pkt_get_poll (pkt))
            {
-             bfd_init_final_control_frame (vm, b0, bs);
+             bfd_init_final_control_frame (vm, b0, bfd_udp_main.bfd_main,
+                                           bs);
              if (is_ipv6)
                {
                  vlib_node_increment_counter (vm, bfd_udp6_input_node.index,
@@ -1025,6 +1282,147 @@ VLIB_REGISTER_NODE (bfd_udp6_input_node, static) = {
 };
 /* *INDENT-ON* */
 
+/*
+ * Process a frame of bfd echo packets
+ * Expect 1 packet / frame
+ */
+static uword
+bfd_udp_echo_input (vlib_main_t * vm, vlib_node_runtime_t * rt,
+                   vlib_frame_t * f, int is_ipv6)
+{
+  u32 n_left_from, *from;
+  bfd_input_trace_t *t0;
+
+  from = vlib_frame_vector_args (f);   /* array of buffer indices */
+  n_left_from = f->n_vectors;  /* number of buffer indices */
+
+  while (n_left_from > 0)
+    {
+      u32 bi0;
+      vlib_buffer_t *b0;
+      u32 next0;
+
+      bi0 = from[0];
+      b0 = vlib_get_buffer (vm, bi0);
+
+      /* If this pkt is traced, snapshot the data */
+      if (b0->flags & VLIB_BUFFER_IS_TRACED)
+       {
+         int len;
+         t0 = vlib_add_trace (vm, rt, b0, sizeof (*t0));
+         len = (b0->current_length < sizeof (t0->data)) ? b0->current_length
+           : sizeof (t0->data);
+         t0->len = len;
+         clib_memcpy (t0->data, vlib_buffer_get_current (b0), len);
+       }
+
+      if (bfd_consume_echo_pkt (bfd_udp_main.bfd_main, b0))
+       {
+         b0->error = rt->errors[BFD_UDP_ERROR_NONE];
+         next0 = BFD_UDP_INPUT_NEXT_NORMAL;
+       }
+      else
+       {
+         /* loop back the packet */
+         b0->error = rt->errors[BFD_UDP_ERROR_NONE];
+         if (is_ipv6)
+           {
+             vlib_node_increment_counter (vm, bfd_udp_echo6_input_node.index,
+                                          b0->error, 1);
+           }
+         else
+           {
+             vlib_node_increment_counter (vm, bfd_udp_echo4_input_node.index,
+                                          b0->error, 1);
+           }
+         next0 = BFD_UDP_INPUT_NEXT_REPLY;
+       }
+
+      vlib_set_next_frame_buffer (vm, rt, next0, bi0);
+
+      from += 1;
+      n_left_from -= 1;
+    }
+
+  return f->n_vectors;
+}
+
+static uword
+bfd_udp_echo4_input (vlib_main_t * vm, vlib_node_runtime_t * rt,
+                    vlib_frame_t * f)
+{
+  return bfd_udp_echo_input (vm, rt, f, 0);
+}
+
+u8 *
+bfd_echo_input_format_trace (u8 * s, va_list * args)
+{
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+  const bfd_udp_echo_input_trace_t *t =
+    va_arg (*args, bfd_udp_echo_input_trace_t *);
+  if (t->len > STRUCT_SIZE_OF (bfd_pkt_t, head))
+    {
+      s = format (s, "BFD ECHO:\n");
+      s = format (s, "    data: %U", format_hexdump, t->data, t->len);
+    }
+
+  return s;
+}
+
+/*
+ * bfd input graph node declaration
+ */
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (bfd_udp_echo4_input_node, static) = {
+  .function = bfd_udp_echo4_input,
+  .name = "bfd-udp-echo4-input",
+  .vector_size = sizeof (u32),
+  .type = VLIB_NODE_TYPE_INTERNAL,
+
+  .n_errors = BFD_UDP_ECHO_N_ERROR,
+  .error_strings = bfd_udp_error_strings,
+
+  .format_trace = bfd_echo_input_format_trace,
+
+  .n_next_nodes = BFD_UDP_INPUT_N_NEXT,
+  .next_nodes =
+      {
+              [BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
+              [BFD_UDP_INPUT_NEXT_REPLY] = "ip4-lookup",
+      },
+};
+/* *INDENT-ON* */
+
+static uword
+bfd_udp_echo6_input (vlib_main_t * vm, vlib_node_runtime_t * rt,
+                    vlib_frame_t * f)
+{
+  return bfd_udp_echo_input (vm, rt, f, 1);
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (bfd_udp_echo6_input_node, static) = {
+  .function = bfd_udp_echo6_input,
+  .name = "bfd-udp-echo6-input",
+  .vector_size = sizeof (u32),
+  .type = VLIB_NODE_TYPE_INTERNAL,
+
+  .n_errors = BFD_UDP_ECHO_N_ERROR,
+  .error_strings = bfd_udp_echo_error_strings,
+
+  .format_trace = bfd_echo_input_format_trace,
+
+  .n_next_nodes = BFD_UDP_INPUT_N_NEXT,
+  .next_nodes =
+      {
+              [BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
+              [BFD_UDP_INPUT_NEXT_REPLY] = "ip6-lookup",
+      },
+};
+
+/* *INDENT-ON* */
+
 static clib_error_t *
 bfd_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
 {
@@ -1059,8 +1457,13 @@ bfd_udp_init (vlib_main_t * vm)
   mhash_init (&bfd_udp_main.bfd_session_idx_by_bfd_key, sizeof (uword),
              sizeof (bfd_udp_key_t));
   bfd_udp_main.bfd_main = &bfd_main;
+  bfd_udp_main.vnet_main = vnet_get_main ();
   udp_register_dst_port (vm, UDP_DST_PORT_bfd4, bfd_udp4_input_node.index, 1);
   udp_register_dst_port (vm, UDP_DST_PORT_bfd6, bfd_udp6_input_node.index, 0);
+  udp_register_dst_port (vm, UDP_DST_PORT_bfd_echo4,
+                        bfd_udp_echo4_input_node.index, 1);
+  udp_register_dst_port (vm, UDP_DST_PORT_bfd_echo6,
+                        bfd_udp_echo6_input_node.index, 0);
   return 0;
 }