#include <vnet/ip/ip4.h>
#include <vnet/ip/ip6.h>
#include <vnet/ip/ip6_packet.h>
+#include <vnet/ip/ip6_link.h>
#include <vnet/adj/adj.h>
#include <vnet/adj/adj_nbr.h>
#include <vnet/dpo/receive_dpo.h>
u32 ip4_rewrite_idx;
/* node index of "ip6-rewrite" node */
u32 ip6_rewrite_idx;
+ /* node index of "ip4-midchain" node */
+ u32 ip4_midchain_idx;
+ /* node index of "ip6-midchain" node */
+ u32 ip6_midchain_idx;
/* log class */
vlib_log_class_t log_class;
/* number of active udp4 sessions */
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, sw_if_index);
+ vnet_get_sw_interface_or_null (bfd_udp_main.vnet_main, sw_if_index);
if (sw_if)
{
bfd_udp_main.echo_source_sw_if_index = sw_if_index;
* 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);
+ vnet_get_sw_interface_or_null (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)
int
bfd_udp_calc_next_node (const struct bfd_session_s *bs, u32 * next_node)
{
+ vnet_main_t *vnm = vnet_get_main ();
const bfd_udp_session_t *bus = &bs->udp;
ip_adjacency_t *adj = adj_get (bus->adj_index);
+
+ /* don't try to send the buffer if the interface is not up */
+ if (!vnet_sw_interface_is_up (vnm, bus->key.sw_if_index))
+ return 0;
+
switch (adj->lookup_next_index)
{
case IP_LOOKUP_NEXT_ARP:
return 1;
}
break;
+ case IP_LOOKUP_NEXT_MIDCHAIN:
+ switch (bs->transport)
+ {
+ case BFD_TRANSPORT_UDP4:
+ *next_node = bfd_udp_main.ip4_midchain_idx;
+ return 1;
+ case BFD_TRANSPORT_UDP6:
+ *next_node = bfd_udp_main.ip6_midchain_idx;
+ return 1;
+ }
+ break;
default:
/* drop */
break;
{
bfd_udp_main_t *bum = &bfd_udp_main;
vnet_sw_interface_t *sw_if =
- vnet_get_sw_interface_safe (bfd_udp_main.vnet_main, sw_if_index);
+ vnet_get_sw_interface_or_null (bfd_udp_main.vnet_main, sw_if_index);
u8 local_ip_valid = 0;
ip_interface_address_t *ia = NULL;
if (!sw_if)
"IP family mismatch (local is ipv6, peer is ipv4)");
return VNET_API_ERROR_INVALID_ARGUMENT;
}
- ip6_main_t *im = &ip6_main;
- /* *INDENT-OFF* */
- foreach_ip_interface_address (
- &im->lookup_main, ia, sw_if_index, 0 /* honor unnumbered */, ({
- ip6_address_t *x =
- ip_interface_address_get_address (&im->lookup_main, ia);
- if (local_addr->ip6.as_u64[0] == x->as_u64[0] &&
- local_addr->ip6.as_u64[1] == x->as_u64[1])
- {
- /* valid address for this interface */
- local_ip_valid = 1;
- break;
- }
- }));
- /* *INDENT-ON* */
+
+ if (ip6_address_is_link_local_unicast (&local_addr->ip6))
+ {
+ const ip6_address_t *ll_addr;
+ ll_addr = ip6_get_link_local_address (sw_if_index);
+ if (ip6_address_is_equal (ll_addr, &local_addr->ip6))
+ {
+ /* valid address for this interface */
+ local_ip_valid = 1;
+ }
+ }
+ else
+ {
+ ip6_main_t *im = &ip6_main;
+ /* *INDENT-OFF* */
+ foreach_ip_interface_address (
+ &im->lookup_main, ia, sw_if_index, 0 /* honor unnumbered */, ({
+ ip6_address_t *x =
+ ip_interface_address_get_address (&im->lookup_main, ia);
+ if (local_addr->ip6.as_u64[0] == x->as_u64[0] &&
+ local_addr->ip6.as_u64[1] == x->as_u64[1])
+ {
+ /* valid address for this interface */
+ local_ip_valid = 1;
+ break;
+ }
+ }));
+ /* *INDENT-ON* */
+ }
}
if (!local_ip_valid)
}
vnet_api_error_t
-bfd_udp_session_set_flags (u32 sw_if_index,
+bfd_udp_session_set_flags (vlib_main_t * vm, u32 sw_if_index,
const ip46_address_t * local_addr,
const ip46_address_t * peer_addr, u8 admin_up_down)
{
bfd_unlock (bm);
return rv;
}
- bfd_session_set_flags (bs, admin_up_down);
+ bfd_session_set_flags (vm, bs, admin_up_down);
bfd_unlock (bm);
return 0;
}
BFD_UDP_INPUT_NEXT_NORMAL,
BFD_UDP_INPUT_NEXT_REPLY_ARP,
BFD_UDP_INPUT_NEXT_REPLY_REWRITE,
+ BFD_UDP_INPUT_NEXT_REPLY_MIDCHAIN,
BFD_UDP_INPUT_N_NEXT,
} bfd_udp_input_next_t;
BFD_UDP_N_ERROR,
} bfd_udp_error_t;
+typedef enum
+{
+ BFD_UDP_ECHO_INPUT_NEXT_NORMAL,
+ BFD_UDP_ECHO_INPUT_NEXT_REPLY_ARP,
+ BFD_UDP_ECHO_INPUT_NEXT_REPLY_REWRITE,
+ BFD_UDP_ECHO_INPUT_N_NEXT,
+} bfd_udp_echo_input_next_t;
+
/* Packet counters - BFD ECHO packets */
#define foreach_bfd_udp_echo_error(F) \
F (NONE, "good bfd echo packets (processed)") \
} bfd_rpc_update_t;
static void
-bfd_rpc_update_session (u32 bs_idx, const bfd_pkt_t * pkt)
+bfd_rpc_update_session (vlib_main_t * vm, u32 bs_idx, const bfd_pkt_t * pkt)
{
bfd_main_t *bm = &bfd_main;
bfd_lock (bm);
- bfd_consume_pkt (bm, pkt, bs_idx);
+ bfd_consume_pkt (vm, bm, pkt, bs_idx);
bfd_unlock (bm);
}
return BFD_UDP_ERROR_BAD;
}
BFD_DBG ("BFD session found, bs_idx=%u", bs->bs_idx);
- if (!bfd_verify_pkt_auth (pkt, b->current_length, bs))
+ if (!bfd_verify_pkt_auth (vm, pkt, b->current_length, bs))
{
BFD_ERR ("Packet verification failed, dropping packet");
return BFD_UDP_ERROR_BAD;
{
return err;
}
- bfd_rpc_update_session (bs->bs_idx, pkt);
+ bfd_rpc_update_session (vm, bs->bs_idx, pkt);
*bs_out = bs;
return BFD_UDP_ERROR_NONE;
}
return BFD_UDP_ERROR_BAD;
}
BFD_DBG ("BFD session found, bs_idx=%u", bs->bs_idx);
- if (!bfd_verify_pkt_auth (pkt, b->current_length, bs))
+ if (!bfd_verify_pkt_auth (vm, pkt, b->current_length, bs))
{
BFD_ERR ("Packet verification failed, dropping packet");
return BFD_UDP_ERROR_BAD;
{
return err;
}
- bfd_rpc_update_session (bs->bs_idx, pkt);
+ bfd_rpc_update_session (vm, bs->bs_idx, pkt);
*bs_out = bs;
return BFD_UDP_ERROR_NONE;
}
case IP_LOOKUP_NEXT_REWRITE:
next0 = BFD_UDP_INPUT_NEXT_REPLY_REWRITE;
break;
+ case IP_LOOKUP_NEXT_MIDCHAIN:
+ next0 = BFD_UDP_INPUT_NEXT_REPLY_MIDCHAIN;
+ break;
default:
/* drop */
break;
[BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
[BFD_UDP_INPUT_NEXT_REPLY_ARP] = "ip4-arp",
[BFD_UDP_INPUT_NEXT_REPLY_REWRITE] = "ip4-lookup",
+ [BFD_UDP_INPUT_NEXT_REPLY_MIDCHAIN] = "ip4-midchain",
},
};
/* *INDENT-ON* */
[BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
[BFD_UDP_INPUT_NEXT_REPLY_ARP] = "ip6-discover-neighbor",
[BFD_UDP_INPUT_NEXT_REPLY_REWRITE] = "ip6-lookup",
+ [BFD_UDP_INPUT_NEXT_REPLY_MIDCHAIN] = "ip6-midchain",
},
};
/* *INDENT-ON* */
}
bfd_lock (bm);
- if (bfd_consume_echo_pkt (bfd_udp_main.bfd_main, b0))
+ if (bfd_consume_echo_pkt (vm, bfd_udp_main.bfd_main, b0))
{
b0->error = rt->errors[BFD_UDP_ERROR_NONE];
- next0 = BFD_UDP_INPUT_NEXT_NORMAL;
+ next0 = BFD_UDP_ECHO_INPUT_NEXT_NORMAL;
}
else
{
vlib_node_increment_counter (vm, bfd_udp_echo4_input_node.index,
b0->error, 1);
}
- next0 = BFD_UDP_INPUT_NEXT_REPLY_REWRITE;
+ next0 = BFD_UDP_ECHO_INPUT_NEXT_REPLY_REWRITE;
}
bfd_unlock (bm);
.format_trace = bfd_echo_input_format_trace,
- .n_next_nodes = BFD_UDP_INPUT_N_NEXT,
+ .n_next_nodes = BFD_UDP_ECHO_INPUT_N_NEXT,
.next_nodes =
{
- [BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
- [BFD_UDP_INPUT_NEXT_REPLY_ARP] = "ip4-arp",
- [BFD_UDP_INPUT_NEXT_REPLY_REWRITE] = "ip4-lookup",
+ [BFD_UDP_ECHO_INPUT_NEXT_NORMAL] = "error-drop",
+ [BFD_UDP_ECHO_INPUT_NEXT_REPLY_ARP] = "ip4-arp",
+ [BFD_UDP_ECHO_INPUT_NEXT_REPLY_REWRITE] = "ip4-lookup",
},
};
/* *INDENT-ON* */
.format_trace = bfd_echo_input_format_trace,
- .n_next_nodes = BFD_UDP_INPUT_N_NEXT,
+ .n_next_nodes = BFD_UDP_ECHO_INPUT_N_NEXT,
.next_nodes =
{
- [BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
- [BFD_UDP_INPUT_NEXT_REPLY_ARP] = "ip6-discover-neighbor",
- [BFD_UDP_INPUT_NEXT_REPLY_REWRITE] = "ip6-lookup",
+ [BFD_UDP_ECHO_INPUT_NEXT_NORMAL] = "error-drop",
+ [BFD_UDP_ECHO_INPUT_NEXT_REPLY_ARP] = "ip6-discover-neighbor",
+ [BFD_UDP_ECHO_INPUT_NEXT_REPLY_REWRITE] = "ip6-lookup",
},
};
vlib_log_notice (bum->log_class,
"removal of sw_if_index=%u forces removal of bfd session "
"with bs_idx=%u", sw_if_index, (*bs)->bs_idx);
- bfd_session_set_flags (*bs, 0);
+ bfd_session_set_flags (vlib_get_main (), *bs, 0);
bfd_udp_del_session_internal (vlib_get_main (), *bs);
}
return 0;
node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite");
ASSERT (node);
bfd_udp_main.ip6_rewrite_idx = node->index;
+ node = vlib_get_node_by_name (vm, (u8 *) "ip4-midchain");
+ ASSERT (node);
+ bfd_udp_main.ip4_midchain_idx = node->index;
+ node = vlib_get_node_by_name (vm, (u8 *) "ip6-midchain");
+ ASSERT (node);
+ bfd_udp_main.ip6_midchain_idx = node->index;
bfd_udp_main.log_class = vlib_log_register_class ("bfd", "udp");
vlib_log_debug (bfd_udp_main.log_class, "initialized");