summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vnet/vnet/ip/format.c48
-rw-r--r--vnet/vnet/ip/format.h17
-rw-r--r--vnet/vnet/ip/icmp4.c456
-rw-r--r--vnet/vnet/ip/icmp4.h20
-rw-r--r--vnet/vnet/ip/icmp46_packet.h302
-rw-r--r--vnet/vnet/ip/icmp6.c514
-rw-r--r--vnet/vnet/ip/icmp6.h20
-rw-r--r--vnet/vnet/ip/igmp_packet.h33
-rw-r--r--vnet/vnet/ip/ip.h68
-rw-r--r--vnet/vnet/ip/ip4.h184
-rw-r--r--vnet/vnet/ip/ip46_cli.c76
-rw-r--r--vnet/vnet/ip/ip4_error.h13
-rw-r--r--vnet/vnet/ip/ip4_format.c87
-rw-r--r--vnet/vnet/ip/ip4_forward.c2578
-rw-r--r--vnet/vnet/ip/ip4_input.c246
-rw-r--r--vnet/vnet/ip/ip4_mtrie.c200
-rw-r--r--vnet/vnet/ip/ip4_mtrie.h80
-rw-r--r--vnet/vnet/ip/ip4_packet.h119
-rw-r--r--vnet/vnet/ip/ip4_pg.c152
-rw-r--r--vnet/vnet/ip/ip4_source_check.c272
-rw-r--r--vnet/vnet/ip/ip4_test.c325
-rw-r--r--vnet/vnet/ip/ip6.h298
-rw-r--r--vnet/vnet/ip/ip6_error.h13
-rw-r--r--vnet/vnet/ip/ip6_format.c204
-rw-r--r--vnet/vnet/ip/ip6_forward.c2560
-rw-r--r--vnet/vnet/ip/ip6_hop_by_hop.c20
-rw-r--r--vnet/vnet/ip/ip6_hop_by_hop.h108
-rw-r--r--vnet/vnet/ip/ip6_hop_by_hop_packet.h22
-rw-r--r--vnet/vnet/ip/ip6_input.c203
-rw-r--r--vnet/vnet/ip/ip6_neighbor.c3605
-rw-r--r--vnet/vnet/ip/ip6_neighbor.h18
-rw-r--r--vnet/vnet/ip/ip6_packet.h111
-rw-r--r--vnet/vnet/ip/ip6_pg.c95
-rw-r--r--vnet/vnet/ip/ip_api.c122
-rw-r--r--vnet/vnet/ip/ip_checksum.c84
-rw-r--r--vnet/vnet/ip/ip_frag.c750
-rw-r--r--vnet/vnet/ip/ip_frag.h30
-rw-r--r--vnet/vnet/ip/ip_init.c26
-rw-r--r--vnet/vnet/ip/ip_input_acl.c460
-rw-r--r--vnet/vnet/ip/ip_packet.h34
-rw-r--r--vnet/vnet/ip/lookup.c685
-rw-r--r--vnet/vnet/ip/lookup.h180
-rw-r--r--vnet/vnet/ip/ping.c518
-rw-r--r--vnet/vnet/ip/ping.h52
-rw-r--r--vnet/vnet/ip/punt.c6
-rw-r--r--vnet/vnet/ip/tcp_packet.h39
-rw-r--r--vnet/vnet/ip/udp.h161
-rw-r--r--vnet/vnet/ip/udp_format.c20
-rw-r--r--vnet/vnet/ip/udp_init.c18
-rw-r--r--vnet/vnet/ip/udp_local.c596
-rw-r--r--vnet/vnet/ip/udp_packet.h11
-rw-r--r--vnet/vnet/ip/udp_pg.c82
52 files changed, 9133 insertions, 7808 deletions
diff --git a/vnet/vnet/ip/format.c b/vnet/vnet/ip/format.c
index 0061d7ee414..be1c4fd32fb 100644
--- a/vnet/vnet/ip/format.c
+++ b/vnet/vnet/ip/format.c
@@ -40,11 +40,12 @@
#include <vnet/ip/ip.h>
/* Format IP protocol. */
-u8 * format_ip_protocol (u8 * s, va_list * args)
+u8 *
+format_ip_protocol (u8 * s, va_list * args)
{
ip_protocol_t protocol = va_arg (*args, ip_protocol_t);
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi = ip_get_protocol_info (im, protocol);
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi = ip_get_protocol_info (im, protocol);
if (pi)
return format (s, "%s", pi->name);
@@ -52,15 +53,16 @@ u8 * format_ip_protocol (u8 * s, va_list * args)
return format (s, "unknown %d", protocol);
}
-uword unformat_ip_protocol (unformat_input_t * input, va_list * args)
+uword
+unformat_ip_protocol (unformat_input_t * input, va_list * args)
{
- u8 * result = va_arg (*args, u8 *);
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi;
+ u8 *result = va_arg (*args, u8 *);
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi;
int i;
- if (! unformat_user (input, unformat_vlib_number_by_name,
- im->protocol_info_by_name, &i))
+ if (!unformat_user (input, unformat_vlib_number_by_name,
+ im->protocol_info_by_name, &i))
return 0;
pi = vec_elt_at_index (im->protocol_infos, i);
@@ -68,12 +70,13 @@ uword unformat_ip_protocol (unformat_input_t * input, va_list * args)
return 1;
}
-u8 * format_tcp_udp_port (u8 * s, va_list * args)
+u8 *
+format_tcp_udp_port (u8 * s, va_list * args)
{
int port = va_arg (*args, int);
- ip_main_t * im = &ip_main;
- tcp_udp_port_info_t * pi;
-
+ ip_main_t *im = &ip_main;
+ tcp_udp_port_info_t *pi;
+
pi = ip_get_tcp_udp_port_info (im, port);
if (pi)
s = format (s, "%s", pi->name);
@@ -83,13 +86,14 @@ u8 * format_tcp_udp_port (u8 * s, va_list * args)
return s;
}
-uword unformat_tcp_udp_port (unformat_input_t * input, va_list * args)
+uword
+unformat_tcp_udp_port (unformat_input_t * input, va_list * args)
{
- u16 * result = va_arg (*args, u16 *);
- ip_main_t * im = &ip_main;
- tcp_udp_port_info_t * pi;
+ u16 *result = va_arg (*args, u16 *);
+ ip_main_t *im = &ip_main;
+ tcp_udp_port_info_t *pi;
u32 i, port;
-
+
if (unformat_user (input, unformat_vlib_number_by_name,
im->port_info_by_name, &i))
@@ -107,3 +111,11 @@ uword unformat_tcp_udp_port (unformat_input_t * input, va_list * args)
*result = port;
return 1;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/format.h b/vnet/vnet/ip/format.h
index 8a76a61f17a..c35f0f4bb74 100644
--- a/vnet/vnet/ip/format.h
+++ b/vnet/vnet/ip/format.h
@@ -50,9 +50,9 @@ unformat_function_t unformat_tcp_udp_port;
typedef enum format_ip_adjacency_flags_t_
{
- FORMAT_IP_ADJACENCY_NONE,
- FORMAT_IP_ADJACENCY_BRIEF = FORMAT_IP_ADJACENCY_NONE,
- FORMAT_IP_ADJACENCY_DETAIL = (1 << 0),
+ FORMAT_IP_ADJACENCY_NONE,
+ FORMAT_IP_ADJACENCY_BRIEF = FORMAT_IP_ADJACENCY_NONE,
+ FORMAT_IP_ADJACENCY_DETAIL = (1 << 0),
} format_ip_adjacency_flags_t;
format_function_t format_ip_adjacency;
@@ -60,7 +60,8 @@ format_function_t format_ip_adjacency_packet_data;
format_function_t format_ip46_address;
-typedef enum {
+typedef enum
+{
IP46_TYPE_ANY,
IP46_TYPE_IP4,
IP46_TYPE_IP6
@@ -103,3 +104,11 @@ format_function_t format_tcp_header, format_udp_header;
unformat_function_t unformat_pg_tcp_header, unformat_pg_udp_header;
#endif /* included_ip_format_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/icmp4.c b/vnet/vnet/ip/icmp4.c
index b1834ac70da..c3afff72f26 100644
--- a/vnet/vnet/ip/icmp4.c
+++ b/vnet/vnet/ip/icmp4.c
@@ -42,17 +42,18 @@
#include <vnet/pg/pg.h>
-static char * icmp_error_strings[] = {
+static char *icmp_error_strings[] = {
#define _(f,s) s,
foreach_icmp4_error
#undef _
};
-static u8 * format_ip4_icmp_type_and_code (u8 * s, va_list * args)
+static u8 *
+format_ip4_icmp_type_and_code (u8 * s, va_list * args)
{
icmp4_type_t type = va_arg (*args, int);
u8 code = va_arg (*args, int);
- char * t = 0;
+ char *t = 0;
#define _(n,f) case n: t = #f; break;
@@ -66,7 +67,7 @@ static u8 * format_ip4_icmp_type_and_code (u8 * s, va_list * args)
#undef _
- if (! t)
+ if (!t)
return format (s, "unknown 0x%x", type);
s = format (s, "%s", t);
@@ -87,9 +88,10 @@ static u8 * format_ip4_icmp_type_and_code (u8 * s, va_list * args)
return s;
}
-static u8 * format_ip4_icmp_header (u8 * s, va_list * args)
+static u8 *
+format_ip4_icmp_header (u8 * s, va_list * args)
{
- icmp46_header_t * icmp = va_arg (*args, icmp46_header_t *);
+ icmp46_header_t *icmp = va_arg (*args, icmp46_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
/* Nothing to do. */
@@ -103,28 +105,30 @@ static u8 * format_ip4_icmp_header (u8 * s, va_list * args)
return s;
}
-static u8 * format_icmp_input_trace (u8 * s, va_list * va)
+static u8 *
+format_icmp_input_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
- icmp_input_trace_t * t = va_arg (*va, icmp_input_trace_t *);
+ icmp_input_trace_t *t = va_arg (*va, icmp_input_trace_t *);
s = format (s, "%U",
- format_ip4_header,
- t->packet_data, sizeof (t->packet_data));
+ format_ip4_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-typedef enum {
+typedef enum
+{
ICMP_INPUT_NEXT_ERROR,
ICMP_INPUT_N_NEXT,
} icmp_input_next_t;
-typedef struct {
- uword * type_and_code_by_name;
+typedef struct
+{
+ uword *type_and_code_by_name;
- uword * type_by_name;
+ uword *type_by_name;
/* Vector dispatch table indexed by [icmp type]. */
u8 ip4_input_next_index_by_type[256];
@@ -134,18 +138,17 @@ icmp4_main_t icmp4_main;
static uword
ip4_icmp_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- icmp4_main_t * im = &icmp4_main;
+ icmp4_main_t *im = &icmp4_main;
uword n_packets = frame->n_vectors;
- u32 * from, * to_next;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next;
from = vlib_frame_vector_args (frame);
n_left_from = n_packets;
next = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
@@ -157,27 +160,27 @@ ip4_icmp_input (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- icmp46_header_t * icmp0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ icmp46_header_t *icmp0;
icmp4_type_t type0;
u32 bi0, next0;
-
- if (PREDICT_TRUE (n_left_from > 2))
- {
- vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
- p0 = vlib_get_buffer (vm, from[1]);
- ip0 = vlib_buffer_get_current (p0);
- CLIB_PREFETCH(ip0, CLIB_CACHE_LINE_BYTES, LOAD);
- }
-
+
+ if (PREDICT_TRUE (n_left_from > 2))
+ {
+ vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
+ p0 = vlib_get_buffer (vm, from[1]);
+ ip0 = vlib_buffer_get_current (p0);
+ CLIB_PREFETCH (ip0, CLIB_CACHE_LINE_BYTES, LOAD);
+ }
+
bi0 = to_next[0] = from[0];
from += 1;
n_left_from -= 1;
to_next += 1;
n_left_to_next -= 1;
-
+
p0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (p0);
icmp0 = ip4_next_header (ip0);
@@ -195,13 +198,14 @@ ip4_icmp_input (vlib_main_t * vm,
n_left_to_next -= 1;
}
}
-
+
vlib_put_next_frame (vm, node, next, n_left_to_next);
}
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_icmp_input_node,static) = {
.function = ip4_icmp_input,
.name = "ip4-icmp-input",
@@ -218,23 +222,23 @@ VLIB_REGISTER_NODE (ip4_icmp_input_node,static) = {
[ICMP_INPUT_NEXT_ERROR] = "error-punt",
},
};
+/* *INDENT-ON* */
static uword
ip4_icmp_echo_request (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
uword n_packets = frame->n_vectors;
- u32 * from, * to_next;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next;
- ip4_main_t * i4m = &ip4_main;
- u16 * fragment_ids, * fid;
+ ip4_main_t *i4m = &ip4_main;
+ u16 *fragment_ids, *fid;
u8 host_config_ttl = i4m->host_config.ttl;
from = vlib_frame_vector_args (frame);
n_left_from = n_packets;
next = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
@@ -242,7 +246,8 @@ ip4_icmp_echo_request (vlib_main_t * vm,
/* Get random fragment IDs for replies. */
fid = fragment_ids = clib_random_buffer_get_data (&vm->random_buffer,
- n_packets * sizeof (fragment_ids[0]));
+ n_packets *
+ sizeof (fragment_ids[0]));
while (n_left_from > 0)
{
@@ -250,13 +255,13 @@ ip4_icmp_echo_request (vlib_main_t * vm,
while (n_left_from > 2 && n_left_to_next > 2)
{
- vlib_buffer_t * p0, * p1;
- ip4_header_t * ip0, * ip1;
- icmp46_header_t * icmp0, * icmp1;
+ vlib_buffer_t *p0, *p1;
+ ip4_header_t *ip0, *ip1;
+ icmp46_header_t *icmp0, *icmp1;
u32 bi0, src0, dst0;
u32 bi1, src1, dst1;
ip_csum_t sum0, sum1;
-
+
bi0 = to_next[0] = from[0];
bi1 = to_next[1] = from[1];
@@ -264,7 +269,7 @@ ip4_icmp_echo_request (vlib_main_t * vm,
n_left_from -= 2;
to_next += 2;
n_left_to_next -= 2;
-
+
p0 = vlib_get_buffer (vm, bi0);
p1 = vlib_get_buffer (vm, bi1);
ip0 = vlib_buffer_get_current (p0);
@@ -272,8 +277,10 @@ ip4_icmp_echo_request (vlib_main_t * vm,
icmp0 = ip4_next_header (ip0);
icmp1 = ip4_next_header (ip1);
- vnet_buffer (p0)->sw_if_index[VLIB_RX] = vnet_main.local_interface_sw_if_index;
- vnet_buffer (p1)->sw_if_index[VLIB_RX] = vnet_main.local_interface_sw_if_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_RX] =
+ vnet_main.local_interface_sw_if_index;
+ vnet_buffer (p1)->sw_if_index[VLIB_RX] =
+ vnet_main.local_interface_sw_if_index;
/* Update ICMP checksum. */
sum0 = icmp0->checksum;
@@ -329,30 +336,31 @@ ip4_icmp_echo_request (vlib_main_t * vm,
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
ASSERT (ip1->checksum == ip4_header_checksum (ip1));
- p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
- p1->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
+ p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
+ p1->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
}
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- icmp46_header_t * icmp0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ icmp46_header_t *icmp0;
u32 bi0, src0, dst0;
ip_csum_t sum0;
-
+
bi0 = to_next[0] = from[0];
from += 1;
n_left_from -= 1;
to_next += 1;
n_left_to_next -= 1;
-
+
p0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (p0);
icmp0 = ip4_next_header (ip0);
- vnet_buffer (p0)->sw_if_index[VLIB_RX] = vnet_main.local_interface_sw_if_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_RX] =
+ vnet_main.local_interface_sw_if_index;
/* Update ICMP checksum. */
sum0 = icmp0->checksum;
@@ -384,19 +392,19 @@ ip4_icmp_echo_request (vlib_main_t * vm,
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
- p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
+ p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
}
-
+
vlib_put_next_frame (vm, node, next, n_left_to_next);
}
vlib_error_count (vm, ip4_icmp_input_node.index,
- ICMP4_ERROR_ECHO_REPLIES_SENT,
- frame->n_vectors);
+ ICMP4_ERROR_ECHO_REPLIES_SENT, frame->n_vectors);
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_icmp_echo_request_node,static) = {
.function = ip4_icmp_echo_request,
.name = "ip4-icmp-echo-request",
@@ -410,153 +418,170 @@ VLIB_REGISTER_NODE (ip4_icmp_echo_request_node,static) = {
[0] = "ip4-load-balance",
},
};
+/* *INDENT-ON* */
-typedef enum {
+typedef enum
+{
IP4_ICMP_ERROR_NEXT_DROP,
IP4_ICMP_ERROR_NEXT_LOOKUP,
IP4_ICMP_ERROR_N_NEXT,
} ip4_icmp_error_next_t;
void
-icmp4_error_set_vnet_buffer (vlib_buffer_t *b, u8 type, u8 code, u32 data)
+icmp4_error_set_vnet_buffer (vlib_buffer_t * b, u8 type, u8 code, u32 data)
{
- vnet_buffer(b)->ip.icmp.type = type;
- vnet_buffer(b)->ip.icmp.code = code;
- vnet_buffer(b)->ip.icmp.data = data;
+ vnet_buffer (b)->ip.icmp.type = type;
+ vnet_buffer (b)->ip.icmp.code = code;
+ vnet_buffer (b)->ip.icmp.data = data;
}
static u8
icmp4_icmp_type_to_error (u8 type)
{
- switch (type) {
- case ICMP4_destination_unreachable:
- return ICMP4_ERROR_DEST_UNREACH_SENT;
- case ICMP4_time_exceeded:
- return ICMP4_ERROR_TTL_EXPIRE_SENT;
- case ICMP4_parameter_problem:
- return ICMP4_ERROR_PARAM_PROBLEM_SENT;
- default:
- return ICMP4_ERROR_DROP;
- }
+ switch (type)
+ {
+ case ICMP4_destination_unreachable:
+ return ICMP4_ERROR_DEST_UNREACH_SENT;
+ case ICMP4_time_exceeded:
+ return ICMP4_ERROR_TTL_EXPIRE_SENT;
+ case ICMP4_parameter_problem:
+ return ICMP4_ERROR_PARAM_PROBLEM_SENT;
+ default:
+ return ICMP4_ERROR_DROP;
+ }
}
static uword
ip4_icmp_error (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- u32 * from, * to_next;
+ u32 *from, *to_next;
uword n_left_from, n_left_to_next;
ip4_icmp_error_next_t next_index;
ip4_main_t *im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
- from = vlib_frame_vector_args(frame);
+ from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
- /* stride */ 1, sizeof (icmp_input_trace_t));
-
- while (n_left_from > 0) {
- vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
-
- while (n_left_from > 0 && n_left_to_next > 0) {
- u32 pi0 = from[0];
- u32 next0 = IP4_ICMP_ERROR_NEXT_LOOKUP;
- u8 error0 = ICMP4_ERROR_NONE;
- vlib_buffer_t * p0;
- ip4_header_t * ip0, * out_ip0;
- icmp46_header_t * icmp0;
- u32 sw_if_index0, if_add_index0;
- ip_csum_t sum;
-
- /* Speculatively enqueue p0 to the current next frame */
- to_next[0] = pi0;
- from += 1;
- to_next += 1;
- n_left_from -= 1;
- n_left_to_next -= 1;
-
- p0 = vlib_get_buffer(vm, pi0);
- ip0 = vlib_buffer_get_current(p0);
- sw_if_index0 = vnet_buffer(p0)->sw_if_index[VLIB_RX];
-
- /*
- * RFC1812 says to keep as much of the original packet as
- * possible within the minimum MTU (576). We cheat "a little"
- * here by keeping whatever fits in the first buffer, to be more
- * efficient
- */
- if (PREDICT_FALSE(p0->total_length_not_including_first_buffer)) {
- /* clear current_length of all other buffers in chain */
- vlib_buffer_t *b = p0;
- p0->total_length_not_including_first_buffer = 0;
- while (b->flags & VLIB_BUFFER_NEXT_PRESENT) {
- b = vlib_get_buffer (vm, b->next_buffer);
- b->current_length = 0;
- }
- }
- p0->current_length = p0->current_length > 576 ? 576 : p0->current_length;
-
- /* Add IP header and ICMPv4 header including a 4 byte data field */
- vlib_buffer_advance(p0,
- -sizeof(ip4_header_t)-sizeof(icmp46_header_t)-4);
- out_ip0 = vlib_buffer_get_current(p0);
- icmp0 = (icmp46_header_t *) &out_ip0[1];
-
- /* Fill ip header fields */
- out_ip0->ip_version_and_header_length = 0x45;
- out_ip0->tos = 0;
- out_ip0->length = clib_host_to_net_u16(p0->current_length);
- out_ip0->fragment_id = 0;
- out_ip0->flags_and_fragment_offset = 0;
- out_ip0->ttl = 0xff;
- out_ip0->protocol = IP_PROTOCOL_ICMP;
- out_ip0->dst_address = ip0->src_address;
- if_add_index0 = ~0;
- if (PREDICT_TRUE (vec_len (lm->if_address_pool_index_by_sw_if_index)
- > sw_if_index0))
- if_add_index0 =
- lm->if_address_pool_index_by_sw_if_index[sw_if_index0];
- if (PREDICT_TRUE(if_add_index0 != ~0)) {
- ip_interface_address_t *if_add =
- pool_elt_at_index(lm->if_address_pool, if_add_index0);
- ip4_address_t *if_ip =
- ip_interface_address_get_address(lm, if_add);
- out_ip0->src_address = *if_ip;
- } else {
- /* interface has no IP4 address - should not happen */
- next0 = IP4_ICMP_ERROR_NEXT_DROP;
- error0 = ICMP4_ERROR_DROP;
- }
- out_ip0->checksum = ip4_header_checksum(out_ip0);
-
- /* Fill icmp header fields */
- icmp0->type = vnet_buffer(p0)->ip.icmp.type;
- icmp0->code = vnet_buffer(p0)->ip.icmp.code;
- *((u32 *)(icmp0 + 1)) = clib_host_to_net_u32(vnet_buffer(p0)->ip.icmp.data);
- icmp0->checksum = 0;
- sum = ip_incremental_checksum(0, icmp0, p0->current_length - sizeof(ip4_header_t));
- icmp0->checksum = ~ip_csum_fold(sum);
-
- /* Update error status */
- if (error0 == ICMP4_ERROR_NONE)
- error0 = icmp4_icmp_type_to_error(icmp0->type);
- vlib_error_count(vm, node->node_index, error0, 1);
-
- /* Verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1(vm, node, next_index,
- to_next, n_left_to_next,
- pi0, next0);
+ /* stride */ 1,
+ sizeof (icmp_input_trace_t));
+
+ while (n_left_from > 0)
+ {
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 pi0 = from[0];
+ u32 next0 = IP4_ICMP_ERROR_NEXT_LOOKUP;
+ u8 error0 = ICMP4_ERROR_NONE;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0, *out_ip0;
+ icmp46_header_t *icmp0;
+ u32 sw_if_index0, if_add_index0;
+ ip_csum_t sum;
+
+ /* Speculatively enqueue p0 to the current next frame */
+ to_next[0] = pi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ p0 = vlib_get_buffer (vm, pi0);
+ ip0 = vlib_buffer_get_current (p0);
+ sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
+
+ /*
+ * RFC1812 says to keep as much of the original packet as
+ * possible within the minimum MTU (576). We cheat "a little"
+ * here by keeping whatever fits in the first buffer, to be more
+ * efficient
+ */
+ if (PREDICT_FALSE (p0->total_length_not_including_first_buffer))
+ {
+ /* clear current_length of all other buffers in chain */
+ vlib_buffer_t *b = p0;
+ p0->total_length_not_including_first_buffer = 0;
+ while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
+ {
+ b = vlib_get_buffer (vm, b->next_buffer);
+ b->current_length = 0;
+ }
+ }
+ p0->current_length =
+ p0->current_length > 576 ? 576 : p0->current_length;
+
+ /* Add IP header and ICMPv4 header including a 4 byte data field */
+ vlib_buffer_advance (p0,
+ -sizeof (ip4_header_t) -
+ sizeof (icmp46_header_t) - 4);
+ out_ip0 = vlib_buffer_get_current (p0);
+ icmp0 = (icmp46_header_t *) & out_ip0[1];
+
+ /* Fill ip header fields */
+ out_ip0->ip_version_and_header_length = 0x45;
+ out_ip0->tos = 0;
+ out_ip0->length = clib_host_to_net_u16 (p0->current_length);
+ out_ip0->fragment_id = 0;
+ out_ip0->flags_and_fragment_offset = 0;
+ out_ip0->ttl = 0xff;
+ out_ip0->protocol = IP_PROTOCOL_ICMP;
+ out_ip0->dst_address = ip0->src_address;
+ if_add_index0 = ~0;
+ if (PREDICT_TRUE (vec_len (lm->if_address_pool_index_by_sw_if_index)
+ > sw_if_index0))
+ if_add_index0 =
+ lm->if_address_pool_index_by_sw_if_index[sw_if_index0];
+ if (PREDICT_TRUE (if_add_index0 != ~0))
+ {
+ ip_interface_address_t *if_add =
+ pool_elt_at_index (lm->if_address_pool, if_add_index0);
+ ip4_address_t *if_ip =
+ ip_interface_address_get_address (lm, if_add);
+ out_ip0->src_address = *if_ip;
+ }
+ else
+ {
+ /* interface has no IP4 address - should not happen */
+ next0 = IP4_ICMP_ERROR_NEXT_DROP;
+ error0 = ICMP4_ERROR_DROP;
+ }
+ out_ip0->checksum = ip4_header_checksum (out_ip0);
+
+ /* Fill icmp header fields */
+ icmp0->type = vnet_buffer (p0)->ip.icmp.type;
+ icmp0->code = vnet_buffer (p0)->ip.icmp.code;
+ *((u32 *) (icmp0 + 1)) =
+ clib_host_to_net_u32 (vnet_buffer (p0)->ip.icmp.data);
+ icmp0->checksum = 0;
+ sum =
+ ip_incremental_checksum (0, icmp0,
+ p0->current_length -
+ sizeof (ip4_header_t));
+ icmp0->checksum = ~ip_csum_fold (sum);
+
+ /* Update error status */
+ if (error0 == ICMP4_ERROR_NONE)
+ error0 = icmp4_icmp_type_to_error (icmp0->type);
+ vlib_error_count (vm, node->node_index, error0, 1);
+
+ /* Verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ pi0, next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_put_next_frame(vm, node, next_index, n_left_to_next);
- }
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_icmp_error_node) = {
.function = ip4_icmp_error,
.name = "ip4-icmp-error",
@@ -573,12 +598,14 @@ VLIB_REGISTER_NODE (ip4_icmp_error_node) = {
.format_trace = format_icmp_input_trace,
};
+/* *INDENT-ON* */
-static uword unformat_icmp_type_and_code (unformat_input_t * input, va_list * args)
+static uword
+unformat_icmp_type_and_code (unformat_input_t * input, va_list * args)
{
- icmp46_header_t * h = va_arg (*args, icmp46_header_t *);
- icmp4_main_t * cm = &icmp4_main;
+ icmp46_header_t *h = va_arg (*args, icmp46_header_t *);
+ icmp4_main_t *cm = &icmp4_main;
u32 i;
if (unformat_user (input, unformat_vlib_number_by_name,
@@ -602,21 +629,19 @@ static uword unformat_icmp_type_and_code (unformat_input_t * input, va_list * ar
static void
icmp4_pg_edit_function (pg_main_t * pg,
pg_stream_t * s,
- pg_edit_group_t * g,
- u32 * packets,
- u32 n_packets)
+ pg_edit_group_t * g, u32 * packets, u32 n_packets)
{
- vlib_main_t * vm = vlib_get_main();
+ vlib_main_t *vm = vlib_get_main ();
u32 ip_offset, icmp_offset;
icmp_offset = g->start_byte_offset;
- ip_offset = (g-1)->start_byte_offset;
+ ip_offset = (g - 1)->start_byte_offset;
while (n_packets >= 1)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- icmp46_header_t * icmp0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ icmp46_header_t *icmp0;
u32 len0;
p0 = vlib_get_buffer (vm, packets[0]);
@@ -627,11 +652,13 @@ icmp4_pg_edit_function (pg_main_t * pg,
ip0 = (void *) (p0->data + ip_offset);
icmp0 = (void *) (p0->data + icmp_offset);
len0 = clib_net_to_host_u16 (ip0->length) - ip4_header_bytes (ip0);
- icmp0->checksum = ~ ip_csum_fold (ip_incremental_checksum (0, icmp0, len0));
+ icmp0->checksum =
+ ~ip_csum_fold (ip_incremental_checksum (0, icmp0, len0));
}
}
-typedef struct {
+typedef struct
+{
pg_edit_t type, code;
pg_edit_t checksum;
} pg_icmp46_header_t;
@@ -641,19 +668,19 @@ pg_icmp_header_init (pg_icmp46_header_t * p)
{
/* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, icmp46_header_t, f);
- _ (type);
- _ (code);
- _ (checksum);
+ _(type);
+ _(code);
+ _(checksum);
#undef _
}
static uword
unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_icmp46_header_t * p;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_icmp46_header_t *p;
u32 group_index;
-
+
p = pg_create_edit_group (s, sizeof (p[0]), sizeof (icmp46_header_t),
&group_index);
pg_icmp_header_init (p);
@@ -663,7 +690,7 @@ unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
{
icmp46_header_t tmp;
- if (! unformat (input, "ICMP %U", unformat_icmp_type_and_code, &tmp))
+ if (!unformat (input, "ICMP %U", unformat_icmp_type_and_code, &tmp))
goto error;
pg_edit_set_fixed (&p->type, tmp.type);
@@ -674,8 +701,7 @@ unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
while (1)
{
if (unformat (input, "checksum %U",
- unformat_pg_edit,
- unformat_pg_number, &p->checksum))
+ unformat_pg_edit, unformat_pg_number, &p->checksum))
;
/* Can't parse input: try next protocol level. */
@@ -683,30 +709,30 @@ unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
break;
}
- if (! unformat_user (input, unformat_pg_payload, s))
+ if (!unformat_user (input, unformat_pg_payload, s))
goto error;
if (p->checksum.type == PG_EDIT_UNSPECIFIED)
{
- pg_edit_group_t * g = pg_stream_get_group (s, group_index);
+ pg_edit_group_t *g = pg_stream_get_group (s, group_index);
g->edit_function = icmp4_pg_edit_function;
g->edit_function_opaque = 0;
}
return 1;
- error:
+error:
/* Free up any edits we may have added. */
pg_free_edit_group (s);
return 0;
}
-void ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type,
- u32 node_index)
+void
+ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type, u32 node_index)
{
- icmp4_main_t * im = &icmp4_main;
+ icmp4_main_t *im = &icmp4_main;
- ASSERT ((int)type < ARRAY_LEN (im->ip4_input_next_index_by_type));
+ ASSERT ((int) type < ARRAY_LEN (im->ip4_input_next_index_by_type));
im->ip4_input_next_index_by_type[type]
= vlib_node_add_next (vm, ip4_icmp_input_node.index, node_index);
}
@@ -714,10 +740,10 @@ void ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type,
static clib_error_t *
icmp4_init (vlib_main_t * vm)
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi;
- icmp4_main_t * cm = &icmp4_main;
- clib_error_t * error;
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi;
+ icmp4_main_t *cm = &icmp4_main;
+ clib_error_t *error;
error = vlib_call_init_function (vm, ip_main_init);
@@ -739,12 +765,20 @@ icmp4_init (vlib_main_t * vm)
#undef _
memset (cm->ip4_input_next_index_by_type,
- ICMP_INPUT_NEXT_ERROR,
- sizeof (cm->ip4_input_next_index_by_type));
+ ICMP_INPUT_NEXT_ERROR, sizeof (cm->ip4_input_next_index_by_type));
- ip4_icmp_register_type (vm, ICMP4_echo_request, ip4_icmp_echo_request_node.index);
+ ip4_icmp_register_type (vm, ICMP4_echo_request,
+ ip4_icmp_echo_request_node.index);
return 0;
}
VLIB_INIT_FUNCTION (icmp4_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/icmp4.h b/vnet/vnet/ip/icmp4.h
index 07fe52d11ea..ae805148c89 100644
--- a/vnet/vnet/ip/icmp4.h
+++ b/vnet/vnet/ip/icmp4.h
@@ -31,18 +31,30 @@
_ (PARAM_PROBLEM_SENT, "parameter problem response sent") \
_ (DROP, "error message dropped")
-typedef enum {
+typedef enum
+{
#define _(f,s) ICMP4_ERROR_##f,
foreach_icmp4_error
#undef _
} icmp4_error_t;
-typedef struct {
+typedef struct
+{
u8 packet_data[64];
} icmp_input_trace_t;
format_function_t format_icmp4_input_trace;
-void ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type, u32 node_index);
-void icmp4_error_set_vnet_buffer (vlib_buffer_t *b, u8 type, u8 code, u32 data);
+void ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type,
+ u32 node_index);
+void icmp4_error_set_vnet_buffer (vlib_buffer_t * b, u8 type, u8 code,
+ u32 data);
#endif /* included_vnet_icmp4_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/icmp46_packet.h b/vnet/vnet/ip/icmp46_packet.h
index fa3fed4d081..a86cbd57bdb 100644
--- a/vnet/vnet/ip/icmp46_packet.h
+++ b/vnet/vnet/ip/icmp46_packet.h
@@ -158,38 +158,41 @@
_ (node_information_response, 1, failed) \
_ (node_information_response, 2, unknown_request)
-typedef enum {
+typedef enum
+{
#define _(n,f) ICMP4_##f = n,
foreach_icmp4_type
#undef _
} icmp4_type_t;
-typedef enum {
+typedef enum
+{
#define _(t,n,f) ICMP4_##t##_##f = n,
foreach_icmp4_code
#undef _
} icmp4_code_t;
-typedef enum {
+typedef enum
+{
#define _(n,f) ICMP6_##f = n,
foreach_icmp6_type
#undef _
} icmp6_type_t;
-typedef enum {
+typedef enum
+{
#define _(t,n,f) ICMP6_##t##_##f = n,
foreach_icmp6_code
#undef _
} icmp6_code_t;
-typedef CLIB_PACKED (struct {
- u8 type;
-
- u8 code;
-
- /* IP checksum of icmp header plus data which follows. */
- u16 checksum;
-}) icmp46_header_t;
+typedef CLIB_PACKED (struct
+ {
+ u8 type;
+ u8 code;
+ /* IP checksum of icmp header plus data which follows. */
+ u16 checksum;
+ }) icmp46_header_t;
/* ip6 neighbor discovery */
#define foreach_icmp6_neighbor_discovery_option \
@@ -225,168 +228,171 @@ typedef CLIB_PACKED (struct {
_ (138, card_request) \
_ (139, card_reply)
-typedef enum icmp6_neighbor_discovery_option_type {
+typedef enum icmp6_neighbor_discovery_option_type
+{
#define _(n,f) ICMP6_NEIGHBOR_DISCOVERY_OPTION_##f = n,
foreach_icmp6_neighbor_discovery_option
#undef _
} icmp6_neighbor_discovery_option_type_t;
-typedef CLIB_PACKED (struct {
- /* Option type. */
- u8 type;
-
- /* Length of this header plus option data in 8 byte units. */
- u8 n_data_u64s;
-
- /* Option data follows. */
- u8 data[0];
-}) icmp6_neighbor_discovery_option_header_t;
-
-typedef CLIB_PACKED (struct {
- icmp6_neighbor_discovery_option_header_t header;
- u8 dst_address_length;
- u8 flags;
+typedef CLIB_PACKED (struct
+ {
+ /* Option type. */
+ u8 type;
+ /* Length of this header plus option data in 8 byte units. */
+ u8 n_data_u64s;
+ /* Option data follows. */
+ u8 data[0];
+ }) icmp6_neighbor_discovery_option_header_t;
+
+typedef CLIB_PACKED (struct
+ {
+ icmp6_neighbor_discovery_option_header_t header;
+ u8 dst_address_length;
+ u8 flags;
#define ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK (1 << 7)
#define ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO (1 << 6)
- u32 valid_time;
- u32 preferred_time;
- u32 unused;
- ip6_address_t dst_address;
-}) icmp6_neighbor_discovery_prefix_information_option_t;
-
-typedef CLIB_PACKED (struct {
- u8 type;
- u8 aux_data_len_u32s;
- u16 num_sources;
- ip6_address_t mcast_addr;
- ip6_address_t source_addr[0];
-}) icmp6_multicast_address_record_t;
-
-typedef CLIB_PACKED (struct {
- ip6_hop_by_hop_ext_t ext_hdr;
- ip6_router_alert_option_t alert;
- ip6_padN_option_t pad;
- icmp46_header_t icmp;
- u16 rsvd;
- u16 num_addr_records;
- icmp6_multicast_address_record_t records[0];
-}) icmp6_multicast_listener_report_header_t;
-
-typedef CLIB_PACKED (struct {
- icmp6_neighbor_discovery_option_header_t header;
- u8 reserved[6];
- /* IP6 header plus payload follows. */
- u8 data[0];
-}) icmp6_neighbor_discovery_redirected_header_option_t;
-
-typedef CLIB_PACKED (struct {
- icmp6_neighbor_discovery_option_header_t header;
- u16 unused;
- u32 mtu;
-}) icmp6_neighbor_discovery_mtu_option_t;
-
-typedef CLIB_PACKED (struct {
- icmp6_neighbor_discovery_option_header_t header;
- u8 ethernet_address[6];
-}) icmp6_neighbor_discovery_ethernet_link_layer_address_option_t;
-
-typedef CLIB_PACKED (struct {
- icmp6_neighbor_discovery_option_header_t header;
- u8 max_l2_address[6+8];
-}) icmp6_neighbor_discovery_max_link_layer_address_option_t;
+ u32 valid_time;
+ u32 preferred_time;
+ u32 unused; ip6_address_t dst_address;
+ }) icmp6_neighbor_discovery_prefix_information_option_t;
+
+typedef CLIB_PACKED (struct
+ {
+ u8 type;
+ u8 aux_data_len_u32s;
+ u16 num_sources;
+ ip6_address_t mcast_addr; ip6_address_t source_addr[0];
+ }) icmp6_multicast_address_record_t;
+
+typedef CLIB_PACKED (struct
+ {
+ ip6_hop_by_hop_ext_t ext_hdr;
+ ip6_router_alert_option_t alert;
+ ip6_padN_option_t pad;
+ icmp46_header_t icmp;
+ u16 rsvd;
+ u16 num_addr_records;
+ icmp6_multicast_address_record_t records[0];
+ }) icmp6_multicast_listener_report_header_t;
+
+typedef CLIB_PACKED (struct
+ {
+ icmp6_neighbor_discovery_option_header_t header;
+ u8 reserved[6];
+ /* IP6 header plus payload follows. */
+ u8 data[0];
+ }) icmp6_neighbor_discovery_redirected_header_option_t;
+
+typedef CLIB_PACKED (struct
+ {
+ icmp6_neighbor_discovery_option_header_t header;
+ u16 unused; u32 mtu;
+ }) icmp6_neighbor_discovery_mtu_option_t;
+
+typedef CLIB_PACKED (struct
+ {
+ icmp6_neighbor_discovery_option_header_t header;
+ u8 ethernet_address[6];
+ })
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t;
+
+typedef CLIB_PACKED (struct
+ {
+ icmp6_neighbor_discovery_option_header_t header;
+ u8 max_l2_address[6 + 8];
+ })
+ icmp6_neighbor_discovery_max_link_layer_address_option_t;
/* Generic neighbor discover header. Used for router solicitations,
etc. */
-typedef CLIB_PACKED (struct {
- icmp46_header_t icmp;
-
- u32 reserved_must_be_zero;
-}) icmp6_neighbor_discovery_header_t;
+typedef CLIB_PACKED (struct
+ {
+ icmp46_header_t icmp; u32 reserved_must_be_zero;
+ }) icmp6_neighbor_discovery_header_t;
/* Router advertisement packet formats. */
-typedef CLIB_PACKED (struct {
- icmp46_header_t icmp;
-
- /* Current hop limit to use for outgoing packets. */
- u8 current_hop_limit;
-
- u8 flags;
+typedef CLIB_PACKED (struct
+ {
+ icmp46_header_t icmp;
+ /* Current hop limit to use for outgoing packets. */
+ u8 current_hop_limit;
+ u8 flags;
#define ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP (1 << 7)
#define ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP (1 << 6)
-
- /* Zero means unspecified. */
- u16 router_lifetime_in_sec;
-
- /* Zero means unspecified. */
- u32 neighbor_reachable_time_in_msec;
-
- /* Zero means unspecified. */
- u32 time_in_msec_between_retransmitted_neighbor_solicitations;
-
- /* Options that may follow: source_link_layer_address, mtu, prefix_information. */
-}) icmp6_router_advertisement_header_t;
+ /* Zero means unspecified. */
+ u16 router_lifetime_in_sec;
+ /* Zero means unspecified. */
+ u32 neighbor_reachable_time_in_msec;
+ /* Zero means unspecified. */
+ u32
+ time_in_msec_between_retransmitted_neighbor_solicitations;
+ /* Options that may follow: source_link_layer_address, mtu, prefix_information. */
+ }) icmp6_router_advertisement_header_t;
/* Neighbor solicitation/advertisement header. */
-typedef CLIB_PACKED (struct {
- icmp46_header_t icmp;
-
- /* Zero for solicitation; flags for advertisement. */
- u32 advertisement_flags;
- /* Set when sent by a router. */
+typedef CLIB_PACKED (struct
+ {
+ icmp46_header_t icmp;
+ /* Zero for solicitation; flags for advertisement. */
+ u32 advertisement_flags;
+ /* Set when sent by a router. */
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_ROUTER (1 << 31)
- /* Set when response to solicitation. */
+ /* Set when response to solicitation. */
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED (1 << 30)
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE (1 << 29)
-
- ip6_address_t target_address;
-
- /* Options that may follow: source_link_layer_address
- (for solicitation) target_link_layer_address (for advertisement). */
-}) icmp6_neighbor_solicitation_or_advertisement_header_t;
-
-typedef CLIB_PACKED (struct {
- icmp46_header_t icmp;
-
- u32 reserved_must_be_zero;
-
- /* Better next hop to use for given destination. */
- ip6_address_t better_next_hop_address;
-
- ip6_address_t dst_address;
-
- /* Options that may follow: target_link_layer_address,
- redirected_header. */
-}) icmp6_redirect_header_t;
+ ip6_address_t target_address;
+ /* Options that may follow: source_link_layer_address
+ (for solicitation) target_link_layer_address (for advertisement). */
+ }) icmp6_neighbor_solicitation_or_advertisement_header_t;
+
+typedef CLIB_PACKED (struct
+ {
+ icmp46_header_t icmp;
+ u32 reserved_must_be_zero;
+ /* Better next hop to use for given destination. */
+ ip6_address_t better_next_hop_address;
+ ip6_address_t dst_address;
+ /* Options that may follow: target_link_layer_address,
+ redirected_header. */
+ }) icmp6_redirect_header_t;
/* Solicitation/advertisement packet format for ethernet. */
-typedef CLIB_PACKED (struct {
- ip6_header_t ip;
-
- icmp6_neighbor_solicitation_or_advertisement_header_t neighbor;
-
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t link_layer_option;
-}) icmp6_neighbor_solicitation_header_t;
+typedef CLIB_PACKED (struct
+ {
+ ip6_header_t ip;
+ icmp6_neighbor_solicitation_or_advertisement_header_t
+ neighbor;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
+ link_layer_option;
+ }) icmp6_neighbor_solicitation_header_t;
/* Router solicitation packet format for ethernet. */
-typedef CLIB_PACKED (struct {
- ip6_header_t ip;
- icmp6_neighbor_discovery_header_t neighbor;
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t link_layer_option;
-}) icmp6_router_solicitation_header_t;
+typedef CLIB_PACKED (struct
+ {
+ ip6_header_t ip;
+ icmp6_neighbor_discovery_header_t neighbor;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
+ link_layer_option;
+ }) icmp6_router_solicitation_header_t;
/* router advertisement packet format for ethernet. */
-typedef CLIB_PACKED (struct {
- ip6_header_t ip;
- icmp6_router_advertisement_header_t router;
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t link_layer_option;
- icmp6_neighbor_discovery_mtu_option_t mtu_option;
- icmp6_neighbor_discovery_prefix_information_option_t prefix[0];
-}) icmp6_router_advertisement_packet_t;
+typedef CLIB_PACKED (struct
+ {
+ ip6_header_t ip;
+ icmp6_router_advertisement_header_t router;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
+ link_layer_option;
+ icmp6_neighbor_discovery_mtu_option_t mtu_option;
+ icmp6_neighbor_discovery_prefix_information_option_t
+ prefix[0];
+ }) icmp6_router_advertisement_packet_t;
/* multicast listener report packet format for ethernet. */
-typedef CLIB_PACKED (struct {
- ip6_header_t ip;
- icmp6_multicast_listener_report_header_t report_hdr;
-}) icmp6_multicast_listener_report_packet_t;
+typedef CLIB_PACKED (struct
+ {
+ ip6_header_t ip;
+ icmp6_multicast_listener_report_header_t report_hdr;
+ }) icmp6_multicast_listener_report_packet_t;
#endif /* included_vnet_icmp46_packet_h */
diff --git a/vnet/vnet/ip/icmp6.c b/vnet/vnet/ip/icmp6.c
index a04373a3a7e..70696d0c6cb 100644
--- a/vnet/vnet/ip/icmp6.c
+++ b/vnet/vnet/ip/icmp6.c
@@ -41,11 +41,12 @@
#include <vnet/ip/ip.h>
#include <vnet/pg/pg.h>
-static u8 * format_ip6_icmp_type_and_code (u8 * s, va_list * args)
+static u8 *
+format_ip6_icmp_type_and_code (u8 * s, va_list * args)
{
icmp6_type_t type = va_arg (*args, int);
u8 code = va_arg (*args, int);
- char * t = 0;
+ char *t = 0;
#define _(n,f) case n: t = #f; break;
@@ -59,7 +60,7 @@ static u8 * format_ip6_icmp_type_and_code (u8 * s, va_list * args)
#undef _
- if (! t)
+ if (!t)
return format (s, "unknown 0x%x", type);
s = format (s, "%s", t);
@@ -80,9 +81,10 @@ static u8 * format_ip6_icmp_type_and_code (u8 * s, va_list * args)
return s;
}
-static u8 * format_icmp6_header (u8 * s, va_list * args)
+static u8 *
+format_icmp6_header (u8 * s, va_list * args)
{
- icmp46_header_t * icmp = va_arg (*args, icmp46_header_t *);
+ icmp46_header_t *icmp = va_arg (*args, icmp46_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
/* Nothing to do. */
@@ -94,47 +96,49 @@ static u8 * format_icmp6_header (u8 * s, va_list * args)
clib_net_to_host_u16 (icmp->checksum));
if (max_header_bytes >=
- sizeof(icmp6_neighbor_solicitation_or_advertisement_header_t) &&
+ sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t) &&
(icmp->type == ICMP6_neighbor_solicitation ||
icmp->type == ICMP6_neighbor_advertisement))
- {
- icmp6_neighbor_solicitation_or_advertisement_header_t *icmp6_nd =
- (icmp6_neighbor_solicitation_or_advertisement_header_t *) icmp;
- s = format (s, "\n target address %U",
- format_ip6_address, &icmp6_nd->target_address);
- }
+ {
+ icmp6_neighbor_solicitation_or_advertisement_header_t *icmp6_nd =
+ (icmp6_neighbor_solicitation_or_advertisement_header_t *) icmp;
+ s = format (s, "\n target address %U",
+ format_ip6_address, &icmp6_nd->target_address);
+ }
return s;
}
-u8 * format_icmp6_input_trace (u8 * s, va_list * va)
+u8 *
+format_icmp6_input_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
- icmp6_input_trace_t * t = va_arg (*va, icmp6_input_trace_t *);
+ icmp6_input_trace_t *t = va_arg (*va, icmp6_input_trace_t *);
s = format (s, "%U",
- format_ip6_header,
- t->packet_data, sizeof (t->packet_data));
+ format_ip6_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-static char * icmp_error_strings[] = {
+static char *icmp_error_strings[] = {
#define _(f,s) s,
foreach_icmp6_error
#undef _
};
-typedef enum {
+typedef enum
+{
ICMP_INPUT_NEXT_DROP,
ICMP_INPUT_N_NEXT,
} icmp_input_next_t;
-typedef struct {
- uword * type_and_code_by_name;
+typedef struct
+{
+ uword *type_and_code_by_name;
- uword * type_by_name;
+ uword *type_by_name;
/* Vector dispatch table indexed by [icmp type]. */
u8 input_next_index_by_type[256];
@@ -152,17 +156,16 @@ icmp6_main_t icmp6_main;
static uword
ip6_icmp_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- icmp6_main_t * im = &icmp6_main;
- u32 * from, * to_next;
+ icmp6_main_t *im = &icmp6_main;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next_index;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
@@ -174,19 +177,19 @@ ip6_icmp_input (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * b0;
- ip6_header_t * ip0;
- icmp46_header_t * icmp0;
+ vlib_buffer_t *b0;
+ ip6_header_t *ip0;
+ icmp46_header_t *icmp0;
icmp6_type_t type0;
u32 bi0, next0, error0, len0;
-
+
bi0 = to_next[0] = from[0];
from += 1;
n_left_from -= 1;
to_next += 1;
n_left_to_next -= 1;
-
+
b0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (b0);
icmp0 = ip6_next_header (ip0);
@@ -195,18 +198,28 @@ ip6_icmp_input (vlib_main_t * vm,
error0 = ICMP6_ERROR_NONE;
next0 = im->input_next_index_by_type[type0];
- error0 = next0 == ICMP_INPUT_NEXT_DROP ? ICMP6_ERROR_UNKNOWN_TYPE : error0;
+ error0 =
+ next0 == ICMP_INPUT_NEXT_DROP ? ICMP6_ERROR_UNKNOWN_TYPE : error0;
/* Check code is valid for type. */
- error0 = icmp0->code > im->max_valid_code_by_type[type0] ? ICMP6_ERROR_INVALID_CODE_FOR_TYPE : error0;
+ error0 =
+ icmp0->code >
+ im->max_valid_code_by_type[type0] ?
+ ICMP6_ERROR_INVALID_CODE_FOR_TYPE : error0;
/* Checksum is already validated by ip6_local node so we don't need to check that. */
/* Check that hop limit == 255 for certain types. */
- error0 = ip0->hop_limit < im->min_valid_hop_limit_by_type[type0] ? ICMP6_ERROR_INVALID_HOP_LIMIT_FOR_TYPE : error0;
+ error0 =
+ ip0->hop_limit <
+ im->min_valid_hop_limit_by_type[type0] ?
+ ICMP6_ERROR_INVALID_HOP_LIMIT_FOR_TYPE : error0;
len0 = clib_net_to_host_u16 (ip0->payload_length);
- error0 = len0 < im->min_valid_length_by_type[type0] ? ICMP6_ERROR_LENGTH_TOO_SMALL_FOR_TYPE : error0;
+ error0 =
+ len0 <
+ im->min_valid_length_by_type[type0] ?
+ ICMP6_ERROR_LENGTH_TOO_SMALL_FOR_TYPE : error0;
b0->error = node->errors[error0];
@@ -216,13 +229,14 @@ ip6_icmp_input (vlib_main_t * vm,
to_next, n_left_to_next,
bi0, next0);
}
-
+
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_icmp_input_node) = {
.function = ip6_icmp_input,
.name = "ip6-icmp-input",
@@ -239,8 +253,10 @@ VLIB_REGISTER_NODE (ip6_icmp_input_node) = {
[ICMP_INPUT_NEXT_DROP] = "error-drop",
},
};
+/* *INDENT-ON* */
-typedef enum {
+typedef enum
+{
ICMP6_ECHO_REQUEST_NEXT_LOOKUP,
ICMP6_ECHO_REQUEST_NEXT_OUTPUT,
ICMP6_ECHO_REQUEST_N_NEXT,
@@ -248,17 +264,16 @@ typedef enum {
static uword
ip6_icmp_echo_request (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- u32 * from, * to_next;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next_index;
- ip6_main_t * im = &ip6_main;
+ ip6_main_t *im = &ip6_main;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
@@ -270,16 +285,16 @@ ip6_icmp_echo_request (vlib_main_t * vm,
while (n_left_from > 2 && n_left_to_next > 2)
{
- vlib_buffer_t * p0, * p1;
- ip6_header_t * ip0, * ip1;
- icmp46_header_t * icmp0, * icmp1;
+ vlib_buffer_t *p0, *p1;
+ ip6_header_t *ip0, *ip1;
+ icmp46_header_t *icmp0, *icmp1;
ip6_address_t tmp0, tmp1;
ip_csum_t sum0, sum1;
u32 bi0, bi1;
- u32 fib_index0, fib_index1;
- u32 next0 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
- u32 next1 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
-
+ u32 fib_index0, fib_index1;
+ u32 next0 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
+ u32 next1 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
+
bi0 = to_next[0] = from[0];
bi1 = to_next[1] = from[1];
@@ -287,7 +302,7 @@ ip6_icmp_echo_request (vlib_main_t * vm,
n_left_from -= 2;
to_next += 2;
n_left_to_next -= 2;
-
+
p0 = vlib_get_buffer (vm, bi0);
p1 = vlib_get_buffer (vm, bi1);
ip0 = vlib_buffer_get_current (p0);
@@ -338,14 +353,14 @@ ip6_icmp_echo_request (vlib_main_t * vm,
clib_memcpy (tmp_mac, eth0->dst_address, 6);
clib_memcpy (eth0->dst_address, eth0->src_address, 6);
clib_memcpy (eth0->src_address, tmp_mac, 6);
- vnet_buffer(p0)->sw_if_index[VLIB_TX] =
- vnet_buffer (p0)->sw_if_index[VLIB_RX];
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] =
+ vnet_buffer (p0)->sw_if_index[VLIB_RX];
next0 = ICMP6_ECHO_REQUEST_NEXT_OUTPUT;
}
else
{
/* Determine the correct lookup fib indices... */
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
+ fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
vnet_buffer (p0)->sw_if_index[VLIB_RX]);
vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index0;
}
@@ -362,48 +377,48 @@ ip6_icmp_echo_request (vlib_main_t * vm,
clib_memcpy (tmp_mac, eth1->dst_address, 6);
clib_memcpy (eth1->dst_address, eth1->src_address, 6);
clib_memcpy (eth1->src_address, tmp_mac, 6);
- vnet_buffer(p1)->sw_if_index[VLIB_TX] =
- vnet_buffer (p1)->sw_if_index[VLIB_RX];
+ vnet_buffer (p1)->sw_if_index[VLIB_TX] =
+ vnet_buffer (p1)->sw_if_index[VLIB_RX];
next1 = ICMP6_ECHO_REQUEST_NEXT_OUTPUT;
}
else
{
/* Determine the correct lookup fib indices... */
- fib_index1 = vec_elt (im->fib_index_by_sw_if_index,
+ fib_index1 = vec_elt (im->fib_index_by_sw_if_index,
vnet_buffer (p1)->sw_if_index[VLIB_RX]);
vnet_buffer (p1)->sw_if_index[VLIB_TX] = fib_index1;
}
- vnet_buffer (p0)->sw_if_index[VLIB_RX]
- = vnet_main.local_interface_sw_if_index;
- vnet_buffer (p1)->sw_if_index[VLIB_RX]
- = vnet_main.local_interface_sw_if_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]
+ = vnet_main.local_interface_sw_if_index;
+ vnet_buffer (p1)->sw_if_index[VLIB_RX]
+ = vnet_main.local_interface_sw_if_index;
- /* verify speculative enqueues, maybe switch current next frame */
- /* if next0==next1==next_index then nothing special needs to be done */
- vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, bi1, next0, next1);
+ /* verify speculative enqueues, maybe switch current next frame */
+ /* if next0==next1==next_index then nothing special needs to be done */
+ vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, bi1, next0, next1);
}
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
- icmp46_header_t * icmp0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
+ icmp46_header_t *icmp0;
u32 bi0;
ip6_address_t tmp0;
ip_csum_t sum0;
- u32 fib_index0;
- u32 next0 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
-
+ u32 fib_index0;
+ u32 next0 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
+
bi0 = to_next[0] = from[0];
from += 1;
n_left_from -= 1;
to_next += 1;
n_left_to_next -= 1;
-
+
p0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (p0);
icmp0 = ip6_next_header (ip0);
@@ -438,35 +453,35 @@ ip6_icmp_echo_request (vlib_main_t * vm,
clib_memcpy (tmp_mac, eth0->dst_address, 6);
clib_memcpy (eth0->dst_address, eth0->src_address, 6);
clib_memcpy (eth0->src_address, tmp_mac, 6);
- vnet_buffer(p0)->sw_if_index[VLIB_TX] =
- vnet_buffer (p0)->sw_if_index[VLIB_RX];
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] =
+ vnet_buffer (p0)->sw_if_index[VLIB_RX];
next0 = ICMP6_ECHO_REQUEST_NEXT_OUTPUT;
}
else
{
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
+ fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
vnet_buffer (p0)->sw_if_index[VLIB_RX]);
vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index0;
}
- vnet_buffer (p0)->sw_if_index[VLIB_RX]
- = vnet_main.local_interface_sw_if_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]
+ = vnet_main.local_interface_sw_if_index;
- /* Verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ /* Verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
}
-
+
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
vlib_error_count (vm, ip6_icmp_input_node.index,
- ICMP6_ERROR_ECHO_REPLIES_SENT,
- frame->n_vectors);
+ ICMP6_ERROR_ECHO_REPLIES_SENT, frame->n_vectors);
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_icmp_echo_request_node,static) = {
.function = ip6_icmp_echo_request,
.name = "ip6-icmp-echo-request",
@@ -481,154 +496,163 @@ VLIB_REGISTER_NODE (ip6_icmp_echo_request_node,static) = {
[ICMP6_ECHO_REQUEST_NEXT_OUTPUT] = "interface-output",
},
};
+/* *INDENT-ON* */
-typedef enum {
+typedef enum
+{
IP6_ICMP_ERROR_NEXT_DROP,
IP6_ICMP_ERROR_NEXT_LOOKUP,
IP6_ICMP_ERROR_N_NEXT,
} ip6_icmp_error_next_t;
void
-icmp6_error_set_vnet_buffer (vlib_buffer_t *b, u8 type, u8 code, u32 data)
+icmp6_error_set_vnet_buffer (vlib_buffer_t * b, u8 type, u8 code, u32 data)
{
- vnet_buffer(b)->ip.icmp.type = type;
- vnet_buffer(b)->ip.icmp.code = code;
- vnet_buffer(b)->ip.icmp.data = data;
+ vnet_buffer (b)->ip.icmp.type = type;
+ vnet_buffer (b)->ip.icmp.code = code;
+ vnet_buffer (b)->ip.icmp.data = data;
}
static u8
icmp6_icmp_type_to_error (u8 type)
{
- switch (type) {
- case ICMP6_destination_unreachable:
- return ICMP6_ERROR_DEST_UNREACH_SENT;
- case ICMP6_packet_too_big:
- return ICMP6_ERROR_PACKET_TOO_BIG_SENT;
- case ICMP6_time_exceeded:
- return ICMP6_ERROR_TTL_EXPIRE_SENT;
- case ICMP6_parameter_problem:
- return ICMP6_ERROR_PARAM_PROBLEM_SENT;
- default:
- return ICMP6_ERROR_DROP;
- }
+ switch (type)
+ {
+ case ICMP6_destination_unreachable:
+ return ICMP6_ERROR_DEST_UNREACH_SENT;
+ case ICMP6_packet_too_big:
+ return ICMP6_ERROR_PACKET_TOO_BIG_SENT;
+ case ICMP6_time_exceeded:
+ return ICMP6_ERROR_TTL_EXPIRE_SENT;
+ case ICMP6_parameter_problem:
+ return ICMP6_ERROR_PARAM_PROBLEM_SENT;
+ default:
+ return ICMP6_ERROR_DROP;
+ }
}
static uword
ip6_icmp_error (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- u32 * from, * to_next;
+ u32 *from, *to_next;
uword n_left_from, n_left_to_next;
ip6_icmp_error_next_t next_index;
ip6_main_t *im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
- from = vlib_frame_vector_args(frame);
+ from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
- /* stride */ 1, sizeof (icmp6_input_trace_t));
+ /* stride */ 1,
+ sizeof (icmp6_input_trace_t));
while (n_left_from > 0)
{
- vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from > 0 && n_left_to_next > 0)
- {
- u32 pi0 = from[0];
- u32 next0 = IP6_ICMP_ERROR_NEXT_LOOKUP;
- u8 error0 = ICMP6_ERROR_NONE;
- vlib_buffer_t * p0;
- ip6_header_t * ip0, * out_ip0;
- icmp46_header_t * icmp0;
- u32 sw_if_index0, if_add_index0;
- int bogus_length;
-
- /* Speculatively enqueue p0 to the current next frame */
- to_next[0] = pi0;
- from += 1;
- to_next += 1;
- n_left_from -= 1;
- n_left_to_next -= 1;
-
- p0 = vlib_get_buffer(vm, pi0);
- ip0 = vlib_buffer_get_current(p0);
- sw_if_index0 = vnet_buffer(p0)->sw_if_index[VLIB_RX];
-
- /* RFC4443 says to keep as much of the original packet as possible
- * within the minimum MTU. We cheat "a little" here by keeping whatever fits
- * in the first buffer, to be more efficient */
- if (PREDICT_FALSE(p0->total_length_not_including_first_buffer))
- { /* clear current_length of all other buffers in chain */
- vlib_buffer_t *b = p0;
- p0->total_length_not_including_first_buffer = 0;
- while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
- {
- b = vlib_get_buffer (vm, b->next_buffer);
- b->current_length = 0;
- }
- }
- p0->current_length = p0->current_length > 1280 ? 1280 : p0->current_length;
-
- /* Add IP header and ICMPv6 header including a 4 byte data field */
- vlib_buffer_advance(p0,
- -sizeof(ip6_header_t)-sizeof(icmp46_header_t)-4);
- out_ip0 = vlib_buffer_get_current(p0);
- icmp0 = (icmp46_header_t *) &out_ip0[1];
-
- /* Fill ip header fields */
- out_ip0->ip_version_traffic_class_and_flow_label =
- clib_host_to_net_u32(0x6<<28);
-
- out_ip0->payload_length = clib_host_to_net_u16(p0->current_length - sizeof(ip6_header_t));
- out_ip0->protocol = IP_PROTOCOL_ICMP6;
- out_ip0->hop_limit = 0xff;
- out_ip0->dst_address = ip0->src_address;
- if_add_index0 =
- lm->if_address_pool_index_by_sw_if_index[sw_if_index0];
- if (PREDICT_TRUE(if_add_index0 != ~0))
- {
- ip_interface_address_t *if_add =
- pool_elt_at_index(lm->if_address_pool, if_add_index0);
- ip6_address_t *if_ip =
- ip_interface_address_get_address(lm, if_add);
- out_ip0->src_address = *if_ip;
- }
- else /* interface has no IP6 address - should not happen */
- {
- next0 = IP6_ICMP_ERROR_NEXT_DROP;
- error0 = ICMP6_ERROR_DROP;
- }
-
- /* Fill icmp header fields */
- icmp0->type = vnet_buffer(p0)->ip.icmp.type;
- icmp0->code = vnet_buffer(p0)->ip.icmp.code;
- *((u32 *)(icmp0 + 1)) = clib_host_to_net_u32(vnet_buffer(p0)->ip.icmp.data);
- icmp0->checksum = 0;
- icmp0->checksum = ip6_tcp_udp_icmp_compute_checksum(
- vm, p0, out_ip0, &bogus_length);
-
-
-
- /* Update error status */
+ {
+ u32 pi0 = from[0];
+ u32 next0 = IP6_ICMP_ERROR_NEXT_LOOKUP;
+ u8 error0 = ICMP6_ERROR_NONE;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0, *out_ip0;
+ icmp46_header_t *icmp0;
+ u32 sw_if_index0, if_add_index0;
+ int bogus_length;
+
+ /* Speculatively enqueue p0 to the current next frame */
+ to_next[0] = pi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ p0 = vlib_get_buffer (vm, pi0);
+ ip0 = vlib_buffer_get_current (p0);
+ sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
+
+ /* RFC4443 says to keep as much of the original packet as possible
+ * within the minimum MTU. We cheat "a little" here by keeping whatever fits
+ * in the first buffer, to be more efficient */
+ if (PREDICT_FALSE (p0->total_length_not_including_first_buffer))
+ { /* clear current_length of all other buffers in chain */
+ vlib_buffer_t *b = p0;
+ p0->total_length_not_including_first_buffer = 0;
+ while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
+ {
+ b = vlib_get_buffer (vm, b->next_buffer);
+ b->current_length = 0;
+ }
+ }
+ p0->current_length =
+ p0->current_length > 1280 ? 1280 : p0->current_length;
+
+ /* Add IP header and ICMPv6 header including a 4 byte data field */
+ vlib_buffer_advance (p0,
+ -sizeof (ip6_header_t) -
+ sizeof (icmp46_header_t) - 4);
+ out_ip0 = vlib_buffer_get_current (p0);
+ icmp0 = (icmp46_header_t *) & out_ip0[1];
+
+ /* Fill ip header fields */
+ out_ip0->ip_version_traffic_class_and_flow_label =
+ clib_host_to_net_u32 (0x6 << 28);
+
+ out_ip0->payload_length =
+ clib_host_to_net_u16 (p0->current_length - sizeof (ip6_header_t));
+ out_ip0->protocol = IP_PROTOCOL_ICMP6;
+ out_ip0->hop_limit = 0xff;
+ out_ip0->dst_address = ip0->src_address;
+ if_add_index0 =
+ lm->if_address_pool_index_by_sw_if_index[sw_if_index0];
+ if (PREDICT_TRUE (if_add_index0 != ~0))
+ {
+ ip_interface_address_t *if_add =
+ pool_elt_at_index (lm->if_address_pool, if_add_index0);
+ ip6_address_t *if_ip =
+ ip_interface_address_get_address (lm, if_add);
+ out_ip0->src_address = *if_ip;
+ }
+ else /* interface has no IP6 address - should not happen */
+ {
+ next0 = IP6_ICMP_ERROR_NEXT_DROP;
+ error0 = ICMP6_ERROR_DROP;
+ }
+
+ /* Fill icmp header fields */
+ icmp0->type = vnet_buffer (p0)->ip.icmp.type;
+ icmp0->code = vnet_buffer (p0)->ip.icmp.code;
+ *((u32 *) (icmp0 + 1)) =
+ clib_host_to_net_u32 (vnet_buffer (p0)->ip.icmp.data);
+ icmp0->checksum = 0;
+ icmp0->checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, p0, out_ip0,
+ &bogus_length);
+
+
+
+ /* Update error status */
if (error0 == ICMP6_ERROR_NONE)
- error0 = icmp6_icmp_type_to_error(icmp0->type);
- vlib_error_count(vm, node->node_index, error0, 1);
-
- /* Verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1(vm, node, next_index,
- to_next, n_left_to_next,
- pi0, next0);
- }
- vlib_put_next_frame(vm, node, next_index, n_left_to_next);
+ error0 = icmp6_icmp_type_to_error (icmp0->type);
+ vlib_error_count (vm, node->node_index, error0, 1);
+
+ /* Verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ pi0, next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_icmp_error_node) = {
.function = ip6_icmp_error,
.name = "ip6-icmp-error",
@@ -645,12 +669,14 @@ VLIB_REGISTER_NODE (ip6_icmp_error_node) = {
.format_trace = format_icmp6_input_trace,
};
+/* *INDENT-ON* */
-static uword unformat_icmp_type_and_code (unformat_input_t * input, va_list * args)
+static uword
+unformat_icmp_type_and_code (unformat_input_t * input, va_list * args)
{
- icmp46_header_t * h = va_arg (*args, icmp46_header_t *);
- icmp6_main_t * cm = &icmp6_main;
+ icmp46_header_t *h = va_arg (*args, icmp46_header_t *);
+ icmp6_main_t *cm = &icmp6_main;
u32 i;
if (unformat_user (input, unformat_vlib_number_by_name,
@@ -674,22 +700,20 @@ static uword unformat_icmp_type_and_code (unformat_input_t * input, va_list * ar
static void
icmp6_pg_edit_function (pg_main_t * pg,
pg_stream_t * s,
- pg_edit_group_t * g,
- u32 * packets,
- u32 n_packets)
+ pg_edit_group_t * g, u32 * packets, u32 n_packets)
{
- vlib_main_t * vm = vlib_get_main();
+ vlib_main_t *vm = vlib_get_main ();
u32 ip_offset, icmp_offset;
int bogus_length;
icmp_offset = g->start_byte_offset;
- ip_offset = (g-1)->start_byte_offset;
+ ip_offset = (g - 1)->start_byte_offset;
while (n_packets >= 1)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
- icmp46_header_t * icmp0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
+ icmp46_header_t *icmp0;
p0 = vlib_get_buffer (vm, packets[0]);
n_packets -= 1;
@@ -699,13 +723,14 @@ icmp6_pg_edit_function (pg_main_t * pg,
ip0 = (void *) (p0->data + ip_offset);
icmp0 = (void *) (p0->data + icmp_offset);
- icmp0->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
- &bogus_length);
+ icmp0->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
+ &bogus_length);
ASSERT (bogus_length == 0);
}
}
-typedef struct {
+typedef struct
+{
pg_edit_t type, code;
pg_edit_t checksum;
} pg_icmp46_header_t;
@@ -715,19 +740,19 @@ pg_icmp_header_init (pg_icmp46_header_t * p)
{
/* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, icmp46_header_t, f);
- _ (type);
- _ (code);
- _ (checksum);
+ _(type);
+ _(code);
+ _(checksum);
#undef _
}
static uword
unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_icmp46_header_t * p;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_icmp46_header_t *p;
u32 group_index;
-
+
p = pg_create_edit_group (s, sizeof (p[0]), sizeof (icmp46_header_t),
&group_index);
pg_icmp_header_init (p);
@@ -737,7 +762,7 @@ unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
{
icmp46_header_t tmp;
- if (! unformat (input, "ICMP %U", unformat_icmp_type_and_code, &tmp))
+ if (!unformat (input, "ICMP %U", unformat_icmp_type_and_code, &tmp))
goto error;
pg_edit_set_fixed (&p->type, tmp.type);
@@ -748,8 +773,7 @@ unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
while (1)
{
if (unformat (input, "checksum %U",
- unformat_pg_edit,
- unformat_pg_number, &p->checksum))
+ unformat_pg_edit, unformat_pg_number, &p->checksum))
;
/* Can't parse input: try next protocol level. */
@@ -757,27 +781,28 @@ unformat_pg_icmp_header (unformat_input_t * input, va_list * args)
break;
}
- if (! unformat_user (input, unformat_pg_payload, s))
+ if (!unformat_user (input, unformat_pg_payload, s))
goto error;
if (p->checksum.type == PG_EDIT_UNSPECIFIED)
{
- pg_edit_group_t * g = pg_stream_get_group (s, group_index);
+ pg_edit_group_t *g = pg_stream_get_group (s, group_index);
g->edit_function = icmp6_pg_edit_function;
g->edit_function_opaque = 0;
}
return 1;
- error:
+error:
/* Free up any edits we may have added. */
pg_free_edit_group (s);
return 0;
}
-void icmp6_register_type (vlib_main_t * vm, icmp6_type_t type, u32 node_index)
+void
+icmp6_register_type (vlib_main_t * vm, icmp6_type_t type, u32 node_index)
{
- icmp6_main_t * im = &icmp6_main;
+ icmp6_main_t *im = &icmp6_main;
ASSERT ((int) type < ARRAY_LEN (im->input_next_index_by_type));
im->input_next_index_by_type[type]
@@ -787,10 +812,10 @@ void icmp6_register_type (vlib_main_t * vm, icmp6_type_t type, u32 node_index)
static clib_error_t *
icmp6_init (vlib_main_t * vm)
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi;
- icmp6_main_t * cm = &icmp6_main;
- clib_error_t * error;
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi;
+ icmp6_main_t *cm = &icmp6_main;
+ clib_error_t *error;
error = vlib_call_init_function (vm, ip_main_init);
@@ -812,33 +837,46 @@ icmp6_init (vlib_main_t * vm)
#undef _
memset (cm->input_next_index_by_type,
- ICMP_INPUT_NEXT_DROP,
- sizeof (cm->input_next_index_by_type));
+ ICMP_INPUT_NEXT_DROP, sizeof (cm->input_next_index_by_type));
memset (cm->max_valid_code_by_type, 0, sizeof (cm->max_valid_code_by_type));
#define _(a,n,t) cm->max_valid_code_by_type[ICMP6_##a] = clib_max (cm->max_valid_code_by_type[ICMP6_##a], n);
foreach_icmp6_code;
#undef _
- memset (cm->min_valid_hop_limit_by_type, 0, sizeof (cm->min_valid_hop_limit_by_type));
+ memset (cm->min_valid_hop_limit_by_type, 0,
+ sizeof (cm->min_valid_hop_limit_by_type));
cm->min_valid_hop_limit_by_type[ICMP6_router_solicitation] = 255;
cm->min_valid_hop_limit_by_type[ICMP6_router_advertisement] = 255;
cm->min_valid_hop_limit_by_type[ICMP6_neighbor_solicitation] = 255;
cm->min_valid_hop_limit_by_type[ICMP6_neighbor_advertisement] = 255;
cm->min_valid_hop_limit_by_type[ICMP6_redirect] = 255;
- memset (cm->min_valid_length_by_type, sizeof (icmp46_header_t), sizeof (cm->min_valid_length_by_type));
- cm->min_valid_length_by_type[ICMP6_router_solicitation] = sizeof (icmp6_neighbor_discovery_header_t);
- cm->min_valid_length_by_type[ICMP6_router_advertisement] = sizeof (icmp6_router_advertisement_header_t);
- cm->min_valid_length_by_type[ICMP6_neighbor_solicitation]
- = sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t);
- cm->min_valid_length_by_type[ICMP6_neighbor_advertisement]
- = sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t);
- cm->min_valid_length_by_type[ICMP6_redirect] = sizeof (icmp6_redirect_header_t);
-
- icmp6_register_type (vm, ICMP6_echo_request, ip6_icmp_echo_request_node.index);
+ memset (cm->min_valid_length_by_type, sizeof (icmp46_header_t),
+ sizeof (cm->min_valid_length_by_type));
+ cm->min_valid_length_by_type[ICMP6_router_solicitation] =
+ sizeof (icmp6_neighbor_discovery_header_t);
+ cm->min_valid_length_by_type[ICMP6_router_advertisement] =
+ sizeof (icmp6_router_advertisement_header_t);
+ cm->min_valid_length_by_type[ICMP6_neighbor_solicitation] =
+ sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t);
+ cm->min_valid_length_by_type[ICMP6_neighbor_advertisement] =
+ sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t);
+ cm->min_valid_length_by_type[ICMP6_redirect] =
+ sizeof (icmp6_redirect_header_t);
+
+ icmp6_register_type (vm, ICMP6_echo_request,
+ ip6_icmp_echo_request_node.index);
return vlib_call_init_function (vm, ip6_neighbor_init);
}
VLIB_INIT_FUNCTION (icmp6_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/icmp6.h b/vnet/vnet/ip/icmp6.h
index d44d0c3dbc9..a426512ea2f 100644
--- a/vnet/vnet/ip/icmp6.h
+++ b/vnet/vnet/ip/icmp6.h
@@ -53,22 +53,34 @@
_ (DROP, "error message dropped")
-typedef enum {
+typedef enum
+{
#define _(f,s) ICMP6_ERROR_##f,
foreach_icmp6_error
#undef _
} icmp6_error_t;
-typedef struct {
+typedef struct
+{
u8 packet_data[64];
} icmp6_input_trace_t;
format_function_t format_icmp6_input_trace;
-void icmp6_register_type (vlib_main_t * vm, icmp6_type_t type, u32 node_index);
-void icmp6_error_set_vnet_buffer (vlib_buffer_t *b, u8 type, u8 code, u32 data);
+void icmp6_register_type (vlib_main_t * vm, icmp6_type_t type,
+ u32 node_index);
+void icmp6_error_set_vnet_buffer (vlib_buffer_t * b, u8 type, u8 code,
+ u32 data);
extern vlib_node_registration_t ip6_icmp_input_node;
#endif /* included_vnet_icmp6_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/igmp_packet.h b/vnet/vnet/ip/igmp_packet.h
index 00b1e0deeb7..503259ece7c 100644
--- a/vnet/vnet/ip/igmp_packet.h
+++ b/vnet/vnet/ip/igmp_packet.h
@@ -58,21 +58,24 @@
_ (0x31, router_solicitation) \
_ (0x32, router_termination)
-typedef enum {
+typedef enum
+{
#define _(n,f) IGMP_TYPE_##f = n,
foreach_igmp_type
#undef _
} igmp_type_t;
-typedef struct {
- igmp_type_t type : 8;
+typedef struct
+{
+ igmp_type_t type:8;
u8 code;
u16 checksum;
} igmp_header_t;
-typedef struct {
+typedef struct
+{
/* membership_query, version <= 2 reports. */
igmp_header_t header;
@@ -88,14 +91,16 @@ typedef struct {
_ (5, allow_new_sources) \
_ (6, block_old_sources)
-typedef enum {
+typedef enum
+{
#define _(n,f) IGMP_MEMBERSHIP_GROUP_##f = n,
foreach_igmp_membership_group_v3_type
#undef _
} igmp_membership_group_v3_type_t;
-typedef struct {
- igmp_membership_group_v3_type_t type : 8;
+typedef struct
+{
+ igmp_membership_group_v3_type_t type:8;
/* Number of 32 bit words of aux data after source addresses. */
u8 n_aux_u32s;
@@ -117,7 +122,8 @@ igmp_membership_group_v3_next (igmp_membership_group_v3_t * g)
+ g->n_aux_u32s * sizeof (u32));
}
-typedef struct {
+typedef struct
+{
/* Type 0x22. */
igmp_header_t header;
@@ -130,7 +136,8 @@ typedef struct {
} igmp_membership_report_v3_t;
/* IP6 flavor of IGMP is called MLD which is embedded in ICMP6. */
-typedef struct {
+typedef struct
+{
/* Preceeded by ICMP v6 header. */
u16 max_response_delay_in_milliseconds;
u16 reserved;
@@ -138,3 +145,11 @@ typedef struct {
} mld_header_t;
#endif /* included_vnet_igmp_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip.h b/vnet/vnet/ip/ip.h
index f50662b2acf..02a1a9636ee 100644
--- a/vnet/vnet/ip/ip.h
+++ b/vnet/vnet/ip/ip.h
@@ -41,7 +41,7 @@
#define included_ip_main_h
#include <vppinfra/hash.h>
-#include <vppinfra/heap.h> /* adjacency heap */
+#include <vppinfra/heap.h> /* adjacency heap */
#include <vppinfra/ptclosure.h>
#include <vnet/vnet.h>
@@ -66,71 +66,73 @@
#include <vnet/classify/vnet_classify.h>
/* Per protocol info. */
-typedef struct {
+typedef struct
+{
/* Protocol name (also used as hash key). */
- u8 * name;
+ u8 *name;
/* Protocol number. */
ip_protocol_t protocol;
/* Format function for this IP protocol. */
- format_function_t * format_header;
+ format_function_t *format_header;
/* Parser for header. */
- unformat_function_t * unformat_header;
+ unformat_function_t *unformat_header;
/* Parser for per-protocol matches. */
- unformat_function_t * unformat_match;
+ unformat_function_t *unformat_match;
/* Parser for packet generator edits for this protocol. */
- unformat_function_t * unformat_pg_edit;
+ unformat_function_t *unformat_pg_edit;
} ip_protocol_info_t;
/* Per TCP/UDP port info. */
-typedef struct {
+typedef struct
+{
/* Port name (used as hash key). */
- u8 * name;
+ u8 *name;
/* UDP/TCP port number in network byte order. */
u16 port;
/* Port specific format function. */
- format_function_t * format_header;
+ format_function_t *format_header;
/* Parser for packet generator edits for this protocol. */
- unformat_function_t * unformat_pg_edit;
+ unformat_function_t *unformat_pg_edit;
} tcp_udp_port_info_t;
-typedef struct {
+typedef struct
+{
/* Per IP protocol info. */
- ip_protocol_info_t * protocol_infos;
+ ip_protocol_info_t *protocol_infos;
/* Protocol info index hashed by 8 bit IP protocol. */
- uword * protocol_info_by_protocol;
+ uword *protocol_info_by_protocol;
/* Hash table mapping IP protocol name (see protocols.def)
to protocol number. */
- uword * protocol_info_by_name;
+ uword *protocol_info_by_name;
/* Per TCP/UDP port info. */
- tcp_udp_port_info_t * port_infos;
+ tcp_udp_port_info_t *port_infos;
/* Hash table from network-byte-order port to port info index. */
- uword * port_info_by_port;
+ uword *port_info_by_port;
/* Hash table mapping TCP/UDP name to port info index. */
- uword * port_info_by_name;
+ uword *port_info_by_name;
} ip_main_t;
extern ip_main_t ip_main;
-clib_error_t *
-ip_main_init (vlib_main_t * vm);
+clib_error_t *ip_main_init (vlib_main_t * vm);
static inline ip_protocol_info_t *
ip_get_protocol_info (ip_main_t * im, u32 protocol)
{
- uword * p;
+ uword *p;
p = hash_get (im->protocol_info_by_protocol, protocol);
return p ? vec_elt_at_index (im->protocol_infos, p[0]) : 0;
@@ -139,22 +141,22 @@ ip_get_protocol_info (ip_main_t * im, u32 protocol)
static inline tcp_udp_port_info_t *
ip_get_tcp_udp_port_info (ip_main_t * im, u32 port)
{
- uword * p;
+ uword *p;
p = hash_get (im->port_info_by_port, port);
return p ? vec_elt_at_index (im->port_infos, p[0]) : 0;
}
-
+
always_inline ip_csum_t
-ip_incremental_checksum_buffer (vlib_main_t * vm, vlib_buffer_t * first_buffer,
+ip_incremental_checksum_buffer (vlib_main_t * vm,
+ vlib_buffer_t * first_buffer,
u32 first_buffer_offset,
- u32 n_bytes_to_checksum,
- ip_csum_t sum)
+ u32 n_bytes_to_checksum, ip_csum_t sum)
{
- vlib_buffer_t * b = first_buffer;
+ vlib_buffer_t *b = first_buffer;
u32 n_bytes_left = n_bytes_to_checksum;
ASSERT (b->current_length >= first_buffer_offset);
- void * h;
+ void *h;
u32 n;
n = clib_min (n_bytes_left, b->current_length);
@@ -177,9 +179,17 @@ ip_incremental_checksum_buffer (vlib_main_t * vm, vlib_buffer_t * first_buffer,
return sum;
}
-void ip_del_all_interface_addresses (vlib_main_t *vm, u32 sw_if_index);
+void ip_del_all_interface_addresses (vlib_main_t * vm, u32 sw_if_index);
extern vlib_node_registration_t ip4_inacl_node;
extern vlib_node_registration_t ip6_inacl_node;
#endif /* included_ip_main_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4.h b/vnet/vnet/ip/ip4.h
index f69f25f5d5d..0331c44563e 100644
--- a/vnet/vnet/ip/ip4.h
+++ b/vnet/vnet/ip/ip4.h
@@ -45,9 +45,10 @@
#include <vnet/ip/lookup.h>
#include <vnet/feature/feature.h>
-typedef struct ip4_fib_t {
+typedef struct ip4_fib_t
+{
/* Hash table for each prefix length mapping. */
- uword * fib_entry_by_dst_address[33];
+ uword *fib_entry_by_dst_address[33];
/* Mtrie for fast lookups. Hash is used to maintain overlapping prefixes. */
ip4_fib_mtrie_t mtrie;
@@ -74,12 +75,11 @@ typedef void (ip4_add_del_interface_address_function_t)
uword opaque,
u32 sw_if_index,
ip4_address_t * address,
- u32 address_length,
- u32 if_address_index,
- u32 is_del);
+ u32 address_length, u32 if_address_index, u32 is_del);
-typedef struct {
- ip4_add_del_interface_address_function_t * function;
+typedef struct
+{
+ ip4_add_del_interface_address_function_t *function;
uword function_opaque;
} ip4_add_del_interface_address_callback_t;
@@ -92,26 +92,28 @@ typedef struct {
* - Feature node run time references
*/
-typedef struct ip4_main_t {
+typedef struct ip4_main_t
+{
ip_lookup_main_t lookup_main;
/** Vector of FIBs. */
- struct fib_table_t_ * fibs;
+ struct fib_table_t_ *fibs;
u32 fib_masks[33];
/** Table index indexed by software interface. */
- u32 * fib_index_by_sw_if_index;
+ u32 *fib_index_by_sw_if_index;
/* IP4 enabled count by software interface */
- u8 * ip_enabled_by_sw_if_index;
+ u8 *ip_enabled_by_sw_if_index;
/** Hash table mapping table id to fib index.
ID space is not necessarily dense; index space is dense. */
- uword * fib_index_by_table_id;
+ uword *fib_index_by_table_id;
/** Functions to call when interface address changes. */
- ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks;
+ ip4_add_del_interface_address_callback_t
+ * add_del_interface_address_callbacks;
/** Template used to generate IP4 ARP packets. */
vlib_packet_template_t ip4_arp_request_packet_template;
@@ -120,7 +122,8 @@ typedef struct ip4_main_t {
u32 flow_hash_seed;
/** @brief Template information for VPP generated packets */
- struct {
+ struct
+ {
/** TTL to use for host generated packets. */
u8 ttl;
@@ -146,16 +149,17 @@ extern vlib_node_registration_t ip4_midchain_node;
always_inline uword
ip4_destination_matches_route (const ip4_main_t * im,
const ip4_address_t * key,
- const ip4_address_t * dest,
- uword dest_length)
-{ return 0 == ((key->data_u32 ^ dest->data_u32) & im->fib_masks[dest_length]); }
+ const ip4_address_t * dest, uword dest_length)
+{
+ return 0 == ((key->data_u32 ^ dest->data_u32) & im->fib_masks[dest_length]);
+}
always_inline uword
ip4_destination_matches_interface (ip4_main_t * im,
ip4_address_t * key,
ip_interface_address_t * ia)
{
- ip4_address_t * a = ip_interface_address_get_address (&im->lookup_main, ia);
+ ip4_address_t *a = ip_interface_address_get_address (&im->lookup_main, ia);
return ip4_destination_matches_route (im, key, a, ia->address_length);
}
@@ -165,40 +169,46 @@ ip4_unaligned_destination_matches_route (ip4_main_t * im,
ip4_address_t * key,
ip4_address_t * dest,
uword dest_length)
-{ return 0 == ((clib_mem_unaligned (&key->data_u32, u32) ^ dest->data_u32) & im->fib_masks[dest_length]); }
+{
+ return 0 ==
+ ((clib_mem_unaligned (&key->data_u32, u32) ^ dest->
+ data_u32) & im->fib_masks[dest_length]);
+}
always_inline int
ip4_src_address_for_packet (ip_lookup_main_t * lm,
- u32 sw_if_index,
- ip4_address_t * src)
+ u32 sw_if_index, ip4_address_t * src)
{
- u32 if_add_index =
- lm->if_address_pool_index_by_sw_if_index[sw_if_index];
- if (PREDICT_TRUE(if_add_index != ~0)) {
- ip_interface_address_t *if_add =
- pool_elt_at_index(lm->if_address_pool, if_add_index);
- ip4_address_t *if_ip =
- ip_interface_address_get_address(lm, if_add);
- *src = *if_ip;
- return 0;
+ u32 if_add_index = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
+ if (PREDICT_TRUE (if_add_index != ~0))
+ {
+ ip_interface_address_t *if_add =
+ pool_elt_at_index (lm->if_address_pool, if_add_index);
+ ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
+ *src = *if_ip;
+ return 0;
}
- else
+ else
{
- ASSERT(0);
- src->as_u32 = 0;
+ ASSERT (0);
+ src->as_u32 = 0;
}
- return (!0);
+ return (!0);
}
/* Find interface address which matches destination. */
always_inline ip4_address_t *
-ip4_interface_address_matching_destination (ip4_main_t * im, ip4_address_t * dst, u32 sw_if_index,
- ip_interface_address_t ** result_ia)
+ip4_interface_address_matching_destination (ip4_main_t * im,
+ ip4_address_t * dst,
+ u32 sw_if_index,
+ ip_interface_address_t **
+ result_ia)
{
- ip_lookup_main_t * lm = &im->lookup_main;
- ip_interface_address_t * ia;
- ip4_address_t * result = 0;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip_interface_address_t *ia;
+ ip4_address_t *result = 0;
+ /* *INDENT-OFF* */
foreach_ip_interface_address (lm, ia, sw_if_index,
1 /* honor unnumbered */,
({
@@ -209,54 +219,52 @@ ip4_interface_address_matching_destination (ip4_main_t * im, ip4_address_t * dst
break;
}
}));
+ /* *INDENT-ON* */
if (result_ia)
*result_ia = result ? ia : 0;
return result;
}
-ip4_address_t *
-ip4_interface_first_address (ip4_main_t * im, u32 sw_if_index,
- ip_interface_address_t ** result_ia);
+ip4_address_t *ip4_interface_first_address (ip4_main_t * im, u32 sw_if_index,
+ ip_interface_address_t **
+ result_ia);
-clib_error_t *
-ip4_add_del_interface_address (vlib_main_t * vm, u32 sw_if_index,
- ip4_address_t * address, u32 address_length,
- u32 is_del);
+clib_error_t *ip4_add_del_interface_address (vlib_main_t * vm,
+ u32 sw_if_index,
+ ip4_address_t * address,
+ u32 address_length, u32 is_del);
-void
-ip4_sw_interface_enable_disable (u32 sw_if_index,
- u32 is_enable);
+void ip4_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable);
int ip4_address_compare (ip4_address_t * a1, ip4_address_t * a2);
/* Send an ARP request to see if given destination is reachable on given interface. */
-clib_error_t *
-ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst, u32 sw_if_index);
+clib_error_t *ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst,
+ u32 sw_if_index);
-clib_error_t *
-ip4_set_arp_limit (u32 arp_limit);
+clib_error_t *ip4_set_arp_limit (u32 arp_limit);
uword
ip4_udp_register_listener (vlib_main_t * vm,
- u16 dst_port,
- u32 next_node_index);
+ u16 dst_port, u32 next_node_index);
void
-ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type,
- u32 node_index);
+ip4_icmp_register_type (vlib_main_t * vm, icmp4_type_t type, u32 node_index);
-u16 ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip4_header_t * ip0);
+u16 ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
+ ip4_header_t * ip0);
void ip4_register_protocol (u32 protocol, u32 node_index);
serialize_function_t serialize_vnet_ip4_main, unserialize_vnet_ip4_main;
-int vnet_set_ip4_flow_hash (u32 table_id, flow_hash_config_t flow_hash_config);
+int vnet_set_ip4_flow_hash (u32 table_id,
+ flow_hash_config_t flow_hash_config);
void ip4_mtrie_init (ip4_fib_mtrie_t * m);
int vnet_set_ip4_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
- u32 table_index);
+ u32 table_index);
/* Compute flow hash. We'll use it to select which adjacency to use for this
flow. And other things. */
@@ -264,43 +272,51 @@ always_inline u32
ip4_compute_flow_hash (const ip4_header_t * ip,
flow_hash_config_t flow_hash_config)
{
- tcp_header_t * tcp = (void *) (ip + 1);
- u32 a, b, c, t1, t2;
- uword is_tcp_udp = (ip->protocol == IP_PROTOCOL_TCP
- || ip->protocol == IP_PROTOCOL_UDP);
+ tcp_header_t *tcp = (void *) (ip + 1);
+ u32 a, b, c, t1, t2;
+ uword is_tcp_udp = (ip->protocol == IP_PROTOCOL_TCP
+ || ip->protocol == IP_PROTOCOL_UDP);
- t1 = (flow_hash_config & IP_FLOW_HASH_SRC_ADDR)
- ? ip->src_address.data_u32 : 0;
- t2 = (flow_hash_config & IP_FLOW_HASH_DST_ADDR)
- ? ip->dst_address.data_u32 : 0;
+ t1 = (flow_hash_config & IP_FLOW_HASH_SRC_ADDR)
+ ? ip->src_address.data_u32 : 0;
+ t2 = (flow_hash_config & IP_FLOW_HASH_DST_ADDR)
+ ? ip->dst_address.data_u32 : 0;
- a = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t2 : t1;
- b = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t1 : t2;
- b ^= (flow_hash_config & IP_FLOW_HASH_PROTO) ? ip->protocol : 0;
+ a = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t2 : t1;
+ b = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t1 : t2;
+ b ^= (flow_hash_config & IP_FLOW_HASH_PROTO) ? ip->protocol : 0;
- t1 = is_tcp_udp ? tcp->ports.src : 0;
- t2 = is_tcp_udp ? tcp->ports.dst : 0;
+ t1 = is_tcp_udp ? tcp->ports.src : 0;
+ t2 = is_tcp_udp ? tcp->ports.dst : 0;
- t1 = (flow_hash_config & IP_FLOW_HASH_SRC_PORT) ? t1 : 0;
- t2 = (flow_hash_config & IP_FLOW_HASH_DST_PORT) ? t2 : 0;
+ t1 = (flow_hash_config & IP_FLOW_HASH_SRC_PORT) ? t1 : 0;
+ t2 = (flow_hash_config & IP_FLOW_HASH_DST_PORT) ? t2 : 0;
- c = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ?
- (t1<<16) | t2 : (t2<<16) | t1;
+ c = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ?
+ (t1 << 16) | t2 : (t2 << 16) | t1;
- hash_v3_mix32 (a, b, c);
- hash_v3_finalize32 (a, b, c);
+ hash_v3_mix32 (a, b, c);
+ hash_v3_finalize32 (a, b, c);
- return c;
+ return c;
}
void
ip4_forward_next_trace (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- vlib_rx_or_tx_t which_adj_index);
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame,
+ vlib_rx_or_tx_t which_adj_index);
-u8 * format_ip4_forward_next_trace (u8 * s, va_list * args);
+u8 *format_ip4_forward_next_trace (u8 * s, va_list * args);
u32 ip4_tcp_udp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0);
#endif /* included_ip_ip4_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip46_cli.c b/vnet/vnet/ip/ip46_cli.c
index 01b18929b0f..ce1ffa6242b 100644
--- a/vnet/vnet/ip/ip46_cli.c
+++ b/vnet/vnet/ip/ip46_cli.c
@@ -47,15 +47,22 @@
*/
-int ip4_address_compare (ip4_address_t * a1, ip4_address_t * a2)
-{ return clib_net_to_host_u32 (a1->data_u32) - clib_net_to_host_u32 (a2->data_u32); }
+int
+ip4_address_compare (ip4_address_t * a1, ip4_address_t * a2)
+{
+ return clib_net_to_host_u32 (a1->data_u32) -
+ clib_net_to_host_u32 (a2->data_u32);
+}
-int ip6_address_compare (ip6_address_t * a1, ip6_address_t * a2)
+int
+ip6_address_compare (ip6_address_t * a1, ip6_address_t * a2)
{
int i;
for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
{
- int cmp = clib_net_to_host_u16 (a1->as_u16[i]) - clib_net_to_host_u16 (a2->as_u16[i]);
+ int cmp =
+ clib_net_to_host_u16 (a1->as_u16[i]) -
+ clib_net_to_host_u16 (a2->as_u16[i]);
if (cmp != 0)
return cmp;
}
@@ -69,18 +76,20 @@ VLIB_CLI_COMMAND (set_interface_ip_command, static) = {
};
/* *INDENT-ON* */
-void ip_del_all_interface_addresses (vlib_main_t *vm, u32 sw_if_index)
+void
+ip_del_all_interface_addresses (vlib_main_t * vm, u32 sw_if_index)
{
- ip4_main_t * im4 = &ip4_main;
- ip4_address_t * ip4_addrs = 0;
+ ip4_main_t *im4 = &ip4_main;
+ ip4_address_t *ip4_addrs = 0;
u32 *ip4_masks = 0;
- ip6_main_t * im6 = &ip6_main;
- ip6_address_t * ip6_addrs = 0;
+ ip6_main_t *im6 = &ip6_main;
+ ip6_address_t *ip6_addrs = 0;
u32 *ip6_masks = 0;
- ip_interface_address_t * ia;
+ ip_interface_address_t *ia;
int i;
- foreach_ip_interface_address (&im4->lookup_main, ia, sw_if_index,
+ /* *INDENT-OFF* */
+ foreach_ip_interface_address (&im4->lookup_main, ia, sw_if_index,
0 /* honor unnumbered */,
({
ip4_address_t * x = (ip4_address_t *)
@@ -88,8 +97,10 @@ void ip_del_all_interface_addresses (vlib_main_t *vm, u32 sw_if_index)
vec_add1 (ip4_addrs, x[0]);
vec_add1 (ip4_masks, ia->address_length);
}));
+ /* *INDENT-ON* */
- foreach_ip_interface_address (&im6->lookup_main, ia, sw_if_index,
+ /* *INDENT-OFF* */
+ foreach_ip_interface_address (&im6->lookup_main, ia, sw_if_index,
0 /* honor unnumbered */,
({
ip6_address_t * x = (ip6_address_t *)
@@ -97,13 +108,14 @@ void ip_del_all_interface_addresses (vlib_main_t *vm, u32 sw_if_index)
vec_add1 (ip6_addrs, x[0]);
vec_add1 (ip6_masks, ia->address_length);
}));
+ /* *INDENT-ON* */
for (i = 0; i < vec_len (ip4_addrs); i++)
- ip4_add_del_interface_address (vm, sw_if_index, &ip4_addrs[i],
- ip4_masks[i], 1 /* is_del */);
+ ip4_add_del_interface_address (vm, sw_if_index, &ip4_addrs[i],
+ ip4_masks[i], 1 /* is_del */ );
for (i = 0; i < vec_len (ip6_addrs); i++)
- ip6_add_del_interface_address (vm, sw_if_index, &ip6_addrs[i],
- ip6_masks[i], 1 /* is_del */);
+ ip6_add_del_interface_address (vm, sw_if_index, &ip6_addrs[i],
+ ip6_masks[i], 1 /* is_del */ );
vec_free (ip4_addrs);
vec_free (ip4_masks);
@@ -114,12 +126,12 @@ void ip_del_all_interface_addresses (vlib_main_t *vm, u32 sw_if_index)
static clib_error_t *
ip_address_delete_cleanup (vnet_main_t * vnm, u32 hw_if_index, u32 is_create)
{
- vlib_main_t * vm = vlib_get_main();
- vnet_hw_interface_t * hw;
+ vlib_main_t *vm = vlib_get_main ();
+ vnet_hw_interface_t *hw;
if (is_create)
return 0;
-
+
hw = vnet_get_hw_interface (vnm, hw_if_index);
ip_del_all_interface_addresses (vm, hw->sw_if_index);
@@ -130,13 +142,12 @@ VNET_HW_INTERFACE_ADD_DEL_FUNCTION (ip_address_delete_cleanup);
static clib_error_t *
add_del_ip_address (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
+ vnet_main_t *vnm = vnet_get_main ();
ip4_address_t a4;
ip6_address_t a6;
- clib_error_t * error = 0;
+ clib_error_t *error = 0;
u32 sw_if_index, length, is_del;
sw_if_index = ~0;
@@ -145,7 +156,7 @@ add_del_ip_address (vlib_main_t * vm,
if (unformat (input, "del"))
is_del = 1;
- if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+ if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
error = clib_error_return (0, "unknown interface `%U'",
format_unformat_error, input);
@@ -168,7 +179,7 @@ add_del_ip_address (vlib_main_t * vm,
}
- done:
+done:
return error;
}
@@ -208,7 +219,18 @@ VLIB_CLI_COMMAND (set_interface_ip_address_command, static) = {
/* *INDENT-ON* */
/* Dummy init function to get us linked in. */
-static clib_error_t * ip4_cli_init (vlib_main_t * vm)
-{ return 0; }
+static clib_error_t *
+ip4_cli_init (vlib_main_t * vm)
+{
+ return 0;
+}
VLIB_INIT_FUNCTION (ip4_cli_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_error.h b/vnet/vnet/ip/ip4_error.h
index 8d7fc53dffc..95d12ec22d5 100644
--- a/vnet/vnet/ip/ip4_error.h
+++ b/vnet/vnet/ip/ip4_error.h
@@ -76,11 +76,20 @@
_ (INACL_TABLE_MISS, "input ACL table-miss drops") \
_ (INACL_SESSION_DENY, "input ACL session deny drops")
-typedef enum {
+typedef enum
+{
#define _(sym,str) IP4_ERROR_##sym,
foreach_ip4_error
#undef _
- IP4_N_ERROR,
+ IP4_N_ERROR,
} ip4_error_t;
#endif /* included_ip_ip4_error_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_format.c b/vnet/vnet/ip/ip4_format.c
index 5f4f8e3667d..c803e0656db 100644
--- a/vnet/vnet/ip/ip4_format.c
+++ b/vnet/vnet/ip/ip4_format.c
@@ -40,27 +40,30 @@
#include <vnet/ip/ip.h>
/* Format an IP4 address. */
-u8 * format_ip4_address (u8 * s, va_list * args)
+u8 *
+format_ip4_address (u8 * s, va_list * args)
{
- u8 * a = va_arg (*args, u8 *);
+ u8 *a = va_arg (*args, u8 *);
return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
}
/* Format an IP4 route destination and length. */
-u8 * format_ip4_address_and_length (u8 * s, va_list * args)
+u8 *
+format_ip4_address_and_length (u8 * s, va_list * args)
{
- u8 * a = va_arg (*args, u8 *);
+ u8 *a = va_arg (*args, u8 *);
u8 l = va_arg (*args, u32);
return format (s, "%U/%d", format_ip4_address, a, l);
}
/* Parse an IP4 address %d.%d.%d.%d. */
-uword unformat_ip4_address (unformat_input_t * input, va_list * args)
+uword
+unformat_ip4_address (unformat_input_t * input, va_list * args)
{
- u8 * result = va_arg (*args, u8 *);
+ u8 *result = va_arg (*args, u8 *);
unsigned a[4];
- if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
+ if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
return 0;
if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
@@ -75,9 +78,10 @@ uword unformat_ip4_address (unformat_input_t * input, va_list * args)
}
/* Format an IP4 header. */
-u8 * format_ip4_header (u8 * s, va_list * args)
+u8 *
+format_ip4_header (u8 * s, va_list * args)
{
- ip4_header_t * ip = va_arg (*args, ip4_header_t *);
+ ip4_header_t *ip = va_arg (*args, ip4_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
u32 ip_version, header_bytes;
uword indent;
@@ -100,9 +104,8 @@ u8 * format_ip4_header (u8 * s, va_list * args)
/* Show IP version and header length only with unexpected values. */
if (ip_version != 4 || header_bytes != sizeof (ip4_header_t))
s = format (s, "\n%Uversion %d, header length %d",
- format_white_space, indent,
- ip_version, header_bytes);
-
+ format_white_space, indent, ip_version, header_bytes);
+
s = format (s, "\n%Utos 0x%02x, ttl %d, length %d, checksum 0x%04x",
format_white_space, indent,
ip->tos, ip->ttl,
@@ -134,9 +137,9 @@ u8 * format_ip4_header (u8 * s, va_list * args)
{
s = format (s, ", flags ");
#define _(l) if (f & IP4_HEADER_FLAG_##l) s = format (s, #l);
- _ (MORE_FRAGMENTS);
- _ (DONT_FRAGMENT);
- _ (CONGESTION);
+ _(MORE_FRAGMENTS);
+ _(DONT_FRAGMENT);
+ _(CONGESTION);
#undef _
}
}
@@ -144,14 +147,13 @@ u8 * format_ip4_header (u8 * s, va_list * args)
/* Recurse into next protocol layer. */
if (max_header_bytes != 0 && header_bytes < max_header_bytes)
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi = ip_get_protocol_info (im, ip->protocol);
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi = ip_get_protocol_info (im, ip->protocol);
if (pi && pi->format_header)
s = format (s, "\n%U%U",
- format_white_space, indent - 2,
- pi->format_header,
- /* next protocol header */ (void*) ip + header_bytes,
+ format_white_space, indent - 2, pi->format_header,
+ /* next protocol header */ (void *) ip + header_bytes,
max_header_bytes - header_bytes);
}
@@ -159,15 +161,16 @@ u8 * format_ip4_header (u8 * s, va_list * args)
}
/* Parse an IP4 header. */
-uword unformat_ip4_header (unformat_input_t * input, va_list * args)
+uword
+unformat_ip4_header (unformat_input_t * input, va_list * args)
{
- u8 ** result = va_arg (*args, u8 **);
- ip4_header_t * ip;
+ u8 **result = va_arg (*args, u8 **);
+ ip4_header_t *ip;
int old_length;
/* Allocate space for IP header. */
{
- void * p;
+ void *p;
old_length = vec_len (*result);
vec_add2 (*result, p, sizeof (ip4_header_t));
@@ -177,10 +180,10 @@ uword unformat_ip4_header (unformat_input_t * input, va_list * args)
memset (ip, 0, sizeof (ip[0]));
ip->ip_version_and_header_length = IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
- if (! unformat (input, "%U: %U -> %U",
- unformat_ip_protocol, &ip->protocol,
- unformat_ip4_address, &ip->src_address,
- unformat_ip4_address, &ip->dst_address))
+ if (!unformat (input, "%U: %U -> %U",
+ unformat_ip_protocol, &ip->protocol,
+ unformat_ip4_address, &ip->src_address,
+ unformat_ip4_address, &ip->dst_address))
return 0;
/* Parse options. */
@@ -195,8 +198,7 @@ uword unformat_ip4_header (unformat_input_t * input, va_list * args)
ip->ttl = i;
else if (unformat (input, "fragment id %U offset %U",
- unformat_vlib_number, &i,
- unformat_vlib_number, &j))
+ unformat_vlib_number, &i, unformat_vlib_number, &j))
{
ip->fragment_id = clib_host_to_net_u16 (i);
ip->flags_and_fragment_offset |=
@@ -205,14 +207,17 @@ uword unformat_ip4_header (unformat_input_t * input, va_list * args)
/* Flags. */
else if (unformat (input, "mf") || unformat (input, "MF"))
- ip->flags_and_fragment_offset |= clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
+ ip->flags_and_fragment_offset |=
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
else if (unformat (input, "df") || unformat (input, "DF"))
- ip->flags_and_fragment_offset |= clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
+ ip->flags_and_fragment_offset |=
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
else if (unformat (input, "ce") || unformat (input, "CE"))
- ip->flags_and_fragment_offset |= clib_host_to_net_u16 (IP4_HEADER_FLAG_CONGESTION);
-
+ ip->flags_and_fragment_offset |=
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_CONGESTION);
+
/* Can't parse input: try next protocol level. */
else
break;
@@ -223,12 +228,12 @@ uword unformat_ip4_header (unformat_input_t * input, va_list * args)
/* Recurse into next protocol layer. */
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi = ip_get_protocol_info (im, ip->protocol);
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi = ip_get_protocol_info (im, ip->protocol);
if (pi && pi->unformat_header)
{
- if (! unformat_user (input, pi->unformat_header, result))
+ if (!unformat_user (input, pi->unformat_header, result))
return 0;
/* Result may have moved. */
@@ -241,3 +246,11 @@ uword unformat_ip4_header (unformat_input_t * input, va_list * args)
return 1;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_forward.c b/vnet/vnet/ip/ip4_forward.c
index 43a894075dd..27f2ece83c3 100644
--- a/vnet/vnet/ip/ip4_forward.c
+++ b/vnet/vnet/ip/ip4_forward.c
@@ -43,10 +43,10 @@
#include <vnet/ethernet/arp_packet.h> /* for ethernet_arp_header_t */
#include <vnet/ppp/ppp.h>
#include <vnet/srp/srp.h> /* for srp_hw_interface_class */
-#include <vnet/api_errno.h> /* for API error numbers */
-#include <vnet/fib/fib_table.h> /* for FIB table and entry creation */
-#include <vnet/fib/fib_entry.h> /* for FIB table and entry creation */
-#include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */
+#include <vnet/api_errno.h> /* for API error numbers */
+#include <vnet/fib/fib_table.h> /* for FIB table and entry creation */
+#include <vnet/fib/fib_entry.h> /* for FIB table and entry creation */
+#include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */
#include <vnet/fib/ip4_fib.h>
#include <vnet/dpo/load_balance.h>
#include <vnet/dpo/classify_dpo.h>
@@ -60,9 +60,9 @@
void
ip4_forward_next_trace (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- vlib_rx_or_tx_t which_adj_index);
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame,
+ vlib_rx_or_tx_t which_adj_index);
always_inline uword
ip4_lookup_inline (vlib_main_t * vm,
@@ -70,11 +70,11 @@ ip4_lookup_inline (vlib_main_t * vm,
vlib_frame_t * frame,
int lookup_for_responses_to_locally_received_packets)
{
- ip4_main_t * im = &ip4_main;
- vlib_combined_counter_main_t * cm = &load_balance_main.lbm_to_counters;
- u32 n_left_from, n_left_to_next, * from, * to_next;
+ ip4_main_t *im = &ip4_main;
+ vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters;
+ u32 n_left_from, n_left_to_next, *from, *to_next;
ip_lookup_next_t next;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -82,216 +82,239 @@ ip4_lookup_inline (vlib_main_t * vm,
while (n_left_from > 0)
{
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
while (n_left_from >= 8 && n_left_to_next >= 4)
- {
- vlib_buffer_t * p0, * p1, * p2, * p3;
- ip4_header_t * ip0, * ip1, * ip2, * ip3;
- __attribute__((unused)) tcp_header_t * tcp0, * tcp1, * tcp2, * tcp3;
- ip_lookup_next_t next0, next1, next2, next3;
- const load_balance_t * lb0, * lb1, * lb2, * lb3;
- ip4_fib_mtrie_t * mtrie0, * mtrie1, * mtrie2, * mtrie3;
- ip4_fib_mtrie_leaf_t leaf0, leaf1, leaf2, leaf3;
- ip4_address_t * dst_addr0, *dst_addr1, *dst_addr2, *dst_addr3;
- __attribute__((unused)) u32 pi0, fib_index0, lb_index0, is_tcp_udp0;
- __attribute__((unused)) u32 pi1, fib_index1, lb_index1, is_tcp_udp1;
- __attribute__((unused)) u32 pi2, fib_index2, lb_index2, is_tcp_udp2;
- __attribute__((unused)) u32 pi3, fib_index3, lb_index3, is_tcp_udp3;
- flow_hash_config_t flow_hash_config0, flow_hash_config1;
- flow_hash_config_t flow_hash_config2, flow_hash_config3;
- u32 hash_c0, hash_c1, hash_c2, hash_c3;
+ {
+ vlib_buffer_t *p0, *p1, *p2, *p3;
+ ip4_header_t *ip0, *ip1, *ip2, *ip3;
+ __attribute__ ((unused)) tcp_header_t *tcp0, *tcp1, *tcp2, *tcp3;
+ ip_lookup_next_t next0, next1, next2, next3;
+ const load_balance_t *lb0, *lb1, *lb2, *lb3;
+ ip4_fib_mtrie_t *mtrie0, *mtrie1, *mtrie2, *mtrie3;
+ ip4_fib_mtrie_leaf_t leaf0, leaf1, leaf2, leaf3;
+ ip4_address_t *dst_addr0, *dst_addr1, *dst_addr2, *dst_addr3;
+ __attribute__ ((unused)) u32 pi0, fib_index0, lb_index0,
+ is_tcp_udp0;
+ __attribute__ ((unused)) u32 pi1, fib_index1, lb_index1,
+ is_tcp_udp1;
+ __attribute__ ((unused)) u32 pi2, fib_index2, lb_index2,
+ is_tcp_udp2;
+ __attribute__ ((unused)) u32 pi3, fib_index3, lb_index3,
+ is_tcp_udp3;
+ flow_hash_config_t flow_hash_config0, flow_hash_config1;
+ flow_hash_config_t flow_hash_config2, flow_hash_config3;
+ u32 hash_c0, hash_c1, hash_c2, hash_c3;
const dpo_id_t *dpo0, *dpo1, *dpo2, *dpo3;
- /* Prefetch next iteration. */
- {
- vlib_buffer_t * p4, * p5, * p6, * p7;
-
- p4 = vlib_get_buffer (vm, from[4]);
- p5 = vlib_get_buffer (vm, from[5]);
- p6 = vlib_get_buffer (vm, from[6]);
- p7 = vlib_get_buffer (vm, from[7]);
-
- vlib_prefetch_buffer_header (p4, LOAD);
- vlib_prefetch_buffer_header (p5, LOAD);
- vlib_prefetch_buffer_header (p6, LOAD);
- vlib_prefetch_buffer_header (p7, LOAD);
-
- CLIB_PREFETCH (p4->data, sizeof (ip0[0]), LOAD);
- CLIB_PREFETCH (p5->data, sizeof (ip0[0]), LOAD);
- CLIB_PREFETCH (p6->data, sizeof (ip0[0]), LOAD);
- CLIB_PREFETCH (p7->data, sizeof (ip0[0]), LOAD);
- }
-
- pi0 = to_next[0] = from[0];
- pi1 = to_next[1] = from[1];
- pi2 = to_next[2] = from[2];
- pi3 = to_next[3] = from[3];
-
- from += 4;
- to_next += 4;
- n_left_to_next -= 4;
- n_left_from -= 4;
-
- p0 = vlib_get_buffer (vm, pi0);
- p1 = vlib_get_buffer (vm, pi1);
- p2 = vlib_get_buffer (vm, pi2);
- p3 = vlib_get_buffer (vm, pi3);
-
- ip0 = vlib_buffer_get_current (p0);
- ip1 = vlib_buffer_get_current (p1);
- ip2 = vlib_buffer_get_current (p2);
- ip3 = vlib_buffer_get_current (p3);
-
- dst_addr0 = &ip0->dst_address;
- dst_addr1 = &ip1->dst_address;
- dst_addr2 = &ip2->dst_address;
- dst_addr3 = &ip3->dst_address;
-
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]);
- fib_index2 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p2)->sw_if_index[VLIB_RX]);
- fib_index3 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p3)->sw_if_index[VLIB_RX]);
- fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
- fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX];
- fib_index2 = (vnet_buffer(p2)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index2 : vnet_buffer(p2)->sw_if_index[VLIB_TX];
- fib_index3 = (vnet_buffer(p3)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index3 : vnet_buffer(p3)->sw_if_index[VLIB_TX];
-
-
- if (! lookup_for_responses_to_locally_received_packets)
- {
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t *p4, *p5, *p6, *p7;
+
+ p4 = vlib_get_buffer (vm, from[4]);
+ p5 = vlib_get_buffer (vm, from[5]);
+ p6 = vlib_get_buffer (vm, from[6]);
+ p7 = vlib_get_buffer (vm, from[7]);
+
+ vlib_prefetch_buffer_header (p4, LOAD);
+ vlib_prefetch_buffer_header (p5, LOAD);
+ vlib_prefetch_buffer_header (p6, LOAD);
+ vlib_prefetch_buffer_header (p7, LOAD);
+
+ CLIB_PREFETCH (p4->data, sizeof (ip0[0]), LOAD);
+ CLIB_PREFETCH (p5->data, sizeof (ip0[0]), LOAD);
+ CLIB_PREFETCH (p6->data, sizeof (ip0[0]), LOAD);
+ CLIB_PREFETCH (p7->data, sizeof (ip0[0]), LOAD);
+ }
+
+ pi0 = to_next[0] = from[0];
+ pi1 = to_next[1] = from[1];
+ pi2 = to_next[2] = from[2];
+ pi3 = to_next[3] = from[3];
+
+ from += 4;
+ to_next += 4;
+ n_left_to_next -= 4;
+ n_left_from -= 4;
+
+ p0 = vlib_get_buffer (vm, pi0);
+ p1 = vlib_get_buffer (vm, pi1);
+ p2 = vlib_get_buffer (vm, pi2);
+ p3 = vlib_get_buffer (vm, pi3);
+
+ ip0 = vlib_buffer_get_current (p0);
+ ip1 = vlib_buffer_get_current (p1);
+ ip2 = vlib_buffer_get_current (p2);
+ ip3 = vlib_buffer_get_current (p3);
+
+ dst_addr0 = &ip0->dst_address;
+ dst_addr1 = &ip1->dst_address;
+ dst_addr2 = &ip2->dst_address;
+ dst_addr3 = &ip3->dst_address;
+
+ fib_index0 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index1 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p1)->sw_if_index[VLIB_RX]);
+ fib_index2 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p2)->sw_if_index[VLIB_RX]);
+ fib_index3 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p3)->sw_if_index[VLIB_RX]);
+ fib_index0 =
+ (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
+ fib_index1 =
+ (vnet_buffer (p1)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index1 : vnet_buffer (p1)->sw_if_index[VLIB_TX];
+ fib_index2 =
+ (vnet_buffer (p2)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index2 : vnet_buffer (p2)->sw_if_index[VLIB_TX];
+ fib_index3 =
+ (vnet_buffer (p3)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index3 : vnet_buffer (p3)->sw_if_index[VLIB_TX];
+
+
+ if (!lookup_for_responses_to_locally_received_packets)
+ {
mtrie0 = &ip4_fib_get (fib_index0)->mtrie;
mtrie1 = &ip4_fib_get (fib_index1)->mtrie;
mtrie2 = &ip4_fib_get (fib_index2)->mtrie;
mtrie3 = &ip4_fib_get (fib_index3)->mtrie;
- leaf0 = leaf1 = leaf2 = leaf3 = IP4_FIB_MTRIE_LEAF_ROOT;
-
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 0);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 0);
- leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 0);
- leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 0);
- }
-
- tcp0 = (void *) (ip0 + 1);
- tcp1 = (void *) (ip1 + 1);
- tcp2 = (void *) (ip2 + 1);
- tcp3 = (void *) (ip3 + 1);
-
- is_tcp_udp0 = (ip0->protocol == IP_PROTOCOL_TCP
- || ip0->protocol == IP_PROTOCOL_UDP);
- is_tcp_udp1 = (ip1->protocol == IP_PROTOCOL_TCP
- || ip1->protocol == IP_PROTOCOL_UDP);
- is_tcp_udp2 = (ip2->protocol == IP_PROTOCOL_TCP
- || ip2->protocol == IP_PROTOCOL_UDP);
- is_tcp_udp3 = (ip1->protocol == IP_PROTOCOL_TCP
- || ip1->protocol == IP_PROTOCOL_UDP);
-
- if (! lookup_for_responses_to_locally_received_packets)
- {
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 1);
- leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 1);
- leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 1);
- }
-
- if (! lookup_for_responses_to_locally_received_packets)
- {
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 2);
- leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 2);
- leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 2);
- }
-
- if (! lookup_for_responses_to_locally_received_packets)
- {
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 3);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 3);
- leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 3);
- leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 3);
- }
-
- if (lookup_for_responses_to_locally_received_packets)
- {
- lb_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_RX];
- lb_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_RX];
- lb_index2 = vnet_buffer (p2)->ip.adj_index[VLIB_RX];
- lb_index3 = vnet_buffer (p3)->ip.adj_index[VLIB_RX];
- }
- else
- {
- /* Handle default route. */
- leaf0 = (leaf0 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
- leaf1 = (leaf1 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie1->default_leaf : leaf1);
- leaf2 = (leaf2 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie2->default_leaf : leaf2);
- leaf3 = (leaf3 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie3->default_leaf : leaf3);
- lb_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- lb_index1 = ip4_fib_mtrie_leaf_get_adj_index (leaf1);
- lb_index2 = ip4_fib_mtrie_leaf_get_adj_index (leaf2);
- lb_index3 = ip4_fib_mtrie_leaf_get_adj_index (leaf3);
- }
+ leaf0 = leaf1 = leaf2 = leaf3 = IP4_FIB_MTRIE_LEAF_ROOT;
+
+ leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 0);
+ leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 0);
+ leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 0);
+ leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 0);
+ }
+
+ tcp0 = (void *) (ip0 + 1);
+ tcp1 = (void *) (ip1 + 1);
+ tcp2 = (void *) (ip2 + 1);
+ tcp3 = (void *) (ip3 + 1);
+
+ is_tcp_udp0 = (ip0->protocol == IP_PROTOCOL_TCP
+ || ip0->protocol == IP_PROTOCOL_UDP);
+ is_tcp_udp1 = (ip1->protocol == IP_PROTOCOL_TCP
+ || ip1->protocol == IP_PROTOCOL_UDP);
+ is_tcp_udp2 = (ip2->protocol == IP_PROTOCOL_TCP
+ || ip2->protocol == IP_PROTOCOL_UDP);
+ is_tcp_udp3 = (ip1->protocol == IP_PROTOCOL_TCP
+ || ip1->protocol == IP_PROTOCOL_UDP);
+
+ if (!lookup_for_responses_to_locally_received_packets)
+ {
+ leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1);
+ leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 1);
+ leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 1);
+ leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 1);
+ }
+
+ if (!lookup_for_responses_to_locally_received_packets)
+ {
+ leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2);
+ leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 2);
+ leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 2);
+ leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 2);
+ }
+
+ if (!lookup_for_responses_to_locally_received_packets)
+ {
+ leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 3);
+ leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 3);
+ leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 3);
+ leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 3);
+ }
+
+ if (lookup_for_responses_to_locally_received_packets)
+ {
+ lb_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_RX];
+ lb_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_RX];
+ lb_index2 = vnet_buffer (p2)->ip.adj_index[VLIB_RX];
+ lb_index3 = vnet_buffer (p3)->ip.adj_index[VLIB_RX];
+ }
+ else
+ {
+ /* Handle default route. */
+ leaf0 =
+ (leaf0 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
+ leaf1 =
+ (leaf1 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie1->default_leaf : leaf1);
+ leaf2 =
+ (leaf2 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie2->default_leaf : leaf2);
+ leaf3 =
+ (leaf3 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie3->default_leaf : leaf3);
+ lb_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
+ lb_index1 = ip4_fib_mtrie_leaf_get_adj_index (leaf1);
+ lb_index2 = ip4_fib_mtrie_leaf_get_adj_index (leaf2);
+ lb_index3 = ip4_fib_mtrie_leaf_get_adj_index (leaf3);
+ }
lb0 = load_balance_get (lb_index0);
lb1 = load_balance_get (lb_index1);
lb2 = load_balance_get (lb_index2);
lb3 = load_balance_get (lb_index3);
- /* Use flow hash to compute multipath adjacency. */
- hash_c0 = vnet_buffer (p0)->ip.flow_hash = 0;
- hash_c1 = vnet_buffer (p1)->ip.flow_hash = 0;
- hash_c2 = vnet_buffer (p2)->ip.flow_hash = 0;
- hash_c3 = vnet_buffer (p3)->ip.flow_hash = 0;
- if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
- {
- flow_hash_config0 = lb0->lb_hash_config;
- hash_c0 = vnet_buffer (p0)->ip.flow_hash =
- ip4_compute_flow_hash (ip0, flow_hash_config0);
- }
- if (PREDICT_FALSE(lb1->lb_n_buckets > 1))
- {
+ /* Use flow hash to compute multipath adjacency. */
+ hash_c0 = vnet_buffer (p0)->ip.flow_hash = 0;
+ hash_c1 = vnet_buffer (p1)->ip.flow_hash = 0;
+ hash_c2 = vnet_buffer (p2)->ip.flow_hash = 0;
+ hash_c3 = vnet_buffer (p3)->ip.flow_hash = 0;
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ flow_hash_config0 = lb0->lb_hash_config;
+ hash_c0 = vnet_buffer (p0)->ip.flow_hash =
+ ip4_compute_flow_hash (ip0, flow_hash_config0);
+ }
+ if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
+ {
flow_hash_config1 = lb1->lb_hash_config;
- hash_c1 = vnet_buffer (p1)->ip.flow_hash =
- ip4_compute_flow_hash (ip1, flow_hash_config1);
- }
- if (PREDICT_FALSE (lb2->lb_n_buckets > 1))
- {
- flow_hash_config2 = lb2->lb_hash_config;
- hash_c2 = vnet_buffer (p2)->ip.flow_hash =
- ip4_compute_flow_hash (ip2, flow_hash_config2);
- }
- if (PREDICT_FALSE(lb3->lb_n_buckets > 1))
- {
+ hash_c1 = vnet_buffer (p1)->ip.flow_hash =
+ ip4_compute_flow_hash (ip1, flow_hash_config1);
+ }
+ if (PREDICT_FALSE (lb2->lb_n_buckets > 1))
+ {
+ flow_hash_config2 = lb2->lb_hash_config;
+ hash_c2 = vnet_buffer (p2)->ip.flow_hash =
+ ip4_compute_flow_hash (ip2, flow_hash_config2);
+ }
+ if (PREDICT_FALSE (lb3->lb_n_buckets > 1))
+ {
flow_hash_config3 = lb3->lb_hash_config;
- hash_c3 = vnet_buffer (p3)->ip.flow_hash =
- ip4_compute_flow_hash (ip3, flow_hash_config3);
- }
+ hash_c3 = vnet_buffer (p3)->ip.flow_hash =
+ ip4_compute_flow_hash (ip3, flow_hash_config3);
+ }
ASSERT (lb0->lb_n_buckets > 0);
ASSERT (is_pow2 (lb0->lb_n_buckets));
- ASSERT (lb1->lb_n_buckets > 0);
+ ASSERT (lb1->lb_n_buckets > 0);
ASSERT (is_pow2 (lb1->lb_n_buckets));
ASSERT (lb2->lb_n_buckets > 0);
ASSERT (is_pow2 (lb2->lb_n_buckets));
- ASSERT (lb3->lb_n_buckets > 0);
+ ASSERT (lb3->lb_n_buckets > 0);
ASSERT (is_pow2 (lb3->lb_n_buckets));
- dpo0 = load_balance_get_bucket_i(lb0,
- (hash_c0 &
- (lb0->lb_n_buckets_minus_1)));
- dpo1 = load_balance_get_bucket_i(lb1,
- (hash_c1 &
- (lb1->lb_n_buckets_minus_1)));
- dpo2 = load_balance_get_bucket_i(lb2,
- (hash_c2 &
- (lb2->lb_n_buckets_minus_1)));
- dpo3 = load_balance_get_bucket_i(lb3,
- (hash_c3 &
- (lb3->lb_n_buckets_minus_1)));
+ dpo0 = load_balance_get_bucket_i (lb0,
+ (hash_c0 &
+ (lb0->lb_n_buckets_minus_1)));
+ dpo1 = load_balance_get_bucket_i (lb1,
+ (hash_c1 &
+ (lb1->lb_n_buckets_minus_1)));
+ dpo2 = load_balance_get_bucket_i (lb2,
+ (hash_c2 &
+ (lb2->lb_n_buckets_minus_1)));
+ dpo3 = load_balance_get_bucket_i (lb3,
+ (hash_c3 &
+ (lb3->lb_n_buckets_minus_1)));
next0 = dpo0->dpoi_next_node;
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
@@ -302,41 +325,41 @@ ip4_lookup_inline (vlib_main_t * vm,
next3 = dpo3->dpoi_next_node;
vnet_buffer (p3)->ip.adj_index[VLIB_TX] = dpo3->dpoi_index;
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index0, 1,
- vlib_buffer_length_in_chain (vm, p0)
- + sizeof(ethernet_header_t));
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index1, 1,
- vlib_buffer_length_in_chain (vm, p1)
- + sizeof(ethernet_header_t));
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index2, 1,
- vlib_buffer_length_in_chain (vm, p2)
- + sizeof(ethernet_header_t));
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index3, 1,
- vlib_buffer_length_in_chain (vm, p3)
- + sizeof(ethernet_header_t));
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index0, 1,
+ vlib_buffer_length_in_chain (vm, p0)
+ + sizeof (ethernet_header_t));
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index1, 1,
+ vlib_buffer_length_in_chain (vm, p1)
+ + sizeof (ethernet_header_t));
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index2, 1,
+ vlib_buffer_length_in_chain (vm, p2)
+ + sizeof (ethernet_header_t));
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index3, 1,
+ vlib_buffer_length_in_chain (vm, p3)
+ + sizeof (ethernet_header_t));
vlib_validate_buffer_enqueue_x4 (vm, node, next,
to_next, n_left_to_next,
pi0, pi1, pi2, pi3,
- next0, next1, next2, next3);
- }
+ next0, next1, next2, next3);
+ }
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- __attribute__((unused)) tcp_header_t * tcp0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ __attribute__ ((unused)) tcp_header_t *tcp0;
ip_lookup_next_t next0;
const load_balance_t *lb0;
- ip4_fib_mtrie_t * mtrie0;
+ ip4_fib_mtrie_t *mtrie0;
ip4_fib_mtrie_leaf_t leaf0;
- ip4_address_t * dst_addr0;
- __attribute__((unused)) u32 pi0, fib_index0, is_tcp_udp0, lbi0;
- flow_hash_config_t flow_hash_config0;
+ ip4_address_t *dst_addr0;
+ __attribute__ ((unused)) u32 pi0, fib_index0, is_tcp_udp0, lbi0;
+ flow_hash_config_t flow_hash_config0;
const dpo_id_t *dpo0;
u32 hash_c0;
@@ -349,13 +372,16 @@ ip4_lookup_inline (vlib_main_t * vm,
dst_addr0 = &ip0->dst_address;
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
+ fib_index0 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index0 =
+ (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
- if (! lookup_for_responses_to_locally_received_packets)
+ if (!lookup_for_responses_to_locally_received_packets)
{
- mtrie0 = &ip4_fib_get( fib_index0)->mtrie;
+ mtrie0 = &ip4_fib_get (fib_index0)->mtrie;
leaf0 = IP4_FIB_MTRIE_LEAF_ROOT;
@@ -367,13 +393,13 @@ ip4_lookup_inline (vlib_main_t * vm,
is_tcp_udp0 = (ip0->protocol == IP_PROTOCOL_TCP
|| ip0->protocol == IP_PROTOCOL_UDP);
- if (! lookup_for_responses_to_locally_received_packets)
+ if (!lookup_for_responses_to_locally_received_packets)
leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1);
- if (! lookup_for_responses_to_locally_received_packets)
+ if (!lookup_for_responses_to_locally_received_packets)
leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2);
- if (! lookup_for_responses_to_locally_received_packets)
+ if (!lookup_for_responses_to_locally_received_packets)
leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 3);
if (lookup_for_responses_to_locally_received_packets)
@@ -381,35 +407,36 @@ ip4_lookup_inline (vlib_main_t * vm,
else
{
/* Handle default route. */
- leaf0 = (leaf0 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
+ leaf0 =
+ (leaf0 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
}
lb0 = load_balance_get (lbi0);
/* Use flow hash to compute multipath adjacency. */
- hash_c0 = vnet_buffer (p0)->ip.flow_hash = 0;
- if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
- {
+ hash_c0 = vnet_buffer (p0)->ip.flow_hash = 0;
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
flow_hash_config0 = lb0->lb_hash_config;
- hash_c0 = vnet_buffer (p0)->ip.flow_hash =
- ip4_compute_flow_hash (ip0, flow_hash_config0);
- }
+ hash_c0 = vnet_buffer (p0)->ip.flow_hash =
+ ip4_compute_flow_hash (ip0, flow_hash_config0);
+ }
ASSERT (lb0->lb_n_buckets > 0);
ASSERT (is_pow2 (lb0->lb_n_buckets));
- dpo0 = load_balance_get_bucket_i(lb0,
- (hash_c0 &
- (lb0->lb_n_buckets_minus_1)));
+ dpo0 = load_balance_get_bucket_i (lb0,
+ (hash_c0 &
+ (lb0->lb_n_buckets_minus_1)));
next0 = dpo0->dpoi_next_node;
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
from += 1;
to_next += 1;
@@ -421,8 +448,7 @@ ip4_lookup_inline (vlib_main_t * vm,
n_left_to_next += 1;
vlib_put_next_frame (vm, node, next, n_left_to_next);
next = next0;
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
to_next[0] = pi0;
to_next += 1;
n_left_to_next -= 1;
@@ -433,7 +459,7 @@ ip4_lookup_inline (vlib_main_t * vm,
}
if (node->flags & VLIB_NODE_FLAG_TRACE)
- ip4_forward_next_trace(vm, node, frame, VLIB_TX);
+ ip4_forward_next_trace (vm, node, frame, VLIB_TX);
return frame->n_vectors;
}
@@ -472,63 +498,57 @@ ip4_lookup_inline (vlib_main_t * vm,
*/
static uword
ip4_lookup (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip4_lookup_inline (vm, node, frame,
- /* lookup_for_responses_to_locally_received_packets */ 0);
+ /* lookup_for_responses_to_locally_received_packets */
+ 0);
}
-static u8 * format_ip4_lookup_trace (u8 * s, va_list * args);
-
-VLIB_REGISTER_NODE (ip4_lookup_node) = {
- .function = ip4_lookup,
- .name = "ip4-lookup",
- .vector_size = sizeof (u32),
+static u8 *format_ip4_lookup_trace (u8 * s, va_list * args);
- .format_trace = format_ip4_lookup_trace,
- .n_next_nodes = IP_LOOKUP_N_NEXT,
- .next_nodes = IP4_LOOKUP_NEXT_NODES,
-};
+VLIB_REGISTER_NODE (ip4_lookup_node) =
+{
+.function = ip4_lookup,.name = "ip4-lookup",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_lookup_trace,.n_next_nodes =
+ IP_LOOKUP_N_NEXT,.next_nodes = IP4_LOOKUP_NEXT_NODES,};
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_lookup_node, ip4_lookup)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_lookup_node, ip4_lookup);
always_inline uword
ip4_load_balance (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- vlib_combined_counter_main_t * cm = &load_balance_main.lbm_via_counters;
- u32 n_left_from, n_left_to_next, * from, * to_next;
+ vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
+ u32 n_left_from, n_left_to_next, *from, *to_next;
ip_lookup_next_t next;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next = node->cached_next_index;
if (node->flags & VLIB_NODE_FLAG_TRACE)
- ip4_forward_next_trace(vm, node, frame, VLIB_TX);
+ ip4_forward_next_trace (vm, node, frame, VLIB_TX);
while (n_left_from > 0)
{
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
- {
- ip_lookup_next_t next0, next1;
+ {
+ ip_lookup_next_t next0, next1;
const load_balance_t *lb0, *lb1;
- vlib_buffer_t * p0, *p1;
+ vlib_buffer_t *p0, *p1;
u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
const ip4_header_t *ip0, *ip1;
const dpo_id_t *dpo0, *dpo1;
- /* Prefetch next iteration. */
- {
- vlib_buffer_t * p2, * p3;
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -538,7 +558,7 @@ ip4_load_balance (vlib_main_t * vm,
CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
- }
+ }
pi0 = to_next[0] = from[0];
pi1 = to_next[1] = from[1];
@@ -556,43 +576,51 @@ ip4_load_balance (vlib_main_t * vm,
lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
- lb0 = load_balance_get(lbi0);
- lb1 = load_balance_get(lbi1);
-
- /*
- * this node is for via FIBs we can re-use the hash value from the
- * to node if present.
- * We don't want to use the same hash value at each level in the recursion
- * graph as that would lead to polarisation
- */
- hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
- hc1 = vnet_buffer (p1)->ip.flow_hash = 0;
-
- if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
- {
- if (PREDICT_TRUE (vnet_buffer(p0)->ip.flow_hash))
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = vnet_buffer(p0)->ip.flow_hash >> 1;
- }
- else
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = ip4_compute_flow_hash(ip0, hc0);
- }
- }
- if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
- {
- if (PREDICT_TRUE (vnet_buffer(p1)->ip.flow_hash))
- {
- hc1 = vnet_buffer(p1)->ip.flow_hash = vnet_buffer(p1)->ip.flow_hash >> 1;
- }
- else
- {
- hc1 = vnet_buffer(p1)->ip.flow_hash = ip4_compute_flow_hash(ip1, hc1);
- }
- }
-
- dpo0 = load_balance_get_bucket_i(lb0, hc0 & (lb0->lb_n_buckets_minus_1));
- dpo1 = load_balance_get_bucket_i(lb1, hc1 & (lb1->lb_n_buckets_minus_1));
+ lb0 = load_balance_get (lbi0);
+ lb1 = load_balance_get (lbi1);
+
+ /*
+ * this node is for via FIBs we can re-use the hash value from the
+ * to node if present.
+ * We don't want to use the same hash value at each level in the recursion
+ * graph as that would lead to polarisation
+ */
+ hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
+ hc1 = vnet_buffer (p1)->ip.flow_hash = 0;
+
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ vnet_buffer (p0)->ip.flow_hash >> 1;
+ }
+ else
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ ip4_compute_flow_hash (ip0, hc0);
+ }
+ }
+ if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
+ {
+ if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash))
+ {
+ hc1 = vnet_buffer (p1)->ip.flow_hash =
+ vnet_buffer (p1)->ip.flow_hash >> 1;
+ }
+ else
+ {
+ hc1 = vnet_buffer (p1)->ip.flow_hash =
+ ip4_compute_flow_hash (ip1, hc1);
+ }
+ }
+
+ dpo0 =
+ load_balance_get_bucket_i (lb0,
+ hc0 & (lb0->lb_n_buckets_minus_1));
+ dpo1 =
+ load_balance_get_bucket_i (lb1,
+ hc1 & (lb1->lb_n_buckets_minus_1));
next0 = dpo0->dpoi_next_node;
next1 = dpo1->dpoi_next_node;
@@ -601,22 +629,20 @@ ip4_load_balance (vlib_main_t * vm,
vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
vlib_increment_combined_counter
- (cm, cpu_index, lbi1, 1,
- vlib_buffer_length_in_chain (vm, p1));
+ (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
vlib_validate_buffer_enqueue_x2 (vm, node, next,
to_next, n_left_to_next,
pi0, pi1, next0, next1);
- }
+ }
while (n_left_from > 0 && n_left_to_next > 0)
{
ip_lookup_next_t next0;
const load_balance_t *lb0;
- vlib_buffer_t * p0;
+ vlib_buffer_t *p0;
u32 pi0, lbi0, hc0;
const ip4_header_t *ip0;
const dpo_id_t *dpo0;
@@ -633,29 +659,32 @@ ip4_load_balance (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
- lb0 = load_balance_get(lbi0);
+ lb0 = load_balance_get (lbi0);
- hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
- if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
- {
- if (PREDICT_TRUE (vnet_buffer(p0)->ip.flow_hash))
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = vnet_buffer(p0)->ip.flow_hash >> 1;
- }
- else
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = ip4_compute_flow_hash(ip0, hc0);
- }
- }
+ hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ vnet_buffer (p0)->ip.flow_hash >> 1;
+ }
+ else
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ ip4_compute_flow_hash (ip0, hc0);
+ }
+ }
- dpo0 = load_balance_get_bucket_i(lb0, hc0 & (lb0->lb_n_buckets_minus_1));
+ dpo0 =
+ load_balance_get_bucket_i (lb0,
+ hc0 & (lb0->lb_n_buckets_minus_1));
next0 = dpo0->dpoi_next_node;
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
vlib_validate_buffer_enqueue_x1 (vm, node, next,
to_next, n_left_to_next,
@@ -668,33 +697,33 @@ ip4_load_balance (vlib_main_t * vm,
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip4_load_balance_node) = {
- .function = ip4_load_balance,
- .name = "ip4-load-balance",
- .vector_size = sizeof (u32),
- .sibling_of = "ip4-lookup",
-
- .format_trace = format_ip4_lookup_trace,
-};
+VLIB_REGISTER_NODE (ip4_load_balance_node) =
+{
+.function = ip4_load_balance,.name = "ip4-load-balance",.vector_size =
+ sizeof (u32),.sibling_of = "ip4-lookup",.format_trace =
+ format_ip4_lookup_trace,};
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_load_balance_node, ip4_load_balance)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_load_balance_node, ip4_load_balance);
/* get first interface address */
ip4_address_t *
ip4_interface_first_address (ip4_main_t * im, u32 sw_if_index,
- ip_interface_address_t ** result_ia)
+ ip_interface_address_t ** result_ia)
{
- ip_lookup_main_t * lm = &im->lookup_main;
- ip_interface_address_t * ia = 0;
- ip4_address_t * result = 0;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip_interface_address_t *ia = 0;
+ ip4_address_t *result = 0;
foreach_ip_interface_address (lm, ia, sw_if_index,
- 1 /* honor unnumbered */,
- ({
- ip4_address_t * a = ip_interface_address_get_address (lm, ia);
- result = a;
- break;
- }));
+ 1 /* honor unnumbered */ ,
+ (
+ {
+ ip4_address_t * a =
+ ip_interface_address_get_address (lm, ia);
+ result = a;
+ break;
+ }
+ ));
if (result_ia)
*result_ia = result ? ia : 0;
return result;
@@ -705,104 +734,79 @@ ip4_add_interface_routes (u32 sw_if_index,
ip4_main_t * im, u32 fib_index,
ip_interface_address_t * a)
{
- ip_lookup_main_t * lm = &im->lookup_main;
- ip4_address_t * address = ip_interface_address_get_address (lm, a);
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip4_address_t *address = ip_interface_address_get_address (lm, a);
fib_prefix_t pfx = {
- .fp_len = a->address_length,
- .fp_proto = FIB_PROTOCOL_IP4,
- .fp_addr.ip4 = *address,
+ .fp_len = a->address_length,
+ .fp_proto = FIB_PROTOCOL_IP4,
+ .fp_addr.ip4 = *address,
};
a->neighbor_probe_adj_index = ~0;
if (pfx.fp_len < 32)
- {
+ {
fib_node_index_t fei;
- fei = fib_table_entry_update_one_path(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE,
- (FIB_ENTRY_FLAG_CONNECTED |
- FIB_ENTRY_FLAG_ATTACHED),
- FIB_PROTOCOL_IP4,
- NULL, /* No next-hop address */
- sw_if_index,
- ~0, // invalid FIB index
- 1,
- NULL, // no out-label stack
- FIB_ROUTE_PATH_FLAG_NONE);
- a->neighbor_probe_adj_index = fib_entry_get_adj(fei);
- }
+ fei = fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_ATTACHED), FIB_PROTOCOL_IP4, NULL, /* No next-hop address */
+ sw_if_index, ~0, // invalid FIB index
+ 1, NULL, // no out-label stack
+ FIB_ROUTE_PATH_FLAG_NONE);
+ a->neighbor_probe_adj_index = fib_entry_get_adj (fei);
+ }
pfx.fp_len = 32;
if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
- {
+ {
u32 classify_table_index =
- lm->classify_table_index_by_sw_if_index [sw_if_index];
- if (classify_table_index != (u32) ~0)
- {
- dpo_id_t dpo = DPO_INVALID;
-
- dpo_set(&dpo,
- DPO_CLASSIFY,
- DPO_PROTO_IP4,
- classify_dpo_create(DPO_PROTO_IP4,
- classify_table_index));
-
- fib_table_entry_special_dpo_add(fib_index,
- &pfx,
- FIB_SOURCE_CLASSIFY,
- FIB_ENTRY_FLAG_NONE,
- &dpo);
- dpo_reset(&dpo);
- }
- }
+ lm->classify_table_index_by_sw_if_index[sw_if_index];
+ if (classify_table_index != (u32) ~ 0)
+ {
+ dpo_id_t dpo = DPO_INVALID;
+
+ dpo_set (&dpo,
+ DPO_CLASSIFY,
+ DPO_PROTO_IP4,
+ classify_dpo_create (DPO_PROTO_IP4, classify_table_index));
+
+ fib_table_entry_special_dpo_add (fib_index,
+ &pfx,
+ FIB_SOURCE_CLASSIFY,
+ FIB_ENTRY_FLAG_NONE, &dpo);
+ dpo_reset (&dpo);
+ }
+ }
- fib_table_entry_update_one_path(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE,
- (FIB_ENTRY_FLAG_CONNECTED |
- FIB_ENTRY_FLAG_LOCAL),
- FIB_PROTOCOL_IP4,
- &pfx.fp_addr,
- sw_if_index,
- ~0, // invalid FIB index
- 1,
- NULL, // no out-label stack
- FIB_ROUTE_PATH_FLAG_NONE);
+ fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL), FIB_PROTOCOL_IP4, &pfx.fp_addr, sw_if_index, ~0, // invalid FIB index
+ 1, NULL, // no out-label stack
+ FIB_ROUTE_PATH_FLAG_NONE);
}
static void
ip4_del_interface_routes (ip4_main_t * im,
u32 fib_index,
- ip4_address_t * address,
- u32 address_length)
+ ip4_address_t * address, u32 address_length)
{
- fib_prefix_t pfx = {
- .fp_len = address_length,
- .fp_proto = FIB_PROTOCOL_IP4,
- .fp_addr.ip4 = *address,
- };
+ fib_prefix_t pfx = {
+ .fp_len = address_length,
+ .fp_proto = FIB_PROTOCOL_IP4,
+ .fp_addr.ip4 = *address,
+ };
- if (pfx.fp_len < 32)
+ if (pfx.fp_len < 32)
{
- fib_table_entry_delete(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE);
+ fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
}
- pfx.fp_len = 32;
- fib_table_entry_delete(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE);
+ pfx.fp_len = 32;
+ fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
}
void
-ip4_sw_interface_enable_disable (u32 sw_if_index,
- u32 is_enable)
+ip4_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
{
- ip4_main_t * im = &ip4_main;
+ ip4_main_t *im = &ip4_main;
vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
@@ -812,19 +816,19 @@ ip4_sw_interface_enable_disable (u32 sw_if_index,
if (is_enable)
{
if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
- return;
+ return;
}
else
{
- ASSERT(im->ip_enabled_by_sw_if_index[sw_if_index] > 0);
+ ASSERT (im->ip_enabled_by_sw_if_index[sw_if_index] > 0);
if (0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
- return;
+ return;
}
vnet_feature_enable_disable ("ip4-unicast", "ip4-lookup", sw_if_index,
is_enable, 0, 0);
- vnet_feature_enable_disable ("ip4-multicast", "ip4-lookup-multicast", sw_if_index,
- is_enable, 0, 0);
+ vnet_feature_enable_disable ("ip4-multicast", "ip4-lookup-multicast",
+ sw_if_index, is_enable, 0, 0);
}
@@ -832,15 +836,14 @@ static clib_error_t *
ip4_add_del_interface_address_internal (vlib_main_t * vm,
u32 sw_if_index,
ip4_address_t * address,
- u32 address_length,
- u32 is_del)
+ u32 address_length, u32 is_del)
{
- vnet_main_t * vnm = vnet_get_main();
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ clib_error_t *error = 0;
u32 if_address_index, elts_before;
- ip4_address_fib_t ip4_af, * addr_fib = 0;
+ ip4_address_fib_t ip4_af, *addr_fib = 0;
vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
ip4_addr_fib_init (&ip4_af, address,
@@ -852,60 +855,64 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm,
* subnets on interfaces. Easy fix - disallow overlapping subnets, like
* most routers do.
*/
- if (! is_del)
+ if (!is_del)
{
/* When adding an address check that it does not conflict
- with an existing address. */
- ip_interface_address_t * ia;
+ with an existing address. */
+ ip_interface_address_t *ia;
foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
- 0 /* honor unnumbered */,
- ({
- ip4_address_t * x = ip_interface_address_get_address (&im->lookup_main, ia);
-
- if (ip4_destination_matches_route (im, address, x, ia->address_length)
- || ip4_destination_matches_route (im, x, address, address_length))
- return clib_error_create ("failed to add %U which conflicts with %U for interface %U",
- format_ip4_address_and_length, address, address_length,
- format_ip4_address_and_length, x, ia->address_length,
- format_vnet_sw_if_index_name, vnm, sw_if_index);
- }));
+ 0 /* honor unnumbered */ ,
+ (
+ {
+ ip4_address_t * x =
+ ip_interface_address_get_address
+ (&im->lookup_main, ia);
+ if (ip4_destination_matches_route
+ (im, address, x, ia->address_length)
+ ||
+ ip4_destination_matches_route (im,
+ x,
+ address,
+ address_length))
+ return
+ clib_error_create
+ ("failed to add %U which conflicts with %U for interface %U",
+ format_ip4_address_and_length, address,
+ address_length,
+ format_ip4_address_and_length, x,
+ ia->address_length,
+ format_vnet_sw_if_index_name, vnm,
+ sw_if_index);}
+ ));
}
elts_before = pool_elts (lm->if_address_pool);
error = ip_interface_address_add_del
- (lm,
- sw_if_index,
- addr_fib,
- address_length,
- is_del,
- &if_address_index);
+ (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index);
if (error)
goto done;
- ip4_sw_interface_enable_disable(sw_if_index, !is_del);
+ ip4_sw_interface_enable_disable (sw_if_index, !is_del);
if (is_del)
- ip4_del_interface_routes (im, ip4_af.fib_index, address,
- address_length);
+ ip4_del_interface_routes (im, ip4_af.fib_index, address, address_length);
else
- ip4_add_interface_routes (sw_if_index,
- im, ip4_af.fib_index,
- pool_elt_at_index
- (lm->if_address_pool, if_address_index));
+ ip4_add_interface_routes (sw_if_index,
+ im, ip4_af.fib_index,
+ pool_elt_at_index
+ (lm->if_address_pool, if_address_index));
/* If pool did not grow/shrink: add duplicate address. */
if (elts_before != pool_elts (lm->if_address_pool))
{
- ip4_add_del_interface_address_callback_t * cb;
+ ip4_add_del_interface_address_callback_t *cb;
vec_foreach (cb, im->add_del_interface_address_callbacks)
cb->function (im, cb->function_opaque, sw_if_index,
- address, address_length,
- if_address_index,
- is_del);
+ address, address_length, if_address_index, is_del);
}
- done:
+done:
vec_free (addr_fib);
return error;
}
@@ -916,145 +923,161 @@ ip4_add_del_interface_address (vlib_main_t * vm, u32 sw_if_index,
u32 is_del)
{
return ip4_add_del_interface_address_internal
- (vm, sw_if_index, address, address_length,
- is_del);
+ (vm, sw_if_index, address, address_length, is_del);
}
/* Built-in ip4 unicast rx feature path definition */
+/* *INDENT-OFF* */
VNET_FEATURE_ARC_INIT (ip4_unicast, static) =
{
- .arc_name = "ip4-unicast",
- .start_nodes = VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"),
- .arc_index_ptr = &ip4_main.lookup_main.ucast_feature_arc_index,
-};
+ .arc_name = "ip4-unicast",
+ .start_nodes =
+ VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"),
+ .arc_index_ptr =
+ &ip4_main.lookup_main.ucast_feature_arc_index,};
-VNET_FEATURE_INIT (ip4_flow_classify, static) = {
+VNET_FEATURE_INIT (ip4_flow_classify, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-flow-classify",
.runs_before = VNET_FEATURES ("ip4-inacl"),
};
-VNET_FEATURE_INIT (ip4_inacl, static) = {
+VNET_FEATURE_INIT (ip4_inacl, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-inacl",
.runs_before = VNET_FEATURES ("ip4-source-check-via-rx"),
};
-VNET_FEATURE_INIT (ip4_source_check_1, static) = {
+VNET_FEATURE_INIT (ip4_source_check_1, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-source-check-via-rx",
.runs_before = VNET_FEATURES ("ip4-source-check-via-any"),
};
-VNET_FEATURE_INIT (ip4_source_check_2, static) = {
+VNET_FEATURE_INIT (ip4_source_check_2, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-source-check-via-any",
.runs_before = VNET_FEATURES ("ip4-policer-classify"),
};
-VNET_FEATURE_INIT (ip4_source_and_port_range_check_rx, static) = {
+VNET_FEATURE_INIT (ip4_source_and_port_range_check_rx, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-source-and-port-range-check-rx",
.runs_before = VNET_FEATURES ("ip4-policer-classify"),
};
-VNET_FEATURE_INIT (ip4_policer_classify, static) = {
+VNET_FEATURE_INIT (ip4_policer_classify, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-policer-classify",
.runs_before = VNET_FEATURES ("ipsec-input-ip4"),
};
-VNET_FEATURE_INIT (ip4_ipsec, static) = {
+VNET_FEATURE_INIT (ip4_ipsec, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ipsec-input-ip4",
.runs_before = VNET_FEATURES ("vpath-input-ip4"),
};
-VNET_FEATURE_INIT (ip4_vpath, static) = {
+VNET_FEATURE_INIT (ip4_vpath, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "vpath-input-ip4",
.runs_before = VNET_FEATURES ("ip4-vxlan-bypass"),
};
-VNET_FEATURE_INIT (ip4_vxlan_bypass, static) = {
+VNET_FEATURE_INIT (ip4_vxlan_bypass, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-vxlan-bypass",
.runs_before = VNET_FEATURES ("ip4-lookup"),
};
-VNET_FEATURE_INIT (ip4_lookup, static) = {
+VNET_FEATURE_INIT (ip4_lookup, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-lookup",
.runs_before = VNET_FEATURES ("ip4-drop"),
};
-VNET_FEATURE_INIT (ip4_drop, static) = {
+VNET_FEATURE_INIT (ip4_drop, static) =
+{
.arc_name = "ip4-unicast",
.node_name = "ip4-drop",
- .runs_before = 0, /* not before any other features */
+ .runs_before = 0, /* not before any other features */
};
/* Built-in ip4 multicast rx feature path definition */
VNET_FEATURE_ARC_INIT (ip4_multicast, static) =
{
- .arc_name = "ip4-multicast",
+ .arc_name = "ip4-multicast",
.start_nodes = VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"),
.arc_index_ptr = &ip4_main.lookup_main.mcast_feature_arc_index,
};
-VNET_FEATURE_INIT (ip4_vpath_mc, static) = {
+VNET_FEATURE_INIT (ip4_vpath_mc, static) =
+{
.arc_name = "ip4-multicast",
.node_name = "vpath-input-ip4",
.runs_before = VNET_FEATURES ("ip4-lookup-multicast"),
};
-VNET_FEATURE_INIT (ip4_lookup_mc, static) = {
+VNET_FEATURE_INIT (ip4_lookup_mc, static) =
+{
.arc_name = "ip4-multicast",
.node_name = "ip4-lookup-multicast",
.runs_before = VNET_FEATURES ("ip4-drop"),
};
-VNET_FEATURE_INIT (ip4_mc_drop, static) = {
+VNET_FEATURE_INIT (ip4_mc_drop, static) =
+{
.arc_name = "ip4-multicast",
.node_name = "ip4-drop",
- .runs_before = 0, /* last feature */
+ .runs_before = 0, /* last feature */
};
/* Source and port-range check ip4 tx feature path definition */
VNET_FEATURE_ARC_INIT (ip4_output, static) =
{
- .arc_name = "ip4-output",
+ .arc_name = "ip4-output",
.start_nodes = VNET_FEATURES ("ip4-rewrite", "ip4-midchain"),
.arc_index_ptr = &ip4_main.lookup_main.output_feature_arc_index,
};
-VNET_FEATURE_INIT (ip4_source_and_port_range_check_tx, static) = {
+VNET_FEATURE_INIT (ip4_source_and_port_range_check_tx, static) =
+{
.arc_name = "ip4-output",
.node_name = "ip4-source-and-port-range-check-tx",
.runs_before = VNET_FEATURES ("ipsec-output-ip4"),
};
-VNET_FEATURE_INIT (ip4_ipsec_output, static) = {
+VNET_FEATURE_INIT (ip4_ipsec_output, static) =
+{
.arc_name = "ip4-output",
.node_name = "ipsec-output-ip4",
.runs_before = VNET_FEATURES ("interface-output"),
};
/* Built-in ip4 tx feature path definition */
-VNET_FEATURE_INIT (ip4_interface_output, static) = {
+VNET_FEATURE_INIT (ip4_interface_output, static) =
+{
.arc_name = "ip4-output",
.node_name = "interface-output",
- .runs_before = 0, /* not before any other features */
+ .runs_before = 0, /* not before any other features */
};
-
+/* *INDENT-ON* */
static clib_error_t *
-ip4_sw_interface_add_del (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 is_add)
+ip4_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
{
- ip4_main_t * im = &ip4_main;
+ ip4_main_t *im = &ip4_main;
/* Fill in lookup tables with default table (0). */
vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
@@ -1079,8 +1102,8 @@ ip4_main_t ip4_main;
clib_error_t *
ip4_lookup_init (vlib_main_t * vm)
{
- ip4_main_t * im = &ip4_main;
- clib_error_t * error;
+ ip4_main_t *im = &ip4_main;
+ clib_error_t *error;
uword i;
if ((error = vlib_call_init_function (vm, vnet_feature_init)))
@@ -1100,10 +1123,10 @@ ip4_lookup_init (vlib_main_t * vm)
ip_lookup_init (&im->lookup_main, /* is_ip6 */ 0);
/* Create FIB with index 0 and table id of 0. */
- fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4, 0);
+ fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, 0);
{
- pg_node_t * pn;
+ pg_node_t *pn;
pn = pg_get_node (ip4_lookup_node.index);
pn->unformat_edit = unformat_pg_ip4_header;
}
@@ -1114,7 +1137,8 @@ ip4_lookup_init (vlib_main_t * vm)
memset (&h, 0, sizeof (h));
/* Set target ethernet address to all zeros. */
- memset (h.ip4_over_ethernet[1].ethernet, 0, sizeof (h.ip4_over_ethernet[1].ethernet));
+ memset (h.ip4_over_ethernet[1].ethernet, 0,
+ sizeof (h.ip4_over_ethernet[1].ethernet));
#define _16(f,v) h.f = clib_host_to_net_u16 (v);
#define _8(f,v) h.f = v;
@@ -1126,8 +1150,7 @@ ip4_lookup_init (vlib_main_t * vm)
#undef _16
#undef _8
- vlib_packet_template_init (vm,
- &im->ip4_arp_request_packet_template,
+ vlib_packet_template_init (vm, &im->ip4_arp_request_packet_template,
/* data */ &h,
sizeof (h),
/* alloc chunk size */ 8,
@@ -1139,21 +1162,24 @@ ip4_lookup_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (ip4_lookup_init);
-typedef struct {
+typedef struct
+{
/* Adjacency taken. */
u32 dpo_index;
u32 flow_hash;
u32 fib_index;
/* Packet data, possibly *after* rewrite. */
- u8 packet_data[64 - 1*sizeof(u32)];
-} ip4_forward_next_trace_t;
+ u8 packet_data[64 - 1 * sizeof (u32)];
+}
+ip4_forward_next_trace_t;
-u8 * format_ip4_forward_next_trace (u8 * s, va_list * args)
+u8 *
+format_ip4_forward_next_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 *);
- ip4_forward_next_trace_t * t = va_arg (*args, ip4_forward_next_trace_t *);
+ ip4_forward_next_trace_t *t = va_arg (*args, ip4_forward_next_trace_t *);
uword indent = format_get_indent (s);
s = format (s, "%U%U",
format_white_space, indent,
@@ -1161,38 +1187,38 @@ u8 * format_ip4_forward_next_trace (u8 * s, va_list * args)
return s;
}
-static u8 * format_ip4_lookup_trace (u8 * s, va_list * args)
+static u8 *
+format_ip4_lookup_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 *);
- ip4_forward_next_trace_t * t = va_arg (*args, ip4_forward_next_trace_t *);
+ ip4_forward_next_trace_t *t = va_arg (*args, ip4_forward_next_trace_t *);
uword indent = format_get_indent (s);
s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
- t->fib_index, t->dpo_index, t->flow_hash);
+ t->fib_index, t->dpo_index, t->flow_hash);
s = format (s, "\n%U%U",
- format_white_space, indent,
- format_ip4_header, t->packet_data, sizeof (t->packet_data));
+ format_white_space, indent,
+ format_ip4_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-static u8 * format_ip4_rewrite_trace (u8 * s, va_list * args)
+static u8 *
+format_ip4_rewrite_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 *);
- ip4_forward_next_trace_t * t = va_arg (*args, ip4_forward_next_trace_t *);
- vnet_main_t * vnm = vnet_get_main();
+ ip4_forward_next_trace_t *t = va_arg (*args, ip4_forward_next_trace_t *);
+ vnet_main_t *vnm = vnet_get_main ();
uword indent = format_get_indent (s);
s = format (s, "tx_sw_if_index %d dpo-idx %d : %U flow hash: 0x%08x",
- t->fib_index, t->dpo_index, format_ip_adjacency,
- t->dpo_index, FORMAT_IP_ADJACENCY_NONE,
- t->flow_hash);
+ t->fib_index, t->dpo_index, format_ip_adjacency,
+ t->dpo_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
s = format (s, "\n%U%U",
- format_white_space, indent,
- format_ip_adjacency_packet_data,
- vnm, t->dpo_index,
- t->packet_data, sizeof (t->packet_data));
+ format_white_space, indent,
+ format_ip_adjacency_packet_data,
+ vnm, t->dpo_index, t->packet_data, sizeof (t->packet_data));
return s;
}
@@ -1200,11 +1226,10 @@ static u8 * format_ip4_rewrite_trace (u8 * s, va_list * args)
void
ip4_forward_next_trace (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- vlib_rx_or_tx_t which_adj_index)
+ vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
{
- u32 * from, n_left;
- ip4_main_t * im = &ip4_main;
+ u32 *from, n_left;
+ ip4_main_t *im = &ip4_main;
n_left = frame->n_vectors;
from = vlib_frame_vector_args (frame);
@@ -1212,8 +1237,8 @@ ip4_forward_next_trace (vlib_main_t * vm,
while (n_left >= 4)
{
u32 bi0, bi1;
- vlib_buffer_t * b0, * b1;
- ip4_forward_next_trace_t * t0, * t1;
+ vlib_buffer_t *b0, *b1;
+ ip4_forward_next_trace_t *t0, *t1;
/* Prefetch next iteration. */
vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
@@ -1230,27 +1255,28 @@ ip4_forward_next_trace (vlib_main_t * vm,
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->dpo_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
- t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
- vnet_buffer(b0)->sw_if_index[VLIB_TX] :
- vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+ t0->fib_index =
+ (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
+ (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (b0)->sw_if_index[VLIB_RX]);
clib_memcpy (t0->packet_data,
- vlib_buffer_get_current (b0),
- sizeof (t0->packet_data));
+ vlib_buffer_get_current (b0),
+ sizeof (t0->packet_data));
}
if (b1->flags & VLIB_BUFFER_IS_TRACED)
{
t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
t1->dpo_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
- t1->fib_index = (vnet_buffer(b1)->sw_if_index[VLIB_TX] != (u32)~0) ?
- vnet_buffer(b1)->sw_if_index[VLIB_TX] :
- vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(b1)->sw_if_index[VLIB_RX]);
- clib_memcpy (t1->packet_data,
- vlib_buffer_get_current (b1),
- sizeof (t1->packet_data));
+ t1->fib_index =
+ (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
+ (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (b1)->sw_if_index[VLIB_RX]);
+ clib_memcpy (t1->packet_data, vlib_buffer_get_current (b1),
+ sizeof (t1->packet_data));
}
from += 2;
n_left -= 2;
@@ -1259,8 +1285,8 @@ ip4_forward_next_trace (vlib_main_t * vm,
while (n_left >= 1)
{
u32 bi0;
- vlib_buffer_t * b0;
- ip4_forward_next_trace_t * t0;
+ vlib_buffer_t *b0;
+ ip4_forward_next_trace_t *t0;
bi0 = from[0];
@@ -1271,13 +1297,13 @@ ip4_forward_next_trace (vlib_main_t * vm,
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->dpo_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
- t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
- vnet_buffer(b0)->sw_if_index[VLIB_TX] :
- vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(b0)->sw_if_index[VLIB_RX]);
- clib_memcpy (t0->packet_data,
- vlib_buffer_get_current (b0),
- sizeof (t0->packet_data));
+ t0->fib_index =
+ (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
+ (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (b0)->sw_if_index[VLIB_RX]);
+ clib_memcpy (t0->packet_data, vlib_buffer_get_current (b0),
+ sizeof (t0->packet_data));
}
from += 1;
n_left -= 1;
@@ -1287,19 +1313,16 @@ ip4_forward_next_trace (vlib_main_t * vm,
static uword
ip4_drop_or_punt (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- ip4_error_t error_code)
+ vlib_frame_t * frame, ip4_error_t error_code)
{
- u32 * buffers = vlib_frame_vector_args (frame);
+ u32 *buffers = vlib_frame_vector_args (frame);
uword n_packets = frame->n_vectors;
- vlib_error_drop_buffers (vm, node,
- buffers,
+ vlib_error_drop_buffers (vm, node, buffers,
/* stride */ 1,
n_packets,
/* next */ 0,
- ip4_input_node.index,
- error_code);
+ ip4_input_node.index, error_code);
if (node->flags & VLIB_NODE_FLAG_TRACE)
ip4_forward_next_trace (vm, node, frame, VLIB_TX);
@@ -1308,46 +1331,38 @@ ip4_drop_or_punt (vlib_main_t * vm,
}
static uword
-ip4_drop (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
-{ return ip4_drop_or_punt (vm, node, frame, IP4_ERROR_ADJACENCY_DROP); }
+ip4_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return ip4_drop_or_punt (vm, node, frame, IP4_ERROR_ADJACENCY_DROP);
+}
static uword
-ip4_punt (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
-{ return ip4_drop_or_punt (vm, node, frame, IP4_ERROR_ADJACENCY_PUNT); }
-
-VLIB_REGISTER_NODE (ip4_drop_node,static) = {
- .function = ip4_drop,
- .name = "ip4-drop",
- .vector_size = sizeof (u32),
-
- .format_trace = format_ip4_forward_next_trace,
-
- .n_next_nodes = 1,
- .next_nodes = {
- [0] = "error-drop",
- },
-};
-
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_drop_node, ip4_drop)
+ip4_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return ip4_drop_or_punt (vm, node, frame, IP4_ERROR_ADJACENCY_PUNT);
+}
-VLIB_REGISTER_NODE (ip4_punt_node,static) = {
- .function = ip4_punt,
- .name = "ip4-punt",
- .vector_size = sizeof (u32),
+VLIB_REGISTER_NODE (ip4_drop_node, static) =
+{
+ .function = ip4_drop,.name = "ip4-drop",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.n_next_nodes =
+ 1,.next_nodes =
+ {
+ [0] = "error-drop",}
+,};
- .format_trace = format_ip4_forward_next_trace,
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_drop_node, ip4_drop);
- .n_next_nodes = 1,
- .next_nodes = {
- [0] = "error-punt",
- },
-};
+VLIB_REGISTER_NODE (ip4_punt_node, static) =
+{
+ .function = ip4_punt,.name = "ip4-punt",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.n_next_nodes =
+ 1,.next_nodes =
+ {
+ [0] = "error-punt",}
+,};
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_punt_node, ip4_punt)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_punt_node, ip4_punt);
/* Compute TCP/UDP/ICMP4 checksum in software. */
u16
@@ -1358,25 +1373,35 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
u32 ip_header_length, payload_length_host_byte_order;
u32 n_this_buffer, n_bytes_left;
u16 sum16;
- void * data_this_buffer;
+ void *data_this_buffer;
/* Initialize checksum with ip header. */
ip_header_length = ip4_header_bytes (ip0);
- payload_length_host_byte_order = clib_net_to_host_u16 (ip0->length) - ip_header_length;
- sum0 = clib_host_to_net_u32 (payload_length_host_byte_order + (ip0->protocol << 16));
+ payload_length_host_byte_order =
+ clib_net_to_host_u16 (ip0->length) - ip_header_length;
+ sum0 =
+ clib_host_to_net_u32 (payload_length_host_byte_order +
+ (ip0->protocol << 16));
if (BITS (uword) == 32)
{
- sum0 = ip_csum_with_carry (sum0, clib_mem_unaligned (&ip0->src_address, u32));
- sum0 = ip_csum_with_carry (sum0, clib_mem_unaligned (&ip0->dst_address, u32));
+ sum0 =
+ ip_csum_with_carry (sum0,
+ clib_mem_unaligned (&ip0->src_address, u32));
+ sum0 =
+ ip_csum_with_carry (sum0,
+ clib_mem_unaligned (&ip0->dst_address, u32));
}
else
- sum0 = ip_csum_with_carry (sum0, clib_mem_unaligned (&ip0->src_address, u64));
+ sum0 =
+ ip_csum_with_carry (sum0, clib_mem_unaligned (&ip0->src_address, u64));
n_bytes_left = n_this_buffer = payload_length_host_byte_order;
data_this_buffer = (void *) ip0 + ip_header_length;
if (n_this_buffer + ip_header_length > p0->current_length)
- n_this_buffer = p0->current_length > ip_header_length ? p0->current_length - ip_header_length : 0;
+ n_this_buffer =
+ p0->current_length >
+ ip_header_length ? p0->current_length - ip_header_length : 0;
while (1)
{
sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
@@ -1390,7 +1415,7 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
n_this_buffer = p0->current_length;
}
- sum16 = ~ ip_csum_fold (sum0);
+ sum16 = ~ip_csum_fold (sum0);
return sum16;
}
@@ -1398,8 +1423,8 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
u32
ip4_tcp_udp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
{
- ip4_header_t * ip0 = vlib_buffer_get_current (p0);
- udp_header_t * udp0;
+ ip4_header_t *ip0 = vlib_buffer_get_current (p0);
+ udp_header_t *udp0;
u16 sum16;
ASSERT (ip0->protocol == IP_PROTOCOL_TCP
@@ -1422,15 +1447,14 @@ ip4_tcp_udp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
}
static uword
-ip4_local (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip4_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
ip_local_next_t next_index;
- u32 * from, * to_next, n_left_from, n_left_to_next;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip4_input_node.index);
+ u32 *from, *to_next, n_left_from, n_left_to_next;
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip4_input_node.index);
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -1444,27 +1468,27 @@ ip4_local (vlib_main_t * vm,
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
- {
- vlib_buffer_t * p0, * p1;
- ip4_header_t * ip0, * ip1;
- udp_header_t * udp0, * udp1;
- ip4_fib_mtrie_t * mtrie0, * mtrie1;
- ip4_fib_mtrie_leaf_t leaf0, leaf1;
- const dpo_id_t *dpo0, *dpo1;
- const load_balance_t *lb0, *lb1;
- u32 pi0, ip_len0, udp_len0, flags0, next0, fib_index0, lbi0;
- u32 pi1, ip_len1, udp_len1, flags1, next1, fib_index1, lbi1;
- i32 len_diff0, len_diff1;
- u8 error0, is_udp0, is_tcp_udp0, good_tcp_udp0, proto0;
- u8 error1, is_udp1, is_tcp_udp1, good_tcp_udp1, proto1;
- u8 enqueue_code;
-
- pi0 = to_next[0] = from[0];
- pi1 = to_next[1] = from[1];
- from += 2;
- n_left_from -= 2;
- to_next += 2;
- n_left_to_next -= 2;
+ {
+ vlib_buffer_t *p0, *p1;
+ ip4_header_t *ip0, *ip1;
+ udp_header_t *udp0, *udp1;
+ ip4_fib_mtrie_t *mtrie0, *mtrie1;
+ ip4_fib_mtrie_leaf_t leaf0, leaf1;
+ const dpo_id_t *dpo0, *dpo1;
+ const load_balance_t *lb0, *lb1;
+ u32 pi0, ip_len0, udp_len0, flags0, next0, fib_index0, lbi0;
+ u32 pi1, ip_len1, udp_len1, flags1, next1, fib_index1, lbi1;
+ i32 len_diff0, len_diff1;
+ u8 error0, is_udp0, is_tcp_udp0, good_tcp_udp0, proto0;
+ u8 error1, is_udp1, is_tcp_udp1, good_tcp_udp1, proto1;
+ u8 enqueue_code;
+
+ pi0 = to_next[0] = from[0];
+ pi1 = to_next[1] = from[1];
+ from += 2;
+ n_left_from -= 2;
+ to_next += 2;
+ n_left_to_next -= 2;
p0 = vlib_get_buffer (vm, pi0);
p1 = vlib_get_buffer (vm, pi1);
@@ -1472,26 +1496,28 @@ ip4_local (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
ip1 = vlib_buffer_get_current (p1);
- vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data;
- vnet_buffer (p1)->ip.start_of_ip_header = p1->current_data;
+ vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data;
+ vnet_buffer (p1)->ip.start_of_ip_header = p1->current_data;
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index1 = vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(p1)->sw_if_index[VLIB_RX]);
+ fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index1 = vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p1)->sw_if_index[VLIB_RX]);
mtrie0 = &ip4_fib_get (fib_index0)->mtrie;
mtrie1 = &ip4_fib_get (fib_index1)->mtrie;
leaf0 = leaf1 = IP4_FIB_MTRIE_LEAF_ROOT;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 0);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 0);
/* Treat IP frag packets as "experimental" protocol for now
until support of IP frag reassembly is implemented */
- proto0 = ip4_is_fragment(ip0) ? 0xfe : ip0->protocol;
- proto1 = ip4_is_fragment(ip1) ? 0xfe : ip1->protocol;
+ proto0 = ip4_is_fragment (ip0) ? 0xfe : ip0->protocol;
+ proto1 = ip4_is_fragment (ip1) ? 0xfe : ip1->protocol;
is_udp0 = proto0 == IP_PROTOCOL_UDP;
is_udp1 = proto1 == IP_PROTOCOL_UDP;
is_tcp_udp0 = is_udp0 || proto0 == IP_PROTOCOL_TCP;
@@ -1510,8 +1536,10 @@ ip4_local (vlib_main_t * vm,
good_tcp_udp0 |= is_udp0 && udp0->checksum == 0;
good_tcp_udp1 |= is_udp1 && udp1->checksum == 0;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 1);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 1);
/* Verify UDP length. */
ip_len0 = clib_net_to_host_u16 (ip0->length);
@@ -1525,13 +1553,13 @@ ip4_local (vlib_main_t * vm,
len_diff0 = is_udp0 ? len_diff0 : 0;
len_diff1 = is_udp1 ? len_diff1 : 0;
- if (PREDICT_FALSE (! (is_tcp_udp0 & is_tcp_udp1
- & good_tcp_udp0 & good_tcp_udp1)))
+ if (PREDICT_FALSE (!(is_tcp_udp0 & is_tcp_udp1
+ & good_tcp_udp0 & good_tcp_udp1)))
{
if (is_tcp_udp0)
{
if (is_tcp_udp0
- && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED))
+ && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED))
flags0 = ip4_tcp_udp_validate_checksum (vm, p0);
good_tcp_udp0 =
(flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
@@ -1540,7 +1568,7 @@ ip4_local (vlib_main_t * vm,
if (is_tcp_udp1)
{
if (is_tcp_udp1
- && ! (flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED))
+ && !(flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED))
flags1 = ip4_tcp_udp_validate_checksum (vm, p1);
good_tcp_udp1 =
(flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
@@ -1551,8 +1579,10 @@ ip4_local (vlib_main_t * vm,
good_tcp_udp0 &= len_diff0 >= 0;
good_tcp_udp1 &= len_diff1 >= 0;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 2);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 2);
error0 = error1 = IP4_ERROR_UNKNOWN_PROTOCOL;
@@ -1560,68 +1590,72 @@ ip4_local (vlib_main_t * vm,
error1 = len_diff1 < 0 ? IP4_ERROR_UDP_LENGTH : error1;
ASSERT (IP4_ERROR_TCP_CHECKSUM + 1 == IP4_ERROR_UDP_CHECKSUM);
- error0 = (is_tcp_udp0 && ! good_tcp_udp0
- ? IP4_ERROR_TCP_CHECKSUM + is_udp0
- : error0);
- error1 = (is_tcp_udp1 && ! good_tcp_udp1
- ? IP4_ERROR_TCP_CHECKSUM + is_udp1
- : error1);
-
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 3);
- leaf0 = (leaf0 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
- leaf1 = (leaf1 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie1->default_leaf : leaf1);
-
- vnet_buffer (p0)->ip.adj_index[VLIB_RX] = lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- vnet_buffer (p0)->ip.adj_index[VLIB_TX] = lbi0;
+ error0 = (is_tcp_udp0 && !good_tcp_udp0
+ ? IP4_ERROR_TCP_CHECKSUM + is_udp0 : error0);
+ error1 = (is_tcp_udp1 && !good_tcp_udp1
+ ? IP4_ERROR_TCP_CHECKSUM + is_udp1 : error1);
+
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 3);
+ leaf0 =
+ (leaf0 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
+ leaf1 =
+ (leaf1 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie1->default_leaf : leaf1);
+
+ vnet_buffer (p0)->ip.adj_index[VLIB_RX] = lbi0 =
+ ip4_fib_mtrie_leaf_get_adj_index (leaf0);
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX] = lbi0;
+
+ vnet_buffer (p1)->ip.adj_index[VLIB_RX] = lbi1 =
+ ip4_fib_mtrie_leaf_get_adj_index (leaf1);
+ vnet_buffer (p1)->ip.adj_index[VLIB_TX] = lbi1;
- vnet_buffer (p1)->ip.adj_index[VLIB_RX] = lbi1 = ip4_fib_mtrie_leaf_get_adj_index (leaf1);
- vnet_buffer (p1)->ip.adj_index[VLIB_TX] = lbi1;
-
- lb0 = load_balance_get(lbi0);
- lb1 = load_balance_get(lbi1);
- dpo0 = load_balance_get_bucket_i(lb0, 0);
- dpo1 = load_balance_get_bucket_i(lb1, 0);
+ lb0 = load_balance_get (lbi0);
+ lb1 = load_balance_get (lbi1);
+ dpo0 = load_balance_get_bucket_i (lb0, 0);
+ dpo1 = load_balance_get_bucket_i (lb1, 0);
/*
- * Must have a route to source otherwise we drop the packet.
- * ip4 broadcasts are accepted, e.g. to make dhcp client work
+ * Must have a route to source otherwise we drop the packet.
+ * ip4 broadcasts are accepted, e.g. to make dhcp client work
*
* The checks are:
* - the source is a recieve => it's from us => bogus, do this
* first since it sets a different error code.
* - uRPF check for any route to source - accept if passes.
* - allow packets destined to the broadcast address from unknown sources
- */
- error0 = ((error0 == IP4_ERROR_UNKNOWN_PROTOCOL &&
+ */
+ error0 = ((error0 == IP4_ERROR_UNKNOWN_PROTOCOL &&
dpo0->dpoi_type == DPO_RECEIVE) ?
- IP4_ERROR_SPOOFED_LOCAL_PACKETS :
- error0);
+ IP4_ERROR_SPOOFED_LOCAL_PACKETS : error0);
error0 = ((error0 == IP4_ERROR_UNKNOWN_PROTOCOL &&
- !fib_urpf_check_size(lb0->lb_urpf) &&
+ !fib_urpf_check_size (lb0->lb_urpf) &&
ip0->dst_address.as_u32 != 0xFFFFFFFF)
- ? IP4_ERROR_SRC_LOOKUP_MISS
- : error0);
- error1 = ((error1 == IP4_ERROR_UNKNOWN_PROTOCOL &&
+ ? IP4_ERROR_SRC_LOOKUP_MISS : error0);
+ error1 = ((error1 == IP4_ERROR_UNKNOWN_PROTOCOL &&
dpo1->dpoi_type == DPO_RECEIVE) ?
- IP4_ERROR_SPOOFED_LOCAL_PACKETS :
- error1);
+ IP4_ERROR_SPOOFED_LOCAL_PACKETS : error1);
error1 = ((error1 == IP4_ERROR_UNKNOWN_PROTOCOL &&
- !fib_urpf_check_size(lb1->lb_urpf) &&
+ !fib_urpf_check_size (lb1->lb_urpf) &&
ip1->dst_address.as_u32 != 0xFFFFFFFF)
- ? IP4_ERROR_SRC_LOOKUP_MISS
- : error1);
+ ? IP4_ERROR_SRC_LOOKUP_MISS : error1);
next0 = lm->local_next_by_ip_protocol[proto0];
next1 = lm->local_next_by_ip_protocol[proto1];
- next0 = error0 != IP4_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
- next1 = error1 != IP4_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
+ next0 =
+ error0 != IP4_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
+ next1 =
+ error1 != IP4_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
p0->error = error0 ? error_node->errors[error0] : 0;
p1->error = error1 ? error_node->errors[error1] : 0;
- enqueue_code = (next0 != next_index) + 2*(next1 != next_index);
+ enqueue_code = (next0 != next_index) + 2 * (next1 != next_index);
if (PREDICT_FALSE (enqueue_code != 0))
{
@@ -1650,9 +1684,11 @@ ip4_local (vlib_main_t * vm,
vlib_set_next_frame_buffer (vm, node, next1, pi1);
if (next0 == next1)
{
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ vlib_put_next_frame (vm, node, next_index,
+ n_left_to_next);
next_index = next1;
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next,
+ n_left_to_next);
}
break;
}
@@ -1661,15 +1697,15 @@ ip4_local (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- udp_header_t * udp0;
- ip4_fib_mtrie_t * mtrie0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ udp_header_t *udp0;
+ ip4_fib_mtrie_t *mtrie0;
ip4_fib_mtrie_leaf_t leaf0;
u32 pi0, next0, ip_len0, udp_len0, flags0, fib_index0, lbi0;
i32 len_diff0;
u8 error0, is_udp0, is_tcp_udp0, good_tcp_udp0, proto0;
- load_balance_t *lb0;
+ load_balance_t *lb0;
const dpo_id_t *dpo0;
pi0 = to_next[0] = from[0];
@@ -1682,20 +1718,21 @@ ip4_local (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
- vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data;
+ vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data;
fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(p0)->sw_if_index[VLIB_RX]);
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
mtrie0 = &ip4_fib_get (fib_index0)->mtrie;
leaf0 = IP4_FIB_MTRIE_LEAF_ROOT;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
/* Treat IP frag packets as "experimental" protocol for now
until support of IP frag reassembly is implemented */
- proto0 = ip4_is_fragment(ip0) ? 0xfe : ip0->protocol;
+ proto0 = ip4_is_fragment (ip0) ? 0xfe : ip0->protocol;
is_udp0 = proto0 == IP_PROTOCOL_UDP;
is_tcp_udp0 = is_udp0 || proto0 == IP_PROTOCOL_TCP;
@@ -1708,7 +1745,8 @@ ip4_local (vlib_main_t * vm,
/* Don't verify UDP checksum for packets with explicit zero checksum. */
good_tcp_udp0 |= is_udp0 && udp0->checksum == 0;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
/* Verify UDP length. */
ip_len0 = clib_net_to_host_u16 (ip0->length);
@@ -1718,12 +1756,12 @@ ip4_local (vlib_main_t * vm,
len_diff0 = is_udp0 ? len_diff0 : 0;
- if (PREDICT_FALSE (! (is_tcp_udp0 & good_tcp_udp0)))
+ if (PREDICT_FALSE (!(is_tcp_udp0 & good_tcp_udp0)))
{
if (is_tcp_udp0)
{
if (is_tcp_udp0
- && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED))
+ && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED))
flags0 = ip4_tcp_udp_validate_checksum (vm, p0);
good_tcp_udp0 =
(flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
@@ -1733,44 +1771,46 @@ ip4_local (vlib_main_t * vm,
good_tcp_udp0 &= len_diff0 >= 0;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
error0 = IP4_ERROR_UNKNOWN_PROTOCOL;
error0 = len_diff0 < 0 ? IP4_ERROR_UDP_LENGTH : error0;
ASSERT (IP4_ERROR_TCP_CHECKSUM + 1 == IP4_ERROR_UDP_CHECKSUM);
- error0 = (is_tcp_udp0 && ! good_tcp_udp0
- ? IP4_ERROR_TCP_CHECKSUM + is_udp0
- : error0);
+ error0 = (is_tcp_udp0 && !good_tcp_udp0
+ ? IP4_ERROR_TCP_CHECKSUM + is_udp0 : error0);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
- leaf0 = (leaf0 == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
+ leaf0 =
+ (leaf0 ==
+ IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie0->default_leaf : leaf0);
lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- vnet_buffer (p0)->ip.adj_index[VLIB_TX] = lbi0;
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX] = lbi0;
- lb0 = load_balance_get(lbi0);
- dpo0 = load_balance_get_bucket_i(lb0, 0);
+ lb0 = load_balance_get (lbi0);
+ dpo0 = load_balance_get_bucket_i (lb0, 0);
vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
- vnet_buffer (p0)->ip.adj_index[VLIB_RX] = lbi0;
+ vnet_buffer (p0)->ip.adj_index[VLIB_RX] = lbi0;
- error0 = ((error0 == IP4_ERROR_UNKNOWN_PROTOCOL &&
+ error0 = ((error0 == IP4_ERROR_UNKNOWN_PROTOCOL &&
dpo0->dpoi_type == DPO_RECEIVE) ?
- IP4_ERROR_SPOOFED_LOCAL_PACKETS :
- error0);
+ IP4_ERROR_SPOOFED_LOCAL_PACKETS : error0);
error0 = ((error0 == IP4_ERROR_UNKNOWN_PROTOCOL &&
- !fib_urpf_check_size(lb0->lb_urpf) &&
+ !fib_urpf_check_size (lb0->lb_urpf) &&
ip0->dst_address.as_u32 != 0xFFFFFFFF)
- ? IP4_ERROR_SRC_LOOKUP_MISS
- : error0);
+ ? IP4_ERROR_SRC_LOOKUP_MISS : error0);
next0 = lm->local_next_by_ip_protocol[proto0];
- next0 = error0 != IP4_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
+ next0 =
+ error0 != IP4_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
- p0->error = error0? error_node->errors[error0] : 0;
+ p0->error = error0 ? error_node->errors[error0] : 0;
if (PREDICT_FALSE (next0 != next_index))
{
@@ -1778,7 +1818,8 @@ ip4_local (vlib_main_t * vm,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
next_index = next0;
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next,
+ n_left_to_next);
to_next[0] = pi0;
to_next += 1;
n_left_to_next -= 1;
@@ -1791,48 +1832,45 @@ ip4_local (vlib_main_t * vm,
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip4_local_node,static) = {
- .function = ip4_local,
- .name = "ip4-local",
- .vector_size = sizeof (u32),
-
- .format_trace = format_ip4_forward_next_trace,
-
- .n_next_nodes = IP_LOCAL_N_NEXT,
- .next_nodes = {
- [IP_LOCAL_NEXT_DROP] = "error-drop",
- [IP_LOCAL_NEXT_PUNT] = "error-punt",
- [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip4-udp-lookup",
- [IP_LOCAL_NEXT_ICMP] = "ip4-icmp-input",
- },
-};
+VLIB_REGISTER_NODE (ip4_local_node, static) =
+{
+ .function = ip4_local,.name = "ip4-local",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.n_next_nodes =
+ IP_LOCAL_N_NEXT,.next_nodes =
+ {
+ [IP_LOCAL_NEXT_DROP] = "error-drop",
+ [IP_LOCAL_NEXT_PUNT] = "error-punt",
+ [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip4-udp-lookup",
+ [IP_LOCAL_NEXT_ICMP] = "ip4-icmp-input",}
+,};
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_local_node, ip4_local)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_local_node, ip4_local);
-void ip4_register_protocol (u32 protocol, u32 node_index)
+void
+ip4_register_protocol (u32 protocol, u32 node_index)
{
- vlib_main_t * vm = vlib_get_main();
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ vlib_main_t *vm = vlib_get_main ();
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
- lm->local_next_by_ip_protocol[protocol] = vlib_node_add_next (vm, ip4_local_node.index, node_index);
+ lm->local_next_by_ip_protocol[protocol] =
+ vlib_node_add_next (vm, ip4_local_node.index, node_index);
}
static clib_error_t *
show_ip_local_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
int i;
vlib_cli_output (vm, "Protocols handled by ip4_local");
- for (i = 0; i < ARRAY_LEN(lm->local_next_by_ip_protocol); i++)
+ for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
{
if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
- vlib_cli_output (vm, "%d", i);
+ vlib_cli_output (vm, "%d", i);
}
return 0;
}
@@ -1852,7 +1890,8 @@ show_ip_local_command_fn (vlib_main_t * vm,
* @cliexend
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_ip_local, static) = {
+VLIB_CLI_COMMAND (show_ip_local, static) =
+{
.path = "show ip local",
.function = show_ip_local_command_fn,
.short_help = "show ip local",
@@ -1862,13 +1901,12 @@ VLIB_CLI_COMMAND (show_ip_local, static) = {
always_inline uword
ip4_arp_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- int is_glean)
+ vlib_frame_t * frame, int is_glean)
{
- vnet_main_t * vnm = vnet_get_main();
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- u32 * from, * to_next_drop;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ u32 *from, *to_next_drop;
uword n_left_from, n_left_to_next_drop, next_index;
static f64 time_last_seed_change = -1e100;
static u32 hash_seeds[3];
@@ -1882,8 +1920,8 @@ ip4_arp_inline (vlib_main_t * vm,
if (time_now - time_last_seed_change > 1e-3)
{
uword i;
- u32 * r = clib_random_buffer_get_data (&vm->random_buffer,
- sizeof (hash_seeds));
+ u32 *r = clib_random_buffer_get_data (&vm->random_buffer,
+ sizeof (hash_seeds));
for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
hash_seeds[i] = r[i];
@@ -1898,7 +1936,7 @@ ip4_arp_inline (vlib_main_t * vm,
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
if (next_index == IP4_ARP_NEXT_DROP)
- next_index = IP4_ARP_N_NEXT; /* point to first interface */
+ next_index = IP4_ARP_N_NEXT; /* point to first interface */
while (n_left_from > 0)
{
@@ -1908,9 +1946,9 @@ ip4_arp_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next_drop > 0)
{
u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
- ip_adjacency_t * adj0;
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
+ ip_adjacency_t *adj0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
uword bm0;
pi0 = from[0];
@@ -1928,18 +1966,18 @@ ip4_arp_inline (vlib_main_t * vm,
sw_if_index0 = adj0->rewrite_header.sw_if_index;
vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
- if (is_glean)
- {
+ if (is_glean)
+ {
/*
* this is the Glean case, so we are ARPing for the
* packet's destination
*/
- a0 ^= ip0->dst_address.data_u32;
- }
- else
- {
- a0 ^= adj0->sub_type.nbr.next_hop.ip4.data_u32;
- }
+ a0 ^= ip0->dst_address.data_u32;
+ }
+ else
+ {
+ a0 ^= adj0->sub_type.nbr.next_hop.ip4.data_u32;
+ }
b0 ^= sw_if_index0;
hash_v3_finalize32 (a0, b0, c0);
@@ -1960,7 +1998,9 @@ ip4_arp_inline (vlib_main_t * vm,
to_next_drop += 1;
n_left_to_next_drop -= 1;
- p0->error = node->errors[drop0 ? IP4_ARP_ERROR_DROP : IP4_ARP_ERROR_REQUEST_SENT];
+ p0->error =
+ node->errors[drop0 ? IP4_ARP_ERROR_DROP :
+ IP4_ARP_ERROR_REQUEST_SENT];
/*
* the adj has been updated to a rewrite but the node the DPO that got
@@ -1972,69 +2012,80 @@ ip4_arp_inline (vlib_main_t * vm,
if (drop0)
continue;
- /*
- * Can happen if the control-plane is programming tables
- * with traffic flowing; at least that's today's lame excuse.
- */
+ /*
+ * Can happen if the control-plane is programming tables
+ * with traffic flowing; at least that's today's lame excuse.
+ */
if ((is_glean && adj0->lookup_next_index != IP_LOOKUP_NEXT_GLEAN) ||
(!is_glean && adj0->lookup_next_index != IP_LOOKUP_NEXT_ARP))
- {
- p0->error = node->errors[IP4_ARP_ERROR_NON_ARP_ADJ];
- }
- else
- /* Send ARP request. */
- {
- u32 bi0 = 0;
- vlib_buffer_t * b0;
- ethernet_arp_header_t * h0;
- vnet_hw_interface_t * hw_if0;
-
- h0 = vlib_packet_template_get_packet (vm, &im->ip4_arp_request_packet_template, &bi0);
+ {
+ p0->error = node->errors[IP4_ARP_ERROR_NON_ARP_ADJ];
+ }
+ else
+ /* Send ARP request. */
+ {
+ u32 bi0 = 0;
+ vlib_buffer_t *b0;
+ ethernet_arp_header_t *h0;
+ vnet_hw_interface_t *hw_if0;
- /* Add rewrite/encap string for ARP packet. */
- vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t));
+ h0 =
+ vlib_packet_template_get_packet (vm,
+ &im->ip4_arp_request_packet_template,
+ &bi0);
- hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
+ /* Add rewrite/encap string for ARP packet. */
+ vnet_rewrite_one_header (adj0[0], h0,
+ sizeof (ethernet_header_t));
- /* Src ethernet address in ARP header. */
- clib_memcpy (h0->ip4_over_ethernet[0].ethernet, hw_if0->hw_address,
- sizeof (h0->ip4_over_ethernet[0].ethernet));
+ hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
- if (is_glean)
- {
- /* The interface's source address is stashed in the Glean Adj */
- h0->ip4_over_ethernet[0].ip4 = adj0->sub_type.glean.receive_addr.ip4;
+ /* Src ethernet address in ARP header. */
+ clib_memcpy (h0->ip4_over_ethernet[0].ethernet,
+ hw_if0->hw_address,
+ sizeof (h0->ip4_over_ethernet[0].ethernet));
- /* Copy in destination address we are requesting. This is the
- * glean case, so it's the packet's destination.*/
- h0->ip4_over_ethernet[1].ip4.data_u32 = ip0->dst_address.data_u32;
- }
- else
- {
- /* Src IP address in ARP header. */
- if (ip4_src_address_for_packet(lm, sw_if_index0,
- &h0->ip4_over_ethernet[0].ip4))
+ if (is_glean)
{
- /* No source address available */
- p0->error = node->errors[IP4_ARP_ERROR_NO_SOURCE_ADDRESS];
- vlib_buffer_free(vm, &bi0, 1);
- continue;
+ /* The interface's source address is stashed in the Glean Adj */
+ h0->ip4_over_ethernet[0].ip4 =
+ adj0->sub_type.glean.receive_addr.ip4;
+
+ /* Copy in destination address we are requesting. This is the
+ * glean case, so it's the packet's destination.*/
+ h0->ip4_over_ethernet[1].ip4.data_u32 =
+ ip0->dst_address.data_u32;
}
+ else
+ {
+ /* Src IP address in ARP header. */
+ if (ip4_src_address_for_packet (lm, sw_if_index0,
+ &h0->
+ ip4_over_ethernet[0].ip4))
+ {
+ /* No source address available */
+ p0->error =
+ node->errors[IP4_ARP_ERROR_NO_SOURCE_ADDRESS];
+ vlib_buffer_free (vm, &bi0, 1);
+ continue;
+ }
- /* Copy in destination address we are requesting from the
- incomplete adj */
- h0->ip4_over_ethernet[1].ip4.data_u32 =
+ /* Copy in destination address we are requesting from the
+ incomplete adj */
+ h0->ip4_over_ethernet[1].ip4.data_u32 =
adj0->sub_type.nbr.next_hop.ip4.as_u32;
- }
+ }
- vlib_buffer_copy_trace_flag (vm, p0, bi0);
- b0 = vlib_get_buffer (vm, bi0);
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
+ vlib_buffer_copy_trace_flag (vm, p0, bi0);
+ b0 = vlib_get_buffer (vm, bi0);
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
- vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
+ vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
- vlib_set_next_frame_buffer (vm, node, adj0->rewrite_header.next_index, bi0);
- }
+ vlib_set_next_frame_buffer (vm, node,
+ adj0->rewrite_header.next_index,
+ bi0);
+ }
}
vlib_put_next_frame (vm, node, IP4_ARP_NEXT_DROP, n_left_to_next_drop);
@@ -2044,22 +2095,18 @@ ip4_arp_inline (vlib_main_t * vm,
}
static uword
-ip4_arp (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip4_arp (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return (ip4_arp_inline(vm, node, frame, 0));
+ return (ip4_arp_inline (vm, node, frame, 0));
}
static uword
-ip4_glean (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip4_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return (ip4_arp_inline(vm, node, frame, 1));
+ return (ip4_arp_inline (vm, node, frame, 1));
}
-static char * ip4_arp_error_strings[] = {
+static char *ip4_arp_error_strings[] = {
[IP4_ARP_ERROR_DROP] = "address overflow drops",
[IP4_ARP_ERROR_REQUEST_SENT] = "ARP requests sent",
[IP4_ARP_ERROR_NON_ARP_ADJ] = "ARPs to non-ARP adjacencies",
@@ -2068,37 +2115,25 @@ static char * ip4_arp_error_strings[] = {
[IP4_ARP_ERROR_NO_SOURCE_ADDRESS] = "no source address for ARP request",
};
-VLIB_REGISTER_NODE (ip4_arp_node) = {
- .function = ip4_arp,
- .name = "ip4-arp",
- .vector_size = sizeof (u32),
-
- .format_trace = format_ip4_forward_next_trace,
-
- .n_errors = ARRAY_LEN (ip4_arp_error_strings),
- .error_strings = ip4_arp_error_strings,
-
- .n_next_nodes = IP4_ARP_N_NEXT,
- .next_nodes = {
- [IP4_ARP_NEXT_DROP] = "error-drop",
- },
-};
-
-VLIB_REGISTER_NODE (ip4_glean_node) = {
- .function = ip4_glean,
- .name = "ip4-glean",
- .vector_size = sizeof (u32),
-
- .format_trace = format_ip4_forward_next_trace,
-
- .n_errors = ARRAY_LEN (ip4_arp_error_strings),
- .error_strings = ip4_arp_error_strings,
+VLIB_REGISTER_NODE (ip4_arp_node) =
+{
+ .function = ip4_arp,.name = "ip4-arp",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.n_errors =
+ ARRAY_LEN (ip4_arp_error_strings),.error_strings =
+ ip4_arp_error_strings,.n_next_nodes = IP4_ARP_N_NEXT,.next_nodes =
+ {
+ [IP4_ARP_NEXT_DROP] = "error-drop",}
+,};
- .n_next_nodes = IP4_ARP_N_NEXT,
- .next_nodes = {
- [IP4_ARP_NEXT_DROP] = "error-drop",
- },
-};
+VLIB_REGISTER_NODE (ip4_glean_node) =
+{
+ .function = ip4_glean,.name = "ip4-glean",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.n_errors =
+ ARRAY_LEN (ip4_arp_error_strings),.error_strings =
+ ip4_arp_error_strings,.n_next_nodes = IP4_ARP_N_NEXT,.next_nodes =
+ {
+ [IP4_ARP_NEXT_DROP] = "error-drop",}
+,};
#define foreach_notrace_ip4_arp_error \
_(DROP) \
@@ -2106,37 +2141,37 @@ _(REQUEST_SENT) \
_(REPLICATE_DROP) \
_(REPLICATE_FAIL)
-clib_error_t * arp_notrace_init (vlib_main_t * vm)
+clib_error_t *
+arp_notrace_init (vlib_main_t * vm)
{
- vlib_node_runtime_t *rt =
- vlib_node_get_runtime (vm, ip4_arp_node.index);
+ vlib_node_runtime_t *rt = vlib_node_get_runtime (vm, ip4_arp_node.index);
/* don't trace ARP request packets */
#define _(a) \
vnet_pcap_drop_trace_filter_add_del \
(rt->errors[IP4_ARP_ERROR_##a], \
1 /* is_add */);
- foreach_notrace_ip4_arp_error;
+ foreach_notrace_ip4_arp_error;
#undef _
return 0;
}
-VLIB_INIT_FUNCTION(arp_notrace_init);
+VLIB_INIT_FUNCTION (arp_notrace_init);
/* Send an ARP request to see if given destination is reachable on given interface. */
clib_error_t *
ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst, u32 sw_if_index)
{
- vnet_main_t * vnm = vnet_get_main();
- ip4_main_t * im = &ip4_main;
- ethernet_arp_header_t * h;
- ip4_address_t * src;
- ip_interface_address_t * ia;
- ip_adjacency_t * adj;
- vnet_hw_interface_t * hi;
- vnet_sw_interface_t * si;
- vlib_buffer_t * b;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip4_main_t *im = &ip4_main;
+ ethernet_arp_header_t *h;
+ ip4_address_t *src;
+ ip_interface_address_t *ia;
+ ip_adjacency_t *adj;
+ vnet_hw_interface_t *hi;
+ vnet_sw_interface_t *si;
+ vlib_buffer_t *b;
u32 bi = 0;
si = vnet_get_sw_interface (vnm, sw_if_index);
@@ -2144,42 +2179,47 @@ ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst, u32 sw_if_index)
if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
{
return clib_error_return (0, "%U: interface %U down",
- format_ip4_address, dst,
- format_vnet_sw_if_index_name, vnm,
- sw_if_index);
+ format_ip4_address, dst,
+ format_vnet_sw_if_index_name, vnm,
+ sw_if_index);
}
- src = ip4_interface_address_matching_destination (im, dst, sw_if_index, &ia);
- if (! src)
+ src =
+ ip4_interface_address_matching_destination (im, dst, sw_if_index, &ia);
+ if (!src)
{
vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
return clib_error_return
- (0, "no matching interface address for destination %U (interface %U)",
- format_ip4_address, dst,
- format_vnet_sw_if_index_name, vnm, sw_if_index);
+ (0, "no matching interface address for destination %U (interface %U)",
+ format_ip4_address, dst,
+ format_vnet_sw_if_index_name, vnm, sw_if_index);
}
adj = ip_get_adjacency (&im->lookup_main, ia->neighbor_probe_adj_index);
- h = vlib_packet_template_get_packet (vm, &im->ip4_arp_request_packet_template, &bi);
+ h =
+ vlib_packet_template_get_packet (vm, &im->ip4_arp_request_packet_template,
+ &bi);
hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
- clib_memcpy (h->ip4_over_ethernet[0].ethernet, hi->hw_address, sizeof (h->ip4_over_ethernet[0].ethernet));
+ clib_memcpy (h->ip4_over_ethernet[0].ethernet, hi->hw_address,
+ sizeof (h->ip4_over_ethernet[0].ethernet));
h->ip4_over_ethernet[0].ip4 = src[0];
h->ip4_over_ethernet[1].ip4 = dst[0];
b = vlib_get_buffer (vm, bi);
- vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
+ vnet_buffer (b)->sw_if_index[VLIB_RX] =
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
/* Add encapsulation string for software interface (e.g. ethernet header). */
vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
{
- vlib_frame_t * f = vlib_get_frame_to_node (vm, hi->output_node_index);
- u32 * to_next = vlib_frame_vector_args (f);
+ vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
+ u32 *to_next = vlib_frame_vector_args (f);
to_next[0] = bi;
f->n_vectors = 1;
vlib_put_frame_to_node (vm, hi->output_node_index, f);
@@ -2188,7 +2228,8 @@ ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst, u32 sw_if_index)
return /* no error */ 0;
}
-typedef enum {
+typedef enum
+{
IP4_REWRITE_NEXT_DROP,
IP4_REWRITE_NEXT_ICMP_ERROR,
} ip4_rewrite_next_t;
@@ -2196,17 +2237,17 @@ typedef enum {
always_inline uword
ip4_rewrite_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- int is_midchain)
+ vlib_frame_t * frame, int is_midchain)
{
- ip_lookup_main_t * lm = &ip4_main.lookup_main;
- u32 * from = vlib_frame_vector_args (frame);
- u32 n_left_from, n_left_to_next, * to_next, next_index;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip4_input_node.index);
+ ip_lookup_main_t *lm = &ip4_main.lookup_main;
+ u32 *from = vlib_frame_vector_args (frame);
+ u32 n_left_from, n_left_to_next, *to_next, next_index;
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip4_input_node.index);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
while (n_left_from > 0)
{
@@ -2214,16 +2255,16 @@ ip4_rewrite_inline (vlib_main_t * vm,
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- ip_adjacency_t * adj0, * adj1;
- vlib_buffer_t * p0, * p1;
- ip4_header_t * ip0, * ip1;
+ ip_adjacency_t *adj0, *adj1;
+ vlib_buffer_t *p0, *p1;
+ ip4_header_t *ip0, *ip1;
u32 pi0, rw_len0, next0, error0, checksum0, adj_index0;
u32 pi1, rw_len1, next1, error1, checksum1, adj_index1;
- u32 tx_sw_if_index0, tx_sw_if_index1;
+ u32 tx_sw_if_index0, tx_sw_if_index1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -2249,20 +2290,20 @@ ip4_rewrite_inline (vlib_main_t * vm,
adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
- /* We should never rewrite a pkt using the MISS adjacency */
- ASSERT(adj_index0 && adj_index1);
+ /* We should never rewrite a pkt using the MISS adjacency */
+ ASSERT (adj_index0 && adj_index1);
ip0 = vlib_buffer_get_current (p0);
ip1 = vlib_buffer_get_current (p1);
error0 = error1 = IP4_ERROR_NONE;
- next0 = next1 = IP4_REWRITE_NEXT_DROP;
+ next0 = next1 = IP4_REWRITE_NEXT_DROP;
/* Decrement TTL & update checksum.
Works either endian, so no need for byte swap. */
- if (PREDICT_TRUE(!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
+ if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
{
- i32 ttl0 = ip0->ttl;
+ i32 ttl0 = ip0->ttl;
/* Input node should have reject packets with ttl 0. */
ASSERT (ip0->ttl > 0);
@@ -2274,27 +2315,28 @@ ip4_rewrite_inline (vlib_main_t * vm,
ttl0 -= 1;
ip0->ttl = ttl0;
- /*
- * If the ttl drops below 1 when forwarding, generate
- * an ICMP response.
- */
- if (PREDICT_FALSE(ttl0 <= 0))
- {
- error0 = IP4_ERROR_TIME_EXPIRED;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32)~0;
- icmp4_error_set_vnet_buffer(p0, ICMP4_time_exceeded,
- ICMP4_time_exceeded_ttl_exceeded_in_transit, 0);
- next0 = IP4_REWRITE_NEXT_ICMP_ERROR;
- }
+ /*
+ * If the ttl drops below 1 when forwarding, generate
+ * an ICMP response.
+ */
+ if (PREDICT_FALSE (ttl0 <= 0))
+ {
+ error0 = IP4_ERROR_TIME_EXPIRED;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ icmp4_error_set_vnet_buffer (p0, ICMP4_time_exceeded,
+ ICMP4_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next0 = IP4_REWRITE_NEXT_ICMP_ERROR;
+ }
/* Verify checksum. */
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
}
- else
- {
- p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
- }
- if (PREDICT_TRUE(!(p1->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
+ else
+ {
+ p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
+ }
+ if (PREDICT_TRUE (!(p1->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
{
i32 ttl1 = ip1->ttl;
@@ -2308,105 +2350,105 @@ ip4_rewrite_inline (vlib_main_t * vm,
ttl1 -= 1;
ip1->ttl = ttl1;
- /*
- * If the ttl drops below 1 when forwarding, generate
- * an ICMP response.
- */
- if (PREDICT_FALSE(ttl1 <= 0))
- {
- error1 = IP4_ERROR_TIME_EXPIRED;
- vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32)~0;
- icmp4_error_set_vnet_buffer(p1, ICMP4_time_exceeded,
- ICMP4_time_exceeded_ttl_exceeded_in_transit, 0);
- next1 = IP4_REWRITE_NEXT_ICMP_ERROR;
- }
+ /*
+ * If the ttl drops below 1 when forwarding, generate
+ * an ICMP response.
+ */
+ if (PREDICT_FALSE (ttl1 <= 0))
+ {
+ error1 = IP4_ERROR_TIME_EXPIRED;
+ vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ icmp4_error_set_vnet_buffer (p1, ICMP4_time_exceeded,
+ ICMP4_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next1 = IP4_REWRITE_NEXT_ICMP_ERROR;
+ }
/* Verify checksum. */
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
ASSERT (ip1->checksum == ip4_header_checksum (ip1));
}
- else
- {
- p1->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
- }
+ else
+ {
+ p1->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
+ }
/* Rewrite packet header and updates lengths. */
adj0 = ip_get_adjacency (lm, adj_index0);
adj1 = ip_get_adjacency (lm, adj_index1);
- /* Worth pipelining. No guarantee that adj0,1 are hot... */
+ /* Worth pipelining. No guarantee that adj0,1 are hot... */
rw_len0 = adj0[0].rewrite_header.data_bytes;
rw_len1 = adj1[0].rewrite_header.data_bytes;
- vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
- vnet_buffer(p1)->ip.save_rewrite_length = rw_len1;
-
- /* Check MTU of outgoing interface. */
- error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
- ? IP4_ERROR_MTU_EXCEEDED
- : error0);
- error1 = (vlib_buffer_length_in_chain (vm, p1) > adj1[0].rewrite_header.max_l3_packet_bytes
- ? IP4_ERROR_MTU_EXCEEDED
- : error1);
-
- next0 = (error0 == IP4_ERROR_NONE)
- ? adj0[0].rewrite_header.next_index : next0;
-
- next1 = (error1 == IP4_ERROR_NONE)
- ? adj1[0].rewrite_header.next_index : next1;
-
- /*
- * We've already accounted for an ethernet_header_t elsewhere
- */
- if (PREDICT_FALSE (rw_len0 > sizeof(ethernet_header_t)))
- vlib_increment_combined_counter
- (&adjacency_counters,
- cpu_index, adj_index0,
- /* packet increment */ 0,
- /* byte increment */ rw_len0-sizeof(ethernet_header_t));
-
- if (PREDICT_FALSE (rw_len1 > sizeof(ethernet_header_t)))
- vlib_increment_combined_counter
- (&adjacency_counters,
- cpu_index, adj_index1,
- /* packet increment */ 0,
- /* byte increment */ rw_len1-sizeof(ethernet_header_t));
-
- /* Don't adjust the buffer for ttl issue; icmp-error node wants
- * to see the IP headerr */
- if (PREDICT_TRUE(error0 == IP4_ERROR_NONE))
- {
- p0->current_data -= rw_len0;
- p0->current_length += rw_len0;
- tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] =
- tx_sw_if_index0;
-
- vnet_feature_arc_start(lm->output_feature_arc_index,
- tx_sw_if_index0, &next0, p0);
- }
- if (PREDICT_TRUE(error1 == IP4_ERROR_NONE))
- {
- p1->current_data -= rw_len1;
- p1->current_length += rw_len1;
-
- tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
- vnet_buffer (p1)->sw_if_index[VLIB_TX] =
- tx_sw_if_index1;
-
- vnet_feature_arc_start(lm->output_feature_arc_index,
- tx_sw_if_index1, &next1, p1);
- }
+ vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
+ vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
+
+ /* Check MTU of outgoing interface. */
+ error0 =
+ (vlib_buffer_length_in_chain (vm, p0) >
+ adj0[0].
+ rewrite_header.max_l3_packet_bytes ? IP4_ERROR_MTU_EXCEEDED :
+ error0);
+ error1 =
+ (vlib_buffer_length_in_chain (vm, p1) >
+ adj1[0].
+ rewrite_header.max_l3_packet_bytes ? IP4_ERROR_MTU_EXCEEDED :
+ error1);
+
+ next0 = (error0 == IP4_ERROR_NONE)
+ ? adj0[0].rewrite_header.next_index : next0;
+
+ next1 = (error1 == IP4_ERROR_NONE)
+ ? adj1[0].rewrite_header.next_index : next1;
+
+ /*
+ * We've already accounted for an ethernet_header_t elsewhere
+ */
+ if (PREDICT_FALSE (rw_len0 > sizeof (ethernet_header_t)))
+ vlib_increment_combined_counter
+ (&adjacency_counters, cpu_index, adj_index0,
+ /* packet increment */ 0,
+ /* byte increment */ rw_len0 - sizeof (ethernet_header_t));
+
+ if (PREDICT_FALSE (rw_len1 > sizeof (ethernet_header_t)))
+ vlib_increment_combined_counter
+ (&adjacency_counters, cpu_index, adj_index1,
+ /* packet increment */ 0,
+ /* byte increment */ rw_len1 - sizeof (ethernet_header_t));
+
+ /* Don't adjust the buffer for ttl issue; icmp-error node wants
+ * to see the IP headerr */
+ if (PREDICT_TRUE (error0 == IP4_ERROR_NONE))
+ {
+ p0->current_data -= rw_len0;
+ p0->current_length += rw_len0;
+ tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
+
+ vnet_feature_arc_start (lm->output_feature_arc_index,
+ tx_sw_if_index0, &next0, p0);
+ }
+ if (PREDICT_TRUE (error1 == IP4_ERROR_NONE))
+ {
+ p1->current_data -= rw_len1;
+ p1->current_length += rw_len1;
+
+ tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
+ vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
+
+ vnet_feature_arc_start (lm->output_feature_arc_index,
+ tx_sw_if_index1, &next1, p1);
+ }
/* Guess we are only writing on simple Ethernet header. */
vnet_rewrite_two_headers (adj0[0], adj1[0],
- ip0, ip1,
- sizeof (ethernet_header_t));
+ ip0, ip1, sizeof (ethernet_header_t));
if (is_midchain)
- {
- adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
- adj1->sub_type.midchain.fixup_func(vm, adj1, p1);
- }
+ {
+ adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
+ adj1->sub_type.midchain.fixup_func (vm, adj1, p1);
+ }
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
@@ -2415,11 +2457,11 @@ ip4_rewrite_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- ip_adjacency_t * adj0;
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
+ ip_adjacency_t *adj0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
u32 pi0, rw_len0, adj_index0, next0, error0, checksum0;
- u32 tx_sw_if_index0;
+ u32 tx_sw_if_index0;
pi0 = to_next[0] = from[0];
@@ -2427,18 +2469,18 @@ ip4_rewrite_inline (vlib_main_t * vm,
adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
- /* We should never rewrite a pkt using the MISS adjacency */
- ASSERT(adj_index0);
+ /* We should never rewrite a pkt using the MISS adjacency */
+ ASSERT (adj_index0);
adj0 = ip_get_adjacency (lm, adj_index0);
ip0 = vlib_buffer_get_current (p0);
error0 = IP4_ERROR_NONE;
- next0 = IP4_REWRITE_NEXT_DROP; /* drop on error */
+ next0 = IP4_REWRITE_NEXT_DROP; /* drop on error */
/* Decrement TTL & update checksum. */
- if (PREDICT_TRUE(!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
+ if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
{
i32 ttl0 = ip0->ttl;
@@ -2456,67 +2498,65 @@ ip4_rewrite_inline (vlib_main_t * vm,
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
- if (PREDICT_FALSE(ttl0 <= 0))
- {
- /*
- * If the ttl drops below 1 when forwarding, generate
- * an ICMP response.
- */
- error0 = IP4_ERROR_TIME_EXPIRED;
- next0 = IP4_REWRITE_NEXT_ICMP_ERROR;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32)~0;
- icmp4_error_set_vnet_buffer(p0, ICMP4_time_exceeded,
- ICMP4_time_exceeded_ttl_exceeded_in_transit, 0);
- }
+ if (PREDICT_FALSE (ttl0 <= 0))
+ {
+ /*
+ * If the ttl drops below 1 when forwarding, generate
+ * an ICMP response.
+ */
+ error0 = IP4_ERROR_TIME_EXPIRED;
+ next0 = IP4_REWRITE_NEXT_ICMP_ERROR;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ icmp4_error_set_vnet_buffer (p0, ICMP4_time_exceeded,
+ ICMP4_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ }
+ }
+ else
+ {
+ p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
}
- else
- {
- p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
- }
/* Guess we are only writing on simple Ethernet header. */
- vnet_rewrite_one_header (adj0[0], ip0,
- sizeof (ethernet_header_t));
-
- /* Update packet buffer attributes/set output interface. */
- rw_len0 = adj0[0].rewrite_header.data_bytes;
- vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
-
- if (PREDICT_FALSE (rw_len0 > sizeof(ethernet_header_t)))
- vlib_increment_combined_counter
- (&adjacency_counters,
- cpu_index, adj_index0,
- /* packet increment */ 0,
- /* byte increment */ rw_len0-sizeof(ethernet_header_t));
-
- /* Check MTU of outgoing interface. */
- error0 = (vlib_buffer_length_in_chain (vm, p0)
- > adj0[0].rewrite_header.max_l3_packet_bytes
- ? IP4_ERROR_MTU_EXCEEDED
- : error0);
+ vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
+
+ /* Update packet buffer attributes/set output interface. */
+ rw_len0 = adj0[0].rewrite_header.data_bytes;
+ vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
+
+ if (PREDICT_FALSE (rw_len0 > sizeof (ethernet_header_t)))
+ vlib_increment_combined_counter
+ (&adjacency_counters, cpu_index, adj_index0,
+ /* packet increment */ 0,
+ /* byte increment */ rw_len0 - sizeof (ethernet_header_t));
+
+ /* Check MTU of outgoing interface. */
+ error0 = (vlib_buffer_length_in_chain (vm, p0)
+ > adj0[0].rewrite_header.max_l3_packet_bytes
+ ? IP4_ERROR_MTU_EXCEEDED : error0);
p0->error = error_node->errors[error0];
- /* Don't adjust the buffer for ttl issue; icmp-error node wants
- * to see the IP headerr */
- if (PREDICT_TRUE(error0 == IP4_ERROR_NONE))
- {
- p0->current_data -= rw_len0;
- p0->current_length += rw_len0;
- tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
+ /* Don't adjust the buffer for ttl issue; icmp-error node wants
+ * to see the IP headerr */
+ if (PREDICT_TRUE (error0 == IP4_ERROR_NONE))
+ {
+ p0->current_data -= rw_len0;
+ p0->current_length += rw_len0;
+ tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
- next0 = adj0[0].rewrite_header.next_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
+ next0 = adj0[0].rewrite_header.next_index;
if (is_midchain)
- {
- adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
+ {
+ adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
}
- vnet_feature_arc_start(lm->output_feature_arc_index,
- tx_sw_if_index0, &next0, p0);
+ vnet_feature_arc_start (lm->output_feature_arc_index,
+ tx_sw_if_index0, &next0, p0);
- }
+ }
from += 1;
n_left_from -= 1;
@@ -2572,61 +2612,50 @@ ip4_rewrite_inline (vlib_main_t * vm,
*/
static uword
ip4_rewrite (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip4_rewrite_inline (vm, node, frame, 0);
}
static uword
ip4_midchain (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip4_rewrite_inline (vm, node, frame, 1);
}
-VLIB_REGISTER_NODE (ip4_rewrite_node) = {
- .function = ip4_rewrite,
- .name = "ip4-rewrite",
- .vector_size = sizeof (u32),
-
- .format_trace = format_ip4_rewrite_trace,
-
- .n_next_nodes = 2,
- .next_nodes = {
- [IP4_REWRITE_NEXT_DROP] = "error-drop",
- [IP4_REWRITE_NEXT_ICMP_ERROR] = "ip4-icmp-error",
- },
-};
-
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_rewrite_node, ip4_rewrite)
-
-VLIB_REGISTER_NODE (ip4_midchain_node) = {
- .function = ip4_midchain,
- .name = "ip4-midchain",
- .vector_size = sizeof (u32),
+VLIB_REGISTER_NODE (ip4_rewrite_node) =
+{
+ .function = ip4_rewrite,.name = "ip4-rewrite",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_rewrite_trace,.n_next_nodes =
+ 2,.next_nodes =
+ {
+ [IP4_REWRITE_NEXT_DROP] = "error-drop",
+ [IP4_REWRITE_NEXT_ICMP_ERROR] = "ip4-icmp-error",}
+,};
- .format_trace = format_ip4_forward_next_trace,
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_rewrite_node, ip4_rewrite);
- .sibling_of = "ip4-rewrite",
-};
+VLIB_REGISTER_NODE (ip4_midchain_node) =
+{
+.function = ip4_midchain,.name = "ip4-midchain",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.sibling_of =
+ "ip4-rewrite",};
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_midchain_node, ip4_midchain)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_midchain_node, ip4_midchain);
static clib_error_t *
add_del_interface_table (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *error = 0;
u32 sw_if_index, table_id;
sw_if_index = ~0;
- if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+ if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
error = clib_error_return (0, "unknown interface `%U'",
format_unformat_error, input);
@@ -2643,11 +2672,11 @@ add_del_interface_table (vlib_main_t * vm,
}
{
- ip4_main_t * im = &ip4_main;
+ ip4_main_t *im = &ip4_main;
u32 fib_index;
fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
- table_id);
+ table_id);
//
// FIXME-LATER
@@ -2658,7 +2687,7 @@ add_del_interface_table (vlib_main_t * vm,
im->fib_index_by_sw_if_index[sw_if_index] = fib_index;
}
- done:
+done:
return error;
}
@@ -2683,7 +2712,8 @@ add_del_interface_table (vlib_main_t * vm,
* @cliexcmd{set interface ip table GigabitEthernet2/0/0 2}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_interface_ip_table_command, static) = {
+VLIB_CLI_COMMAND (set_interface_ip_table_command, static) =
+{
.path = "set interface ip table",
.function = add_del_interface_table,
.short_help = "set interface ip table <interface> <table-id>",
@@ -2693,14 +2723,13 @@ VLIB_CLI_COMMAND (set_interface_ip_table_command, static) = {
static uword
ip4_lookup_multicast (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- ip4_main_t * im = &ip4_main;
- vlib_combined_counter_main_t * cm = &load_balance_main.lbm_to_counters;
- u32 n_left_from, n_left_to_next, * from, * to_next;
+ ip4_main_t *im = &ip4_main;
+ vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters;
+ u32 n_left_from, n_left_to_next, *from, *to_next;
ip_lookup_next_t next;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -2708,22 +2737,21 @@ ip4_lookup_multicast (vlib_main_t * vm,
while (n_left_from > 0)
{
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- vlib_buffer_t * p0, * p1;
+ vlib_buffer_t *p0, *p1;
u32 pi0, pi1, lb_index0, lb_index1, wrong_next;
ip_lookup_next_t next0, next1;
- ip4_header_t * ip0, * ip1;
- u32 fib_index0, fib_index1;
+ ip4_header_t *ip0, *ip1;
+ u32 fib_index0, fib_index1;
const dpo_id_t *dpo0, *dpo1;
- const load_balance_t * lb0, * lb1;
+ const load_balance_t *lb0, *lb1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -2744,59 +2772,65 @@ ip4_lookup_multicast (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
ip1 = vlib_buffer_get_current (p1);
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]);
- fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
- fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX];
-
- lb_index0 = ip4_fib_table_lookup_lb (ip4_fib_get(fib_index0),
- &ip0->dst_address);
- lb_index1 = ip4_fib_table_lookup_lb (ip4_fib_get(fib_index1),
- &ip1->dst_address);
+ fib_index0 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index1 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p1)->sw_if_index[VLIB_RX]);
+ fib_index0 =
+ (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
+ fib_index1 =
+ (vnet_buffer (p1)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index1 : vnet_buffer (p1)->sw_if_index[VLIB_TX];
+
+ lb_index0 = ip4_fib_table_lookup_lb (ip4_fib_get (fib_index0),
+ &ip0->dst_address);
+ lb_index1 = ip4_fib_table_lookup_lb (ip4_fib_get (fib_index1),
+ &ip1->dst_address);
lb0 = load_balance_get (lb_index0);
lb1 = load_balance_get (lb_index1);
ASSERT (lb0->lb_n_buckets > 0);
ASSERT (is_pow2 (lb0->lb_n_buckets));
- ASSERT (lb1->lb_n_buckets > 0);
+ ASSERT (lb1->lb_n_buckets > 0);
ASSERT (is_pow2 (lb1->lb_n_buckets));
vnet_buffer (p0)->ip.flow_hash = ip4_compute_flow_hash
- (ip0, lb0->lb_hash_config);
+ (ip0, lb0->lb_hash_config);
vnet_buffer (p1)->ip.flow_hash = ip4_compute_flow_hash
- (ip1, lb1->lb_hash_config);
+ (ip1, lb1->lb_hash_config);
- dpo0 = load_balance_get_bucket_i(lb0,
- (vnet_buffer (p0)->ip.flow_hash &
- (lb0->lb_n_buckets_minus_1)));
- dpo1 = load_balance_get_bucket_i(lb1,
- (vnet_buffer (p1)->ip.flow_hash &
- (lb1->lb_n_buckets_minus_1)));
+ dpo0 = load_balance_get_bucket_i (lb0,
+ (vnet_buffer (p0)->ip.flow_hash &
+ (lb0->lb_n_buckets_minus_1)));
+ dpo1 = load_balance_get_bucket_i (lb1,
+ (vnet_buffer (p1)->ip.flow_hash &
+ (lb1->lb_n_buckets_minus_1)));
next0 = dpo0->dpoi_next_node;
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
next1 = dpo1->dpoi_next_node;
vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
- if (1) /* $$$$$$ HACK FIXME */
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index0, 1,
- vlib_buffer_length_in_chain (vm, p0));
- if (1) /* $$$$$$ HACK FIXME */
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index1, 1,
- vlib_buffer_length_in_chain (vm, p1));
+ if (1) /* $$$$$$ HACK FIXME */
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index0, 1,
+ vlib_buffer_length_in_chain (vm, p0));
+ if (1) /* $$$$$$ HACK FIXME */
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index1, 1,
+ vlib_buffer_length_in_chain (vm, p1));
from += 2;
to_next += 2;
n_left_to_next -= 2;
n_left_from -= 2;
- wrong_next = (next0 != next) + 2*(next1 != next);
+ wrong_next = (next0 != next) + 2 * (next1 != next);
if (PREDICT_FALSE (wrong_next != 0))
{
switch (wrong_next)
@@ -2827,7 +2861,8 @@ ip4_lookup_multicast (vlib_main_t * vm,
/* A B B */
vlib_put_next_frame (vm, node, next, n_left_to_next);
next = next1;
- vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next,
+ n_left_to_next);
}
}
}
@@ -2835,13 +2870,13 @@ ip4_lookup_multicast (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
u32 pi0, lb_index0;
ip_lookup_next_t next0;
- u32 fib_index0;
+ u32 fib_index0;
const dpo_id_t *dpo0;
- const load_balance_t * lb0;
+ const load_balance_t *lb0;
pi0 = from[0];
to_next[0] = pi0;
@@ -2851,12 +2886,12 @@ ip4_lookup_multicast (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index0 = (vnet_buffer (p0)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
+ fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
- lb_index0 = ip4_fib_table_lookup_lb (ip4_fib_get(fib_index0),
- &ip0->dst_address);
+ lb_index0 = ip4_fib_table_lookup_lb (ip4_fib_get (fib_index0),
+ &ip0->dst_address);
lb0 = load_balance_get (lb_index0);
@@ -2864,19 +2899,19 @@ ip4_lookup_multicast (vlib_main_t * vm,
ASSERT (is_pow2 (lb0->lb_n_buckets));
vnet_buffer (p0)->ip.flow_hash = ip4_compute_flow_hash
- (ip0, lb0->lb_hash_config);
+ (ip0, lb0->lb_hash_config);
- dpo0 = load_balance_get_bucket_i(lb0,
- (vnet_buffer (p0)->ip.flow_hash &
- (lb0->lb_n_buckets_minus_1)));
+ dpo0 = load_balance_get_bucket_i (lb0,
+ (vnet_buffer (p0)->ip.flow_hash &
+ (lb0->lb_n_buckets_minus_1)));
next0 = dpo0->dpoi_next_node;
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
- if (1) /* $$$$$$ HACK FIXME */
- vlib_increment_combined_counter
- (cm, cpu_index, lb_index0, 1,
- vlib_buffer_length_in_chain (vm, p0));
+ if (1) /* $$$$$$ HACK FIXME */
+ vlib_increment_combined_counter
+ (cm, cpu_index, lb_index0, 1,
+ vlib_buffer_length_in_chain (vm, p0));
from += 1;
to_next += 1;
@@ -2888,8 +2923,7 @@ ip4_lookup_multicast (vlib_main_t * vm,
n_left_to_next += 1;
vlib_put_next_frame (vm, node, next, n_left_to_next);
next = next0;
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
to_next[0] = pi0;
to_next += 1;
n_left_to_next -= 1;
@@ -2900,39 +2934,33 @@ ip4_lookup_multicast (vlib_main_t * vm,
}
if (node->flags & VLIB_NODE_FLAG_TRACE)
- ip4_forward_next_trace(vm, node, frame, VLIB_TX);
+ ip4_forward_next_trace (vm, node, frame, VLIB_TX);
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip4_lookup_multicast_node,static) = {
- .function = ip4_lookup_multicast,
- .name = "ip4-lookup-multicast",
- .vector_size = sizeof (u32),
- .sibling_of = "ip4-lookup",
- .format_trace = format_ip4_lookup_trace,
-
- .n_next_nodes = 0,
-};
-
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_lookup_multicast_node, ip4_lookup_multicast)
-
-VLIB_REGISTER_NODE (ip4_multicast_node,static) = {
- .function = ip4_drop,
- .name = "ip4-multicast",
- .vector_size = sizeof (u32),
+VLIB_REGISTER_NODE (ip4_lookup_multicast_node, static) =
+{
+.function = ip4_lookup_multicast,.name =
+ "ip4-lookup-multicast",.vector_size = sizeof (u32),.sibling_of =
+ "ip4-lookup",.format_trace = format_ip4_lookup_trace,.n_next_nodes = 0,};
- .format_trace = format_ip4_forward_next_trace,
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_lookup_multicast_node,
+ ip4_lookup_multicast);
- .n_next_nodes = 1,
- .next_nodes = {
- [0] = "error-drop",
- },
-};
+VLIB_REGISTER_NODE (ip4_multicast_node, static) =
+{
+ .function = ip4_drop,.name = "ip4-multicast",.vector_size =
+ sizeof (u32),.format_trace = format_ip4_forward_next_trace,.n_next_nodes =
+ 1,.next_nodes =
+ {
+ [0] = "error-drop",}
+,};
-int ip4_lookup_validate (ip4_address_t *a, u32 fib_index0)
+int
+ip4_lookup_validate (ip4_address_t * a, u32 fib_index0)
{
- ip4_fib_mtrie_t * mtrie0;
+ ip4_fib_mtrie_t *mtrie0;
ip4_fib_mtrie_leaf_t leaf0;
u32 lbi0;
@@ -2949,13 +2977,12 @@ int ip4_lookup_validate (ip4_address_t *a, u32 fib_index0)
lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- return lbi0 == ip4_fib_table_lookup_lb (ip4_fib_get(fib_index0), a);
+ return lbi0 == ip4_fib_table_lookup_lb (ip4_fib_get (fib_index0), a);
}
static clib_error_t *
test_lookup_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
ip4_fib_t *fib;
u32 table_id = 0;
@@ -2965,36 +2992,37 @@ test_lookup_command_fn (vlib_main_t * vm,
ip4_address_t ip4_base_address;
u64 errors = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
if (unformat (input, "table %d", &table_id))
- {
- /* Make sure the entry exists. */
- fib = ip4_fib_get(table_id);
- if ((fib) && (fib->index != table_id))
- return clib_error_return (0, "<fib-index> %d does not exist",
- table_id);
- }
+ {
+ /* Make sure the entry exists. */
+ fib = ip4_fib_get (table_id);
+ if ((fib) && (fib->index != table_id))
+ return clib_error_return (0, "<fib-index> %d does not exist",
+ table_id);
+ }
else if (unformat (input, "count %f", &count))
;
else if (unformat (input, "%U",
unformat_ip4_address, &ip4_base_address))
- ;
+ ;
else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
- }
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
n = count;
for (i = 0; i < n; i++)
{
if (!ip4_lookup_validate (&ip4_base_address, table_id))
- errors++;
+ errors++;
ip4_base_address.as_u32 =
- clib_host_to_net_u32 (1 +
- clib_net_to_host_u32 (ip4_base_address.as_u32));
+ clib_host_to_net_u32 (1 +
+ clib_net_to_host_u32 (ip4_base_address.as_u32));
}
if (errors)
@@ -3023,18 +3051,20 @@ test_lookup_command_fn (vlib_main_t * vm,
* @cliexend
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lookup_test_command, static) = {
- .path = "test lookup",
- .short_help = "test lookup <ipv4-addr> [table <fib-id>] [count <nn>]",
- .function = test_lookup_command_fn,
+VLIB_CLI_COMMAND (lookup_test_command, static) =
+{
+ .path = "test lookup",
+ .short_help = "test lookup <ipv4-addr> [table <fib-id>] [count <nn>]",
+ .function = test_lookup_command_fn,
};
/* *INDENT-ON* */
-int vnet_set_ip4_flow_hash (u32 table_id, u32 flow_hash_config)
+int
+vnet_set_ip4_flow_hash (u32 table_id, u32 flow_hash_config)
{
- ip4_main_t * im4 = &ip4_main;
- ip4_fib_t * fib;
- uword * p = hash_get (im4->fib_index_by_table_id, table_id);
+ ip4_main_t *im4 = &ip4_main;
+ ip4_fib_t *fib;
+ uword *p = hash_get (im4->fib_index_by_table_id, table_id);
if (p == 0)
return VNET_API_ERROR_NO_SUCH_FIB;
@@ -3047,27 +3077,29 @@ int vnet_set_ip4_flow_hash (u32 table_id, u32 flow_hash_config)
static clib_error_t *
set_ip_flow_hash_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
int matched = 0;
u32 table_id = 0;
u32 flow_hash_config = 0;
int rv;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "table %d", &table_id))
- matched = 1;
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "table %d", &table_id))
+ matched = 1;
#define _(a,v) \
else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
- foreach_flow_hash_bit
+ foreach_flow_hash_bit
#undef _
- else break;
- }
+ else
+ break;
+ }
if (matched == 0)
return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
switch (rv)
@@ -3170,7 +3202,8 @@ set_ip_flow_hash_command_fn (vlib_main_t * vm,
* @cliexend
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_ip_flow_hash_command, static) = {
+VLIB_CLI_COMMAND (set_ip_flow_hash_command, static) =
+{
.path = "set ip flow-hash",
.short_help =
"set ip flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
@@ -3178,14 +3211,15 @@ VLIB_CLI_COMMAND (set_ip_flow_hash_command, static) = {
};
/* *INDENT-ON* */
-int vnet_set_ip4_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
- u32 table_index)
+int
+vnet_set_ip4_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
+ u32 table_index)
{
- vnet_main_t * vnm = vnet_get_main();
- vnet_interface_main_t * im = &vnm->interface_main;
- ip4_main_t * ipm = &ip4_main;
- ip_lookup_main_t * lm = &ipm->lookup_main;
- vnet_classify_main_t * cm = &vnet_classify_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_interface_main_t *im = &vnm->interface_main;
+ ip4_main_t *ipm = &ip4_main;
+ ip_lookup_main_t *lm = &ipm->lookup_main;
+ vnet_classify_main_t *cm = &vnet_classify_main;
ip4_address_t *if_addr;
if (pool_is_free_index (im->sw_interfaces, sw_if_index))
@@ -3195,69 +3229,68 @@ int vnet_set_ip4_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
return VNET_API_ERROR_NO_SUCH_ENTRY;
vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
- lm->classify_table_index_by_sw_if_index [sw_if_index] = table_index;
+ lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
if_addr = ip4_interface_first_address (ipm, sw_if_index, NULL);
if (NULL != if_addr)
- {
+ {
fib_prefix_t pfx = {
- .fp_len = 32,
- .fp_proto = FIB_PROTOCOL_IP4,
- .fp_addr.ip4 = *if_addr,
+ .fp_len = 32,
+ .fp_proto = FIB_PROTOCOL_IP4,
+ .fp_addr.ip4 = *if_addr,
};
u32 fib_index;
- fib_index = fib_table_get_index_for_sw_if_index(FIB_PROTOCOL_IP4,
- sw_if_index);
+ fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
+ sw_if_index);
- if (table_index != (u32) ~0)
- {
- dpo_id_t dpo = DPO_INVALID;
-
- dpo_set(&dpo,
- DPO_CLASSIFY,
- DPO_PROTO_IP4,
- classify_dpo_create(DPO_PROTO_IP4, table_index));
-
- fib_table_entry_special_dpo_add(fib_index,
- &pfx,
- FIB_SOURCE_CLASSIFY,
- FIB_ENTRY_FLAG_NONE,
- &dpo);
- dpo_reset(&dpo);
- }
+ if (table_index != (u32) ~ 0)
+ {
+ dpo_id_t dpo = DPO_INVALID;
+
+ dpo_set (&dpo,
+ DPO_CLASSIFY,
+ DPO_PROTO_IP4,
+ classify_dpo_create (DPO_PROTO_IP4, table_index));
+
+ fib_table_entry_special_dpo_add (fib_index,
+ &pfx,
+ FIB_SOURCE_CLASSIFY,
+ FIB_ENTRY_FLAG_NONE, &dpo);
+ dpo_reset (&dpo);
+ }
else
- {
- fib_table_entry_special_remove(fib_index,
- &pfx,
- FIB_SOURCE_CLASSIFY);
- }
- }
+ {
+ fib_table_entry_special_remove (fib_index,
+ &pfx, FIB_SOURCE_CLASSIFY);
+ }
+ }
return 0;
}
static clib_error_t *
set_ip_classify_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
u32 table_index = ~0;
int table_index_set = 0;
u32 sw_if_index = ~0;
int rv;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "table-index %d", &table_index))
- table_index_set = 1;
- else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
- vnet_get_main(), &sw_if_index))
- ;
- else
- break;
- }
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "table-index %d", &table_index))
+ table_index_set = 1;
+ else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
+ vnet_get_main (), &sw_if_index))
+ ;
+ else
+ break;
+ }
if (table_index_set == 0)
return clib_error_return (0, "classify table-index must be specified");
@@ -3292,10 +3325,19 @@ set_ip_classify_command_fn (vlib_main_t * vm,
* @cliexcmd{set ip classify intfc GigabitEthernet2/0/0 table-index 1}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_ip_classify_command, static) = {
+VLIB_CLI_COMMAND (set_ip_classify_command, static) =
+{
.path = "set ip classify",
.short_help =
"set ip classify intfc <interface> table-index <classify-idx>",
.function = set_ip_classify_command_fn,
};
/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_input.c b/vnet/vnet/ip/ip4_input.c
index a3620de8b42..69b1e5a83d2 100644
--- a/vnet/vnet/ip/ip4_input.c
+++ b/vnet/vnet/ip/ip4_input.c
@@ -42,24 +42,26 @@
#include <vnet/ppp/ppp.h>
#include <vnet/hdlc/hdlc.h>
-typedef struct {
+typedef struct
+{
u8 packet_data[64];
} ip4_input_trace_t;
-static u8 * format_ip4_input_trace (u8 * s, va_list * va)
+static u8 *
+format_ip4_input_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
- ip4_input_trace_t * t = va_arg (*va, ip4_input_trace_t *);
+ ip4_input_trace_t *t = va_arg (*va, ip4_input_trace_t *);
s = format (s, "%U",
- format_ip4_header,
- t->packet_data, sizeof (t->packet_data));
+ format_ip4_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-typedef enum {
+typedef enum
+{
IP4_INPUT_NEXT_DROP,
IP4_INPUT_NEXT_PUNT,
IP4_INPUT_NEXT_LOOKUP,
@@ -73,17 +75,17 @@ typedef enum {
always_inline uword
ip4_input_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- int verify_checksum)
+ vlib_frame_t * frame, int verify_checksum)
{
- ip4_main_t * im = &ip4_main;
- vnet_main_t * vnm = vnet_get_main();
- ip_lookup_main_t * lm = &im->lookup_main;
- u32 n_left_from, * from, * to_next;
+ ip4_main_t *im = &ip4_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip_lookup_main_t *lm = &im->lookup_main;
+ u32 n_left_from, *from, *to_next;
ip4_input_next_t next_index;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip4_input_node.index);
- vlib_simple_counter_main_t * cm;
- u32 cpu_index = os_get_cpu_number();
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip4_input_node.index);
+ vlib_simple_counter_main_t *cm;
+ u32 cpu_index = os_get_cpu_number ();
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -95,19 +97,18 @@ ip4_input_inline (vlib_main_t * vm,
sizeof (ip4_input_trace_t));
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
- VNET_INTERFACE_COUNTER_IP4);
+ VNET_INTERFACE_COUNTER_IP4);
while (n_left_from > 0)
{
u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- vlib_buffer_t * p0, * p1;
- ip4_header_t * ip0, * ip1;
+ vlib_buffer_t *p0, *p1;
+ ip4_header_t *ip0, *ip1;
u32 sw_if_index0, pi0, ip_len0, cur_len0, next0 = 0;
u32 sw_if_index1, pi1, ip_len1, cur_len1, next1 = 0;
i32 len_diff0, len_diff1;
@@ -115,7 +116,7 @@ ip4_input_inline (vlib_main_t * vm,
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -143,8 +144,12 @@ ip4_input_inline (vlib_main_t * vm,
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
sw_if_index1 = vnet_buffer (p1)->sw_if_index[VLIB_RX];
- arc0 = ip4_address_is_multicast (&ip0->dst_address) ? lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
- arc1 = ip4_address_is_multicast (&ip1->dst_address) ? lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
+ arc0 =
+ ip4_address_is_multicast (&ip0->dst_address) ?
+ lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
+ arc1 =
+ ip4_address_is_multicast (&ip1->dst_address) ?
+ lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
vnet_buffer (p0)->ip.adj_index[VLIB_RX] = ~0;
vnet_buffer (p1)->ip.adj_index[VLIB_RX] = ~0;
@@ -158,12 +163,20 @@ ip4_input_inline (vlib_main_t * vm,
error0 = error1 = IP4_ERROR_NONE;
/* Punt packets with options. */
- error0 = (ip0->ip_version_and_header_length & 0xf) != 5 ? IP4_ERROR_OPTIONS : error0;
- error1 = (ip1->ip_version_and_header_length & 0xf) != 5 ? IP4_ERROR_OPTIONS : error1;
+ error0 =
+ (ip0->ip_version_and_header_length & 0xf) !=
+ 5 ? IP4_ERROR_OPTIONS : error0;
+ error1 =
+ (ip1->ip_version_and_header_length & 0xf) !=
+ 5 ? IP4_ERROR_OPTIONS : error1;
/* Version != 4? Drop it. */
- error0 = (ip0->ip_version_and_header_length >> 4) != 4 ? IP4_ERROR_VERSION : error0;
- error1 = (ip1->ip_version_and_header_length >> 4) != 4 ? IP4_ERROR_VERSION : error1;
+ error0 =
+ (ip0->ip_version_and_header_length >> 4) !=
+ 4 ? IP4_ERROR_VERSION : error0;
+ error1 =
+ (ip1->ip_version_and_header_length >> 4) !=
+ 4 ? IP4_ERROR_VERSION : error1;
/* Verify header checksum. */
if (verify_checksum)
@@ -173,17 +186,31 @@ ip4_input_inline (vlib_main_t * vm,
ip4_partial_header_checksum_x1 (ip0, sum0);
ip4_partial_header_checksum_x1 (ip1, sum1);
- error0 = 0xffff != ip_csum_fold (sum0) ? IP4_ERROR_BAD_CHECKSUM : error0;
- error1 = 0xffff != ip_csum_fold (sum1) ? IP4_ERROR_BAD_CHECKSUM : error1;
+ error0 =
+ 0xffff !=
+ ip_csum_fold (sum0) ? IP4_ERROR_BAD_CHECKSUM : error0;
+ error1 =
+ 0xffff !=
+ ip_csum_fold (sum1) ? IP4_ERROR_BAD_CHECKSUM : error1;
}
/* Drop fragmentation offset 1 packets. */
- error0 = ip4_get_fragment_offset (ip0) == 1 ? IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
- error1 = ip4_get_fragment_offset (ip1) == 1 ? IP4_ERROR_FRAGMENT_OFFSET_ONE : error1;
+ error0 =
+ ip4_get_fragment_offset (ip0) ==
+ 1 ? IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
+ error1 =
+ ip4_get_fragment_offset (ip1) ==
+ 1 ? IP4_ERROR_FRAGMENT_OFFSET_ONE : error1;
/* TTL < 1? Drop it. */
- error0 = (ip0->ttl < 1 && arc0 == lm->ucast_feature_arc_index) ? IP4_ERROR_TIME_EXPIRED : error0;
- error1 = (ip1->ttl < 1 && arc1 == lm->ucast_feature_arc_index) ? IP4_ERROR_TIME_EXPIRED : error1;
+ error0 = (ip0->ttl < 1
+ && arc0 ==
+ lm->ucast_feature_arc_index) ? IP4_ERROR_TIME_EXPIRED :
+ error0;
+ error1 = (ip1->ttl < 1
+ && arc1 ==
+ lm->ucast_feature_arc_index) ? IP4_ERROR_TIME_EXPIRED :
+ error1;
/* Verify lengths. */
ip_len0 = clib_net_to_host_u16 (ip0->length);
@@ -205,33 +232,45 @@ ip4_input_inline (vlib_main_t * vm,
p0->error = error_node->errors[error0];
p1->error = error_node->errors[error1];
- if (PREDICT_FALSE(error0 != IP4_ERROR_NONE))
- {
- if (error0 == IP4_ERROR_TIME_EXPIRED) {
- icmp4_error_set_vnet_buffer(p0, ICMP4_time_exceeded,
- ICMP4_time_exceeded_ttl_exceeded_in_transit, 0);
- next0 = IP4_INPUT_NEXT_ICMP_ERROR;
- } else
- next0 = error0 != IP4_ERROR_OPTIONS ? IP4_INPUT_NEXT_DROP : IP4_INPUT_NEXT_PUNT;
- }
- if (PREDICT_FALSE(error1 != IP4_ERROR_NONE))
- {
- if (error1 == IP4_ERROR_TIME_EXPIRED) {
- icmp4_error_set_vnet_buffer(p1, ICMP4_time_exceeded,
- ICMP4_time_exceeded_ttl_exceeded_in_transit, 0);
- next1 = IP4_INPUT_NEXT_ICMP_ERROR;
- } else
- next1 = error1 != IP4_ERROR_OPTIONS ? IP4_INPUT_NEXT_DROP : IP4_INPUT_NEXT_PUNT;
- }
+ if (PREDICT_FALSE (error0 != IP4_ERROR_NONE))
+ {
+ if (error0 == IP4_ERROR_TIME_EXPIRED)
+ {
+ icmp4_error_set_vnet_buffer (p0, ICMP4_time_exceeded,
+ ICMP4_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next0 = IP4_INPUT_NEXT_ICMP_ERROR;
+ }
+ else
+ next0 =
+ error0 !=
+ IP4_ERROR_OPTIONS ? IP4_INPUT_NEXT_DROP :
+ IP4_INPUT_NEXT_PUNT;
+ }
+ if (PREDICT_FALSE (error1 != IP4_ERROR_NONE))
+ {
+ if (error1 == IP4_ERROR_TIME_EXPIRED)
+ {
+ icmp4_error_set_vnet_buffer (p1, ICMP4_time_exceeded,
+ ICMP4_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next1 = IP4_INPUT_NEXT_ICMP_ERROR;
+ }
+ else
+ next1 =
+ error1 !=
+ IP4_ERROR_OPTIONS ? IP4_INPUT_NEXT_DROP :
+ IP4_INPUT_NEXT_PUNT;
+ }
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
pi0, pi1, next0, next1);
- }
+ }
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
u32 sw_if_index0, pi0, ip_len0, cur_len0, next0 = 0;
i32 len_diff0;
u8 error0, arc0;
@@ -248,7 +287,9 @@ ip4_input_inline (vlib_main_t * vm,
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
- arc0 = ip4_address_is_multicast (&ip0->dst_address) ? lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
+ arc0 =
+ ip4_address_is_multicast (&ip0->dst_address) ?
+ lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
vnet_buffer (p0)->ip.adj_index[VLIB_RX] = ~0;
vnet_feature_arc_start (arc0, sw_if_index0, &next0, p0);
@@ -257,10 +298,14 @@ ip4_input_inline (vlib_main_t * vm,
error0 = IP4_ERROR_NONE;
/* Punt packets with options. */
- error0 = (ip0->ip_version_and_header_length & 0xf) != 5 ? IP4_ERROR_OPTIONS : error0;
+ error0 =
+ (ip0->ip_version_and_header_length & 0xf) !=
+ 5 ? IP4_ERROR_OPTIONS : error0;
/* Version != 4? Drop it. */
- error0 = (ip0->ip_version_and_header_length >> 4) != 4 ? IP4_ERROR_VERSION : error0;
+ error0 =
+ (ip0->ip_version_and_header_length >> 4) !=
+ 4 ? IP4_ERROR_VERSION : error0;
/* Verify header checksum. */
if (verify_checksum)
@@ -268,14 +313,21 @@ ip4_input_inline (vlib_main_t * vm,
ip_csum_t sum0;
ip4_partial_header_checksum_x1 (ip0, sum0);
- error0 = 0xffff != ip_csum_fold (sum0) ? IP4_ERROR_BAD_CHECKSUM : error0;
+ error0 =
+ 0xffff !=
+ ip_csum_fold (sum0) ? IP4_ERROR_BAD_CHECKSUM : error0;
}
/* Drop fragmentation offset 1 packets. */
- error0 = ip4_get_fragment_offset (ip0) == 1 ? IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
+ error0 =
+ ip4_get_fragment_offset (ip0) ==
+ 1 ? IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
/* TTL < 1? Drop it. */
- error0 = (ip0->ttl < 1 && arc0 == lm->ucast_feature_arc_index) ? IP4_ERROR_TIME_EXPIRED : error0;
+ error0 = (ip0->ttl < 1
+ && arc0 ==
+ lm->ucast_feature_arc_index) ? IP4_ERROR_TIME_EXPIRED :
+ error0;
/* Verify lengths. */
ip_len0 = clib_net_to_host_u16 (ip0->length);
@@ -288,15 +340,21 @@ ip4_input_inline (vlib_main_t * vm,
error0 = len_diff0 < 0 ? IP4_ERROR_BAD_LENGTH : error0;
p0->error = error_node->errors[error0];
- if (PREDICT_FALSE(error0 != IP4_ERROR_NONE))
- {
- if (error0 == IP4_ERROR_TIME_EXPIRED) {
- icmp4_error_set_vnet_buffer(p0, ICMP4_time_exceeded,
- ICMP4_time_exceeded_ttl_exceeded_in_transit, 0);
- next0 = IP4_INPUT_NEXT_ICMP_ERROR;
- } else
- next0 = error0 != IP4_ERROR_OPTIONS ? IP4_INPUT_NEXT_DROP : IP4_INPUT_NEXT_PUNT;
- }
+ if (PREDICT_FALSE (error0 != IP4_ERROR_NONE))
+ {
+ if (error0 == IP4_ERROR_TIME_EXPIRED)
+ {
+ icmp4_error_set_vnet_buffer (p0, ICMP4_time_exceeded,
+ ICMP4_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next0 = IP4_INPUT_NEXT_ICMP_ERROR;
+ }
+ else
+ next0 =
+ error0 !=
+ IP4_ERROR_OPTIONS ? IP4_INPUT_NEXT_DROP :
+ IP4_INPUT_NEXT_PUNT;
+ }
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
@@ -324,10 +382,10 @@ ip4_input_inline (vlib_main_t * vm,
@par Graph mechanics: buffer metadata, next index usage
@em Uses:
- - vnet_feature_config_main_t cm corresponding to each pkt's dst address unicast /
+ - vnet_feature_config_main_t cm corresponding to each pkt's dst address unicast /
multicast status.
- <code>b->current_config_index</code> corresponding to each pkt's
- rx sw_if_index.
+ rx sw_if_index.
- This sets the per-packet graph trajectory, ensuring that
each packet visits the per-interface features in order.
@@ -342,30 +400,28 @@ ip4_input_inline (vlib_main_t * vm,
<em>Next Indices:</em>
- Dispatches pkts to the (first) feature node:
<code> vnet_get_config_data (... &next0 ...); </code>
- or @c error-drop
+ or @c error-drop
*/
static uword
-ip4_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip4_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip4_input_inline (vm, node, frame, /* verify_checksum */ 1);
}
static uword
ip4_input_no_checksum (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip4_input_inline (vm, node, frame, /* verify_checksum */ 0);
}
-static char * ip4_error_strings[] = {
+static char *ip4_error_strings[] = {
#define _(sym,string) string,
foreach_ip4_error
#undef _
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_input_node) = {
.function = ip4_input,
.name = "ip4-input",
@@ -386,9 +442,11 @@ VLIB_REGISTER_NODE (ip4_input_node) = {
.format_buffer = format_ip4_header,
.format_trace = format_ip4_input_trace,
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_input_node, ip4_input)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_input_node, ip4_input);
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_input_no_checksum_node,static) = {
.function = ip4_input_no_checksum,
.name = "ip4-input-no-checksum",
@@ -406,22 +464,22 @@ VLIB_REGISTER_NODE (ip4_input_no_checksum_node,static) = {
.format_buffer = format_ip4_header,
.format_trace = format_ip4_input_trace,
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_input_no_checksum_node, ip4_input_no_checksum)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_input_no_checksum_node,
+ ip4_input_no_checksum);
-static clib_error_t * ip4_init (vlib_main_t * vm)
+static clib_error_t *
+ip4_init (vlib_main_t * vm)
{
- clib_error_t * error;
+ clib_error_t *error;
- ethernet_register_input_type (vm, ETHERNET_TYPE_IP4,
- ip4_input_node.index);
- ppp_register_input_protocol (vm, PPP_PROTOCOL_ip4,
- ip4_input_node.index);
- hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip4,
- ip4_input_node.index);
+ ethernet_register_input_type (vm, ETHERNET_TYPE_IP4, ip4_input_node.index);
+ ppp_register_input_protocol (vm, PPP_PROTOCOL_ip4, ip4_input_node.index);
+ hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip4, ip4_input_node.index);
{
- pg_node_t * pn;
+ pg_node_t *pn;
pn = pg_get_node (ip4_input_node.index);
pn->unformat_edit = unformat_pg_ip4_header;
pn = pg_get_node (ip4_input_no_checksum_node.index);
@@ -434,7 +492,7 @@ static clib_error_t * ip4_init (vlib_main_t * vm)
if ((error = vlib_call_init_function (vm, ip4_source_check_init)))
return error;
- if ((error = vlib_call_init_function
+ if ((error = vlib_call_init_function
(vm, ip4_source_and_port_range_check_init)))
return error;
@@ -448,3 +506,11 @@ static clib_error_t * ip4_init (vlib_main_t * vm)
}
VLIB_INIT_FUNCTION (ip4_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_mtrie.c b/vnet/vnet/ip/ip4_mtrie.c
index 364182415ba..6e3d0e8068b 100644
--- a/vnet/vnet/ip/ip4_mtrie.c
+++ b/vnet/vnet/ip/ip4_mtrie.c
@@ -41,15 +41,18 @@
#include <vnet/fib/fib_entry.h>
static void
-ply_init (ip4_fib_mtrie_ply_t * p, ip4_fib_mtrie_leaf_t init, uword prefix_len)
+ply_init (ip4_fib_mtrie_ply_t * p, ip4_fib_mtrie_leaf_t init,
+ uword prefix_len)
{
- p->n_non_empty_leafs = ip4_fib_mtrie_leaf_is_empty (init) ? 0 : ARRAY_LEN (p->leaves);
- memset (p->dst_address_bits_of_leaves, prefix_len, sizeof (p->dst_address_bits_of_leaves));
+ p->n_non_empty_leafs =
+ ip4_fib_mtrie_leaf_is_empty (init) ? 0 : ARRAY_LEN (p->leaves);
+ memset (p->dst_address_bits_of_leaves, prefix_len,
+ sizeof (p->dst_address_bits_of_leaves));
/* Initialize leaves. */
#ifdef CLIB_HAVE_VEC128
{
- u32x4 * l, init_x4;
+ u32x4 *l, init_x4;
#ifndef __ALTIVEC__
init_x4 = u32x4_splat (init);
@@ -62,9 +65,10 @@ ply_init (ip4_fib_mtrie_ply_t * p, ip4_fib_mtrie_leaf_t init, uword prefix_len)
y.as_u32[3] = init;
init_x4 = y.as_u32x4;
}
-#endif
+#endif
- for (l = p->leaves_as_u32x4; l < p->leaves_as_u32x4 + ARRAY_LEN (p->leaves_as_u32x4); l += 4)
+ for (l = p->leaves_as_u32x4;
+ l < p->leaves_as_u32x4 + ARRAY_LEN (p->leaves_as_u32x4); l += 4)
{
l[0] = init_x4;
l[1] = init_x4;
@@ -74,7 +78,7 @@ ply_init (ip4_fib_mtrie_ply_t * p, ip4_fib_mtrie_leaf_t init, uword prefix_len)
}
#else
{
- u32 * l;
+ u32 *l;
for (l = p->leaves; l < p->leaves + ARRAY_LEN (p->leaves); l += 4)
{
@@ -88,9 +92,10 @@ ply_init (ip4_fib_mtrie_ply_t * p, ip4_fib_mtrie_leaf_t init, uword prefix_len)
}
static ip4_fib_mtrie_leaf_t
-ply_create (ip4_fib_mtrie_t * m, ip4_fib_mtrie_leaf_t init_leaf, uword prefix_len)
+ply_create (ip4_fib_mtrie_t * m, ip4_fib_mtrie_leaf_t init_leaf,
+ uword prefix_len)
{
- ip4_fib_mtrie_ply_t * p;
+ ip4_fib_mtrie_ply_t *p;
/* Get cache aligned ply. */
pool_get_aligned (m->ply_pool, p, sizeof (p[0]));
@@ -115,12 +120,12 @@ ply_free (ip4_fib_mtrie_t * m, ip4_fib_mtrie_ply_t * p)
is_root = p - m->ply_pool == 0;
- for (i = 0 ; i < ARRAY_LEN (p->leaves); i++)
+ for (i = 0; i < ARRAY_LEN (p->leaves); i++)
{
ip4_fib_mtrie_leaf_t l = p->leaves[i];
if (ip4_fib_mtrie_leaf_is_next_ply (l))
ply_free (m, get_next_ply_for_leaf (m, l));
- }
+ }
if (is_root)
ply_init (p, IP4_FIB_MTRIE_LEAF_EMPTY, /* prefix_len */ 0);
@@ -128,15 +133,17 @@ ply_free (ip4_fib_mtrie_t * m, ip4_fib_mtrie_ply_t * p)
pool_put (m->ply_pool, p);
}
-void ip4_fib_free (ip4_fib_mtrie_t * m)
+void
+ip4_fib_free (ip4_fib_mtrie_t * m)
{
- ip4_fib_mtrie_ply_t * root_ply = pool_elt_at_index (m->ply_pool, 0);
+ ip4_fib_mtrie_ply_t *root_ply = pool_elt_at_index (m->ply_pool, 0);
ply_free (m, root_ply);
}
-u32 ip4_mtrie_lookup_address (ip4_fib_mtrie_t * m, ip4_address_t dst)
+u32
+ip4_mtrie_lookup_address (ip4_fib_mtrie_t * m, ip4_address_t dst)
{
- ip4_fib_mtrie_ply_t * p = pool_elt_at_index (m->ply_pool, 0);
+ ip4_fib_mtrie_ply_t *p = pool_elt_at_index (m->ply_pool, 0);
ip4_fib_mtrie_leaf_t l;
l = p->leaves[dst.as_u8[0]];
@@ -160,7 +167,8 @@ u32 ip4_mtrie_lookup_address (ip4_fib_mtrie_t * m, ip4_address_t dst)
return ip4_fib_mtrie_leaf_get_adj_index (l);
}
-typedef struct {
+typedef struct
+{
ip4_address_t dst_address;
u32 dst_address_length;
u32 adj_index;
@@ -176,24 +184,26 @@ set_ply_with_more_specific_leaf (ip4_fib_mtrie_t * m,
uword i;
ASSERT (ip4_fib_mtrie_leaf_is_terminal (new_leaf));
- ASSERT (! ip4_fib_mtrie_leaf_is_empty (new_leaf));
+ ASSERT (!ip4_fib_mtrie_leaf_is_empty (new_leaf));
for (i = 0; i < ARRAY_LEN (ply->leaves); i++)
{
old_leaf = ply->leaves[i];
/* Recurse into sub plies. */
- if (! ip4_fib_mtrie_leaf_is_terminal (old_leaf))
+ if (!ip4_fib_mtrie_leaf_is_terminal (old_leaf))
{
- ip4_fib_mtrie_ply_t * sub_ply = get_next_ply_for_leaf (m, old_leaf);
- set_ply_with_more_specific_leaf (m, sub_ply, new_leaf, new_leaf_dst_address_bits);
+ ip4_fib_mtrie_ply_t *sub_ply = get_next_ply_for_leaf (m, old_leaf);
+ set_ply_with_more_specific_leaf (m, sub_ply, new_leaf,
+ new_leaf_dst_address_bits);
}
/* Replace less specific terminal leaves with new leaf. */
- else if (new_leaf_dst_address_bits >= ply->dst_address_bits_of_leaves[i])
+ else if (new_leaf_dst_address_bits >=
+ ply->dst_address_bits_of_leaves[i])
{
- __sync_val_compare_and_swap (&ply->leaves[i], old_leaf, new_leaf);
- ASSERT(ply->leaves[i] == new_leaf);
+ __sync_val_compare_and_swap (&ply->leaves[i], old_leaf, new_leaf);
+ ASSERT (ply->leaves[i] == new_leaf);
ply->dst_address_bits_of_leaves[i] = new_leaf_dst_address_bits;
ply->n_non_empty_leafs += ip4_fib_mtrie_leaf_is_empty (old_leaf);
}
@@ -203,8 +213,7 @@ set_ply_with_more_specific_leaf (ip4_fib_mtrie_t * m,
static void
set_leaf (ip4_fib_mtrie_t * m,
ip4_fib_mtrie_set_unset_leaf_args_t * a,
- u32 old_ply_index,
- u32 dst_address_byte_index)
+ u32 old_ply_index, u32 dst_address_byte_index)
{
ip4_fib_mtrie_leaf_t old_leaf, new_leaf;
i32 n_dst_bits_next_plies;
@@ -213,7 +222,8 @@ set_leaf (ip4_fib_mtrie_t * m,
ASSERT (a->dst_address_length > 0 && a->dst_address_length <= 32);
ASSERT (dst_address_byte_index < ARRAY_LEN (a->dst_address.as_u8));
- n_dst_bits_next_plies = a->dst_address_length - BITS (u8) * (dst_address_byte_index + 1);
+ n_dst_bits_next_plies =
+ a->dst_address_length - BITS (u8) * (dst_address_byte_index + 1);
dst_byte = a->dst_address.as_u8[dst_address_byte_index];
@@ -223,11 +233,12 @@ set_leaf (ip4_fib_mtrie_t * m,
uword i, n_dst_bits_this_ply, old_leaf_is_terminal;
n_dst_bits_this_ply = -n_dst_bits_next_plies;
- ASSERT ((a->dst_address.as_u8[dst_address_byte_index] & pow2_mask (n_dst_bits_this_ply)) == 0);
+ ASSERT ((a->dst_address.as_u8[dst_address_byte_index] &
+ pow2_mask (n_dst_bits_this_ply)) == 0);
for (i = dst_byte; i < dst_byte + (1 << n_dst_bits_this_ply); i++)
{
- ip4_fib_mtrie_ply_t * old_ply, * new_ply;
+ ip4_fib_mtrie_ply_t *old_ply, *new_ply;
old_ply = pool_elt_at_index (m->ply_pool, old_ply_index);
@@ -241,49 +252,57 @@ set_leaf (ip4_fib_mtrie_t * m,
if (old_leaf_is_terminal)
{
- old_ply->dst_address_bits_of_leaves[i] = a->dst_address_length;
- __sync_val_compare_and_swap (&old_ply->leaves[i], old_leaf,
- new_leaf);
- ASSERT(old_ply->leaves[i] == new_leaf);
- old_ply->n_non_empty_leafs += ip4_fib_mtrie_leaf_is_empty (old_leaf);
- ASSERT (old_ply->n_non_empty_leafs <= ARRAY_LEN (old_ply->leaves));
+ old_ply->dst_address_bits_of_leaves[i] =
+ a->dst_address_length;
+ __sync_val_compare_and_swap (&old_ply->leaves[i], old_leaf,
+ new_leaf);
+ ASSERT (old_ply->leaves[i] == new_leaf);
+ old_ply->n_non_empty_leafs +=
+ ip4_fib_mtrie_leaf_is_empty (old_leaf);
+ ASSERT (old_ply->n_non_empty_leafs <=
+ ARRAY_LEN (old_ply->leaves));
}
else
{
/* Existing leaf points to another ply. We need to place new_leaf into all
more specific slots. */
new_ply = get_next_ply_for_leaf (m, old_leaf);
- set_ply_with_more_specific_leaf (m, new_ply, new_leaf, a->dst_address_length);
+ set_ply_with_more_specific_leaf (m, new_ply, new_leaf,
+ a->dst_address_length);
}
}
- else if (! old_leaf_is_terminal)
+ else if (!old_leaf_is_terminal)
{
new_ply = get_next_ply_for_leaf (m, old_leaf);
- set_leaf (m, a, new_ply - m->ply_pool, dst_address_byte_index + 1);
+ set_leaf (m, a, new_ply - m->ply_pool,
+ dst_address_byte_index + 1);
}
}
}
else
{
- ip4_fib_mtrie_ply_t * old_ply, * new_ply;
+ ip4_fib_mtrie_ply_t *old_ply, *new_ply;
old_ply = pool_elt_at_index (m->ply_pool, old_ply_index);
old_leaf = old_ply->leaves[dst_byte];
if (ip4_fib_mtrie_leaf_is_terminal (old_leaf))
{
- new_leaf = ply_create (m, old_leaf, old_ply->dst_address_bits_of_leaves[dst_byte]);
+ new_leaf =
+ ply_create (m, old_leaf,
+ old_ply->dst_address_bits_of_leaves[dst_byte]);
new_ply = get_next_ply_for_leaf (m, new_leaf);
/* Refetch since ply_create may move pool. */
old_ply = pool_elt_at_index (m->ply_pool, old_ply_index);
- __sync_val_compare_and_swap (&old_ply->leaves[dst_byte], old_leaf,
- new_leaf);
- ASSERT(old_ply->leaves[dst_byte] == new_leaf);
+ __sync_val_compare_and_swap (&old_ply->leaves[dst_byte], old_leaf,
+ new_leaf);
+ ASSERT (old_ply->leaves[dst_byte] == new_leaf);
old_ply->dst_address_bits_of_leaves[dst_byte] = 0;
- old_ply->n_non_empty_leafs -= ip4_fib_mtrie_leaf_is_non_empty (old_leaf);
+ old_ply->n_non_empty_leafs -=
+ ip4_fib_mtrie_leaf_is_non_empty (old_leaf);
ASSERT (old_ply->n_non_empty_leafs >= 0);
/* Account for the ply we just created. */
@@ -299,8 +318,7 @@ set_leaf (ip4_fib_mtrie_t * m,
static uword
unset_leaf (ip4_fib_mtrie_t * m,
ip4_fib_mtrie_set_unset_leaf_args_t * a,
- ip4_fib_mtrie_ply_t * old_ply,
- u32 dst_address_byte_index)
+ ip4_fib_mtrie_ply_t * old_ply, u32 dst_address_byte_index)
{
ip4_fib_mtrie_leaf_t old_leaf, del_leaf;
i32 n_dst_bits_next_plies;
@@ -310,13 +328,15 @@ unset_leaf (ip4_fib_mtrie_t * m,
ASSERT (a->dst_address_length > 0 && a->dst_address_length <= 32);
ASSERT (dst_address_byte_index < ARRAY_LEN (a->dst_address.as_u8));
- n_dst_bits_next_plies = a->dst_address_length - BITS (u8) * (dst_address_byte_index + 1);
+ n_dst_bits_next_plies =
+ a->dst_address_length - BITS (u8) * (dst_address_byte_index + 1);
dst_byte = a->dst_address.as_u8[dst_address_byte_index];
if (n_dst_bits_next_plies < 0)
dst_byte &= ~pow2_mask (-n_dst_bits_next_plies);
- n_dst_bits_this_ply = n_dst_bits_next_plies <= 0 ? -n_dst_bits_next_plies : 0;
+ n_dst_bits_this_ply =
+ n_dst_bits_next_plies <= 0 ? -n_dst_bits_next_plies : 0;
n_dst_bits_this_ply = clib_min (8, n_dst_bits_this_ply);
del_leaf = ip4_fib_mtrie_leaf_set_adj_index (a->adj_index);
@@ -327,14 +347,15 @@ unset_leaf (ip4_fib_mtrie_t * m,
old_leaf_is_terminal = ip4_fib_mtrie_leaf_is_terminal (old_leaf);
if (old_leaf == del_leaf
- || (! old_leaf_is_terminal
- && unset_leaf (m, a, get_next_ply_for_leaf (m, old_leaf), dst_address_byte_index + 1)))
+ || (!old_leaf_is_terminal
+ && unset_leaf (m, a, get_next_ply_for_leaf (m, old_leaf),
+ dst_address_byte_index + 1)))
{
old_ply->leaves[i] = IP4_FIB_MTRIE_LEAF_EMPTY;
old_ply->dst_address_bits_of_leaves[i] = 0;
/* No matter what we just deleted a non-empty leaf. */
- ASSERT (! ip4_fib_mtrie_leaf_is_empty (old_leaf));
+ ASSERT (!ip4_fib_mtrie_leaf_is_empty (old_leaf));
old_ply->n_non_empty_leafs -= 1;
ASSERT (old_ply->n_non_empty_leafs >= 0);
@@ -351,12 +372,14 @@ unset_leaf (ip4_fib_mtrie_t * m,
return 0;
}
-void ip4_mtrie_init (ip4_fib_mtrie_t * m)
+void
+ip4_mtrie_init (ip4_fib_mtrie_t * m)
{
ip4_fib_mtrie_leaf_t root;
memset (m, 0, sizeof (m[0]));
m->default_leaf = IP4_FIB_MTRIE_LEAF_EMPTY;
- root = ply_create (m, IP4_FIB_MTRIE_LEAF_EMPTY, /* dst_address_bits_of_leaves */ 0);
+ root = ply_create (m, IP4_FIB_MTRIE_LEAF_EMPTY, /* dst_address_bits_of_leaves */
+ 0);
ASSERT (ip4_fib_mtrie_leaf_get_next_ply_index (root) == 0);
}
@@ -364,15 +387,14 @@ void
ip4_fib_mtrie_add_del_route (ip4_fib_t * fib,
ip4_address_t dst_address,
u32 dst_address_length,
- u32 adj_index,
- u32 is_del)
+ u32 adj_index, u32 is_del)
{
- ip4_fib_mtrie_t * m = &fib->mtrie;
- ip4_fib_mtrie_ply_t * root_ply;
+ ip4_fib_mtrie_t *m = &fib->mtrie;
+ ip4_fib_mtrie_ply_t *root_ply;
ip4_fib_mtrie_set_unset_leaf_args_t a;
- ip4_main_t * im = &ip4_main;
+ ip4_main_t *im = &ip4_main;
- ASSERT(m->ply_pool != 0);
+ ASSERT (m->ply_pool != 0);
root_ply = pool_elt_at_index (m->ply_pool, 0);
@@ -382,7 +404,7 @@ ip4_fib_mtrie_add_del_route (ip4_fib_t * fib,
a.dst_address_length = dst_address_length;
a.adj_index = adj_index;
- if (! is_del)
+ if (!is_del)
{
if (dst_address_length == 0)
m->default_leaf = ip4_fib_mtrie_leaf_set_adj_index (adj_index);
@@ -396,7 +418,7 @@ ip4_fib_mtrie_add_del_route (ip4_fib_t * fib,
else
{
- ip4_main_t * im = &ip4_main;
+ ip4_main_t *im = &ip4_main;
uword i;
unset_leaf (m, &a, root_ply, 0);
@@ -404,26 +426,27 @@ ip4_fib_mtrie_add_del_route (ip4_fib_t * fib,
/* Find next less specific route and insert into mtrie. */
for (i = dst_address_length - 1; i >= 1; i--)
{
- uword * p;
- index_t lbi;
+ uword *p;
+ index_t lbi;
ip4_address_t key;
- if (! fib->fib_entry_by_dst_address[i])
+ if (!fib->fib_entry_by_dst_address[i])
continue;
-
+
key.as_u32 = dst_address.as_u32 & im->fib_masks[i];
p = hash_get (fib->fib_entry_by_dst_address[i], key.as_u32);
if (p)
{
- lbi = fib_entry_contribute_ip_forwarding(p[0])->dpoi_index;
+ lbi = fib_entry_contribute_ip_forwarding (p[0])->dpoi_index;
if (INDEX_INVALID == lbi)
- continue;
+ continue;
a.dst_address = key;
a.adj_index = lbi;
a.dst_address_length = i;
- set_leaf (m, &a, /* ply_index */ 0, /* dst_address_byte_index */ 0);
+ set_leaf (m, &a, /* ply_index */ 0,
+ /* dst_address_byte_index */ 0);
break;
}
}
@@ -432,11 +455,12 @@ ip4_fib_mtrie_add_del_route (ip4_fib_t * fib,
}
/* Returns number of bytes of memory used by mtrie. */
-static uword mtrie_memory_usage (ip4_fib_mtrie_t * m, ip4_fib_mtrie_ply_t * p)
+static uword
+mtrie_memory_usage (ip4_fib_mtrie_t * m, ip4_fib_mtrie_ply_t * p)
{
uword bytes, i;
- if (! p)
+ if (!p)
{
if (pool_is_free_index (m->ply_pool, 0))
return 0;
@@ -444,7 +468,7 @@ static uword mtrie_memory_usage (ip4_fib_mtrie_t * m, ip4_fib_mtrie_ply_t * p)
}
bytes = sizeof (p[0]);
- for (i = 0 ; i < ARRAY_LEN (p->leaves); i++)
+ for (i = 0; i < ARRAY_LEN (p->leaves); i++)
{
ip4_fib_mtrie_leaf_t l = p->leaves[i];
if (ip4_fib_mtrie_leaf_is_next_ply (l))
@@ -454,7 +478,8 @@ static uword mtrie_memory_usage (ip4_fib_mtrie_t * m, ip4_fib_mtrie_ply_t * p)
return bytes;
}
-static u8 * format_ip4_fib_mtrie_leaf (u8 * s, va_list * va)
+static u8 *
+format_ip4_fib_mtrie_leaf (u8 * s, va_list * va)
{
ip4_fib_mtrie_leaf_t l = va_arg (*va, ip4_fib_mtrie_leaf_t);
@@ -467,33 +492,36 @@ static u8 * format_ip4_fib_mtrie_leaf (u8 * s, va_list * va)
return s;
}
-static u8 * format_ip4_fib_mtrie_ply (u8 * s, va_list * va)
+static u8 *
+format_ip4_fib_mtrie_ply (u8 * s, va_list * va)
{
- ip4_fib_mtrie_t * m = va_arg (*va, ip4_fib_mtrie_t *);
+ ip4_fib_mtrie_t *m = va_arg (*va, ip4_fib_mtrie_t *);
u32 base_address = va_arg (*va, u32);
u32 ply_index = va_arg (*va, u32);
u32 dst_address_byte_index = va_arg (*va, u32);
- ip4_fib_mtrie_ply_t * p;
+ ip4_fib_mtrie_ply_t *p;
uword i, indent;
p = pool_elt_at_index (m->ply_pool, ply_index);
indent = format_get_indent (s);
- s = format (s, "ply index %d, %d non-empty leaves", ply_index, p->n_non_empty_leafs);
+ s =
+ format (s, "ply index %d, %d non-empty leaves", ply_index,
+ p->n_non_empty_leafs);
for (i = 0; i < ARRAY_LEN (p->leaves); i++)
{
ip4_fib_mtrie_leaf_t l = p->leaves[i];
- if (! ip4_fib_mtrie_leaf_is_empty (l))
+ if (!ip4_fib_mtrie_leaf_is_empty (l))
{
u32 a, ia_length;
ip4_address_t ia;
- a = base_address + (i << (24 - 8*dst_address_byte_index));
+ a = base_address + (i << (24 - 8 * dst_address_byte_index));
ia.as_u32 = clib_host_to_net_u32 (a);
if (ip4_fib_mtrie_leaf_is_terminal (l))
ia_length = p->dst_address_bits_of_leaves[i];
else
- ia_length = 8*(1 + dst_address_byte_index);
+ ia_length = 8 * (1 + dst_address_byte_index);
s = format (s, "\n%U%20U %U",
format_white_space, indent + 2,
format_ip4_address_and_length, &ia, ia_length,
@@ -511,9 +539,10 @@ static u8 * format_ip4_fib_mtrie_ply (u8 * s, va_list * va)
return s;
}
-u8 * format_ip4_fib_mtrie (u8 * s, va_list * va)
+u8 *
+format_ip4_fib_mtrie (u8 * s, va_list * va)
{
- ip4_fib_mtrie_t * m = va_arg (*va, ip4_fib_mtrie_t *);
+ ip4_fib_mtrie_t *m = va_arg (*va, ip4_fib_mtrie_t *);
s = format (s, "%d plies, memory usage %U",
pool_elts (m->ply_pool),
@@ -523,8 +552,17 @@ u8 * format_ip4_fib_mtrie (u8 * s, va_list * va)
{
ip4_address_t base_address;
base_address.as_u32 = 0;
- s = format (s, "\n %U", format_ip4_fib_mtrie_ply, m, base_address, 0, 0);
+ s =
+ format (s, "\n %U", format_ip4_fib_mtrie_ply, m, base_address, 0, 0);
}
return s;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_mtrie.h b/vnet/vnet/ip/ip4_mtrie.h
index 4771be43e3f..c0afc2cf842 100644
--- a/vnet/vnet/ip/ip4_mtrie.h
+++ b/vnet/vnet/ip/ip4_mtrie.h
@@ -54,49 +54,67 @@ typedef u32 ip4_fib_mtrie_leaf_t;
#define IP4_FIB_MTRIE_LEAF_EMPTY (1 + 2*0)
#define IP4_FIB_MTRIE_LEAF_ROOT (0 + 2*0)
-always_inline u32 ip4_fib_mtrie_leaf_is_empty (ip4_fib_mtrie_leaf_t n)
-{ return n == IP4_FIB_MTRIE_LEAF_EMPTY; }
+always_inline u32
+ip4_fib_mtrie_leaf_is_empty (ip4_fib_mtrie_leaf_t n)
+{
+ return n == IP4_FIB_MTRIE_LEAF_EMPTY;
+}
-always_inline u32 ip4_fib_mtrie_leaf_is_non_empty (ip4_fib_mtrie_leaf_t n)
-{ return n != IP4_FIB_MTRIE_LEAF_EMPTY; }
+always_inline u32
+ip4_fib_mtrie_leaf_is_non_empty (ip4_fib_mtrie_leaf_t n)
+{
+ return n != IP4_FIB_MTRIE_LEAF_EMPTY;
+}
-always_inline u32 ip4_fib_mtrie_leaf_is_terminal (ip4_fib_mtrie_leaf_t n)
-{ return n & 1; }
+always_inline u32
+ip4_fib_mtrie_leaf_is_terminal (ip4_fib_mtrie_leaf_t n)
+{
+ return n & 1;
+}
-always_inline u32 ip4_fib_mtrie_leaf_get_adj_index (ip4_fib_mtrie_leaf_t n)
+always_inline u32
+ip4_fib_mtrie_leaf_get_adj_index (ip4_fib_mtrie_leaf_t n)
{
ASSERT (ip4_fib_mtrie_leaf_is_terminal (n));
return n >> 1;
}
-always_inline ip4_fib_mtrie_leaf_t ip4_fib_mtrie_leaf_set_adj_index (u32 adj_index)
+always_inline ip4_fib_mtrie_leaf_t
+ip4_fib_mtrie_leaf_set_adj_index (u32 adj_index)
{
ip4_fib_mtrie_leaf_t l;
- l = 1 + 2*adj_index;
+ l = 1 + 2 * adj_index;
ASSERT (ip4_fib_mtrie_leaf_get_adj_index (l) == adj_index);
return l;
}
-always_inline u32 ip4_fib_mtrie_leaf_is_next_ply (ip4_fib_mtrie_leaf_t n)
-{ return (n & 1) == 0; }
+always_inline u32
+ip4_fib_mtrie_leaf_is_next_ply (ip4_fib_mtrie_leaf_t n)
+{
+ return (n & 1) == 0;
+}
-always_inline u32 ip4_fib_mtrie_leaf_get_next_ply_index (ip4_fib_mtrie_leaf_t n)
+always_inline u32
+ip4_fib_mtrie_leaf_get_next_ply_index (ip4_fib_mtrie_leaf_t n)
{
ASSERT (ip4_fib_mtrie_leaf_is_next_ply (n));
return n >> 1;
}
-always_inline ip4_fib_mtrie_leaf_t ip4_fib_mtrie_leaf_set_next_ply_index (u32 i)
+always_inline ip4_fib_mtrie_leaf_t
+ip4_fib_mtrie_leaf_set_next_ply_index (u32 i)
{
ip4_fib_mtrie_leaf_t l;
- l = 0 + 2*i;
+ l = 0 + 2 * i;
ASSERT (ip4_fib_mtrie_leaf_get_next_ply_index (l) == i);
return l;
}
/* One ply of the 4 ply mtrie fib. */
-typedef struct {
- union {
+typedef struct
+{
+ union
+ {
ip4_fib_mtrie_leaf_t leaves[256];
#ifdef CLIB_HAVE_VEC128
@@ -111,16 +129,17 @@ typedef struct {
i32 n_non_empty_leafs;
/* Pad to cache line boundary. */
- u8 pad[CLIB_CACHE_LINE_BYTES
- - 1 * sizeof (i32)];
-} ip4_fib_mtrie_ply_t;
+ u8 pad[CLIB_CACHE_LINE_BYTES - 1 * sizeof (i32)];
+}
+ip4_fib_mtrie_ply_t;
-STATIC_ASSERT(0 == sizeof(ip4_fib_mtrie_ply_t) % CLIB_CACHE_LINE_BYTES,
- "IP4 Mtrie ply cache line");
+STATIC_ASSERT (0 == sizeof (ip4_fib_mtrie_ply_t) % CLIB_CACHE_LINE_BYTES,
+ "IP4 Mtrie ply cache line");
-typedef struct {
+typedef struct
+{
/* Pool of plies. Index zero is root ply. */
- ip4_fib_mtrie_ply_t * ply_pool;
+ ip4_fib_mtrie_ply_t *ply_pool;
/* Special case leaf for default route 0.0.0.0/0. */
ip4_fib_mtrie_leaf_t default_leaf;
@@ -130,11 +149,10 @@ void ip4_fib_mtrie_init (ip4_fib_mtrie_t * m);
struct ip4_fib_t;
-void ip4_fib_mtrie_add_del_route (struct ip4_fib_t * f,
+void ip4_fib_mtrie_add_del_route (struct ip4_fib_t *f,
ip4_address_t dst_address,
u32 dst_address_length,
- u32 adj_index,
- u32 is_del);
+ u32 adj_index, u32 is_del);
/* Returns adjacency index. */
u32 ip4_mtrie_lookup_address (ip4_fib_mtrie_t * m, ip4_address_t dst);
@@ -149,7 +167,7 @@ ip4_fib_mtrie_lookup_step (ip4_fib_mtrie_t * m,
u32 dst_address_byte_index)
{
ip4_fib_mtrie_leaf_t next_leaf;
- ip4_fib_mtrie_ply_t * ply;
+ ip4_fib_mtrie_ply_t *ply;
uword current_is_terminal = ip4_fib_mtrie_leaf_is_terminal (current_leaf);
ply = m->ply_pool + (current_is_terminal ? 0 : (current_leaf >> 1));
@@ -160,3 +178,11 @@ ip4_fib_mtrie_lookup_step (ip4_fib_mtrie_t * m,
}
#endif /* included_ip_ip4_fib_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_packet.h b/vnet/vnet/ip/ip4_packet.h
index 277b968f9ab..8da788b411f 100644
--- a/vnet/vnet/ip/ip4_packet.h
+++ b/vnet/vnet/ip/ip4_packet.h
@@ -46,7 +46,8 @@
/* IP4 address which can be accessed either as 4 bytes
or as a 32-bit number. */
-typedef union {
+typedef union
+{
u8 data[4];
u32 data_u32;
/* Aliases. */
@@ -54,7 +55,8 @@ typedef union {
u32 as_u32;
} ip4_address_t;
-typedef struct {
+typedef struct
+{
/* IP address must be first for ip_interface_address_get_address() to work */
ip4_address_t ip4_addr;
u32 fib_index;
@@ -69,7 +71,8 @@ ip4_addr_fib_init (ip4_address_fib_t * addr_fib, ip4_address_t * address,
}
/* (src,dst) pair of addresses as found in packet header. */
-typedef struct {
+typedef struct
+{
ip4_address_t src, dst;
} ip4_address_pair_t;
@@ -83,26 +86,46 @@ ip4_address_netmask_length (ip4_address_t * a)
{
switch (a->as_u8[i])
{
- case 0xff: result += 8; break;
- case 0xfe: result += 7; goto done;
- case 0xfc: result += 6; goto done;
- case 0xf8: result += 5; goto done;
- case 0xf0: result += 4; goto done;
- case 0xe0: result += 3; goto done;
- case 0xc0: result += 2; goto done;
- case 0x80: result += 1; goto done;
- case 0x00: result += 0; goto done;
+ case 0xff:
+ result += 8;
+ break;
+ case 0xfe:
+ result += 7;
+ goto done;
+ case 0xfc:
+ result += 6;
+ goto done;
+ case 0xf8:
+ result += 5;
+ goto done;
+ case 0xf0:
+ result += 4;
+ goto done;
+ case 0xe0:
+ result += 3;
+ goto done;
+ case 0xc0:
+ result += 2;
+ goto done;
+ case 0x80:
+ result += 1;
+ goto done;
+ case 0x00:
+ result += 0;
+ goto done;
default:
/* Not a valid netmask mask. */
return ~0;
}
}
- done:
+done:
return result;
}
-typedef union {
- struct {
+typedef union
+{
+ struct
+ {
/* 4 bit packet length (in 32bit units) and version VVVVLLLL.
e.g. for packets w/ no options ip_version_and_header_length == 0x45. */
u8 ip_version_and_header_length;
@@ -133,25 +156,31 @@ typedef union {
u16 checksum;
/* Source and destination address. */
- union {
- struct {
+ union
+ {
+ struct
+ {
ip4_address_t src_address, dst_address;
};
ip4_address_pair_t address_pair;
- };
+ };
};
/* For checksumming we'll want to access IP header in word sized chunks. */
/* For 64 bit machines. */
+ /* *INDENT-OFF* */
CLIB_PACKED (struct {
u64 checksum_data_64[2];
u32 checksum_data_64_32[1];
});
+ /* *INDENT-ON* */
/* For 32 bit machines. */
+ /* *INDENT-OFF* */
CLIB_PACKED (struct {
u32 checksum_data_32[5];
});
+ /* *INDENT-ON* */
} ip4_header_t;
/* Value of ip_version_and_header_length for packets w/o options. */
@@ -160,35 +189,50 @@ typedef union {
always_inline int
ip4_get_fragment_offset (ip4_header_t * i)
-{ return clib_net_to_host_u16 (i->flags_and_fragment_offset) & 0x1fff; }
+{
+ return clib_net_to_host_u16 (i->flags_and_fragment_offset) & 0x1fff;
+}
always_inline int
ip4_get_fragment_more (ip4_header_t * i)
-{ return clib_net_to_host_u16 (i->flags_and_fragment_offset) & IP4_HEADER_FLAG_MORE_FRAGMENTS; }
+{
+ return clib_net_to_host_u16 (i->flags_and_fragment_offset) &
+ IP4_HEADER_FLAG_MORE_FRAGMENTS;
+}
always_inline int
ip4_is_fragment (ip4_header_t * i)
-{ return (i->flags_and_fragment_offset &
- clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)); }
+{
+ return (i->flags_and_fragment_offset &
+ clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS));
+}
always_inline int
ip4_is_first_fragment (ip4_header_t * i)
-{ return (i->flags_and_fragment_offset &
- clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)) ==
- clib_net_to_host_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS); }
+{
+ return (i->flags_and_fragment_offset &
+ clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)) ==
+ clib_net_to_host_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
+}
/* Fragment offset in bytes. */
always_inline int
ip4_get_fragment_offset_bytes (ip4_header_t * i)
-{ return 8 * ip4_get_fragment_offset (i); }
+{
+ return 8 * ip4_get_fragment_offset (i);
+}
always_inline int
ip4_header_bytes (ip4_header_t * i)
-{ return sizeof (u32) * (i->ip_version_and_header_length & 0xf); }
+{
+ return sizeof (u32) * (i->ip_version_and_header_length & 0xf);
+}
always_inline void *
ip4_next_header (ip4_header_t * i)
-{ return (void *) i + ip4_header_bytes (i); }
+{
+ return (void *) i + ip4_header_bytes (i);
+}
always_inline u16
ip4_header_checksum (ip4_header_t * i)
@@ -213,7 +257,9 @@ ip4_header_checksum (ip4_header_t * i)
static inline uword
ip4_header_checksum_is_valid (ip4_header_t * i)
-{ return i->checksum == ip4_header_checksum (i); }
+{
+ return i->checksum == ip4_header_checksum (i);
+}
#define ip4_partial_header_checksum_x1(ip0,sum0) \
do { \
@@ -261,10 +307,13 @@ do { \
always_inline uword
ip4_address_is_multicast (ip4_address_t * a)
-{ return (a->data[0] & 0xf0) == 0xe0; }
+{
+ return (a->data[0] & 0xf0) == 0xe0;
+}
always_inline void
-ip4_multicast_address_set_for_group (ip4_address_t * a, ip_multicast_group_t g)
+ip4_multicast_address_set_for_group (ip4_address_t * a,
+ ip_multicast_group_t g)
{
ASSERT ((u32) g < (1 << 28));
a->as_u32 = clib_host_to_net_u32 ((0xe << 28) + g);
@@ -325,3 +374,11 @@ ip4_tcp_reply_x2 (ip4_header_t * ip0, ip4_header_t * ip1,
}
#endif /* included_ip4_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_pg.c b/vnet/vnet/ip/ip4_pg.c
index 42dad85272a..9697a3b9c89 100644
--- a/vnet/vnet/ip/ip4_pg.c
+++ b/vnet/vnet/ip/ip4_pg.c
@@ -47,16 +47,15 @@ static_always_inline void
compute_length_and_or_checksum (vlib_main_t * vm,
u32 * packets,
u32 n_packets,
- u32 ip_header_offset,
- u32 flags)
+ u32 ip_header_offset, u32 flags)
{
ASSERT (flags != 0);
while (n_packets >= 2)
{
u32 pi0, pi1;
- vlib_buffer_t * p0, * p1;
- ip4_header_t * ip0, * ip1;
+ vlib_buffer_t *p0, *p1;
+ ip4_header_t *ip0, *ip1;
ip_csum_t sum0, sum1;
pi0 = packets[0];
@@ -71,8 +70,12 @@ compute_length_and_or_checksum (vlib_main_t * vm,
if (flags & IP4_PG_EDIT_LENGTH)
{
- ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) - ip_header_offset);
- ip1->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p1) - ip_header_offset);
+ ip0->length =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) -
+ ip_header_offset);
+ ip1->length =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p1) -
+ ip_header_offset);
}
if (flags & IP4_PG_EDIT_CHECKSUM)
@@ -84,8 +87,8 @@ compute_length_and_or_checksum (vlib_main_t * vm,
ip1->checksum = 0;
ip4_partial_header_checksum_x2 (ip0, ip1, sum0, sum1);
- ip0->checksum = ~ ip_csum_fold (sum0);
- ip1->checksum = ~ ip_csum_fold (sum1);
+ ip0->checksum = ~ip_csum_fold (sum0);
+ ip1->checksum = ~ip_csum_fold (sum1);
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
ASSERT (ip1->checksum == ip4_header_checksum (ip1));
@@ -95,8 +98,8 @@ compute_length_and_or_checksum (vlib_main_t * vm,
while (n_packets >= 1)
{
u32 pi0;
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
ip_csum_t sum0;
pi0 = packets[0];
@@ -107,7 +110,9 @@ compute_length_and_or_checksum (vlib_main_t * vm,
ip0 = (void *) (p0->data + ip_header_offset);
if (flags & IP4_PG_EDIT_LENGTH)
- ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) - ip_header_offset);
+ ip0->length =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) -
+ ip_header_offset);
if (flags & IP4_PG_EDIT_CHECKSUM)
{
@@ -116,7 +121,7 @@ compute_length_and_or_checksum (vlib_main_t * vm,
ip0->checksum = 0;
ip4_partial_header_checksum_x1 (ip0, sum0);
- ip0->checksum = ~ ip_csum_fold (sum0);
+ ip0->checksum = ~ip_csum_fold (sum0);
ASSERT (ip0->checksum == ip4_header_checksum (ip0));
}
@@ -126,11 +131,9 @@ compute_length_and_or_checksum (vlib_main_t * vm,
static void
ip4_pg_edit_function (pg_main_t * pg,
pg_stream_t * s,
- pg_edit_group_t * g,
- u32 * packets,
- u32 n_packets)
+ pg_edit_group_t * g, u32 * packets, u32 n_packets)
{
- vlib_main_t * vm = vlib_get_main();
+ vlib_main_t *vm = vlib_get_main ();
u32 ip_offset;
ip_offset = g->start_byte_offset;
@@ -159,7 +162,8 @@ ip4_pg_edit_function (pg_main_t * pg,
}
}
-typedef struct {
+typedef struct
+{
pg_edit_t ip_version, header_length;
pg_edit_t tos;
pg_edit_t length;
@@ -183,53 +187,46 @@ pg_ip4_header_init (pg_ip4_header_t * p)
{
/* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, ip4_header_t, f);
- _ (tos);
- _ (length);
- _ (fragment_id);
- _ (ttl);
- _ (protocol);
- _ (checksum);
- _ (src_address);
- _ (dst_address);
+ _(tos);
+ _(length);
+ _(fragment_id);
+ _(ttl);
+ _(protocol);
+ _(checksum);
+ _(src_address);
+ _(dst_address);
#undef _
/* Initialize bit fields. */
pg_edit_init_bitfield (&p->header_length, ip4_header_t,
- ip_version_and_header_length,
- 0, 4);
+ ip_version_and_header_length, 0, 4);
pg_edit_init_bitfield (&p->ip_version, ip4_header_t,
- ip_version_and_header_length,
- 4, 4);
+ ip_version_and_header_length, 4, 4);
pg_edit_init_bitfield (&p->fragment_offset, ip4_header_t,
- flags_and_fragment_offset,
- 0, 13);
+ flags_and_fragment_offset, 0, 13);
pg_edit_init_bitfield (&p->mf_flag, ip4_header_t,
- flags_and_fragment_offset,
- 13, 1);
+ flags_and_fragment_offset, 13, 1);
pg_edit_init_bitfield (&p->df_flag, ip4_header_t,
- flags_and_fragment_offset,
- 14, 1);
+ flags_and_fragment_offset, 14, 1);
pg_edit_init_bitfield (&p->ce_flag, ip4_header_t,
- flags_and_fragment_offset,
- 15, 1);
+ flags_and_fragment_offset, 15, 1);
}
uword
unformat_pg_ip4_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_ip4_header_t * p;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_ip4_header_t *p;
u32 group_index;
-
+
p = pg_create_edit_group (s, sizeof (p[0]), sizeof (ip4_header_t),
&group_index);
pg_ip4_header_init (p);
/* Defaults. */
pg_edit_set_fixed (&p->ip_version, 4);
- pg_edit_set_fixed (&p->header_length,
- sizeof (ip4_header_t) / sizeof (u32));
+ pg_edit_set_fixed (&p->header_length, sizeof (ip4_header_t) / sizeof (u32));
pg_edit_set_fixed (&p->tos, 0);
pg_edit_set_fixed (&p->ttl, 64);
@@ -244,26 +241,23 @@ unformat_pg_ip4_header (unformat_input_t * input, va_list * args)
p->checksum.type = PG_EDIT_UNSPECIFIED;
if (unformat (input, "%U: %U -> %U",
- unformat_pg_edit,
- unformat_ip_protocol, &p->protocol,
- unformat_pg_edit,
- unformat_ip4_address, &p->src_address,
- unformat_pg_edit,
- unformat_ip4_address, &p->dst_address))
- goto found;
-
- if (! unformat (input, "%U:",
- unformat_pg_edit,
- unformat_ip_protocol, &p->protocol))
- goto error;
+ unformat_pg_edit,
+ unformat_ip_protocol, &p->protocol,
+ unformat_pg_edit,
+ unformat_ip4_address, &p->src_address,
+ unformat_pg_edit, unformat_ip4_address, &p->dst_address))
+ goto found;
+
+ if (!unformat (input, "%U:",
+ unformat_pg_edit, unformat_ip_protocol, &p->protocol))
+ goto error;
found:
/* Parse options. */
while (1)
{
if (unformat (input, "version %U",
- unformat_pg_edit,
- unformat_pg_number, &p->ip_version))
+ unformat_pg_edit, unformat_pg_number, &p->ip_version))
;
else if (unformat (input, "header-length %U",
@@ -272,23 +266,19 @@ found:
;
else if (unformat (input, "tos %U",
- unformat_pg_edit,
- unformat_pg_number, &p->tos))
+ unformat_pg_edit, unformat_pg_number, &p->tos))
;
else if (unformat (input, "length %U",
- unformat_pg_edit,
- unformat_pg_number, &p->length))
+ unformat_pg_edit, unformat_pg_number, &p->length))
;
else if (unformat (input, "checksum %U",
- unformat_pg_edit,
- unformat_pg_number, &p->checksum))
+ unformat_pg_edit, unformat_pg_number, &p->checksum))
;
else if (unformat (input, "ttl %U",
- unformat_pg_edit,
- unformat_pg_number, &p->ttl))
+ unformat_pg_edit, unformat_pg_number, &p->ttl))
;
else if (unformat (input, "fragment id %U offset %U",
@@ -298,10 +288,11 @@ found:
unformat_pg_number, &p->fragment_offset))
{
int i;
- for (i = 0; i< ARRAY_LEN (p->fragment_offset.values); i++)
+ for (i = 0; i < ARRAY_LEN (p->fragment_offset.values); i++)
pg_edit_set_value (&p->fragment_offset, i,
- pg_edit_get_value (&p->fragment_offset, i) / 8);
-
+ pg_edit_get_value (&p->fragment_offset,
+ i) / 8);
+
}
/* Flags. */
@@ -313,16 +304,16 @@ found:
else if (unformat (input, "ce") || unformat (input, "CE"))
pg_edit_set_fixed (&p->ce_flag, 1);
-
+
/* Can't parse input: try next protocol level. */
else
break;
}
{
- ip_main_t * im = &ip_main;
+ ip_main_t *im = &ip_main;
ip_protocol_t protocol;
- ip_protocol_info_t * pi;
+ ip_protocol_info_t *pi;
pi = 0;
if (p->protocol.type == PG_EDIT_FIXED)
@@ -335,7 +326,7 @@ found:
&& unformat_user (input, pi->unformat_pg_edit, s))
;
- else if (! unformat_user (input, unformat_pg_payload, s))
+ else if (!unformat_user (input, unformat_pg_payload, s))
goto error;
if (p->length.type == PG_EDIT_UNSPECIFIED
@@ -350,7 +341,7 @@ found:
if (p->checksum.type == PG_EDIT_UNSPECIFIED)
{
ip4_header_t fixed_header, fixed_mask, cmp_mask;
-
+
/* See if header is all fixed and specified except for
checksum field. */
memset (&cmp_mask, ~0, sizeof (cmp_mask));
@@ -358,16 +349,17 @@ found:
pg_edit_group_get_fixed_packet_data (s, group_index,
&fixed_header, &fixed_mask);
- if (! memcmp (&fixed_mask, &cmp_mask, sizeof (cmp_mask)))
+ if (!memcmp (&fixed_mask, &cmp_mask, sizeof (cmp_mask)))
pg_edit_set_fixed (&p->checksum,
- clib_net_to_host_u16 (ip4_header_checksum (&fixed_header)));
+ clib_net_to_host_u16 (ip4_header_checksum
+ (&fixed_header)));
}
p = pg_get_edit_group (s, group_index);
if (p->length.type == PG_EDIT_UNSPECIFIED
|| p->checksum.type == PG_EDIT_UNSPECIFIED)
{
- pg_edit_group_t * g = pg_stream_get_group (s, group_index);
+ pg_edit_group_t *g = pg_stream_get_group (s, group_index);
g->edit_function = ip4_pg_edit_function;
g->edit_function_opaque = 0;
if (p->length.type == PG_EDIT_UNSPECIFIED)
@@ -379,9 +371,17 @@ found:
return 1;
}
- error:
+error:
/* Free up any edits we may have added. */
pg_free_edit_group (s);
return 0;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_source_check.c b/vnet/vnet/ip/ip4_source_check.c
index f7900d304c2..d461cc885d6 100644
--- a/vnet/vnet/ip/ip4_source_check.c
+++ b/vnet/vnet/ip/ip4_source_check.c
@@ -50,35 +50,39 @@
*/
-typedef struct {
+typedef struct
+{
u8 packet_data[64];
- index_t urpf;
+ index_t urpf;
} ip4_source_check_trace_t;
-static u8 * format_ip4_source_check_trace (u8 * s, va_list * va)
+static u8 *
+format_ip4_source_check_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
- ip4_source_check_trace_t * t = va_arg (*va, ip4_source_check_trace_t *);
+ ip4_source_check_trace_t *t = va_arg (*va, ip4_source_check_trace_t *);
s = format (s, "%U",
- format_ip4_header,
- t->packet_data, sizeof (t->packet_data));
+ format_ip4_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-typedef enum {
+typedef enum
+{
IP4_SOURCE_CHECK_NEXT_DROP,
IP4_SOURCE_CHECK_N_NEXT,
} ip4_source_check_next_t;
-typedef enum {
+typedef enum
+{
IP4_SOURCE_CHECK_REACHABLE_VIA_RX,
IP4_SOURCE_CHECK_REACHABLE_VIA_ANY,
} ip4_source_check_type_t;
-typedef union {
+typedef union
+{
u32 fib_index;
} ip4_source_check_config_t;
@@ -88,9 +92,10 @@ ip4_source_check_inline (vlib_main_t * vm,
vlib_frame_t * frame,
ip4_source_check_type_t source_check_type)
{
- u32 n_left_from, * from, * to_next;
+ u32 n_left_from, *from, *to_next;
u32 next_index;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip4_input_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip4_input_node.index);
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -105,23 +110,22 @@ ip4_source_check_inline (vlib_main_t * vm,
{
u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- vlib_buffer_t * p0, * p1;
- ip4_header_t * ip0, * ip1;
- ip4_fib_mtrie_t * mtrie0, * mtrie1;
+ vlib_buffer_t *p0, *p1;
+ ip4_header_t *ip0, *ip1;
+ ip4_fib_mtrie_t *mtrie0, *mtrie1;
ip4_fib_mtrie_leaf_t leaf0, leaf1;
- ip4_source_check_config_t * c0, * c1;
- const load_balance_t * lb0, * lb1;
+ ip4_source_check_config_t *c0, *c1;
+ const load_balance_t *lb0, *lb1;
u32 pi0, next0, pass0, lb_index0;
u32 pi1, next1, pass1, lb_index1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -146,68 +150,88 @@ ip4_source_check_inline (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
ip1 = vlib_buffer_get_current (p1);
- c0 = vnet_feature_next_with_data(vnet_buffer (p0)->sw_if_index[VLIB_RX] , &next0, p0, sizeof (c0[0]));
- c1 = vnet_feature_next_with_data(vnet_buffer (p1)->sw_if_index[VLIB_RX] , &next1, p1, sizeof (c1[0]));
+ c0 =
+ vnet_feature_next_with_data (vnet_buffer (p0)->sw_if_index
+ [VLIB_RX], &next0, p0,
+ sizeof (c0[0]));
+ c1 =
+ vnet_feature_next_with_data (vnet_buffer (p1)->sw_if_index
+ [VLIB_RX], &next1, p1,
+ sizeof (c1[0]));
mtrie0 = &ip4_fib_get (c0->fib_index)->mtrie;
mtrie1 = &ip4_fib_get (c1->fib_index)->mtrie;
leaf0 = leaf1 = IP4_FIB_MTRIE_LEAF_ROOT;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 0);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 0);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 1);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 1);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 2);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 2);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
- leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 3);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
+ leaf1 =
+ ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 3);
lb_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
lb_index1 = ip4_fib_mtrie_leaf_get_adj_index (leaf1);
- lb0 = load_balance_get(lb_index0);
- lb1 = load_balance_get(lb_index1);
+ lb0 = load_balance_get (lb_index0);
+ lb1 = load_balance_get (lb_index1);
/* Pass multicast. */
- pass0 = ip4_address_is_multicast (&ip0->src_address) || ip0->src_address.as_u32 == clib_host_to_net_u32(0xFFFFFFFF);
- pass1 = ip4_address_is_multicast (&ip1->src_address) || ip1->src_address.as_u32 == clib_host_to_net_u32(0xFFFFFFFF);
+ pass0 = ip4_address_is_multicast (&ip0->src_address)
+ || ip0->src_address.as_u32 == clib_host_to_net_u32 (0xFFFFFFFF);
+ pass1 = ip4_address_is_multicast (&ip1->src_address)
+ || ip1->src_address.as_u32 == clib_host_to_net_u32 (0xFFFFFFFF);
if (IP4_SOURCE_CHECK_REACHABLE_VIA_RX == source_check_type)
- {
- pass0 |= fib_urpf_check(lb0->lb_urpf,
- vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- pass1 |= fib_urpf_check(lb1->lb_urpf,
- vnet_buffer (p1)->sw_if_index[VLIB_RX]);
- }
+ {
+ pass0 |= fib_urpf_check (lb0->lb_urpf,
+ vnet_buffer (p0)->sw_if_index
+ [VLIB_RX]);
+ pass1 |=
+ fib_urpf_check (lb1->lb_urpf,
+ vnet_buffer (p1)->sw_if_index[VLIB_RX]);
+ }
else
- {
- pass0 |= fib_urpf_check_size(lb0->lb_urpf);
- pass1 |= fib_urpf_check_size(lb1->lb_urpf);
- }
+ {
+ pass0 |= fib_urpf_check_size (lb0->lb_urpf);
+ pass1 |= fib_urpf_check_size (lb1->lb_urpf);
+ }
next0 = (pass0 ? next0 : IP4_SOURCE_CHECK_NEXT_DROP);
next1 = (pass1 ? next1 : IP4_SOURCE_CHECK_NEXT_DROP);
- p0->error = error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
- p1->error = error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
+ p0->error =
+ error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
+ p1->error =
+ error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
pi0, pi1, next0, next1);
}
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- ip4_fib_mtrie_t * mtrie0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ ip4_fib_mtrie_t *mtrie0;
ip4_fib_mtrie_leaf_t leaf0;
- ip4_source_check_config_t * c0;
+ ip4_source_check_config_t *c0;
u32 pi0, next0, pass0, lb_index0;
- const load_balance_t * lb0;
+ const load_balance_t *lb0;
pi0 = from[0];
to_next[0] = pi0;
@@ -219,39 +243,49 @@ ip4_source_check_inline (vlib_main_t * vm,
p0 = vlib_get_buffer (vm, pi0);
ip0 = vlib_buffer_get_current (p0);
- c0 = vnet_feature_next_with_data(vnet_buffer (p0)->sw_if_index[VLIB_RX] , &next0, p0, sizeof (c0[0]));
+ c0 =
+ vnet_feature_next_with_data (vnet_buffer (p0)->sw_if_index
+ [VLIB_RX], &next0, p0,
+ sizeof (c0[0]));
mtrie0 = &ip4_fib_get (c0->fib_index)->mtrie;
leaf0 = IP4_FIB_MTRIE_LEAF_ROOT;
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 0);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
- leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
+ leaf0 =
+ ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
lb_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- lb0 = load_balance_get(lb_index0);
+ lb0 = load_balance_get (lb_index0);
/* Pass multicast. */
- pass0 = ip4_address_is_multicast (&ip0->src_address) || ip0->src_address.as_u32 == clib_host_to_net_u32(0xFFFFFFFF);
+ pass0 = ip4_address_is_multicast (&ip0->src_address)
+ || ip0->src_address.as_u32 == clib_host_to_net_u32 (0xFFFFFFFF);
if (IP4_SOURCE_CHECK_REACHABLE_VIA_RX == source_check_type)
- {
- pass0 |= fib_urpf_check(lb0->lb_urpf,
- vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- }
+ {
+ pass0 |= fib_urpf_check (lb0->lb_urpf,
+ vnet_buffer (p0)->sw_if_index
+ [VLIB_RX]);
+ }
else
- {
- pass0 |= fib_urpf_check_size(lb0->lb_urpf);
- }
+ {
+ pass0 |= fib_urpf_check_size (lb0->lb_urpf);
+ }
next0 = (pass0 ? next0 : IP4_SOURCE_CHECK_NEXT_DROP);
- p0->error = error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
+ p0->error =
+ error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
@@ -269,17 +303,20 @@ ip4_source_check_reachable_via_any (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
- return ip4_source_check_inline (vm, node, frame, IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ return ip4_source_check_inline (vm, node, frame,
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
}
static uword
ip4_source_check_reachable_via_rx (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
{
- return ip4_source_check_inline (vm, node, frame, IP4_SOURCE_CHECK_REACHABLE_VIA_RX);
+ return ip4_source_check_inline (vm, node, frame,
+ IP4_SOURCE_CHECK_REACHABLE_VIA_RX);
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_check_source_reachable_via_any) = {
.function = ip4_source_check_reachable_via_any,
.name = "ip4-source-check-via-any",
@@ -293,10 +330,12 @@ VLIB_REGISTER_NODE (ip4_check_source_reachable_via_any) = {
.format_buffer = format_ip4_header,
.format_trace = format_ip4_source_check_trace,
};
+/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip4_check_source_reachable_via_any,
- ip4_source_check_reachable_via_any)
+ ip4_source_check_reachable_via_any);
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_check_source_reachable_via_rx) = {
.function = ip4_source_check_reachable_via_rx,
.name = "ip4-source-check-via-rx",
@@ -310,39 +349,40 @@ VLIB_REGISTER_NODE (ip4_check_source_reachable_via_rx) = {
.format_buffer = format_ip4_header,
.format_trace = format_ip4_source_check_trace,
};
+/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip4_check_source_reachable_via_rx,
- ip4_source_check_reachable_via_rx)
+ ip4_source_check_reachable_via_rx);
static clib_error_t *
set_ip_source_check (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- unformat_input_t _line_input, * line_input = &_line_input;
- vnet_main_t * vnm = vnet_get_main();
- ip4_main_t * im = &ip4_main;
- clib_error_t * error = 0;
+ unformat_input_t _line_input, *line_input = &_line_input;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip4_main_t *im = &ip4_main;
+ clib_error_t *error = 0;
u32 sw_if_index, is_del;
ip4_source_check_config_t config;
- char * feature_name = "ip4-source-check-via-rx";
+ char *feature_name = "ip4-source-check-via-rx";
sw_if_index = ~0;
is_del = 0;
- if (! unformat_user (input, unformat_line_input, line_input))
+ if (!unformat_user (input, unformat_line_input, line_input))
return 0;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat_user (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
- ;
+ if (unformat_user
+ (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+ ;
else if (unformat (line_input, "del"))
- is_del = 1;
+ is_del = 1;
else if (unformat (line_input, "loose"))
feature_name = "ip4-source-check-via-any";
else
- {
+ {
error = unformat_parse_error (line_input);
goto done;
}
@@ -358,7 +398,7 @@ set_ip_source_check (vlib_main_t * vm,
config.fib_index = im->fib_index_by_sw_if_index[sw_if_index];
vnet_feature_enable_disable ("ip4-unicast", feature_name, sw_if_index,
is_del == 0, &config, sizeof (config));
- done:
+done:
return error;
}
@@ -429,21 +469,20 @@ VLIB_CLI_COMMAND (set_interface_ip_source_check_command, static) = {
static clib_error_t *
ip_source_check_accept (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- unformat_input_t _line_input, * line_input = &_line_input;
+ unformat_input_t _line_input, *line_input = &_line_input;
fib_prefix_t pfx = {
- .fp_proto = FIB_PROTOCOL_IP4,
+ .fp_proto = FIB_PROTOCOL_IP4,
};
- clib_error_t * error = NULL;
+ clib_error_t *error = NULL;
u32 table_id, is_add, fib_index;
is_add = 1;
table_id = ~0;
/* Get a line of input. */
- if (! unformat_user (input, unformat_line_input, line_input))
+ if (!unformat_user (input, unformat_line_input, line_input))
return 0;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
@@ -455,25 +494,21 @@ ip_source_check_accept (vlib_main_t * vm,
else if (unformat (line_input, "add"))
is_add = 1;
else if (unformat (line_input, "%U/%d",
- unformat_ip4_address,
- &pfx.fp_addr.ip4,
- &pfx.fp_len))
- pfx.fp_proto = FIB_PROTOCOL_IP4;
+ unformat_ip4_address, &pfx.fp_addr.ip4, &pfx.fp_len))
+ pfx.fp_proto = FIB_PROTOCOL_IP4;
else
- {
+ {
error = unformat_parse_error (line_input);
goto done;
- }
+ }
}
if (~0 != table_id)
{
- fib_index = fib_table_id_find_fib_index(pfx.fp_proto, table_id);
+ fib_index = fib_table_id_find_fib_index (pfx.fp_proto, table_id);
if (~0 == fib_index)
- {
- error = clib_error_return (0,
- "Nonexistent table id %d",
- table_id);
+ {
+ error = clib_error_return (0, "Nonexistent table id %d", table_id);
goto done;
}
}
@@ -484,18 +519,16 @@ ip_source_check_accept (vlib_main_t * vm,
if (is_add)
{
- fib_table_entry_special_add(fib_index,
- &pfx,
- FIB_SOURCE_URPF_EXEMPT,
- FIB_ENTRY_FLAG_DROP,
- ADJ_INDEX_INVALID);
+ fib_table_entry_special_add (fib_index,
+ &pfx,
+ FIB_SOURCE_URPF_EXEMPT,
+ FIB_ENTRY_FLAG_DROP, ADJ_INDEX_INVALID);
}
else
- {
- fib_table_entry_special_remove(fib_index,
- &pfx,
- FIB_SOURCE_URPF_EXEMPT);
- }
+ {
+ fib_table_entry_special_remove (fib_index,
+ &pfx, FIB_SOURCE_URPF_EXEMPT);
+ }
done:
return (error);
@@ -523,7 +556,18 @@ VLIB_CLI_COMMAND (ip_source_check_accept_command, static) = {
/* Dummy init function to get us linked in. */
-clib_error_t * ip4_source_check_init (vlib_main_t * vm)
-{ return 0; }
+clib_error_t *
+ip4_source_check_init (vlib_main_t * vm)
+{
+ return 0;
+}
VLIB_INIT_FUNCTION (ip4_source_check_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip4_test.c b/vnet/vnet/ip/ip4_test.c
index f97a06525b1..45d171130df 100644
--- a/vnet/vnet/ip/ip4_test.c
+++ b/vnet/vnet/ip/ip4_test.c
@@ -22,35 +22,36 @@
* Not compiled in by default. IPv4 FIB tester. Add, probe, delete a bunch of
* random routes / masks and make sure that the mtrie agrees with
* the hash-table FIB.
- *
+ *
* Manipulate the FIB by means of the debug CLI commands, to minimize
* the chances of doing something idiotic.
*/
-/*
+/*
* These routines need to be redeclared non-static elsewhere.
*
* Also: rename ip_route() -> vnet_ip_route_cmd() and add the usual
* test_route_init() call to main.c
*/
-clib_error_t *
-vnet_ip_route_cmd (vlib_main_t * vm,
- unformat_input_t * input, vlib_cli_command_t * cmd_arg);
+clib_error_t *vnet_ip_route_cmd (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd_arg);
-int ip4_lookup_validate (ip4_address_t *a, u32 fib_index0);
+int ip4_lookup_validate (ip4_address_t * a, u32 fib_index0);
-ip4_fib_t *
-find_fib_by_table_index_or_id (ip4_main_t * im, u32 table_index_or_id,
- u32 flags);
+ip4_fib_t *find_fib_by_table_index_or_id (ip4_main_t * im,
+ u32 table_index_or_id, u32 flags);
/* Routes to insert/delete/probe in FIB */
-typedef struct {
+typedef struct
+{
ip4_address_t address;
u32 mask_width;
- u32 interface_id; /* not an xx_if_index */
+ u32 interface_id; /* not an xx_if_index */
} test_route_t;
-typedef struct {
+typedef struct
+{
/* Test routes in use */
test_route_t *route_pool;
@@ -61,29 +62,32 @@ typedef struct {
test_main_t test_main;
/* fake ethernet device class, distinct from "fake-ethX" */
-static u8 * format_test_interface_name (u8 * s, va_list * args)
+static u8 *
+format_test_interface_name (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
return format (s, "test-eth%d", dev_instance);
}
-static uword dummy_interface_tx (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+static uword
+dummy_interface_tx (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
clib_warning ("you shouldn't be here, leaking buffers...");
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VNET_DEVICE_CLASS (test_interface_device_class,static) = {
.name = "Test interface",
.format_device_name = format_test_interface_name,
.tx_function = dummy_interface_tx,
};
+/* *INDENT-ON* */
static clib_error_t *
-thrash (vlib_main_t * vm,
- unformat_input_t * main_input, vlib_cli_command_t * cmd_arg)
+thrash (vlib_main_t * vm,
+ unformat_input_t * main_input, vlib_cli_command_t * cmd_arg)
{
u32 seed = 0xdeaddabe;
u32 niter = 10;
@@ -91,57 +95,57 @@ thrash (vlib_main_t * vm,
u32 ninterfaces = 4;
f64 min_mask_bits = 7.0;
f64 max_mask_bits = 32.0;
- u32 table_id = 11; /* my amp goes to 11 (use fib 11) */
+ u32 table_id = 11; /* my amp goes to 11 (use fib 11) */
u32 table_index;
int iter, i;
- u8 * cmd;
+ u8 *cmd;
test_route_t *tr;
test_main_t *tm = &test_main;
- ip4_main_t * im = &ip4_main;
- vnet_main_t * vnm = vnet_get_main();
+ ip4_main_t *im = &ip4_main;
+ vnet_main_t *vnm = vnet_get_main ();
unformat_input_t cmd_input;
f64 rf;
u32 *masks = 0;
u32 tmp;
u32 hw_if_index;
- clib_error_t * error = 0;
+ clib_error_t *error = 0;
uword *p;
- unformat_input_t _line_input, * line_input = &_line_input;
+ unformat_input_t _line_input, *line_input = &_line_input;
u8 hw_address[6];
- ip4_fib_t * fib;
+ ip4_fib_t *fib;
int verbose = 0;
/* Precompute mask width -> mask vector */
- tmp = (u32)~0;
+ tmp = (u32) ~ 0;
vec_validate (masks, 32);
for (i = 32; i > 0; i--)
{
- masks [i] = tmp;
+ masks[i] = tmp;
tmp <<= 1;
}
if (unformat_user (main_input, unformat_line_input, line_input))
{
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "seed %d", &seed))
- ;
- else if (unformat (line_input, "niter %d", &niter))
- ;
- else if (unformat (line_input, "nroutes %d", &nroutes))
- ;
- else if (unformat (line_input, "ninterfaces %d", &ninterfaces))
- ;
- else if (unformat (line_input, "min-mask-bits %d", &tmp))
- min_mask_bits = (f64) tmp;
- else if (unformat (line_input, "max-mask-bits %d", &tmp))
- max_mask_bits = (f64) tmp;
- else if (unformat (line_input, "verbose"))
- verbose = 1;
- else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, line_input);
- }
+ {
+ if (unformat (line_input, "seed %d", &seed))
+ ;
+ else if (unformat (line_input, "niter %d", &niter))
+ ;
+ else if (unformat (line_input, "nroutes %d", &nroutes))
+ ;
+ else if (unformat (line_input, "ninterfaces %d", &ninterfaces))
+ ;
+ else if (unformat (line_input, "min-mask-bits %d", &tmp))
+ min_mask_bits = (f64) tmp;
+ else if (unformat (line_input, "max-mask-bits %d", &tmp))
+ max_mask_bits = (f64) tmp;
+ else if (unformat (line_input, "verbose"))
+ verbose = 1;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, line_input);
+ }
}
/* Find or create FIB table 11 */
@@ -149,25 +153,22 @@ thrash (vlib_main_t * vm,
for (i = tm->test_interfaces_created; i < ninterfaces; i++)
{
- vnet_hw_interface_t * hw;
+ vnet_hw_interface_t *hw;
memset (hw_address, 0, sizeof (hw_address));
hw_address[0] = 0xd0;
hw_address[1] = 0x0f;
hw_address[5] = i;
error = ethernet_register_interface
- (vnm,
- test_interface_device_class.index,
- i /* instance */,
- hw_address,
- &hw_if_index,
- /* flag change */ 0);
-
+ (vnm, test_interface_device_class.index, i /* instance */ ,
+ hw_address, &hw_if_index,
+ /* flag change */ 0);
+
/* Fake interfaces use FIB table 11 */
hw = vnet_get_hw_interface (vnm, hw_if_index);
vec_validate (im->fib_index_by_sw_if_index, hw->sw_if_index);
im->fib_index_by_sw_if_index[hw->sw_if_index] = fib->index;
- ip4_sw_interface_enable_disable(sw_if_index, 1);
+ ip4_sw_interface_enable_disable (sw_if_index, 1);
}
tm->test_interfaces_created = ninterfaces;
@@ -176,8 +177,7 @@ thrash (vlib_main_t * vm,
p = hash_get (im->fib_index_by_table_id, table_id);
if (p == 0)
{
- vlib_cli_output (vm, "Couldn't map fib id %d to fib index\n",
- table_id);
+ vlib_cli_output (vm, "Couldn't map fib id %d to fib index\n", table_id);
return 0;
}
table_index = p[0];
@@ -186,115 +186,111 @@ thrash (vlib_main_t * vm,
{
/* Pick random routes to install */
for (i = 0; i < nroutes; i++)
- {
- int j;
-
- pool_get (tm->route_pool, tr);
- memset (tr, 0, sizeof (*tr));
-
- again:
- rf = random_f64 (&seed);
- tr->mask_width = (u32) (min_mask_bits
- + rf * (max_mask_bits - min_mask_bits));
- tmp = random_u32 (&seed);
- tmp &= masks[tr->mask_width];
- tr->address.as_u32 = clib_host_to_net_u32(tmp);
-
- /* We can't add the same address/mask twice... */
- for (j = 0; j < i; j++)
- {
- test_route_t *prev;
- prev = pool_elt_at_index (tm->route_pool, j);
- if ((prev->address.as_u32 == tr->address.as_u32)
- && (prev->mask_width == tr->mask_width))
- goto again;
- }
-
- rf = random_f64 (&seed);
- tr->interface_id = (u32) (rf * ninterfaces);
- }
-
+ {
+ int j;
+
+ pool_get (tm->route_pool, tr);
+ memset (tr, 0, sizeof (*tr));
+
+ again:
+ rf = random_f64 (&seed);
+ tr->mask_width = (u32) (min_mask_bits
+ + rf * (max_mask_bits - min_mask_bits));
+ tmp = random_u32 (&seed);
+ tmp &= masks[tr->mask_width];
+ tr->address.as_u32 = clib_host_to_net_u32 (tmp);
+
+ /* We can't add the same address/mask twice... */
+ for (j = 0; j < i; j++)
+ {
+ test_route_t *prev;
+ prev = pool_elt_at_index (tm->route_pool, j);
+ if ((prev->address.as_u32 == tr->address.as_u32)
+ && (prev->mask_width == tr->mask_width))
+ goto again;
+ }
+
+ rf = random_f64 (&seed);
+ tr->interface_id = (u32) (rf * ninterfaces);
+ }
+
/* Add them */
for (i = 0; i < nroutes; i++)
- {
- tr = pool_elt_at_index (tm->route_pool, i);
- cmd = format (0, "add table %d %U/%d via test-eth%d",
- table_id,
- format_ip4_address, &tr->address,
- tr->mask_width, tr->interface_id);
- vec_add1(cmd,0);
- if (verbose)
- fformat(stderr, "ip route %s\n", cmd);
- unformat_init_string (&cmd_input, (char *) cmd, vec_len(cmd)-1);
- error = vnet_ip_route_cmd (vm, &cmd_input, cmd_arg);
- if (error)
- clib_error_report(error);
- unformat_free (&cmd_input);
- vec_free(cmd);
- }
+ {
+ tr = pool_elt_at_index (tm->route_pool, i);
+ cmd = format (0, "add table %d %U/%d via test-eth%d",
+ table_id,
+ format_ip4_address, &tr->address,
+ tr->mask_width, tr->interface_id);
+ vec_add1 (cmd, 0);
+ if (verbose)
+ fformat (stderr, "ip route %s\n", cmd);
+ unformat_init_string (&cmd_input, (char *) cmd, vec_len (cmd) - 1);
+ error = vnet_ip_route_cmd (vm, &cmd_input, cmd_arg);
+ if (error)
+ clib_error_report (error);
+ unformat_free (&cmd_input);
+ vec_free (cmd);
+ }
/* Probe them */
for (i = 0; i < nroutes; i++)
- {
- tr = pool_elt_at_index (tm->route_pool, i);
- if (!ip4_lookup_validate (&tr->address, table_index))
- {
- if (verbose)
- fformat (stderr, "test lookup table %d %U\n",
- table_index, format_ip4_address, &tr->address);
-
- fformat (stderr, "FAIL-after-insert: %U/%d\n",
- format_ip4_address, &tr->address,
- tr->mask_width);
- }
- }
+ {
+ tr = pool_elt_at_index (tm->route_pool, i);
+ if (!ip4_lookup_validate (&tr->address, table_index))
+ {
+ if (verbose)
+ fformat (stderr, "test lookup table %d %U\n",
+ table_index, format_ip4_address, &tr->address);
+
+ fformat (stderr, "FAIL-after-insert: %U/%d\n",
+ format_ip4_address, &tr->address, tr->mask_width);
+ }
+ }
/* Delete them */
for (i = 0; i < nroutes; i++)
- {
- int j;
- tr = pool_elt_at_index (tm->route_pool, i);
- if (0)
- cmd = format (0, "del table %d %U/%d via test-eth%d",
- table_id,
- format_ip4_address, &tr->address,
- tr->mask_width, tr->interface_id);
- else
- cmd = format (0, "del table %d %U/%d",
- table_id,
- format_ip4_address, &tr->address,
- tr->mask_width);
- vec_add1(cmd,0);
- if (verbose)
- fformat(stderr, "ip route %s\n", cmd);
- unformat_init_string (&cmd_input, (char *) cmd, vec_len(cmd)-1);
- error = vnet_ip_route_cmd (vm, &cmd_input, cmd_arg);
- if (error)
- clib_error_report(error);
- unformat_free (&cmd_input);
- vec_free(cmd);
-
- /* Make sure all undeleted routes still work */
- for (j = i+1; j < nroutes; j++)
- {
- test_route_t *rr; /* remaining route */
- rr = pool_elt_at_index (tm->route_pool, j);
- if (!ip4_lookup_validate (&rr->address, table_index))
- {
- if (verbose)
- fformat (stderr, "test lookup table %d %U\n",
- table_index, format_ip4_address, &rr->address);
-
- fformat (stderr, "FAIL: %U/%d AWOL\n",
- format_ip4_address, &rr->address,
- rr->mask_width);
- fformat (stderr, " iter %d after %d of %d deletes\n",
- iter, i, nroutes);
- fformat (stderr, " last route deleted %U/%d\n",
- format_ip4_address, &tr->address,
- tr->mask_width);
- }
- }
- }
+ {
+ int j;
+ tr = pool_elt_at_index (tm->route_pool, i);
+ if (0)
+ cmd = format (0, "del table %d %U/%d via test-eth%d",
+ table_id,
+ format_ip4_address, &tr->address,
+ tr->mask_width, tr->interface_id);
+ else
+ cmd = format (0, "del table %d %U/%d",
+ table_id,
+ format_ip4_address, &tr->address, tr->mask_width);
+ vec_add1 (cmd, 0);
+ if (verbose)
+ fformat (stderr, "ip route %s\n", cmd);
+ unformat_init_string (&cmd_input, (char *) cmd, vec_len (cmd) - 1);
+ error = vnet_ip_route_cmd (vm, &cmd_input, cmd_arg);
+ if (error)
+ clib_error_report (error);
+ unformat_free (&cmd_input);
+ vec_free (cmd);
+
+ /* Make sure all undeleted routes still work */
+ for (j = i + 1; j < nroutes; j++)
+ {
+ test_route_t *rr; /* remaining route */
+ rr = pool_elt_at_index (tm->route_pool, j);
+ if (!ip4_lookup_validate (&rr->address, table_index))
+ {
+ if (verbose)
+ fformat (stderr, "test lookup table %d %U\n",
+ table_index, format_ip4_address, &rr->address);
+
+ fformat (stderr, "FAIL: %U/%d AWOL\n",
+ format_ip4_address, &rr->address, rr->mask_width);
+ fformat (stderr, " iter %d after %d of %d deletes\n",
+ iter, i, nroutes);
+ fformat (stderr, " last route deleted %U/%d\n",
+ format_ip4_address, &tr->address, tr->mask_width);
+ }
+ }
+ }
pool_free (tm->route_pool);
}
@@ -327,9 +323,18 @@ VLIB_CLI_COMMAND (test_route_command, static) = {
};
/* *INDENT-ON* */
-clib_error_t *test_route_init (vlib_main_t *vm)
+clib_error_t *
+test_route_init (vlib_main_t * vm)
{
return 0;
}
VLIB_INIT_FUNCTION (test_route_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6.h b/vnet/vnet/ip/ip6.h
index 428a16f60aa..586b7c1b7f2 100644
--- a/vnet/vnet/ip/ip6.h
+++ b/vnet/vnet/ip/ip6.h
@@ -56,13 +56,15 @@
#define IP6_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
#define IP6_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
-typedef struct {
+typedef struct
+{
ip6_address_t addr;
u32 dst_address_length;
u32 vrf_index;
} ip6_fib_key_t;
-typedef struct {
+typedef struct
+{
/* Table ID (hash key) for this FIB. */
u32 table_id;
@@ -80,31 +82,31 @@ typedef void (ip6_add_del_interface_address_function_t)
uword opaque,
u32 sw_if_index,
ip6_address_t * address,
- u32 address_length,
- u32 if_address_index,
- u32 is_del);
+ u32 address_length, u32 if_address_index, u32 is_del);
-typedef struct {
- ip6_add_del_interface_address_function_t * function;
+typedef struct
+{
+ ip6_add_del_interface_address_function_t *function;
uword function_opaque;
} ip6_add_del_interface_address_callback_t;
/**
* Enumeration of the FIB table instance types
*/
-typedef enum ip6_fib_table_instance_type_t_ {
+typedef enum ip6_fib_table_instance_type_t_
+{
/**
* This table stores the routes that are used to forward traffic.
* The key is the prefix, the result the adjacnecy to forward on.
*/
- IP6_FIB_TABLE_FWDING,
+ IP6_FIB_TABLE_FWDING,
/**
* The table that stores ALL routes learned by the DP.
* Some of these routes may not be ready to install in forwarding
* at a given time.
* The key in this table is the prefix, the result is the fib_entry_t
*/
- IP6_FIB_TABLE_NON_FWDING,
+ IP6_FIB_TABLE_NON_FWDING,
} ip6_fib_table_instance_type_t;
#define IP6_FIB_NUM_TABLES (IP6_FIB_TABLE_NON_FWDING+1)
@@ -112,17 +114,19 @@ typedef enum ip6_fib_table_instance_type_t_ {
/**
* A represenation of a single IP6 table
*/
-typedef struct ip6_fib_table_instance_t_ {
+typedef struct ip6_fib_table_instance_t_
+{
/* The hash table */
- BVT(clib_bihash) ip6_hash;
+ BVT (clib_bihash) ip6_hash;
/* bitmap / refcounts / vector of mask widths to search */
- uword * non_empty_dst_address_length_bitmap;
- u8 * prefix_lengths_in_search_order;
+ uword *non_empty_dst_address_length_bitmap;
+ u8 *prefix_lengths_in_search_order;
i32 dst_address_length_refcounts[129];
} ip6_fib_table_instance_t;
-typedef struct ip6_main_t {
+typedef struct ip6_main_t
+{
/**
* The two FIB tables; fwding and non-fwding
*/
@@ -131,26 +135,27 @@ typedef struct ip6_main_t {
ip_lookup_main_t lookup_main;
/* Pool of FIBs. */
- struct fib_table_t_ * fibs;
+ struct fib_table_t_ *fibs;
/* Network byte orders subnet mask for each prefix length */
ip6_address_t fib_masks[129];
/* Table index indexed by software interface. */
- u32 * fib_index_by_sw_if_index;
+ u32 *fib_index_by_sw_if_index;
/* IP6 enabled count by software interface */
- u8 * ip_enabled_by_sw_if_index;
+ u8 *ip_enabled_by_sw_if_index;
/* Hash table mapping table id to fib index.
ID space is not necessarily dense; index space is dense. */
- uword * fib_index_by_table_id;
+ uword *fib_index_by_table_id;
/* Hash table mapping interface rewrite adjacency index by sw if index. */
- uword * interface_route_adj_index_by_sw_if_index;
+ uword *interface_route_adj_index_by_sw_if_index;
/* Functions to call when interface address changes. */
- ip6_add_del_interface_address_callback_t * add_del_interface_address_callbacks;
+ ip6_add_del_interface_address_callback_t
+ * add_del_interface_address_callbacks;
/* Template used to generate IP6 neighbor solicitation packets. */
vlib_packet_template_t discover_neighbor_packet_template;
@@ -162,7 +167,8 @@ typedef struct ip6_main_t {
/* Seed for Jenkins hash used to compute ip6 flow hash. */
u32 flow_hash_seed;
- struct {
+ struct
+ {
/* TTL to use for host generated packets. */
u8 ttl;
@@ -187,13 +193,16 @@ extern vlib_node_registration_t ip6_midchain_node;
extern vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node;
/* ipv6 neighbor discovery - timer/event types */
-typedef enum {
+typedef enum
+{
ICMP6_ND_EVENT_INIT,
} ip6_icmp_neighbor_discovery_event_type_t;
-typedef union {
+typedef union
+{
u32 add_del_swindex;
- struct {
+ struct
+ {
u32 up_down_swindex;
u32 fib_index;
} up_down_event;
@@ -202,13 +211,13 @@ typedef union {
always_inline uword
ip6_destination_matches_route (const ip6_main_t * im,
const ip6_address_t * key,
- const ip6_address_t * dest,
- uword dest_length)
+ const ip6_address_t * dest, uword dest_length)
{
int i;
for (i = 0; i < ARRAY_LEN (key->as_uword); i++)
{
- if ((key->as_uword[i] ^ dest->as_uword[i]) & im->fib_masks[dest_length].as_uword[i])
+ if ((key->as_uword[i] ^ dest->as_uword[i]) & im->
+ fib_masks[dest_length].as_uword[i])
return 0;
}
return 1;
@@ -219,7 +228,7 @@ ip6_destination_matches_interface (ip6_main_t * im,
ip6_address_t * key,
ip_interface_address_t * ia)
{
- ip6_address_t * a = ip_interface_address_get_address (&im->lookup_main, ia);
+ ip6_address_t *a = ip_interface_address_get_address (&im->lookup_main, ia);
return ip6_destination_matches_route (im, key, a, ia->address_length);
}
@@ -233,7 +242,8 @@ ip6_unaligned_destination_matches_route (ip6_main_t * im,
int i;
for (i = 0; i < ARRAY_LEN (key->as_uword); i++)
{
- if ((clib_mem_unaligned (&key->as_uword[i], uword) ^ dest->as_uword[i]) & im->fib_masks[dest_length].as_uword[i])
+ if ((clib_mem_unaligned (&key->as_uword[i], uword) ^ dest->as_uword[i])
+ & im->fib_masks[dest_length].as_uword[i])
return 0;
}
return 1;
@@ -241,36 +251,38 @@ ip6_unaligned_destination_matches_route (ip6_main_t * im,
always_inline int
ip6_src_address_for_packet (ip_lookup_main_t * lm,
- u32 sw_if_index,
- ip6_address_t * src)
+ u32 sw_if_index, ip6_address_t * src)
{
- u32 if_add_index =
- lm->if_address_pool_index_by_sw_if_index[sw_if_index];
- if (PREDICT_TRUE(if_add_index != ~0)) {
- ip_interface_address_t *if_add =
- pool_elt_at_index(lm->if_address_pool, if_add_index);
- ip6_address_t *if_ip =
- ip_interface_address_get_address(lm, if_add);
- *src = *if_ip;
- return (0);
+ u32 if_add_index = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
+ if (PREDICT_TRUE (if_add_index != ~0))
+ {
+ ip_interface_address_t *if_add =
+ pool_elt_at_index (lm->if_address_pool, if_add_index);
+ ip6_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
+ *src = *if_ip;
+ return (0);
}
- else
+ else
{
- src->as_u64[0] = 0;
- src->as_u64[1] = 0;
+ src->as_u64[0] = 0;
+ src->as_u64[1] = 0;
}
- return (!0);
+ return (!0);
}
/* Find interface address which matches destination. */
always_inline ip6_address_t *
-ip6_interface_address_matching_destination (ip6_main_t * im, ip6_address_t * dst, u32 sw_if_index,
- ip_interface_address_t ** result_ia)
+ip6_interface_address_matching_destination (ip6_main_t * im,
+ ip6_address_t * dst,
+ u32 sw_if_index,
+ ip_interface_address_t **
+ result_ia)
{
- ip_lookup_main_t * lm = &im->lookup_main;
- ip_interface_address_t * ia;
- ip6_address_t * result = 0;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip_interface_address_t *ia;
+ ip6_address_t *result = 0;
+ /* *INDENT-OFF* */
foreach_ip_interface_address (lm, ia, sw_if_index,
1 /* honor unnumbered */,
({
@@ -281,128 +293,115 @@ ip6_interface_address_matching_destination (ip6_main_t * im, ip6_address_t * dst
break;
}
}));
+ /* *INDENT-ON* */
if (result_ia)
*result_ia = result ? ia : 0;
return result;
}
-clib_error_t *
-ip6_add_del_interface_address (vlib_main_t * vm, u32 sw_if_index,
- ip6_address_t * address, u32 address_length,
- u32 is_del);
-void
-ip6_sw_interface_enable_disable (u32 sw_if_index,
- u32 is_enable);
+clib_error_t *ip6_add_del_interface_address (vlib_main_t * vm,
+ u32 sw_if_index,
+ ip6_address_t * address,
+ u32 address_length, u32 is_del);
+void ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable);
int ip6_address_compare (ip6_address_t * a1, ip6_address_t * a2);
-clib_error_t *
-ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index);
+clib_error_t *ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst,
+ u32 sw_if_index);
-clib_error_t *
-ip6_set_neighbor_limit (u32 neighbor_limit);
+clib_error_t *ip6_set_neighbor_limit (u32 neighbor_limit);
uword
ip6_udp_register_listener (vlib_main_t * vm,
- u16 dst_port,
- u32 next_node_index);
+ u16 dst_port, u32 next_node_index);
-u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6_header_t * ip0, int *bogus_lengthp);
+u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
+ ip6_header_t * ip0,
+ int *bogus_lengthp);
void ip6_register_protocol (u32 protocol, u32 node_index);
serialize_function_t serialize_vnet_ip6_main, unserialize_vnet_ip6_main;
void ip6_ethernet_update_adjacency (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 ai);
+ u32 sw_if_index, u32 ai);
int
vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t * a,
- u8 * link_layer_address,
- uword n_bytes_link_layer_address,
- int is_static);
+ u32 sw_if_index,
+ ip6_address_t * a,
+ u8 * link_layer_address,
+ uword n_bytes_link_layer_address,
+ int is_static);
int
vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t * a,
- u8 * link_layer_address,
- uword n_bytes_link_layer_address);
+ u32 sw_if_index,
+ ip6_address_t * a,
+ u8 * link_layer_address,
+ uword n_bytes_link_layer_address);
void
-ip6_link_local_address_from_ethernet_mac_address (ip6_address_t *ip,
- u8 *mac);
+ip6_link_local_address_from_ethernet_mac_address (ip6_address_t * ip,
+ u8 * mac);
void
-ip6_ethernet_mac_address_from_link_local_address (u8 *mac,
- ip6_address_t *ip);
+ip6_ethernet_mac_address_from_link_local_address (u8 * mac,
+ ip6_address_t * ip);
int vnet_set_ip6_flow_hash (u32 table_id,
flow_hash_config_t flow_hash_config);
int
-ip6_neighbor_ra_config(vlib_main_t * vm, u32 sw_if_index,
- u8 suppress, u8 managed, u8 other,
- u8 ll_option, u8 send_unicast, u8 cease,
- u8 use_lifetime, u32 lifetime,
- u32 initial_count, u32 initial_interval,
- u32 max_interval, u32 min_interval,
- u8 is_no);
+ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index,
+ u8 suppress, u8 managed, u8 other,
+ u8 ll_option, u8 send_unicast, u8 cease,
+ u8 use_lifetime, u32 lifetime,
+ u32 initial_count, u32 initial_interval,
+ u32 max_interval, u32 min_interval, u8 is_no);
int
-ip6_neighbor_ra_prefix(vlib_main_t * vm, u32 sw_if_index,
- ip6_address_t *prefix_addr, u8 prefix_len,
- u8 use_default, u32 val_lifetime, u32 pref_lifetime,
- u8 no_advertise, u8 off_link, u8 no_autoconfig, u8 no_onlink,
- u8 is_no);
+ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index,
+ ip6_address_t * prefix_addr, u8 prefix_len,
+ u8 use_default, u32 val_lifetime, u32 pref_lifetime,
+ u8 no_advertise, u8 off_link, u8 no_autoconfig,
+ u8 no_onlink, u8 is_no);
-clib_error_t *
-enable_ip6_interface(vlib_main_t * vm,
- u32 sw_if_index);
+clib_error_t *enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index);
-clib_error_t *
-disable_ip6_interface(vlib_main_t * vm,
- u32 sw_if_index);
+clib_error_t *disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index);
-int
-ip6_interface_enabled(vlib_main_t * vm,
- u32 sw_if_index);
+int ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index);
-clib_error_t *
-set_ip6_link_local_address(vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t *address,
- u8 address_length);
+clib_error_t *set_ip6_link_local_address (vlib_main_t * vm,
+ u32 sw_if_index,
+ ip6_address_t * address,
+ u8 address_length);
-void vnet_register_ip6_neighbor_resolution_event(vnet_main_t * vnm,
- void * address_arg,
- uword node_index,
- uword type_opaque,
- uword data);
+void vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
+ void *address_arg,
+ uword node_index,
+ uword type_opaque,
+ uword data);
int vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
- void * data_callback,
+ void *data_callback,
u32 pid,
- void * address_arg,
+ void *address_arg,
uword node_index,
uword type_opaque,
- uword data,
- int is_add);
+ uword data, int is_add);
int vnet_ip6_nd_term (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_buffer_t * p0,
ethernet_header_t * eth,
ip6_header_t * ip,
- u32 sw_if_index,
- u16 bd_index,
- u8 shg);
+ u32 sw_if_index, u16 bd_index, u8 shg);
int vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
- u32 table_index);
+ u32 table_index);
extern vlib_node_registration_t ip6_lookup_node;
/* Compute flow hash. We'll use it to select which Sponge to use for this
@@ -411,50 +410,55 @@ always_inline u32
ip6_compute_flow_hash (const ip6_header_t * ip,
flow_hash_config_t flow_hash_config)
{
- tcp_header_t * tcp = (void *) (ip + 1);
- u64 a, b, c;
- u64 t1, t2;
- uword is_tcp_udp = (ip->protocol == IP_PROTOCOL_TCP
- || ip->protocol == IP_PROTOCOL_UDP);
+ tcp_header_t *tcp = (void *) (ip + 1);
+ u64 a, b, c;
+ u64 t1, t2;
+ uword is_tcp_udp = (ip->protocol == IP_PROTOCOL_TCP
+ || ip->protocol == IP_PROTOCOL_UDP);
- t1 = (ip->src_address.as_u64[0] ^ ip->src_address.as_u64[1]);
- t1 = (flow_hash_config & IP_FLOW_HASH_SRC_ADDR) ? t1 : 0;
+ t1 = (ip->src_address.as_u64[0] ^ ip->src_address.as_u64[1]);
+ t1 = (flow_hash_config & IP_FLOW_HASH_SRC_ADDR) ? t1 : 0;
- t2 = (ip->dst_address.as_u64[0] ^ ip->dst_address.as_u64[1]);
- t2 = (flow_hash_config & IP_FLOW_HASH_DST_ADDR) ? t2 : 0;
+ t2 = (ip->dst_address.as_u64[0] ^ ip->dst_address.as_u64[1]);
+ t2 = (flow_hash_config & IP_FLOW_HASH_DST_ADDR) ? t2 : 0;
- a = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t2 : t1;
- b = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t1 : t2;
- b ^= (flow_hash_config & IP_FLOW_HASH_PROTO) ? ip->protocol : 0;
+ a = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t2 : t1;
+ b = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t1 : t2;
+ b ^= (flow_hash_config & IP_FLOW_HASH_PROTO) ? ip->protocol : 0;
- t1 = is_tcp_udp ? tcp->ports.src : 0;
- t2 = is_tcp_udp ? tcp->ports.dst : 0;
+ t1 = is_tcp_udp ? tcp->ports.src : 0;
+ t2 = is_tcp_udp ? tcp->ports.dst : 0;
- t1 = (flow_hash_config & IP_FLOW_HASH_SRC_PORT) ? t1 : 0;
- t2 = (flow_hash_config & IP_FLOW_HASH_DST_PORT) ? t2 : 0;
+ t1 = (flow_hash_config & IP_FLOW_HASH_SRC_PORT) ? t1 : 0;
+ t2 = (flow_hash_config & IP_FLOW_HASH_DST_PORT) ? t2 : 0;
- c = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ?
- ((t1<<16) | t2) : ((t2<<16) | t1);
+ c = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ?
+ ((t1 << 16) | t2) : ((t2 << 16) | t1);
- hash_mix64 (a, b, c);
- return (u32) c;
+ hash_mix64 (a, b, c);
+ return (u32) c;
}
/*
* Hop-by-Hop handling
*/
-typedef struct {
+typedef struct
+{
/* Array of function pointers to HBH option handling routines */
- int (*options[256])(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt);
- u8 *(*trace[256])(u8 *s, ip6_hop_by_hop_option_t *opt);
+ int (*options[256]) (vlib_buffer_t * b, ip6_header_t * ip,
+ ip6_hop_by_hop_option_t * opt);
+ u8 *(*trace[256]) (u8 * s, ip6_hop_by_hop_option_t * opt);
uword next_override;
} ip6_hop_by_hop_main_t;
extern ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
int ip6_hbh_register_option (u8 option,
- int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt),
- u8 *trace(u8 *s, ip6_hop_by_hop_option_t *opt));
+ int options (vlib_buffer_t * b,
+ ip6_header_t * ip,
+ ip6_hop_by_hop_option_t * opt),
+ u8 * trace (u8 * s,
+ ip6_hop_by_hop_option_t * opt));
int ip6_hbh_unregister_option (u8 option);
void ip6_hbh_set_next_override (uword next);
@@ -462,3 +466,11 @@ void ip6_hbh_set_next_override (uword next);
#define OI_DECAP 0x80000000
#endif /* included_ip_ip6_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_error.h b/vnet/vnet/ip/ip6_error.h
index c28cda20f57..a2807169123 100644
--- a/vnet/vnet/ip/ip6_error.h
+++ b/vnet/vnet/ip/ip6_error.h
@@ -73,11 +73,20 @@
_ (INACL_TABLE_MISS, "input ACL table-miss drops") \
_ (INACL_SESSION_DENY, "input ACL session deny drops")
-typedef enum {
+typedef enum
+{
#define _(sym,str) IP6_ERROR_##sym,
foreach_ip6_error
#undef _
- IP6_N_ERROR,
+ IP6_N_ERROR,
} ip6_error_t;
#endif /* included_ip_ip6_error_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_format.c b/vnet/vnet/ip/ip6_format.c
index 5d32189478b..56899b73d8b 100644
--- a/vnet/vnet/ip/ip6_format.c
+++ b/vnet/vnet/ip/ip6_format.c
@@ -40,11 +40,12 @@
#include <vnet/ip/ip.h>
/* Format an IP6 address. */
-u8 * format_ip6_address (u8 * s, va_list * args)
+u8 *
+format_ip6_address (u8 * s, va_list * args)
{
- ip6_address_t * a = va_arg (*args, ip6_address_t *);
+ ip6_address_t *a = va_arg (*args, ip6_address_t *);
u32 max_zero_run = 0, this_zero_run = 0;
- int max_zero_run_index = -1, this_zero_run_index=0;
+ int max_zero_run_index = -1, this_zero_run_index = 0;
int in_zero_run = 0, i;
int last_double_colon = 0;
@@ -52,49 +53,49 @@ u8 * format_ip6_address (u8 * s, va_list * args)
for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
{
if (a->as_u16[i] == 0)
- {
- if (in_zero_run)
- this_zero_run++;
- else
- {
- in_zero_run = 1;
- this_zero_run =1;
- this_zero_run_index = i;
- }
- }
+ {
+ if (in_zero_run)
+ this_zero_run++;
+ else
+ {
+ in_zero_run = 1;
+ this_zero_run = 1;
+ this_zero_run_index = i;
+ }
+ }
else
- {
- if (in_zero_run)
- {
- /* offer to compress the biggest run of > 1 zero */
- if (this_zero_run > max_zero_run && this_zero_run > 1)
- {
- max_zero_run_index = this_zero_run_index;
- max_zero_run = this_zero_run;
- }
- }
- in_zero_run = 0;
- this_zero_run = 0;
- }
+ {
+ if (in_zero_run)
+ {
+ /* offer to compress the biggest run of > 1 zero */
+ if (this_zero_run > max_zero_run && this_zero_run > 1)
+ {
+ max_zero_run_index = this_zero_run_index;
+ max_zero_run = this_zero_run;
+ }
+ }
+ in_zero_run = 0;
+ this_zero_run = 0;
+ }
}
if (in_zero_run)
{
if (this_zero_run > max_zero_run && this_zero_run > 1)
- {
- max_zero_run_index = this_zero_run_index;
- max_zero_run = this_zero_run;
- }
+ {
+ max_zero_run_index = this_zero_run_index;
+ max_zero_run = this_zero_run;
+ }
}
-
+
for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
{
if (i == max_zero_run_index)
- {
+ {
s = format (s, "::");
- i += max_zero_run - 1;
- last_double_colon = 1;
- }
+ i += max_zero_run - 1;
+ last_double_colon = 1;
+ }
else
{
s = format (s, "%s%x",
@@ -108,17 +109,19 @@ u8 * format_ip6_address (u8 * s, va_list * args)
}
/* Format an IP6 route destination and length. */
-u8 * format_ip6_address_and_length (u8 * s, va_list * args)
+u8 *
+format_ip6_address_and_length (u8 * s, va_list * args)
{
- ip6_address_t * a = va_arg (*args, ip6_address_t *);
+ ip6_address_t *a = va_arg (*args, ip6_address_t *);
u8 l = va_arg (*args, u32);
return format (s, "%U/%d", format_ip6_address, a, l);
}
/* Parse an IP6 address. */
-uword unformat_ip6_address (unformat_input_t * input, va_list * args)
+uword
+unformat_ip6_address (unformat_input_t * input, va_list * args)
{
- ip6_address_t * result = va_arg (*args, ip6_address_t *);
+ ip6_address_t *result = va_arg (*args, ip6_address_t *);
u16 hex_quads[8];
uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
uword c, n_colon, double_colon_index;
@@ -157,7 +160,7 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args)
n_colon = 0;
n_hex_digits++;
}
-
+
/* Save position of :: */
if (n_colon == 2)
{
@@ -190,10 +193,10 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args)
hex_quads[n_zero + i] = hex_quads[i];
for (i = 0; i < n_zero; i++)
- {
- ASSERT ((double_colon_index + i) < ARRAY_LEN (hex_quads));
- hex_quads[double_colon_index + i] = 0;
- }
+ {
+ ASSERT ((double_colon_index + i) < ARRAY_LEN (hex_quads));
+ hex_quads[double_colon_index + i] = 0;
+ }
n_hex_quads = ARRAY_LEN (hex_quads);
}
@@ -210,9 +213,10 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args)
}
/* Format an IP6 header. */
-u8 * format_ip6_header (u8 * s, va_list * args)
+u8 *
+format_ip6_header (u8 * s, va_list * args)
{
- ip6_header_t * ip = va_arg (*args, ip6_header_t *);
+ ip6_header_t *ip = va_arg (*args, ip6_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
u32 i, ip_version, traffic_class, flow_label;
uword indent;
@@ -235,25 +239,24 @@ u8 * format_ip6_header (u8 * s, va_list * args)
flow_label = i & pow2_mask (20);
if (ip_version != 6)
- s = format (s, "\n%Uversion %d",
- format_white_space, indent, ip_version);
-
- s = format (s, "\n%Utos 0x%02x, flow label 0x%x, hop limit %d, payload length %d",
- format_white_space, indent,
- traffic_class, flow_label, ip->hop_limit,
- clib_net_to_host_u16 (ip->payload_length));
+ s = format (s, "\n%Uversion %d", format_white_space, indent, ip_version);
+
+ s =
+ format (s,
+ "\n%Utos 0x%02x, flow label 0x%x, hop limit %d, payload length %d",
+ format_white_space, indent, traffic_class, flow_label,
+ ip->hop_limit, clib_net_to_host_u16 (ip->payload_length));
/* Recurse into next protocol layer. */
if (max_header_bytes != 0 && sizeof (ip[0]) < max_header_bytes)
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi = ip_get_protocol_info (im, ip->protocol);
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi = ip_get_protocol_info (im, ip->protocol);
if (pi && pi->format_header)
s = format (s, "\n%U%U",
- format_white_space, indent - 2,
- pi->format_header,
- /* next protocol header */ (void*) (ip + 1),
+ format_white_space, indent - 2, pi->format_header,
+ /* next protocol header */ (void *) (ip + 1),
max_header_bytes - sizeof (ip[0]));
}
@@ -261,15 +264,16 @@ u8 * format_ip6_header (u8 * s, va_list * args)
}
/* Parse an IP6 header. */
-uword unformat_ip6_header (unformat_input_t * input, va_list * args)
+uword
+unformat_ip6_header (unformat_input_t * input, va_list * args)
{
- u8 ** result = va_arg (*args, u8 **);
- ip6_header_t * ip;
+ u8 **result = va_arg (*args, u8 **);
+ ip6_header_t *ip;
int old_length;
/* Allocate space for IP header. */
{
- void * p;
+ void *p;
old_length = vec_len (*result);
vec_add2 (*result, p, sizeof (ip[0]));
@@ -277,12 +281,13 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args)
}
memset (ip, 0, sizeof (ip[0]));
- ip->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (6 << 28);
+ ip->ip_version_traffic_class_and_flow_label =
+ clib_host_to_net_u32 (6 << 28);
- if (! unformat (input, "%U: %U -> %U",
- unformat_ip_protocol, &ip->protocol,
- unformat_ip6_address, &ip->src_address,
- unformat_ip6_address, &ip->dst_address))
+ if (!unformat (input, "%U: %U -> %U",
+ unformat_ip_protocol, &ip->protocol,
+ unformat_ip6_address, &ip->src_address,
+ unformat_ip6_address, &ip->dst_address))
return 0;
/* Parse options. */
@@ -291,7 +296,8 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args)
int i;
if (unformat (input, "tos %U", unformat_vlib_number, &i))
- ip->ip_version_traffic_class_and_flow_label |= clib_host_to_net_u32 ((i & 0xff) << 20);
+ ip->ip_version_traffic_class_and_flow_label |=
+ clib_host_to_net_u32 ((i & 0xff) << 20);
else if (unformat (input, "hop-limit %U", unformat_vlib_number, &i))
ip->hop_limit = i;
@@ -303,12 +309,12 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args)
/* Recurse into next protocol layer. */
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi = ip_get_protocol_info (im, ip->protocol);
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi = ip_get_protocol_info (im, ip->protocol);
if (pi && pi->unformat_header)
{
- if (! unformat_user (input, pi->unformat_header, result))
+ if (!unformat_user (input, pi->unformat_header, result))
return 0;
/* Result may have moved. */
@@ -316,29 +322,35 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args)
}
}
- ip->payload_length = clib_host_to_net_u16 (vec_len (*result) - (old_length + sizeof (ip[0])));
+ ip->payload_length =
+ clib_host_to_net_u16 (vec_len (*result) - (old_length + sizeof (ip[0])));
return 1;
}
/* Parse an IP46 address. */
-uword unformat_ip46_address (unformat_input_t * input, va_list * args)
+uword
+unformat_ip46_address (unformat_input_t * input, va_list * args)
{
ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
ip46_type_t type = va_arg (*args, ip46_type_t);
if ((type != IP46_TYPE_IP6) &&
- unformat(input, "%U", unformat_ip4_address, &ip46->ip4)) {
- ip46_address_mask_ip4(ip46);
- return 1;
- } else if ((type != IP46_TYPE_IP4) &&
- unformat(input, "%U", unformat_ip6_address, &ip46->ip6)) {
- return 1;
- }
+ unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
+ {
+ ip46_address_mask_ip4 (ip46);
+ return 1;
+ }
+ else if ((type != IP46_TYPE_IP4) &&
+ unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
+ {
+ return 1;
+ }
return 0;
}
/* Format an IP46 address. */
-u8 * format_ip46_address (u8 * s, va_list * args)
+u8 *
+format_ip46_address (u8 * s, va_list * args)
{
ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
ip46_type_t type = va_arg (*args, ip46_type_t);
@@ -346,18 +358,26 @@ u8 * format_ip46_address (u8 * s, va_list * args)
switch (type)
{
- case IP46_TYPE_ANY:
- is_ip4 = ip46_address_is_ip4(ip46);
- break;
- case IP46_TYPE_IP4:
- is_ip4 = 1;
- break;
- case IP46_TYPE_IP6:
- is_ip4 = 0;
- break;
+ case IP46_TYPE_ANY:
+ is_ip4 = ip46_address_is_ip4 (ip46);
+ break;
+ case IP46_TYPE_IP4:
+ is_ip4 = 1;
+ break;
+ case IP46_TYPE_IP6:
+ is_ip4 = 0;
+ break;
}
return is_ip4 ?
- format(s, "%U", format_ip4_address, &ip46->ip4):
- format(s, "%U", format_ip6_address, &ip46->ip6);
+ format (s, "%U", format_ip4_address, &ip46->ip4) :
+ format (s, "%U", format_ip6_address, &ip46->ip6);
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_forward.c b/vnet/vnet/ip/ip6_forward.c
index 6b74b7c9135..b5c795523ca 100644
--- a/vnet/vnet/ip/ip6_forward.c
+++ b/vnet/vnet/ip/ip6_forward.c
@@ -39,7 +39,7 @@
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
-#include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
+#include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
#include <vnet/srp/srp.h> /* for srp_hw_interface_class */
#include <vppinfra/cache.h>
#include <vnet/fib/fib_table.h>
@@ -58,20 +58,19 @@
void
ip6_forward_next_trace (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- vlib_rx_or_tx_t which_adj_index);
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame,
+ vlib_rx_or_tx_t which_adj_index);
always_inline uword
ip6_lookup_inline (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- ip6_main_t * im = &ip6_main;
- vlib_combined_counter_main_t * cm = &load_balance_main.lbm_to_counters;
- u32 n_left_from, n_left_to_next, * from, * to_next;
+ ip6_main_t *im = &ip6_main;
+ vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters;
+ u32 n_left_from, n_left_to_next, *from, *to_next;
ip_lookup_next_t next;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -79,24 +78,23 @@ ip6_lookup_inline (vlib_main_t * vm,
while (n_left_from > 0)
{
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- vlib_buffer_t * p0, * p1;
+ vlib_buffer_t *p0, *p1;
u32 pi0, pi1, lbi0, lbi1, wrong_next;
ip_lookup_next_t next0, next1;
- ip6_header_t * ip0, * ip1;
- ip6_address_t * dst_addr0, * dst_addr1;
- u32 fib_index0, fib_index1;
- u32 flow_hash_config0, flow_hash_config1;
+ ip6_header_t *ip0, *ip1;
+ ip6_address_t *dst_addr0, *dst_addr1;
+ u32 fib_index0, fib_index1;
+ u32 flow_hash_config0, flow_hash_config1;
const dpo_id_t *dpo0, *dpo1;
const load_balance_t *lb0, *lb1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -119,13 +117,17 @@ ip6_lookup_inline (vlib_main_t * vm,
dst_addr0 = &ip0->dst_address;
dst_addr1 = &ip1->dst_address;
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]);
+ fib_index0 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index1 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p1)->sw_if_index[VLIB_RX]);
- fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
- fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX];
+ fib_index0 = (vnet_buffer (p0)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
+ fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
+ fib_index1 = (vnet_buffer (p1)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
+ fib_index1 : vnet_buffer (p1)->sw_if_index[VLIB_TX];
lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0);
lbi1 = ip6_fib_table_fwding_lookup (im, fib_index1, dst_addr1);
@@ -133,65 +135,64 @@ ip6_lookup_inline (vlib_main_t * vm,
lb0 = load_balance_get (lbi0);
lb1 = load_balance_get (lbi1);
- vnet_buffer (p0)->ip.flow_hash =
- vnet_buffer(p1)->ip.flow_hash = 0;
-
- if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
- {
- flow_hash_config0 = lb0->lb_hash_config;
- vnet_buffer (p0)->ip.flow_hash =
- ip6_compute_flow_hash (ip0, flow_hash_config0);
- }
- if (PREDICT_FALSE(lb1->lb_n_buckets > 1))
- {
- flow_hash_config1 = lb1->lb_hash_config;
- vnet_buffer (p1)->ip.flow_hash =
- ip6_compute_flow_hash (ip1, flow_hash_config1);
- }
+ vnet_buffer (p0)->ip.flow_hash = vnet_buffer (p1)->ip.flow_hash = 0;
+
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ flow_hash_config0 = lb0->lb_hash_config;
+ vnet_buffer (p0)->ip.flow_hash =
+ ip6_compute_flow_hash (ip0, flow_hash_config0);
+ }
+ if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
+ {
+ flow_hash_config1 = lb1->lb_hash_config;
+ vnet_buffer (p1)->ip.flow_hash =
+ ip6_compute_flow_hash (ip1, flow_hash_config1);
+ }
ASSERT (lb0->lb_n_buckets > 0);
ASSERT (lb1->lb_n_buckets > 0);
ASSERT (is_pow2 (lb0->lb_n_buckets));
ASSERT (is_pow2 (lb1->lb_n_buckets));
- dpo0 = load_balance_get_bucket_i(lb0,
- (vnet_buffer (p0)->ip.flow_hash &
- lb0->lb_n_buckets_minus_1));
- dpo1 = load_balance_get_bucket_i(lb1,
- (vnet_buffer (p1)->ip.flow_hash &
- lb1->lb_n_buckets_minus_1));
+ dpo0 = load_balance_get_bucket_i (lb0,
+ (vnet_buffer (p0)->ip.flow_hash &
+ lb0->lb_n_buckets_minus_1));
+ dpo1 = load_balance_get_bucket_i (lb1,
+ (vnet_buffer (p1)->ip.flow_hash &
+ lb1->lb_n_buckets_minus_1));
next0 = dpo0->dpoi_next_node;
next1 = dpo1->dpoi_next_node;
/* Only process the HBH Option Header if explicitly configured to do so */
- if (PREDICT_FALSE(ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE
+ (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- next0 = (dpo_is_adj(dpo0) && im->hbh_enabled) ?
+ next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
(ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
}
- if (PREDICT_FALSE(ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE
+ (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- next1 = (dpo_is_adj(dpo1) && im->hbh_enabled) ?
+ next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
(ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
}
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
vlib_increment_combined_counter
- (cm, cpu_index, lbi1, 1,
- vlib_buffer_length_in_chain (vm, p1));
+ (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
from += 2;
to_next += 2;
n_left_to_next -= 2;
n_left_from -= 2;
- wrong_next = (next0 != next) + 2*(next1 != next);
+ wrong_next = (next0 != next) + 2 * (next1 != next);
if (PREDICT_FALSE (wrong_next != 0))
- {
+ {
switch (wrong_next)
{
case 1:
@@ -220,7 +221,8 @@ ip6_lookup_inline (vlib_main_t * vm,
/* A B B */
vlib_put_next_frame (vm, node, next, n_left_to_next);
next = next1;
- vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next,
+ n_left_to_next);
}
}
}
@@ -228,13 +230,13 @@ ip6_lookup_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
u32 pi0, lbi0;
ip_lookup_next_t next0;
- load_balance_t * lb0;
- ip6_address_t * dst_addr0;
- u32 fib_index0, flow_hash_config0;
+ load_balance_t *lb0;
+ ip6_address_t *dst_addr0;
+ u32 fib_index0, flow_hash_config0;
const dpo_id_t *dpo0;
pi0 = from[0];
@@ -246,44 +248,46 @@ ip6_lookup_inline (vlib_main_t * vm,
dst_addr0 = &ip0->dst_address;
- fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
- fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
- fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
+ fib_index0 =
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+ fib_index0 =
+ (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
+ (u32) ~ 0) ? fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
- flow_hash_config0 =
- ip6_fib_get (fib_index0)->flow_hash_config;
+ flow_hash_config0 = ip6_fib_get (fib_index0)->flow_hash_config;
lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0);
lb0 = load_balance_get (lbi0);
- vnet_buffer (p0)->ip.flow_hash = 0;
+ vnet_buffer (p0)->ip.flow_hash = 0;
- if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
- {
- flow_hash_config0 = lb0->lb_hash_config;
- vnet_buffer (p0)->ip.flow_hash =
- ip6_compute_flow_hash (ip0, flow_hash_config0);
- }
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ flow_hash_config0 = lb0->lb_hash_config;
+ vnet_buffer (p0)->ip.flow_hash =
+ ip6_compute_flow_hash (ip0, flow_hash_config0);
+ }
ASSERT (lb0->lb_n_buckets > 0);
ASSERT (is_pow2 (lb0->lb_n_buckets));
- dpo0 = load_balance_get_bucket_i(lb0,
- (vnet_buffer (p0)->ip.flow_hash &
- lb0->lb_n_buckets_minus_1));
+ dpo0 = load_balance_get_bucket_i (lb0,
+ (vnet_buffer (p0)->ip.flow_hash &
+ lb0->lb_n_buckets_minus_1));
next0 = dpo0->dpoi_next_node;
/* Only process the HBH Option Header if explicitly configured to do so */
- if (PREDICT_FALSE(ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE
+ (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- next0 = (dpo_is_adj(dpo0) && im->hbh_enabled) ?
+ next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
(ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
}
vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
from += 1;
to_next += 1;
@@ -295,8 +299,7 @@ ip6_lookup_inline (vlib_main_t * vm,
n_left_to_next += 1;
vlib_put_next_frame (vm, node, next, n_left_to_next);
next = next0;
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
to_next[0] = pi0;
to_next += 1;
n_left_to_next -= 1;
@@ -307,7 +310,7 @@ ip6_lookup_inline (vlib_main_t * vm,
}
if (node->flags & VLIB_NODE_FLAG_TRACE)
- ip6_forward_next_trace(vm, node, frame, VLIB_TX);
+ ip6_forward_next_trace (vm, node, frame, VLIB_TX);
return frame->n_vectors;
}
@@ -317,102 +320,77 @@ ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
ip6_main_t * im, u32 fib_index,
ip_interface_address_t * a)
{
- ip_lookup_main_t * lm = &im->lookup_main;
- ip6_address_t * address = ip_interface_address_get_address (lm, a);
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip6_address_t *address = ip_interface_address_get_address (lm, a);
fib_prefix_t pfx = {
- .fp_len = a->address_length,
- .fp_proto = FIB_PROTOCOL_IP6,
- .fp_addr.ip6 = *address,
+ .fp_len = a->address_length,
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_addr.ip6 = *address,
};
a->neighbor_probe_adj_index = ~0;
if (a->address_length < 128)
- {
+ {
fib_node_index_t fei;
- fei = fib_table_entry_update_one_path(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE,
- (FIB_ENTRY_FLAG_CONNECTED |
- FIB_ENTRY_FLAG_ATTACHED),
- FIB_PROTOCOL_IP6,
- NULL, /* No next-hop address */
- sw_if_index,
- ~0, // invalid FIB index
- 1,
- NULL, // no label stack
- FIB_ROUTE_PATH_FLAG_NONE);
- a->neighbor_probe_adj_index = fib_entry_get_adj(fei);
- }
+ fei = fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_ATTACHED), FIB_PROTOCOL_IP6, NULL, /* No next-hop address */
+ sw_if_index, ~0, // invalid FIB index
+ 1, NULL, // no label stack
+ FIB_ROUTE_PATH_FLAG_NONE);
+ a->neighbor_probe_adj_index = fib_entry_get_adj (fei);
+ }
pfx.fp_len = 128;
if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
- {
+ {
u32 classify_table_index =
- lm->classify_table_index_by_sw_if_index [sw_if_index];
- if (classify_table_index != (u32) ~0)
- {
- dpo_id_t dpo = DPO_INVALID;
-
- dpo_set(&dpo,
- DPO_CLASSIFY,
- DPO_PROTO_IP6,
- classify_dpo_create(DPO_PROTO_IP6, classify_table_index));
-
- fib_table_entry_special_dpo_add(fib_index,
- &pfx,
- FIB_SOURCE_CLASSIFY,
- FIB_ENTRY_FLAG_NONE,
- &dpo);
- dpo_reset(&dpo);
- }
- }
+ lm->classify_table_index_by_sw_if_index[sw_if_index];
+ if (classify_table_index != (u32) ~ 0)
+ {
+ dpo_id_t dpo = DPO_INVALID;
+
+ dpo_set (&dpo,
+ DPO_CLASSIFY,
+ DPO_PROTO_IP6,
+ classify_dpo_create (DPO_PROTO_IP6, classify_table_index));
+
+ fib_table_entry_special_dpo_add (fib_index,
+ &pfx,
+ FIB_SOURCE_CLASSIFY,
+ FIB_ENTRY_FLAG_NONE, &dpo);
+ dpo_reset (&dpo);
+ }
+ }
- fib_table_entry_update_one_path(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE,
- (FIB_ENTRY_FLAG_CONNECTED |
- FIB_ENTRY_FLAG_LOCAL),
- FIB_PROTOCOL_IP6,
- &pfx.fp_addr,
- sw_if_index,
- ~0, // invalid FIB index
- 1,
- NULL,
- FIB_ROUTE_PATH_FLAG_NONE);
+ fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL), FIB_PROTOCOL_IP6, &pfx.fp_addr, sw_if_index, ~0, // invalid FIB index
+ 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
}
static void
ip6_del_interface_routes (ip6_main_t * im,
u32 fib_index,
- ip6_address_t * address,
- u32 address_length)
+ ip6_address_t * address, u32 address_length)
{
- fib_prefix_t pfx = {
- .fp_len = address_length,
- .fp_proto = FIB_PROTOCOL_IP6,
- .fp_addr.ip6 = *address,
- };
+ fib_prefix_t pfx = {
+ .fp_len = address_length,
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_addr.ip6 = *address,
+ };
- if (pfx.fp_len < 128)
+ if (pfx.fp_len < 128)
{
- fib_table_entry_delete(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE);
+ fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
}
- pfx.fp_len = 128;
- fib_table_entry_delete(fib_index,
- &pfx,
- FIB_SOURCE_INTERFACE);
+ pfx.fp_len = 128;
+ fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
}
void
-ip6_sw_interface_enable_disable (u32 sw_if_index,
- u32 is_enable)
+ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
{
- ip6_main_t * im = &ip6_main;
+ ip6_main_t *im = &ip6_main;
vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
@@ -422,13 +400,13 @@ ip6_sw_interface_enable_disable (u32 sw_if_index,
if (is_enable)
{
if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
- return;
+ return;
}
else
{
- ASSERT(im->ip_enabled_by_sw_if_index[sw_if_index] > 0);
+ ASSERT (im->ip_enabled_by_sw_if_index[sw_if_index] > 0);
if (0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
- return;
+ return;
}
vnet_feature_enable_disable ("ip6-unicast", "ip6-lookup", sw_if_index,
@@ -443,12 +421,13 @@ ip6_sw_interface_enable_disable (u32 sw_if_index,
ip6_address_t *
ip6_interface_first_address (ip6_main_t * im,
u32 sw_if_index,
- ip_interface_address_t ** result_ia)
+ ip_interface_address_t ** result_ia)
{
- ip_lookup_main_t * lm = &im->lookup_main;
- ip_interface_address_t * ia = 0;
- ip6_address_t * result = 0;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip_interface_address_t *ia = 0;
+ ip6_address_t *result = 0;
+ /* *INDENT-OFF* */
foreach_ip_interface_address (lm, ia, sw_if_index,
1 /* honor unnumbered */,
({
@@ -456,6 +435,7 @@ ip6_interface_first_address (ip6_main_t * im,
result = a;
break;
}));
+ /* *INDENT-ON* */
if (result_ia)
*result_ia = result ? ia : 0;
return result;
@@ -465,15 +445,14 @@ clib_error_t *
ip6_add_del_interface_address (vlib_main_t * vm,
u32 sw_if_index,
ip6_address_t * address,
- u32 address_length,
- u32 is_del)
+ u32 address_length, u32 is_del)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- clib_error_t * error;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ clib_error_t *error;
u32 if_address_index;
- ip6_address_fib_t ip6_af, * addr_fib = 0;
+ ip6_address_fib_t ip6_af, *addr_fib = 0;
vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
ip6_addr_fib_init (&ip6_af, address,
@@ -484,12 +463,7 @@ ip6_add_del_interface_address (vlib_main_t * vm,
uword elts_before = pool_elts (lm->if_address_pool);
error = ip_interface_address_add_del
- (lm,
- sw_if_index,
- addr_fib,
- address_length,
- is_del,
- &if_address_index);
+ (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index);
if (error)
goto done;
@@ -498,49 +472,48 @@ ip6_add_del_interface_address (vlib_main_t * vm,
goto done;
}
- ip6_sw_interface_enable_disable(sw_if_index, !is_del);
+ ip6_sw_interface_enable_disable (sw_if_index, !is_del);
if (is_del)
- ip6_del_interface_routes (im, ip6_af.fib_index, address,
- address_length);
+ ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length);
else
- ip6_add_interface_routes (vnm, sw_if_index,
- im, ip6_af.fib_index,
- pool_elt_at_index (lm->if_address_pool, if_address_index));
+ ip6_add_interface_routes (vnm, sw_if_index,
+ im, ip6_af.fib_index,
+ pool_elt_at_index (lm->if_address_pool,
+ if_address_index));
{
- ip6_add_del_interface_address_callback_t * cb;
+ ip6_add_del_interface_address_callback_t *cb;
vec_foreach (cb, im->add_del_interface_address_callbacks)
cb->function (im, cb->function_opaque, sw_if_index,
- address, address_length,
- if_address_index,
- is_del);
+ address, address_length, if_address_index, is_del);
}
- done:
+done:
vec_free (addr_fib);
return error;
}
clib_error_t *
-ip6_sw_interface_admin_up_down (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 flags)
+ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
{
- ip6_main_t * im = &ip6_main;
- ip_interface_address_t * ia;
- ip6_address_t * a;
+ ip6_main_t *im = &ip6_main;
+ ip_interface_address_t *ia;
+ ip6_address_t *a;
u32 is_admin_up, fib_index;
/* Fill in lookup tables with default table (0). */
vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
- vec_validate_init_empty (im->lookup_main.if_address_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (im->
+ lookup_main.if_address_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
+ /* *INDENT-OFF* */
foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
0 /* honor unnumbered */,
({
@@ -553,6 +526,7 @@ ip6_sw_interface_admin_up_down (vnet_main_t * vnm,
ip6_del_interface_routes (im, fib_index,
a, ia->address_length);
}));
+ /* *INDENT-ON* */
return 0;
}
@@ -560,6 +534,7 @@ ip6_sw_interface_admin_up_down (vnet_main_t * vnm,
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
/* Built-in ip6 unicast rx feature path definition */
+/* *INDENT-OFF* */
VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
{
.arc_name = "ip6-unicast",
@@ -567,49 +542,57 @@ VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
.arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index,
};
-VNET_FEATURE_INIT (ip6_flow_classify, static) = {
+VNET_FEATURE_INIT (ip6_flow_classify, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "ip6-flow-classify",
.runs_before = VNET_FEATURES ("ip6-inacl"),
};
-VNET_FEATURE_INIT (ip6_inacl, static) = {
+VNET_FEATURE_INIT (ip6_inacl, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "ip6-inacl",
.runs_before = VNET_FEATURES ("ip6-policer-classify"),
};
-VNET_FEATURE_INIT (ip6_policer_classify, static) = {
+VNET_FEATURE_INIT (ip6_policer_classify, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "ip6-policer-classify",
.runs_before = VNET_FEATURES ("ipsec-input-ip6"),
};
-VNET_FEATURE_INIT (ip6_ipsec, static) = {
+VNET_FEATURE_INIT (ip6_ipsec, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "ipsec-input-ip6",
.runs_before = VNET_FEATURES ("l2tp-decap"),
};
-VNET_FEATURE_INIT (ip6_l2tp, static) = {
+VNET_FEATURE_INIT (ip6_l2tp, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "l2tp-decap",
.runs_before = VNET_FEATURES ("vpath-input-ip6"),
};
-VNET_FEATURE_INIT (ip6_vpath, static) = {
+VNET_FEATURE_INIT (ip6_vpath, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "vpath-input-ip6",
.runs_before = VNET_FEATURES ("ip6-lookup"),
};
-VNET_FEATURE_INIT (ip6_lookup, static) = {
+VNET_FEATURE_INIT (ip6_lookup, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "ip6-lookup",
.runs_before = VNET_FEATURES ("ip6-drop"),
};
-VNET_FEATURE_INIT (ip6_drop, static) = {
+VNET_FEATURE_INIT (ip6_drop, static) =
+{
.arc_name = "ip6-unicast",
.node_name = "ip6-drop",
.runs_before = 0, /*last feature*/
@@ -660,11 +643,10 @@ VNET_FEATURE_INIT (ip6_interface_output, static) = {
.node_name = "interface-output",
.runs_before = 0, /* not before any other features */
};
+/* *INDENT-ON* */
clib_error_t *
-ip6_sw_interface_add_del (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 is_add)
+ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
{
vnet_feature_enable_disable ("ip6-unicast", "ip6-drop", sw_if_index,
is_add, 0, 0);
@@ -682,214 +664,224 @@ VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
static uword
ip6_lookup (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip6_lookup_inline (vm, node, frame);
}
-static u8 * format_ip6_lookup_trace (u8 * s, va_list * args);
+static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
-VLIB_REGISTER_NODE (ip6_lookup_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_lookup_node) =
+{
.function = ip6_lookup,
.name = "ip6-lookup",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_lookup_trace,
-
.n_next_nodes = IP6_LOOKUP_N_NEXT,
.next_nodes = IP6_LOOKUP_NEXT_NODES,
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup);
always_inline uword
ip6_load_balance (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- vlib_combined_counter_main_t * cm = &load_balance_main.lbm_via_counters;
- u32 n_left_from, n_left_to_next, * from, * to_next;
+ vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
+ u32 n_left_from, n_left_to_next, *from, *to_next;
ip_lookup_next_t next;
- u32 cpu_index = os_get_cpu_number();
- ip6_main_t * im = &ip6_main;
+ u32 cpu_index = os_get_cpu_number ();
+ ip6_main_t *im = &ip6_main;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next = node->cached_next_index;
if (node->flags & VLIB_NODE_FLAG_TRACE)
- ip6_forward_next_trace(vm, node, frame, VLIB_TX);
+ ip6_forward_next_trace (vm, node, frame, VLIB_TX);
while (n_left_from > 0)
{
- vlib_get_next_frame (vm, node, next,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
- {
- ip_lookup_next_t next0, next1;
- const load_balance_t *lb0, *lb1;
- vlib_buffer_t * p0, *p1;
- u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
- const ip6_header_t *ip0, *ip1;
- const dpo_id_t *dpo0, *dpo1;
-
- /* Prefetch next iteration. */
- {
- vlib_buffer_t * p2, * p3;
-
- p2 = vlib_get_buffer (vm, from[2]);
- p3 = vlib_get_buffer (vm, from[3]);
-
- vlib_prefetch_buffer_header (p2, STORE);
- vlib_prefetch_buffer_header (p3, STORE);
-
- CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
- CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
- }
-
- pi0 = to_next[0] = from[0];
- pi1 = to_next[1] = from[1];
-
- from += 2;
- n_left_from -= 2;
- to_next += 2;
- n_left_to_next -= 2;
-
- p0 = vlib_get_buffer (vm, pi0);
- p1 = vlib_get_buffer (vm, pi1);
-
- ip0 = vlib_buffer_get_current (p0);
- ip1 = vlib_buffer_get_current (p1);
- lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
- lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
-
- lb0 = load_balance_get(lbi0);
- lb1 = load_balance_get(lbi1);
-
- /*
- * this node is for via FIBs we can re-use the hash value from the
- * to node if present.
- * We don't want to use the same hash value at each level in the recursion
- * graph as that would lead to polarisation
- */
- hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
- hc1 = vnet_buffer (p1)->ip.flow_hash = 0;
-
- if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
- {
- if (PREDICT_TRUE (vnet_buffer(p0)->ip.flow_hash))
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = vnet_buffer(p0)->ip.flow_hash >> 1;
- }
- else
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = ip6_compute_flow_hash(ip0, hc0);
- }
- }
- if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
- {
- if (PREDICT_TRUE (vnet_buffer(p1)->ip.flow_hash))
- {
- hc1 = vnet_buffer(p1)->ip.flow_hash = vnet_buffer(p1)->ip.flow_hash >> 1;
- }
- else
- {
- hc1 = vnet_buffer(p1)->ip.flow_hash = ip6_compute_flow_hash(ip1, hc1);
- }
- }
-
- dpo0 = load_balance_get_bucket_i(lb0, hc0 & (lb0->lb_n_buckets_minus_1));
- dpo1 = load_balance_get_bucket_i(lb1, hc1 & (lb1->lb_n_buckets_minus_1));
-
- next0 = dpo0->dpoi_next_node;
- next1 = dpo1->dpoi_next_node;
-
- /* Only process the HBH Option Header if explicitly configured to do so */
- if (PREDICT_FALSE(ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
- {
- next0 = (dpo_is_adj(dpo0) && im->hbh_enabled) ?
- (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
- }
- /* Only process the HBH Option Header if explicitly configured to do so */
- if (PREDICT_FALSE(ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
- {
- next1 = (dpo_is_adj(dpo1) && im->hbh_enabled) ?
- (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
- }
-
- vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
- vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
-
- vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
- vlib_increment_combined_counter
- (cm, cpu_index, lbi1, 1,
- vlib_buffer_length_in_chain (vm, p1));
-
- vlib_validate_buffer_enqueue_x2 (vm, node, next,
- to_next, n_left_to_next,
- pi0, pi1, next0, next1);
- }
+ {
+ ip_lookup_next_t next0, next1;
+ const load_balance_t *lb0, *lb1;
+ vlib_buffer_t *p0, *p1;
+ u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
+ const ip6_header_t *ip0, *ip1;
+ const dpo_id_t *dpo0, *dpo1;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t *p2, *p3;
+
+ p2 = vlib_get_buffer (vm, from[2]);
+ p3 = vlib_get_buffer (vm, from[3]);
+
+ vlib_prefetch_buffer_header (p2, STORE);
+ vlib_prefetch_buffer_header (p3, STORE);
+
+ CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
+ CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
+ }
+
+ pi0 = to_next[0] = from[0];
+ pi1 = to_next[1] = from[1];
+
+ from += 2;
+ n_left_from -= 2;
+ to_next += 2;
+ n_left_to_next -= 2;
+
+ p0 = vlib_get_buffer (vm, pi0);
+ p1 = vlib_get_buffer (vm, pi1);
+
+ ip0 = vlib_buffer_get_current (p0);
+ ip1 = vlib_buffer_get_current (p1);
+ lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+ lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
+
+ lb0 = load_balance_get (lbi0);
+ lb1 = load_balance_get (lbi1);
+
+ /*
+ * this node is for via FIBs we can re-use the hash value from the
+ * to node if present.
+ * We don't want to use the same hash value at each level in the recursion
+ * graph as that would lead to polarisation
+ */
+ hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
+ hc1 = vnet_buffer (p1)->ip.flow_hash = 0;
+
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ vnet_buffer (p0)->ip.flow_hash >> 1;
+ }
+ else
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ ip6_compute_flow_hash (ip0, hc0);
+ }
+ }
+ if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
+ {
+ if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash))
+ {
+ hc1 = vnet_buffer (p1)->ip.flow_hash =
+ vnet_buffer (p1)->ip.flow_hash >> 1;
+ }
+ else
+ {
+ hc1 = vnet_buffer (p1)->ip.flow_hash =
+ ip6_compute_flow_hash (ip1, hc1);
+ }
+ }
+
+ dpo0 =
+ load_balance_get_bucket_i (lb0,
+ hc0 & (lb0->lb_n_buckets_minus_1));
+ dpo1 =
+ load_balance_get_bucket_i (lb1,
+ hc1 & (lb1->lb_n_buckets_minus_1));
+
+ next0 = dpo0->dpoi_next_node;
+ next1 = dpo1->dpoi_next_node;
+
+ /* Only process the HBH Option Header if explicitly configured to do so */
+ if (PREDICT_FALSE
+ (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ {
+ next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
+ (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
+ }
+ /* Only process the HBH Option Header if explicitly configured to do so */
+ if (PREDICT_FALSE
+ (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ {
+ next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
+ (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
+ }
+
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
+ vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
+
+ vlib_increment_combined_counter
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
+ vlib_increment_combined_counter
+ (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
+
+ vlib_validate_buffer_enqueue_x2 (vm, node, next,
+ to_next, n_left_to_next,
+ pi0, pi1, next0, next1);
+ }
while (n_left_from > 0 && n_left_to_next > 0)
- {
- ip_lookup_next_t next0;
- const load_balance_t *lb0;
- vlib_buffer_t * p0;
- u32 pi0, lbi0, hc0;
- const ip6_header_t *ip0;
- const dpo_id_t *dpo0;
-
- pi0 = from[0];
- to_next[0] = pi0;
- from += 1;
- to_next += 1;
- n_left_to_next -= 1;
- n_left_from -= 1;
-
- p0 = vlib_get_buffer (vm, pi0);
-
- ip0 = vlib_buffer_get_current (p0);
- lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
-
- lb0 = load_balance_get(lbi0);
-
- hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
- if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
- {
- if (PREDICT_TRUE (vnet_buffer(p0)->ip.flow_hash))
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = vnet_buffer(p0)->ip.flow_hash >> 1;
- }
- else
- {
- hc0 = vnet_buffer(p0)->ip.flow_hash = ip6_compute_flow_hash(ip0, hc0);
- }
- }
- dpo0 = load_balance_get_bucket_i(lb0, hc0 & (lb0->lb_n_buckets_minus_1));
-
- next0 = dpo0->dpoi_next_node;
- vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
-
- /* Only process the HBH Option Header if explicitly configured to do so */
- if (PREDICT_FALSE(ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
- {
- next0 = (dpo_is_adj(dpo0) && im->hbh_enabled) ?
- (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
- }
-
- vlib_increment_combined_counter
- (cm, cpu_index, lbi0, 1,
- vlib_buffer_length_in_chain (vm, p0));
-
- vlib_validate_buffer_enqueue_x1 (vm, node, next,
- to_next, n_left_to_next,
- pi0, next0);
- }
+ {
+ ip_lookup_next_t next0;
+ const load_balance_t *lb0;
+ vlib_buffer_t *p0;
+ u32 pi0, lbi0, hc0;
+ const ip6_header_t *ip0;
+ const dpo_id_t *dpo0;
+
+ pi0 = from[0];
+ to_next[0] = pi0;
+ from += 1;
+ to_next += 1;
+ n_left_to_next -= 1;
+ n_left_from -= 1;
+
+ p0 = vlib_get_buffer (vm, pi0);
+
+ ip0 = vlib_buffer_get_current (p0);
+ lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+
+ lb0 = load_balance_get (lbi0);
+
+ hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
+ if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
+ {
+ if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ vnet_buffer (p0)->ip.flow_hash >> 1;
+ }
+ else
+ {
+ hc0 = vnet_buffer (p0)->ip.flow_hash =
+ ip6_compute_flow_hash (ip0, hc0);
+ }
+ }
+ dpo0 =
+ load_balance_get_bucket_i (lb0,
+ hc0 & (lb0->lb_n_buckets_minus_1));
+
+ next0 = dpo0->dpoi_next_node;
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
+
+ /* Only process the HBH Option Header if explicitly configured to do so */
+ if (PREDICT_FALSE
+ (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ {
+ next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
+ (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
+ }
+
+ vlib_increment_combined_counter
+ (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
+
+ vlib_validate_buffer_enqueue_x1 (vm, node, next,
+ to_next, n_left_to_next,
+ pi0, next0);
+ }
vlib_put_next_frame (vm, node, next, n_left_to_next);
}
@@ -897,73 +889,78 @@ ip6_load_balance (vlib_main_t * vm,
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip6_load_balance_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_load_balance_node) =
+{
.function = ip6_load_balance,
.name = "ip6-load-balance",
.vector_size = sizeof (u32),
.sibling_of = "ip6-lookup",
-
.format_trace = format_ip6_lookup_trace,
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance);
-typedef struct {
+typedef struct
+{
/* Adjacency taken. */
u32 adj_index;
u32 flow_hash;
u32 fib_index;
/* Packet data, possibly *after* rewrite. */
- u8 packet_data[128 - 1*sizeof(u32)];
-} ip6_forward_next_trace_t;
+ u8 packet_data[128 - 1 * sizeof (u32)];
+}
+ip6_forward_next_trace_t;
-static u8 * format_ip6_forward_next_trace (u8 * s, va_list * args)
+static u8 *
+format_ip6_forward_next_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 *);
- ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
+ ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
uword indent = format_get_indent (s);
- s = format(s, "%U%U",
- format_white_space, indent,
- format_ip6_header, t->packet_data, sizeof (t->packet_data));
+ s = format (s, "%U%U",
+ format_white_space, indent,
+ format_ip6_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-static u8 * format_ip6_lookup_trace (u8 * s, va_list * args)
+static u8 *
+format_ip6_lookup_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 *);
- ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
+ ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
uword indent = format_get_indent (s);
s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
- t->fib_index, t->adj_index, t->flow_hash);
- s = format(s, "\n%U%U",
- format_white_space, indent,
- format_ip6_header, t->packet_data, sizeof (t->packet_data));
+ t->fib_index, t->adj_index, t->flow_hash);
+ s = format (s, "\n%U%U",
+ format_white_space, indent,
+ format_ip6_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-static u8 * format_ip6_rewrite_trace (u8 * s, va_list * args)
+static u8 *
+format_ip6_rewrite_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 *);
- ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
- vnet_main_t * vnm = vnet_get_main();
+ ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
+ vnet_main_t *vnm = vnet_get_main ();
uword indent = format_get_indent (s);
s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
- t->fib_index, t->adj_index, format_ip_adjacency,
- t->adj_index, FORMAT_IP_ADJACENCY_NONE,
- t->flow_hash);
+ t->fib_index, t->adj_index, format_ip_adjacency,
+ t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
s = format (s, "\n%U%U",
- format_white_space, indent,
- format_ip_adjacency_packet_data,
- vnm, t->adj_index,
- t->packet_data, sizeof (t->packet_data));
+ format_white_space, indent,
+ format_ip_adjacency_packet_data,
+ vnm, t->adj_index, t->packet_data, sizeof (t->packet_data));
return s;
}
@@ -971,11 +968,10 @@ static u8 * format_ip6_rewrite_trace (u8 * s, va_list * args)
void
ip6_forward_next_trace (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- vlib_rx_or_tx_t which_adj_index)
+ vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
{
- u32 * from, n_left;
- ip6_main_t * im = &ip6_main;
+ u32 *from, n_left;
+ ip6_main_t *im = &ip6_main;
n_left = frame->n_vectors;
from = vlib_frame_vector_args (frame);
@@ -983,8 +979,8 @@ ip6_forward_next_trace (vlib_main_t * vm,
while (n_left >= 4)
{
u32 bi0, bi1;
- vlib_buffer_t * b0, * b1;
- ip6_forward_next_trace_t * t0, * t1;
+ vlib_buffer_t *b0, *b1;
+ ip6_forward_next_trace_t *t0, *t1;
/* Prefetch next iteration. */
vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
@@ -1000,29 +996,31 @@ ip6_forward_next_trace (vlib_main_t * vm,
{
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
- t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
- t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
- vnet_buffer(b0)->sw_if_index[VLIB_TX] :
- vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+ t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
+ t0->fib_index =
+ (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
+ (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (b0)->sw_if_index[VLIB_RX]);
clib_memcpy (t0->packet_data,
- vlib_buffer_get_current (b0),
- sizeof (t0->packet_data));
+ vlib_buffer_get_current (b0),
+ sizeof (t0->packet_data));
}
if (b1->flags & VLIB_BUFFER_IS_TRACED)
{
t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
- t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
- t1->fib_index = (vnet_buffer(b1)->sw_if_index[VLIB_TX] != (u32)~0) ?
- vnet_buffer(b1)->sw_if_index[VLIB_TX] :
- vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(b1)->sw_if_index[VLIB_RX]);
+ t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
+ t1->fib_index =
+ (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
+ (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (b1)->sw_if_index[VLIB_RX]);
clib_memcpy (t1->packet_data,
- vlib_buffer_get_current (b1),
- sizeof (t1->packet_data));
+ vlib_buffer_get_current (b1),
+ sizeof (t1->packet_data));
}
from += 2;
n_left -= 2;
@@ -1031,8 +1029,8 @@ ip6_forward_next_trace (vlib_main_t * vm,
while (n_left >= 1)
{
u32 bi0;
- vlib_buffer_t * b0;
- ip6_forward_next_trace_t * t0;
+ vlib_buffer_t *b0;
+ ip6_forward_next_trace_t *t0;
bi0 = from[0];
@@ -1042,15 +1040,16 @@ ip6_forward_next_trace (vlib_main_t * vm,
{
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
- t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
- t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
- vnet_buffer(b0)->sw_if_index[VLIB_TX] :
- vec_elt (im->fib_index_by_sw_if_index,
- vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+ t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
+ t0->fib_index =
+ (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
+ (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
+ vec_elt (im->fib_index_by_sw_if_index,
+ vnet_buffer (b0)->sw_if_index[VLIB_RX]);
clib_memcpy (t0->packet_data,
- vlib_buffer_get_current (b0),
- sizeof (t0->packet_data));
+ vlib_buffer_get_current (b0),
+ sizeof (t0->packet_data));
}
from += 1;
n_left -= 1;
@@ -1060,19 +1059,16 @@ ip6_forward_next_trace (vlib_main_t * vm,
static uword
ip6_drop_or_punt (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- ip6_error_t error_code)
+ vlib_frame_t * frame, ip6_error_t error_code)
{
- u32 * buffers = vlib_frame_vector_args (frame);
+ u32 *buffers = vlib_frame_vector_args (frame);
uword n_packets = frame->n_vectors;
- vlib_error_drop_buffers (vm, node,
- buffers,
+ vlib_error_drop_buffers (vm, node, buffers,
/* stride */ 1,
n_packets,
/* next */ 0,
- ip6_input_node.index,
- error_code);
+ ip6_input_node.index, error_code);
if (node->flags & VLIB_NODE_FLAG_TRACE)
ip6_forward_next_trace (vm, node, frame, VLIB_TX);
@@ -1081,70 +1077,77 @@ ip6_drop_or_punt (vlib_main_t * vm,
}
static uword
-ip6_drop (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
-{ return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP); }
+ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP);
+}
static uword
-ip6_punt (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
-{ return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT); }
+ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT);
+}
-VLIB_REGISTER_NODE (ip6_drop_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_drop_node, static) =
+{
.function = ip6_drop,
.name = "ip6-drop",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.n_next_nodes = 1,
- .next_nodes = {
- [0] = "error-drop",
- },
+ .next_nodes =
+ {
+ [0] = "error-drop",},
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop);
-VLIB_REGISTER_NODE (ip6_punt_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_punt_node, static) =
+{
.function = ip6_punt,
.name = "ip6-punt",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.n_next_nodes = 1,
- .next_nodes = {
- [0] = "error-punt",
- },
+ .next_nodes =
+ {
+ [0] = "error-punt",},
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt);
-VLIB_REGISTER_NODE (ip6_multicast_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_multicast_node, static) =
+{
.function = ip6_drop,
.name = "ip6-multicast",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.n_next_nodes = 1,
- .next_nodes = {
+ .next_nodes =
+ {
[0] = "error-drop",
},
};
+/* *INDENT-ON* */
+
/* Compute TCP/UDP/ICMP6 checksum in software. */
-u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6_header_t * ip0, int *bogus_lengthp)
+u16
+ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
+ ip6_header_t * ip0, int *bogus_lengthp)
{
ip_csum_t sum0;
u16 sum16, payload_length_host_byte_order;
u32 i, n_this_buffer, n_bytes_left;
- u32 headers_size = sizeof(ip0[0]);
- void * data_this_buffer;
+ u32 headers_size = sizeof (ip0[0]);
+ void *data_this_buffer;
- ASSERT(bogus_lengthp);
+ ASSERT (bogus_lengthp);
*bogus_lengthp = 0;
/* Initialize checksum with ip header. */
@@ -1155,30 +1158,37 @@ u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6
for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
{
sum0 = ip_csum_with_carry (sum0,
- clib_mem_unaligned (&ip0->src_address.as_uword[i], uword));
- sum0 = ip_csum_with_carry (sum0,
- clib_mem_unaligned (&ip0->dst_address.as_uword[i], uword));
+ clib_mem_unaligned (&ip0->
+ src_address.as_uword[i],
+ uword));
+ sum0 =
+ ip_csum_with_carry (sum0,
+ clib_mem_unaligned (&ip0->dst_address.as_uword[i],
+ uword));
}
/* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
- if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- u32 skip_bytes;
- ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *)data_this_buffer;
+ u32 skip_bytes;
+ ip6_hop_by_hop_ext_t *ext_hdr =
+ (ip6_hop_by_hop_ext_t *) data_this_buffer;
/* validate really icmp6 next */
- ASSERT(ext_hdr->next_hdr == IP_PROTOCOL_ICMP6);
+ ASSERT (ext_hdr->next_hdr == IP_PROTOCOL_ICMP6);
- skip_bytes = 8* (1 + ext_hdr->n_data_u64s);
- data_this_buffer = (void *)((u8 *)data_this_buffer + skip_bytes);
+ skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
+ data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
- payload_length_host_byte_order -= skip_bytes;
+ payload_length_host_byte_order -= skip_bytes;
headers_size += skip_bytes;
- }
+ }
n_bytes_left = n_this_buffer = payload_length_host_byte_order;
- if (p0 && n_this_buffer + headers_size > p0->current_length)
- n_this_buffer = p0->current_length > headers_size ? p0->current_length - headers_size : 0;
+ if (p0 && n_this_buffer + headers_size > p0->current_length)
+ n_this_buffer =
+ p0->current_length >
+ headers_size ? p0->current_length - headers_size : 0;
while (1)
{
sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
@@ -1187,24 +1197,25 @@ u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6
break;
if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
- {
- *bogus_lengthp = 1;
- return 0xfefe;
- }
+ {
+ *bogus_lengthp = 1;
+ return 0xfefe;
+ }
p0 = vlib_get_buffer (vm, p0->next_buffer);
data_this_buffer = vlib_buffer_get_current (p0);
n_this_buffer = p0->current_length;
}
- sum16 = ~ ip_csum_fold (sum0);
+ sum16 = ~ip_csum_fold (sum0);
return sum16;
}
-u32 ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
+u32
+ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
{
- ip6_header_t * ip0 = vlib_buffer_get_current (p0);
- udp_header_t * udp0;
+ ip6_header_t *ip0 = vlib_buffer_get_current (p0);
+ udp_header_t *udp0;
u16 sum16;
int bogus_length;
@@ -1212,7 +1223,7 @@ u32 ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
ASSERT (ip0->protocol == IP_PROTOCOL_TCP
|| ip0->protocol == IP_PROTOCOL_ICMP6
|| ip0->protocol == IP_PROTOCOL_UDP
- || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
+ || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
udp0 = (void *) (ip0 + 1);
if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
@@ -1242,75 +1253,77 @@ u32 ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
* 3. If find_hdr header is not found or packet is malformed or
* it is a non-first fragment -1 is returned.
*/
-always_inline int ip6_locate_header (vlib_buffer_t *p0,
- ip6_header_t *ip0,
- int find_hdr,
- u32 *offset)
+always_inline int
+ip6_locate_header (vlib_buffer_t * p0,
+ ip6_header_t * ip0, int find_hdr, u32 * offset)
{
u8 next_proto = ip0->protocol;
u8 *next_header;
u8 done = 0;
u32 cur_offset;
- u8 *temp_nxthdr = 0;
+ u8 *temp_nxthdr = 0;
u32 exthdr_len = 0;
- next_header = ip6_next_header(ip0);
- cur_offset = sizeof(ip6_header_t);
- while(1)
+ next_header = ip6_next_header (ip0);
+ cur_offset = sizeof (ip6_header_t);
+ while (1)
{
done = (next_proto == find_hdr);
- if (PREDICT_FALSE(next_header >= (u8 *)vlib_buffer_get_current(p0) + p0->current_length))
+ if (PREDICT_FALSE
+ (next_header >=
+ (u8 *) vlib_buffer_get_current (p0) + p0->current_length))
{
//A malicious packet could set an extension header with a too big size
- return(-1);
+ return (-1);
}
if (done)
break;
- if ((!ip6_ext_hdr(next_proto)) || next_proto == IP_PROTOCOL_IP6_NONXT)
+ if ((!ip6_ext_hdr (next_proto)) || next_proto == IP_PROTOCOL_IP6_NONXT)
{
if (find_hdr < 0)
break;
return -1;
- }
+ }
if (next_proto == IP_PROTOCOL_IPV6_FRAGMENTATION)
{
- ip6_frag_hdr_t *frag_hdr = (ip6_frag_hdr_t *)next_header;
- u16 frag_off = ip6_frag_hdr_offset(frag_hdr);
- /* Non first fragment return -1 */
+ ip6_frag_hdr_t *frag_hdr = (ip6_frag_hdr_t *) next_header;
+ u16 frag_off = ip6_frag_hdr_offset (frag_hdr);
+ /* Non first fragment return -1 */
if (frag_off)
- return(-1);
- exthdr_len = sizeof(ip6_frag_hdr_t);
- temp_nxthdr = next_header + exthdr_len;
+ return (-1);
+ exthdr_len = sizeof (ip6_frag_hdr_t);
+ temp_nxthdr = next_header + exthdr_len;
}
else if (next_proto == IP_PROTOCOL_IPSEC_AH)
{
- exthdr_len = ip6_ext_authhdr_len(((ip6_ext_header_t *)next_header));
+ exthdr_len =
+ ip6_ext_authhdr_len (((ip6_ext_header_t *) next_header));
temp_nxthdr = next_header + exthdr_len;
}
else
{
- exthdr_len = ip6_ext_header_len(((ip6_ext_header_t *)next_header));
+ exthdr_len =
+ ip6_ext_header_len (((ip6_ext_header_t *) next_header));
temp_nxthdr = next_header + exthdr_len;
}
- next_proto = ((ip6_ext_header_t *)next_header)->next_hdr;
- next_header = temp_nxthdr;
- cur_offset += exthdr_len;
+ next_proto = ((ip6_ext_header_t *) next_header)->next_hdr;
+ next_header = temp_nxthdr;
+ cur_offset += exthdr_len;
}
*offset = cur_offset;
- return(next_proto);
+ return (next_proto);
}
static uword
-ip6_local (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- ip6_main_t * im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ip6_main_t *im = &ip6_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
ip_local_next_t next_index;
- u32 * from, * to_next, n_left_from, n_left_to_next;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
+ u32 *from, *to_next, n_left_from, n_left_to_next;
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_input_node.index);
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -1321,14 +1334,13 @@ ip6_local (vlib_main_t * vm,
while (n_left_from > 0)
{
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- vlib_buffer_t * p0, * p1;
- ip6_header_t * ip0, * ip1;
- udp_header_t * udp0, * udp1;
+ vlib_buffer_t *p0, *p1;
+ ip6_header_t *ip0, *ip1;
+ udp_header_t *udp0, *udp1;
u32 pi0, ip_len0, udp_len0, flags0, next0;
u32 pi1, ip_len1, udp_len1, flags1, next1;
i32 len_diff0, len_diff1;
@@ -1364,35 +1376,43 @@ ip6_local (vlib_main_t * vm,
len_diff1 = 0;
/* Skip HBH local processing */
- if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE
+ (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *)ip6_next_header(ip0);
+ ip6_hop_by_hop_ext_t *ext_hdr =
+ (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0);
next0 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr];
type0 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr];
}
- if (PREDICT_FALSE (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE
+ (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *)ip6_next_header(ip1);
+ ip6_hop_by_hop_ext_t *ext_hdr =
+ (ip6_hop_by_hop_ext_t *) ip6_next_header (ip1);
next1 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr];
type1 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr];
}
- if (PREDICT_TRUE(IP_PROTOCOL_UDP == ip6_locate_header(p0, ip0,
- IP_PROTOCOL_UDP, &udp_offset0)))
+ if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p0, ip0,
+ IP_PROTOCOL_UDP,
+ &udp_offset0)))
{
- udp0 = (udp_header_t *)((u8 *)ip0 + udp_offset0);
+ udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
/* Don't verify UDP checksum for packets with explicit zero checksum. */
- good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP && udp0->checksum == 0;
+ good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
+ && udp0->checksum == 0;
/* Verify UDP length. */
ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
udp_len0 = clib_net_to_host_u16 (udp0->length);
len_diff0 = ip_len0 - udp_len0;
}
- if (PREDICT_TRUE(IP_PROTOCOL_UDP == ip6_locate_header(p1, ip1,
- IP_PROTOCOL_UDP, &udp_offset1)))
+ if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p1, ip1,
+ IP_PROTOCOL_UDP,
+ &udp_offset1)))
{
- udp1 = (udp_header_t *)((u8 *)ip1 + udp_offset1);
+ udp1 = (udp_header_t *) ((u8 *) ip1 + udp_offset1);
/* Don't verify UDP checksum for packets with explicit zero checksum. */
- good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP && udp1->checksum == 0;
+ good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP
+ && udp1->checksum == 0;
/* Verify UDP length. */
ip_len1 = clib_net_to_host_u16 (ip1->payload_length);
udp_len1 = clib_net_to_host_u16 (udp1->length);
@@ -1406,16 +1426,16 @@ ip6_local (vlib_main_t * vm,
len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0;
if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
- && ! good_l4_checksum0
- && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
+ && !good_l4_checksum0
+ && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
{
flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
good_l4_checksum0 =
(flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
}
if (PREDICT_FALSE (type1 != IP_BUILTIN_PROTOCOL_UNKNOWN
- && ! good_l4_checksum1
- && ! (flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
+ && !good_l4_checksum1
+ && !(flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
{
flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1);
good_l4_checksum1 =
@@ -1427,38 +1447,38 @@ ip6_local (vlib_main_t * vm,
error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
- ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
- ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
- error0 = (! good_l4_checksum0
- ? IP6_ERROR_UDP_CHECKSUM + type0
- : error0);
- error1 = (! good_l4_checksum1
- ? IP6_ERROR_UDP_CHECKSUM + type1
- : error1);
+ ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
+ IP6_ERROR_UDP_CHECKSUM);
+ ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
+ IP6_ERROR_ICMP_CHECKSUM);
+ error0 =
+ (!good_l4_checksum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
+ error1 =
+ (!good_l4_checksum1 ? IP6_ERROR_UDP_CHECKSUM + type1 : error1);
/* Drop packets from unroutable hosts. */
- /* If this is a neighbor solicitation (ICMP), skip source RPF check */
+ /* If this is a neighbor solicitation (ICMP), skip source RPF check */
if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
type0 != IP_BUILTIN_PROTOCOL_ICMP &&
- !ip6_address_is_link_local_unicast(&ip0->src_address))
+ !ip6_address_is_link_local_unicast (&ip0->src_address))
{
u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
error0 = (ADJ_INDEX_INVALID == src_adj_index0
- ? IP6_ERROR_SRC_LOOKUP_MISS
- : error0);
+ ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
}
if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL &&
type1 != IP_BUILTIN_PROTOCOL_ICMP &&
- !ip6_address_is_link_local_unicast(&ip1->src_address))
+ !ip6_address_is_link_local_unicast (&ip1->src_address))
{
u32 src_adj_index1 = ip6_src_lookup_for_packet (im, p1, ip1);
error1 = (ADJ_INDEX_INVALID == src_adj_index1
- ? IP6_ERROR_SRC_LOOKUP_MISS
- : error1);
+ ? IP6_ERROR_SRC_LOOKUP_MISS : error1);
}
- next0 = error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
- next1 = error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
+ next0 =
+ error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
+ next1 =
+ error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
p0->error = error_node->errors[error0];
p1->error = error_node->errors[error1];
@@ -1470,13 +1490,13 @@ ip6_local (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
- udp_header_t * udp0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
+ udp_header_t *udp0;
u32 pi0, ip_len0, udp_len0, flags0, next0;
i32 len_diff0;
u8 error0, type0, good_l4_checksum0;
- u32 udp_offset0;
+ u32 udp_offset0;
pi0 = to_next[0] = from[0];
from += 1;
@@ -1497,18 +1517,22 @@ ip6_local (vlib_main_t * vm,
len_diff0 = 0;
/* Skip HBH local processing */
- if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
+ if (PREDICT_FALSE
+ (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
{
- ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *)ip6_next_header(ip0);
+ ip6_hop_by_hop_ext_t *ext_hdr =
+ (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0);
next0 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr];
type0 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr];
}
- if (PREDICT_TRUE(IP_PROTOCOL_UDP == ip6_locate_header(p0, ip0,
- IP_PROTOCOL_UDP, &udp_offset0)))
+ if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p0, ip0,
+ IP_PROTOCOL_UDP,
+ &udp_offset0)))
{
- udp0 = (udp_header_t *)((u8 *)ip0 + udp_offset0);
+ udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
/* Don't verify UDP checksum for packets with explicit zero checksum. */
- good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP && udp0->checksum == 0;
+ good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
+ && udp0->checksum == 0;
/* Verify UDP length. */
ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
udp_len0 = clib_net_to_host_u16 (udp0->length);
@@ -1519,8 +1543,8 @@ ip6_local (vlib_main_t * vm,
len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
- && ! good_l4_checksum0
- && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
+ && !good_l4_checksum0
+ && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
{
flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
good_l4_checksum0 =
@@ -1531,24 +1555,25 @@ ip6_local (vlib_main_t * vm,
error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
- ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
- ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
- error0 = (! good_l4_checksum0
- ? IP6_ERROR_UDP_CHECKSUM + type0
- : error0);
+ ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
+ IP6_ERROR_UDP_CHECKSUM);
+ ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
+ IP6_ERROR_ICMP_CHECKSUM);
+ error0 =
+ (!good_l4_checksum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
- /* If this is a neighbor solicitation (ICMP), skip source RPF check */
+ /* If this is a neighbor solicitation (ICMP), skip source RPF check */
if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
type0 != IP_BUILTIN_PROTOCOL_ICMP &&
- !ip6_address_is_link_local_unicast(&ip0->src_address))
+ !ip6_address_is_link_local_unicast (&ip0->src_address))
{
u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
error0 = (ADJ_INDEX_INVALID == src_adj_index0
- ? IP6_ERROR_SRC_LOOKUP_MISS
- : error0);
+ ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
}
- next0 = error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
+ next0 =
+ error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
p0->error = error_node->errors[error0];
@@ -1563,41 +1588,47 @@ ip6_local (vlib_main_t * vm,
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip6_local_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_local_node, static) =
+{
.function = ip6_local,
.name = "ip6-local",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.n_next_nodes = IP_LOCAL_N_NEXT,
- .next_nodes = {
+ .next_nodes =
+ {
[IP_LOCAL_NEXT_DROP] = "error-drop",
[IP_LOCAL_NEXT_PUNT] = "error-punt",
[IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
[IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
},
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local);
-void ip6_register_protocol (u32 protocol, u32 node_index)
+void
+ip6_register_protocol (u32 protocol, u32 node_index)
{
- vlib_main_t * vm = vlib_get_main();
- ip6_main_t * im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ vlib_main_t *vm = vlib_get_main ();
+ ip6_main_t *im = &ip6_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
- lm->local_next_by_ip_protocol[protocol] = vlib_node_add_next (vm, ip6_local_node.index, node_index);
+ lm->local_next_by_ip_protocol[protocol] =
+ vlib_node_add_next (vm, ip6_local_node.index, node_index);
}
-typedef enum {
+typedef enum
+{
IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX,
IP6_DISCOVER_NEIGHBOR_N_NEXT,
} ip6_discover_neighbor_next_t;
-typedef enum {
+typedef enum
+{
IP6_DISCOVER_NEIGHBOR_ERROR_DROP,
IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT,
IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS,
@@ -1606,13 +1637,12 @@ typedef enum {
static uword
ip6_discover_neighbor_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- int is_glean)
+ vlib_frame_t * frame, int is_glean)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- u32 * from, * to_next_drop;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ u32 *from, *to_next_drop;
uword n_left_from, n_left_to_next_drop;
static f64 time_last_seed_change = -1e100;
static u32 hash_seeds[3];
@@ -1627,8 +1657,8 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
if (time_now - time_last_seed_change > 1e-3)
{
uword i;
- u32 * r = clib_random_buffer_get_data (&vm->random_buffer,
- sizeof (hash_seeds));
+ u32 *r = clib_random_buffer_get_data (&vm->random_buffer,
+ sizeof (hash_seeds));
for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
hash_seeds[i] = r[i];
@@ -1649,12 +1679,12 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next_drop > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
uword bm0;
- ip_adjacency_t * adj0;
- vnet_hw_interface_t * hw_if0;
+ ip_adjacency_t *adj0;
+ vnet_hw_interface_t *hw_if0;
u32 next0;
pi0 = from[0];
@@ -1669,8 +1699,10 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
if (!is_glean)
{
- ip0->dst_address.as_u64[0] = adj0->sub_type.nbr.next_hop.ip6.as_u64[0];
- ip0->dst_address.as_u64[1] = adj0->sub_type.nbr.next_hop.ip6.as_u64[1];
+ ip0->dst_address.as_u64[0] =
+ adj0->sub_type.nbr.next_hop.ip6.as_u64[0];
+ ip0->dst_address.as_u64[1] =
+ adj0->sub_type.nbr.next_hop.ip6.as_u64[1];
}
a0 = hash_seeds[0];
@@ -1707,15 +1739,15 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
to_next_drop += 1;
n_left_to_next_drop -= 1;
- hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
+ hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
- /* If the interface is link-down, drop the pkt */
- if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
- drop0 = 1;
+ /* If the interface is link-down, drop the pkt */
+ if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
+ drop0 = 1;
p0->error =
- node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP
- : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT];
+ node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP
+ : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT];
if (drop0)
continue;
@@ -1728,32 +1760,33 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
{
u32 bi0 = 0;
- icmp6_neighbor_solicitation_header_t * h0;
- vlib_buffer_t * b0;
+ icmp6_neighbor_solicitation_header_t *h0;
+ vlib_buffer_t *b0;
h0 = vlib_packet_template_get_packet
- (vm, &im->discover_neighbor_packet_template, &bi0);
+ (vm, &im->discover_neighbor_packet_template, &bi0);
/*
- * Build ethernet header.
- * Choose source address based on destination lookup
- * adjacency.
- */
+ * Build ethernet header.
+ * Choose source address based on destination lookup
+ * adjacency.
+ */
if (ip6_src_address_for_packet (lm,
sw_if_index0,
&h0->ip.src_address))
{
/* There is no address on the interface */
- p0->error = node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
- vlib_buffer_free(vm, &bi0, 1);
+ p0->error =
+ node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
+ vlib_buffer_free (vm, &bi0, 1);
continue;
}
/*
- * Destination address is a solicited node multicast address.
- * We need to fill in
- * the low 24 bits with low 24 bits of target's address.
- */
+ * Destination address is a solicited node multicast address.
+ * We need to fill in
+ * the low 24 bits with low 24 bits of target's address.
+ */
h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13];
h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14];
h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15];
@@ -1761,24 +1794,23 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
h0->neighbor.target_address = ip0->dst_address;
clib_memcpy (h0->link_layer_option.ethernet_address,
- hw_if0->hw_address, vec_len (hw_if0->hw_address));
+ hw_if0->hw_address, vec_len (hw_if0->hw_address));
- /* $$$$ appears we need this; why is the checksum non-zero? */
- h0->neighbor.icmp.checksum = 0;
+ /* $$$$ appears we need this; why is the checksum non-zero? */
+ h0->neighbor.icmp.checksum = 0;
h0->neighbor.icmp.checksum =
- ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
- &bogus_length);
+ ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
+ &bogus_length);
- ASSERT (bogus_length == 0);
+ ASSERT (bogus_length == 0);
vlib_buffer_copy_trace_flag (vm, p0, bi0);
b0 = vlib_get_buffer (vm, bi0);
vnet_buffer (b0)->sw_if_index[VLIB_TX]
- = vnet_buffer (p0)->sw_if_index[VLIB_TX];
+ = vnet_buffer (p0)->sw_if_index[VLIB_TX];
/* Add rewrite/encap string. */
- vnet_rewrite_one_header (adj0[0], h0,
- sizeof (ethernet_header_t));
+ vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t));
vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX;
@@ -1788,7 +1820,7 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
}
vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
- n_left_to_next_drop);
+ n_left_to_next_drop);
}
return frame->n_vectors;
@@ -1796,74 +1828,72 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
static uword
ip6_discover_neighbor (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return (ip6_discover_neighbor_inline(vm, node, frame, 0));
+ return (ip6_discover_neighbor_inline (vm, node, frame, 0));
}
static uword
-ip6_glean (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip6_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return (ip6_discover_neighbor_inline(vm, node, frame, 1));
+ return (ip6_discover_neighbor_inline (vm, node, frame, 1));
}
-static char * ip6_discover_neighbor_error_strings[] = {
+static char *ip6_discover_neighbor_error_strings[] = {
[IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
- [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT]
- = "neighbor solicitations sent",
+ [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] = "neighbor solicitations sent",
[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]
= "no source address for ND solicitation",
};
-VLIB_REGISTER_NODE (ip6_discover_neighbor_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_discover_neighbor_node) =
+{
.function = ip6_discover_neighbor,
.name = "ip6-discover-neighbor",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
.error_strings = ip6_discover_neighbor_error_strings,
-
.n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
- .next_nodes = {
+ .next_nodes =
+ {
[IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
[IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
},
};
+/* *INDENT-ON* */
-VLIB_REGISTER_NODE (ip6_glean_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_glean_node) =
+{
.function = ip6_glean,
.name = "ip6-glean",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
.error_strings = ip6_discover_neighbor_error_strings,
-
.n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
- .next_nodes = {
+ .next_nodes =
+ {
[IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
[IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
},
};
+/* *INDENT-ON* */
clib_error_t *
ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
- icmp6_neighbor_solicitation_header_t * h;
- ip6_address_t * src;
- ip_interface_address_t * ia;
- ip_adjacency_t * adj;
- vnet_hw_interface_t * hi;
- vnet_sw_interface_t * si;
- vlib_buffer_t * b;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
+ icmp6_neighbor_solicitation_header_t *h;
+ ip6_address_t *src;
+ ip_interface_address_t *ia;
+ ip_adjacency_t *adj;
+ vnet_hw_interface_t *hi;
+ vnet_sw_interface_t *si;
+ vlib_buffer_t *b;
u32 bi = 0;
int bogus_length;
@@ -1872,22 +1902,26 @@ ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
{
return clib_error_return (0, "%U: interface %U down",
- format_ip6_address, dst,
- format_vnet_sw_if_index_name, vnm,
- sw_if_index);
+ format_ip6_address, dst,
+ format_vnet_sw_if_index_name, vnm,
+ sw_if_index);
}
- src = ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
- if (! src)
+ src =
+ ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
+ if (!src)
{
vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
return clib_error_return
- (0, "no matching interface address for destination %U (interface %U)",
- format_ip6_address, dst,
- format_vnet_sw_if_index_name, vnm, sw_if_index);
+ (0, "no matching interface address for destination %U (interface %U)",
+ format_ip6_address, dst,
+ format_vnet_sw_if_index_name, vnm, sw_if_index);
}
- h = vlib_packet_template_get_packet (vm, &im->discover_neighbor_packet_template, &bi);
+ h =
+ vlib_packet_template_get_packet (vm,
+ &im->discover_neighbor_packet_template,
+ &bi);
hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
@@ -1900,14 +1934,16 @@ ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
h->ip.src_address = src[0];
h->neighbor.target_address = dst[0];
- clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address, vec_len (hi->hw_address));
+ clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address,
+ vec_len (hi->hw_address));
h->neighbor.icmp.checksum =
ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
- ASSERT(bogus_length == 0);
+ ASSERT (bogus_length == 0);
b = vlib_get_buffer (vm, bi);
- vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
+ vnet_buffer (b)->sw_if_index[VLIB_RX] =
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
/* Add encapsulation string for software interface (e.g. ethernet header). */
adj = ip_get_adjacency (&im->lookup_main, ia->neighbor_probe_adj_index);
@@ -1915,8 +1951,8 @@ ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
{
- vlib_frame_t * f = vlib_get_frame_to_node (vm, hi->output_node_index);
- u32 * to_next = vlib_frame_vector_args (f);
+ vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
+ u32 *to_next = vlib_frame_vector_args (f);
to_next[0] = bi;
f->n_vectors = 1;
vlib_put_frame_to_node (vm, hi->output_node_index, f);
@@ -1925,7 +1961,8 @@ ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
return /* no error */ 0;
}
-typedef enum {
+typedef enum
+{
IP6_REWRITE_NEXT_DROP,
IP6_REWRITE_NEXT_ICMP_ERROR,
} ip6_rewrite_next_t;
@@ -1933,17 +1970,17 @@ typedef enum {
always_inline uword
ip6_rewrite_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- int is_midchain)
+ vlib_frame_t * frame, int is_midchain)
{
- ip_lookup_main_t * lm = &ip6_main.lookup_main;
- u32 * from = vlib_frame_vector_args (frame);
- u32 n_left_from, n_left_to_next, * to_next, next_index;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
+ ip_lookup_main_t *lm = &ip6_main.lookup_main;
+ u32 *from = vlib_frame_vector_args (frame);
+ u32 n_left_from, n_left_to_next, *to_next, next_index;
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_input_node.index);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
while (n_left_from > 0)
{
@@ -1951,16 +1988,16 @@ ip6_rewrite_inline (vlib_main_t * vm,
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- ip_adjacency_t * adj0, * adj1;
- vlib_buffer_t * p0, * p1;
- ip6_header_t * ip0, * ip1;
+ ip_adjacency_t *adj0, *adj1;
+ vlib_buffer_t *p0, *p1;
+ ip6_header_t *ip0, *ip1;
u32 pi0, rw_len0, next0, error0, adj_index0;
u32 pi1, rw_len1, next1, error1, adj_index1;
- u32 tx_sw_if_index0, tx_sw_if_index1;
+ u32 tx_sw_if_index0, tx_sw_if_index1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -1989,18 +2026,18 @@ ip6_rewrite_inline (vlib_main_t * vm,
adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
- /* We should never rewrite a pkt using the MISS adjacency */
- ASSERT(adj_index0 && adj_index1);
+ /* We should never rewrite a pkt using the MISS adjacency */
+ ASSERT (adj_index0 && adj_index1);
ip0 = vlib_buffer_get_current (p0);
ip1 = vlib_buffer_get_current (p1);
error0 = error1 = IP6_ERROR_NONE;
- next0 = next1 = IP6_REWRITE_NEXT_DROP;
+ next0 = next1 = IP6_REWRITE_NEXT_DROP;
- if (PREDICT_TRUE(!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
+ if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
{
- i32 hop_limit0 = ip0->hop_limit;
+ i32 hop_limit0 = ip0->hop_limit;
/* Input node should have reject packets with hop limit 0. */
ASSERT (ip0->hop_limit > 0);
@@ -2009,25 +2046,26 @@ ip6_rewrite_inline (vlib_main_t * vm,
ip0->hop_limit = hop_limit0;
- /*
- * If the hop count drops below 1 when forwarding, generate
- * an ICMP response.
- */
- if (PREDICT_FALSE(hop_limit0 <= 0))
- {
- error0 = IP6_ERROR_TIME_EXPIRED;
- next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32)~0;
- icmp6_error_set_vnet_buffer(p0, ICMP6_time_exceeded,
- ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
- }
+ /*
+ * If the hop count drops below 1 when forwarding, generate
+ * an ICMP response.
+ */
+ if (PREDICT_FALSE (hop_limit0 <= 0))
+ {
+ error0 = IP6_ERROR_TIME_EXPIRED;
+ next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
+ ICMP6_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ }
}
- else
- {
- p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
- }
- if (PREDICT_TRUE(!(p1->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
- {
+ else
+ {
+ p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
+ }
+ if (PREDICT_TRUE (!(p1->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
+ {
i32 hop_limit1 = ip1->hop_limit;
/* Input node should have reject packets with hop limit 0. */
@@ -2037,89 +2075,89 @@ ip6_rewrite_inline (vlib_main_t * vm,
ip1->hop_limit = hop_limit1;
- /*
- * If the hop count drops below 1 when forwarding, generate
- * an ICMP response.
- */
- if (PREDICT_FALSE(hop_limit1 <= 0))
- {
- error1 = IP6_ERROR_TIME_EXPIRED;
- next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
- vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32)~0;
- icmp6_error_set_vnet_buffer(p1, ICMP6_time_exceeded,
- ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
- }
- }
- else
- {
- p1->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
- }
+ /*
+ * If the hop count drops below 1 when forwarding, generate
+ * an ICMP response.
+ */
+ if (PREDICT_FALSE (hop_limit1 <= 0))
+ {
+ error1 = IP6_ERROR_TIME_EXPIRED;
+ next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
+ vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
+ ICMP6_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ }
+ }
+ else
+ {
+ p1->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
+ }
adj0 = ip_get_adjacency (lm, adj_index0);
adj1 = ip_get_adjacency (lm, adj_index1);
rw_len0 = adj0[0].rewrite_header.data_bytes;
rw_len1 = adj1[0].rewrite_header.data_bytes;
- vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
- vnet_buffer(p1)->ip.save_rewrite_length = rw_len1;
+ vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
+ vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
vlib_increment_combined_counter (&adjacency_counters,
- cpu_index,
- adj_index0,
+ cpu_index, adj_index0,
/* packet increment */ 0,
/* byte increment */ rw_len0);
vlib_increment_combined_counter (&adjacency_counters,
- cpu_index,
- adj_index1,
+ cpu_index, adj_index1,
/* packet increment */ 0,
/* byte increment */ rw_len1);
/* Check MTU of outgoing interface. */
- error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
- ? IP6_ERROR_MTU_EXCEEDED
- : error0);
- error1 = (vlib_buffer_length_in_chain (vm, p1) > adj1[0].rewrite_header.max_l3_packet_bytes
- ? IP6_ERROR_MTU_EXCEEDED
- : error1);
-
- /* Don't adjust the buffer for hop count issue; icmp-error node
- * wants to see the IP headerr */
- if (PREDICT_TRUE(error0 == IP6_ERROR_NONE))
- {
- p0->current_data -= rw_len0;
- p0->current_length += rw_len0;
-
- tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] =
- tx_sw_if_index0;
- next0 = adj0[0].rewrite_header.next_index;
-
- vnet_feature_arc_start(lm->output_feature_arc_index,
- tx_sw_if_index0, &next0, p0);
- }
- if (PREDICT_TRUE(error1 == IP6_ERROR_NONE))
- {
- p1->current_data -= rw_len1;
- p1->current_length += rw_len1;
-
- tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
- vnet_buffer (p1)->sw_if_index[VLIB_TX] =
- tx_sw_if_index1;
- next1 = adj1[0].rewrite_header.next_index;
-
- vnet_feature_arc_start(lm->output_feature_arc_index,
- tx_sw_if_index1, &next1, p1);
- }
+ error0 =
+ (vlib_buffer_length_in_chain (vm, p0) >
+ adj0[0].
+ rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
+ error0);
+ error1 =
+ (vlib_buffer_length_in_chain (vm, p1) >
+ adj1[0].
+ rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
+ error1);
+
+ /* Don't adjust the buffer for hop count issue; icmp-error node
+ * wants to see the IP headerr */
+ if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
+ {
+ p0->current_data -= rw_len0;
+ p0->current_length += rw_len0;
+
+ tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
+ next0 = adj0[0].rewrite_header.next_index;
+
+ vnet_feature_arc_start (lm->output_feature_arc_index,
+ tx_sw_if_index0, &next0, p0);
+ }
+ if (PREDICT_TRUE (error1 == IP6_ERROR_NONE))
+ {
+ p1->current_data -= rw_len1;
+ p1->current_length += rw_len1;
+
+ tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
+ vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
+ next1 = adj1[0].rewrite_header.next_index;
+
+ vnet_feature_arc_start (lm->output_feature_arc_index,
+ tx_sw_if_index1, &next1, p1);
+ }
/* Guess we are only writing on simple Ethernet header. */
vnet_rewrite_two_headers (adj0[0], adj1[0],
- ip0, ip1,
- sizeof (ethernet_header_t));
+ ip0, ip1, sizeof (ethernet_header_t));
if (is_midchain)
- {
- adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
- adj1->sub_type.midchain.fixup_func(vm, adj1, p1);
- }
+ {
+ adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
+ adj1->sub_type.midchain.fixup_func (vm, adj1, p1);
+ }
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
@@ -2128,12 +2166,12 @@ ip6_rewrite_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- ip_adjacency_t * adj0;
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ ip_adjacency_t *adj0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
u32 pi0, rw_len0;
u32 adj_index0, next0, error0;
- u32 tx_sw_if_index0;
+ u32 tx_sw_if_index0;
pi0 = to_next[0] = from[0];
@@ -2141,18 +2179,18 @@ ip6_rewrite_inline (vlib_main_t * vm,
adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
- /* We should never rewrite a pkt using the MISS adjacency */
- ASSERT(adj_index0);
+ /* We should never rewrite a pkt using the MISS adjacency */
+ ASSERT (adj_index0);
adj0 = ip_get_adjacency (lm, adj_index0);
ip0 = vlib_buffer_get_current (p0);
error0 = IP6_ERROR_NONE;
- next0 = IP6_REWRITE_NEXT_DROP;
+ next0 = IP6_REWRITE_NEXT_DROP;
/* Check hop limit */
- if (PREDICT_TRUE(!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
+ if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
{
i32 hop_limit0 = ip0->hop_limit;
@@ -2162,62 +2200,64 @@ ip6_rewrite_inline (vlib_main_t * vm,
ip0->hop_limit = hop_limit0;
- if (PREDICT_FALSE(hop_limit0 <= 0))
- {
- /*
- * If the hop count drops below 1 when forwarding, generate
- * an ICMP response.
- */
- error0 = IP6_ERROR_TIME_EXPIRED;
- next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32)~0;
- icmp6_error_set_vnet_buffer(p0, ICMP6_time_exceeded,
- ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
- }
+ if (PREDICT_FALSE (hop_limit0 <= 0))
+ {
+ /*
+ * If the hop count drops below 1 when forwarding, generate
+ * an ICMP response.
+ */
+ error0 = IP6_ERROR_TIME_EXPIRED;
+ next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
+ ICMP6_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ }
+ }
+ else
+ {
+ p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
}
- else
- {
- p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
- }
/* Guess we are only writing on simple Ethernet header. */
vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
/* Update packet buffer attributes/set output interface. */
rw_len0 = adj0[0].rewrite_header.data_bytes;
- vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
+ vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
vlib_increment_combined_counter (&adjacency_counters,
- cpu_index,
- adj_index0,
+ cpu_index, adj_index0,
/* packet increment */ 0,
/* byte increment */ rw_len0);
/* Check MTU of outgoing interface. */
- error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
- ? IP6_ERROR_MTU_EXCEEDED
- : error0);
-
- /* Don't adjust the buffer for hop count issue; icmp-error node
- * wants to see the IP headerr */
- if (PREDICT_TRUE(error0 == IP6_ERROR_NONE))
- {
+ error0 =
+ (vlib_buffer_length_in_chain (vm, p0) >
+ adj0[0].
+ rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
+ error0);
+
+ /* Don't adjust the buffer for hop count issue; icmp-error node
+ * wants to see the IP headerr */
+ if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
+ {
p0->current_data -= rw_len0;
p0->current_length += rw_len0;
- tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
+ tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
- vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
- next0 = adj0[0].rewrite_header.next_index;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
+ next0 = adj0[0].rewrite_header.next_index;
- vnet_feature_arc_start(lm->output_feature_arc_index,
- tx_sw_if_index0, &next0, p0);
- }
+ vnet_feature_arc_start (lm->output_feature_arc_index,
+ tx_sw_if_index0, &next0, p0);
+ }
if (is_midchain)
- {
- adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
- }
+ {
+ adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
+ }
p0->error = error_node->errors[error0];
@@ -2243,8 +2283,7 @@ ip6_rewrite_inline (vlib_main_t * vm,
static uword
ip6_rewrite (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip6_rewrite_inline (vm, node, frame,
/* midchain */ 0);
@@ -2252,38 +2291,40 @@ ip6_rewrite (vlib_main_t * vm,
static uword
ip6_midchain (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
return ip6_rewrite_inline (vm, node, frame,
/* midchain */ 1);
}
-VLIB_REGISTER_NODE (ip6_midchain_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_midchain_node) =
+{
.function = ip6_midchain,
.name = "ip6-midchain",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_forward_next_trace,
-
.sibling_of = "ip6-rewrite",
-};
+ };
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain);
-VLIB_REGISTER_NODE (ip6_rewrite_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_rewrite_node) =
+{
.function = ip6_rewrite,
.name = "ip6-rewrite",
.vector_size = sizeof (u32),
-
.format_trace = format_ip6_rewrite_trace,
-
.n_next_nodes = 2,
- .next_nodes = {
+ .next_nodes =
+ {
[IP6_REWRITE_NEXT_DROP] = "error-drop",
[IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
},
};
+/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite);
@@ -2298,18 +2339,20 @@ _(PROCESSED, "pkts with ip6 hop-by-hop options") \
_(FORMAT, "incorrectly formatted hop-by-hop options") \
_(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
-typedef enum {
+typedef enum
+{
#define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
foreach_ip6_hop_by_hop_error
#undef _
- IP6_HOP_BY_HOP_N_ERROR,
+ IP6_HOP_BY_HOP_N_ERROR,
} ip6_hop_by_hop_error_t;
/*
* Primary h-b-h handler trace support
* We work pretty hard on the problem for obvious reasons
*/
-typedef struct {
+typedef struct
+{
u32 next_index;
u32 trace_len;
u8 option_data[256];
@@ -2317,7 +2360,7 @@ typedef struct {
vlib_node_registration_t ip6_hop_by_hop_node;
-static char * ip6_hop_by_hop_error_strings[] = {
+static char *ip6_hop_by_hop_error_strings[] = {
#define _(sym,string) string,
foreach_ip6_hop_by_hop_error
#undef _
@@ -2328,48 +2371,56 @@ format_ip6_hop_by_hop_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 *);
- ip6_hop_by_hop_trace_t * t = va_arg (*args, ip6_hop_by_hop_trace_t *);
+ ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *);
ip6_hop_by_hop_header_t *hbh0;
ip6_hop_by_hop_option_t *opt0, *limit0;
ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
u8 type0;
- hbh0 = (ip6_hop_by_hop_header_t *)t->option_data;
+ hbh0 = (ip6_hop_by_hop_header_t *) t->option_data;
s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
- t->next_index, (hbh0->length+1)<<3, t->trace_len);
+ t->next_index, (hbh0->length + 1) << 3, t->trace_len);
- opt0 = (ip6_hop_by_hop_option_t *) (hbh0+1);
- limit0 = (ip6_hop_by_hop_option_t *) ((u8 *)hbh0) + t->trace_len;
+ opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
+ limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len;
- while (opt0 < limit0) {
- type0 = opt0->type;
- switch (type0) {
- case 0: /* Pad, just stop */
- opt0 = (ip6_hop_by_hop_option_t *) ((u8 *)opt0) + 1;
- break;
+ while (opt0 < limit0)
+ {
+ type0 = opt0->type;
+ switch (type0)
+ {
+ case 0: /* Pad, just stop */
+ opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
+ break;
- default:
- if (hm->trace[type0]) {
- s = (*hm->trace[type0])(s, opt0);
- } else {
- s = format (s, "\n unrecognized option %d length %d", type0, opt0->length);
- }
- opt0 = (ip6_hop_by_hop_option_t *) (((u8 *)opt0) + opt0->length + sizeof (ip6_hop_by_hop_option_t));
- break;
+ default:
+ if (hm->trace[type0])
+ {
+ s = (*hm->trace[type0]) (s, opt0);
+ }
+ else
+ {
+ s =
+ format (s, "\n unrecognized option %d length %d", type0,
+ opt0->length);
+ }
+ opt0 =
+ (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
+ sizeof (ip6_hop_by_hop_option_t));
+ break;
+ }
}
- }
return s;
}
-always_inline u8 ip6_scan_hbh_options (
- vlib_buffer_t * b0,
- ip6_header_t *ip0,
- ip6_hop_by_hop_header_t *hbh0,
- ip6_hop_by_hop_option_t *opt0,
- ip6_hop_by_hop_option_t *limit0,
- u32 *next0)
+always_inline u8
+ip6_scan_hbh_options (vlib_buffer_t * b0,
+ ip6_header_t * ip0,
+ ip6_hop_by_hop_header_t * hbh0,
+ ip6_hop_by_hop_option_t * opt0,
+ ip6_hop_by_hop_option_t * limit0, u32 * next0)
{
ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
u8 type0;
@@ -2380,19 +2431,19 @@ always_inline u8 ip6_scan_hbh_options (
type0 = opt0->type;
switch (type0)
{
- case 0: /* Pad1 */
- opt0 = (ip6_hop_by_hop_option_t *) ((u8 *)opt0) + 1;
+ case 0: /* Pad1 */
+ opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
continue;
- case 1: /* PadN */
+ case 1: /* PadN */
break;
default:
if (hm->options[type0])
{
- if ((*hm->options[type0])(b0, ip0, opt0) < 0)
- {
+ if ((*hm->options[type0]) (b0, ip0, opt0) < 0)
+ {
error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
- return(error0);
- }
+ return (error0);
+ }
}
else
{
@@ -2408,29 +2459,34 @@ always_inline u8 ip6_scan_hbh_options (
case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
*next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
- icmp6_error_set_vnet_buffer(b0, ICMP6_parameter_problem,
- ICMP6_parameter_problem_unrecognized_option, (u8 *)opt0 - (u8 *)ip0);
+ icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
+ ICMP6_parameter_problem_unrecognized_option,
+ (u8 *) opt0 - (u8 *) ip0);
break;
case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
- if (!ip6_address_is_multicast(&ip0->dst_address))
+ if (!ip6_address_is_multicast (&ip0->dst_address))
{
- *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
- icmp6_error_set_vnet_buffer(b0, ICMP6_parameter_problem,
- ICMP6_parameter_problem_unrecognized_option, (u8 *)opt0 - (u8 *)ip0);
+ *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
+ icmp6_error_set_vnet_buffer (b0,
+ ICMP6_parameter_problem,
+ ICMP6_parameter_problem_unrecognized_option,
+ (u8 *) opt0 - (u8 *) ip0);
}
else
{
- *next0 = IP_LOOKUP_NEXT_DROP;
+ *next0 = IP_LOOKUP_NEXT_DROP;
}
break;
}
- return(error0);
+ return (error0);
}
}
- opt0 = (ip6_hop_by_hop_option_t *) (((u8 *)opt0) + opt0->length + sizeof (ip6_hop_by_hop_option_t));
+ opt0 =
+ (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
+ sizeof (ip6_hop_by_hop_option_t));
}
- return(error0);
+ return (error0);
}
/*
@@ -2438,245 +2494,288 @@ always_inline u8 ip6_scan_hbh_options (
*/
static uword
ip6_hop_by_hop (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- vlib_node_runtime_t *error_node = vlib_node_get_runtime(vm, ip6_hop_by_hop_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index);
ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
u32 n_left_from, *from, *to_next;
ip_lookup_next_t next_index;
- ip6_main_t * im = &ip6_main;
+ ip6_main_t *im = &ip6_main;
ip_lookup_main_t *lm = &im->lookup_main;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
- while (n_left_from > 0) {
- u32 n_left_to_next;
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
- while (n_left_from >= 4 && n_left_to_next >= 2) {
- u32 bi0, bi1;
- vlib_buffer_t * b0, *b1;
- u32 next0, next1;
- ip6_header_t * ip0, *ip1;
- ip6_hop_by_hop_header_t *hbh0, *hbh1;
- ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
- u8 error0 = 0, error1 = 0;
+ while (n_left_from >= 4 && n_left_to_next >= 2)
+ {
+ u32 bi0, bi1;
+ vlib_buffer_t *b0, *b1;
+ u32 next0, next1;
+ ip6_header_t *ip0, *ip1;
+ ip6_hop_by_hop_header_t *hbh0, *hbh1;
+ ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
+ u8 error0 = 0, error1 = 0;
- /* Prefetch next iteration. */
- {
- vlib_buffer_t * p2, * p3;
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t *p2, *p3;
- p2 = vlib_get_buffer (vm, from[2]);
- p3 = vlib_get_buffer (vm, from[3]);
+ p2 = vlib_get_buffer (vm, from[2]);
+ p3 = vlib_get_buffer (vm, from[3]);
- vlib_prefetch_buffer_header (p2, LOAD);
- vlib_prefetch_buffer_header (p3, LOAD);
+ vlib_prefetch_buffer_header (p2, LOAD);
+ vlib_prefetch_buffer_header (p3, LOAD);
- CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
- CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
- }
+ CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
+ }
- /* Speculatively enqueue b0, b1 to the current next frame */
- to_next[0] = bi0 = from[0];
- to_next[1] = bi1 = from[1];
- from += 2;
- to_next += 2;
- n_left_from -= 2;
- n_left_to_next -= 2;
+ /* Speculatively enqueue b0, b1 to the current next frame */
+ to_next[0] = bi0 = from[0];
+ to_next[1] = bi1 = from[1];
+ from += 2;
+ to_next += 2;
+ n_left_from -= 2;
+ n_left_to_next -= 2;
- b0 = vlib_get_buffer (vm, bi0);
- b1 = vlib_get_buffer (vm, bi1);
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+
+ /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
+ u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
+ ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0);
+ u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
+ ip_adjacency_t *adj1 = ip_get_adjacency (lm, adj_index1);
+
+ /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
+ next0 = adj0->lookup_next_index;
+ next1 = adj1->lookup_next_index;
+
+ ip0 = vlib_buffer_get_current (b0);
+ ip1 = vlib_buffer_get_current (b1);
+ hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
+ hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
+ opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
+ opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1);
+ limit0 =
+ (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
+ ((hbh0->length + 1) << 3));
+ limit1 =
+ (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 +
+ ((hbh1->length + 1) << 3));
- /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
- u32 adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
- ip_adjacency_t *adj0 = ip_get_adjacency(lm, adj_index0);
- u32 adj_index1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX];
- ip_adjacency_t *adj1 = ip_get_adjacency(lm, adj_index1);
-
- /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
- next0 = adj0->lookup_next_index;
- next1 = adj1->lookup_next_index;
-
- ip0 = vlib_buffer_get_current (b0);
- ip1 = vlib_buffer_get_current (b1);
- hbh0 = (ip6_hop_by_hop_header_t *)(ip0+1);
- hbh1 = (ip6_hop_by_hop_header_t *)(ip1+1);
- opt0 = (ip6_hop_by_hop_option_t *)(hbh0+1);
- opt1 = (ip6_hop_by_hop_option_t *)(hbh1+1);
- limit0 = (ip6_hop_by_hop_option_t *)((u8 *)hbh0 + ((hbh0->length + 1) << 3));
- limit1 = (ip6_hop_by_hop_option_t *)((u8 *)hbh1 + ((hbh1->length + 1) << 3));
-
- /*
- * Basic validity checks
- */
- if ((hbh0->length + 1) << 3 > clib_net_to_host_u16(ip0->payload_length)) {
- error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
- next0 = IP_LOOKUP_NEXT_DROP;
- goto outdual;
- }
- /* Scan the set of h-b-h options, process ones that we understand */
- error0 = ip6_scan_hbh_options(b0, ip0, hbh0, opt0, limit0, &next0);
-
- if ((hbh1->length + 1) << 3 > clib_net_to_host_u16(ip1->payload_length)) {
- error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
- next1 = IP_LOOKUP_NEXT_DROP;
- goto outdual;
- }
- /* Scan the set of h-b-h options, process ones that we understand */
- error1 = ip6_scan_hbh_options(b1,ip1,hbh1,opt1,limit1, &next1);
-
- outdual:
- /* Has the classifier flagged this buffer for special treatment? */
- if (PREDICT_FALSE((error0 == 0) && (vnet_buffer(b0)->l2_classify.opaque_index & OI_DECAP)))
- next0 = hm->next_override;
-
- /* Has the classifier flagged this buffer for special treatment? */
- if (PREDICT_FALSE((error1 == 0) && (vnet_buffer(b1)->l2_classify.opaque_index & OI_DECAP)))
- next1 = hm->next_override;
-
- if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)))
- {
- if (b0->flags & VLIB_BUFFER_IS_TRACED) {
- ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b0, sizeof (*t));
- u32 trace_len = (hbh0->length + 1) << 3;
- t->next_index = next0;
- /* Capture the h-b-h option verbatim */
- trace_len = trace_len < ARRAY_LEN(t->option_data) ? trace_len : ARRAY_LEN(t->option_data);
- t->trace_len = trace_len;
- clib_memcpy(t->option_data, hbh0, trace_len);
- }
- if (b1->flags & VLIB_BUFFER_IS_TRACED) {
- ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b1, sizeof (*t));
- u32 trace_len = (hbh1->length + 1) << 3;
- t->next_index = next1;
- /* Capture the h-b-h option verbatim */
- trace_len = trace_len < ARRAY_LEN(t->option_data) ? trace_len : ARRAY_LEN(t->option_data);
- t->trace_len = trace_len;
- clib_memcpy(t->option_data, hbh1, trace_len);
- }
+ /*
+ * Basic validity checks
+ */
+ if ((hbh0->length + 1) << 3 >
+ clib_net_to_host_u16 (ip0->payload_length))
+ {
+ error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
+ next0 = IP_LOOKUP_NEXT_DROP;
+ goto outdual;
+ }
+ /* Scan the set of h-b-h options, process ones that we understand */
+ error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
+ if ((hbh1->length + 1) << 3 >
+ clib_net_to_host_u16 (ip1->payload_length))
+ {
+ error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
+ next1 = IP_LOOKUP_NEXT_DROP;
+ goto outdual;
+ }
+ /* Scan the set of h-b-h options, process ones that we understand */
+ error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1);
+
+ outdual:
+ /* Has the classifier flagged this buffer for special treatment? */
+ if (PREDICT_FALSE
+ ((error0 == 0)
+ && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
+ next0 = hm->next_override;
+
+ /* Has the classifier flagged this buffer for special treatment? */
+ if (PREDICT_FALSE
+ ((error1 == 0)
+ && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP)))
+ next1 = hm->next_override;
+
+ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
+ {
+ if (b0->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ ip6_hop_by_hop_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ u32 trace_len = (hbh0->length + 1) << 3;
+ t->next_index = next0;
+ /* Capture the h-b-h option verbatim */
+ trace_len =
+ trace_len <
+ ARRAY_LEN (t->option_data) ? trace_len :
+ ARRAY_LEN (t->option_data);
+ t->trace_len = trace_len;
+ clib_memcpy (t->option_data, hbh0, trace_len);
+ }
+ if (b1->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ ip6_hop_by_hop_trace_t *t =
+ vlib_add_trace (vm, node, b1, sizeof (*t));
+ u32 trace_len = (hbh1->length + 1) << 3;
+ t->next_index = next1;
+ /* Capture the h-b-h option verbatim */
+ trace_len =
+ trace_len <
+ ARRAY_LEN (t->option_data) ? trace_len :
+ ARRAY_LEN (t->option_data);
+ t->trace_len = trace_len;
+ clib_memcpy (t->option_data, hbh1, trace_len);
+ }
+
+ }
+
+ b0->error = error_node->errors[error0];
+ b1->error = error_node->errors[error1];
+
+ /* verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, bi1, next0,
+ next1);
}
- b0->error = error_node->errors[error0];
- b1->error = error_node->errors[error1];
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ u32 next0;
+ ip6_header_t *ip0;
+ ip6_hop_by_hop_header_t *hbh0;
+ ip6_hop_by_hop_option_t *opt0, *limit0;
+ u8 error0 = 0;
+
+ /* Speculatively enqueue b0 to the current next frame */
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ /*
+ * Default use the next_index from the adjacency.
+ * A HBH option rarely redirects to a different node
+ */
+ u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
+ ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0);
+ next0 = adj0->lookup_next_index;
- /* verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, n_left_to_next, bi0,
- bi1,next0, next1);
- }
+ ip0 = vlib_buffer_get_current (b0);
+ hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
+ opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
+ limit0 =
+ (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
+ ((hbh0->length + 1) << 3));
- while (n_left_from > 0 && n_left_to_next > 0) {
- u32 bi0;
- vlib_buffer_t * b0;
- u32 next0;
- ip6_header_t * ip0;
- ip6_hop_by_hop_header_t *hbh0;
- ip6_hop_by_hop_option_t *opt0, *limit0;
- u8 error0 = 0;
-
- /* Speculatively enqueue b0 to the current next frame */
- bi0 = from[0];
- to_next[0] = bi0;
- from += 1;
- to_next += 1;
- n_left_from -= 1;
- n_left_to_next -= 1;
+ /*
+ * Basic validity checks
+ */
+ if ((hbh0->length + 1) << 3 >
+ clib_net_to_host_u16 (ip0->payload_length))
+ {
+ error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
+ next0 = IP_LOOKUP_NEXT_DROP;
+ goto out0;
+ }
- b0 = vlib_get_buffer (vm, bi0);
- /*
- * Default use the next_index from the adjacency.
- * A HBH option rarely redirects to a different node
- */
- u32 adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
- ip_adjacency_t *adj0 = ip_get_adjacency(lm, adj_index0);
- next0 = adj0->lookup_next_index;
-
- ip0 = vlib_buffer_get_current (b0);
- hbh0 = (ip6_hop_by_hop_header_t *)(ip0+1);
- opt0 = (ip6_hop_by_hop_option_t *)(hbh0+1);
- limit0 = (ip6_hop_by_hop_option_t *)((u8 *)hbh0 + ((hbh0->length + 1) << 3));
-
- /*
- * Basic validity checks
- */
- if ((hbh0->length + 1) << 3 > clib_net_to_host_u16(ip0->payload_length)) {
- error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
- next0 = IP_LOOKUP_NEXT_DROP;
- goto out0;
- }
-
- /* Scan the set of h-b-h options, process ones that we understand */
- error0 = ip6_scan_hbh_options(b0, ip0, hbh0, opt0, limit0, &next0);
-
- out0:
- /* Has the classifier flagged this buffer for special treatment? */
- if (PREDICT_FALSE((error0 == 0) && (vnet_buffer(b0)->l2_classify.opaque_index & OI_DECAP)))
- next0 = hm->next_override;
-
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) {
- ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b0, sizeof (*t));
- u32 trace_len = (hbh0->length + 1) << 3;
- t->next_index = next0;
- /* Capture the h-b-h option verbatim */
- trace_len = trace_len < ARRAY_LEN(t->option_data) ? trace_len : ARRAY_LEN(t->option_data);
- t->trace_len = trace_len;
- clib_memcpy(t->option_data, hbh0, trace_len);
- }
-
- b0->error = error_node->errors[error0];
-
- /* verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, bi0, next0);
+ /* Scan the set of h-b-h options, process ones that we understand */
+ error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
+
+ out0:
+ /* Has the classifier flagged this buffer for special treatment? */
+ if (PREDICT_FALSE
+ ((error0 == 0)
+ && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
+ next0 = hm->next_override;
+
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ ip6_hop_by_hop_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ u32 trace_len = (hbh0->length + 1) << 3;
+ t->next_index = next0;
+ /* Capture the h-b-h option verbatim */
+ trace_len =
+ trace_len <
+ ARRAY_LEN (t->option_data) ? trace_len :
+ ARRAY_LEN (t->option_data);
+ t->trace_len = trace_len;
+ clib_memcpy (t->option_data, hbh0, trace_len);
+ }
+
+ b0->error = error_node->errors[error0];
+
+ /* verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- }
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip6_hop_by_hop_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
+{
.function = ip6_hop_by_hop,
.name = "ip6-hop-by-hop",
.sibling_of = "ip6-lookup",
.vector_size = sizeof (u32),
.format_trace = format_ip6_hop_by_hop_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
- .n_errors = ARRAY_LEN(ip6_hop_by_hop_error_strings),
+ .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings),
.error_strings = ip6_hop_by_hop_error_strings,
.n_next_nodes = 0,
};
+/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop);
static clib_error_t *
ip6_hop_by_hop_init (vlib_main_t * vm)
{
- ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
- memset(hm->options, 0, sizeof(hm->options));
- memset(hm->trace, 0, sizeof(hm->trace));
+ ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
+ memset (hm->options, 0, sizeof (hm->options));
+ memset (hm->trace, 0, sizeof (hm->trace));
hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
return (0);
}
VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
-void ip6_hbh_set_next_override (uword next)
+void
+ip6_hbh_set_next_override (uword next)
{
- ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
+ ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
hm->next_override = next;
}
int
ip6_hbh_register_option (u8 option,
- int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt),
- u8 *trace(u8 *s, ip6_hop_by_hop_option_t *opt))
+ int options (vlib_buffer_t * b, ip6_header_t * ip,
+ ip6_hop_by_hop_option_t * opt),
+ u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt))
{
- ip6_main_t * im = &ip6_main;
- ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
+ ip6_main_t *im = &ip6_main;
+ ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
ASSERT (option < ARRAY_LEN (hm->options));
@@ -2696,8 +2795,8 @@ ip6_hbh_register_option (u8 option,
int
ip6_hbh_unregister_option (u8 option)
{
- ip6_main_t * im = &ip6_main;
- ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
+ ip6_main_t *im = &ip6_main;
+ ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
ASSERT (option < ARRAY_LEN (hm->options));
@@ -2711,12 +2810,14 @@ ip6_hbh_unregister_option (u8 option)
/* Disable global knob if this was the last option configured */
int i;
bool found = false;
- for (i = 0; i < 256; i++) {
- if (hm->options[option]) {
- found = true;
- break;
+ for (i = 0; i < 256; i++)
+ {
+ if (hm->options[option])
+ {
+ found = true;
+ break;
+ }
}
- }
if (!found)
im->hbh_enabled = 0;
@@ -2729,8 +2830,8 @@ ip6_main_t ip6_main;
static clib_error_t *
ip6_lookup_init (vlib_main_t * vm)
{
- ip6_main_t * im = &ip6_main;
- clib_error_t * error;
+ ip6_main_t *im = &ip6_main;
+ clib_error_t *error;
uword i;
if ((error = vlib_call_init_function (vm, vnet_feature_init)))
@@ -2747,7 +2848,8 @@ ip6_lookup_init (vlib_main_t * vm)
im->fib_masks[i].as_u32[j] = ~0;
if (i1)
- im->fib_masks[i].as_u32[i0] = clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
+ im->fib_masks[i].as_u32[i0] =
+ clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
}
ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
@@ -2755,25 +2857,23 @@ ip6_lookup_init (vlib_main_t * vm)
if (im->lookup_table_nbuckets == 0)
im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS;
- im->lookup_table_nbuckets = 1<< max_log2 (im->lookup_table_nbuckets);
+ im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets);
if (im->lookup_table_size == 0)
im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE;
- BV(clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
- "ip6 FIB fwding table",
- im->lookup_table_nbuckets,
- im->lookup_table_size);
- BV(clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
- "ip6 FIB non-fwding table",
- im->lookup_table_nbuckets,
- im->lookup_table_size);
+ BV (clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
+ "ip6 FIB fwding table",
+ im->lookup_table_nbuckets, im->lookup_table_size);
+ BV (clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
+ "ip6 FIB non-fwding table",
+ im->lookup_table_nbuckets, im->lookup_table_size);
/* Create FIB with index 0 and table id of 0. */
- fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP6, 0);
+ fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0);
{
- pg_node_t * pn;
+ pg_node_t *pn;
pn = pg_get_node (ip6_lookup_node.index);
pn->unformat_edit = unformat_pg_ip6_header;
}
@@ -2786,17 +2886,22 @@ ip6_lookup_init (vlib_main_t * vm)
memset (&p, 0, sizeof (p));
- p.ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
- p.ip.payload_length = clib_host_to_net_u16 (sizeof (p)
- - STRUCT_OFFSET_OF (icmp6_neighbor_solicitation_header_t, neighbor));
+ p.ip.ip_version_traffic_class_and_flow_label =
+ clib_host_to_net_u32 (0x6 << 28);
+ p.ip.payload_length =
+ clib_host_to_net_u16 (sizeof (p) -
+ STRUCT_OFFSET_OF
+ (icmp6_neighbor_solicitation_header_t, neighbor));
p.ip.protocol = IP_PROTOCOL_ICMP6;
p.ip.hop_limit = 255;
ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
- p.link_layer_option.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
- p.link_layer_option.header.n_data_u64s = sizeof (p.link_layer_option) / sizeof (u64);
+ p.link_layer_option.header.type =
+ ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
+ p.link_layer_option.header.n_data_u64s =
+ sizeof (p.link_layer_option) / sizeof (u64);
vlib_packet_template_init (vm,
&im->discover_neighbor_packet_template,
@@ -2812,16 +2917,16 @@ VLIB_INIT_FUNCTION (ip6_lookup_init);
static clib_error_t *
add_del_ip6_interface_table (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *error = 0;
u32 sw_if_index, table_id;
sw_if_index = ~0;
- if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+ if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
error = clib_error_return (0, "unknown interface `%U'",
format_unformat_error, input);
@@ -2838,15 +2943,15 @@ add_del_ip6_interface_table (vlib_main_t * vm,
}
{
- u32 fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP6,
- table_id);
+ u32 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
+ table_id);
vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
}
- done:
+done:
return error;
}
@@ -2871,7 +2976,8 @@ add_del_ip6_interface_table (vlib_main_t * vm,
* @cliexcmd{set interface ip6 table GigabitEthernet2/0/0 2}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_interface_ip6_table_command, static) = {
+VLIB_CLI_COMMAND (set_interface_ip6_table_command, static) =
+{
.path = "set interface ip6 table",
.function = add_del_ip6_interface_table,
.short_help = "set interface ip6 table <interface> <table-id>"
@@ -2879,38 +2985,37 @@ VLIB_CLI_COMMAND (set_interface_ip6_table_command, static) = {
/* *INDENT-ON* */
void
-ip6_link_local_address_from_ethernet_mac_address (ip6_address_t *ip,
- u8 *mac)
+ip6_link_local_address_from_ethernet_mac_address (ip6_address_t * ip,
+ u8 * mac)
{
ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
/* Invert the "u" bit */
- ip->as_u8 [8] = mac[0] ^ (1<<1);
- ip->as_u8 [9] = mac[1];
- ip->as_u8 [10] = mac[2];
- ip->as_u8 [11] = 0xFF;
- ip->as_u8 [12] = 0xFE;
- ip->as_u8 [13] = mac[3];
- ip->as_u8 [14] = mac[4];
- ip->as_u8 [15] = mac[5];
+ ip->as_u8[8] = mac[0] ^ (1 << 1);
+ ip->as_u8[9] = mac[1];
+ ip->as_u8[10] = mac[2];
+ ip->as_u8[11] = 0xFF;
+ ip->as_u8[12] = 0xFE;
+ ip->as_u8[13] = mac[3];
+ ip->as_u8[14] = mac[4];
+ ip->as_u8[15] = mac[5];
}
void
-ip6_ethernet_mac_address_from_link_local_address (u8 *mac,
- ip6_address_t *ip)
+ip6_ethernet_mac_address_from_link_local_address (u8 * mac,
+ ip6_address_t * ip)
{
/* Invert the previously inverted "u" bit */
- mac[0] = ip->as_u8 [8] ^ (1<<1);
- mac[1] = ip->as_u8 [9];
- mac[2] = ip->as_u8 [10];
- mac[3] = ip->as_u8 [13];
- mac[4] = ip->as_u8 [14];
- mac[5] = ip->as_u8 [15];
+ mac[0] = ip->as_u8[8] ^ (1 << 1);
+ mac[1] = ip->as_u8[9];
+ mac[2] = ip->as_u8[10];
+ mac[3] = ip->as_u8[13];
+ mac[4] = ip->as_u8[14];
+ mac[5] = ip->as_u8[15];
}
static clib_error_t *
test_ip6_link_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
u8 mac[6];
ip6_address_t _a, *a = &_a;
@@ -2918,11 +3023,10 @@ test_ip6_link_command_fn (vlib_main_t * vm,
if (unformat (input, "%U", unformat_ethernet_address, mac))
{
ip6_link_local_address_from_ethernet_mac_address (a, mac);
- vlib_cli_output (vm, "Link local address: %U",
- format_ip6_address, a);
+ vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
ip6_ethernet_mac_address_from_link_local_address (mac, a);
vlib_cli_output (vm, "Original MAC address: %U",
- format_ethernet_address, mac);
+ format_ethernet_address, mac);
}
return 0;
@@ -2940,18 +3044,20 @@ test_ip6_link_command_fn (vlib_main_t * vm,
* @cliexend
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (test_link_command, static) = {
+VLIB_CLI_COMMAND (test_link_command, static) =
+{
.path = "test ip6 link",
.function = test_ip6_link_command_fn,
.short_help = "test ip6 link <mac-address>",
};
/* *INDENT-ON* */
-int vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
+int
+vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
{
- ip6_main_t * im6 = &ip6_main;
- ip6_fib_t * fib;
- uword * p = hash_get (im6->fib_index_by_table_id, table_id);
+ ip6_main_t *im6 = &ip6_main;
+ ip6_fib_t *fib;
+ uword *p = hash_get (im6->fib_index_by_table_id, table_id);
if (p == 0)
return -1;
@@ -2964,27 +3070,29 @@ int vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
static clib_error_t *
set_ip6_flow_hash_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
int matched = 0;
u32 table_id = 0;
u32 flow_hash_config = 0;
int rv;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "table %d", &table_id))
- matched = 1;
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "table %d", &table_id))
+ matched = 1;
#define _(a,v) \
else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
- foreach_flow_hash_bit
+ foreach_flow_hash_bit
#undef _
- else break;
- }
+ else
+ break;
+ }
if (matched == 0)
return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
switch (rv)
@@ -3079,28 +3187,28 @@ set_ip6_flow_hash_command_fn (vlib_main_t * vm,
* @endparblock
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = {
- .path = "set ip6 flow-hash",
- .short_help =
- "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
- .function = set_ip6_flow_hash_command_fn,
+VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) =
+{
+ .path = "set ip6 flow-hash",
+ .short_help =
+ "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
+ .function = set_ip6_flow_hash_command_fn,
};
/* *INDENT-ON* */
static clib_error_t *
show_ip6_local_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- ip6_main_t * im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ip6_main_t *im = &ip6_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
int i;
vlib_cli_output (vm, "Protocols handled by ip6_local");
- for (i = 0; i < ARRAY_LEN(lm->local_next_by_ip_protocol); i++)
+ for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
{
if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
- vlib_cli_output (vm, "%d", i);
+ vlib_cli_output (vm, "%d", i);
}
return 0;
}
@@ -3121,21 +3229,23 @@ show_ip6_local_command_fn (vlib_main_t * vm,
* @cliexend
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_ip6_local, static) = {
+VLIB_CLI_COMMAND (show_ip6_local, static) =
+{
.path = "show ip6 local",
.function = show_ip6_local_command_fn,
.short_help = "show ip6 local",
};
/* *INDENT-ON* */
-int vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
- u32 table_index)
+int
+vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
+ u32 table_index)
{
- vnet_main_t * vnm = vnet_get_main();
- vnet_interface_main_t * im = &vnm->interface_main;
- ip6_main_t * ipm = &ip6_main;
- ip_lookup_main_t * lm = &ipm->lookup_main;
- vnet_classify_main_t * cm = &vnet_classify_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_interface_main_t *im = &vnm->interface_main;
+ ip6_main_t *ipm = &ip6_main;
+ ip_lookup_main_t *lm = &ipm->lookup_main;
+ vnet_classify_main_t *cm = &vnet_classify_main;
ip6_address_t *if_addr;
if (pool_is_free_index (im->sw_interfaces, sw_if_index))
@@ -3145,73 +3255,71 @@ int vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
return VNET_API_ERROR_NO_SUCH_ENTRY;
vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
- lm->classify_table_index_by_sw_if_index [sw_if_index] = table_index;
+ lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
if_addr = ip6_interface_first_address (ipm, sw_if_index, NULL);
if (NULL != if_addr)
- {
+ {
fib_prefix_t pfx = {
- .fp_len = 128,
- .fp_proto = FIB_PROTOCOL_IP6,
- .fp_addr.ip6 = *if_addr,
+ .fp_len = 128,
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_addr.ip6 = *if_addr,
};
u32 fib_index;
- fib_index = fib_table_get_index_for_sw_if_index(FIB_PROTOCOL_IP4,
- sw_if_index);
-
-
- if (table_index != (u32) ~0)
- {
- dpo_id_t dpo = DPO_INVALID;
+ fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
+ sw_if_index);
- dpo_set(&dpo,
- DPO_CLASSIFY,
- DPO_PROTO_IP6,
- classify_dpo_create(DPO_PROTO_IP6,
- table_index));
- fib_table_entry_special_dpo_add(fib_index,
- &pfx,
- FIB_SOURCE_CLASSIFY,
- FIB_ENTRY_FLAG_NONE,
- &dpo);
- dpo_reset(&dpo);
- }
+ if (table_index != (u32) ~ 0)
+ {
+ dpo_id_t dpo = DPO_INVALID;
+
+ dpo_set (&dpo,
+ DPO_CLASSIFY,
+ DPO_PROTO_IP6,
+ classify_dpo_create (DPO_PROTO_IP6, table_index));
+
+ fib_table_entry_special_dpo_add (fib_index,
+ &pfx,
+ FIB_SOURCE_CLASSIFY,
+ FIB_ENTRY_FLAG_NONE, &dpo);
+ dpo_reset (&dpo);
+ }
else
- {
- fib_table_entry_special_remove(fib_index,
- &pfx,
- FIB_SOURCE_CLASSIFY);
- }
- }
+ {
+ fib_table_entry_special_remove (fib_index,
+ &pfx, FIB_SOURCE_CLASSIFY);
+ }
+ }
return 0;
}
static clib_error_t *
set_ip6_classify_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
u32 table_index = ~0;
int table_index_set = 0;
u32 sw_if_index = ~0;
int rv;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "table-index %d", &table_index))
- table_index_set = 1;
- else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
- vnet_get_main(), &sw_if_index))
- ;
- else
- break;
- }
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "table-index %d", &table_index))
+ table_index_set = 1;
+ else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
+ vnet_get_main (), &sw_if_index))
+ ;
+ else
+ break;
+ }
if (table_index_set == 0)
- return clib_error_return (0, "classify table-index must be specified");
+ return clib_error_return (0, "classify table-index must be specified");
if (sw_if_index == ~0)
return clib_error_return (0, "interface / subif must be specified");
@@ -3243,37 +3351,39 @@ set_ip6_classify_command_fn (vlib_main_t * vm,
* @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_ip6_classify_command, static) = {
- .path = "set ip6 classify",
- .short_help =
- "set ip6 classify intfc <interface> table-index <classify-idx>",
- .function = set_ip6_classify_command_fn,
+VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
+{
+ .path = "set ip6 classify",
+ .short_help =
+ "set ip6 classify intfc <interface> table-index <classify-idx>",
+ .function = set_ip6_classify_command_fn,
};
/* *INDENT-ON* */
static clib_error_t *
ip6_config (vlib_main_t * vm, unformat_input_t * input)
{
- ip6_main_t * im = &ip6_main;
+ ip6_main_t *im = &ip6_main;
uword heapsize = 0;
u32 tmp;
u32 nbuckets = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "hash-buckets %d", &tmp))
- nbuckets = tmp;
- else if (unformat (input, "heap-size %dm", &tmp))
- heapsize = ((u64)tmp) << 20;
- else if (unformat (input, "heap-size %dM", &tmp))
- heapsize = ((u64)tmp) << 20;
- else if (unformat (input, "heap-size %dg", &tmp))
- heapsize = ((u64)tmp) << 30;
- else if (unformat (input, "heap-size %dG", &tmp))
- heapsize = ((u64)tmp) << 30;
- else
- return clib_error_return (0, "unknown input '%U'",
- format_unformat_error, input);
- }
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "hash-buckets %d", &tmp))
+ nbuckets = tmp;
+ else if (unformat (input, "heap-size %dm", &tmp))
+ heapsize = ((u64) tmp) << 20;
+ else if (unformat (input, "heap-size %dM", &tmp))
+ heapsize = ((u64) tmp) << 20;
+ else if (unformat (input, "heap-size %dg", &tmp))
+ heapsize = ((u64) tmp) << 30;
+ else if (unformat (input, "heap-size %dG", &tmp))
+ heapsize = ((u64) tmp) << 30;
+ else
+ return clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, input);
+ }
im->lookup_table_nbuckets = nbuckets;
im->lookup_table_size = heapsize;
@@ -3282,3 +3392,11 @@ ip6_config (vlib_main_t * vm, unformat_input_t * input)
}
VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6");
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_hop_by_hop.c b/vnet/vnet/ip/ip6_hop_by_hop.c
index e8bc8906335..3a820b3cefc 100644
--- a/vnet/vnet/ip/ip6_hop_by_hop.c
+++ b/vnet/vnet/ip/ip6_hop_by_hop.c
@@ -460,6 +460,7 @@ ip6_add_hop_by_hop_node_fn (vlib_main_t * vm,
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_add_hop_by_hop_node) = /* *INDENT-OFF* */
{
.function = ip6_add_hop_by_hop_node_fn,.name =
@@ -476,19 +477,21 @@ VLIB_REGISTER_NODE (ip6_add_hop_by_hop_node) = /* *INDENT-OFF* */
#undef _
}
,};
+/* *INDENT-ON* */
/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip6_add_hop_by_hop_node,
- ip6_add_hop_by_hop_node_fn)
+ ip6_add_hop_by_hop_node_fn);
/* The main h-b-h tracer was already invoked, no need to do much here */
- typedef struct
- {
- u32 next_index;
- } ip6_pop_hop_by_hop_trace_t;
+typedef struct
+{
+ u32 next_index;
+} ip6_pop_hop_by_hop_trace_t;
/* packet trace format function */
- static u8 *format_ip6_pop_hop_by_hop_trace (u8 * s, va_list * args)
+static u8 *
+format_ip6_pop_hop_by_hop_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 *);
@@ -816,8 +819,9 @@ VLIB_REGISTER_NODE (ip6_pop_hop_by_hop_node) =
/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip6_pop_hop_by_hop_node,
- ip6_pop_hop_by_hop_node_fn)
- static clib_error_t *ip6_hop_by_hop_ioam_init (vlib_main_t * vm)
+ ip6_pop_hop_by_hop_node_fn);
+static clib_error_t *
+ip6_hop_by_hop_ioam_init (vlib_main_t * vm)
{
clib_error_t *error;
ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
diff --git a/vnet/vnet/ip/ip6_hop_by_hop.h b/vnet/vnet/ip/ip6_hop_by_hop.h
index e86a6d05f82..acfaa37ed2f 100644
--- a/vnet/vnet/ip/ip6_hop_by_hop.h
+++ b/vnet/vnet/ip/ip6_hop_by_hop.h
@@ -34,14 +34,16 @@
/*
* Stores the run time flow data of hbh options
*/
-typedef struct {
+typedef struct
+{
u32 ctx[MAX_IP6_HBH_OPTION];
u8 flow_name[64];
} flow_data_t;
-typedef struct {
+typedef struct
+{
/* The current rewrite we're using */
- u8 * rewrite;
+ u8 *rewrite;
/* Trace data processing callback */
void *ioam_end_of_path_cb;
@@ -71,94 +73,111 @@ typedef struct {
/* Array of function pointers to ADD and POP HBH option handling routines */
u8 options_size[MAX_IP6_HBH_OPTION];
- int (*add_options[MAX_IP6_HBH_OPTION])(u8 *rewrite_string, u8 *rewrite_size);
- int (*pop_options[MAX_IP6_HBH_OPTION])(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt);
- int (*get_sizeof_options[MAX_IP6_HBH_OPTION])(u32 *rewrite_size);
+ int (*add_options[MAX_IP6_HBH_OPTION]) (u8 * rewrite_string,
+ u8 * rewrite_size);
+ int (*pop_options[MAX_IP6_HBH_OPTION]) (vlib_buffer_t * b,
+ ip6_header_t * ip,
+ ip6_hop_by_hop_option_t * opt);
+ int (*get_sizeof_options[MAX_IP6_HBH_OPTION]) (u32 * rewrite_size);
int (*config_handler[MAX_IP6_HBH_OPTION]) (void *data, u8 disable);
/* Array of function pointers to handle hbh options being used with classifier */
- u32 (*flow_handler[MAX_IP6_HBH_OPTION])(u32 flow_ctx, u8 add);
+ u32 (*flow_handler[MAX_IP6_HBH_OPTION]) (u32 flow_ctx, u8 add);
flow_data_t *flows;
/* convenience */
- vlib_main_t * vlib_main;
- vnet_main_t * vnet_main;
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
} ip6_hop_by_hop_ioam_main_t;
extern ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main;
-extern u8 * format_path_map(u8 * s, va_list * args);
+extern u8 *format_path_map (u8 * s, va_list * args);
-extern clib_error_t *
-ip6_ioam_enable(int has_trace_option, int has_pot_option,
- int has_seqno_option, int has_analyse_option);
+extern clib_error_t *ip6_ioam_enable (int has_trace_option,
+ int has_pot_option,
+ int has_seqno_option,
+ int has_analyse_option);
-extern int ip6_ioam_set_destination (ip6_address_t *addr, u32 mask_width,
- u32 vrf_id, int is_add, int is_pop, int is_none);
+extern int ip6_ioam_set_destination (ip6_address_t * addr, u32 mask_width,
+ u32 vrf_id, int is_add, int is_pop,
+ int is_none);
-extern clib_error_t * clear_ioam_rewrite_fn(void);
+extern clib_error_t *clear_ioam_rewrite_fn (void);
-static inline u8 is_zero_ip4_address (ip4_address_t *a)
+static inline u8
+is_zero_ip4_address (ip4_address_t * a)
{
return (a->as_u32 == 0);
}
-static inline void copy_ip6_address (ip6_address_t *dst, ip6_address_t *src)
+static inline void
+copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
{
dst->as_u64[0] = src->as_u64[0];
dst->as_u64[1] = src->as_u64[1];
}
-static inline void set_zero_ip6_address (ip6_address_t *a)
+static inline void
+set_zero_ip6_address (ip6_address_t * a)
{
a->as_u64[0] = 0;
a->as_u64[1] = 0;
}
-static inline u8 cmp_ip6_address (ip6_address_t *a1, ip6_address_t *a2)
+static inline u8
+cmp_ip6_address (ip6_address_t * a1, ip6_address_t * a2)
{
- return ((a1->as_u64[0] == a2->as_u64[0]) && (a1->as_u64[1] == a2->as_u64[1]));
+ return ((a1->as_u64[0] == a2->as_u64[0])
+ && (a1->as_u64[1] == a2->as_u64[1]));
}
-static inline u8 is_zero_ip6_address (ip6_address_t *a)
+
+static inline u8
+is_zero_ip6_address (ip6_address_t * a)
{
return ((a->as_u64[0] == 0) && (a->as_u64[1] == 0));
}
int ip6_hbh_add_register_option (u8 option,
u8 size,
- int rewrite_options(u8 *rewrite_string, u8 *size));
+ int rewrite_options (u8 * rewrite_string,
+ u8 * size));
int ip6_hbh_add_unregister_option (u8 option);
int ip6_hbh_pop_register_option (u8 option,
- int options(vlib_buffer_t *b,
- ip6_header_t *ip, ip6_hop_by_hop_option_t *opt));
+ int options (vlib_buffer_t * b,
+ ip6_header_t * ip,
+ ip6_hop_by_hop_option_t * opt));
int ip6_hbh_pop_unregister_option (u8 option);
int
ip6_hbh_get_sizeof_register_option (u8 option,
- int get_sizeof_hdr_options(u32 *rewrite_size));
+ int get_sizeof_hdr_options (u32 *
+ rewrite_size));
int
-ip6_ioam_set_rewrite (u8 **rwp, int has_trace_option,
+ip6_ioam_set_rewrite (u8 ** rwp, int has_trace_option,
int has_pot_option, int has_seq_no);
int
ip6_hbh_config_handler_register (u8 option,
- int config_handler(void *data, u8 disable));
+ int config_handler (void *data, u8 disable));
int ip6_hbh_config_handler_unregister (u8 option);
-int ip6_hbh_flow_handler_register(u8 option,
- u32 ioam_flow_handler(u32 flow_ctx, u8 add));
+int ip6_hbh_flow_handler_register (u8 option,
+ u32 ioam_flow_handler (u32 flow_ctx,
+ u8 add));
-int ip6_hbh_flow_handler_unregister(u8 option);
+int ip6_hbh_flow_handler_unregister (u8 option);
-u8 * get_flow_name_from_flow_ctx(u32 flow_ctx);
+u8 *get_flow_name_from_flow_ctx (u32 flow_ctx);
-static inline flow_data_t * get_flow (u32 index)
+static inline flow_data_t *
+get_flow (u32 index)
{
flow_data_t *flow = NULL;
- ip6_hop_by_hop_ioam_main_t * hm = &ip6_hop_by_hop_ioam_main;
+ ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
if (pool_is_free_index (hm->flows, index))
return NULL;
@@ -167,23 +186,32 @@ static inline flow_data_t * get_flow (u32 index)
return flow;
}
-static inline u32 get_flow_data_from_flow_ctx (u32 flow_ctx, u8 option)
+static inline u32
+get_flow_data_from_flow_ctx (u32 flow_ctx, u8 option)
{
flow_data_t *flow = NULL;
- ip6_hop_by_hop_ioam_main_t * hm = &ip6_hop_by_hop_ioam_main;
+ ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
u32 index;
- index = IOAM_MASK_DECAP_BIT(flow_ctx);
+ index = IOAM_MASK_DECAP_BIT (flow_ctx);
//flow = pool_elt_at_index (hm->flows, index);
flow = &hm->flows[index];
return (flow->ctx[option]);
}
-static inline u8 is_seqno_enabled (void)
+static inline u8
+is_seqno_enabled (void)
{
return (ip6_hop_by_hop_ioam_main.has_seqno_option);
}
-int
-ip6_trace_profile_setup ();
+int ip6_trace_profile_setup ();
#endif /* __included_ip6_hop_by_hop_ioam_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_hop_by_hop_packet.h b/vnet/vnet/ip/ip6_hop_by_hop_packet.h
index 8c358334c56..543ba8b0533 100644
--- a/vnet/vnet/ip/ip6_hop_by_hop_packet.h
+++ b/vnet/vnet/ip/ip6_hop_by_hop_packet.h
@@ -15,17 +15,19 @@
#ifndef __included_ip6_hop_by_hop_packet_h__
#define __included_ip6_hop_by_hop_packet_h__
-typedef struct {
+typedef struct
+{
/* Protocol for next header */
u8 protocol;
/*
- * Length of hop_by_hop header in 8 octet units,
+ * Length of hop_by_hop header in 8 octet units,
* not including the first 8 octets
*/
u8 length;
} ip6_hop_by_hop_header_t;
-typedef struct {
+typedef struct
+{
/* Option Type */
#define HBH_OPTION_TYPE_SKIP_UNKNOWN (0x00)
#define HBH_OPTION_TYPE_DISCARD_UNKNOWN (0x40)
@@ -39,16 +41,26 @@ typedef struct {
} ip6_hop_by_hop_option_t;
/* $$$$ IANA banana constants */
-#define HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST 59 /* Third highest bit set (change en-route) */
-#define HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT 60 /* Third highest bit set (change en-route) */
+#define HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST 59 /* Third highest bit set (change en-route) */
+#define HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT 60 /* Third highest bit set (change en-route) */
#define HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE 29
+/* *INDENT-OFF* */
typedef CLIB_PACKED(struct {
ip6_hop_by_hop_option_t hdr;
u8 e2e_type;
u8 reserved;
u32 e2e_data;
}) ioam_e2e_option_t;
+/* *INDENT-ON* */
#endif /* __included_ip6_hop_by_hop_packet_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_input.c b/vnet/vnet/ip/ip6_input.c
index f6d56be2829..bbc2cebaa39 100644
--- a/vnet/vnet/ip/ip6_input.c
+++ b/vnet/vnet/ip/ip6_input.c
@@ -42,24 +42,26 @@
#include <vnet/ppp/ppp.h>
#include <vnet/hdlc/hdlc.h>
-typedef struct {
+typedef struct
+{
u8 packet_data[64];
} ip6_input_trace_t;
-static u8 * format_ip6_input_trace (u8 * s, va_list * va)
+static u8 *
+format_ip6_input_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
- ip6_input_trace_t * t = va_arg (*va, ip6_input_trace_t *);
+ ip6_input_trace_t *t = va_arg (*va, ip6_input_trace_t *);
s = format (s, "%U",
- format_ip6_header,
- t->packet_data, sizeof (t->packet_data));
+ format_ip6_header, t->packet_data, sizeof (t->packet_data));
return s;
}
-typedef enum {
+typedef enum
+{
IP6_INPUT_NEXT_DROP,
IP6_INPUT_NEXT_LOOKUP,
IP6_INPUT_NEXT_ICMP_ERROR,
@@ -69,18 +71,17 @@ typedef enum {
/* Validate IP v6 packets and pass them either to forwarding code
or drop exception packets. */
static uword
-ip6_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip6_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- u32 n_left_from, * from, * to_next;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ u32 n_left_from, *from, *to_next;
ip6_input_next_t next_index;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
- vlib_simple_counter_main_t * cm;
- u32 cpu_index = os_get_cpu_number();
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_input_node.index);
+ vlib_simple_counter_main_t *cm;
+ u32 cpu_index = os_get_cpu_number ();
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -92,26 +93,25 @@ ip6_input (vlib_main_t * vm,
sizeof (ip6_input_trace_t));
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
- VNET_INTERFACE_COUNTER_IP6);
+ VNET_INTERFACE_COUNTER_IP6);
while (n_left_from > 0)
{
u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
- vlib_buffer_t * p0, * p1;
- ip6_header_t * ip0, * ip1;
+ vlib_buffer_t *p0, *p1;
+ ip6_header_t *ip0, *ip1;
u32 pi0, sw_if_index0, next0 = 0;
u32 pi1, sw_if_index1, next1 = 0;
u8 error0, error1, arc0, arc1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -142,8 +142,12 @@ ip6_input (vlib_main_t * vm,
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
sw_if_index1 = vnet_buffer (p1)->sw_if_index[VLIB_RX];
- arc0 = ip6_address_is_multicast (&ip0->dst_address) ? lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
- arc1 = ip6_address_is_multicast (&ip1->dst_address) ? lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
+ arc0 =
+ ip6_address_is_multicast (&ip0->dst_address) ?
+ lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
+ arc1 =
+ ip6_address_is_multicast (&ip1->dst_address) ?
+ lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
vnet_buffer (p0)->ip.adj_index[VLIB_RX] = ~0;
vnet_buffer (p1)->ip.adj_index[VLIB_RX] = ~0;
@@ -157,40 +161,58 @@ ip6_input (vlib_main_t * vm,
error0 = error1 = IP6_ERROR_NONE;
/* Version != 6? Drop it. */
- error0 = (clib_net_to_host_u32 (ip0->ip_version_traffic_class_and_flow_label) >> 28) != 6 ? IP6_ERROR_VERSION : error0;
- error1 = (clib_net_to_host_u32 (ip1->ip_version_traffic_class_and_flow_label) >> 28) != 6 ? IP6_ERROR_VERSION : error1;
+ error0 =
+ (clib_net_to_host_u32
+ (ip0->ip_version_traffic_class_and_flow_label) >> 28) !=
+ 6 ? IP6_ERROR_VERSION : error0;
+ error1 =
+ (clib_net_to_host_u32
+ (ip1->ip_version_traffic_class_and_flow_label) >> 28) !=
+ 6 ? IP6_ERROR_VERSION : error1;
/* hop limit < 1? Drop it. for link-local broadcast packets,
- * like dhcpv6 packets from client has hop-limit 1, which should not
- * be dropped.
- */
+ * like dhcpv6 packets from client has hop-limit 1, which should not
+ * be dropped.
+ */
error0 = ip0->hop_limit < 1 ? IP6_ERROR_TIME_EXPIRED : error0;
error1 = ip1->hop_limit < 1 ? IP6_ERROR_TIME_EXPIRED : error1;
/* L2 length must be at least minimal IP header. */
- error0 = p0->current_length < sizeof (ip0[0]) ? IP6_ERROR_TOO_SHORT : error0;
- error1 = p1->current_length < sizeof (ip1[0]) ? IP6_ERROR_TOO_SHORT : error1;
-
- if (PREDICT_FALSE(error0 != IP6_ERROR_NONE))
- {
- if (error0 == IP6_ERROR_TIME_EXPIRED) {
- icmp6_error_set_vnet_buffer(p0, ICMP6_time_exceeded,
- ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
- next0 = IP6_INPUT_NEXT_ICMP_ERROR;
- } else {
- next0 = IP6_INPUT_NEXT_DROP;
- }
- }
- if (PREDICT_FALSE(error1 != IP6_ERROR_NONE))
- {
- if (error1 == IP6_ERROR_TIME_EXPIRED) {
- icmp6_error_set_vnet_buffer(p1, ICMP6_time_exceeded,
- ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
- next1 = IP6_INPUT_NEXT_ICMP_ERROR;
- } else {
- next1 = IP6_INPUT_NEXT_DROP;
- }
- }
+ error0 =
+ p0->current_length <
+ sizeof (ip0[0]) ? IP6_ERROR_TOO_SHORT : error0;
+ error1 =
+ p1->current_length <
+ sizeof (ip1[0]) ? IP6_ERROR_TOO_SHORT : error1;
+
+ if (PREDICT_FALSE (error0 != IP6_ERROR_NONE))
+ {
+ if (error0 == IP6_ERROR_TIME_EXPIRED)
+ {
+ icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
+ ICMP6_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next0 = IP6_INPUT_NEXT_ICMP_ERROR;
+ }
+ else
+ {
+ next0 = IP6_INPUT_NEXT_DROP;
+ }
+ }
+ if (PREDICT_FALSE (error1 != IP6_ERROR_NONE))
+ {
+ if (error1 == IP6_ERROR_TIME_EXPIRED)
+ {
+ icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
+ ICMP6_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next1 = IP6_INPUT_NEXT_ICMP_ERROR;
+ }
+ else
+ {
+ next1 = IP6_INPUT_NEXT_DROP;
+ }
+ }
p0->error = error_node->errors[error0];
p1->error = error_node->errors[error1];
@@ -199,11 +221,11 @@ ip6_input (vlib_main_t * vm,
to_next, n_left_to_next,
pi0, pi1, next0, next1);
}
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
u32 pi0, sw_if_index0, next0 = 0;
u8 error0, arc0;
@@ -218,7 +240,9 @@ ip6_input (vlib_main_t * vm,
ip0 = vlib_buffer_get_current (p0);
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
- arc0 = ip6_address_is_multicast (&ip0->dst_address) ? lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
+ arc0 =
+ ip6_address_is_multicast (&ip0->dst_address) ?
+ lm->mcast_feature_arc_index : lm->ucast_feature_arc_index;
vnet_buffer (p0)->ip.adj_index[VLIB_RX] = ~0;
vnet_feature_arc_start (arc0, sw_if_index0, &next0, p0);
@@ -226,27 +250,36 @@ ip6_input (vlib_main_t * vm,
error0 = IP6_ERROR_NONE;
/* Version != 6? Drop it. */
- error0 = (clib_net_to_host_u32 (ip0->ip_version_traffic_class_and_flow_label) >> 28) != 6 ? IP6_ERROR_VERSION : error0;
+ error0 =
+ (clib_net_to_host_u32
+ (ip0->ip_version_traffic_class_and_flow_label) >> 28) !=
+ 6 ? IP6_ERROR_VERSION : error0;
/* hop limit < 1? Drop it. for link-local broadcast packets,
- * like dhcpv6 packets from client has hop-limit 1, which should not
- * be dropped.
- */
+ * like dhcpv6 packets from client has hop-limit 1, which should not
+ * be dropped.
+ */
error0 = ip0->hop_limit < 1 ? IP6_ERROR_TIME_EXPIRED : error0;
/* L2 length must be at least minimal IP header. */
- error0 = p0->current_length < sizeof (ip0[0]) ? IP6_ERROR_TOO_SHORT : error0;
-
- if (PREDICT_FALSE(error0 != IP6_ERROR_NONE))
- {
- if (error0 == IP6_ERROR_TIME_EXPIRED) {
- icmp6_error_set_vnet_buffer(p0, ICMP6_time_exceeded,
- ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
- next0 = IP6_INPUT_NEXT_ICMP_ERROR;
- } else {
- next0 = IP6_INPUT_NEXT_DROP;
- }
- }
+ error0 =
+ p0->current_length <
+ sizeof (ip0[0]) ? IP6_ERROR_TOO_SHORT : error0;
+
+ if (PREDICT_FALSE (error0 != IP6_ERROR_NONE))
+ {
+ if (error0 == IP6_ERROR_TIME_EXPIRED)
+ {
+ icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
+ ICMP6_time_exceeded_ttl_exceeded_in_transit,
+ 0);
+ next0 = IP6_INPUT_NEXT_ICMP_ERROR;
+ }
+ else
+ {
+ next0 = IP6_INPUT_NEXT_DROP;
+ }
+ }
p0->error = error_node->errors[error0];
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
@@ -260,12 +293,13 @@ ip6_input (vlib_main_t * vm,
return frame->n_vectors;
}
-static char * ip6_error_strings[] = {
+static char *ip6_error_strings[] = {
#define _(sym,string) string,
foreach_ip6_error
#undef _
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_input_node) = {
.function = ip6_input,
.name = "ip6-input",
@@ -284,20 +318,17 @@ VLIB_REGISTER_NODE (ip6_input_node) = {
.format_buffer = format_ip6_header,
.format_trace = format_ip6_input_trace,
};
+/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (ip6_input_node, ip6_input)
-
-static clib_error_t * ip6_init (vlib_main_t * vm)
+ static clib_error_t *ip6_init (vlib_main_t * vm)
{
- ethernet_register_input_type (vm, ETHERNET_TYPE_IP6,
- ip6_input_node.index);
- ppp_register_input_protocol (vm, PPP_PROTOCOL_ip6,
- ip6_input_node.index);
- hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip6,
- ip6_input_node.index);
+ ethernet_register_input_type (vm, ETHERNET_TYPE_IP6, ip6_input_node.index);
+ ppp_register_input_protocol (vm, PPP_PROTOCOL_ip6, ip6_input_node.index);
+ hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip6, ip6_input_node.index);
{
- pg_node_t * pn;
+ pg_node_t *pn;
pn = pg_get_node (ip6_input_node.index);
pn->unformat_edit = unformat_pg_ip6_header;
}
@@ -312,3 +343,11 @@ static clib_error_t * ip6_init (vlib_main_t * vm)
}
VLIB_INIT_FUNCTION (ip6_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_neighbor.c b/vnet/vnet/ip/ip6_neighbor.c
index 15b3f764622..432e09bb2e1 100644
--- a/vnet/vnet/ip/ip6_neighbor.c
+++ b/vnet/vnet/ip/ip6_neighbor.c
@@ -36,7 +36,8 @@
#define ETHER_MAC_ADDR_LEN 6
/* advertised prefix option */
-typedef struct {
+typedef struct
+{
/* basic advertised information */
ip6_address_t prefix;
u8 prefix_len;
@@ -47,12 +48,12 @@ typedef struct {
/* advertised values are computed from these times if decrementing */
f64 valid_lifetime_expires;
- f64 pref_lifetime_expires;
-
+ f64 pref_lifetime_expires;
+
/* local information */
int enabled;
int deprecated_prefix_flag;
- int decrement_lifetime_flag;
+ int decrement_lifetime_flag;
#define MIN_ADV_VALID_LIFETIME 7203 /* seconds */
#define DEF_ADV_VALID_LIFETIME 2592000
@@ -62,7 +63,8 @@ typedef struct {
} ip6_radv_prefix_t;
-typedef struct {
+typedef struct
+{
/* group information */
u8 type;
ip6_address_t mcast_address;
@@ -71,31 +73,32 @@ typedef struct {
} ip6_mldp_group_t;
/* configured router advertisement information per ipv6 interface */
-typedef struct {
+typedef struct
+{
/* advertised config information, zero means unspecified */
- u8 curr_hop_limit;
+ u8 curr_hop_limit;
int adv_managed_flag;
int adv_other_flag;
- u16 adv_router_lifetime_in_sec;
+ u16 adv_router_lifetime_in_sec;
u32 adv_neighbor_reachable_time_in_msec;
u32 adv_time_in_msec_between_retransmitted_neighbor_solicitations;
/* mtu option */
u32 adv_link_mtu;
-
+
/* source link layer option */
- u8 link_layer_address[8];
- u8 link_layer_addr_len;
+ u8 link_layer_address[8];
+ u8 link_layer_addr_len;
/* prefix option */
- ip6_radv_prefix_t * adv_prefixes_pool;
+ ip6_radv_prefix_t *adv_prefixes_pool;
/* Hash table mapping address to index in interface advertised prefix pool. */
mhash_t address_to_prefix_index;
/* MLDP group information */
- ip6_mldp_group_t * mldp_group_pool;
+ ip6_mldp_group_t *mldp_group_pool;
/* Hash table mapping address to index in mldp address pool. */
mhash_t address_to_mldp_index;
@@ -103,8 +106,8 @@ typedef struct {
/* local information */
u32 sw_if_index;
u32 fib_index;
- int send_radv; /* radv on/off on this interface - set by config */
- int cease_radv; /* we are ceasing to send - set byf config */
+ int send_radv; /* radv on/off on this interface - set by config */
+ int cease_radv; /* we are ceasing to send - set byf config */
int send_unicast;
int adv_link_layer_address;
int prefix_option;
@@ -116,7 +119,7 @@ typedef struct {
adj_index_t all_nodes_adj_index;
adj_index_t all_routers_adj_index;
adj_index_t all_mldv2_routers_adj_index;
-
+
/* timing information */
#define DEF_MAX_RADV_INTERVAL 200
#define DEF_MIN_RADV_INTERVAL .75 * DEF_MAX_RADV_INTERVAL
@@ -124,11 +127,11 @@ typedef struct {
#define DEF_DEF_RTR_LIFETIME 3 * DEF_MAX_RADV_INTERVAL
#define MAX_DEF_RTR_LIFETIME 9000
-#define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 /* seconds */
-#define MAX_INITIAL_RTR_ADVERTISEMENTS 3 /*transmissions */
-#define MIN_DELAY_BETWEEN_RAS 3 /* seconds */
-#define MAX_DELAY_BETWEEN_RAS 1800 /* seconds */
-#define MAX_RA_DELAY_TIME .5 /* seconds */
+#define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 /* seconds */
+#define MAX_INITIAL_RTR_ADVERTISEMENTS 3 /*transmissions */
+#define MIN_DELAY_BETWEEN_RAS 3 /* seconds */
+#define MAX_DELAY_BETWEEN_RAS 1800 /* seconds */
+#define MAX_RA_DELAY_TIME .5 /* seconds */
f64 max_radv_interval;
f64 min_radv_interval;
@@ -142,7 +145,7 @@ typedef struct {
u32 initial_adverts_count;
- f64 initial_adverts_interval;
+ f64 initial_adverts_interval;
u32 initial_adverts_sent;
/* stats */
@@ -156,38 +159,40 @@ typedef struct {
} ip6_radv_t;
-typedef struct {
+typedef struct
+{
u32 next_index;
uword node_index;
uword type_opaque;
uword data;
/* Used for nd event notification only */
- void * data_callback;
+ void *data_callback;
u32 pid;
} pending_resolution_t;
-typedef struct {
+typedef struct
+{
/* Hash tables mapping name to opcode. */
- uword * opcode_by_name;
+ uword *opcode_by_name;
/* lite beer "glean" adjacency handling */
mhash_t pending_resolutions_by_address;
- pending_resolution_t * pending_resolutions;
+ pending_resolution_t *pending_resolutions;
/* Mac address change notification */
mhash_t mac_changes_by_address;
- pending_resolution_t * mac_changes;
+ pending_resolution_t *mac_changes;
- u32 * neighbor_input_next_index_by_hw_if_index;
+ u32 *neighbor_input_next_index_by_hw_if_index;
- ip6_neighbor_t * neighbor_pool;
+ ip6_neighbor_t *neighbor_pool;
mhash_t neighbor_index_by_key;
- u32 * if_radv_pool_index_by_sw_if_index;
+ u32 *if_radv_pool_index_by_sw_if_index;
- ip6_radv_t * if_radv_pool;
+ ip6_radv_t *if_radv_pool;
/* Neighbor attack mitigation */
u32 limit_neighbor_cache_size;
@@ -196,59 +201,63 @@ typedef struct {
} ip6_neighbor_main_t;
static ip6_neighbor_main_t ip6_neighbor_main;
-static ip6_address_t ip6a_zero; /* ip6 address 0 */
+static ip6_address_t ip6a_zero; /* ip6 address 0 */
-static u8 * format_ip6_neighbor_ip6_entry (u8 * s, va_list * va)
+static u8 *
+format_ip6_neighbor_ip6_entry (u8 * s, va_list * va)
{
- vlib_main_t * vm = va_arg (*va, vlib_main_t *);
- ip6_neighbor_t * n = va_arg (*va, ip6_neighbor_t *);
- vnet_main_t * vnm = vnet_get_main();
- vnet_sw_interface_t * si;
- u8 * flags = 0;
+ vlib_main_t *vm = va_arg (*va, vlib_main_t *);
+ ip6_neighbor_t *n = va_arg (*va, ip6_neighbor_t *);
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_sw_interface_t *si;
+ u8 *flags = 0;
- if (! n)
- return format (s, "%=12s%=20s%=6s%=20s%=40s", "Time", "Address", "Flags", "Link layer", "Interface");
+ if (!n)
+ return format (s, "%=12s%=20s%=6s%=20s%=40s", "Time", "Address", "Flags",
+ "Link layer", "Interface");
if (n->flags & IP6_NEIGHBOR_FLAG_DYNAMIC)
- flags = format(flags, "D");
+ flags = format (flags, "D");
if (n->flags & IP6_NEIGHBOR_FLAG_STATIC)
- flags = format(flags, "S");
+ flags = format (flags, "S");
si = vnet_get_sw_interface (vnm, n->key.sw_if_index);
s = format (s, "%=12U%=20U%=6s%=20U%=40U",
format_vlib_cpu_time, vm, n->cpu_time_last_updated,
format_ip6_address, &n->key.ip6_address,
- flags ? (char *)flags : "",
+ flags ? (char *) flags : "",
format_ethernet_address, n->link_layer_address,
format_vnet_sw_interface_name, vnm, si);
- vec_free(flags);
+ vec_free (flags);
return s;
}
static clib_error_t *
ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 flags)
+ u32 sw_if_index, u32 flags)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_neighbor_t * n;
-
- if (! (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_neighbor_t *n;
+
+ if (!(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
{
- u32 i, * to_delete = 0;
+ u32 i, *to_delete = 0;
- pool_foreach (n, nm->neighbor_pool, ({
+ /* *INDENT-OFF* */
+ pool_foreach (n, nm->neighbor_pool,
+ ({
if (n->key.sw_if_index == sw_if_index)
vec_add1 (to_delete, n - nm->neighbor_pool);
}));
+ /* *INDENT-ON* */
for (i = 0; i < vec_len (to_delete); i++)
{
n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]);
mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
- fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
+ fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
pool_put (nm->neighbor_pool, n);
}
@@ -260,12 +269,13 @@ ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm,
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_neighbor_sw_interface_up_down);
-static void unset_random_neighbor_entry (void)
+static void
+unset_random_neighbor_entry (void)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- vnet_main_t * vnm = vnet_get_main();
- vlib_main_t * vm = vnm->vlib_main;
- ip6_neighbor_t * e;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ vlib_main_t *vm = vnm->vlib_main;
+ ip6_neighbor_t *e;
u32 index;
index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
@@ -283,14 +293,15 @@ static void unset_random_neighbor_entry (void)
return;
e = pool_elt_at_index (nm->neighbor_pool, index);
-
+
vnet_unset_ip6_ethernet_neighbor (vm, e->key.sw_if_index,
- &e->key.ip6_address,
- e->link_layer_address,
- ETHER_MAC_ADDR_LEN);
+ &e->key.ip6_address,
+ e->link_layer_address,
+ ETHER_MAC_ADDR_LEN);
}
-typedef struct {
+typedef struct
+{
u8 is_add;
u8 is_static;
u8 link_layer_address[6];
@@ -298,66 +309,64 @@ typedef struct {
ip6_address_t addr;
} ip6_neighbor_set_unset_rpc_args_t;
-static void ip6_neighbor_set_unset_rpc_callback
-( ip6_neighbor_set_unset_rpc_args_t * a);
+static void ip6_neighbor_set_unset_rpc_callback
+ (ip6_neighbor_set_unset_rpc_args_t * a);
-static void set_unset_ip6_neighbor_rpc
-(vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t * a,
- u8 *link_layer_addreess,
- int is_add, int is_static)
+static void set_unset_ip6_neighbor_rpc
+ (vlib_main_t * vm,
+ u32 sw_if_index,
+ ip6_address_t * a, u8 * link_layer_addreess, int is_add, int is_static)
{
ip6_neighbor_set_unset_rpc_args_t args;
void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
-
+
args.sw_if_index = sw_if_index;
args.is_add = is_add;
args.is_static = is_static;
clib_memcpy (&args.addr, a, sizeof (*a));
clib_memcpy (args.link_layer_address, link_layer_addreess, 6);
-
+
vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback,
- (u8 *) &args, sizeof (args));
+ (u8 *) & args, sizeof (args));
}
static void
-ip6_nbr_probe (ip_adjacency_t *adj)
-{
- icmp6_neighbor_solicitation_header_t * h;
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
- ip_interface_address_t * ia;
- ip6_address_t * dst, *src;
- vnet_hw_interface_t * hi;
- vnet_sw_interface_t * si;
- vlib_buffer_t * b;
+ip6_nbr_probe (ip_adjacency_t * adj)
+{
+ icmp6_neighbor_solicitation_header_t *h;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
+ ip_interface_address_t *ia;
+ ip6_address_t *dst, *src;
+ vnet_hw_interface_t *hi;
+ vnet_sw_interface_t *si;
+ vlib_buffer_t *b;
int bogus_length;
- vlib_main_t * vm;
+ vlib_main_t *vm;
u32 bi = 0;
- vm = vlib_get_main();
+ vm = vlib_get_main ();
- si = vnet_get_sw_interface(vnm, adj->rewrite_header.sw_if_index);
+ si = vnet_get_sw_interface (vnm, adj->rewrite_header.sw_if_index);
dst = &adj->sub_type.nbr.next_hop.ip6;
if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
{
return;
}
- src = ip6_interface_address_matching_destination(im, dst,
- adj->rewrite_header.sw_if_index,
- &ia);
- if (! src)
+ src = ip6_interface_address_matching_destination (im, dst,
+ adj->rewrite_header.
+ sw_if_index, &ia);
+ if (!src)
{
return;
}
- h = vlib_packet_template_get_packet(vm,
- &im->discover_neighbor_packet_template,
- &bi);
+ h = vlib_packet_template_get_packet (vm,
+ &im->discover_neighbor_packet_template,
+ &bi);
- hi = vnet_get_sup_hw_interface(vnm, adj->rewrite_header.sw_if_index);
+ hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
h->ip.dst_address.as_u8[13] = dst->as_u8[13];
h->ip.dst_address.as_u8[14] = dst->as_u8[14];
@@ -366,28 +375,26 @@ ip6_nbr_probe (ip_adjacency_t *adj)
h->neighbor.target_address = dst[0];
clib_memcpy (h->link_layer_option.ethernet_address,
- hi->hw_address,
- vec_len(hi->hw_address));
+ hi->hw_address, vec_len (hi->hw_address));
h->neighbor.icmp.checksum =
- ip6_tcp_udp_icmp_compute_checksum(vm, 0, &h->ip, &bogus_length);
- ASSERT(bogus_length == 0);
+ ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
+ ASSERT (bogus_length == 0);
b = vlib_get_buffer (vm, bi);
vnet_buffer (b)->sw_if_index[VLIB_RX] =
- vnet_buffer (b)->sw_if_index[VLIB_TX] =
- adj->rewrite_header.sw_if_index;
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index;
/* Add encapsulation string for software interface (e.g. ethernet header). */
- vnet_rewrite_one_header(adj[0], h, sizeof (ethernet_header_t));
- vlib_buffer_advance(b, -adj->rewrite_header.data_bytes);
+ vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
+ vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
{
- vlib_frame_t * f = vlib_get_frame_to_node(vm, hi->output_node_index);
- u32 * to_next = vlib_frame_vector_args(f);
- to_next[0] = bi;
- f->n_vectors = 1;
- vlib_put_frame_to_node(vm, hi->output_node_index, f);
+ vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
+ u32 *to_next = vlib_frame_vector_args (f);
+ to_next[0] = bi;
+ f->n_vectors = 1;
+ vlib_put_frame_to_node (vm, hi->output_node_index, f);
}
}
@@ -397,22 +404,22 @@ ip6_nd_mk_complete (adj_index_t ai, ip6_neighbor_t * nbr)
adj_nbr_update_rewrite (ai, ADJ_NBR_REWRITE_FLAG_COMPLETE,
ethernet_build_rewrite (vnet_get_main (),
nbr->key.sw_if_index,
- adj_get_link_type(ai),
+ adj_get_link_type (ai),
nbr->link_layer_address));
}
static void
ip6_nd_mk_incomplete (adj_index_t ai)
{
- ip_adjacency_t *adj = adj_get(ai);
+ ip_adjacency_t *adj = adj_get (ai);
- adj_nbr_update_rewrite (
- ai,
- ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
- ethernet_build_rewrite (vnet_get_main (),
- adj->rewrite_header.sw_if_index,
- adj_get_link_type(ai),
- VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
+ adj_nbr_update_rewrite (ai,
+ ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
+ ethernet_build_rewrite (vnet_get_main (),
+ adj->rewrite_header.
+ sw_if_index,
+ adj_get_link_type (ai),
+ VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
}
#define IP6_NBR_MK_KEY(k, sw_if_index, addr) \
@@ -423,20 +430,20 @@ ip6_nd_mk_incomplete (adj_index_t ai)
}
static ip6_neighbor_t *
-ip6_nd_find (u32 sw_if_index,
- const ip6_address_t * addr)
+ip6_nd_find (u32 sw_if_index, const ip6_address_t * addr)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_neighbor_t * n = NULL;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_neighbor_t *n = NULL;
ip6_neighbor_key_t k;
uword *p;
- IP6_NBR_MK_KEY(k, sw_if_index, addr);
+ IP6_NBR_MK_KEY (k, sw_if_index, addr);
p = mhash_get (&nm->neighbor_index_by_key, &k);
- if (p) {
- n = pool_elt_at_index (nm->neighbor_pool, p[0]);
- }
+ if (p)
+ {
+ n = pool_elt_at_index (nm->neighbor_pool, p[0]);
+ }
return (n);
}
@@ -460,9 +467,7 @@ ip6_nd_mk_incomplete_walk (adj_index_t ai, void *ctx)
}
void
-ip6_ethernet_update_adjacency (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 ai)
+ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai)
{
ip6_neighbor_t *nbr;
ip_adjacency_t *adj;
@@ -503,24 +508,24 @@ ip6_ethernet_update_adjacency (vnet_main_t * vnm,
int
vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t * a,
- u8 * link_layer_address,
- uword n_bytes_link_layer_address,
- int is_static)
+ u32 sw_if_index,
+ ip6_address_t * a,
+ u8 * link_layer_address,
+ uword n_bytes_link_layer_address,
+ int is_static)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
ip6_neighbor_key_t k;
- ip6_neighbor_t * n = 0;
- int make_new_nd_cache_entry=1;
- uword * p;
+ ip6_neighbor_t *n = 0;
+ int make_new_nd_cache_entry = 1;
+ uword *p;
u32 next_index;
- pending_resolution_t * pr, * mc;
+ pending_resolution_t *pr, *mc;
- if (os_get_cpu_number())
+ if (os_get_cpu_number ())
{
set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
- 1 /* set new neighbor */, is_static);
+ 1 /* set new neighbor */ , is_static);
return 0;
}
@@ -529,66 +534,55 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
k.pad = 0;
p = mhash_get (&nm->neighbor_index_by_key, &k);
- if (p) {
- n = pool_elt_at_index (nm->neighbor_pool, p[0]);
- /* Refuse to over-write static neighbor entry. */
- if (!is_static &&
- (n->flags & IP6_NEIGHBOR_FLAG_STATIC))
- return -2;
- make_new_nd_cache_entry = 0;
- }
+ if (p)
+ {
+ n = pool_elt_at_index (nm->neighbor_pool, p[0]);
+ /* Refuse to over-write static neighbor entry. */
+ if (!is_static && (n->flags & IP6_NEIGHBOR_FLAG_STATIC))
+ return -2;
+ make_new_nd_cache_entry = 0;
+ }
- if (make_new_nd_cache_entry) {
+ if (make_new_nd_cache_entry)
+ {
fib_prefix_t pfx = {
- .fp_len = 128,
- .fp_proto = FIB_PROTOCOL_IP6,
- .fp_addr = {
- .ip6 = k.ip6_address,
- },
+ .fp_len = 128,
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_addr = {
+ .ip6 = k.ip6_address,
+ }
+ ,
};
u32 fib_index;
- pool_get (nm->neighbor_pool, n);
- mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
- /* old value */ 0);
- n->key = k;
-
- clib_memcpy (n->link_layer_address,
- link_layer_address,
- n_bytes_link_layer_address);
-
- /*
- * create the adj-fib. the entry in the FIB table for and to the peer.
- */
- fib_index = ip6_main.fib_index_by_sw_if_index[n->key.sw_if_index];
- n->fib_entry_index =
- fib_table_entry_update_one_path(fib_index,
- &pfx,
- FIB_SOURCE_ADJ,
- FIB_ENTRY_FLAG_NONE,
- FIB_PROTOCOL_IP6,
- &pfx.fp_addr,
- n->key.sw_if_index,
- ~0,
- 1,
- NULL, // no label stack
- FIB_ROUTE_PATH_FLAG_NONE);
- }
+ pool_get (nm->neighbor_pool, n);
+ mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
+ /* old value */ 0);
+ n->key = k;
+
+ clib_memcpy (n->link_layer_address,
+ link_layer_address, n_bytes_link_layer_address);
+
+ /*
+ * create the adj-fib. the entry in the FIB table for and to the peer.
+ */
+ fib_index = ip6_main.fib_index_by_sw_if_index[n->key.sw_if_index];
+ n->fib_entry_index = fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_ADJ, FIB_ENTRY_FLAG_NONE, FIB_PROTOCOL_IP6, &pfx.fp_addr, n->key.sw_if_index, ~0, 1, NULL, // no label stack
+ FIB_ROUTE_PATH_FLAG_NONE);
+ }
else
- {
- /*
- * prevent a DoS attack from the data-plane that
- * spams us with no-op updates to the MAC address
- */
- if (0 == memcmp(n->link_layer_address,
- link_layer_address,
- n_bytes_link_layer_address))
- return -1;
-
- clib_memcpy (n->link_layer_address,
- link_layer_address,
- n_bytes_link_layer_address);
- }
+ {
+ /*
+ * prevent a DoS attack from the data-plane that
+ * spams us with no-op updates to the MAC address
+ */
+ if (0 == memcmp (n->link_layer_address,
+ link_layer_address, n_bytes_link_layer_address))
+ return -1;
+
+ clib_memcpy (n->link_layer_address,
+ link_layer_address, n_bytes_link_layer_address);
+ }
/* Update time stamp and flags. */
n->cpu_time_last_updated = clib_cpu_time_now ();
@@ -598,24 +592,22 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
n->flags |= IP6_NEIGHBOR_FLAG_DYNAMIC;
adj_nbr_walk_nh6 (sw_if_index,
- &n->key.ip6_address,
- ip6_nd_mk_complete_walk, n);
+ &n->key.ip6_address, ip6_nd_mk_complete_walk, n);
/* Customer(s) waiting for this address to be resolved? */
p = mhash_get (&nm->pending_resolutions_by_address, a);
if (p)
{
next_index = p[0];
-
- while (next_index != (u32)~0)
- {
+
+ while (next_index != (u32) ~ 0)
+ {
pr = pool_elt_at_index (nm->pending_resolutions, next_index);
vlib_process_signal_event (vm, pr->node_index,
- pr->type_opaque,
- pr->data);
+ pr->type_opaque, pr->data);
next_index = pr->next_index;
pool_put (nm->pending_resolutions, pr);
- }
+ }
mhash_unset (&nm->pending_resolutions_by_address, a, 0);
}
@@ -626,26 +618,26 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
{
next_index = p[0];
- while (next_index != (u32)~0)
- {
- int (*fp)(u32, u8 *, u32, ip6_address_t *);
- int rv = 1;
- mc = pool_elt_at_index (nm->mac_changes, next_index);
- fp = mc->data_callback;
-
- /* Call the user's data callback, return 1 to suppress dup events */
- if (fp)
- rv = (*fp)(mc->data, link_layer_address, sw_if_index, &ip6a_zero);
- /*
- * Signal the resolver process, as long as the user
- * says they want to be notified
- */
- if (rv == 0)
- vlib_process_signal_event (vm, mc->node_index,
- mc->type_opaque,
- mc->data);
- next_index = mc->next_index;
- }
+ while (next_index != (u32) ~ 0)
+ {
+ int (*fp) (u32, u8 *, u32, ip6_address_t *);
+ int rv = 1;
+ mc = pool_elt_at_index (nm->mac_changes, next_index);
+ fp = mc->data_callback;
+
+ /* Call the user's data callback, return 1 to suppress dup events */
+ if (fp)
+ rv =
+ (*fp) (mc->data, link_layer_address, sw_if_index, &ip6a_zero);
+ /*
+ * Signal the resolver process, as long as the user
+ * says they want to be notified
+ */
+ if (rv == 0)
+ vlib_process_signal_event (vm, mc->node_index,
+ mc->type_opaque, mc->data);
+ next_index = mc->next_index;
+ }
}
return 0;
@@ -653,71 +645,69 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
int
vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t * a,
- u8 * link_layer_address,
- uword n_bytes_link_layer_address)
+ u32 sw_if_index,
+ ip6_address_t * a,
+ u8 * link_layer_address,
+ uword n_bytes_link_layer_address)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
ip6_neighbor_key_t k;
- ip6_neighbor_t * n;
- uword * p;
+ ip6_neighbor_t *n;
+ uword *p;
int rv = 0;
- if (os_get_cpu_number())
+ if (os_get_cpu_number ())
{
set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
- 0 /* unset */, 0);
+ 0 /* unset */ , 0);
return 0;
}
k.sw_if_index = sw_if_index;
k.ip6_address = a[0];
k.pad = 0;
-
+
p = mhash_get (&nm->neighbor_index_by_key, &k);
if (p == 0)
{
rv = -1;
goto out;
}
-
+
n = pool_elt_at_index (nm->neighbor_pool, p[0]);
mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
adj_nbr_walk_nh6 (sw_if_index,
- &n->key.ip6_address,
- ip6_nd_mk_incomplete_walk,
- NULL);
+ &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL);
- fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
+ fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
pool_put (nm->neighbor_pool, n);
-
- out:
+
+out:
return rv;
}
-static void ip6_neighbor_set_unset_rpc_callback
-( ip6_neighbor_set_unset_rpc_args_t * a)
+static void ip6_neighbor_set_unset_rpc_callback
+ (ip6_neighbor_set_unset_rpc_args_t * a)
{
- vlib_main_t * vm = vlib_get_main();
- if (a->is_add)
- vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
- a->link_layer_address, 6, a->is_static);
+ vlib_main_t *vm = vlib_get_main ();
+ if (a->is_add)
+ vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
+ a->link_layer_address, 6, a->is_static);
else
- vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
- a->link_layer_address, 6);
+ vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
+ a->link_layer_address, 6);
}
static int
ip6_neighbor_sort (void *a1, void *a2)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_t * n1 = a1, * n2 = a2;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_t *n1 = a1, *n2 = a2;
int cmp;
- cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index,
- n2->key.sw_if_index);
- if (! cmp)
+ cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index,
+ n2->key.sw_if_index);
+ if (!cmp)
cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address);
return cmp;
}
@@ -725,11 +715,12 @@ ip6_neighbor_sort (void *a1, void *a2)
ip6_neighbor_t *
ip6_neighbors_entries (u32 sw_if_index)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
ip6_neighbor_t *n, *ns = 0;
/* *INDENT-OFF* */
- pool_foreach (n, nm->neighbor_pool, ({
+ pool_foreach (n, nm->neighbor_pool,
+ ({
if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index)
continue;
vec_add1 (ns, n[0]);
@@ -743,12 +734,11 @@ ip6_neighbors_entries (u32 sw_if_index)
static clib_error_t *
show_ip6_neighbors (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_t * n, * ns;
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_t *n, *ns;
+ clib_error_t *error = 0;
u32 sw_if_index;
/* Filter entries by interface if given. */
@@ -759,8 +749,9 @@ show_ip6_neighbors (vlib_main_t * vm,
if (ns)
{
vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0);
- vec_foreach (n, ns) {
- vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n);
+ vec_foreach (n, ns)
+ {
+ vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n);
}
vec_free (ns);
}
@@ -798,10 +789,9 @@ VLIB_CLI_COMMAND (show_ip6_neighbors_command, static) = {
static clib_error_t *
set_ip6_neighbor (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
+ vnet_main_t *vnm = vnet_get_main ();
ip6_address_t addr;
u8 mac_address[6];
int addr_valid = 0;
@@ -809,32 +799,33 @@ set_ip6_neighbor (vlib_main_t * vm,
int is_static = 0;
u32 sw_if_index;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
/* intfc, ip6-address, mac-address */
if (unformat (input, "%U %U %U",
- unformat_vnet_sw_interface, vnm, &sw_if_index,
- unformat_ip6_address, &addr,
- unformat_ethernet_address, mac_address))
- addr_valid = 1;
+ unformat_vnet_sw_interface, vnm, &sw_if_index,
+ unformat_ip6_address, &addr,
+ unformat_ethernet_address, mac_address))
+ addr_valid = 1;
else if (unformat (input, "delete") || unformat (input, "del"))
- is_del = 1;
+ is_del = 1;
else if (unformat (input, "static"))
- is_static = 1;
+ is_static = 1;
else
- break;
+ break;
}
if (!addr_valid)
return clib_error_return (0, "Missing interface, ip6 or hw address");
-
+
if (!is_del)
vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
- mac_address, sizeof(mac_address), is_static);
+ mac_address, sizeof (mac_address),
+ is_static);
else
vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
- mac_address, sizeof(mac_address));
+ mac_address, sizeof (mac_address));
return 0;
}
@@ -851,14 +842,16 @@ set_ip6_neighbor (vlib_main_t * vm,
* @cliexcmd{set ip6 neighbor del GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) = {
+VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) =
+{
.path = "set ip6 neighbor",
.function = set_ip6_neighbor,
.short_help = "set ip6 neighbor [del] <interface> <ip6-address> <mac-address> [static]",
};
/* *INDENT-ON* */
-typedef enum {
+typedef enum
+{
ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP,
ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY,
ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
@@ -870,25 +863,26 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
vlib_frame_t * frame,
uword is_solicitation)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
uword n_packets = frame->n_vectors;
- u32 * from, * to_next;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent;
icmp6_neighbor_discovery_option_type_t option_type;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
int bogus_length;
from = vlib_frame_vector_args (frame);
n_left_from = n_packets;
next_index = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
sizeof (icmp6_input_trace_t));
- option_type =
+ option_type =
(is_solicitation
? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address
: ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address);
@@ -900,139 +894,153 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
- icmp6_neighbor_solicitation_or_advertisement_header_t * h0;
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t * o0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
+ icmp6_neighbor_solicitation_or_advertisement_header_t *h0;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
u32 bi0, options_len0, sw_if_index0, next0, error0;
- u32 ip6_sadd_link_local, ip6_sadd_unspecified;
- int is_rewrite0;
- u32 ni0;
-
+ u32 ip6_sadd_link_local, ip6_sadd_unspecified;
+ int is_rewrite0;
+ u32 ni0;
+
bi0 = to_next[0] = from[0];
from += 1;
to_next += 1;
n_left_from -= 1;
n_left_to_next -= 1;
-
+
p0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (p0);
h0 = ip6_next_header (ip0);
- options_len0 = clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
+ options_len0 =
+ clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
error0 = ICMP6_ERROR_NONE;
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
- ip6_sadd_link_local = ip6_address_is_link_local_unicast(&ip0->src_address);
- ip6_sadd_unspecified = ip6_address_is_unspecified (&ip0->src_address);
+ ip6_sadd_link_local =
+ ip6_address_is_link_local_unicast (&ip0->src_address);
+ ip6_sadd_unspecified =
+ ip6_address_is_unspecified (&ip0->src_address);
/* Check that source address is unspecified, link-local or else on-link. */
if (!ip6_sadd_unspecified && !ip6_sadd_link_local)
{
u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
- if (ADJ_INDEX_INVALID != src_adj_index0)
- {
- ip_adjacency_t * adj0 = ip_get_adjacency (&im->lookup_main, src_adj_index0);
-
- /* Allow all realistic-looking rewrite adjacencies to pass */
- ni0 = adj0->lookup_next_index;
- is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) &&
- (ni0 < IP6_LOOKUP_N_NEXT);
-
- error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
- || ! is_rewrite0)
- ? ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK
- : error0);
- }
- else
- {
- error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK;
- }
- }
-
+ if (ADJ_INDEX_INVALID != src_adj_index0)
+ {
+ ip_adjacency_t *adj0 =
+ ip_get_adjacency (&im->lookup_main, src_adj_index0);
+
+ /* Allow all realistic-looking rewrite adjacencies to pass */
+ ni0 = adj0->lookup_next_index;
+ is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) &&
+ (ni0 < IP6_LOOKUP_N_NEXT);
+
+ error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
+ || !is_rewrite0)
+ ?
+ ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK
+ : error0);
+ }
+ else
+ {
+ error0 =
+ ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK;
+ }
+ }
+
o0 = (void *) (h0 + 1);
o0 = ((options_len0 == 8 && o0->header.type == option_type
&& o0->header.n_data_u64s == 1) ? o0 : 0);
/* If src address unspecified or link local, donot learn neighbor MAC */
- if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
- !ip6_sadd_unspecified && !ip6_sadd_link_local))
- {
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- if (nm->limit_neighbor_cache_size &&
- pool_elts (nm->neighbor_pool) >= nm->limit_neighbor_cache_size)
- unset_random_neighbor_entry();
- vnet_set_ip6_ethernet_neighbor (
- vm, sw_if_index0,
- is_solicitation ? &ip0->src_address : &h0->target_address,
- o0->ethernet_address, sizeof (o0->ethernet_address), 0);
- }
+ if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
+ !ip6_sadd_unspecified && !ip6_sadd_link_local))
+ {
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ if (nm->limit_neighbor_cache_size &&
+ pool_elts (nm->neighbor_pool) >=
+ nm->limit_neighbor_cache_size)
+ unset_random_neighbor_entry ();
+ vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
+ is_solicitation ?
+ &ip0->src_address :
+ &h0->target_address,
+ o0->ethernet_address,
+ sizeof (o0->ethernet_address),
+ 0);
+ }
if (is_solicitation && error0 == ICMP6_ERROR_NONE)
{
/* Check that target address is local to this router. */
- fib_node_index_t fei;
+ fib_node_index_t fei;
u32 fib_index;
- fib_index = ip6_fib_table_get_index_for_sw_if_index(sw_if_index0);
+ fib_index =
+ ip6_fib_table_get_index_for_sw_if_index (sw_if_index0);
if (~0 == fib_index)
- {
+ {
error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
}
else
- {
- fei = ip6_fib_table_lookup_exact_match(fib_index,
- &h0->target_address,
- 128);
+ {
+ fei = ip6_fib_table_lookup_exact_match (fib_index,
+ &h0->target_address,
+ 128);
- if (FIB_NODE_INDEX_INVALID == fei ||
+ if (FIB_NODE_INDEX_INVALID == fei ||
!(FIB_ENTRY_FLAG_LOCAL &
- fib_entry_get_flags_for_source(fei, FIB_SOURCE_INTERFACE)))
+ fib_entry_get_flags_for_source (fei,
+ FIB_SOURCE_INTERFACE)))
{
- error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
+ error0 =
+ ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
}
}
}
if (is_solicitation)
- next0 = (error0 != ICMP6_ERROR_NONE
- ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
- : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
+ next0 = (error0 != ICMP6_ERROR_NONE
+ ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
+ : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
else
{
- next0 = 0;
- error0 = error0 == ICMP6_ERROR_NONE ?
- ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
+ next0 = 0;
+ error0 = error0 == ICMP6_ERROR_NONE ?
+ ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
}
if (is_solicitation && error0 == ICMP6_ERROR_NONE)
{
- vnet_sw_interface_t * sw_if0;
- ethernet_interface_t * eth_if0;
- ethernet_header_t *eth0;
+ vnet_sw_interface_t *sw_if0;
+ ethernet_interface_t *eth_if0;
+ ethernet_header_t *eth0;
- /* dst address is either source address or the all-nodes mcast addr */
- if(!ip6_sadd_unspecified)
- ip0->dst_address = ip0->src_address;
+ /* dst address is either source address or the all-nodes mcast addr */
+ if (!ip6_sadd_unspecified)
+ ip0->dst_address = ip0->src_address;
else
- ip6_set_reserved_multicast_address(&ip0->dst_address,
- IP6_MULTICAST_SCOPE_link_local,
- IP6_MULTICAST_GROUP_ID_all_hosts);
+ ip6_set_reserved_multicast_address (&ip0->dst_address,
+ IP6_MULTICAST_SCOPE_link_local,
+ IP6_MULTICAST_GROUP_ID_all_hosts);
ip0->src_address = h0->target_address;
- ip0->hop_limit = 255;
+ ip0->hop_limit = 255;
h0->icmp.type = ICMP6_neighbor_advertisement;
sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
- eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
+ eth_if0 =
+ ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
if (eth_if0 && o0)
{
- clib_memcpy (o0->ethernet_address, eth_if0->address, 6);
- o0->header.type =
- ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
+ clib_memcpy (o0->ethernet_address, eth_if0->address, 6);
+ o0->header.type =
+ ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
}
h0->advertisement_flags = clib_host_to_net_u32
@@ -1040,27 +1048,27 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
| ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
h0->icmp.checksum = 0;
- h0->icmp.checksum =
- ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
- &bogus_length);
- ASSERT(bogus_length == 0);
-
- /* Reuse current MAC header, copy SMAC to DMAC and
- * interface MAC to SMAC */
- vlib_buffer_advance(p0, - ethernet_buffer_header_size(p0));
- eth0 = vlib_buffer_get_current(p0);
- clib_memcpy(eth0->dst_address, eth0->src_address, 6);
- if (eth_if0)
- clib_memcpy(eth0->src_address, eth_if0->address, 6);
-
- /* Setup input and output sw_if_index for packet */
- ASSERT(vnet_buffer(p0)->sw_if_index[VLIB_RX] == sw_if_index0);
- vnet_buffer(p0)->sw_if_index[VLIB_TX] = sw_if_index0;
- vnet_buffer(p0)->sw_if_index[VLIB_RX] =
- vnet_main.local_interface_sw_if_index;
+ h0->icmp.checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
+ &bogus_length);
+ ASSERT (bogus_length == 0);
+
+ /* Reuse current MAC header, copy SMAC to DMAC and
+ * interface MAC to SMAC */
+ vlib_buffer_advance (p0, -ethernet_buffer_header_size (p0));
+ eth0 = vlib_buffer_get_current (p0);
+ clib_memcpy (eth0->dst_address, eth0->src_address, 6);
+ if (eth_if0)
+ clib_memcpy (eth0->src_address, eth_if0->address, 6);
+
+ /* Setup input and output sw_if_index for packet */
+ ASSERT (vnet_buffer (p0)->sw_if_index[VLIB_RX] == sw_if_index0);
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
+ vnet_buffer (p0)->sw_if_index[VLIB_RX] =
+ vnet_main.local_interface_sw_if_index;
n_advertisements_sent++;
- }
+ }
p0->error = error_node->errors[error0];
@@ -1073,7 +1081,9 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
}
/* Account for advertisements sent. */
- vlib_error_count (vm, error_node->node_index, ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, n_advertisements_sent);
+ vlib_error_count (vm, error_node->node_index,
+ ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX,
+ n_advertisements_sent);
return frame->n_vectors;
}
@@ -1089,51 +1099,54 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
_ (ALERT, "ALERT") \
_ (EMERG, "EMERGENCY")
-typedef enum {
+typedef enum
+{
#define _(f,s) LOG_##f,
foreach_log_level
#undef _
} log_level_t;
-static char * log_level_strings[] = {
+static char *log_level_strings[] = {
#define _(f,s) s,
foreach_log_level
#undef _
};
-static int logmask = 1 << LOG_DEBUG;
+static int logmask = 1 << LOG_DEBUG;
static void
-ip6_neighbor_syslog(vlib_main_t *vm, int priority, char * fmt, ...)
+ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...)
{
/* just use elog for now */
u8 *what;
va_list va;
- if( (priority > LOG_EMERG) ||
- !(logmask & (1 << priority)))
- return;
+ if ((priority > LOG_EMERG) || !(logmask & (1 << priority)))
+ return;
va_start (va, fmt);
- if(fmt)
+ if (fmt)
{
what = va_format (0, fmt, &va);
- ELOG_TYPE_DECLARE (e) = {
- .format = "ip6 nd: (%s): %s",
- .format_args = "T4T4",
- };
- struct { u32 s[2]; } * ed;
+ ELOG_TYPE_DECLARE (e) =
+ {
+ .format = "ip6 nd: (%s): %s",.format_args = "T4T4",};
+ struct
+ {
+ u32 s[2];
+ } *ed;
ed = ELOG_DATA (&vm->elog_main, e);
- ed->s[0] = elog_string(&vm->elog_main, log_level_strings[priority]);
- ed->s[1] = elog_string(&vm->elog_main, (char *)what);
+ ed->s[0] = elog_string (&vm->elog_main, log_level_strings[priority]);
+ ed->s[1] = elog_string (&vm->elog_main, (char *) what);
}
va_end (va);
return;
}
/* ipv6 neighbor discovery - router advertisements */
-typedef enum {
+typedef enum
+{
ICMP6_ROUTER_SOLICITATION_NEXT_DROP,
ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW,
ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX,
@@ -1141,27 +1154,27 @@ typedef enum {
} icmp6_router_solicitation_or_advertisement_next_t;
static_always_inline uword
-icmp6_router_solicitation(vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+icmp6_router_solicitation (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_main_t * im = &ip6_main;
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_main_t *im = &ip6_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
uword n_packets = frame->n_vectors;
- u32 * from, * to_next;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next_index;
- u32 n_advertisements_sent = 0;
+ u32 n_advertisements_sent = 0;
int bogus_length;
icmp6_neighbor_discovery_option_type_t option_type;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
from = vlib_frame_vector_args (frame);
n_left_from = n_packets;
next_index = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
@@ -1173,19 +1186,19 @@ icmp6_router_solicitation(vlib_main_t * vm,
while (n_left_from > 0)
{
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
ip6_radv_t *radv_info = 0;
- icmp6_neighbor_discovery_header_t * h0;
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t * o0;
-
+ icmp6_neighbor_discovery_header_t *h0;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
+
u32 bi0, options_len0, sw_if_index0, next0, error0;
- u32 is_solicitation = 1, is_dropped = 0;
- u32 is_unspecified, is_link_local;
+ u32 is_solicitation = 1, is_dropped = 0;
+ u32 is_unspecified, is_link_local;
bi0 = to_next[0] = from[0];
@@ -1193,17 +1206,19 @@ icmp6_router_solicitation(vlib_main_t * vm,
to_next += 1;
n_left_from -= 1;
n_left_to_next -= 1;
-
+
p0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (p0);
h0 = ip6_next_header (ip0);
- options_len0 = clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
- is_unspecified = ip6_address_is_unspecified (&ip0->src_address);
- is_link_local = ip6_address_is_link_local_unicast (&ip0->src_address);
+ options_len0 =
+ clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
+ is_unspecified = ip6_address_is_unspecified (&ip0->src_address);
+ is_link_local =
+ ip6_address_is_link_local_unicast (&ip0->src_address);
error0 = ICMP6_ERROR_NONE;
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
-
+
/* check if solicitation (not from nd_timer node) */
if (ip6_address_is_unspecified (&ip0->dst_address))
is_solicitation = 0;
@@ -1213,85 +1228,97 @@ icmp6_router_solicitation(vlib_main_t * vm,
{
u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
- if (ADJ_INDEX_INVALID != src_adj_index0)
- {
- ip_adjacency_t * adj0 = ip_get_adjacency (&im->lookup_main,
- src_adj_index0);
-
- error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0
- ? ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK
- : error0);
- }
- else
- {
- error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK;
- }
- }
-
+ if (ADJ_INDEX_INVALID != src_adj_index0)
+ {
+ ip_adjacency_t *adj0 = ip_get_adjacency (&im->lookup_main,
+ src_adj_index0);
+
+ error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0
+ ?
+ ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK
+ : error0);
+ }
+ else
+ {
+ error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK;
+ }
+ }
+
/* check for source LL option and process */
o0 = (void *) (h0 + 1);
o0 = ((options_len0 == 8
&& o0->header.type == option_type
- && o0->header.n_data_u64s == 1)
- ? o0
- : 0);
-
+ && o0->header.n_data_u64s == 1) ? o0 : 0);
+
/* if src address unspecified IGNORE any options */
- if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
- !is_unspecified && !is_link_local)) {
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- if (nm->limit_neighbor_cache_size &&
- pool_elts (nm->neighbor_pool) >= nm->limit_neighbor_cache_size)
- unset_random_neighbor_entry();
-
- vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
- &ip0->src_address,
- o0->ethernet_address,
- sizeof (o0->ethernet_address), 0);
- }
-
+ if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
+ !is_unspecified && !is_link_local))
+ {
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ if (nm->limit_neighbor_cache_size &&
+ pool_elts (nm->neighbor_pool) >=
+ nm->limit_neighbor_cache_size)
+ unset_random_neighbor_entry ();
+
+ vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
+ &ip0->src_address,
+ o0->ethernet_address,
+ sizeof (o0->ethernet_address),
+ 0);
+ }
+
/* default is to drop */
next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
-
+
if (error0 == ICMP6_ERROR_NONE)
{
- vnet_sw_interface_t * sw_if0;
- ethernet_interface_t * eth_if0;
- u32 adj_index0;
+ vnet_sw_interface_t *sw_if0;
+ ethernet_interface_t *eth_if0;
+ u32 adj_index0;
sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
- eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
+ eth_if0 =
+ ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
/* only support ethernet interface type for now */
- error0 = (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF : error0;
+ error0 =
+ (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
+ : error0;
if (error0 == ICMP6_ERROR_NONE)
{
u32 ri;
/* adjust the sizeof the buffer to just include the ipv6 header */
- p0->current_length -= (options_len0 + sizeof(icmp6_neighbor_discovery_header_t));
+ p0->current_length -=
+ (options_len0 +
+ sizeof (icmp6_neighbor_discovery_header_t));
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
+ vec_validate_init_empty
+ (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
- if(ri != ~0)
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
-
- error0 = ((!radv_info) ? ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : error0);
+ if (ri != ~0)
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+
+ error0 =
+ ((!radv_info) ?
+ ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
+ error0);
if (error0 == ICMP6_ERROR_NONE)
{
f64 now = vlib_time_now (vm);
/* for solicited adverts - need to rate limit */
- if(is_solicitation)
+ if (is_solicitation)
{
- if( (now - radv_info->last_radv_time) < MIN_DELAY_BETWEEN_RAS )
- is_dropped = 1;
+ if ((now - radv_info->last_radv_time) <
+ MIN_DELAY_BETWEEN_RAS)
+ is_dropped = 1;
else
radv_info->last_radv_time = now;
}
@@ -1302,181 +1329,223 @@ icmp6_router_solicitation(vlib_main_t * vm,
rh.icmp.type = ICMP6_router_advertisement;
rh.icmp.code = 0;
rh.icmp.checksum = 0;
-
- rh.current_hop_limit = radv_info->curr_hop_limit;
- rh.router_lifetime_in_sec = clib_host_to_net_u16(radv_info->adv_router_lifetime_in_sec);
- rh.time_in_msec_between_retransmitted_neighbor_solicitations =
- clib_host_to_net_u32(radv_info->adv_time_in_msec_between_retransmitted_neighbor_solicitations);
- rh.neighbor_reachable_time_in_msec =
- clib_host_to_net_u32(radv_info->adv_neighbor_reachable_time_in_msec);
-
- rh.flags = (radv_info->adv_managed_flag) ? ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP : 0;
- rh.flags |= ( (radv_info->adv_other_flag) ? ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP : 0);
-
- u16 payload_length = sizeof(icmp6_router_advertisement_header_t);
+ rh.current_hop_limit = radv_info->curr_hop_limit;
+ rh.router_lifetime_in_sec =
+ clib_host_to_net_u16
+ (radv_info->adv_router_lifetime_in_sec);
+ rh.
+ time_in_msec_between_retransmitted_neighbor_solicitations
+ =
+ clib_host_to_net_u32 (radv_info->
+ adv_time_in_msec_between_retransmitted_neighbor_solicitations);
+ rh.neighbor_reachable_time_in_msec =
+ clib_host_to_net_u32 (radv_info->
+ adv_neighbor_reachable_time_in_msec);
+
+ rh.flags =
+ (radv_info->adv_managed_flag) ?
+ ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP :
+ 0;
+ rh.flags |=
+ ((radv_info->adv_other_flag) ?
+ ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP :
+ 0);
+
+
+ u16 payload_length =
+ sizeof (icmp6_router_advertisement_header_t);
vlib_buffer_add_data (vm,
p0->free_list_index,
bi0,
- (void *)&rh, sizeof(icmp6_router_advertisement_header_t));
+ (void *) &rh,
+ sizeof
+ (icmp6_router_advertisement_header_t));
- if(radv_info->adv_link_layer_address)
+ if (radv_info->adv_link_layer_address)
{
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t h;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
+ h;
- h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
+ h.header.type =
+ ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
h.header.n_data_u64s = 1;
/* copy ll address */
- clib_memcpy(&h.ethernet_address[0], eth_if0->address, 6);
+ clib_memcpy (&h.ethernet_address[0],
+ eth_if0->address, 6);
vlib_buffer_add_data (vm,
p0->free_list_index,
bi0,
- (void *)&h, sizeof(icmp6_neighbor_discovery_ethernet_link_layer_address_option_t));
+ (void *) &h,
+ sizeof
+ (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t));
- payload_length += sizeof(icmp6_neighbor_discovery_ethernet_link_layer_address_option_t);
+ payload_length +=
+ sizeof
+ (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t);
}
-
+
/* add MTU option */
- if(radv_info->adv_link_mtu)
+ if (radv_info->adv_link_mtu)
{
icmp6_neighbor_discovery_mtu_option_t h;
h.unused = 0;
- h.mtu = clib_host_to_net_u32(radv_info->adv_link_mtu);
+ h.mtu =
+ clib_host_to_net_u32 (radv_info->adv_link_mtu);
h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu;
h.header.n_data_u64s = 1;
-
- payload_length += sizeof( icmp6_neighbor_discovery_mtu_option_t);
+
+ payload_length +=
+ sizeof (icmp6_neighbor_discovery_mtu_option_t);
vlib_buffer_add_data (vm,
p0->free_list_index,
bi0,
- (void *)&h, sizeof(icmp6_neighbor_discovery_mtu_option_t));
+ (void *) &h,
+ sizeof
+ (icmp6_neighbor_discovery_mtu_option_t));
}
-
- /* add advertised prefix options */
- ip6_radv_prefix_t *pr_info;
-
- pool_foreach (pr_info, radv_info->adv_prefixes_pool, ({
- if(pr_info->enabled &&
- (!pr_info->decrement_lifetime_flag || (pr_info->pref_lifetime_expires >0)))
- {
- /* advertise this prefix */
- icmp6_neighbor_discovery_prefix_information_option_t h;
-
- h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information;
- h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3);
-
- h.dst_address_length = pr_info->prefix_len;
-
- h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0;
- h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0;
-
- if(radv_info->cease_radv && pr_info->deprecated_prefix_flag)
- {
- h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME);
- h.preferred_time = 0;
- }
- else
- {
- if(pr_info->decrement_lifetime_flag)
- {
- pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ?
- (pr_info->valid_lifetime_expires - now) : 0;
-
- pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ?
- (pr_info->pref_lifetime_expires - now) : 0;
- }
-
- h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs);
- h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ;
- }
- h.unused = 0;
-
- clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t));
-
- payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t);
-
- vlib_buffer_add_data (vm,
- p0->free_list_index,
- bi0,
- (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t));
-
- }
- }));
+ /* add advertised prefix options */
+ ip6_radv_prefix_t *pr_info;
+
+ /* *INDENT-OFF* */
+ pool_foreach (pr_info, radv_info->adv_prefixes_pool,
+ ({
+ if(pr_info->enabled &&
+ (!pr_info->decrement_lifetime_flag
+ || (pr_info->pref_lifetime_expires >0)))
+ {
+ /* advertise this prefix */
+ icmp6_neighbor_discovery_prefix_information_option_t h;
+
+ h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information;
+ h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3);
+
+ h.dst_address_length = pr_info->prefix_len;
+
+ h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0;
+ h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0;
+
+ if(radv_info->cease_radv && pr_info->deprecated_prefix_flag)
+ {
+ h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME);
+ h.preferred_time = 0;
+ }
+ else
+ {
+ if(pr_info->decrement_lifetime_flag)
+ {
+ pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ?
+ (pr_info->valid_lifetime_expires - now) : 0;
+
+ pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ?
+ (pr_info->pref_lifetime_expires - now) : 0;
+ }
+
+ h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs);
+ h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ;
+ }
+ h.unused = 0;
+
+ clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t));
+
+ payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t);
+
+ vlib_buffer_add_data (vm,
+ p0->free_list_index,
+ bi0,
+ (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t));
+
+ }
+ }));
+ /* *INDENT-ON* */
/* add additional options before here */
/* finish building the router advertisement... */
- if(!is_unspecified && radv_info->send_unicast)
+ if (!is_unspecified && radv_info->send_unicast)
{
ip0->dst_address = ip0->src_address;
}
else
- {
- /* target address is all-nodes mcast addr */
- ip6_set_reserved_multicast_address(&ip0->dst_address,
- IP6_MULTICAST_SCOPE_link_local,
- IP6_MULTICAST_GROUP_ID_all_hosts);
+ {
+ /* target address is all-nodes mcast addr */
+ ip6_set_reserved_multicast_address
+ (&ip0->dst_address,
+ IP6_MULTICAST_SCOPE_link_local,
+ IP6_MULTICAST_GROUP_ID_all_hosts);
}
-
+
/* source address MUST be the link-local address */
ip0->src_address = radv_info->link_local_address;
-
+
ip0->hop_limit = 255;
- ip0->payload_length = clib_host_to_net_u16 (payload_length);
-
- icmp6_router_advertisement_header_t * rh0 = (icmp6_router_advertisement_header_t *)(ip0 + 1);
- rh0->icmp.checksum =
- ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
- &bogus_length);
- ASSERT(bogus_length == 0);
-
+ ip0->payload_length =
+ clib_host_to_net_u16 (payload_length);
+
+ icmp6_router_advertisement_header_t *rh0 =
+ (icmp6_router_advertisement_header_t *) (ip0 + 1);
+ rh0->icmp.checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
+ &bogus_length);
+ ASSERT (bogus_length == 0);
+
/* setup output if and adjacency */
- vnet_buffer (p0)->sw_if_index[VLIB_RX] =
+ vnet_buffer (p0)->sw_if_index[VLIB_RX] =
vnet_main.local_interface_sw_if_index;
-
- if (is_solicitation)
- {
- ethernet_header_t *eth0;
- /* Reuse current MAC header, copy SMAC to DMAC and
- * interface MAC to SMAC */
- vlib_buffer_reset (p0);
- eth0 = vlib_buffer_get_current(p0);
- clib_memcpy(eth0->dst_address, eth0->src_address, 6);
- clib_memcpy(eth0->src_address, eth_if0->address, 6);
- next0 = is_dropped ?
- next0 : ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX;
- vnet_buffer(p0)->sw_if_index[VLIB_TX] = sw_if_index0;
- }
- else
- {
- adj_index0 = radv_info->all_nodes_adj_index;
- if (adj_index0 == 0)
- error0 = ICMP6_ERROR_DST_LOOKUP_MISS;
- else
- {
- ip_adjacency_t * adj0 = ip_get_adjacency (&im->lookup_main, adj_index0);
- error0 =
- ((adj0->rewrite_header.sw_if_index != sw_if_index0
- || adj0->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
- ? ICMP6_ERROR_ROUTER_SOLICITATION_DEST_UNKNOWN
- : error0);
- next0 = is_dropped ?
- next0 : ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW;
- vnet_buffer (p0)->ip.adj_index[VLIB_TX] = adj_index0;
- }
- }
- p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
-
- radv_info->n_solicitations_dropped += is_dropped;
- radv_info->n_solicitations_rcvd += is_solicitation;
-
- if((error0 == ICMP6_ERROR_NONE) && !is_dropped)
+
+ if (is_solicitation)
+ {
+ ethernet_header_t *eth0;
+ /* Reuse current MAC header, copy SMAC to DMAC and
+ * interface MAC to SMAC */
+ vlib_buffer_reset (p0);
+ eth0 = vlib_buffer_get_current (p0);
+ clib_memcpy (eth0->dst_address, eth0->src_address,
+ 6);
+ clib_memcpy (eth0->src_address, eth_if0->address,
+ 6);
+ next0 =
+ is_dropped ? next0 :
+ ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX;
+ vnet_buffer (p0)->sw_if_index[VLIB_TX] =
+ sw_if_index0;
+ }
+ else
+ {
+ adj_index0 = radv_info->all_nodes_adj_index;
+ if (adj_index0 == 0)
+ error0 = ICMP6_ERROR_DST_LOOKUP_MISS;
+ else
+ {
+ ip_adjacency_t *adj0 =
+ ip_get_adjacency (&im->lookup_main,
+ adj_index0);
+ error0 =
+ ((adj0->rewrite_header.sw_if_index !=
+ sw_if_index0
+ || adj0->lookup_next_index !=
+ IP_LOOKUP_NEXT_REWRITE) ?
+ ICMP6_ERROR_ROUTER_SOLICITATION_DEST_UNKNOWN
+ : error0);
+ next0 =
+ is_dropped ? next0 :
+ ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW;
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
+ adj_index0;
+ }
+ }
+ p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
+
+ radv_info->n_solicitations_dropped += is_dropped;
+ radv_info->n_solicitations_rcvd += is_solicitation;
+
+ if ((error0 == ICMP6_ERROR_NONE) && !is_dropped)
{
radv_info->n_advertisements_sent++;
n_advertisements_sent++;
@@ -1487,43 +1556,45 @@ icmp6_router_solicitation(vlib_main_t * vm,
p0->error = error_node->errors[error0];
- if(error0 != ICMP6_ERROR_NONE)
+ if (error0 != ICMP6_ERROR_NONE)
vlib_error_count (vm, error_node->node_index, error0, 1);
-
+
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
-
+
}
-
+
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
/* Account for router advertisements sent. */
- vlib_error_count (vm, error_node->node_index, ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX, n_advertisements_sent);
+ vlib_error_count (vm, error_node->node_index,
+ ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX,
+ n_advertisements_sent);
return frame->n_vectors;
}
/* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */
static_always_inline uword
-icmp6_router_advertisement(vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+icmp6_router_advertisement (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
uword n_packets = frame->n_vectors;
- u32 * from, * to_next;
+ u32 *from, *to_next;
u32 n_left_from, n_left_to_next, next_index;
u32 n_advertisements_rcvd = 0;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
from = vlib_frame_vector_args (frame);
n_left_from = n_packets;
next_index = node->cached_next_index;
-
+
if (node->flags & VLIB_NODE_FLAG_TRACE)
vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
/* stride */ 1,
@@ -1532,13 +1603,13 @@ icmp6_router_advertisement(vlib_main_t * vm,
while (n_left_from > 0)
{
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
ip6_radv_t *radv_info = 0;
- icmp6_router_advertisement_header_t * h0;
+ icmp6_router_advertisement_header_t *h0;
u32 bi0, options_len0, sw_if_index0, next0, error0;
bi0 = to_next[0] = from[0];
@@ -1547,196 +1618,252 @@ icmp6_router_advertisement(vlib_main_t * vm,
to_next += 1;
n_left_from -= 1;
n_left_to_next -= 1;
-
+
p0 = vlib_get_buffer (vm, bi0);
ip0 = vlib_buffer_get_current (p0);
h0 = ip6_next_header (ip0);
- options_len0 = clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
+ options_len0 =
+ clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
error0 = ICMP6_ERROR_NONE;
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
- /* Check that source address is link-local*/
- error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ?
+ /* Check that source address is link-local */
+ error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ?
ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0;
/* default is to drop */
next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
-
+
n_advertisements_rcvd++;
if (error0 == ICMP6_ERROR_NONE)
{
- vnet_sw_interface_t * sw_if0;
- ethernet_interface_t * eth_if0;
-
+ vnet_sw_interface_t *sw_if0;
+ ethernet_interface_t *eth_if0;
+
sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
- eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
+ eth_if0 =
+ ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
/* only support ethernet interface type for now */
- error0 = (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF : error0;
+ error0 =
+ (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
+ : error0;
if (error0 == ICMP6_ERROR_NONE)
{
u32 ri;
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
+ vec_validate_init_empty
+ (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
- if(ri != ~0)
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
-
- error0 = ((!radv_info) ? ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : error0);
+ if (ri != ~0)
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+
+ error0 =
+ ((!radv_info) ?
+ ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
+ error0);
if (error0 == ICMP6_ERROR_NONE)
{
/* validate advertised information */
- if((h0->current_hop_limit && radv_info->curr_hop_limit) &&
- (h0->current_hop_limit != radv_info->curr_hop_limit))
+ if ((h0->current_hop_limit && radv_info->curr_hop_limit)
+ && (h0->current_hop_limit !=
+ radv_info->curr_hop_limit))
{
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our AdvCurHopLimit on %U doesn't agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_WARNING,
+ "our AdvCurHopLimit on %U doesn't agree with %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
}
- if((h0->flags & ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP) !=
- radv_info->adv_managed_flag)
+ if ((h0->flags &
+ ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP)
+ != radv_info->adv_managed_flag)
{
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our AdvManagedFlag on %U doesn't agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_WARNING,
+ "our AdvManagedFlag on %U doesn't agree with %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
}
- if((h0->flags & ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP) !=
- radv_info->adv_other_flag)
+ if ((h0->flags &
+ ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP)
+ != radv_info->adv_other_flag)
{
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our AdvOtherConfigFlag on %U doesn't agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_WARNING,
+ "our AdvOtherConfigFlag on %U doesn't agree with %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
}
- if((h0->time_in_msec_between_retransmitted_neighbor_solicitations &&
- radv_info->adv_time_in_msec_between_retransmitted_neighbor_solicitations) &&
- (h0->time_in_msec_between_retransmitted_neighbor_solicitations !=
- clib_host_to_net_u32(radv_info->adv_time_in_msec_between_retransmitted_neighbor_solicitations)))
+ if ((h0->
+ time_in_msec_between_retransmitted_neighbor_solicitations
+ && radv_info->
+ adv_time_in_msec_between_retransmitted_neighbor_solicitations)
+ && (h0->
+ time_in_msec_between_retransmitted_neighbor_solicitations
+ !=
+ clib_host_to_net_u32 (radv_info->
+ adv_time_in_msec_between_retransmitted_neighbor_solicitations)))
{
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our AdvRetransTimer on %U doesn't agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_WARNING,
+ "our AdvRetransTimer on %U doesn't agree with %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
}
- if((h0->neighbor_reachable_time_in_msec &&
- radv_info->adv_neighbor_reachable_time_in_msec) &&
- (h0->neighbor_reachable_time_in_msec !=
- clib_host_to_net_u32(radv_info->adv_neighbor_reachable_time_in_msec)))
+ if ((h0->neighbor_reachable_time_in_msec &&
+ radv_info->adv_neighbor_reachable_time_in_msec) &&
+ (h0->neighbor_reachable_time_in_msec !=
+ clib_host_to_net_u32
+ (radv_info->adv_neighbor_reachable_time_in_msec)))
{
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our AdvReachableTime on %U doesn't agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_WARNING,
+ "our AdvReachableTime on %U doesn't agree with %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
}
/* check for MTU or prefix options or .. */
- u8 * opt_hdr = (u8 *)(h0 + 1);
- while( options_len0 > 0)
+ u8 *opt_hdr = (u8 *) (h0 + 1);
+ while (options_len0 > 0)
{
- icmp6_neighbor_discovery_option_header_t *o0 = ( icmp6_neighbor_discovery_option_header_t *)opt_hdr;
+ icmp6_neighbor_discovery_option_header_t *o0 =
+ (icmp6_neighbor_discovery_option_header_t *)
+ opt_hdr;
int opt_len = o0->n_data_u64s << 3;
- icmp6_neighbor_discovery_option_type_t option_type = o0->type;
+ icmp6_neighbor_discovery_option_type_t option_type =
+ o0->type;
- if(options_len0 < 2)
+ if (options_len0 < 2)
{
- ip6_neighbor_syslog(vm, LOG_ERR,
- "malformed RA packet on %U from %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_ERR,
+ "malformed RA packet on %U from %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
break;
}
- if(opt_len == 0)
+ if (opt_len == 0)
{
- ip6_neighbor_syslog(vm, LOG_ERR,
- " zero length option in RA on %U from %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_ERR,
+ " zero length option in RA on %U from %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
break;
}
- else if( opt_len > options_len0)
+ else if (opt_len > options_len0)
{
- ip6_neighbor_syslog(vm, LOG_ERR,
- "option length in RA packet greater than total length on %U from %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_ERR,
+ "option length in RA packet greater than total length on %U from %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
break;
}
options_len0 -= opt_len;
opt_hdr += opt_len;
- switch(option_type)
+ switch (option_type)
{
case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu:
- {
+ {
icmp6_neighbor_discovery_mtu_option_t *h =
- (icmp6_neighbor_discovery_mtu_option_t *)(o0);
+ (icmp6_neighbor_discovery_mtu_option_t
+ *) (o0);
- if(opt_len < sizeof(*h))
+ if (opt_len < sizeof (*h))
break;
- if((h->mtu && radv_info->adv_link_mtu) &&
- (h->mtu != clib_host_to_net_u32(radv_info->adv_link_mtu)))
+ if ((h->mtu && radv_info->adv_link_mtu) &&
+ (h->mtu !=
+ clib_host_to_net_u32
+ (radv_info->adv_link_mtu)))
{
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our AdvLinkMTU on %U doesn't agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
+ ip6_neighbor_syslog (vm, LOG_WARNING,
+ "our AdvLinkMTU on %U doesn't agree with %U",
+ format_vnet_sw_if_index_name,
+ vnm, sw_if_index0,
+ format_ip6_address,
+ &ip0->src_address);
}
}
break;
-
+
case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information:
{
- icmp6_neighbor_discovery_prefix_information_option_t *h =
- (icmp6_neighbor_discovery_prefix_information_option_t *)(o0);
-
+ icmp6_neighbor_discovery_prefix_information_option_t
+ * h =
+ (icmp6_neighbor_discovery_prefix_information_option_t
+ *) (o0);
+
/* validate advertised prefix options */
- ip6_radv_prefix_t *pr_info;
+ ip6_radv_prefix_t *pr_info;
u32 preferred, valid;
- if(opt_len < sizeof(*h))
+ if (opt_len < sizeof (*h))
break;
- preferred = clib_net_to_host_u32(h->preferred_time);
- valid = clib_net_to_host_u32(h->valid_time);
+ preferred =
+ clib_net_to_host_u32 (h->preferred_time);
+ valid = clib_net_to_host_u32 (h->valid_time);
/* look for matching prefix - if we our advertising it, it better be consistant */
- pool_foreach (pr_info, radv_info->adv_prefixes_pool, ({
-
- ip6_address_t mask;
- ip6_address_mask_from_width(&mask, pr_info->prefix_len);
-
- if(pr_info->enabled &&
- (pr_info->prefix_len == h->dst_address_length) &&
- ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask))
- {
- /* found it */
- if(!pr_info->decrement_lifetime_flag &&
- valid != pr_info->adv_valid_lifetime_in_secs)
- {
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our ADV validlifetime on %U for %U does not agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
- format_ip6_address, &h->dst_address);
- }
- if(!pr_info->decrement_lifetime_flag &&
- preferred != pr_info->adv_pref_lifetime_in_secs)
- {
- ip6_neighbor_syslog(vm, LOG_WARNING,
- "our ADV preferredlifetime on %U for %U does not agree with %U",
- format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
- format_ip6_address, &h->dst_address);
- }
- }
- break;
- }));
+ /* *INDENT-OFF* */
+ pool_foreach (pr_info, radv_info->adv_prefixes_pool,
+ ({
+
+ ip6_address_t mask;
+ ip6_address_mask_from_width(&mask, pr_info->prefix_len);
+
+ if(pr_info->enabled &&
+ (pr_info->prefix_len == h->dst_address_length) &&
+ ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask))
+ {
+ /* found it */
+ if(!pr_info->decrement_lifetime_flag &&
+ valid != pr_info->adv_valid_lifetime_in_secs)
+ {
+ ip6_neighbor_syslog(vm, LOG_WARNING,
+ "our ADV validlifetime on %U for %U does not agree with %U",
+ format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
+ format_ip6_address, &h->dst_address);
+ }
+ if(!pr_info->decrement_lifetime_flag &&
+ preferred != pr_info->adv_pref_lifetime_in_secs)
+ {
+ ip6_neighbor_syslog(vm, LOG_WARNING,
+ "our ADV preferredlifetime on %U for %U does not agree with %U",
+ format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
+ format_ip6_address, &h->dst_address);
+ }
+ }
+ break;
+ }));
+ /* *INDENT-ON* */
break;
}
default:
@@ -1750,19 +1877,21 @@ icmp6_router_advertisement(vlib_main_t * vm,
p0->error = error_node->errors[error0];
- if(error0 != ICMP6_ERROR_NONE)
+ if (error0 != ICMP6_ERROR_NONE)
vlib_error_count (vm, error_node->node_index, error0, 1);
-
+
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
}
-
+
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
/* Account for router advertisements sent. */
- vlib_error_count (vm, error_node->node_index, ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX, n_advertisements_rcvd);
+ vlib_error_count (vm, error_node->node_index,
+ ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX,
+ n_advertisements_rcvd);
return frame->n_vectors;
}
@@ -1770,257 +1899,275 @@ icmp6_router_advertisement(vlib_main_t * vm,
/* create and initialize router advertisement parameters with default values for this intfc */
static u32
ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 is_add)
+ u32 sw_if_index, u32 is_add)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_radv_t * a= 0;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_radv_t *a = 0;
u32 ri = ~0;
- vnet_sw_interface_t * sw_if0;
- ethernet_interface_t * eth_if0 = 0;
+ vnet_sw_interface_t *sw_if0;
+ ethernet_interface_t *eth_if0 = 0;
/* lookup radv container - ethernet interfaces only */
sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
- if(sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
+ if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
- if(!eth_if0)
+ if (!eth_if0)
return ri;
-
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
+
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
- if(ri != ~0)
+ if (ri != ~0)
{
a = pool_elt_at_index (nm->if_radv_pool, ri);
- if(!is_add)
+ if (!is_add)
{
- u32 i, * to_delete = 0;
- ip6_radv_prefix_t *p;
+ u32 i, *to_delete = 0;
+ ip6_radv_prefix_t *p;
ip6_mldp_group_t *m;
-
+
/* remove adjacencies */
- adj_unlock(a->all_nodes_adj_index);
- adj_unlock(a->all_routers_adj_index);
- adj_unlock(a->all_mldv2_routers_adj_index);
-
+ adj_unlock (a->all_nodes_adj_index);
+ adj_unlock (a->all_routers_adj_index);
+ adj_unlock (a->all_mldv2_routers_adj_index);
+
/* clean up prefix_pool */
- pool_foreach (p, a->adv_prefixes_pool, ({
- vec_add1 (to_delete, p - a->adv_prefixes_pool);
- }));
-
+ /* *INDENT-OFF* */
+ pool_foreach (p, a->adv_prefixes_pool,
+ ({
+ vec_add1 (to_delete, p - a->adv_prefixes_pool);
+ }));
+ /* *INDENT-ON* */
+
for (i = 0; i < vec_len (to_delete); i++)
{
p = pool_elt_at_index (a->adv_prefixes_pool, to_delete[i]);
mhash_unset (&a->address_to_prefix_index, &p->prefix, 0);
pool_put (a->adv_prefixes_pool, p);
}
-
+
vec_free (to_delete);
to_delete = 0;
-
+
/* clean up mldp group pool */
- pool_foreach (m, a->mldp_group_pool, ({
- vec_add1 (to_delete, m - a->mldp_group_pool);
- }));
-
+ /* *INDENT-OFF* */
+ pool_foreach (m, a->mldp_group_pool,
+ ({
+ vec_add1 (to_delete, m - a->mldp_group_pool);
+ }));
+ /* *INDENT-ON* */
+
for (i = 0; i < vec_len (to_delete); i++)
{
m = pool_elt_at_index (a->mldp_group_pool, to_delete[i]);
mhash_unset (&a->address_to_mldp_index, &m->mcast_address, 0);
pool_put (a->mldp_group_pool, m);
}
-
+
vec_free (to_delete);
-
- pool_put (nm->if_radv_pool, a);
+
+ pool_put (nm->if_radv_pool, a);
nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0;
ri = ~0;
}
}
- else
- {
- if(is_add)
- {
- vnet_hw_interface_t * hw_if0;
-
- hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index);
-
- pool_get (nm->if_radv_pool, a);
-
- ri = a - nm->if_radv_pool;
- nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri;
-
- /* initialize default values (most of which are zero) */
- memset (a, 0, sizeof (a[0]));
-
- a->sw_if_index = sw_if_index;
- a->fib_index = ~0;
- a->max_radv_interval = DEF_MAX_RADV_INTERVAL;
- a->min_radv_interval = DEF_MIN_RADV_INTERVAL;
- a->curr_hop_limit = DEF_CURR_HOP_LIMIT;
- a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME;
-
- a->adv_link_layer_address = 1; /* send ll address source address option */
-
- a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS;
- a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS;
- a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME;
- a->seed = (u32) clib_cpu_time_now();
- (void) random_u32 (&a->seed);
- a->randomizer = clib_cpu_time_now();
- (void) random_u64 (&a->randomizer);
-
- a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS ;
- a->initial_adverts_sent = a->initial_adverts_count-1;
- a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
-
- /* deafult is to send */
- a->send_radv = 1;
-
- /* fill in radv_info for this interface that will be needed later */
- a->adv_link_mtu = hw_if0->max_l3_packet_bytes[VLIB_RX];
-
- clib_memcpy (a->link_layer_address, eth_if0->address, 6);
-
- /* fill in default link-local address (this may be overridden) */
- ip6_link_local_address_from_ethernet_address (&a->link_local_address, eth_if0->address);
- a->link_local_prefix_len = 64;
-
- mhash_init (&a->address_to_prefix_index, sizeof (uword), sizeof (ip6_address_t));
- mhash_init (&a->address_to_mldp_index, sizeof (uword), sizeof (ip6_address_t));
-
- {
- u8 link_layer_address[6] =
- {0x33, 0x33, 0x00, 0x00, 0x00, IP6_MULTICAST_GROUP_ID_all_hosts};
-
- a->all_nodes_adj_index = adj_rewrite_add_and_lock(FIB_PROTOCOL_IP6,
- VNET_LINK_IP6,
- sw_if_index,
- link_layer_address);
- }
-
- {
- u8 link_layer_address[6] =
- {0x33, 0x33, 0x00, 0x00, 0x00, IP6_MULTICAST_GROUP_ID_all_routers};
-
- a->all_routers_adj_index = adj_rewrite_add_and_lock(FIB_PROTOCOL_IP6,
- VNET_LINK_IP6,
- sw_if_index,
- link_layer_address);
- }
-
- {
- u8 link_layer_address[6] =
- {0x33, 0x33, 0x00, 0x00, 0x00, IP6_MULTICAST_GROUP_ID_mldv2_routers};
-
- a->all_mldv2_routers_adj_index =
- adj_rewrite_add_and_lock(FIB_PROTOCOL_IP6,
+ else
+ {
+ if (is_add)
+ {
+ vnet_hw_interface_t *hw_if0;
+
+ hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index);
+
+ pool_get (nm->if_radv_pool, a);
+
+ ri = a - nm->if_radv_pool;
+ nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri;
+
+ /* initialize default values (most of which are zero) */
+ memset (a, 0, sizeof (a[0]));
+
+ a->sw_if_index = sw_if_index;
+ a->fib_index = ~0;
+ a->max_radv_interval = DEF_MAX_RADV_INTERVAL;
+ a->min_radv_interval = DEF_MIN_RADV_INTERVAL;
+ a->curr_hop_limit = DEF_CURR_HOP_LIMIT;
+ a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME;
+
+ a->adv_link_layer_address = 1; /* send ll address source address option */
+
+ a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS;
+ a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS;
+ a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME;
+ a->seed = (u32) clib_cpu_time_now ();
+ (void) random_u32 (&a->seed);
+ a->randomizer = clib_cpu_time_now ();
+ (void) random_u64 (&a->randomizer);
+
+ a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS;
+ a->initial_adverts_sent = a->initial_adverts_count - 1;
+ a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
+
+ /* deafult is to send */
+ a->send_radv = 1;
+
+ /* fill in radv_info for this interface that will be needed later */
+ a->adv_link_mtu = hw_if0->max_l3_packet_bytes[VLIB_RX];
+
+ clib_memcpy (a->link_layer_address, eth_if0->address, 6);
+
+ /* fill in default link-local address (this may be overridden) */
+ ip6_link_local_address_from_ethernet_address
+ (&a->link_local_address, eth_if0->address);
+ a->link_local_prefix_len = 64;
+
+ mhash_init (&a->address_to_prefix_index, sizeof (uword),
+ sizeof (ip6_address_t));
+ mhash_init (&a->address_to_mldp_index, sizeof (uword),
+ sizeof (ip6_address_t));
+
+ {
+ u8 link_layer_address[6] = { 0x33, 0x33, 0x00, 0x00, 0x00,
+ IP6_MULTICAST_GROUP_ID_all_hosts
+ };
+
+ a->all_nodes_adj_index =
+ adj_rewrite_add_and_lock (FIB_PROTOCOL_IP6, VNET_LINK_IP6,
+ sw_if_index, link_layer_address);
+ }
+
+ {
+ u8 link_layer_address[6] = { 0x33, 0x33, 0x00, 0x00, 0x00,
+ IP6_MULTICAST_GROUP_ID_all_routers
+ };
+
+ a->all_routers_adj_index =
+ adj_rewrite_add_and_lock (FIB_PROTOCOL_IP6, VNET_LINK_IP6,
+ sw_if_index, link_layer_address);
+ }
+
+ {
+ u8 link_layer_address[6] = { 0x33, 0x33, 0x00, 0x00, 0x00,
+ IP6_MULTICAST_GROUP_ID_mldv2_routers
+ };
+
+ a->all_mldv2_routers_adj_index =
+ adj_rewrite_add_and_lock (FIB_PROTOCOL_IP6,
VNET_LINK_IP6,
- sw_if_index,
- link_layer_address);
- }
-
- /* add multicast groups we will always be reporting */
- ip6_address_t addr;
- ip6_mldp_group_t *mcast_group_info;
-
- ip6_set_reserved_multicast_address (&addr,
- IP6_MULTICAST_SCOPE_link_local,
- IP6_MULTICAST_GROUP_ID_all_hosts);
-
- /* lookup mldp info for this interface */
-
- uword * p = mhash_get (&a->address_to_mldp_index, &addr);
- mcast_group_info = p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
-
- /* add address */
- if(!mcast_group_info)
- {
- /* add */
- u32 mi;
- pool_get (a->mldp_group_pool, mcast_group_info);
-
- mi = mcast_group_info - a->mldp_group_pool;
- mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */ 0);
-
- mcast_group_info->type = 4;
- mcast_group_info->mcast_source_address_pool = 0;
- mcast_group_info->num_sources = 0;
- clib_memcpy(&mcast_group_info->mcast_address, &addr, sizeof(ip6_address_t));
- }
-
- ip6_set_reserved_multicast_address (&addr,
- IP6_MULTICAST_SCOPE_link_local,
- IP6_MULTICAST_GROUP_ID_all_routers);
-
- p = mhash_get (&a->address_to_mldp_index, &addr);
- mcast_group_info = p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
-
- if(!mcast_group_info)
- {
- /* add */
- u32 mi;
- pool_get (a->mldp_group_pool, mcast_group_info);
-
- mi = mcast_group_info - a->mldp_group_pool;
- mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */ 0);
-
- mcast_group_info->type = 4;
- mcast_group_info->mcast_source_address_pool = 0;
- mcast_group_info->num_sources = 0;
- clib_memcpy(&mcast_group_info->mcast_address, &addr, sizeof(ip6_address_t));
- }
-
- ip6_set_reserved_multicast_address (&addr,
- IP6_MULTICAST_SCOPE_link_local,
- IP6_MULTICAST_GROUP_ID_mldv2_routers);
-
- p = mhash_get (&a->address_to_mldp_index, &addr);
- mcast_group_info = p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
-
- if(!mcast_group_info)
- {
- /* add */
- u32 mi;
- pool_get (a->mldp_group_pool, mcast_group_info);
-
- mi = mcast_group_info - a->mldp_group_pool;
- mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */ 0);
-
- mcast_group_info->type = 4;
- mcast_group_info->mcast_source_address_pool = 0;
- mcast_group_info->num_sources = 0;
- clib_memcpy(&mcast_group_info->mcast_address, &addr, sizeof(ip6_address_t));
- }
- }
- }
- return ri;
+ sw_if_index, link_layer_address);
+ }
+
+ /* add multicast groups we will always be reporting */
+ ip6_address_t addr;
+ ip6_mldp_group_t *mcast_group_info;
+
+ ip6_set_reserved_multicast_address (&addr,
+ IP6_MULTICAST_SCOPE_link_local,
+ IP6_MULTICAST_GROUP_ID_all_hosts);
+
+ /* lookup mldp info for this interface */
+
+ uword *p = mhash_get (&a->address_to_mldp_index, &addr);
+ mcast_group_info =
+ p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
+
+ /* add address */
+ if (!mcast_group_info)
+ {
+ /* add */
+ u32 mi;
+ pool_get (a->mldp_group_pool, mcast_group_info);
+
+ mi = mcast_group_info - a->mldp_group_pool;
+ mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */
+ 0);
+
+ mcast_group_info->type = 4;
+ mcast_group_info->mcast_source_address_pool = 0;
+ mcast_group_info->num_sources = 0;
+ clib_memcpy (&mcast_group_info->mcast_address, &addr,
+ sizeof (ip6_address_t));
+ }
+
+ ip6_set_reserved_multicast_address (&addr,
+ IP6_MULTICAST_SCOPE_link_local,
+ IP6_MULTICAST_GROUP_ID_all_routers);
+
+ p = mhash_get (&a->address_to_mldp_index, &addr);
+ mcast_group_info =
+ p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
+
+ if (!mcast_group_info)
+ {
+ /* add */
+ u32 mi;
+ pool_get (a->mldp_group_pool, mcast_group_info);
+
+ mi = mcast_group_info - a->mldp_group_pool;
+ mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */
+ 0);
+
+ mcast_group_info->type = 4;
+ mcast_group_info->mcast_source_address_pool = 0;
+ mcast_group_info->num_sources = 0;
+ clib_memcpy (&mcast_group_info->mcast_address, &addr,
+ sizeof (ip6_address_t));
+ }
+
+ ip6_set_reserved_multicast_address (&addr,
+ IP6_MULTICAST_SCOPE_link_local,
+ IP6_MULTICAST_GROUP_ID_mldv2_routers);
+
+ p = mhash_get (&a->address_to_mldp_index, &addr);
+ mcast_group_info =
+ p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
+
+ if (!mcast_group_info)
+ {
+ /* add */
+ u32 mi;
+ pool_get (a->mldp_group_pool, mcast_group_info);
+
+ mi = mcast_group_info - a->mldp_group_pool;
+ mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */
+ 0);
+
+ mcast_group_info->type = 4;
+ mcast_group_info->mcast_source_address_pool = 0;
+ mcast_group_info->num_sources = 0;
+ clib_memcpy (&mcast_group_info->mcast_address, &addr,
+ sizeof (ip6_address_t));
+ }
+ }
+ }
+ return ri;
}
/* send an mldpv2 report */
static void
-ip6_neighbor_send_mldpv2_report(u32 sw_if_index)
+ip6_neighbor_send_mldpv2_report (u32 sw_if_index)
{
- vnet_main_t * vnm = vnet_get_main();
- vlib_main_t * vm = vnm->vlib_main;
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- vnet_sw_interface_t * sw_if0;
- ethernet_interface_t * eth_if0;
+ vnet_main_t *vnm = vnet_get_main ();
+ vlib_main_t *vm = vnm->vlib_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ vnet_sw_interface_t *sw_if0;
+ ethernet_interface_t *eth_if0;
u32 ri;
int bogus_length;
- ip6_radv_t *radv_info;
+ ip6_radv_t *radv_info;
u16 payload_length;
- vlib_buffer_t * b0;
- ip6_header_t * ip0;
- u32 * to_next;
- vlib_frame_t * f;
+ vlib_buffer_t *b0;
+ ip6_header_t *ip0;
+ u32 *to_next;
+ vlib_frame_t *f;
u32 bo0;
u32 n_to_alloc = 1;
u32 n_allocated;
-
+
icmp6_multicast_listener_report_header_t *rh0;
icmp6_multicast_listener_report_packet_t *rp0;
@@ -2032,19 +2179,20 @@ ip6_neighbor_send_mldpv2_report(u32 sw_if_index)
return;
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
-
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
+
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
-
- if(ri == ~0)
+
+ if (ri == ~0)
return;
-
+
/* send report now - build a mldpv2 report packet */
- n_allocated = vlib_buffer_alloc_from_free_list(vm,
- &bo0,
- n_to_alloc,
- VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
- if (PREDICT_FALSE(n_allocated == 0))
+ n_allocated = vlib_buffer_alloc_from_free_list (vm,
+ &bo0,
+ n_to_alloc,
+ VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+ if (PREDICT_FALSE (n_allocated == 0))
{
clib_warning ("buffer allocation failure");
return;
@@ -2053,36 +2201,37 @@ ip6_neighbor_send_mldpv2_report(u32 sw_if_index)
b0 = vlib_get_buffer (vm, bo0);
/* adjust the sizeof the buffer to just include the ipv6 header */
- b0->current_length = sizeof(icmp6_multicast_listener_report_packet_t);
+ b0->current_length = sizeof (icmp6_multicast_listener_report_packet_t);
- payload_length = sizeof(icmp6_multicast_listener_report_header_t);
+ payload_length = sizeof (icmp6_multicast_listener_report_header_t);
b0->error = ICMP6_ERROR_NONE;
rp0 = vlib_buffer_get_current (b0);
- ip0 = (ip6_header_t *)&rp0-> ip;
- rh0 = (icmp6_multicast_listener_report_header_t *)&rp0-> report_hdr;
-
- memset (rp0 , 0x0, sizeof (icmp6_multicast_listener_report_packet_t));
-
- ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
-
- ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
+ ip0 = (ip6_header_t *) & rp0->ip;
+ rh0 = (icmp6_multicast_listener_report_header_t *) & rp0->report_hdr;
+
+ memset (rp0, 0x0, sizeof (icmp6_multicast_listener_report_packet_t));
+
+ ip0->ip_version_traffic_class_and_flow_label =
+ clib_host_to_net_u32 (0x6 << 28);
+
+ ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
/* for DEBUG - vnet driver won't seem to emit router alerts */
/* ip0->protocol = IP_PROTOCOL_ICMP6; */
ip0->hop_limit = 1;
-
+
rh0->icmp.type = ICMP6_multicast_listener_report_v2;
-
+
/* source address MUST be the link-local address */
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
- ip0->src_address = radv_info->link_local_address;
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ ip0->src_address = radv_info->link_local_address;
/* destination is all mldpv2 routers */
- ip6_set_reserved_multicast_address(&ip0->dst_address,
- IP6_MULTICAST_SCOPE_link_local,
- IP6_MULTICAST_GROUP_ID_mldv2_routers);
-
+ ip6_set_reserved_multicast_address (&ip0->dst_address,
+ IP6_MULTICAST_SCOPE_link_local,
+ IP6_MULTICAST_GROUP_ID_mldv2_routers);
+
/* add reports here */
ip6_mldp_group_t *m;
int num_addr_records = 0;
@@ -2091,66 +2240,69 @@ ip6_neighbor_send_mldpv2_report(u32 sw_if_index)
/* fill in the hop-by-hop extension header (router alert) info */
rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6;
rh0->ext_hdr.n_data_u64s = 0;
-
+
rh0->alert.type = IP6_MLDP_ALERT_TYPE;
rh0->alert.len = 2;
rh0->alert.value = 0;
-
+
rh0->pad.type = 1;
rh0->pad.len = 0;
-
+
rh0->icmp.checksum = 0;
- pool_foreach (m, radv_info->mldp_group_pool, ({
+ /* *INDENT-OFF* */
+ pool_foreach (m, radv_info->mldp_group_pool,
+ ({
+ rr.type = m->type;
+ rr.aux_data_len_u32s = 0;
+ rr.num_sources = clib_host_to_net_u16 (m->num_sources);
+ clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t));
- rr.type = m->type;
- rr.aux_data_len_u32s = 0;
- rr.num_sources = clib_host_to_net_u16 (m->num_sources);
- clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t));
+ num_addr_records++;
- num_addr_records++;
+ vlib_buffer_add_data
+ (vm, b0->free_list_index, bo0,
+ (void *)&rr, sizeof(icmp6_multicast_address_record_t));
- vlib_buffer_add_data (vm,
- b0->free_list_index,
- bo0,
- (void *)&rr, sizeof(icmp6_multicast_address_record_t));
-
- payload_length += sizeof( icmp6_multicast_address_record_t);
- }));
+ payload_length += sizeof( icmp6_multicast_address_record_t);
+ }));
+ /* *INDENT-ON* */
rh0->rsvd = 0;
- rh0->num_addr_records = clib_host_to_net_u16(num_addr_records);
-
+ rh0->num_addr_records = clib_host_to_net_u16 (num_addr_records);
+
/* update lengths */
ip0->payload_length = clib_host_to_net_u16 (payload_length);
- rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0,
- &bogus_length);
- ASSERT(bogus_length == 0);
+ rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0,
+ &bogus_length);
+ ASSERT (bogus_length == 0);
- /*
+ /*
* OK to override w/ no regard for actual FIB, because
* ip6-rewrite only looks at the adjacency.
*/
- vnet_buffer (b0)->sw_if_index[VLIB_RX] =
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] =
vnet_main.local_interface_sw_if_index;
-
- vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
+
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
radv_info->all_mldv2_routers_adj_index;
b0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
- vlib_node_t * node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite");
-
+ vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite");
+
f = vlib_get_frame_to_node (vm, node->index);
to_next = vlib_frame_vector_args (f);
to_next[0] = bo0;
f->n_vectors = 1;
-
+
vlib_put_frame_to_node (vm, node->index, f);
return;
}
-VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) =
+{
.function = icmp6_router_solicitation,
.name = "icmp6-router-solicitation",
@@ -2165,135 +2317,136 @@ VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) = {
[ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output",
},
};
+/* *INDENT-ON* */
/* send a RA or update the timer info etc.. */
static uword
ip6_neighbor_process_timer_event (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_radv_t *radv_info;
- vlib_frame_t * f = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_radv_t *radv_info;
+ vlib_frame_t *f = 0;
u32 n_this_frame = 0;
u32 n_left_to_next = 0;
- u32 * to_next = 0;
- u32 bo0;
- icmp6_router_solicitation_header_t * h0;
- vlib_buffer_t * b0;
+ u32 *to_next = 0;
+ u32 bo0;
+ icmp6_router_solicitation_header_t *h0;
+ vlib_buffer_t *b0;
f64 now = vlib_time_now (vm);
/* Interface ip6 radv info list */
- pool_foreach (radv_info, nm->if_radv_pool, ({
+ /* *INDENT-OFF* */
+ pool_foreach (radv_info, nm->if_radv_pool,
+ ({
+ if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index))
+ {
+ radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1;
+ radv_info->next_multicast_time = now;
+ radv_info->last_multicast_time = now;
+ radv_info->last_radv_time = 0;
+ radv_info->all_routers_mcast = 0;
+ continue;
+ }
- if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index))
- {
- radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1;
- radv_info->next_multicast_time = now;
- radv_info->last_multicast_time = now;
- radv_info->last_radv_time = 0;
- radv_info->all_routers_mcast = 0;
- continue;
- }
+ /* Make sure that we've joined the all-routers multicast group */
+ if(!radv_info->all_routers_mcast)
+ {
+ /* send MDLP_REPORT_EVENT message */
+ ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index);
+ radv_info->all_routers_mcast = 1;
+ }
- /* Make sure that we've joined the all-routers multicast group */
- if(!radv_info->all_routers_mcast)
- {
- /* send MDLP_REPORT_EVENT message */
- ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index);
- radv_info->all_routers_mcast = 1;
- }
+ /* is it time to send a multicast RA on this interface? */
+ if(radv_info->send_radv && (now >= radv_info->next_multicast_time))
+ {
+ u32 n_to_alloc = 1;
+ u32 n_allocated;
+
+ f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) *
+ random_f64 (&radv_info->seed) + radv_info->min_radv_interval;
+
+ /* multicast send - compute next multicast send time */
+ if( radv_info->initial_adverts_sent > 0)
+ {
+ radv_info->initial_adverts_sent--;
+ if(rfn > radv_info-> initial_adverts_interval)
+ rfn = radv_info-> initial_adverts_interval;
+
+ /* check to see if we are ceasing to send */
+ if( radv_info->initial_adverts_sent == 0)
+ if(radv_info->cease_radv)
+ radv_info->send_radv = 0;
+ }
- /* is it time to send a multicast RA on this interface? */
- if(radv_info->send_radv && (now >= radv_info->next_multicast_time))
- {
- u32 n_to_alloc = 1;
- u32 n_allocated;
-
- f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) *
- random_f64 (&radv_info->seed) + radv_info->min_radv_interval;
-
- /* multicast send - compute next multicast send time */
- if( radv_info->initial_adverts_sent > 0)
- {
- radv_info->initial_adverts_sent--;
- if(rfn > radv_info-> initial_adverts_interval)
- rfn = radv_info-> initial_adverts_interval;
-
- /* check to see if we are ceasing to send */
- if( radv_info->initial_adverts_sent == 0)
- if(radv_info->cease_radv)
- radv_info->send_radv = 0;
- }
-
- radv_info->next_multicast_time = rfn + now;
- radv_info->last_multicast_time = now;
-
- /* send advert now - build a "solicted" router advert with unspecified source address */
- n_allocated = vlib_buffer_alloc_from_free_list(vm,
- &bo0,
- n_to_alloc,
- VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
-
- if (PREDICT_FALSE(n_allocated == 0))
- {
- clib_warning ("buffer allocation failure");
- continue;
- }
- b0 = vlib_get_buffer (vm, bo0);
- b0->current_length = sizeof( icmp6_router_solicitation_header_t);
- b0->error = ICMP6_ERROR_NONE;
- vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index;
-
- h0 = vlib_buffer_get_current (b0);
-
- memset (h0, 0, sizeof (icmp6_router_solicitation_header_t));
-
- h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
- h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t)
- - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor));
- h0->ip.protocol = IP_PROTOCOL_ICMP6;
- h0->ip.hop_limit = 255;
-
- /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */
- h0->ip.src_address.as_u64[0] = 0;
- h0->ip.src_address.as_u64[1] = 0;
-
- h0->ip.dst_address.as_u64[0] = 0;
- h0->ip.dst_address.as_u64[1] = 0;
-
- h0->neighbor.icmp.type = ICMP6_router_solicitation;
-
- if (PREDICT_FALSE(f == 0))
- {
- f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index);
- to_next = vlib_frame_vector_args (f);
- n_left_to_next = VLIB_FRAME_SIZE;
- n_this_frame = 0;
- }
-
- n_this_frame++;
- n_left_to_next--;
- to_next[0] = bo0;
- to_next += 1;
-
- if (PREDICT_FALSE(n_left_to_next == 0))
- {
- f->n_vectors = n_this_frame;
- vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
- f = 0;
- }
- }
- }));
+ radv_info->next_multicast_time = rfn + now;
+ radv_info->last_multicast_time = now;
+
+ /* send advert now - build a "solicted" router advert with unspecified source address */
+ n_allocated = vlib_buffer_alloc_from_free_list
+ (vm, &bo0, n_to_alloc, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+
+ if (PREDICT_FALSE(n_allocated == 0))
+ {
+ clib_warning ("buffer allocation failure");
+ continue;
+ }
+ b0 = vlib_get_buffer (vm, bo0);
+ b0->current_length = sizeof( icmp6_router_solicitation_header_t);
+ b0->error = ICMP6_ERROR_NONE;
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index;
+
+ h0 = vlib_buffer_get_current (b0);
+
+ memset (h0, 0, sizeof (icmp6_router_solicitation_header_t));
+
+ h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
+ h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t)
+ - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor));
+ h0->ip.protocol = IP_PROTOCOL_ICMP6;
+ h0->ip.hop_limit = 255;
+
+ /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */
+ h0->ip.src_address.as_u64[0] = 0;
+ h0->ip.src_address.as_u64[1] = 0;
+
+ h0->ip.dst_address.as_u64[0] = 0;
+ h0->ip.dst_address.as_u64[1] = 0;
+
+ h0->neighbor.icmp.type = ICMP6_router_solicitation;
+
+ if (PREDICT_FALSE(f == 0))
+ {
+ f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index);
+ to_next = vlib_frame_vector_args (f);
+ n_left_to_next = VLIB_FRAME_SIZE;
+ n_this_frame = 0;
+ }
+
+ n_this_frame++;
+ n_left_to_next--;
+ to_next[0] = bo0;
+ to_next += 1;
+
+ if (PREDICT_FALSE(n_left_to_next == 0))
+ {
+ f->n_vectors = n_this_frame;
+ vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
+ f = 0;
+ }
+ }
+ }));
+ /* *INDENT-ON* */
if (f)
{
- ASSERT(n_this_frame);
+ ASSERT (n_this_frame);
f->n_vectors = n_this_frame;
vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
}
- return 0;
+ return 0;
}
static uword
@@ -2302,36 +2455,37 @@ ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm,
vlib_frame_t * frame)
{
uword event_type;
- ip6_icmp_neighbor_discovery_event_data_t * event_data;
+ ip6_icmp_neighbor_discovery_event_data_t *event_data;
/* init code here */
-
+
while (1)
{
- vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */);
+ vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */ );
- event_data = vlib_process_get_event_data (vm, &event_type);
+ event_data = vlib_process_get_event_data (vm, &event_type);
- if(!event_data)
+ if (!event_data)
{
/* No events found: timer expired. */
/* process interface list and send RAs as appropriate, update timer info */
- ip6_neighbor_process_timer_event (vm, node, frame);
+ ip6_neighbor_process_timer_event (vm, node, frame);
}
else
{
- switch (event_type) {
+ switch (event_type)
+ {
+
+ case ICMP6_ND_EVENT_INIT:
+ break;
+
+ case ~0:
+ break;
+
+ default:
+ ASSERT (0);
+ }
- case ICMP6_ND_EVENT_INIT:
- break;
-
- case ~0:
- break;
-
- default:
- ASSERT (0);
- }
-
if (event_data)
_vec_len (event_data) = 0;
}
@@ -2339,7 +2493,9 @@ ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm,
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) =
+{
.function = icmp6_router_advertisement,
.name = "icmp6-router-advertisement",
@@ -2352,6 +2508,7 @@ VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) = {
[0] = "error-drop",
},
};
+/* *INDENT-ON* */
vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = {
@@ -2362,17 +2519,26 @@ vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = {
static uword
icmp6_neighbor_solicitation (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
-{ return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, /* is_solicitation */ 1); }
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
+ /* is_solicitation */
+ 1);
+}
static uword
icmp6_neighbor_advertisement (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
-{ return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, /* is_solicitation */ 0); }
+{
+ return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
+ /* is_solicitation */
+ 0);
+}
-VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) =
+{
.function = icmp6_neighbor_solicitation,
.name = "icmp6-neighbor-solicitation",
@@ -2386,8 +2552,11 @@ VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) = {
[ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output",
},
};
+/* *INDENT-ON* */
-VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) =
+{
.function = icmp6_neighbor_advertisement,
.name = "icmp6-neighbor-advertisement",
@@ -2400,277 +2569,307 @@ VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) = {
[0] = "error-drop",
},
};
+/* *INDENT-ON* */
-/* API support functions */
+/* API support functions */
int
-ip6_neighbor_ra_config(vlib_main_t * vm, u32 sw_if_index,
- u8 suppress, u8 managed, u8 other,
- u8 ll_option, u8 send_unicast, u8 cease,
- u8 use_lifetime, u32 lifetime,
- u32 initial_count, u32 initial_interval,
- u32 max_interval, u32 min_interval,
- u8 is_no)
-{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- int error;
+ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index,
+ u8 suppress, u8 managed, u8 other,
+ u8 ll_option, u8 send_unicast, u8 cease,
+ u8 use_lifetime, u32 lifetime,
+ u32 initial_count, u32 initial_interval,
+ u32 max_interval, u32 min_interval, u8 is_no)
+{
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ int error;
u32 ri;
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
- error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
+ error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
- if(!error)
+ if (!error)
{
- ip6_radv_t * radv_info;
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
-
- if((max_interval != 0) && (min_interval ==0))
- min_interval = .75 * max_interval;
-
- max_interval = (max_interval != 0) ? ( (is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) : radv_info->max_radv_interval;
- min_interval = (min_interval != 0) ? ( (is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) : radv_info->min_radv_interval;
- lifetime = (use_lifetime != 0) ? ( (is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) : radv_info->adv_router_lifetime_in_sec;
-
- if(lifetime)
+ ip6_radv_t *radv_info;
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+
+ if ((max_interval != 0) && (min_interval == 0))
+ min_interval = .75 * max_interval;
+
+ max_interval =
+ (max_interval !=
+ 0) ? ((is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) :
+ radv_info->max_radv_interval;
+ min_interval =
+ (min_interval !=
+ 0) ? ((is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) :
+ radv_info->min_radv_interval;
+ lifetime =
+ (use_lifetime !=
+ 0) ? ((is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) :
+ radv_info->adv_router_lifetime_in_sec;
+
+ if (lifetime)
{
- if(lifetime > MAX_DEF_RTR_LIFETIME)
+ if (lifetime > MAX_DEF_RTR_LIFETIME)
lifetime = MAX_DEF_RTR_LIFETIME;
-
- if(lifetime <= max_interval)
- return VNET_API_ERROR_INVALID_VALUE;
+
+ if (lifetime <= max_interval)
+ return VNET_API_ERROR_INVALID_VALUE;
}
-
- if(min_interval != 0)
+
+ if (min_interval != 0)
{
- if((min_interval > .75 * max_interval) ||
- (min_interval < 3))
- return VNET_API_ERROR_INVALID_VALUE;
+ if ((min_interval > .75 * max_interval) || (min_interval < 3))
+ return VNET_API_ERROR_INVALID_VALUE;
}
- if((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) ||
- (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL))
- return VNET_API_ERROR_INVALID_VALUE;
-
- /*
- if "flag" is set and is_no is true then restore default value else set value corresponding to "flag"
- if "flag" is clear don't change corresponding value
- */
- radv_info->send_radv = (suppress != 0) ? ( (is_no != 0) ? 1 : 0 ) : radv_info->send_radv;
- radv_info->adv_managed_flag = ( managed != 0) ? ( (is_no) ? 0 : 1) : radv_info->adv_managed_flag;
- radv_info->adv_other_flag = (other != 0) ? ( (is_no) ? 0: 1) : radv_info->adv_other_flag;
- radv_info->adv_link_layer_address = ( ll_option != 0) ? ( (is_no) ? 1 : 0) : radv_info->adv_link_layer_address;
- radv_info->send_unicast = (send_unicast != 0) ? ( (is_no) ? 0 : 1) : radv_info->send_unicast;
- radv_info->cease_radv = ( cease != 0) ? ( (is_no) ? 0 : 1) : radv_info->cease_radv;
-
- radv_info->min_radv_interval = min_interval;
+ if ((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) ||
+ (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL))
+ return VNET_API_ERROR_INVALID_VALUE;
+
+ /*
+ if "flag" is set and is_no is true then restore default value else set value corresponding to "flag"
+ if "flag" is clear don't change corresponding value
+ */
+ radv_info->send_radv =
+ (suppress != 0) ? ((is_no != 0) ? 1 : 0) : radv_info->send_radv;
+ radv_info->adv_managed_flag =
+ (managed != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_managed_flag;
+ radv_info->adv_other_flag =
+ (other != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_other_flag;
+ radv_info->adv_link_layer_address =
+ (ll_option !=
+ 0) ? ((is_no) ? 1 : 0) : radv_info->adv_link_layer_address;
+ radv_info->send_unicast =
+ (send_unicast != 0) ? ((is_no) ? 0 : 1) : radv_info->send_unicast;
+ radv_info->cease_radv =
+ (cease != 0) ? ((is_no) ? 0 : 1) : radv_info->cease_radv;
+
+ radv_info->min_radv_interval = min_interval;
radv_info->max_radv_interval = max_interval;
radv_info->adv_router_lifetime_in_sec = lifetime;
- radv_info->initial_adverts_count =
- (initial_count != 0) ? ( (is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) : radv_info->initial_adverts_count ;
- radv_info->initial_adverts_interval =
- (initial_interval != 0) ? ( (is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) : radv_info->initial_adverts_interval;
+ radv_info->initial_adverts_count =
+ (initial_count !=
+ 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) :
+ radv_info->initial_adverts_count;
+ radv_info->initial_adverts_interval =
+ (initial_interval !=
+ 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) :
+ radv_info->initial_adverts_interval;
/* restart */
- if((cease != 0) && (is_no))
- radv_info-> send_radv = 1;
+ if ((cease != 0) && (is_no))
+ radv_info->send_radv = 1;
- radv_info->initial_adverts_sent = radv_info->initial_adverts_count -1;
- radv_info->next_multicast_time = vlib_time_now (vm);
+ radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
+ radv_info->next_multicast_time = vlib_time_now (vm);
radv_info->last_multicast_time = vlib_time_now (vm);
- radv_info->last_radv_time = 0;
+ radv_info->last_radv_time = 0;
}
- return(error);
+ return (error);
}
int
-ip6_neighbor_ra_prefix(vlib_main_t * vm, u32 sw_if_index,
- ip6_address_t *prefix_addr, u8 prefix_len,
- u8 use_default, u32 val_lifetime, u32 pref_lifetime,
- u8 no_advertise, u8 off_link, u8 no_autoconfig, u8 no_onlink,
- u8 is_no)
+ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index,
+ ip6_address_t * prefix_addr, u8 prefix_len,
+ u8 use_default, u32 val_lifetime, u32 pref_lifetime,
+ u8 no_advertise, u8 off_link, u8 no_autoconfig,
+ u8 no_onlink, u8 is_no)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
int error;
-
+
u32 ri;
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
-
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
+
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
-
- if(!error)
+
+ if (!error)
{
f64 now = vlib_time_now (vm);
- ip6_radv_t * radv_info;
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ ip6_radv_t *radv_info;
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
/* prefix info add, delete or update */
- ip6_radv_prefix_t * prefix;
-
+ ip6_radv_prefix_t *prefix;
+
/* lookup prefix info for this address on this interface */
- uword * p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr);
-
+ uword *p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr);
+
prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0;
- if(is_no)
+ if (is_no)
{
/* delete */
- if(!prefix)
- return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */
-
- if(prefix->prefix_len != prefix_len)
+ if (!prefix)
+ return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */
+
+ if (prefix->prefix_len != prefix_len)
return VNET_API_ERROR_INVALID_VALUE_2;
- /* FIXME - Should the DP do this or the CP ?*/
+ /* FIXME - Should the DP do this or the CP ? */
/* do specific delete processing here before returning */
/* try to remove from routing table */
- mhash_unset (&radv_info->address_to_prefix_index, prefix_addr,/* old_value */ 0);
+ mhash_unset (&radv_info->address_to_prefix_index, prefix_addr,
+ /* old_value */ 0);
pool_put (radv_info->adv_prefixes_pool, prefix);
- radv_info->initial_adverts_sent = radv_info->initial_adverts_count -1;
- radv_info->next_multicast_time = vlib_time_now (vm);
+ radv_info->initial_adverts_sent =
+ radv_info->initial_adverts_count - 1;
+ radv_info->next_multicast_time = vlib_time_now (vm);
radv_info->last_multicast_time = vlib_time_now (vm);
- radv_info->last_radv_time = 0;
- return(error);
+ radv_info->last_radv_time = 0;
+ return (error);
}
/* adding or changing */
- if(!prefix)
+ if (!prefix)
{
/* add */
u32 pi;
pool_get (radv_info->adv_prefixes_pool, prefix);
pi = prefix - radv_info->adv_prefixes_pool;
- mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi, /* old_value */ 0);
-
- memset(prefix, 0x0, sizeof(ip6_radv_prefix_t));
-
+ mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi,
+ /* old_value */ 0);
+
+ memset (prefix, 0x0, sizeof (ip6_radv_prefix_t));
+
prefix->prefix_len = prefix_len;
- clib_memcpy(&prefix->prefix, prefix_addr, sizeof(ip6_address_t));
-
+ clib_memcpy (&prefix->prefix, prefix_addr, sizeof (ip6_address_t));
+
/* initialize default values */
- prefix->adv_on_link_flag = 1; /* L bit set */
- prefix->adv_autonomous_flag = 1; /* A bit set */
- prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME;
+ prefix->adv_on_link_flag = 1; /* L bit set */
+ prefix->adv_autonomous_flag = 1; /* A bit set */
+ prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME;
prefix->adv_pref_lifetime_in_secs = DEF_ADV_PREF_LIFETIME;
prefix->enabled = 1;
prefix->decrement_lifetime_flag = 1;
prefix->deprecated_prefix_flag = 1;
- if(off_link == 0)
+ if (off_link == 0)
{
- /* FIXME - Should the DP do this or the CP ?*/
+ /* FIXME - Should the DP do this or the CP ? */
/* insert prefix into routing table as a connected prefix */
}
- if(use_default)
+ if (use_default)
goto restart;
}
else
{
-
- if(prefix->prefix_len != prefix_len)
+
+ if (prefix->prefix_len != prefix_len)
return VNET_API_ERROR_INVALID_VALUE_2;
- if(off_link != 0)
+ if (off_link != 0)
{
- /* FIXME - Should the DP do this or the CP ?*/
+ /* FIXME - Should the DP do this or the CP ? */
/* remove from routing table if already there */
- }
+ }
}
- if((val_lifetime == ~0) || (pref_lifetime == ~0))
+ if ((val_lifetime == ~0) || (pref_lifetime == ~0))
{
- prefix->adv_valid_lifetime_in_secs = ~0;
+ prefix->adv_valid_lifetime_in_secs = ~0;
prefix->adv_pref_lifetime_in_secs = ~0;
prefix->decrement_lifetime_flag = 0;
}
else
{
- prefix->adv_valid_lifetime_in_secs = val_lifetime;;
- prefix->adv_pref_lifetime_in_secs = pref_lifetime;
+ prefix->adv_valid_lifetime_in_secs = val_lifetime;;
+ prefix->adv_pref_lifetime_in_secs = pref_lifetime;
}
-
+
/* copy remaining */
prefix->enabled = !(no_advertise != 0);
prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0));
prefix->adv_autonomous_flag = !(no_autoconfig != 0);
- restart:
+ restart:
/* restart */
/* fill in the expiration times */
- prefix->valid_lifetime_expires = now + prefix->adv_valid_lifetime_in_secs;
+ prefix->valid_lifetime_expires =
+ now + prefix->adv_valid_lifetime_in_secs;
prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs;
-
- radv_info->initial_adverts_sent = radv_info->initial_adverts_count -1;
- radv_info->next_multicast_time = vlib_time_now (vm);
+
+ radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
+ radv_info->next_multicast_time = vlib_time_now (vm);
radv_info->last_multicast_time = vlib_time_now (vm);
- radv_info->last_radv_time = 0;
+ radv_info->last_radv_time = 0;
}
- return(error);
+ return (error);
}
clib_error_t *
-ip6_neighbor_cmd(vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_command_t * cmd)
+ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input,
+ vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ clib_error_t *error = 0;
u8 is_no = 0;
- u8 suppress = 0, managed = 0, other = 0;
- u8 suppress_ll_option = 0, send_unicast = 0, cease= 0;
+ u8 suppress = 0, managed = 0, other = 0;
+ u8 suppress_ll_option = 0, send_unicast = 0, cease = 0;
u8 use_lifetime = 0;
- u32 sw_if_index, ra_lifetime = 0, ra_initial_count = 0, ra_initial_interval = 0;
- u32 ra_max_interval = 0 , ra_min_interval = 0;
+ u32 sw_if_index, ra_lifetime = 0, ra_initial_count =
+ 0, ra_initial_interval = 0;
+ u32 ra_max_interval = 0, ra_min_interval = 0;
- unformat_input_t _line_input, * line_input = &_line_input;
- vnet_sw_interface_t * sw_if0;
+ unformat_input_t _line_input, *line_input = &_line_input;
+ vnet_sw_interface_t *sw_if0;
int add_radv_info = 1;
- __attribute__((unused)) ip6_radv_t * radv_info = 0;
+ __attribute__ ((unused)) ip6_radv_t *radv_info = 0;
ip6_address_t ip6_addr;
u32 addr_len;
-
+
/* Get a line of input. */
- if (! unformat_user (main_input, unformat_line_input, line_input))
+ if (!unformat_user (main_input, unformat_line_input, line_input))
return 0;
/* get basic radv info for this interface */
- if(unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat_user (line_input,
+ if (unformat_user (line_input,
unformat_vnet_sw_interface, vnm, &sw_if_index))
{
u32 ri;
- ethernet_interface_t * eth_if0 = 0;
-
+ ethernet_interface_t *eth_if0 = 0;
+
sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
- if(sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
- eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
-
- if(!eth_if0)
+ if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
+ eth_if0 =
+ ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
+
+ if (!eth_if0)
{
- error = clib_error_return (0, "Interface must be of ethernet type");
+ error =
+ clib_error_return (0, "Interface must be of ethernet type");
goto done;
}
-
+
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
-
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
+
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
-
- if(ri != ~0)
+
+ if (ri != ~0)
{
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
}
else
{
@@ -2691,10 +2890,9 @@ ip6_neighbor_cmd(vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_comma
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "no"))
- is_no = 1;
- else if(unformat (line_input, "prefix %U/%d",
- unformat_ip6_address, &ip6_addr,
- &addr_len))
+ is_no = 1;
+ else if (unformat (line_input, "prefix %U/%d",
+ unformat_ip6_address, &ip6_addr, &addr_len))
{
add_radv_info = 0;
break;
@@ -2710,13 +2908,13 @@ ip6_neighbor_cmd(vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_comma
break;
}
else if (unformat (line_input, "ra-suppress") ||
- unformat (line_input, "ra-surpress"))
+ unformat (line_input, "ra-surpress"))
{
suppress = 1;
break;
}
else if (unformat (line_input, "ra-suppress-link-layer") ||
- unformat (line_input, "ra-surpress-link-layer"))
+ unformat (line_input, "ra-surpress-link-layer"))
{
suppress_ll_option = 1;
break;
@@ -2729,70 +2927,70 @@ ip6_neighbor_cmd(vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_comma
else if (unformat (line_input, "ra-lifetime"))
{
if (!unformat (line_input, "%d", &ra_lifetime))
- return(error = unformat_parse_error (line_input));
+ return (error = unformat_parse_error (line_input));
use_lifetime = 1;
break;
- }
+ }
else if (unformat (line_input, "ra-initial"))
{
- if (!unformat (line_input, "%d %d", &ra_initial_count, &ra_initial_interval))
- return(error = unformat_parse_error (line_input));
+ if (!unformat
+ (line_input, "%d %d", &ra_initial_count, &ra_initial_interval))
+ return (error = unformat_parse_error (line_input));
break;
}
else if (unformat (line_input, "ra-interval"))
{
if (!unformat (line_input, "%d", &ra_max_interval))
- return(error = unformat_parse_error (line_input));
+ return (error = unformat_parse_error (line_input));
if (!unformat (line_input, "%d", &ra_min_interval))
ra_min_interval = 0;
break;
}
- else if(unformat (line_input, "ra-cease"))
+ else if (unformat (line_input, "ra-cease"))
{
cease = 1;
break;
}
else
- return(unformat_parse_error (line_input));
+ return (unformat_parse_error (line_input));
}
- if(add_radv_info)
+ if (add_radv_info)
{
- ip6_neighbor_ra_config(vm, sw_if_index,
- suppress, managed, other,
- suppress_ll_option, send_unicast, cease,
- use_lifetime, ra_lifetime,
- ra_initial_count, ra_initial_interval,
- ra_max_interval, ra_min_interval,
- is_no);
+ ip6_neighbor_ra_config (vm, sw_if_index,
+ suppress, managed, other,
+ suppress_ll_option, send_unicast, cease,
+ use_lifetime, ra_lifetime,
+ ra_initial_count, ra_initial_interval,
+ ra_max_interval, ra_min_interval, is_no);
}
else
{
- u32 valid_lifetime_in_secs = 0;
+ u32 valid_lifetime_in_secs = 0;
u32 pref_lifetime_in_secs = 0;
u8 use_prefix_default_values = 0;
- u8 no_advertise = 0;
- u8 off_link= 0;
+ u8 no_advertise = 0;
+ u8 off_link = 0;
u8 no_autoconfig = 0;
- u8 no_onlink= 0;
+ u8 no_onlink = 0;
/* get the rest of the command */
- while(unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if(unformat (line_input, "default"))
+ if (unformat (line_input, "default"))
{
use_prefix_default_values = 1;
break;
}
- else if(unformat (line_input, "infinite"))
+ else if (unformat (line_input, "infinite"))
{
- valid_lifetime_in_secs = ~0;
+ valid_lifetime_in_secs = ~0;
pref_lifetime_in_secs = ~0;
break;
}
- else if(unformat (line_input, "%d %d", &valid_lifetime_in_secs,
- &pref_lifetime_in_secs))
+ else if (unformat (line_input, "%d %d", &valid_lifetime_in_secs,
+ &pref_lifetime_in_secs))
break;
else
break;
@@ -2803,104 +3001,103 @@ ip6_neighbor_cmd(vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_comma
while (!use_prefix_default_values &&
unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if(unformat (line_input, "no-advertise"))
+ if (unformat (line_input, "no-advertise"))
no_advertise = 1;
- else if(unformat (line_input, "off-link"))
+ else if (unformat (line_input, "off-link"))
off_link = 1;
- else if(unformat (line_input, "no-autoconfig"))
+ else if (unformat (line_input, "no-autoconfig"))
no_autoconfig = 1;
- else if(unformat (line_input, "no-onlink"))
+ else if (unformat (line_input, "no-onlink"))
no_onlink = 1;
else
- return(unformat_parse_error (line_input));
+ return (unformat_parse_error (line_input));
}
-
- ip6_neighbor_ra_prefix(vm, sw_if_index,
- &ip6_addr, addr_len,
- use_prefix_default_values,
- valid_lifetime_in_secs,
- pref_lifetime_in_secs,
- no_advertise,
- off_link,
- no_autoconfig,
- no_onlink,
- is_no);
+
+ ip6_neighbor_ra_prefix (vm, sw_if_index,
+ &ip6_addr, addr_len,
+ use_prefix_default_values,
+ valid_lifetime_in_secs,
+ pref_lifetime_in_secs,
+ no_advertise,
+ off_link, no_autoconfig, no_onlink, is_no);
}
unformat_free (line_input);
-
- done:
+
+done:
return error;
}
static void
-ip6_print_addrs(vlib_main_t * vm,
- u32 *addrs)
+ip6_print_addrs (vlib_main_t * vm, u32 * addrs)
{
- ip_lookup_main_t * lm = &ip6_main.lookup_main;
+ ip_lookup_main_t *lm = &ip6_main.lookup_main;
u32 i;
for (i = 0; i < vec_len (addrs); i++)
{
- ip_interface_address_t * a = pool_elt_at_index(lm->if_address_pool, addrs[i]);
- ip6_address_t * address = ip_interface_address_get_address (lm, a);
+ ip_interface_address_t *a =
+ pool_elt_at_index (lm->if_address_pool, addrs[i]);
+ ip6_address_t *address = ip_interface_address_get_address (lm, a);
vlib_cli_output (vm, "\t\t%U/%d",
- format_ip6_address, address,
- a->address_length);
+ format_ip6_address, address, a->address_length);
}
}
static clib_error_t *
show_ip6_interface_cmd (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ clib_error_t *error = 0;
u32 sw_if_index;
sw_if_index = ~0;
- if (unformat_user (input,
- unformat_vnet_sw_interface, vnm, &sw_if_index))
+ if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
u32 ri;
-
+
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
-
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
+
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
-
- if(ri != ~0)
+
+ if (ri != ~0)
{
- ip_lookup_main_t * lm = &ip6_main.lookup_main;
- ip6_radv_t * radv_info;
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ ip_lookup_main_t *lm = &ip6_main.lookup_main;
+ ip6_radv_t *radv_info;
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
- vlib_cli_output (vm, "%U is admin %s\n", format_vnet_sw_interface_name, vnm,
+ vlib_cli_output (vm, "%U is admin %s\n",
+ format_vnet_sw_interface_name, vnm,
vnet_get_sw_interface (vnm, sw_if_index),
- (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ? "up" : "down"));
-
+ (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ?
+ "up" : "down"));
+
u32 ai;
u32 *link_scope = 0, *global_scope = 0;
u32 *local_scope = 0, *unknown_scope = 0;
- ip_interface_address_t * a;
+ ip_interface_address_t *a;
- vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
- while (ai != (u32)~0)
+ while (ai != (u32) ~ 0)
{
- a = pool_elt_at_index(lm->if_address_pool, ai);
- ip6_address_t * address = ip_interface_address_get_address (lm, a);
+ a = pool_elt_at_index (lm->if_address_pool, ai);
+ ip6_address_t *address =
+ ip_interface_address_get_address (lm, a);
if (ip6_address_is_link_local_unicast (address))
vec_add1 (link_scope, ai);
- else if(ip6_address_is_global_unicast (address))
+ else if (ip6_address_is_global_unicast (address))
vec_add1 (global_scope, ai);
- else if(ip6_address_is_local_unicast (address))
+ else if (ip6_address_is_local_unicast (address))
vec_add1 (local_scope, ai);
else
vec_add1 (unknown_scope, ai);
@@ -2908,48 +3105,55 @@ show_ip6_interface_cmd (vlib_main_t * vm,
ai = a->next_this_sw_interface;
}
- if (vec_len (link_scope))
- {
- vlib_cli_output (vm, "\tLink-local address(es):\n");
- ip6_print_addrs (vm, link_scope);
- vec_free (link_scope);
- }
-
- if (vec_len (local_scope))
- {
- vlib_cli_output (vm, "\tLocal unicast address(es):\n");
- ip6_print_addrs (vm, local_scope);
- vec_free (local_scope);
- }
-
- if (vec_len (global_scope))
- {
- vlib_cli_output (vm, "\tGlobal unicast address(es):\n");
- ip6_print_addrs (vm, global_scope);
- vec_free (global_scope);
- }
-
- if (vec_len (unknown_scope))
- {
- vlib_cli_output (vm, "\tOther-scope address(es):\n");
- ip6_print_addrs (vm, unknown_scope);
- vec_free (unknown_scope);
- }
+ if (vec_len (link_scope))
+ {
+ vlib_cli_output (vm, "\tLink-local address(es):\n");
+ ip6_print_addrs (vm, link_scope);
+ vec_free (link_scope);
+ }
+
+ if (vec_len (local_scope))
+ {
+ vlib_cli_output (vm, "\tLocal unicast address(es):\n");
+ ip6_print_addrs (vm, local_scope);
+ vec_free (local_scope);
+ }
+
+ if (vec_len (global_scope))
+ {
+ vlib_cli_output (vm, "\tGlobal unicast address(es):\n");
+ ip6_print_addrs (vm, global_scope);
+ vec_free (global_scope);
+ }
+
+ if (vec_len (unknown_scope))
+ {
+ vlib_cli_output (vm, "\tOther-scope address(es):\n");
+ ip6_print_addrs (vm, unknown_scope);
+ vec_free (unknown_scope);
+ }
vlib_cli_output (vm, "\tJoined group address(es):\n");
ip6_mldp_group_t *m;
- pool_foreach (m, radv_info->mldp_group_pool, ({
- vlib_cli_output (vm, "\t\t%U\n", format_ip6_address, &m->mcast_address);
- }));
+ /* *INDENT-OFF* */
+ pool_foreach (m, radv_info->mldp_group_pool,
+ ({
+ vlib_cli_output (vm, "\t\t%U\n", format_ip6_address,
+ &m->mcast_address);
+ }));
+ /* *INDENT-ON* */
vlib_cli_output (vm, "\tAdvertised Prefixes:\n");
- ip6_radv_prefix_t * p;
- pool_foreach (p, radv_info->adv_prefixes_pool, ({
- vlib_cli_output (vm, "\t\tprefix %U, length %d\n",
- format_ip6_address, &p->prefix, p->prefix_len);
- }));
-
- vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu);
+ ip6_radv_prefix_t *p;
+ /* *INDENT-OFF* */
+ pool_foreach (p, radv_info->adv_prefixes_pool,
+ ({
+ vlib_cli_output (vm, "\t\tprefix %U, length %d\n",
+ format_ip6_address, &p->prefix, p->prefix_len);
+ }));
+ /* *INDENT-ON* */
+
+ vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu);
vlib_cli_output (vm, "\tICMP error messages are unlimited\n");
vlib_cli_output (vm, "\tICMP redirects are disabled\n");
vlib_cli_output (vm, "\tICMP unreachables are not sent\n");
@@ -2957,20 +3161,29 @@ show_ip6_interface_cmd (vlib_main_t * vm,
//vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",);
vlib_cli_output (vm, "\tND advertised reachable time is %d\n",
radv_info->adv_neighbor_reachable_time_in_msec);
- vlib_cli_output (vm, "\tND advertised retransmit interval is %d (msec)\n",
- radv_info->adv_time_in_msec_between_retransmitted_neighbor_solicitations);
+ vlib_cli_output (vm,
+ "\tND advertised retransmit interval is %d (msec)\n",
+ radv_info->
+ adv_time_in_msec_between_retransmitted_neighbor_solicitations);
u32 ra_interval = radv_info->max_radv_interval;
u32 ra_interval_min = radv_info->min_radv_interval;
- vlib_cli_output (vm, "\tND router advertisements are sent every %d seconds (min interval is %d)\n",
+ vlib_cli_output (vm,
+ "\tND router advertisements are sent every %d seconds (min interval is %d)\n",
ra_interval, ra_interval_min);
- vlib_cli_output (vm, "\tND router advertisements live for %d seconds\n",
+ vlib_cli_output (vm,
+ "\tND router advertisements live for %d seconds\n",
radv_info->adv_router_lifetime_in_sec);
- vlib_cli_output (vm, "\tHosts %s stateless autoconfig for addresses\n",
- (radv_info->adv_managed_flag) ? "use" :" don't use");
- vlib_cli_output (vm, "\tND router advertisements sent %d\n", radv_info->n_advertisements_sent);
- vlib_cli_output (vm, "\tND router solicitations received %d\n", radv_info->n_solicitations_rcvd);
- vlib_cli_output (vm, "\tND router solicitations dropped %d\n", radv_info->n_solicitations_dropped);
+ vlib_cli_output (vm,
+ "\tHosts %s stateless autoconfig for addresses\n",
+ (radv_info->adv_managed_flag) ? "use" :
+ " don't use");
+ vlib_cli_output (vm, "\tND router advertisements sent %d\n",
+ radv_info->n_advertisements_sent);
+ vlib_cli_output (vm, "\tND router solicitations received %d\n",
+ radv_info->n_solicitations_rcvd);
+ vlib_cli_output (vm, "\tND router solicitations dropped %d\n",
+ radv_info->n_solicitations_dropped);
}
else
{
@@ -3019,7 +3232,8 @@ show_ip6_interface_cmd (vlib_main_t * vm,
* @cliexend
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_ip6_interface_command, static) = {
+VLIB_CLI_COMMAND (show_ip6_interface_command, static) =
+{
.path = "show ip6 interface",
.function = show_ip6_interface_cmd,
.short_help = "show ip6 interface <interface>",
@@ -3027,133 +3241,141 @@ VLIB_CLI_COMMAND (show_ip6_interface_command, static) = {
/* *INDENT-ON* */
clib_error_t *
-disable_ip6_interface(vlib_main_t * vm,
- u32 sw_if_index)
+disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
{
- clib_error_t * error = 0;
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ clib_error_t *error = 0;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
u32 ri;
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
-
+
/* if not created - do nothing */
- if(ri != ~0)
+ if (ri != ~0)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_radv_t * radv_info;
-
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_radv_t *radv_info;
+
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
/* check radv_info ref count for other ip6 addresses on this interface */
- if(radv_info->ref_count == 0 )
+ if (radv_info->ref_count == 0)
{
/* essentially "disables" ipv6 on this interface */
error = ip6_add_del_interface_address (vm, sw_if_index,
- &radv_info->link_local_address,
- radv_info->link_local_prefix_len,
- 1 /* is_del */);
-
- ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0/* is_add */);
+ &radv_info->
+ link_local_address,
+ radv_info->
+ link_local_prefix_len,
+ 1 /* is_del */ );
+
+ ip6_neighbor_sw_interface_add_del (vnm, sw_if_index,
+ 0 /* is_add */ );
}
}
return error;
}
int
-ip6_interface_enabled(vlib_main_t * vm,
- u32 sw_if_index)
+ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- u32 ri = ~0;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ u32 ri = ~0;
- /* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
+ /* look up the radv_t information for this interface */
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
- ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
+ ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
- return ri != ~0;
+ return ri != ~0;
}
-clib_error_t *
-enable_ip6_interface(vlib_main_t * vm,
- u32 sw_if_index)
+clib_error_t *
+enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
{
- clib_error_t * error = 0;
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ clib_error_t *error = 0;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
u32 ri;
int is_add = 1;
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
-
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
+ ~0);
+
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
-
+
/* if not created yet */
- if(ri == ~0)
+ if (ri == ~0)
{
- vnet_main_t * vnm = vnet_get_main();
- vnet_sw_interface_t * sw_if0;
-
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_sw_interface_t *sw_if0;
+
sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
- if(sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
+ if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
{
- ethernet_interface_t * eth_if0;
+ ethernet_interface_t *eth_if0;
- eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
- if(eth_if0)
+ eth_if0 =
+ ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
+ if (eth_if0)
{
/* create radv_info. for this interface. This holds all the info needed for router adverts */
- ri = ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add);
+ ri =
+ ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add);
- if(ri != ~0)
+ if (ri != ~0)
{
- ip6_radv_t * radv_info;
+ ip6_radv_t *radv_info;
ip6_address_t link_local_address;
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
- ip6_link_local_address_from_ethernet_mac_address (&link_local_address,
- eth_if0->address);
+ ip6_link_local_address_from_ethernet_mac_address
+ (&link_local_address, eth_if0->address);
sw_if0 = vnet_get_sw_interface (vnm, sw_if_index);
- if(sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB)
+ if (sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB)
{
/* make up an interface id */
md5_context_t m;
u8 digest[16];
-
+
link_local_address.as_u64[0] = radv_info->randomizer;
-
+
md5_init (&m);
md5_add (&m, &link_local_address, 16);
- md5_finish (&m, digest);
-
- clib_memcpy(&link_local_address, digest, 16);
-
+ md5_finish (&m, digest);
+
+ clib_memcpy (&link_local_address, digest, 16);
+
radv_info->randomizer = link_local_address.as_u64[0];
-
- link_local_address.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
+
+ link_local_address.as_u64[0] =
+ clib_host_to_net_u64 (0xFE80000000000000ULL);
/* clear u bit */
link_local_address.as_u8[8] &= 0xfd;
}
-
+
/* essentially "enables" ipv6 on this interface */
error = ip6_add_del_interface_address (vm, sw_if_index,
&link_local_address,
- 128 /* address width */,
- 0 /* is_del */);
-
- if(error)
- ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, !is_add);
+ 128
+ /* address width */ ,
+ 0 /* is_del */ );
+
+ if (error)
+ ip6_neighbor_sw_interface_add_del (vnm, sw_if_index,
+ !is_add);
else
{
- radv_info->link_local_address = link_local_address;
- radv_info->link_local_prefix_len = 64;
+ radv_info->link_local_address = link_local_address;
+ radv_info->link_local_prefix_len = 64;
}
}
- }
+ }
}
}
return error;
@@ -3161,26 +3383,24 @@ enable_ip6_interface(vlib_main_t * vm,
static clib_error_t *
enable_ip6_interface_cmd (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *error = 0;
u32 sw_if_index;
sw_if_index = ~0;
- if (unformat_user (input,
- unformat_vnet_sw_interface, vnm, &sw_if_index))
+ if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
- enable_ip6_interface(vm, sw_if_index);
+ enable_ip6_interface (vm, sw_if_index);
+ }
+ else
+ {
+ error = clib_error_return (0, "unknown interface\n'",
+ format_unformat_error, input);
+
}
- else
- {
- error = clib_error_return (0, "unknown interface\n'",
- format_unformat_error, input);
-
- }
return error;
}
@@ -3192,7 +3412,8 @@ enable_ip6_interface_cmd (vlib_main_t * vm,
* @cliexcmd{enable ip6 interface GigabitEthernet2/0/0}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (enable_ip6_interface_command, static) = {
+VLIB_CLI_COMMAND (enable_ip6_interface_command, static) =
+{
.path = "enable ip6 interface",
.function = enable_ip6_interface_cmd,
.short_help = "enable ip6 interface <interface>",
@@ -3201,26 +3422,24 @@ VLIB_CLI_COMMAND (enable_ip6_interface_command, static) = {
static clib_error_t *
disable_ip6_interface_cmd (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *error = 0;
u32 sw_if_index;
sw_if_index = ~0;
- if (unformat_user (input,
- unformat_vnet_sw_interface, vnm, &sw_if_index))
+ if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
- error = disable_ip6_interface(vm, sw_if_index);
+ error = disable_ip6_interface (vm, sw_if_index);
+ }
+ else
+ {
+ error = clib_error_return (0, "unknown interface\n'",
+ format_unformat_error, input);
+
}
- else
- {
- error = clib_error_return (0, "unknown interface\n'",
- format_unformat_error, input);
-
- }
return error;
}
@@ -3232,7 +3451,8 @@ disable_ip6_interface_cmd (vlib_main_t * vm,
* @cliexcmd{disable ip6 interface GigabitEthernet2/0/0}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (disable_ip6_interface_command, static) = {
+VLIB_CLI_COMMAND (disable_ip6_interface_command, static) =
+{
.path = "disable ip6 interface",
.function = disable_ip6_interface_cmd,
.short_help = "disable ip6 interface <interface>",
@@ -3355,7 +3575,8 @@ VLIB_CLI_COMMAND (disable_ip6_interface_command, static) = {
* @cliexcmd{ip6 nd GigabitEthernet2/0/0 no prefix fe80::fe:28ff:fe9c:75b3/64}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (ip6_nd_command, static) = {
+VLIB_CLI_COMMAND (ip6_nd_command, static) =
+{
.path = "ip6 nd",
.short_help = "ip6 nd <interface> ...",
.function = ip6_neighbor_cmd,
@@ -3363,53 +3584,53 @@ VLIB_CLI_COMMAND (ip6_nd_command, static) = {
/* *INDENT-ON* */
clib_error_t *
-set_ip6_link_local_address(vlib_main_t * vm,
- u32 sw_if_index,
- ip6_address_t *address,
- u8 address_length)
+set_ip6_link_local_address (vlib_main_t * vm,
+ u32 sw_if_index,
+ ip6_address_t * address, u8 address_length)
{
- clib_error_t * error = 0;
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ clib_error_t *error = 0;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
u32 ri;
- ip6_radv_t * radv_info;
- vnet_main_t * vnm = vnet_get_main();
+ ip6_radv_t *radv_info;
+ vnet_main_t *vnm = vnet_get_main ();
- if( !ip6_address_is_link_local_unicast (address))
+ if (!ip6_address_is_link_local_unicast (address))
{
vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_LINK_LOCAL;
- return(error = clib_error_return (0, "address not link-local",
- format_unformat_error));
+ return (error = clib_error_return (0, "address not link-local",
+ format_unformat_error));
}
/* call enable ipv6 */
- enable_ip6_interface(vm, sw_if_index);
-
+ enable_ip6_interface (vm, sw_if_index);
+
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
-
- if(ri != ~0)
+
+ if (ri != ~0)
{
- radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
+ radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
/* save if link local address (overwrite default) */
-
+
/* delete the old one */
error = ip6_add_del_interface_address (vm, sw_if_index,
&radv_info->link_local_address,
- radv_info->link_local_prefix_len /* address width */,
- 1 /* is_del */);
-
- if(!error)
+ radv_info->link_local_prefix_len
+ /* address width */ ,
+ 1 /* is_del */ );
+
+ if (!error)
{
/* add the new one */
error = ip6_add_del_interface_address (vm, sw_if_index,
- address ,
- address_length /* address width */,
- 0/* is_del */);
-
- if(!error)
+ address, address_length
+ /* address width */ ,
+ 0 /* is_del */ );
+
+ if (!error)
{
radv_info->link_local_address = *address;
- radv_info->link_local_prefix_len = address_length;
+ radv_info->link_local_prefix_len = address_length;
}
}
}
@@ -3421,36 +3642,31 @@ set_ip6_link_local_address(vlib_main_t * vm,
}
return error;
}
-
+
clib_error_t *
set_ip6_link_local_address_cmd (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *error = 0;
u32 sw_if_index;
ip6_address_t ip6_addr;
u32 addr_len = 0;
-
- if (unformat_user (input,
- unformat_vnet_sw_interface, vnm, &sw_if_index))
+
+ if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
/* get the rest of the command */
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
- if(unformat (input, "%U/%d",
- unformat_ip6_address, &ip6_addr,
- &addr_len))
+ if (unformat (input, "%U/%d",
+ unformat_ip6_address, &ip6_addr, &addr_len))
break;
else
- return(unformat_parse_error (input));
+ return (unformat_parse_error (input));
}
}
- error = set_ip6_link_local_address(vm,
- sw_if_index,
- &ip6_addr,
- addr_len);
+ error = set_ip6_link_local_address (vm, sw_if_index, &ip6_addr, addr_len);
return error;
}
@@ -3465,7 +3681,8 @@ set_ip6_link_local_address_cmd (vlib_main_t * vm,
* @cliexcmd{set ip6 link-local address GigabitEthernet2/0/0 FE80::AB8/64}
?*/
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) = {
+VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) =
+{
.path = "set ip6 link-local address",
.short_help = "set ip6 link-local address <interface> <ip6-address>/<width>",
.function = set_ip6_link_local_address_cmd,
@@ -3479,60 +3696,63 @@ ip6_neighbor_add_del_interface_address (ip6_main_t * im,
u32 sw_if_index,
ip6_address_t * address,
u32 address_length,
- u32 if_address_index,
- u32 is_delete)
+ u32 if_address_index, u32 is_delete)
{
- vnet_main_t * vnm = vnet_get_main();
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
u32 ri;
- vlib_main_t * vm = vnm->vlib_main;
- ip6_radv_t * radv_info;
+ vlib_main_t *vm = vnm->vlib_main;
+ ip6_radv_t *radv_info;
ip6_address_t a;
- ip6_mldp_group_t *mcast_group_info;
+ ip6_mldp_group_t *mcast_group_info;
/* create solicited node multicast address for this interface adddress */
ip6_set_solicited_node_multicast_address (&a, 0);
-
+
a.as_u8[0xd] = address->as_u8[0xd];
a.as_u8[0xe] = address->as_u8[0xe];
a.as_u8[0xf] = address->as_u8[0xf];
-
- if(!is_delete)
+
+ if (!is_delete)
{
/* try to create radv_info - does nothing if ipv6 already enabled */
- enable_ip6_interface(vm, sw_if_index);
+ enable_ip6_interface (vm, sw_if_index);
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
- if(ri != ~0)
+ if (ri != ~0)
{
/* get radv_info */
radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
/* add address */
- if( !ip6_address_is_link_local_unicast (address))
+ if (!ip6_address_is_link_local_unicast (address))
radv_info->ref_count++;
/* lookup prefix info for this address on this interface */
- uword * p = mhash_get (&radv_info->address_to_mldp_index, &a);
- mcast_group_info = p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
+ uword *p = mhash_get (&radv_info->address_to_mldp_index, &a);
+ mcast_group_info =
+ p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
/* add -solicted node multicast address */
- if(!mcast_group_info)
+ if (!mcast_group_info)
{
/* add */
u32 mi;
pool_get (radv_info->mldp_group_pool, mcast_group_info);
-
+
mi = mcast_group_info - radv_info->mldp_group_pool;
- mhash_set (&radv_info->address_to_mldp_index, &a, mi, /* old_value */ 0);
-
+ mhash_set (&radv_info->address_to_mldp_index, &a, mi,
+ /* old_value */ 0);
+
mcast_group_info->type = 4;
mcast_group_info->mcast_source_address_pool = 0;
mcast_group_info->num_sources = 0;
- clib_memcpy(&mcast_group_info->mcast_address, &a, sizeof(ip6_address_t));
- }
+ clib_memcpy (&mcast_group_info->mcast_address, &a,
+ sizeof (ip6_address_t));
+ }
}
}
else
@@ -3540,20 +3760,23 @@ ip6_neighbor_add_del_interface_address (ip6_main_t * im,
/* delete */
/* look up the radv_t information for this interface */
- vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
- if(ri != ~0)
+ if (ri != ~0)
{
/* get radv_info */
radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
/* lookup prefix info for this address on this interface */
- uword * p = mhash_get (&radv_info->address_to_mldp_index, &a);
- mcast_group_info = p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
-
- if(mcast_group_info)
+ uword *p = mhash_get (&radv_info->address_to_mldp_index, &a);
+ mcast_group_info =
+ p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
+
+ if (mcast_group_info)
{
- mhash_unset (&radv_info->address_to_mldp_index, &a,/* old_value */ 0);
+ mhash_unset (&radv_info->address_to_mldp_index, &a,
+ /* old_value */ 0);
pool_put (radv_info->mldp_group_pool, mcast_group_info);
}
@@ -3561,41 +3784,47 @@ ip6_neighbor_add_del_interface_address (ip6_main_t * im,
radv_info->all_routers_mcast = 0;
/* add address */
- if( !ip6_address_is_link_local_unicast (address))
+ if (!ip6_address_is_link_local_unicast (address))
radv_info->ref_count--;
}
}
}
-clib_error_t *ip6_set_neighbor_limit (u32 neighbor_limit)
+clib_error_t *
+ip6_set_neighbor_limit (u32 neighbor_limit)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
nm->limit_neighbor_cache_size = neighbor_limit;
return 0;
}
-static clib_error_t * ip6_neighbor_init (vlib_main_t * vm)
+static clib_error_t *
+ip6_neighbor_init (vlib_main_t * vm)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_main_t * im = &ip6_main;
-
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_main_t *im = &ip6_main;
+
mhash_init (&nm->neighbor_index_by_key,
/* value size */ sizeof (uword),
/* key size */ sizeof (ip6_neighbor_key_t));
- icmp6_register_type (vm, ICMP6_neighbor_solicitation, ip6_icmp_neighbor_solicitation_node.index);
- icmp6_register_type (vm, ICMP6_neighbor_advertisement, ip6_icmp_neighbor_advertisement_node.index);
- icmp6_register_type (vm, ICMP6_router_solicitation, ip6_icmp_router_solicitation_node.index);
- icmp6_register_type (vm, ICMP6_router_advertisement, ip6_icmp_router_advertisement_node.index);
+ icmp6_register_type (vm, ICMP6_neighbor_solicitation,
+ ip6_icmp_neighbor_solicitation_node.index);
+ icmp6_register_type (vm, ICMP6_neighbor_advertisement,
+ ip6_icmp_neighbor_advertisement_node.index);
+ icmp6_register_type (vm, ICMP6_router_solicitation,
+ ip6_icmp_router_solicitation_node.index);
+ icmp6_register_type (vm, ICMP6_router_advertisement,
+ ip6_icmp_router_advertisement_node.index);
/* handler node for ip6 neighbor discovery events and timers */
vlib_register_node (vm, &ip6_icmp_neighbor_discovery_event_node);
/* add call backs */
- ip6_add_del_interface_address_callback_t cb;
- memset(&cb, 0x0, sizeof(ip6_add_del_interface_address_callback_t));
-
+ ip6_add_del_interface_address_callback_t cb;
+ memset (&cb, 0x0, sizeof (ip6_add_del_interface_address_callback_t));
+
/* when an interface address changes... */
cb.function = ip6_neighbor_add_del_interface_address;
cb.function_opaque = 0;
@@ -3614,8 +3843,8 @@ static clib_error_t * ip6_neighbor_init (vlib_main_t * vm)
#if 0
/* $$$$ Hack fix for today */
- vec_validate_init_empty
- (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */);
+ vec_validate_init_empty
+ (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */ );
#endif
return 0;
@@ -3624,17 +3853,17 @@ static clib_error_t * ip6_neighbor_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (ip6_neighbor_init);
-void vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
- void * address_arg,
- uword node_index,
- uword type_opaque,
- uword data)
+void
+vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
+ void *address_arg,
+ uword node_index,
+ uword type_opaque, uword data)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_address_t * address = address_arg;
- uword * p;
- pending_resolution_t * pr;
-
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_address_t *address = address_arg;
+ uword *p;
+ pending_resolution_t *pr;
+
pool_get (nm->pending_resolutions, pr);
pr->next_index = ~0;
@@ -3649,26 +3878,25 @@ void vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
pr->next_index = p[0];
mhash_unset (&nm->pending_resolutions_by_address, address, 0);
}
-
- mhash_set (&nm->pending_resolutions_by_address, address,
- pr - nm->pending_resolutions, 0 /* old value */);
+
+ mhash_set (&nm->pending_resolutions_by_address, address,
+ pr - nm->pending_resolutions, 0 /* old value */ );
}
-int vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
- void * data_callback,
- u32 pid,
- void * address_arg,
- uword node_index,
- uword type_opaque,
- uword data,
- int is_add)
-{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_address_t * address = address_arg;
- uword * p;
- pending_resolution_t * mc;
- void (*fp)(u32, u8 *) = data_callback;
-
+int
+vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
+ void *data_callback,
+ u32 pid,
+ void *address_arg,
+ uword node_index,
+ uword type_opaque, uword data, int is_add)
+{
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_address_t *address = address_arg;
+ uword *p;
+ pending_resolution_t *mc;
+ void (*fp) (u32, u8 *) = data_callback;
+
if (is_add)
{
pool_get (nm->mac_changes, mc);
@@ -3679,83 +3907,80 @@ int vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
mc->data = data;
mc->data_callback = data_callback;
mc->pid = pid;
-
+
p = mhash_get (&nm->mac_changes_by_address, address);
if (p)
- {
- /* Insert new resolution at the head of the list */
- mc->next_index = p[0];
- mhash_unset (&nm->mac_changes_by_address, address, 0);
- }
-
- mhash_set (&nm->mac_changes_by_address, address,
+ {
+ /* Insert new resolution at the head of the list */
+ mc->next_index = p[0];
+ mhash_unset (&nm->mac_changes_by_address, address, 0);
+ }
+
+ mhash_set (&nm->mac_changes_by_address, address,
mc - nm->mac_changes, 0);
return 0;
}
else
{
u32 index;
- pending_resolution_t * mc_last = 0;
+ pending_resolution_t *mc_last = 0;
p = mhash_get (&nm->mac_changes_by_address, address);
if (p == 0)
- return VNET_API_ERROR_NO_SUCH_ENTRY;
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
index = p[0];
- while (index != (u32)~0)
- {
- mc = pool_elt_at_index (nm->mac_changes, index);
- if (mc->node_index == node_index &&
- mc->type_opaque == type_opaque &&
- mc->pid == pid)
- {
- /* Clients may need to clean up pool entries, too */
- if (fp)
- (*fp)(mc->data, 0 /* no new mac addrs */);
- if (index == p[0])
- {
+ while (index != (u32) ~ 0)
+ {
+ mc = pool_elt_at_index (nm->mac_changes, index);
+ if (mc->node_index == node_index &&
+ mc->type_opaque == type_opaque && mc->pid == pid)
+ {
+ /* Clients may need to clean up pool entries, too */
+ if (fp)
+ (*fp) (mc->data, 0 /* no new mac addrs */ );
+ if (index == p[0])
+ {
mhash_unset (&nm->mac_changes_by_address, address, 0);
- if (mc->next_index != ~0)
- mhash_set (&nm->mac_changes_by_address, address,
+ if (mc->next_index != ~0)
+ mhash_set (&nm->mac_changes_by_address, address,
mc->next_index, 0);
- pool_put (nm->mac_changes, mc);
- return 0;
- }
- else
- {
- ASSERT(mc_last);
- mc_last->next_index = mc->next_index;
- pool_put (nm->mac_changes, mc);
- return 0;
- }
- }
- mc_last = mc;
- index = mc->next_index;
- }
-
+ pool_put (nm->mac_changes, mc);
+ return 0;
+ }
+ else
+ {
+ ASSERT (mc_last);
+ mc_last->next_index = mc->next_index;
+ pool_put (nm->mac_changes, mc);
+ return 0;
+ }
+ }
+ mc_last = mc;
+ index = mc->next_index;
+ }
+
return VNET_API_ERROR_NO_SUCH_ENTRY;
}
}
-int vnet_ip6_nd_term (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_buffer_t * p0,
- ethernet_header_t * eth,
- ip6_header_t * ip,
- u32 sw_if_index,
- u16 bd_index,
- u8 shg)
-{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- icmp6_neighbor_solicitation_or_advertisement_header_t * ndh;
- pending_resolution_t * mc;
+int
+vnet_ip6_nd_term (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_buffer_t * p0,
+ ethernet_header_t * eth,
+ ip6_header_t * ip, u32 sw_if_index, u16 bd_index, u8 shg)
+{
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ icmp6_neighbor_solicitation_or_advertisement_header_t *ndh;
+ pending_resolution_t *mc;
uword *p;
ndh = ip6_next_header (ip);
if (ndh->icmp.type != ICMP6_neighbor_solicitation &&
ndh->icmp.type != ICMP6_neighbor_advertisement)
- return 0;
+ return 0;
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
(p0->flags & VLIB_BUFFER_IS_TRACED)))
@@ -3767,69 +3992,68 @@ int vnet_ip6_nd_term (vlib_main_t * vm,
/* Check if anyone want ND events for L2 BDs */
p = mhash_get (&nm->mac_changes_by_address, &ip6a_zero);
- if (p && shg == 0 && /* Only SHG 0 interface which is more likely local */
+ if (p && shg == 0 && /* Only SHG 0 interface which is more likely local */
!ip6_address_is_link_local_unicast (&ip->src_address))
- {
+ {
u32 next_index = p[0];
- while (next_index != (u32)~0)
- {
- int (*fp)(u32, u8 *, u32, ip6_address_t *);
+ while (next_index != (u32) ~ 0)
+ {
+ int (*fp) (u32, u8 *, u32, ip6_address_t *);
int rv = 1;
mc = pool_elt_at_index (nm->mac_changes, next_index);
fp = mc->data_callback;
/* Call the callback, return 1 to suppress dup events */
- if (fp) rv = (*fp)(mc->data,
- eth->src_address,
- sw_if_index,
- &ip->src_address);
+ if (fp)
+ rv = (*fp) (mc->data,
+ eth->src_address, sw_if_index, &ip->src_address);
/* Signal the resolver process */
if (rv == 0)
- vlib_process_signal_event (vm, mc->node_index,
- mc->type_opaque,
- mc->data);
+ vlib_process_signal_event (vm, mc->node_index,
+ mc->type_opaque, mc->data);
next_index = mc->next_index;
- }
+ }
}
/* Check if MAC entry exsist for solicited target IP */
if (ndh->icmp.type == ICMP6_neighbor_solicitation)
{
- icmp6_neighbor_discovery_ethernet_link_layer_address_option_t * opt;
+ icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt;
l2_bridge_domain_t *bd_config;
- u8 * macp;
+ u8 *macp;
opt = (void *) (ndh + 1);
- if ((opt->header.type !=
+ if ((opt->header.type !=
ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) ||
(opt->header.n_data_u64s != 1))
- return 0; /* source link layer address option not present */
-
+ return 0; /* source link layer address option not present */
+
bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
- macp = (u8 *) hash_get_mem (bd_config->mac_by_ip6, &ndh->target_address);
+ macp =
+ (u8 *) hash_get_mem (bd_config->mac_by_ip6, &ndh->target_address);
if (macp)
- { /* found ip-mac entry, generate eighbor advertisement response */
+ { /* found ip-mac entry, generate eighbor advertisement response */
int bogus_length;
- vlib_node_runtime_t * error_node =
- vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
ip->dst_address = ip->src_address;
ip->src_address = ndh->target_address;
ip->hop_limit = 255;
opt->header.type =
- ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
+ ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
clib_memcpy (opt->ethernet_address, macp, 6);
ndh->icmp.type = ICMP6_neighbor_advertisement;
ndh->advertisement_flags = clib_host_to_net_u32
- (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
- ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
+ (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
+ ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
ndh->icmp.checksum = 0;
- ndh->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum(vm, p0, ip,
- &bogus_length);
- clib_memcpy(eth->dst_address, eth->src_address, 6);
- clib_memcpy(eth->src_address, macp, 6);
- vlib_error_count (vm, error_node->node_index,
+ ndh->icmp.checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip, &bogus_length);
+ clib_memcpy (eth->dst_address, eth->src_address, 6);
+ clib_memcpy (eth->src_address, macp, 6);
+ vlib_error_count (vm, error_node->node_index,
ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, 1);
- return 1;
- }
+ return 1;
+ }
}
return 0;
@@ -3839,17 +4063,26 @@ int vnet_ip6_nd_term (vlib_main_t * vm,
void
ethernet_ndp_change_mac (vlib_main_t * vm, u32 sw_if_index)
{
- ip6_neighbor_main_t * nm = &ip6_neighbor_main;
- ip6_neighbor_t * n;
+ ip6_neighbor_main_t *nm = &ip6_neighbor_main;
+ ip6_neighbor_t *n;
/* *INDENT-OFF* */
- pool_foreach (n, nm->neighbor_pool, ({
+ pool_foreach (n, nm->neighbor_pool,
+ ({
if (n->key.sw_if_index == sw_if_index)
- {
+ {
adj_nbr_walk_nh6 (sw_if_index,
&n->key.ip6_address,
ip6_nd_mk_complete_walk, n);
- }
+ }
}));
/* *INDENT-ON* */
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_neighbor.h b/vnet/vnet/ip/ip6_neighbor.h
index 2d572089dc2..b2c9f48ae8a 100644
--- a/vnet/vnet/ip/ip6_neighbor.h
+++ b/vnet/vnet/ip/ip6_neighbor.h
@@ -21,13 +21,15 @@
#include <vnet/fib/fib_types.h>
-typedef struct {
+typedef struct
+{
ip6_address_t ip6_address;
u32 sw_if_index;
u32 pad;
} ip6_neighbor_key_t;
-typedef struct {
+typedef struct
+{
ip6_neighbor_key_t key;
u8 link_layer_address[8];
u16 flags;
@@ -37,6 +39,14 @@ typedef struct {
fib_node_index_t fib_entry_index;
} ip6_neighbor_t;
-ip6_neighbor_t * ip6_neighbors_entries (u32 sw_if_index);
+ip6_neighbor_t *ip6_neighbors_entries (u32 sw_if_index);
-#endif /* included_ip6_neighbor_h */
+#endif /* included_ip6_neighbor_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_packet.h b/vnet/vnet/ip/ip6_packet.h
index d29a06942ef..1e551c8b67d 100644
--- a/vnet/vnet/ip/ip6_packet.h
+++ b/vnet/vnet/ip/ip6_packet.h
@@ -43,21 +43,26 @@
#include <vnet/ip/tcp_packet.h>
#include <vnet/ip/ip4_packet.h>
-typedef union {
+typedef union
+{
u8 as_u8[16];
u16 as_u16[8];
u32 as_u32[4];
u64 as_u64[2];
uword as_uword[16 / sizeof (uword)];
-} ip6_address_t;
+}
+ip6_address_t;
/* Packed so that the mhash key doesn't include uninitialized pad bytes */
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
/* IP address must be first for ip_interface_address_get_address() to work */
ip6_address_t ip6_addr;
u32 fib_index;
}) ip6_address_fib_t;
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
typedef CLIB_PACKED (union {
struct {
u32 pad[3];
@@ -67,6 +72,7 @@ typedef CLIB_PACKED (union {
u8 as_u8[16];
u64 as_u64[2];
}) ip46_address_t;
+/* *INDENT-ON* */
#define ip46_address_is_ip4(ip46) (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0)
#define ip46_address_mask_ip4(ip46) ((ip46)->pad[0] = (ip46)->pad[1] = (ip46)->pad[2] = 0)
#define ip46_address_set_ip4(ip46, ip) (ip46_address_mask_ip4(ip46), (ip46)->ip4 = (ip)[0])
@@ -75,12 +81,12 @@ typedef CLIB_PACKED (union {
#define ip46_address_is_zero(ip46) (((ip46)->as_u64[0] == 0) && ((ip46)->as_u64[1] == 0))
always_inline void
-ip46_from_addr_buf(u32 is_ipv6, u8 *buf, ip46_address_t *ip)
+ip46_from_addr_buf (u32 is_ipv6, u8 * buf, ip46_address_t * ip)
{
if (is_ipv6)
ip->ip6 = *((ip6_address_t *) buf);
else
- ip46_address_set_ip4(ip, (ip4_address_t *) buf);
+ ip46_address_set_ip4 (ip, (ip4_address_t *) buf);
}
always_inline void
@@ -100,7 +106,7 @@ ip6_addr_fib_init (ip6_address_fib_t * addr_fib, ip6_address_t * address,
link local unicast fe80::/10
multicast ff00::/8
ietf reserved everything else. */
-
+
#define foreach_ip6_multicast_address_scope \
_ (loopback, 0x1) \
_ (link_local, 0x2) \
@@ -117,13 +123,15 @@ ip6_addr_fib_init (ip6_address_fib_t * addr_fib, ip6_address_t * address,
_ (pim_routers, 0xd) \
_ (mldv2_routers, 0x16)
-typedef enum {
+typedef enum
+{
#define _(f,n) IP6_MULTICAST_SCOPE_##f = n,
foreach_ip6_multicast_address_scope
#undef _
} ip6_multicast_address_scope_t;
-typedef enum {
+typedef enum
+{
#define _(f,n) IP6_MULTICAST_GROUP_ID_##f = n,
foreach_ip6_multicast_link_local_group_id
#undef _
@@ -131,13 +139,15 @@ typedef enum {
always_inline uword
ip6_address_is_multicast (ip6_address_t * a)
-{ return a->as_u8[0] == 0xff; }
+{
+ return a->as_u8[0] == 0xff;
+}
always_inline uword
ip46_address_is_multicast (ip46_address_t * a)
{
- return ip46_address_is_ip4(a) ? ip4_address_is_multicast(&a->ip4) :
- ip6_address_is_multicast(&a->ip6);
+ return ip46_address_is_ip4 (a) ? ip4_address_is_multicast (&a->ip4) :
+ ip6_address_is_multicast (&a->ip6);
}
always_inline void
@@ -163,7 +173,8 @@ ip6_set_solicited_node_multicast_address (ip6_address_t * a, u32 id)
}
always_inline void
-ip6_link_local_address_from_ethernet_address (ip6_address_t * a, u8 * ethernet_address)
+ip6_link_local_address_from_ethernet_address (ip6_address_t * a,
+ u8 * ethernet_address)
{
a->as_u64[0] = a->as_u64[1] = 0;
a->as_u16[0] = clib_host_to_net_u16 (0xfe80);
@@ -185,8 +196,8 @@ ip6_multicast_ethernet_address (u8 * ethernet_address, u32 group_id)
ethernet_address[1] = 0x33;
ethernet_address[2] = ((group_id >> 24) & 0xff);
ethernet_address[3] = ((group_id >> 16) & 0xff);
- ethernet_address[4] = ((group_id >> 8) & 0xff);
- ethernet_address[5] = ((group_id >> 0) & 0xff);
+ ethernet_address[4] = ((group_id >> 8) & 0xff);
+ ethernet_address[5] = ((group_id >> 0) & 0xff);
}
always_inline uword
@@ -200,8 +211,8 @@ ip6_address_is_equal (ip6_address_t * a, ip6_address_t * b)
}
always_inline uword
-ip6_address_is_equal_masked (ip6_address_t * a, ip6_address_t * b,
- ip6_address_t * mask)
+ip6_address_is_equal_masked (ip6_address_t * a, ip6_address_t * b,
+ ip6_address_t * mask)
{
int i;
for (i = 0; i < ARRAY_LEN (a->as_uword); i++)
@@ -211,7 +222,7 @@ ip6_address_is_equal_masked (ip6_address_t * a, ip6_address_t * b,
b_masked = b->as_uword[i] & mask->as_uword[i];
if (a_masked != b_masked)
- return 0;
+ return 0;
}
return 1;
}
@@ -242,7 +253,7 @@ ip6_address_mask_from_width (ip6_address_t * a, u32 width)
{
bitnum = (7 - (i & 7));
byte = i / 8;
- bit = 1<<bitnum;
+ bit = 1 << bitnum;
a->as_u8[byte] |= bit;
}
}
@@ -260,7 +271,9 @@ ip6_address_is_zero (ip6_address_t * a)
/* Check for unspecified address ::0 */
always_inline uword
ip6_address_is_unspecified (ip6_address_t * a)
-{ return ip6_address_is_zero (a); }
+{
+ return ip6_address_is_zero (a);
+}
/* Check for loopback address ::1 */
always_inline uword
@@ -277,17 +290,23 @@ ip6_address_is_loopback (ip6_address_t * a)
/* Check for link local unicast fe80::/10. */
always_inline uword
ip6_address_is_link_local_unicast (ip6_address_t * a)
-{ return a->as_u8[0] == 0xfe && (a->as_u8[1] & 0xc0) == 0x80; }
+{
+ return a->as_u8[0] == 0xfe && (a->as_u8[1] & 0xc0) == 0x80;
+}
/* Check for unique local unicast fc00::/7. */
always_inline uword
ip6_address_is_local_unicast (ip6_address_t * a)
-{ return (a->as_u8[0] & 0xfe) == 0xfc; }
+{
+ return (a->as_u8[0] & 0xfe) == 0xfc;
+}
/* Check for unique global unicast 2000::/3. */
always_inline uword
ip6_address_is_global_unicast (ip6_address_t * a)
-{ return (a->as_u8[0] & 0xe0) == 0x20; }
+{
+ return (a->as_u8[0] & 0xe0) == 0x20;
+}
/* Check for solicited node multicast 0xff02::1:ff00:0/104 */
always_inline uword
@@ -299,7 +318,8 @@ ip6_is_solicited_node_multicast_address (ip6_address_t * a)
&& a->as_u8[12] == 0xff);
}
-typedef struct {
+typedef struct
+{
/* 4 bit version, 8 bit traffic class and 20 bit flow label. */
u32 ip_version_traffic_class_and_flow_label;
@@ -319,22 +339,23 @@ typedef struct {
always_inline void *
ip6_next_header (ip6_header_t * i)
-{ return (void *) (i + 1); }
+{
+ return (void *) (i + 1);
+}
always_inline void
-ip6_copy_header (ip6_header_t * dst,
- const ip6_header_t *src)
+ip6_copy_header (ip6_header_t * dst, const ip6_header_t * src)
{
- dst->ip_version_traffic_class_and_flow_label =
- src->ip_version_traffic_class_and_flow_label;
- dst->payload_length = src->payload_length;
- dst->protocol = src->protocol;
- dst->hop_limit = src->hop_limit;
-
- dst->src_address.as_uword[0] = src->src_address.as_uword[0];
- dst->src_address.as_uword[1] = src->src_address.as_uword[1];
- dst->dst_address.as_uword[0] = src->dst_address.as_uword[0];
- dst->dst_address.as_uword[1] = src->dst_address.as_uword[1];
+ dst->ip_version_traffic_class_and_flow_label =
+ src->ip_version_traffic_class_and_flow_label;
+ dst->payload_length = src->payload_length;
+ dst->protocol = src->protocol;
+ dst->hop_limit = src->hop_limit;
+
+ dst->src_address.as_uword[0] = src->src_address.as_uword[0];
+ dst->src_address.as_uword[1] = src->src_address.as_uword[1];
+ dst->dst_address.as_uword[0] = src->dst_address.as_uword[0];
+ dst->dst_address.as_uword[1] = src->dst_address.as_uword[1];
}
always_inline void
@@ -391,23 +412,30 @@ ip6_tcp_reply_x2 (ip6_header_t * ip0, ip6_header_t * ip1,
}
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
u8 data;
}) ip6_pad1_option_t;
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
u8 type;
u8 len;
u8 data[0];
}) ip6_padN_option_t;
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
-#define IP6_MLDP_ALERT_TYPE 0x5
+#define IP6_MLDP_ALERT_TYPE 0x5
u8 type;
u8 len;
u16 value;
}) ip6_router_alert_option_t;
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
u8 next_hdr;
/* Length of this header plus option data in 8 byte units. */
@@ -440,13 +468,16 @@ typedef CLIB_PACKED (struct {
u8 n_data_u64s;
u8 data[0];
}) ip6_hop_by_hop_ext_t;
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
u8 next_hdr;
u8 rsv;
u16 fragment_offset_and_more;
u32 identification;
}) ip6_frag_hdr_t;
+/* *INDENT-ON* */
#define ip6_frag_hdr_offset(hdr) \
(clib_net_to_host_u16((hdr)->fragment_offset_and_more) >> 3)
@@ -458,3 +489,11 @@ typedef CLIB_PACKED (struct {
clib_host_to_net_u16(((offset) << 3) + !!(more))
#endif /* included_ip6_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip6_pg.c b/vnet/vnet/ip/ip6_pg.c
index 872f197076a..ba1e4ad9a58 100644
--- a/vnet/vnet/ip/ip6_pg.c
+++ b/vnet/vnet/ip/ip6_pg.c
@@ -43,18 +43,16 @@
static void
ip6_pg_edit_function (pg_main_t * pg,
pg_stream_t * s,
- pg_edit_group_t * g,
- u32 * packets,
- u32 n_packets)
+ pg_edit_group_t * g, u32 * packets, u32 n_packets)
{
- vlib_main_t * vm = vlib_get_main();
+ vlib_main_t *vm = vlib_get_main ();
u32 ip_header_offset = g->start_byte_offset;
while (n_packets >= 2)
{
u32 pi0, pi1;
- vlib_buffer_t * p0, * p1;
- ip6_header_t * ip0, * ip1;
+ vlib_buffer_t *p0, *p1;
+ ip6_header_t *ip0, *ip1;
pi0 = packets[0];
pi1 = packets[1];
@@ -66,15 +64,19 @@ ip6_pg_edit_function (pg_main_t * pg,
ip0 = (void *) (p0->data + ip_header_offset);
ip1 = (void *) (p1->data + ip_header_offset);
- ip0->payload_length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) - ip_header_offset - sizeof (ip0[0]));
- ip1->payload_length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p1) - ip_header_offset - sizeof (ip1[0]));
+ ip0->payload_length =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) -
+ ip_header_offset - sizeof (ip0[0]));
+ ip1->payload_length =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p1) -
+ ip_header_offset - sizeof (ip1[0]));
}
while (n_packets >= 1)
{
u32 pi0;
- vlib_buffer_t * p0;
- ip6_header_t * ip0;
+ vlib_buffer_t *p0;
+ ip6_header_t *ip0;
pi0 = packets[0];
p0 = vlib_get_buffer (vm, pi0);
@@ -83,11 +85,14 @@ ip6_pg_edit_function (pg_main_t * pg,
ip0 = (void *) (p0->data + ip_header_offset);
- ip0->payload_length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) - ip_header_offset - sizeof (ip0[0]));
+ ip0->payload_length =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) -
+ ip_header_offset - sizeof (ip0[0]));
}
}
-typedef struct {
+typedef struct
+{
pg_edit_t ip_version;
pg_edit_t traffic_class;
pg_edit_t flow_label;
@@ -102,32 +107,29 @@ pg_ip6_header_init (pg_ip6_header_t * p)
{
/* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, ip6_header_t, f);
- _ (payload_length);
- _ (hop_limit);
- _ (protocol);
- _ (src_address);
- _ (dst_address);
+ _(payload_length);
+ _(hop_limit);
+ _(protocol);
+ _(src_address);
+ _(dst_address);
#undef _
/* Initialize bit fields. */
pg_edit_init_bitfield (&p->ip_version, ip6_header_t,
- ip_version_traffic_class_and_flow_label,
- 28, 4);
+ ip_version_traffic_class_and_flow_label, 28, 4);
pg_edit_init_bitfield (&p->traffic_class, ip6_header_t,
- ip_version_traffic_class_and_flow_label,
- 20, 8);
+ ip_version_traffic_class_and_flow_label, 20, 8);
pg_edit_init_bitfield (&p->flow_label, ip6_header_t,
- ip_version_traffic_class_and_flow_label,
- 0, 20);
+ ip_version_traffic_class_and_flow_label, 0, 20);
}
uword
unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_ip6_header_t * p;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_ip6_header_t *p;
u32 group_index;
-
+
p = pg_create_edit_group (s, sizeof (p[0]), sizeof (ip6_header_t),
&group_index);
pg_ip6_header_init (p);
@@ -140,21 +142,19 @@ unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
p->payload_length.type = PG_EDIT_UNSPECIFIED;
- if (! unformat (input, "%U: %U -> %U",
- unformat_pg_edit,
- unformat_ip_protocol, &p->protocol,
- unformat_pg_edit,
- unformat_ip6_address, &p->src_address,
- unformat_pg_edit,
- unformat_ip6_address, &p->dst_address))
+ if (!unformat (input, "%U: %U -> %U",
+ unformat_pg_edit,
+ unformat_ip_protocol, &p->protocol,
+ unformat_pg_edit,
+ unformat_ip6_address, &p->src_address,
+ unformat_pg_edit, unformat_ip6_address, &p->dst_address))
goto error;
/* Parse options. */
while (1)
{
if (unformat (input, "version %U",
- unformat_pg_edit,
- unformat_pg_number, &p->ip_version))
+ unformat_pg_edit, unformat_pg_number, &p->ip_version))
;
else if (unformat (input, "traffic-class %U",
@@ -168,8 +168,7 @@ unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
;
else if (unformat (input, "hop-limit %U",
- unformat_pg_edit,
- unformat_pg_number, &p->hop_limit))
+ unformat_pg_edit, unformat_pg_number, &p->hop_limit))
;
/* Can't parse input: try next protocol level. */
@@ -178,9 +177,9 @@ unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
}
{
- ip_main_t * im = &ip_main;
+ ip_main_t *im = &ip_main;
ip_protocol_t protocol;
- ip_protocol_info_t * pi;
+ ip_protocol_info_t *pi;
pi = 0;
if (p->protocol.type == PG_EDIT_FIXED)
@@ -193,7 +192,7 @@ unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
&& unformat_user (input, pi->unformat_pg_edit, s))
;
- else if (! unformat_user (input, unformat_pg_payload, s))
+ else if (!unformat_user (input, unformat_pg_payload, s))
goto error;
if (p->payload_length.type == PG_EDIT_UNSPECIFIED
@@ -201,22 +200,32 @@ unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
&& group_index + 1 < vec_len (s->edit_groups))
{
pg_edit_set_fixed (&p->payload_length,
- pg_edit_group_n_bytes (s, group_index) - sizeof (ip6_header_t));
+ pg_edit_group_n_bytes (s,
+ group_index) -
+ sizeof (ip6_header_t));
}
p = pg_get_edit_group (s, group_index);
if (p->payload_length.type == PG_EDIT_UNSPECIFIED)
{
- pg_edit_group_t * g = pg_stream_get_group (s, group_index);
+ pg_edit_group_t *g = pg_stream_get_group (s, group_index);
g->edit_function = ip6_pg_edit_function;
}
return 1;
}
- error:
+error:
/* Free up any edits we may have added. */
pg_free_edit_group (s);
return 0;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip_api.c b/vnet/vnet/ip/ip_api.c
index a11362642c6..cd9b7397d29 100644
--- a/vnet/vnet/ip/ip_api.c
+++ b/vnet/vnet/ip/ip_api.c
@@ -119,11 +119,11 @@ vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
/* *INDENT-OFF* */
vec_foreach (n, ns)
{
- send_ip_neighbor_details (mp->is_ipv6,
- ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
- (u8 *) n->link_layer_address,
- (u8 *) & (n->key.ip6_address.as_u8),
- q, mp->context);
+ send_ip_neighbor_details
+ (mp->is_ipv6, ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
+ (u8 *) n->link_layer_address,
+ (u8 *) & (n->key.ip6_address.as_u8),
+ q, mp->context);
}
/* *INDENT-ON* */
vec_free (ns);
@@ -285,22 +285,21 @@ vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp)
}));
}
}));
+ /* *INDENT-ON* */
- vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
+ vec_sort_with_function (lfeis, fib_entry_cmp_for_sort);
- vec_foreach(lfeip, lfeis)
+ vec_foreach (lfeip, lfeis)
{
- fib_entry_get_prefix(*lfeip, &pfx);
- fib_index = fib_entry_get_fib_index(*lfeip);
- fib_table = fib_table_get(fib_index, pfx.fp_proto);
+ fib_entry_get_prefix (*lfeip, &pfx);
+ fib_index = fib_entry_get_fib_index (*lfeip);
+ fib_table = fib_table_get (fib_index, pfx.fp_proto);
api_rpaths = NULL;
- fib_entry_encode(*lfeip, &api_rpaths);
+ fib_entry_encode (*lfeip, &api_rpaths);
send_ip_fib_details (am, q,
- fib_table->ft_table_id,
- &pfx,
- api_rpaths,
- mp->context);
- vec_free(api_rpaths);
+ fib_table->ft_table_id, &pfx, api_rpaths,
+ mp->context);
+ vec_free (api_rpaths);
}
vec_free (lfeis);
@@ -326,16 +325,16 @@ vl_api_ip6_fib_details_t_print (vl_api_ip6_fib_details_t * mp)
static void
send_ip6_fib_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- u32 table_id, fib_prefix_t *pfx,
- fib_route_path_encode_t *api_rpaths, u32 context)
+ unix_shared_memory_queue_t * q,
+ u32 table_id, fib_prefix_t * pfx,
+ fib_route_path_encode_t * api_rpaths, u32 context)
{
vl_api_ip6_fib_details_t *mp;
fib_route_path_encode_t *api_rpath;
vl_api_fib_path_t *fp;
int path_count;
- path_count = vec_len(api_rpaths);
+ path_count = vec_len (api_rpaths);
mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
if (!mp)
return;
@@ -345,11 +344,11 @@ send_ip6_fib_details (vpe_api_main_t * am,
mp->table_id = htonl (table_id);
mp->address_length = pfx->fp_len;
- memcpy(mp->address, &pfx->fp_addr.ip6, sizeof(pfx->fp_addr.ip6));
+ memcpy (mp->address, &pfx->fp_addr.ip6, sizeof (pfx->fp_addr.ip6));
mp->count = htonl (path_count);
fp = mp->path;
- vec_foreach(api_rpath, api_rpaths)
+ vec_foreach (api_rpath, api_rpaths)
{
memset (fp, 0, sizeof (*fp));
switch (api_rpath->dpo.dpoi_type)
@@ -363,13 +362,13 @@ send_ip6_fib_details (vpe_api_main_t * am,
case DPO_IP_NULL:
switch (api_rpath->dpo.dpoi_index)
{
- case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_NONE:
+ case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_NONE:
fp->is_drop = true;
break;
- case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_UNREACH:
+ case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_SEND_ICMP_UNREACH:
fp->is_unreach = true;
break;
- case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
+ case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
fp->is_prohibit = true;
break;
default:
@@ -379,8 +378,8 @@ send_ip6_fib_details (vpe_api_main_t * am,
default:
break;
}
- fp->weight = htonl(api_rpath->rpath.frp_weight);
- fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
+ fp->weight = htonl (api_rpath->rpath.frp_weight);
+ fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
copy_fib_next_hop (api_rpath, fp);
fp++;
}
@@ -388,60 +387,56 @@ send_ip6_fib_details (vpe_api_main_t * am,
vl_msg_api_send_shmem (q, (u8 *) & mp);
}
-typedef struct apt_ip6_fib_show_ctx_t_ {
- u32 fib_index;
- fib_node_index_t *entries;
+typedef struct apt_ip6_fib_show_ctx_t_
+{
+ u32 fib_index;
+ fib_node_index_t *entries;
} api_ip6_fib_show_ctx_t;
static void
-api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp,
- void *arg)
+api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp, void *arg)
{
api_ip6_fib_show_ctx_t *ctx = arg;
if ((kvp->key[2] >> 32) == ctx->fib_index)
{
- vec_add1(ctx->entries, kvp->value);
+ vec_add1 (ctx->entries, kvp->value);
}
}
static void
-api_ip6_fib_table_get_all (unix_shared_memory_queue_t *q,
- vl_api_ip6_fib_dump_t *mp,
- fib_table_t *fib_table)
+api_ip6_fib_table_get_all (unix_shared_memory_queue_t * q,
+ vl_api_ip6_fib_dump_t * mp,
+ fib_table_t * fib_table)
{
vpe_api_main_t *am = &vpe_api_main;
ip6_main_t *im6 = &ip6_main;
ip6_fib_t *fib = &fib_table->v6;
fib_node_index_t *fib_entry_index;
api_ip6_fib_show_ctx_t ctx = {
- .fib_index = fib->index,
- .entries = NULL,
+ .fib_index = fib->index,.entries = NULL,
};
fib_route_path_encode_t *api_rpaths;
fib_prefix_t pfx;
- BV(clib_bihash_foreach_key_value_pair)
- ((BVT(clib_bihash) *) &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
- api_ip6_fib_table_put_entries,
- &ctx);
+ BV (clib_bihash_foreach_key_value_pair)
+ ((BVT (clib_bihash) *) & im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].
+ ip6_hash, api_ip6_fib_table_put_entries, &ctx);
- vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
+ vec_sort_with_function (ctx.entries, fib_entry_cmp_for_sort);
- vec_foreach(fib_entry_index, ctx.entries)
- {
- fib_entry_get_prefix(*fib_entry_index, &pfx);
- api_rpaths = NULL;
- fib_entry_encode(*fib_entry_index, &api_rpaths);
- send_ip6_fib_details (am, q,
- fib_table->ft_table_id,
- &pfx,
- api_rpaths,
- mp->context);
- vec_free(api_rpaths);
- }
+ vec_foreach (fib_entry_index, ctx.entries)
+ {
+ fib_entry_get_prefix (*fib_entry_index, &pfx);
+ api_rpaths = NULL;
+ fib_entry_encode (*fib_entry_index, &api_rpaths);
+ send_ip6_fib_details (am, q,
+ fib_table->ft_table_id,
+ &pfx, api_rpaths, mp->context);
+ vec_free (api_rpaths);
+ }
- vec_free(ctx.entries);
+ vec_free (ctx.entries);
}
static void
@@ -460,6 +455,7 @@ vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp)
({
api_ip6_fib_table_get_all(q, mp, fib_table);
}));
+ /* *INDENT-ON* */
}
static void
@@ -610,7 +606,7 @@ add_del_route_t_handler (u8 is_multipath,
if (pool_is_free_index (cm->tables,
ntohl (classify_table_index)))
{
- stats_dsunlock();
+ stats_dsunlock ();
return VNET_API_ERROR_NO_SUCH_TABLE;
}
@@ -620,7 +616,7 @@ add_del_route_t_handler (u8 is_multipath,
}
else
{
- stats_dsunlock();
+ stats_dsunlock ();
return VNET_API_ERROR_NO_SUCH_TABLE;
}
@@ -651,7 +647,7 @@ add_del_route_t_handler (u8 is_multipath,
}
}
- stats_dsunlock();
+ stats_dsunlock ();
return (0);
}
@@ -914,9 +910,9 @@ vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
if (q == 0)
return;
- /* *INDENT-OFF* */
if (mp->is_ipv6)
{
+ /* *INDENT-OFF* */
foreach_ip_interface_address (lm6, ia, sw_if_index,
1 /* honor unnumbered */,
({
@@ -924,10 +920,11 @@ vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
u16 prefix_length = ia->address_length;
send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
}));
+ /* *INDENT-ON* */
}
-
else
{
+ /* *INDENT-OFF* */
foreach_ip_interface_address (lm4, ia, sw_if_index,
1 /* honor unnumbered */,
({
@@ -935,9 +932,8 @@ vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
u16 prefix_length = ia->address_length;
send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
}));
+ /* *INDENT-ON* */
}
- /* *INDENT-ON* */
-
BAD_SW_IF_INDEX_LABEL;
}
diff --git a/vnet/vnet/ip/ip_checksum.c b/vnet/vnet/ip/ip_checksum.c
index 680b7a44c63..6a9cf657a5c 100644
--- a/vnet/vnet/ip/ip_checksum.c
+++ b/vnet/vnet/ip/ip_checksum.c
@@ -40,7 +40,7 @@
#include <vnet/ip/ip.h>
ip_csum_t
-ip_incremental_checksum (ip_csum_t sum, void * _data, uword n_bytes)
+ip_incremental_checksum (ip_csum_t sum, void *_data, uword n_bytes)
{
uword data = pointer_to_uword (_data);
ip_csum_t sum0, sum1;
@@ -61,27 +61,27 @@ do { \
} \
} while (0)
- _ (u8);
- _ (u16);
+ _(u8);
+ _(u16);
if (BITS (ip_csum_t) > 32)
- _ (u32);
+ _(u32);
#undef _
- {
- ip_csum_t * d = uword_to_pointer (data, ip_csum_t *);
+ {
+ ip_csum_t *d = uword_to_pointer (data, ip_csum_t *);
- while (n_bytes >= 2 * sizeof (d[0]))
- {
- sum0 = ip_csum_with_carry (sum0, d[0]);
- sum1 = ip_csum_with_carry (sum1, d[1]);
- d += 2;
- n_bytes -= 2 * sizeof (d[0]);
- }
+ while (n_bytes >= 2 * sizeof (d[0]))
+ {
+ sum0 = ip_csum_with_carry (sum0, d[0]);
+ sum1 = ip_csum_with_carry (sum1, d[1]);
+ d += 2;
+ n_bytes -= 2 * sizeof (d[0]);
+ }
+
+ data = pointer_to_uword (d);
+ }
- data = pointer_to_uword (d);
- }
-
#define _(t) \
do { \
if (n_bytes >= sizeof (t) && sizeof (t) <= sizeof (ip_csum_t)) \
@@ -92,47 +92,49 @@ do { \
} \
} while (0)
- if (BITS (ip_csum_t) > 32)
- _ (u64);
- _ (u32);
- _ (u16);
- _ (u8);
+ if (BITS (ip_csum_t) > 32)
+ _(u64);
+ _(u32);
+ _(u16);
+ _(u8);
#undef _
- /* Combine even and odd sums. */
- sum0 = ip_csum_with_carry (sum0, sum1);
+ /* Combine even and odd sums. */
+ sum0 = ip_csum_with_carry (sum0, sum1);
- return sum0;
+ return sum0;
}
ip_csum_t
-ip_csum_and_memcpy (ip_csum_t sum, void * dst, void * src, uword n_bytes)
+ip_csum_and_memcpy (ip_csum_t sum, void *dst, void *src, uword n_bytes)
{
uword n_left;
ip_csum_t sum0 = sum, sum1;
n_left = n_bytes;
- if (n_left && (pointer_to_uword (dst) & sizeof(u8)))
+ if (n_left && (pointer_to_uword (dst) & sizeof (u8)))
{
- u8 * d8, val;
+ u8 *d8, val;
d8 = dst;
- val = ((u8 *)src)[0];
+ val = ((u8 *) src)[0];
d8[0] = val;
dst += 1;
src += 1;
n_left -= 1;
- sum0 = ip_csum_with_carry (sum0, val << (8 * CLIB_ARCH_IS_LITTLE_ENDIAN));
+ sum0 =
+ ip_csum_with_carry (sum0, val << (8 * CLIB_ARCH_IS_LITTLE_ENDIAN));
}
- while ((n_left >= sizeof (u16)) && (pointer_to_uword (dst) & (sizeof (sum) - sizeof (u16))))
+ while ((n_left >= sizeof (u16))
+ && (pointer_to_uword (dst) & (sizeof (sum) - sizeof (u16))))
{
- u16 * d16, * s16;
+ u16 *d16, *s16;
d16 = dst;
s16 = src;
-
+
d16[0] = clib_mem_unaligned (&s16[0], u16);
sum0 = ip_csum_with_carry (sum0, d16[0]);
@@ -155,8 +157,8 @@ ip_csum_and_memcpy (ip_csum_t sum, void * dst, void * src, uword n_bytes)
dst_even[0] = dst0;
dst_even[1] = dst1;
- dst += 2 * sizeof(dst_even[0]);
- src += 2 * sizeof(dst_even[0]);
+ dst += 2 * sizeof (dst_even[0]);
+ src += 2 * sizeof (dst_even[0]);
n_left -= 2 * sizeof (dst_even[0]);
sum0 = ip_csum_with_carry (sum0, dst0);
@@ -175,8 +177,8 @@ ip_csum_and_memcpy (ip_csum_t sum, void * dst, void * src, uword n_bytes)
dst_even[0] = dst0;
- dst += 1 * sizeof(sum);
- src += 1 * sizeof(sum);
+ dst += 1 * sizeof (sum);
+ src += 1 * sizeof (sum);
n_left -= 1 * sizeof (sum);
sum0 = ip_csum_with_carry (sum0, dst0);
@@ -202,7 +204,7 @@ ip_csum_and_memcpy (ip_csum_t sum, void * dst, void * src, uword n_bytes)
if (n_left == 1)
{
- u8 * d8, * s8, val;
+ u8 *d8, *s8, val;
d8 = dst;
s8 = src;
@@ -216,3 +218,11 @@ ip_csum_and_memcpy (ip_csum_t sum, void * dst, void * src, uword n_bytes)
return sum0;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip_frag.c b/vnet/vnet/ip/ip_frag.c
index 8aa21a023d2..ca062bfd5e8 100644
--- a/vnet/vnet/ip/ip_frag.c
+++ b/vnet/vnet/ip/ip_frag.c
@@ -24,7 +24,8 @@
#include <vnet/ip/ip.h>
-typedef struct {
+typedef struct
+{
u8 ipv6;
u16 header_offset;
u16 mtu;
@@ -32,413 +33,505 @@ typedef struct {
u16 n_fragments;
} ip_frag_trace_t;
-static u8 * format_ip_frag_trace (u8 * s, va_list * args)
+static u8 *
+format_ip_frag_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 *);
- ip_frag_trace_t * t = va_arg (*args, ip_frag_trace_t *);
- s = format(s, "IPv%s offset: %u mtu: %u fragments: %u",
- t->ipv6?"6":"4", t->header_offset, t->mtu, t->n_fragments);
+ ip_frag_trace_t *t = va_arg (*args, ip_frag_trace_t *);
+ s = format (s, "IPv%s offset: %u mtu: %u fragments: %u",
+ t->ipv6 ? "6" : "4", t->header_offset, t->mtu, t->n_fragments);
return s;
}
static u32 running_fragment_id;
static void
-ip4_frag_do_fragment(vlib_main_t *vm, u32 pi, u32 **buffer, ip_frag_error_t *error)
+ip4_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
+ ip_frag_error_t * error)
{
vlib_buffer_t *p;
ip4_header_t *ip4;
- u16 mtu, ptr, len, max, rem,
- offset, ip_frag_id, ip_frag_offset;
+ u16 mtu, ptr, len, max, rem, offset, ip_frag_id, ip_frag_offset;
u8 *packet, more;
- vec_add1(*buffer, pi);
- p = vlib_get_buffer(vm, pi);
- offset = vnet_buffer(p)->ip_frag.header_offset;
- mtu = vnet_buffer(p)->ip_frag.mtu;
- packet = (u8 *)vlib_buffer_get_current(p);
- ip4 = (ip4_header_t *)(packet + offset);
+ vec_add1 (*buffer, pi);
+ p = vlib_get_buffer (vm, pi);
+ offset = vnet_buffer (p)->ip_frag.header_offset;
+ mtu = vnet_buffer (p)->ip_frag.mtu;
+ packet = (u8 *) vlib_buffer_get_current (p);
+ ip4 = (ip4_header_t *) (packet + offset);
- rem = clib_net_to_host_u16(ip4->length) - sizeof(*ip4);
+ rem = clib_net_to_host_u16 (ip4->length) - sizeof (*ip4);
ptr = 0;
- max = (mtu - sizeof(*ip4) - vnet_buffer(p)->ip_frag.header_offset) & ~0x7;
+ max = (mtu - sizeof (*ip4) - vnet_buffer (p)->ip_frag.header_offset) & ~0x7;
- if (rem < (p->current_length - offset - sizeof(*ip4))) {
- *error = IP_FRAG_ERROR_MALFORMED;
- return;
- }
+ if (rem < (p->current_length - offset - sizeof (*ip4)))
+ {
+ *error = IP_FRAG_ERROR_MALFORMED;
+ return;
+ }
- if (mtu < sizeof(*ip4)) {
- *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
- return;
- }
+ if (mtu < sizeof (*ip4))
+ {
+ *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
+ return;
+ }
if (ip4->flags_and_fragment_offset &
- clib_host_to_net_u16(IP4_HEADER_FLAG_DONT_FRAGMENT)) {
- *error = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
- return;
- }
-
- if (ip4_is_fragment(ip4)) {
- ip_frag_id = ip4->fragment_id;
- ip_frag_offset = ip4_get_fragment_offset(ip4);
- more = !!(ip4->flags_and_fragment_offset & clib_host_to_net_u16(IP4_HEADER_FLAG_MORE_FRAGMENTS));
- } else {
- ip_frag_id = (++running_fragment_id);
- ip_frag_offset = 0;
- more = 0;
- }
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT))
+ {
+ *error = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
+ return;
+ }
- //Do the actual fragmentation
- while (rem) {
- u32 bi;
- vlib_buffer_t *b;
- ip4_header_t *fip4;
-
- len = (rem > (mtu - sizeof(*ip4) - vnet_buffer(p)->ip_frag.header_offset)) ? max : rem;
-
- if (ptr == 0) {
- bi = pi;
- b = p;
- fip4 = (ip4_header_t *)(vlib_buffer_get_current(b) + offset);
- } else {
- if (!vlib_buffer_alloc(vm, &bi, 1)) {
- *error = IP_FRAG_ERROR_MEMORY;
- return;
- }
- vec_add1(*buffer, bi);
- b = vlib_get_buffer(vm, bi);
- vnet_buffer(b)->sw_if_index[VLIB_RX] = vnet_buffer(p)->sw_if_index[VLIB_RX];
- vnet_buffer(b)->sw_if_index[VLIB_TX] = vnet_buffer(p)->sw_if_index[VLIB_TX];
- fip4 = (ip4_header_t *)(vlib_buffer_get_current(b) + offset);
-
- //Copy offset and ip4 header
- clib_memcpy(b->data, packet, offset + sizeof(*ip4));
- //Copy data
- clib_memcpy(((u8*)(fip4)) + sizeof(*fip4),
- packet + offset + sizeof(*fip4) + ptr, len);
+ if (ip4_is_fragment (ip4))
+ {
+ ip_frag_id = ip4->fragment_id;
+ ip_frag_offset = ip4_get_fragment_offset (ip4);
+ more =
+ ! !(ip4->flags_and_fragment_offset &
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS));
}
- b->current_length = offset + len + sizeof(*fip4);
-
- fip4->fragment_id = ip_frag_id;
- fip4->flags_and_fragment_offset = clib_host_to_net_u16((ptr >> 3) + ip_frag_offset);
- fip4->flags_and_fragment_offset |= clib_host_to_net_u16(((len != rem) || more) << 13);
- // ((len0 != rem0) || more0) << 13 is optimization for
- // ((len0 != rem0) || more0) ? IP4_HEADER_FLAG_MORE_FRAGMENTS : 0
- fip4->length = clib_host_to_net_u16(len + sizeof(*fip4));
- fip4->checksum = ip4_header_checksum(fip4);
-
- if(vnet_buffer(p)->ip_frag.flags & IP_FRAG_FLAG_IP4_HEADER) {
- //Encapsulating ipv4 header
- ip4_header_t *encap_header4 = (ip4_header_t *)vlib_buffer_get_current(b);
- encap_header4->length = clib_host_to_net_u16(b->current_length);
- encap_header4->checksum = ip4_header_checksum(encap_header4);
- } else if (vnet_buffer(p)->ip_frag.flags & IP_FRAG_FLAG_IP6_HEADER) {
- //Encapsulating ipv6 header
- ip6_header_t *encap_header6 = (ip6_header_t *)vlib_buffer_get_current(b);
- encap_header6->payload_length = clib_host_to_net_u16(b->current_length - sizeof(*encap_header6));
+ else
+ {
+ ip_frag_id = (++running_fragment_id);
+ ip_frag_offset = 0;
+ more = 0;
}
- rem -= len;
- ptr += len;
- }
+ //Do the actual fragmentation
+ while (rem)
+ {
+ u32 bi;
+ vlib_buffer_t *b;
+ ip4_header_t *fip4;
+
+ len =
+ (rem >
+ (mtu - sizeof (*ip4) -
+ vnet_buffer (p)->ip_frag.header_offset)) ? max : rem;
+
+ if (ptr == 0)
+ {
+ bi = pi;
+ b = p;
+ fip4 = (ip4_header_t *) (vlib_buffer_get_current (b) + offset);
+ }
+ else
+ {
+ if (!vlib_buffer_alloc (vm, &bi, 1))
+ {
+ *error = IP_FRAG_ERROR_MEMORY;
+ return;
+ }
+ vec_add1 (*buffer, bi);
+ b = vlib_get_buffer (vm, bi);
+ vnet_buffer (b)->sw_if_index[VLIB_RX] =
+ vnet_buffer (p)->sw_if_index[VLIB_RX];
+ vnet_buffer (b)->sw_if_index[VLIB_TX] =
+ vnet_buffer (p)->sw_if_index[VLIB_TX];
+ fip4 = (ip4_header_t *) (vlib_buffer_get_current (b) + offset);
+
+ //Copy offset and ip4 header
+ clib_memcpy (b->data, packet, offset + sizeof (*ip4));
+ //Copy data
+ clib_memcpy (((u8 *) (fip4)) + sizeof (*fip4),
+ packet + offset + sizeof (*fip4) + ptr, len);
+ }
+ b->current_length = offset + len + sizeof (*fip4);
+
+ fip4->fragment_id = ip_frag_id;
+ fip4->flags_and_fragment_offset =
+ clib_host_to_net_u16 ((ptr >> 3) + ip_frag_offset);
+ fip4->flags_and_fragment_offset |=
+ clib_host_to_net_u16 (((len != rem) || more) << 13);
+ // ((len0 != rem0) || more0) << 13 is optimization for
+ // ((len0 != rem0) || more0) ? IP4_HEADER_FLAG_MORE_FRAGMENTS : 0
+ fip4->length = clib_host_to_net_u16 (len + sizeof (*fip4));
+ fip4->checksum = ip4_header_checksum (fip4);
+
+ if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP4_HEADER)
+ {
+ //Encapsulating ipv4 header
+ ip4_header_t *encap_header4 =
+ (ip4_header_t *) vlib_buffer_get_current (b);
+ encap_header4->length = clib_host_to_net_u16 (b->current_length);
+ encap_header4->checksum = ip4_header_checksum (encap_header4);
+ }
+ else if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP6_HEADER)
+ {
+ //Encapsulating ipv6 header
+ ip6_header_t *encap_header6 =
+ (ip6_header_t *) vlib_buffer_get_current (b);
+ encap_header6->payload_length =
+ clib_host_to_net_u16 (b->current_length -
+ sizeof (*encap_header6));
+ }
+
+ rem -= len;
+ ptr += len;
+ }
}
void
-ip_frag_set_vnet_buffer (vlib_buffer_t *b, u16 offset, u16 mtu, u8 next_index, u8 flags)
+ip_frag_set_vnet_buffer (vlib_buffer_t * b, u16 offset, u16 mtu,
+ u8 next_index, u8 flags)
{
- vnet_buffer(b)->ip_frag.header_offset = offset;
- vnet_buffer(b)->ip_frag.mtu = mtu;
- vnet_buffer(b)->ip_frag.next_index = next_index;
- vnet_buffer(b)->ip_frag.flags = flags;
+ vnet_buffer (b)->ip_frag.header_offset = offset;
+ vnet_buffer (b)->ip_frag.mtu = mtu;
+ vnet_buffer (b)->ip_frag.next_index = next_index;
+ vnet_buffer (b)->ip_frag.flags = flags;
}
static uword
-ip4_frag (vlib_main_t *vm,
- vlib_node_runtime_t *node,
- vlib_frame_t *frame)
+ip4_frag (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime(vm, ip4_frag_node.index);
- from = vlib_frame_vector_args(frame);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip4_frag_node.index);
+ from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
u32 frag_sent = 0, small_packets = 0;
u32 *buffer = 0;
- while (n_left_from > 0) {
- vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
-
- while (n_left_from > 0 && n_left_to_next > 0) {
- u32 pi0, *frag_from, frag_left;
- vlib_buffer_t *p0;
- ip_frag_error_t error0;
- ip4_frag_next_t next0;
-
- //Note: The packet is not enqueued now.
- //It is instead put in a vector where other fragments
- //will be put as well.
- pi0 = from[0];
- from += 1;
- n_left_from -= 1;
- error0 = IP_FRAG_ERROR_NONE;
-
- p0 = vlib_get_buffer(vm, pi0);
- ip4_frag_do_fragment(vm, pi0, &buffer, &error0);
-
- if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED)) {
- ip_frag_trace_t *tr = vlib_add_trace(vm, node, p0, sizeof (*tr));
- tr->header_offset = vnet_buffer(p0)->ip_frag.header_offset;
- tr->mtu = vnet_buffer(p0)->ip_frag.mtu;
- tr->ipv6 = 0;
- tr->n_fragments = vec_len(buffer);
- tr->next = vnet_buffer(p0)->ip_frag.next_index;
- }
-
- if (error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET) {
- icmp4_error_set_vnet_buffer(p0, ICMP4_destination_unreachable,
- ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
- vnet_buffer(p0)->ip_frag.mtu);
- vlib_buffer_advance(p0, vnet_buffer(p0)->ip_frag.header_offset);
- next0 = IP4_FRAG_NEXT_ICMP_ERROR;
- } else
- next0 = (error0 == IP_FRAG_ERROR_NONE) ? vnet_buffer(p0)->ip_frag.next_index : IP4_FRAG_NEXT_DROP;
-
- if (error0 == IP_FRAG_ERROR_NONE) {
- frag_sent += vec_len(buffer);
- small_packets += (vec_len(buffer) == 1);
- } else
- vlib_error_count(vm, ip4_frag_node.index, error0, 1);
-
- //Send fragments that were added in the frame
- frag_from = buffer;
- frag_left = vec_len(buffer);
-
- while (frag_left > 0) {
- while (frag_left > 0 && n_left_to_next > 0) {
- u32 i;
- i = to_next[0] = frag_from[0];
- frag_from += 1;
- frag_left -= 1;
- to_next += 1;
- n_left_to_next -= 1;
-
- vlib_get_buffer(vm, i)->error = error_node->errors[error0];
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next, i,
- next0);
- }
- vlib_put_next_frame(vm, node, next_index, n_left_to_next);
- vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
- }
- vec_reset_length(buffer);
+ while (n_left_from > 0)
+ {
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 pi0, *frag_from, frag_left;
+ vlib_buffer_t *p0;
+ ip_frag_error_t error0;
+ ip4_frag_next_t next0;
+
+ //Note: The packet is not enqueued now.
+ //It is instead put in a vector where other fragments
+ //will be put as well.
+ pi0 = from[0];
+ from += 1;
+ n_left_from -= 1;
+ error0 = IP_FRAG_ERROR_NONE;
+
+ p0 = vlib_get_buffer (vm, pi0);
+ ip4_frag_do_fragment (vm, pi0, &buffer, &error0);
+
+ if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ ip_frag_trace_t *tr =
+ vlib_add_trace (vm, node, p0, sizeof (*tr));
+ tr->header_offset = vnet_buffer (p0)->ip_frag.header_offset;
+ tr->mtu = vnet_buffer (p0)->ip_frag.mtu;
+ tr->ipv6 = 0;
+ tr->n_fragments = vec_len (buffer);
+ tr->next = vnet_buffer (p0)->ip_frag.next_index;
+ }
+
+ if (error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
+ {
+ icmp4_error_set_vnet_buffer (p0, ICMP4_destination_unreachable,
+ ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
+ vnet_buffer (p0)->ip_frag.mtu);
+ vlib_buffer_advance (p0,
+ vnet_buffer (p0)->ip_frag.header_offset);
+ next0 = IP4_FRAG_NEXT_ICMP_ERROR;
+ }
+ else
+ next0 =
+ (error0 ==
+ IP_FRAG_ERROR_NONE) ? vnet_buffer (p0)->
+ ip_frag.next_index : IP4_FRAG_NEXT_DROP;
+
+ if (error0 == IP_FRAG_ERROR_NONE)
+ {
+ frag_sent += vec_len (buffer);
+ small_packets += (vec_len (buffer) == 1);
+ }
+ else
+ vlib_error_count (vm, ip4_frag_node.index, error0, 1);
+
+ //Send fragments that were added in the frame
+ frag_from = buffer;
+ frag_left = vec_len (buffer);
+
+ while (frag_left > 0)
+ {
+ while (frag_left > 0 && n_left_to_next > 0)
+ {
+ u32 i;
+ i = to_next[0] = frag_from[0];
+ frag_from += 1;
+ frag_left -= 1;
+ to_next += 1;
+ n_left_to_next -= 1;
+
+ vlib_get_buffer (vm, i)->error = error_node->errors[error0];
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next, i,
+ next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next,
+ n_left_to_next);
+ }
+ vec_reset_length (buffer);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_put_next_frame(vm, node, next_index, n_left_to_next);
- }
- vec_free(buffer);
+ vec_free (buffer);
- vlib_node_increment_counter(vm, ip4_frag_node.index, IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
- vlib_node_increment_counter(vm, ip4_frag_node.index, IP_FRAG_ERROR_SMALL_PACKET, small_packets);
+ vlib_node_increment_counter (vm, ip4_frag_node.index,
+ IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
+ vlib_node_increment_counter (vm, ip4_frag_node.index,
+ IP_FRAG_ERROR_SMALL_PACKET, small_packets);
return frame->n_vectors;
}
static void
-ip6_frag_do_fragment(vlib_main_t *vm, u32 pi, u32 **buffer, ip_frag_error_t *error)
+ip6_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
+ ip_frag_error_t * error)
{
vlib_buffer_t *p;
ip6_header_t *ip6_hdr;
ip6_frag_hdr_t *frag_hdr;
u8 *payload, *next_header;
- p = vlib_get_buffer(vm, pi);
+ p = vlib_get_buffer (vm, pi);
//Parsing the IPv6 headers
- ip6_hdr = vlib_buffer_get_current(p) + vnet_buffer(p)->ip_frag.header_offset;
- payload = (u8 *)(ip6_hdr + 1);
+ ip6_hdr =
+ vlib_buffer_get_current (p) + vnet_buffer (p)->ip_frag.header_offset;
+ payload = (u8 *) (ip6_hdr + 1);
next_header = &ip6_hdr->protocol;
- if (*next_header == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) {
- next_header = payload;
- payload += payload[1] * 8;
- }
-
- if (*next_header == IP_PROTOCOL_IP6_DESTINATION_OPTIONS) {
- next_header = payload;
- payload += payload[1] * 8;
- }
-
- if (*next_header == IP_PROTOCOL_IPV6_ROUTE) {
- next_header = payload;
- payload += payload[1] * 8;
- }
-
- if (PREDICT_FALSE(payload >= (u8 *)vlib_buffer_get_current(p) + p->current_length)) {
- //A malicious packet could set an extension header with a too big size
- //and make us modify another vlib_buffer
- *error = IP_FRAG_ERROR_MALFORMED;
- return;
- }
+ if (*next_header == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
+ {
+ next_header = payload;
+ payload += payload[1] * 8;
+ }
+
+ if (*next_header == IP_PROTOCOL_IP6_DESTINATION_OPTIONS)
+ {
+ next_header = payload;
+ payload += payload[1] * 8;
+ }
+
+ if (*next_header == IP_PROTOCOL_IPV6_ROUTE)
+ {
+ next_header = payload;
+ payload += payload[1] * 8;
+ }
+
+ if (PREDICT_FALSE
+ (payload >= (u8 *) vlib_buffer_get_current (p) + p->current_length))
+ {
+ //A malicious packet could set an extension header with a too big size
+ //and make us modify another vlib_buffer
+ *error = IP_FRAG_ERROR_MALFORMED;
+ return;
+ }
u8 has_more;
u16 initial_offset;
- if (*next_header == IP_PROTOCOL_IPV6_FRAGMENTATION) {
- //The fragmentation header is already there
- frag_hdr = (ip6_frag_hdr_t *)payload;
- has_more = ip6_frag_hdr_more(frag_hdr);
- initial_offset = ip6_frag_hdr_offset(frag_hdr);
- } else {
- //Insert a fragmentation header in the packet
- u8 nh = *next_header;
- *next_header = IP_PROTOCOL_IPV6_FRAGMENTATION;
- vlib_buffer_advance(p, -sizeof(*frag_hdr));
- u8 *start = vlib_buffer_get_current(p);
- memmove(start, start + sizeof(*frag_hdr), payload - (start + sizeof(*frag_hdr)));
- frag_hdr = (ip6_frag_hdr_t *)(payload - sizeof(*frag_hdr));
- frag_hdr->identification = ++running_fragment_id;
- frag_hdr->next_hdr = nh;
- frag_hdr->rsv = 0;
- has_more = 0;
- initial_offset = 0;
- }
- payload = (u8 *)(frag_hdr + 1);
-
- u16 headers_len = payload - (u8 *)vlib_buffer_get_current(p);
- u16 max_payload = vnet_buffer(p)->ip_frag.mtu - headers_len;
+ if (*next_header == IP_PROTOCOL_IPV6_FRAGMENTATION)
+ {
+ //The fragmentation header is already there
+ frag_hdr = (ip6_frag_hdr_t *) payload;
+ has_more = ip6_frag_hdr_more (frag_hdr);
+ initial_offset = ip6_frag_hdr_offset (frag_hdr);
+ }
+ else
+ {
+ //Insert a fragmentation header in the packet
+ u8 nh = *next_header;
+ *next_header = IP_PROTOCOL_IPV6_FRAGMENTATION;
+ vlib_buffer_advance (p, -sizeof (*frag_hdr));
+ u8 *start = vlib_buffer_get_current (p);
+ memmove (start, start + sizeof (*frag_hdr),
+ payload - (start + sizeof (*frag_hdr)));
+ frag_hdr = (ip6_frag_hdr_t *) (payload - sizeof (*frag_hdr));
+ frag_hdr->identification = ++running_fragment_id;
+ frag_hdr->next_hdr = nh;
+ frag_hdr->rsv = 0;
+ has_more = 0;
+ initial_offset = 0;
+ }
+ payload = (u8 *) (frag_hdr + 1);
+
+ u16 headers_len = payload - (u8 *) vlib_buffer_get_current (p);
+ u16 max_payload = vnet_buffer (p)->ip_frag.mtu - headers_len;
u16 rem = p->current_length - headers_len;
u16 ptr = 0;
- if(max_payload < 8) {
- *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
- return;
- }
-
- while (rem) {
- u32 bi;
- vlib_buffer_t *b;
- u16 len = (rem > max_payload)?(max_payload & ~0x7):rem;
- rem -= len;
-
- if (ptr != 0) {
- if (!vlib_buffer_alloc(vm, &bi, 1)) {
- *error = IP_FRAG_ERROR_MEMORY;
- return;
- }
- b = vlib_get_buffer(vm, bi);
- vnet_buffer(b)->sw_if_index[VLIB_RX] = vnet_buffer(p)->sw_if_index[VLIB_RX];
- vnet_buffer(b)->sw_if_index[VLIB_TX] = vnet_buffer(p)->sw_if_index[VLIB_TX];
- clib_memcpy(vlib_buffer_get_current(b), vlib_buffer_get_current(p), headers_len);
- clib_memcpy(vlib_buffer_get_current(b) + headers_len, payload + ptr, len);
- frag_hdr = vlib_buffer_get_current(b) + headers_len - sizeof(*frag_hdr);
- } else {
- bi = pi;
- b = vlib_get_buffer(vm, bi);
- //frag_hdr already set here
+ if (max_payload < 8)
+ {
+ *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
+ return;
}
- ip6_hdr = vlib_buffer_get_current(b) + vnet_buffer(p)->ip_frag.header_offset;
- frag_hdr->fragment_offset_and_more = ip6_frag_hdr_offset_and_more(initial_offset + (ptr >> 3), (rem || has_more));
- b->current_length = headers_len + len;
- ip6_hdr->payload_length = clib_host_to_net_u16(b->current_length - vnet_buffer(p)->ip_frag.header_offset - sizeof(*ip6_hdr));
-
- if(vnet_buffer(p)->ip_frag.flags & IP_FRAG_FLAG_IP4_HEADER) {
- //Encapsulating ipv4 header
- ip4_header_t *encap_header4 = (ip4_header_t *)vlib_buffer_get_current(b);
- encap_header4->length = clib_host_to_net_u16(b->current_length);
- encap_header4->checksum = ip4_header_checksum(encap_header4);
- } else if (vnet_buffer(p)->ip_frag.flags & IP_FRAG_FLAG_IP6_HEADER) {
- //Encapsulating ipv6 header
- ip6_header_t *encap_header6 = (ip6_header_t *)vlib_buffer_get_current(b);
- encap_header6->payload_length = clib_host_to_net_u16(b->current_length - sizeof(*encap_header6));
+ while (rem)
+ {
+ u32 bi;
+ vlib_buffer_t *b;
+ u16 len = (rem > max_payload) ? (max_payload & ~0x7) : rem;
+ rem -= len;
+
+ if (ptr != 0)
+ {
+ if (!vlib_buffer_alloc (vm, &bi, 1))
+ {
+ *error = IP_FRAG_ERROR_MEMORY;
+ return;
+ }
+ b = vlib_get_buffer (vm, bi);
+ vnet_buffer (b)->sw_if_index[VLIB_RX] =
+ vnet_buffer (p)->sw_if_index[VLIB_RX];
+ vnet_buffer (b)->sw_if_index[VLIB_TX] =
+ vnet_buffer (p)->sw_if_index[VLIB_TX];
+ clib_memcpy (vlib_buffer_get_current (b),
+ vlib_buffer_get_current (p), headers_len);
+ clib_memcpy (vlib_buffer_get_current (b) + headers_len,
+ payload + ptr, len);
+ frag_hdr =
+ vlib_buffer_get_current (b) + headers_len - sizeof (*frag_hdr);
+ }
+ else
+ {
+ bi = pi;
+ b = vlib_get_buffer (vm, bi);
+ //frag_hdr already set here
+ }
+
+ ip6_hdr =
+ vlib_buffer_get_current (b) + vnet_buffer (p)->ip_frag.header_offset;
+ frag_hdr->fragment_offset_and_more =
+ ip6_frag_hdr_offset_and_more (initial_offset + (ptr >> 3),
+ (rem || has_more));
+ b->current_length = headers_len + len;
+ ip6_hdr->payload_length =
+ clib_host_to_net_u16 (b->current_length -
+ vnet_buffer (p)->ip_frag.header_offset -
+ sizeof (*ip6_hdr));
+
+ if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP4_HEADER)
+ {
+ //Encapsulating ipv4 header
+ ip4_header_t *encap_header4 =
+ (ip4_header_t *) vlib_buffer_get_current (b);
+ encap_header4->length = clib_host_to_net_u16 (b->current_length);
+ encap_header4->checksum = ip4_header_checksum (encap_header4);
+ }
+ else if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP6_HEADER)
+ {
+ //Encapsulating ipv6 header
+ ip6_header_t *encap_header6 =
+ (ip6_header_t *) vlib_buffer_get_current (b);
+ encap_header6->payload_length =
+ clib_host_to_net_u16 (b->current_length -
+ sizeof (*encap_header6));
+ }
+
+ vec_add1 (*buffer, bi);
+
+ ptr += len;
}
-
- vec_add1(*buffer, bi);
-
- ptr += len;
- }
}
static uword
-ip6_frag (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip6_frag (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
- vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_frag_node.index);
+ vlib_node_runtime_t *error_node =
+ vlib_node_get_runtime (vm, ip6_frag_node.index);
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
u32 frag_sent = 0, small_packets = 0;
u32 *buffer = 0;
- while (n_left_from > 0) {
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
- while (n_left_from > 0 && n_left_to_next > 0) {
- u32 pi0, *frag_from, frag_left;
- vlib_buffer_t * p0;
- ip_frag_error_t error0;
- ip6_frag_next_t next0;
-
- pi0 = from[0];
- from += 1;
- n_left_from -= 1;
- error0 = IP_FRAG_ERROR_NONE;
-
- p0 = vlib_get_buffer(vm, pi0);
- ip6_frag_do_fragment(vm, pi0, &buffer, &error0);
-
- if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED)) {
- ip_frag_trace_t *tr = vlib_add_trace(vm, node, p0, sizeof (*tr));
- tr->header_offset = vnet_buffer(p0)->ip_frag.header_offset;
- tr->mtu = vnet_buffer(p0)->ip_frag.mtu;
- tr->ipv6 = 1;
- tr->n_fragments = vec_len(buffer);
- tr->next = vnet_buffer(p0)->ip_frag.next_index;
- }
-
- next0 = (error0 == IP_FRAG_ERROR_NONE) ? vnet_buffer(p0)->ip_frag.next_index : IP6_FRAG_NEXT_DROP;
- frag_sent += vec_len(buffer);
- small_packets += (vec_len(buffer) == 1);
-
- //Send fragments that were added in the frame
- frag_from = buffer;
- frag_left = vec_len(buffer);
- while (frag_left > 0) {
- while (frag_left > 0 && n_left_to_next > 0) {
- u32 i;
- i = to_next[0] = frag_from[0];
- frag_from += 1;
- frag_left -= 1;
- to_next += 1;
- n_left_to_next -= 1;
-
- vlib_get_buffer(vm, i)->error = error_node->errors[error0];
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next, i,
- next0);
- }
- vlib_put_next_frame(vm, node, next_index, n_left_to_next);
- vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
- }
- vec_reset_length(buffer);
+ while (n_left_from > 0)
+ {
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 pi0, *frag_from, frag_left;
+ vlib_buffer_t *p0;
+ ip_frag_error_t error0;
+ ip6_frag_next_t next0;
+
+ pi0 = from[0];
+ from += 1;
+ n_left_from -= 1;
+ error0 = IP_FRAG_ERROR_NONE;
+
+ p0 = vlib_get_buffer (vm, pi0);
+ ip6_frag_do_fragment (vm, pi0, &buffer, &error0);
+
+ if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ ip_frag_trace_t *tr =
+ vlib_add_trace (vm, node, p0, sizeof (*tr));
+ tr->header_offset = vnet_buffer (p0)->ip_frag.header_offset;
+ tr->mtu = vnet_buffer (p0)->ip_frag.mtu;
+ tr->ipv6 = 1;
+ tr->n_fragments = vec_len (buffer);
+ tr->next = vnet_buffer (p0)->ip_frag.next_index;
+ }
+
+ next0 =
+ (error0 ==
+ IP_FRAG_ERROR_NONE) ? vnet_buffer (p0)->
+ ip_frag.next_index : IP6_FRAG_NEXT_DROP;
+ frag_sent += vec_len (buffer);
+ small_packets += (vec_len (buffer) == 1);
+
+ //Send fragments that were added in the frame
+ frag_from = buffer;
+ frag_left = vec_len (buffer);
+ while (frag_left > 0)
+ {
+ while (frag_left > 0 && n_left_to_next > 0)
+ {
+ u32 i;
+ i = to_next[0] = frag_from[0];
+ frag_from += 1;
+ frag_left -= 1;
+ to_next += 1;
+ n_left_to_next -= 1;
+
+ vlib_get_buffer (vm, i)->error = error_node->errors[error0];
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next, i,
+ next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next,
+ n_left_to_next);
+ }
+ vec_reset_length (buffer);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_put_next_frame(vm, node, next_index, n_left_to_next);
- }
- vec_free(buffer);
- vlib_node_increment_counter(vm, ip6_frag_node.index, IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
- vlib_node_increment_counter(vm, ip6_frag_node.index, IP_FRAG_ERROR_SMALL_PACKET, small_packets);
+ vec_free (buffer);
+ vlib_node_increment_counter (vm, ip6_frag_node.index,
+ IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
+ vlib_node_increment_counter (vm, ip6_frag_node.index,
+ IP_FRAG_ERROR_SMALL_PACKET, small_packets);
return frame->n_vectors;
}
-static char * ip4_frag_error_strings[] = {
+static char *ip4_frag_error_strings[] = {
#define _(sym,string) string,
foreach_ip_frag_error
#undef _
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_frag_node) = {
.function = ip4_frag,
.name = IP4_FRAG_NODE_NAME,
@@ -457,7 +550,9 @@ VLIB_REGISTER_NODE (ip4_frag_node) = {
[IP4_FRAG_NEXT_DROP] = "error-drop"
},
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_frag_node) = {
.function = ip6_frag,
.name = IP6_FRAG_NODE_NAME,
@@ -475,3 +570,12 @@ VLIB_REGISTER_NODE (ip6_frag_node) = {
[IP6_FRAG_NEXT_DROP] = "error-drop"
},
};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip_frag.h b/vnet/vnet/ip/ip_frag.h
index 118acf86bf4..348f5a2fbc6 100644
--- a/vnet/vnet/ip/ip_frag.h
+++ b/vnet/vnet/ip/ip_frag.h
@@ -37,8 +37,8 @@
#include <vnet/vnet.h>
-#define IP_FRAG_FLAG_IP4_HEADER 0x01 //Encapsulating IPv4 header
-#define IP_FRAG_FLAG_IP6_HEADER 0x02 //Encapsulating IPv6 header
+#define IP_FRAG_FLAG_IP4_HEADER 0x01 //Encapsulating IPv4 header
+#define IP_FRAG_FLAG_IP6_HEADER 0x02 //Encapsulating IPv6 header
#define IP4_FRAG_NODE_NAME "ip4-frag"
#define IP6_FRAG_NODE_NAME "ip6-frag"
@@ -46,7 +46,8 @@
extern vlib_node_registration_t ip4_frag_node;
extern vlib_node_registration_t ip6_frag_node;
-typedef enum {
+typedef enum
+{
IP4_FRAG_NEXT_IP4_LOOKUP,
IP4_FRAG_NEXT_IP6_LOOKUP,
IP4_FRAG_NEXT_ICMP_ERROR,
@@ -54,7 +55,8 @@ typedef enum {
IP4_FRAG_N_NEXT
} ip4_frag_next_t;
-typedef enum {
+typedef enum
+{
IP6_FRAG_NEXT_IP4_LOOKUP,
IP6_FRAG_NEXT_IP6_LOOKUP,
IP6_FRAG_NEXT_DROP,
@@ -72,13 +74,23 @@ typedef enum {
_(MEMORY, "could not allocate buffer") \
_(UNKNOWN, "unknown error")
-typedef enum {
+typedef enum
+{
#define _(sym,str) IP_FRAG_ERROR_##sym,
- foreach_ip_frag_error
+ foreach_ip_frag_error
#undef _
- IP_FRAG_N_ERROR,
- } ip_frag_error_t;
+ IP_FRAG_N_ERROR,
+} ip_frag_error_t;
-void ip_frag_set_vnet_buffer(vlib_buffer_t *b, u16 offset, u16 mtu, u8 next_index, u8 flags);
+void ip_frag_set_vnet_buffer (vlib_buffer_t * b, u16 offset, u16 mtu,
+ u8 next_index, u8 flags);
#endif /* ifndef IP_FRAG_H */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip_init.c b/vnet/vnet/ip/ip_init.c
index d87a92efdc6..f7635b35d0e 100644
--- a/vnet/vnet/ip/ip_init.c
+++ b/vnet/vnet/ip/ip_init.c
@@ -44,13 +44,13 @@ ip_main_t ip_main;
clib_error_t *
ip_main_init (vlib_main_t * vm)
{
- ip_main_t * im = &ip_main;
- clib_error_t * error = 0;
+ ip_main_t *im = &ip_main;
+ clib_error_t *error = 0;
memset (im, 0, sizeof (im[0]));
{
- ip_protocol_info_t * pi;
+ ip_protocol_info_t *pi;
u32 i;
#define ip_protocol(n,s) \
@@ -75,20 +75,18 @@ do { \
}
{
- tcp_udp_port_info_t * pi;
+ tcp_udp_port_info_t *pi;
u32 i;
- static char * port_names[] =
- {
+ static char *port_names[] = {
#define ip_port(s,n) #s,
#include "ports.def"
#undef ip_port
- };
- static u16 ports[] =
- {
+ };
+ static u16 ports[] = {
#define ip_port(s,n) n,
#include "ports.def"
#undef ip_port
- };
+ };
vec_resize (im->port_infos, ARRAY_LEN (port_names));
im->port_info_by_name = hash_create_string (0, sizeof (uword));
@@ -144,3 +142,11 @@ do { \
VLIB_INIT_FUNCTION (ip_main_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip_input_acl.c b/vnet/vnet/ip/ip_input_acl.c
index 93a580ce47c..b0b52ab11c3 100644
--- a/vnet/vnet/ip/ip_input_acl.c
+++ b/vnet/vnet/ip/ip_input_acl.c
@@ -16,7 +16,8 @@
#include <vnet/classify/vnet_classify.h>
#include <vnet/classify/input_acl.h>
-typedef struct {
+typedef struct
+{
u32 sw_if_index;
u32 next_index;
u32 table_index;
@@ -24,14 +25,15 @@ typedef struct {
} ip_inacl_trace_t;
/* packet trace format function */
-static u8 * format_ip_inacl_trace (u8 * s, va_list * args)
+static u8 *
+format_ip_inacl_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 *);
- ip_inacl_trace_t * t = va_arg (*args, ip_inacl_trace_t *);
+ ip_inacl_trace_t *t = va_arg (*args, ip_inacl_trace_t *);
s = format (s, "INACL: sw_if_index %d, next_index %d, table %d, offset %d",
- t->sw_if_index, t->next_index, t->table_index, t->offset);
+ t->sw_if_index, t->next_index, t->table_index, t->offset);
return s;
}
@@ -43,14 +45,15 @@ _(MISS, "input ACL misses") \
_(HIT, "input ACL hits") \
_(CHAIN_HIT, "input ACL hits after chain walk")
-typedef enum {
+typedef enum
+{
#define _(sym,str) IP_INACL_ERROR_##sym,
foreach_ip_inacl_error
#undef _
- IP_INACL_N_ERROR,
+ IP_INACL_N_ERROR,
} ip_inacl_error_t;
-static char * ip_inacl_error_strings[] = {
+static char *ip_inacl_error_strings[] = {
#define _(sym,string) string,
foreach_ip_inacl_error
#undef _
@@ -58,19 +61,18 @@ static char * ip_inacl_error_strings[] = {
static inline uword
ip_inacl_inline (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame, int is_ip4)
+ vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip4)
{
- u32 n_left_from, * from, * to_next;
+ u32 n_left_from, *from, *to_next;
acl_next_index_t next_index;
- input_acl_main_t * am = &input_acl_main;
- vnet_classify_main_t * vcm = am->vnet_classify_main;
+ input_acl_main_t *am = &input_acl_main;
+ vnet_classify_main_t *vcm = am->vnet_classify_main;
f64 now = vlib_time_now (vm);
u32 hits = 0;
u32 misses = 0;
u32 chain_hits = 0;
input_acl_table_id_t tid;
- vlib_node_runtime_t * error_node;
+ vlib_node_runtime_t *error_node;
u32 n_next_nodes;
n_next_nodes = node->n_next_nodes;
@@ -93,24 +95,24 @@ ip_inacl_inline (vlib_main_t * vm,
while (n_left_from > 2)
{
- vlib_buffer_t * b0, * b1;
+ vlib_buffer_t *b0, *b1;
u32 bi0, bi1;
- u8 * h0, * h1;
+ u8 *h0, *h1;
u32 sw_if_index0, sw_if_index1;
u32 table_index0, table_index1;
- vnet_classify_table_t * t0, * t1;
+ vnet_classify_table_t *t0, *t1;
/* prefetch next iteration */
{
- vlib_buffer_t * p1, * p2;
+ vlib_buffer_t *p1, *p2;
- p1 = vlib_get_buffer (vm, from[1]);
- p2 = vlib_get_buffer (vm, from[2]);
+ p1 = vlib_get_buffer (vm, from[1]);
+ p2 = vlib_get_buffer (vm, from[2]);
- vlib_prefetch_buffer_header (p1, STORE);
- CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE);
- vlib_prefetch_buffer_header (p2, STORE);
- CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
+ vlib_prefetch_buffer_header (p1, STORE);
+ CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE);
+ vlib_prefetch_buffer_header (p2, STORE);
+ CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
}
bi0 = from[0];
@@ -120,38 +122,40 @@ ip_inacl_inline (vlib_main_t * vm,
b1 = vlib_get_buffer (vm, bi1);
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
- table_index0 = am->classify_table_index_by_sw_if_index[tid][sw_if_index0];
+ table_index0 =
+ am->classify_table_index_by_sw_if_index[tid][sw_if_index0];
sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
- table_index1 = am->classify_table_index_by_sw_if_index[tid][sw_if_index1];
+ table_index1 =
+ am->classify_table_index_by_sw_if_index[tid][sw_if_index1];
t0 = pool_elt_at_index (vcm->tables, table_index0);
t1 = pool_elt_at_index (vcm->tables, table_index1);
if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
- h0 = (void *)vlib_buffer_get_current (b0) + t0->current_data_offset;
+ h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset;
else
- h0 = b0->data;
+ h0 = b0->data;
- vnet_buffer(b0)->l2_classify.hash =
- vnet_classify_hash_packet (t0, (u8 *) h0);
+ vnet_buffer (b0)->l2_classify.hash =
+ vnet_classify_hash_packet (t0, (u8 *) h0);
- vnet_classify_prefetch_bucket (t0, vnet_buffer(b0)->l2_classify.hash);
+ vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
if (t1->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
- h1 = (void *)vlib_buffer_get_current (b1) + t1->current_data_offset;
+ h1 = (void *) vlib_buffer_get_current (b1) + t1->current_data_offset;
else
- h1 = b1->data;
+ h1 = b1->data;
- vnet_buffer(b1)->l2_classify.hash =
- vnet_classify_hash_packet (t1, (u8 *) h1);
+ vnet_buffer (b1)->l2_classify.hash =
+ vnet_classify_hash_packet (t1, (u8 *) h1);
- vnet_classify_prefetch_bucket (t1, vnet_buffer(b1)->l2_classify.hash);
+ vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash);
- vnet_buffer(b0)->l2_classify.table_index = table_index0;
+ vnet_buffer (b0)->l2_classify.table_index = table_index0;
- vnet_buffer(b1)->l2_classify.table_index = table_index1;
+ vnet_buffer (b1)->l2_classify.table_index = table_index1;
from += 2;
n_left_from -= 2;
@@ -159,31 +163,32 @@ ip_inacl_inline (vlib_main_t * vm,
while (n_left_from > 0)
{
- vlib_buffer_t * b0;
+ vlib_buffer_t *b0;
u32 bi0;
- u8 * h0;
+ u8 *h0;
u32 sw_if_index0;
u32 table_index0;
- vnet_classify_table_t * t0;
+ vnet_classify_table_t *t0;
bi0 = from[0];
b0 = vlib_get_buffer (vm, bi0);
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
- table_index0 = am->classify_table_index_by_sw_if_index[tid][sw_if_index0];
+ table_index0 =
+ am->classify_table_index_by_sw_if_index[tid][sw_if_index0];
t0 = pool_elt_at_index (vcm->tables, table_index0);
if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
- h0 = (void *)vlib_buffer_get_current (b0) + t0->current_data_offset;
+ h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset;
else
- h0 = b0->data;
+ h0 = b0->data;
- vnet_buffer(b0)->l2_classify.hash =
- vnet_classify_hash_packet (t0, (u8 *) h0);
+ vnet_buffer (b0)->l2_classify.hash =
+ vnet_classify_hash_packet (t0, (u8 *) h0);
- vnet_buffer(b0)->l2_classify.table_index = table_index0;
- vnet_classify_prefetch_bucket (t0, vnet_buffer(b0)->l2_classify.hash);
+ vnet_buffer (b0)->l2_classify.table_index = table_index0;
+ vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
from++;
n_left_from--;
@@ -197,194 +202,194 @@ ip_inacl_inline (vlib_main_t * vm,
{
u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
/* Not enough load/store slots to dual loop... */
while (n_left_from > 0 && n_left_to_next > 0)
- {
- u32 bi0;
- vlib_buffer_t * b0;
- u32 next0 = ACL_NEXT_INDEX_DENY;
- u32 table_index0;
- vnet_classify_table_t * t0;
- vnet_classify_entry_t * e0;
- u64 hash0;
- u8 * h0;
- u8 error0;
-
- /* Stride 3 seems to work best */
- if (PREDICT_TRUE (n_left_from > 3))
- {
- vlib_buffer_t * p1 = vlib_get_buffer(vm, from[3]);
- vnet_classify_table_t * tp1;
- u32 table_index1;
- u64 phash1;
-
- table_index1 = vnet_buffer(p1)->l2_classify.table_index;
-
- if (PREDICT_TRUE (table_index1 != ~0))
- {
- tp1 = pool_elt_at_index (vcm->tables, table_index1);
- phash1 = vnet_buffer(p1)->l2_classify.hash;
- vnet_classify_prefetch_entry (tp1, phash1);
- }
- }
-
- /* speculatively enqueue b0 to the current next frame */
- bi0 = from[0];
- to_next[0] = bi0;
- from += 1;
- to_next += 1;
- n_left_from -= 1;
- n_left_to_next -= 1;
-
- b0 = vlib_get_buffer (vm, bi0);
- table_index0 = vnet_buffer(b0)->l2_classify.table_index;
- e0 = 0;
- t0 = 0;
- vnet_get_config_data (am->vnet_config_main[tid],
- &b0->current_config_index,
- &next0,
- /* # bytes of config data */ 0);
-
- vnet_buffer(b0)->l2_classify.opaque_index = ~0;
-
- if (PREDICT_TRUE(table_index0 != ~0))
- {
- hash0 = vnet_buffer(b0)->l2_classify.hash;
- t0 = pool_elt_at_index (vcm->tables, table_index0);
-
- if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
- h0 = (void *)vlib_buffer_get_current (b0) + t0->current_data_offset;
- else
- h0 = b0->data;
-
- e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0,
- now);
- if (e0)
- {
- vnet_buffer(b0)->l2_classify.opaque_index
- = e0->opaque_index;
- vlib_buffer_advance (b0, e0->advance);
-
- next0 = (e0->next_index < n_next_nodes)?
- e0->next_index:next0;
-
- hits++;
-
- if (is_ip4)
- error0 = (next0 == ACL_NEXT_INDEX_DENY)?
- IP4_ERROR_INACL_SESSION_DENY:IP4_ERROR_NONE;
- else
- error0 = (next0 == ACL_NEXT_INDEX_DENY)?
- IP6_ERROR_INACL_SESSION_DENY:IP6_ERROR_NONE;
- b0->error = error_node->errors[error0];
-
- if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
- e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = e0->metadata;
- }
- else
- {
- while (1)
- {
- if (PREDICT_TRUE(t0->next_table_index != ~0))
- t0 = pool_elt_at_index (vcm->tables,
- t0->next_table_index);
- else
- {
- next0 = (t0->miss_next_index < n_next_nodes)?
- t0->miss_next_index:next0;
-
- misses++;
-
- if (is_ip4)
- error0 = (next0 == ACL_NEXT_INDEX_DENY)?
- IP4_ERROR_INACL_TABLE_MISS:IP4_ERROR_NONE;
- else
- error0 = (next0 == ACL_NEXT_INDEX_DENY)?
- IP6_ERROR_INACL_TABLE_MISS:IP6_ERROR_NONE;
- b0->error = error_node->errors[error0];
- break;
- }
-
- if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
- h0 = (void *)vlib_buffer_get_current (b0) + t0->current_data_offset;
- else
- h0 = b0->data;
-
- hash0 = vnet_classify_hash_packet (t0, (u8 *) h0);
- e0 = vnet_classify_find_entry
- (t0, (u8 *) h0, hash0, now);
- if (e0)
- {
- vnet_buffer(b0)->l2_classify.opaque_index
- = e0->opaque_index;
- vlib_buffer_advance (b0, e0->advance);
- next0 = (e0->next_index < n_next_nodes)?
- e0->next_index:next0;
- hits++;
- chain_hits++;
-
- if (is_ip4)
- error0 = (next0 == ACL_NEXT_INDEX_DENY)?
- IP4_ERROR_INACL_SESSION_DENY:IP4_ERROR_NONE;
- else
- error0 = (next0 == ACL_NEXT_INDEX_DENY)?
- IP6_ERROR_INACL_SESSION_DENY:IP6_ERROR_NONE;
- b0->error = error_node->errors[error0];
-
- if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
- e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = e0->metadata;
- break;
- }
- }
- }
- }
-
- if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
- && (b0->flags & VLIB_BUFFER_IS_TRACED)))
- {
- ip_inacl_trace_t *t =
- vlib_add_trace (vm, node, b0, sizeof (*t));
- t->sw_if_index = vnet_buffer(b0)->sw_if_index[VLIB_RX];
- t->next_index = next0;
- t->table_index = t0 ? t0 - vcm->tables : ~0;
- t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0): ~0;
- }
-
- /* verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, next0);
- }
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ u32 next0 = ACL_NEXT_INDEX_DENY;
+ u32 table_index0;
+ vnet_classify_table_t *t0;
+ vnet_classify_entry_t *e0;
+ u64 hash0;
+ u8 *h0;
+ u8 error0;
+
+ /* Stride 3 seems to work best */
+ if (PREDICT_TRUE (n_left_from > 3))
+ {
+ vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]);
+ vnet_classify_table_t *tp1;
+ u32 table_index1;
+ u64 phash1;
+
+ table_index1 = vnet_buffer (p1)->l2_classify.table_index;
+
+ if (PREDICT_TRUE (table_index1 != ~0))
+ {
+ tp1 = pool_elt_at_index (vcm->tables, table_index1);
+ phash1 = vnet_buffer (p1)->l2_classify.hash;
+ vnet_classify_prefetch_entry (tp1, phash1);
+ }
+ }
+
+ /* speculatively enqueue b0 to the current next frame */
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ table_index0 = vnet_buffer (b0)->l2_classify.table_index;
+ e0 = 0;
+ t0 = 0;
+ vnet_get_config_data (am->vnet_config_main[tid],
+ &b0->current_config_index, &next0,
+ /* # bytes of config data */ 0);
+
+ vnet_buffer (b0)->l2_classify.opaque_index = ~0;
+
+ if (PREDICT_TRUE (table_index0 != ~0))
+ {
+ hash0 = vnet_buffer (b0)->l2_classify.hash;
+ t0 = pool_elt_at_index (vcm->tables, table_index0);
+
+ if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
+ h0 =
+ (void *) vlib_buffer_get_current (b0) +
+ t0->current_data_offset;
+ else
+ h0 = b0->data;
+
+ e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now);
+ if (e0)
+ {
+ vnet_buffer (b0)->l2_classify.opaque_index
+ = e0->opaque_index;
+ vlib_buffer_advance (b0, e0->advance);
+
+ next0 = (e0->next_index < n_next_nodes) ?
+ e0->next_index : next0;
+
+ hits++;
+
+ if (is_ip4)
+ error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
+ IP4_ERROR_INACL_SESSION_DENY : IP4_ERROR_NONE;
+ else
+ error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
+ IP6_ERROR_INACL_SESSION_DENY : IP6_ERROR_NONE;
+ b0->error = error_node->errors[error0];
+
+ if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
+ e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] = e0->metadata;
+ }
+ else
+ {
+ while (1)
+ {
+ if (PREDICT_TRUE (t0->next_table_index != ~0))
+ t0 = pool_elt_at_index (vcm->tables,
+ t0->next_table_index);
+ else
+ {
+ next0 = (t0->miss_next_index < n_next_nodes) ?
+ t0->miss_next_index : next0;
+
+ misses++;
+
+ if (is_ip4)
+ error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
+ IP4_ERROR_INACL_TABLE_MISS : IP4_ERROR_NONE;
+ else
+ error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
+ IP6_ERROR_INACL_TABLE_MISS : IP6_ERROR_NONE;
+ b0->error = error_node->errors[error0];
+ break;
+ }
+
+ if (t0->current_data_flag ==
+ CLASSIFY_FLAG_USE_CURR_DATA)
+ h0 =
+ (void *) vlib_buffer_get_current (b0) +
+ t0->current_data_offset;
+ else
+ h0 = b0->data;
+
+ hash0 = vnet_classify_hash_packet (t0, (u8 *) h0);
+ e0 = vnet_classify_find_entry
+ (t0, (u8 *) h0, hash0, now);
+ if (e0)
+ {
+ vnet_buffer (b0)->l2_classify.opaque_index
+ = e0->opaque_index;
+ vlib_buffer_advance (b0, e0->advance);
+ next0 = (e0->next_index < n_next_nodes) ?
+ e0->next_index : next0;
+ hits++;
+ chain_hits++;
+
+ if (is_ip4)
+ error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
+ IP4_ERROR_INACL_SESSION_DENY : IP4_ERROR_NONE;
+ else
+ error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
+ IP6_ERROR_INACL_SESSION_DENY : IP6_ERROR_NONE;
+ b0->error = error_node->errors[error0];
+
+ if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX
+ || e0->action ==
+ CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ e0->metadata;
+ break;
+ }
+ }
+ }
+ }
+
+ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
+ && (b0->flags & VLIB_BUFFER_IS_TRACED)))
+ {
+ ip_inacl_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+ t->next_index = next0;
+ t->table_index = t0 ? t0 - vcm->tables : ~0;
+ t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0;
+ }
+
+ /* verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, next0);
+ }
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
vlib_node_increment_counter (vm, node->node_index,
- IP_INACL_ERROR_MISS,
- misses);
+ IP_INACL_ERROR_MISS, misses);
vlib_node_increment_counter (vm, node->node_index,
- IP_INACL_ERROR_HIT,
- hits);
+ IP_INACL_ERROR_HIT, hits);
vlib_node_increment_counter (vm, node->node_index,
- IP_INACL_ERROR_CHAIN_HIT,
- chain_hits);
+ IP_INACL_ERROR_CHAIN_HIT, chain_hits);
return frame->n_vectors;
}
static uword
-ip4_inacl (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip4_inacl (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return ip_inacl_inline (vm, node, frame, 1 /* is_ip4 */);
+ return ip_inacl_inline (vm, node, frame, 1 /* is_ip4 */ );
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_inacl_node) = {
.function = ip4_inacl,
.name = "ip4-inacl",
@@ -398,18 +403,18 @@ VLIB_REGISTER_NODE (ip4_inacl_node) = {
[ACL_NEXT_INDEX_DENY] = "error-drop",
},
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_inacl_node, ip4_inacl)
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_inacl_node, ip4_inacl);
static uword
-ip6_inacl (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip6_inacl (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return ip_inacl_inline (vm, node, frame, 0 /* is_ip4 */);
+ return ip_inacl_inline (vm, node, frame, 0 /* is_ip4 */ );
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_inacl_node) = {
.function = ip6_inacl,
.name = "ip6-inacl",
@@ -423,8 +428,9 @@ VLIB_REGISTER_NODE (ip6_inacl_node) = {
[ACL_NEXT_INDEX_DENY] = "error-drop",
},
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_inacl_node, ip6_inacl)
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_inacl_node, ip6_inacl);
static clib_error_t *
ip_inacl_init (vlib_main_t * vm)
@@ -434,3 +440,11 @@ ip_inacl_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (ip_inacl_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ip_packet.h b/vnet/vnet/ip/ip_packet.h
index 84b125818e0..d3f3de771bc 100644
--- a/vnet/vnet/ip/ip_packet.h
+++ b/vnet/vnet/ip/ip_packet.h
@@ -43,21 +43,24 @@
#include <vppinfra/byte_order.h>
#include <vppinfra/error.h>
-typedef enum ip_protocol {
+typedef enum ip_protocol
+{
#define ip_protocol(n,s) IP_PROTOCOL_##s = n,
#include "protocols.def"
#undef ip_protocol
} ip_protocol_t;
/* TCP/UDP ports. */
-typedef enum {
+typedef enum
+{
#define ip_port(s,n) IP_PORT_##s = n,
#include "ports.def"
#undef ip_port
} ip_port_t;
/* Classifies protocols into UDP, ICMP or other. */
-typedef enum {
+typedef enum
+{
IP_BUILTIN_PROTOCOL_UDP,
IP_BUILTIN_PROTOCOL_ICMP,
IP_BUILTIN_PROTOCOL_UNKNOWN,
@@ -74,7 +77,8 @@ typedef enum {
_ (102, hsrp) \
_ (22, igmp_v3)
-typedef enum {
+typedef enum
+{
#define _(n,f) IP_MULTICAST_GROUP_##f = n,
foreach_ip_builtin_multicast_group
#undef _
@@ -111,7 +115,9 @@ ip_csum_add_even (ip_csum_t c, ip_csum_t x)
/* Update checksum changing field at even byte offset from 0 -> x. */
always_inline ip_csum_t
ip_csum_sub_even (ip_csum_t c, ip_csum_t x)
-{ return ip_csum_with_carry (c, x); }
+{
+ return ip_csum_with_carry (c, x);
+}
always_inline ip_csum_t
ip_csum_update_inline (ip_csum_t sum, ip_csum_t old, ip_csum_t new,
@@ -135,7 +141,8 @@ ip_csum_update_inline (ip_csum_t sum, ip_csum_t old, ip_csum_t new,
STRUCT_OFFSET_OF (type, field), \
STRUCT_SIZE_OF (type, field))
-always_inline u16 ip_csum_fold (ip_csum_t c)
+always_inline u16
+ip_csum_fold (ip_csum_t c)
{
/* Reduce to 16 bits. */
#if uword_bits == 64
@@ -150,15 +157,24 @@ always_inline u16 ip_csum_fold (ip_csum_t c)
}
/* Copy data and checksum at the same time. */
-ip_csum_t ip_csum_and_memcpy (ip_csum_t sum, void * dst, void * src, uword n_bytes);
+ip_csum_t ip_csum_and_memcpy (ip_csum_t sum, void *dst, void *src,
+ uword n_bytes);
always_inline u16
-ip_csum_and_memcpy_fold (ip_csum_t sum, void * dst)
+ip_csum_and_memcpy_fold (ip_csum_t sum, void *dst)
{
return ip_csum_fold (sum);
}
/* Checksum routine. */
-ip_csum_t ip_incremental_checksum (ip_csum_t sum, void * data, uword n_bytes);
+ip_csum_t ip_incremental_checksum (ip_csum_t sum, void *data, uword n_bytes);
#endif /* included_ip_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/lookup.c b/vnet/vnet/ip/lookup.c
index 1a32b4a6467..126deef7dd0 100644
--- a/vnet/vnet/ip/lookup.c
+++ b/vnet/vnet/ip/lookup.c
@@ -58,56 +58,62 @@
clib_error_t *
ip_interface_address_add_del (ip_lookup_main_t * lm,
u32 sw_if_index,
- void * addr_fib,
+ void *addr_fib,
u32 address_length,
- u32 is_del,
- u32 * result_if_address_index)
+ u32 is_del, u32 * result_if_address_index)
{
- vnet_main_t * vnm = vnet_get_main();
- ip_interface_address_t * a, * prev, * next;
- uword * p = mhash_get (&lm->address_to_if_address_index, addr_fib);
+ vnet_main_t *vnm = vnet_get_main ();
+ ip_interface_address_t *a, *prev, *next;
+ uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib);
- vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, sw_if_index, ~0);
+ vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
+ sw_if_index, ~0);
a = p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
/* Verify given length. */
if ((a && (address_length != a->address_length)) || (address_length == 0))
{
vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
- return clib_error_create
- ( "%U wrong length (expected %d) for interface %U",
- lm->format_address_and_length, addr_fib,
- address_length, a? a->address_length : -1,
- format_vnet_sw_if_index_name, vnm, sw_if_index);
+ return clib_error_create
+ ("%U wrong length (expected %d) for interface %U",
+ lm->format_address_and_length, addr_fib,
+ address_length, a ? a->address_length : -1,
+ format_vnet_sw_if_index_name, vnm, sw_if_index);
}
if (is_del)
{
- if (!a)
- {
- vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, sw_if_index);
- vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
- return clib_error_create ("%U not found for interface %U",
- lm->format_address_and_length,
- addr_fib, address_length,
- format_vnet_sw_interface_name, vnm, si);
- }
+ if (!a)
+ {
+ vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
+ vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
+ return clib_error_create ("%U not found for interface %U",
+ lm->format_address_and_length,
+ addr_fib, address_length,
+ format_vnet_sw_interface_name, vnm, si);
+ }
if (a->prev_this_sw_interface != ~0)
{
- prev = pool_elt_at_index (lm->if_address_pool, a->prev_this_sw_interface);
+ prev =
+ pool_elt_at_index (lm->if_address_pool,
+ a->prev_this_sw_interface);
prev->next_this_sw_interface = a->next_this_sw_interface;
}
if (a->next_this_sw_interface != ~0)
{
- next = pool_elt_at_index (lm->if_address_pool, a->next_this_sw_interface);
+ next =
+ pool_elt_at_index (lm->if_address_pool,
+ a->next_this_sw_interface);
next->prev_this_sw_interface = a->prev_this_sw_interface;
- if(a->prev_this_sw_interface == ~0)
- lm->if_address_pool_index_by_sw_if_index[sw_if_index] = a->next_this_sw_interface;
+ if (a->prev_this_sw_interface == ~0)
+ lm->if_address_pool_index_by_sw_if_index[sw_if_index] =
+ a->next_this_sw_interface;
}
- if ((a->next_this_sw_interface == ~0) && (a->prev_this_sw_interface == ~0))
+ if ((a->next_this_sw_interface == ~0)
+ && (a->prev_this_sw_interface == ~0))
lm->if_address_pool_index_by_sw_if_index[sw_if_index] = ~0;
mhash_unset (&lm->address_to_if_address_index, addr_fib,
@@ -118,11 +124,11 @@ ip_interface_address_add_del (ip_lookup_main_t * lm,
*result_if_address_index = ~0;
}
- else if (! a)
+ else if (!a)
{
- u32 pi; /* previous index */
- u32 ai;
- u32 hi; /* head index */
+ u32 pi; /* previous index */
+ u32 ai;
+ u32 hi; /* head index */
pool_get (lm->if_address_pool, a);
memset (a, ~0, sizeof (a[0]));
@@ -130,12 +136,12 @@ ip_interface_address_add_del (ip_lookup_main_t * lm,
hi = pi = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
prev = 0;
- while (pi != (u32)~0)
- {
- prev = pool_elt_at_index(lm->if_address_pool, pi);
- pi = prev->next_this_sw_interface;
- }
- pi = prev ? prev - lm->if_address_pool : (u32)~0;
+ while (pi != (u32) ~ 0)
+ {
+ prev = pool_elt_at_index (lm->if_address_pool, pi);
+ pi = prev->next_this_sw_interface;
+ }
+ pi = prev ? prev - lm->if_address_pool : (u32) ~ 0;
a->address_key = mhash_set (&lm->address_to_if_address_index,
addr_fib, ai, /* old_value */ 0);
@@ -145,10 +151,10 @@ ip_interface_address_add_del (ip_lookup_main_t * lm,
a->prev_this_sw_interface = pi;
a->next_this_sw_interface = ~0;
if (prev)
- prev->next_this_sw_interface = ai;
+ prev->next_this_sw_interface = ai;
- lm->if_address_pool_index_by_sw_if_index[sw_if_index] =
- (hi != ~0) ? hi : ai;
+ lm->if_address_pool_index_by_sw_if_index[sw_if_index] =
+ (hi != ~0) ? hi : ai;
if (result_if_address_index)
*result_if_address_index = ai;
}
@@ -157,23 +163,25 @@ ip_interface_address_add_del (ip_lookup_main_t * lm,
if (result_if_address_index)
*result_if_address_index = a - lm->if_address_pool;
}
-
+
return /* no error */ 0;
}
-void ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6)
+void
+ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6)
{
/* ensure that adjacency is cacheline aligned and sized */
- STATIC_ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0) == 0,
- "Cache line marker must be 1st element in struct");
- STATIC_ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline1) == CLIB_CACHE_LINE_BYTES,
- "Data in cache line 0 is bigger than cache line size");
+ STATIC_ASSERT (STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0,
+ "Cache line marker must be 1st element in struct");
+ STATIC_ASSERT (STRUCT_OFFSET_OF (ip_adjacency_t, cacheline1) ==
+ CLIB_CACHE_LINE_BYTES,
+ "Data in cache line 0 is bigger than cache line size");
/* Preallocate three "special" adjacencies */
lm->adjacency_heap = adj_pool;
- if (! lm->fib_result_n_bytes)
+ if (!lm->fib_result_n_bytes)
lm->fib_result_n_bytes = sizeof (uword);
lm->is_ip6 = is_ip6;
@@ -201,16 +209,21 @@ void ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6)
}
lm->local_next_by_ip_protocol[IP_PROTOCOL_UDP] = IP_LOCAL_NEXT_UDP_LOOKUP;
- lm->local_next_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : IP_PROTOCOL_ICMP] = IP_LOCAL_NEXT_ICMP;
- lm->builtin_protocol_by_ip_protocol[IP_PROTOCOL_UDP] = IP_BUILTIN_PROTOCOL_UDP;
- lm->builtin_protocol_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : IP_PROTOCOL_ICMP] = IP_BUILTIN_PROTOCOL_ICMP;
+ lm->local_next_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 :
+ IP_PROTOCOL_ICMP] = IP_LOCAL_NEXT_ICMP;
+ lm->builtin_protocol_by_ip_protocol[IP_PROTOCOL_UDP] =
+ IP_BUILTIN_PROTOCOL_UDP;
+ lm->builtin_protocol_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 :
+ IP_PROTOCOL_ICMP] =
+ IP_BUILTIN_PROTOCOL_ICMP;
}
}
-u8 * format_ip_flow_hash_config (u8 * s, va_list * args)
+u8 *
+format_ip_flow_hash_config (u8 * s, va_list * args)
{
flow_hash_config_t flow_hash_config = va_arg (*args, u32);
-
+
#define _(n,v) if (flow_hash_config & v) s = format (s, "%s ", #n);
foreach_flow_hash_bit;
#undef _
@@ -218,10 +231,11 @@ u8 * format_ip_flow_hash_config (u8 * s, va_list * args)
return s;
}
-u8 * format_ip_lookup_next (u8 * s, va_list * args)
+u8 *
+format_ip_lookup_next (u8 * s, va_list * args)
{
ip_lookup_next_t n = va_arg (*args, ip_lookup_next_t);
- char * t = 0;
+ char *t = 0;
switch (n)
{
@@ -229,11 +243,21 @@ u8 * format_ip_lookup_next (u8 * s, va_list * args)
s = format (s, "unknown %d", n);
return s;
- case IP_LOOKUP_NEXT_DROP: t = "drop"; break;
- case IP_LOOKUP_NEXT_PUNT: t = "punt"; break;
- case IP_LOOKUP_NEXT_ARP: t = "arp"; break;
- case IP_LOOKUP_NEXT_MIDCHAIN: t="midchain"; break;
- case IP_LOOKUP_NEXT_GLEAN: t="glean"; break;
+ case IP_LOOKUP_NEXT_DROP:
+ t = "drop";
+ break;
+ case IP_LOOKUP_NEXT_PUNT:
+ t = "punt";
+ break;
+ case IP_LOOKUP_NEXT_ARP:
+ t = "arp";
+ break;
+ case IP_LOOKUP_NEXT_MIDCHAIN:
+ t = "midchain";
+ break;
+ case IP_LOOKUP_NEXT_GLEAN:
+ t = "glean";
+ break;
case IP_LOOKUP_NEXT_REWRITE:
break;
}
@@ -244,20 +268,22 @@ u8 * format_ip_lookup_next (u8 * s, va_list * args)
return s;
}
-u8 * format_ip_adjacency_packet_data (u8 * s, va_list * args)
+u8 *
+format_ip_adjacency_packet_data (u8 * s, va_list * args)
{
- vnet_main_t * vnm = va_arg (*args, vnet_main_t *);
+ vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
u32 adj_index = va_arg (*args, u32);
- u8 * packet_data = va_arg (*args, u8 *);
+ u8 *packet_data = va_arg (*args, u8 *);
u32 n_packet_data_bytes = va_arg (*args, u32);
- ip_adjacency_t * adj = adj_get(adj_index);
+ ip_adjacency_t *adj = adj_get (adj_index);
switch (adj->lookup_next_index)
{
case IP_LOOKUP_NEXT_REWRITE:
s = format (s, "%U",
format_vnet_rewrite_header,
- vnm->vlib_main, &adj->rewrite_header, packet_data, n_packet_data_bytes);
+ vnm->vlib_main, &adj->rewrite_header, packet_data,
+ n_packet_data_bytes);
break;
default:
@@ -267,38 +293,39 @@ u8 * format_ip_adjacency_packet_data (u8 * s, va_list * args)
return s;
}
-static uword unformat_dpo (unformat_input_t * input, va_list * args)
+static uword
+unformat_dpo (unformat_input_t * input, va_list * args)
{
dpo_id_t *dpo = va_arg (*args, dpo_id_t *);
fib_protocol_t fp = va_arg (*args, int);
dpo_proto_t proto;
- proto = fib_proto_to_dpo(fp);
+ proto = fib_proto_to_dpo (fp);
if (unformat (input, "drop"))
- dpo_copy(dpo, drop_dpo_get(proto));
+ dpo_copy (dpo, drop_dpo_get (proto));
else if (unformat (input, "punt"))
- dpo_copy(dpo, punt_dpo_get(proto));
+ dpo_copy (dpo, punt_dpo_get (proto));
else if (unformat (input, "local"))
- receive_dpo_add_or_lock(proto, ~0, NULL, dpo);
+ receive_dpo_add_or_lock (proto, ~0, NULL, dpo);
else if (unformat (input, "null-send-unreach"))
- ip_null_dpo_add_and_lock(proto, IP_NULL_ACTION_SEND_ICMP_UNREACH, dpo);
+ ip_null_dpo_add_and_lock (proto, IP_NULL_ACTION_SEND_ICMP_UNREACH, dpo);
else if (unformat (input, "null-send-prohibit"))
- ip_null_dpo_add_and_lock(proto, IP_NULL_ACTION_SEND_ICMP_PROHIBIT, dpo);
+ ip_null_dpo_add_and_lock (proto, IP_NULL_ACTION_SEND_ICMP_PROHIBIT, dpo);
else if (unformat (input, "null"))
- ip_null_dpo_add_and_lock(proto, IP_NULL_ACTION_NONE, dpo);
+ ip_null_dpo_add_and_lock (proto, IP_NULL_ACTION_NONE, dpo);
else if (unformat (input, "classify"))
{
u32 classify_table_index;
if (!unformat (input, "%d", &classify_table_index))
- {
+ {
clib_warning ("classify adj must specify table index");
- return 0;
+ return 0;
}
- dpo_set(dpo, DPO_CLASSIFY, proto,
- classify_dpo_create(proto, classify_table_index));
+ dpo_set (dpo, DPO_CLASSIFY, proto,
+ classify_dpo_create (proto, classify_table_index));
}
else
return 0;
@@ -307,69 +334,66 @@ static uword unformat_dpo (unformat_input_t * input, va_list * args)
}
const ip46_address_t zero_addr = {
- .as_u64 = {
- 0, 0
- },
+ .as_u64 = {
+ 0, 0},
};
u32
-fib_table_id_find_fib_index (fib_protocol_t proto,
- u32 table_id)
+fib_table_id_find_fib_index (fib_protocol_t proto, u32 table_id)
{
- ip4_main_t *im4 = &ip4_main;
- ip6_main_t *im6 = &ip6_main;
- uword * p;
+ ip4_main_t *im4 = &ip4_main;
+ ip6_main_t *im6 = &ip6_main;
+ uword *p;
- switch (proto)
+ switch (proto)
{
case FIB_PROTOCOL_IP4:
- p = hash_get(im4->fib_index_by_table_id, table_id);
- break;
+ p = hash_get (im4->fib_index_by_table_id, table_id);
+ break;
case FIB_PROTOCOL_IP6:
- p = hash_get(im6->fib_index_by_table_id, table_id);
- break;
+ p = hash_get (im6->fib_index_by_table_id, table_id);
+ break;
default:
- p = NULL;
- break;
+ p = NULL;
+ break;
}
- if (NULL != p)
+ if (NULL != p)
{
- return (p[0]);
+ return (p[0]);
}
- return (~0);
+ return (~0);
}
clib_error_t *
vnet_ip_route_cmd (vlib_main_t * vm,
- unformat_input_t * main_input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * main_input, vlib_cli_command_t * cmd)
{
- unformat_input_t _line_input, * line_input = &_line_input;
+ unformat_input_t _line_input, *line_input = &_line_input;
fib_route_path_t *rpaths = NULL, rpath;
dpo_id_t dpo = DPO_INVALID, *dpos = NULL;
fib_prefix_t *prefixs = NULL, pfx;
mpls_label_t out_label, via_label;
- clib_error_t * error = NULL;
+ clib_error_t *error = NULL;
u32 table_id, is_del;
- vnet_main_t * vnm;
+ vnet_main_t *vnm;
u32 fib_index;
f64 count;
int i;
- vnm = vnet_get_main();
+ vnm = vnet_get_main ();
is_del = 0;
table_id = 0;
count = 1;
- memset(&pfx, 0, sizeof(pfx));
+ memset (&pfx, 0, sizeof (pfx));
out_label = via_label = MPLS_LABEL_INVALID;
/* Get a line of input. */
- if (! unformat_user (main_input, unformat_line_input, line_input))
+ if (!unformat_user (main_input, unformat_line_input, line_input))
return 0;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- memset(&rpath, 0, sizeof(rpath));
+ memset (&rpath, 0, sizeof (rpath));
if (unformat (line_input, "table %d", &table_id))
;
@@ -378,129 +402,120 @@ vnet_ip_route_cmd (vlib_main_t * vm,
else if (unformat (line_input, "add"))
is_del = 0;
else if (unformat (line_input, "resolve-via-host"))
- {
- if (vec_len(rpaths) == 0)
- {
- error = clib_error_return(0 , "Paths then flags");
+ {
+ if (vec_len (rpaths) == 0)
+ {
+ error = clib_error_return (0, "Paths then flags");
goto done;
- }
- rpaths[vec_len(rpaths)-1].frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
- }
+ }
+ rpaths[vec_len (rpaths) - 1].frp_flags |=
+ FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
+ }
else if (unformat (line_input, "resolve-via-attached"))
- {
- if (vec_len(rpaths) == 0)
- {
- error = clib_error_return(0 , "Paths then flags");
+ {
+ if (vec_len (rpaths) == 0)
+ {
+ error = clib_error_return (0, "Paths then flags");
goto done;
- }
- rpaths[vec_len(rpaths)-1].frp_flags |=
- FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
- }
+ }
+ rpaths[vec_len (rpaths) - 1].frp_flags |=
+ FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
+ }
else if (unformat (line_input, "out-label %U",
- unformat_mpls_unicast_label, &out_label))
- {
- if (vec_len(rpaths) == 0)
- {
- error = clib_error_return(0 , "Paths then labels");
+ unformat_mpls_unicast_label, &out_label))
+ {
+ if (vec_len (rpaths) == 0)
+ {
+ error = clib_error_return (0, "Paths then labels");
goto done;
- }
- vec_add1(rpaths[vec_len(rpaths)-1].frp_label_stack, out_label);
- }
+ }
+ vec_add1 (rpaths[vec_len (rpaths) - 1].frp_label_stack, out_label);
+ }
else if (unformat (line_input, "via-label %U",
- unformat_mpls_unicast_label,
- &rpath.frp_local_label))
- {
+ unformat_mpls_unicast_label, &rpath.frp_local_label))
+ {
rpath.frp_weight = 1;
rpath.frp_proto = FIB_PROTOCOL_MPLS;
rpath.frp_sw_if_index = ~0;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "count %f", &count))
;
else if (unformat (line_input, "%U/%d",
- unformat_ip4_address,
- &pfx.fp_addr.ip4,
- &pfx.fp_len))
- {
+ unformat_ip4_address, &pfx.fp_addr.ip4, &pfx.fp_len))
+ {
pfx.fp_proto = FIB_PROTOCOL_IP4;
- vec_add1(prefixs, pfx);
- }
+ vec_add1 (prefixs, pfx);
+ }
else if (unformat (line_input, "%U/%d",
- unformat_ip6_address,
- &pfx.fp_addr.ip6,
- &pfx.fp_len))
- {
+ unformat_ip6_address, &pfx.fp_addr.ip6, &pfx.fp_len))
+ {
pfx.fp_proto = FIB_PROTOCOL_IP6;
- vec_add1(prefixs, pfx);
- }
+ vec_add1 (prefixs, pfx);
+ }
else if (unformat (line_input, "via %U %U weight %u",
unformat_ip4_address,
&rpath.frp_addr.ip4,
unformat_vnet_sw_interface, vnm,
- &rpath.frp_sw_if_index,
- &rpath.frp_weight))
- {
+ &rpath.frp_sw_if_index, &rpath.frp_weight))
+ {
rpath.frp_proto = FIB_PROTOCOL_IP4;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "via %U %U weight %u",
unformat_ip6_address,
&rpath.frp_addr.ip6,
unformat_vnet_sw_interface, vnm,
- &rpath.frp_sw_if_index,
- &rpath.frp_weight))
- {
+ &rpath.frp_sw_if_index, &rpath.frp_weight))
+ {
rpath.frp_proto = FIB_PROTOCOL_IP6;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "via %U %U",
unformat_ip4_address,
- &rpath.frp_addr.ip4,
+ &rpath.frp_addr.ip4,
unformat_vnet_sw_interface, vnm,
&rpath.frp_sw_if_index))
- {
+ {
rpath.frp_weight = 1;
rpath.frp_proto = FIB_PROTOCOL_IP4;
- vec_add1(rpaths, rpath);
- }
-
+ vec_add1 (rpaths, rpath);
+ }
+
else if (unformat (line_input, "via %U %U",
unformat_ip6_address,
- &rpath.frp_addr.ip6,
+ &rpath.frp_addr.ip6,
unformat_vnet_sw_interface, vnm,
&rpath.frp_sw_if_index))
- {
+ {
rpath.frp_weight = 1;
rpath.frp_proto = FIB_PROTOCOL_IP6;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "via %U next-hop-table %d",
unformat_ip4_address,
- &rpath.frp_addr.ip4,
- &rpath.frp_fib_index))
- {
+ &rpath.frp_addr.ip4, &rpath.frp_fib_index))
+ {
rpath.frp_weight = 1;
rpath.frp_sw_if_index = ~0;
rpath.frp_proto = FIB_PROTOCOL_IP4;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "via %U next-hop-table %d",
unformat_ip6_address,
- &rpath.frp_addr.ip6,
- &rpath.frp_fib_index))
- {
+ &rpath.frp_addr.ip6, &rpath.frp_fib_index))
+ {
rpath.frp_weight = 1;
rpath.frp_sw_if_index = ~0;
rpath.frp_proto = FIB_PROTOCOL_IP6;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "via %U",
- unformat_ip4_address,
- &rpath.frp_addr.ip4))
- {
+ unformat_ip4_address, &rpath.frp_addr.ip4))
+ {
/*
* the recursive next-hops are by default in the same table
* as the prefix
@@ -509,44 +524,43 @@ vnet_ip_route_cmd (vlib_main_t * vm,
rpath.frp_weight = 1;
rpath.frp_sw_if_index = ~0;
rpath.frp_proto = FIB_PROTOCOL_IP4;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input, "via %U",
- unformat_ip6_address,
- &rpath.frp_addr.ip6))
- {
+ unformat_ip6_address, &rpath.frp_addr.ip6))
+ {
rpath.frp_fib_index = table_id;
rpath.frp_weight = 1;
rpath.frp_sw_if_index = ~0;
rpath.frp_proto = FIB_PROTOCOL_IP6;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (unformat (line_input,
- "lookup in table %d",
- &rpath.frp_fib_index))
- {
+ "lookup in table %d", &rpath.frp_fib_index))
+ {
rpath.frp_proto = pfx.fp_proto;
rpath.frp_sw_if_index = ~0;
- vec_add1(rpaths, rpath);
- }
+ vec_add1 (rpaths, rpath);
+ }
else if (vec_len (prefixs) > 0 &&
unformat (line_input, "via %U",
unformat_dpo, &dpo, prefixs[0].fp_proto))
- {
+ {
vec_add1 (dpos, dpo);
- }
+ }
else
- {
+ {
error = unformat_parse_error (line_input);
goto done;
- }
+ }
}
-
+
unformat_free (line_input);
if (vec_len (prefixs) == 0)
- {
- error = clib_error_return (0, "expected ip4/ip6 destination address/length.");
+ {
+ error =
+ clib_error_return (0, "expected ip4/ip6 destination address/length.");
goto done;
}
@@ -557,50 +571,47 @@ vnet_ip_route_cmd (vlib_main_t * vm,
}
if (~0 == table_id)
- {
+ {
/*
* if no table_id is passed we will manipulate the default
*/
fib_index = 0;
- }
+ }
else
- {
- fib_index = fib_table_id_find_fib_index(prefixs[0].fp_proto,
- table_id);
+ {
+ fib_index = fib_table_id_find_fib_index (prefixs[0].fp_proto, table_id);
if (~0 == fib_index)
- {
- error = clib_error_return (0,
- "Nonexistent table id %d",
- table_id);
+ {
+ error = clib_error_return (0, "Nonexistent table id %d", table_id);
goto done;
- }
- }
+ }
+ }
for (i = 0; i < vec_len (prefixs); i++)
- {
+ {
if (is_del && 0 == vec_len (rpaths))
- {
- fib_table_entry_delete(fib_index,
- &prefixs[i],
- FIB_SOURCE_CLI);
- }
+ {
+ fib_table_entry_delete (fib_index, &prefixs[i], FIB_SOURCE_CLI);
+ }
else if (!is_del && 1 == vec_len (dpos))
- {
- fib_table_entry_special_dpo_add(fib_index,
- &prefixs[i],
- FIB_SOURCE_CLI,
- FIB_ENTRY_FLAG_EXCLUSIVE,
- &dpos[0]);
- dpo_reset(&dpos[0]);
- }
+ {
+ fib_table_entry_special_dpo_add (fib_index,
+ &prefixs[i],
+ FIB_SOURCE_CLI,
+ FIB_ENTRY_FLAG_EXCLUSIVE,
+ &dpos[0]);
+ dpo_reset (&dpos[0]);
+ }
else if (vec_len (dpos) > 0)
- {
- error = clib_error_return(0 , "Load-balancing over multiple special adjacencies is unsupported");
+ {
+ error =
+ clib_error_return (0,
+ "Load-balancing over multiple special adjacencies is unsupported");
goto done;
- }
+ }
else if (0 < vec_len (rpaths))
- {
+ {
u32 k, j, n, incr;
ip46_address_t dst = prefixs[i].fp_addr;
f64 t[2];
@@ -610,97 +621,106 @@ vnet_ip_route_cmd (vlib_main_t * vm,
prefixs[i].fp_len);
for (k = 0; k < n; k++)
- {
+ {
for (j = 0; j < vec_len (rpaths); j++)
- {
+ {
u32 fi;
/*
* the CLI parsing stored table Ids, swap to FIB indicies
*/
- fi = fib_table_id_find_fib_index(prefixs[i].fp_proto,
- rpaths[i].frp_fib_index);
+ fi = fib_table_id_find_fib_index (prefixs[i].fp_proto,
+ rpaths[i].frp_fib_index);
if (~0 == fi)
- {
- error = clib_error_return(0 , "Via table %d does not exist",
- rpaths[i].frp_fib_index);
+ {
+ error =
+ clib_error_return (0, "Via table %d does not exist",
+ rpaths[i].frp_fib_index);
goto done;
- }
+ }
rpaths[i].frp_fib_index = fi;
fib_prefix_t rpfx = {
- .fp_len = prefixs[i].fp_len,
- .fp_proto = prefixs[i].fp_proto,
- .fp_addr = dst,
+ .fp_len = prefixs[i].fp_len,
+ .fp_proto = prefixs[i].fp_proto,
+ .fp_addr = dst,
};
- if (is_del)
- fib_table_entry_path_remove2(fib_index,
- &rpfx,
- FIB_SOURCE_CLI,
- &rpaths[j]);
- else
- fib_table_entry_path_add2(fib_index,
- &rpfx,
- FIB_SOURCE_CLI,
- FIB_ENTRY_FLAG_NONE,
- &rpaths[j]);
- }
+ if (is_del)
+ fib_table_entry_path_remove2 (fib_index,
+ &rpfx,
+ FIB_SOURCE_CLI, &rpaths[j]);
+ else
+ fib_table_entry_path_add2 (fib_index,
+ &rpfx,
+ FIB_SOURCE_CLI,
+ FIB_ENTRY_FLAG_NONE,
+ &rpaths[j]);
+ }
if (FIB_PROTOCOL_IP4 == prefixs[0].fp_proto)
- {
+ {
dst.ip4.as_u32 =
- clib_host_to_net_u32(incr +
- clib_net_to_host_u32 (dst.ip4.as_u32));
- }
+ clib_host_to_net_u32 (incr +
+ clib_net_to_host_u32 (dst.
+ ip4.as_u32));
+ }
else
- {
+ {
int bucket = (incr < 64 ? 0 : 1);
dst.ip6.as_u64[bucket] =
- clib_host_to_net_u64(incr +
- clib_net_to_host_u64 (
- dst.ip6.as_u64[bucket]));
+ clib_host_to_net_u64 (incr +
+ clib_net_to_host_u64 (dst.ip6.as_u64
+ [bucket]));
- }
- }
+ }
+ }
t[1] = vlib_time_now (vm);
if (count > 1)
- vlib_cli_output (vm, "%.6e routes/sec", count / (t[1] - t[0]));
- }
+ vlib_cli_output (vm, "%.6e routes/sec", count / (t[1] - t[0]));
+ }
else
- {
- error = clib_error_return(0 , "Don't understand what you want...");
+ {
+ error = clib_error_return (0, "Don't understand what you want...");
goto done;
- }
- }
+ }
+ }
- done:
+done:
vec_free (dpos);
vec_free (prefixs);
vec_free (rpaths);
return error;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vlib_cli_ip_command, static) = {
.path = "ip",
.short_help = "Internet protocol (IP) commands",
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vlib_cli_ip6_command, static) = {
.path = "ip6",
.short_help = "Internet protocol version 6 (IPv6) commands",
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vlib_cli_show_ip_command, static) = {
.path = "show ip",
.short_help = "Internet protocol (IP) show commands",
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vlib_cli_show_ip6_command, static) = {
.path = "show ip6",
.short_help = "Internet protocol version 6 (IPv6) show commands",
};
+/* *INDENT-ON* */
/*?
* This command is used to add or delete IPv4 or IPv6 routes. All
@@ -744,22 +764,22 @@ VLIB_CLI_COMMAND (ip_route_command, static) = {
* or dependent route-adds will simply fail.
*/
static clib_error_t *
-ip6_probe_neighbor_wait (vlib_main_t *vm, ip6_address_t * a, u32 sw_if_index,
+ip6_probe_neighbor_wait (vlib_main_t * vm, ip6_address_t * a, u32 sw_if_index,
int retry_count)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * e;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *e;
int i;
int resolved = 0;
uword event_type;
uword *event_data = 0;
- ASSERT (vlib_in_process_context(vm));
+ ASSERT (vlib_in_process_context (vm));
if (retry_count > 0)
vnet_register_ip6_neighbor_resolution_event
(vnm, a, vlib_get_current_process (vm)->node_runtime.node_index,
- 1 /* event */, 0 /* data */);
+ 1 /* event */ , 0 /* data */ );
for (i = 0; i < retry_count; i++)
{
@@ -773,121 +793,118 @@ ip6_probe_neighbor_wait (vlib_main_t *vm, ip6_address_t * a, u32 sw_if_index,
event_type = vlib_process_get_events (vm, &event_data);
switch (event_type)
{
- case 1: /* resolved... */
- vlib_cli_output (vm, "Resolved %U",
- format_ip6_address, a);
- resolved = 1;
- goto done;
-
- case ~0: /* timeout */
- break;
-
- default:
- clib_warning ("unknown event_type %d", event_type);
- }
+ case 1: /* resolved... */
+ vlib_cli_output (vm, "Resolved %U", format_ip6_address, a);
+ resolved = 1;
+ goto done;
+
+ case ~0: /* timeout */
+ break;
+
+ default:
+ clib_warning ("unknown event_type %d", event_type);
+ }
vec_reset_length (event_data);
}
-
- done:
+
+done:
if (!resolved)
return clib_error_return (0, "Resolution failed for %U",
- format_ip6_address, a);
+ format_ip6_address, a);
return 0;
}
static clib_error_t *
-ip4_probe_neighbor_wait (vlib_main_t *vm, ip4_address_t * a, u32 sw_if_index,
- int retry_count)
+ip4_probe_neighbor_wait (vlib_main_t * vm, ip4_address_t * a, u32 sw_if_index,
+ int retry_count)
{
- vnet_main_t * vnm = vnet_get_main();
- clib_error_t * e;
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *e;
int i;
int resolved = 0;
uword event_type;
uword *event_data = 0;
- ASSERT (vlib_in_process_context(vm));
+ ASSERT (vlib_in_process_context (vm));
if (retry_count > 0)
- vnet_register_ip4_arp_resolution_event
+ vnet_register_ip4_arp_resolution_event
(vnm, a, vlib_get_current_process (vm)->node_runtime.node_index,
- 1 /* event */, 0 /* data */);
-
+ 1 /* event */ , 0 /* data */ );
+
for (i = 0; i < retry_count; i++)
{
/* The interface may be down, etc. */
e = ip4_probe_neighbor (vm, a, sw_if_index);
-
+
if (e)
- return e;
-
+ return e;
+
vlib_process_wait_for_event_or_clock (vm, 1.0);
event_type = vlib_process_get_events (vm, &event_data);
- switch (event_type)
- {
- case 1: /* resolved... */
- vlib_cli_output (vm, "Resolved %U",
- format_ip4_address, a);
- resolved = 1;
- goto done;
-
- case ~0: /* timeout */
- break;
-
- default:
- clib_warning ("unknown event_type %d", event_type);
- }
+ switch (event_type)
+ {
+ case 1: /* resolved... */
+ vlib_cli_output (vm, "Resolved %U", format_ip4_address, a);
+ resolved = 1;
+ goto done;
+
+ case ~0: /* timeout */
+ break;
+
+ default:
+ clib_warning ("unknown event_type %d", event_type);
+ }
vec_reset_length (event_data);
}
-
- done:
+
+done:
vec_reset_length (event_data);
if (!resolved)
return clib_error_return (0, "Resolution failed for %U",
- format_ip4_address, a);
+ format_ip4_address, a);
return 0;
}
static clib_error_t *
probe_neighbor_address (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- vnet_main_t * vnm = vnet_get_main();
- unformat_input_t _line_input, * line_input = &_line_input;
+ vnet_main_t *vnm = vnet_get_main ();
+ unformat_input_t _line_input, *line_input = &_line_input;
ip4_address_t a4;
ip6_address_t a6;
- clib_error_t * error = 0;
+ clib_error_t *error = 0;
u32 sw_if_index = ~0;
int retry_count = 3;
int is_ip4 = 1;
int address_set = 0;
/* Get a line of input. */
- if (! unformat_user (input, unformat_line_input, line_input))
+ if (!unformat_user (input, unformat_line_input, line_input))
return 0;
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat_user (line_input, unformat_vnet_sw_interface, vnm,
- &sw_if_index))
- ;
+ if (unformat_user (line_input, unformat_vnet_sw_interface, vnm,
+ &sw_if_index))
+ ;
else if (unformat (line_input, "retry %d", &retry_count))
- ;
+ ;
else if (unformat (line_input, "%U", unformat_ip4_address, &a4))
- address_set++;
+ address_set++;
else if (unformat (line_input, "%U", unformat_ip6_address, &a6))
- {
- address_set++;
- is_ip4 = 0;
- }
+ {
+ address_set++;
+ is_ip4 = 0;
+ }
else
- return clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
+ return clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, line_input);
}
unformat_free (line_input);
@@ -898,10 +915,10 @@ probe_neighbor_address (vlib_main_t * vm,
return clib_error_return (0, "ip address required, not set.");
if (address_set > 1)
return clib_error_return (0, "Multiple ip addresses not supported.");
-
+
if (is_ip4)
error = ip4_probe_neighbor_wait (vm, &a4, sw_if_index, retry_count);
- else
+ else
error = ip6_probe_neighbor_wait (vm, &a6, sw_if_index, retry_count);
return error;
@@ -931,3 +948,11 @@ VLIB_CLI_COMMAND (ip_probe_neighbor_command, static) = {
.is_mp_safe = 1,
};
/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/lookup.h b/vnet/vnet/ip/lookup.h
index 4b6aaa10da9..3dbd7b3b8e8 100644
--- a/vnet/vnet/ip/lookup.h
+++ b/vnet/vnet/ip/lookup.h
@@ -57,7 +57,8 @@
#include <vnet/feature/feature.h>
/** @brief Common (IP4/IP6) next index stored in adjacency. */
-typedef enum {
+typedef enum
+{
/** Adjacency to drop this packet. */
IP_LOOKUP_NEXT_DROP,
/** Adjacency to punt this packet. */
@@ -93,11 +94,13 @@ typedef enum {
IP_LOOKUP_N_NEXT,
} ip_lookup_next_t;
-typedef enum {
+typedef enum
+{
IP4_LOOKUP_N_NEXT = IP_LOOKUP_N_NEXT,
} ip4_lookup_next_t;
-typedef enum {
+typedef enum
+{
/* Hop-by-hop header handling */
IP6_LOOKUP_NEXT_HOP_BY_HOP = IP_LOOKUP_N_NEXT,
IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP,
@@ -164,9 +167,9 @@ struct ip_adjacency_t_;
/**
* @brief A function type for post-rewrite fixups on midchain adjacency
*/
-typedef void (*adj_midchain_fixup_t)(vlib_main_t * vm,
- struct ip_adjacency_t_ *adj,
- vlib_buffer_t * b0);
+typedef void (*adj_midchain_fixup_t) (vlib_main_t * vm,
+ struct ip_adjacency_t_ * adj,
+ vlib_buffer_t * b0);
/**
* @brief Flags on an IP adjacency
@@ -176,22 +179,24 @@ typedef enum ip_adjacency_flags_t_
/**
* Currently a sync walk is active. Used to prevent re-entrant walking
*/
- IP_ADJ_SYNC_WALK_ACTIVE = (1 << 0),
+ IP_ADJ_SYNC_WALK_ACTIVE = (1 << 0),
} ip_adjacency_flags_t;
/** @brief IP unicast adjacency.
@note cache aligned.
*/
-typedef struct ip_adjacency_t_ {
- CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
+typedef struct ip_adjacency_t_
+{
+ CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
/** Number of adjecencies in block. Greater than 1 means multipath;
otherwise equal to 1. */
u16 n_adj;
/** Next hop after ip4-lookup. */
- union {
- ip_lookup_next_t lookup_next_index : 16;
+ union
+ {
+ ip_lookup_next_t lookup_next_index:16;
u16 lookup_next_index_as_int;
};
@@ -199,7 +204,7 @@ typedef struct ip_adjacency_t_ {
u32 if_address_index;
/** Force re-lookup in a different FIB. ~0 => normal behavior */
- u16 mcast_group_index;
+ u16 mcast_group_index;
/** Highest possible perf subgraph arc interposition, e.g. for ip6 ioam */
u16 saved_lookup_next_index;
@@ -210,15 +215,17 @@ typedef struct ip_adjacency_t_ {
vnet_link_t ia_link;
u8 ia_nh_proto;
- union {
+ union
+ {
/**
* IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE
*
* neighbour adjacency sub-type;
*/
- struct {
- ip46_address_t next_hop;
- } nbr;
+ struct
+ {
+ ip46_address_t next_hop;
+ } nbr;
/**
* IP_LOOKUP_NEXT_MIDCHAIN
*
@@ -227,38 +234,40 @@ typedef struct ip_adjacency_t_ {
* so be sure to leave the two structs with the next_hop
* fields aligned.
*/
- struct {
+ struct
+ {
/**
* The recursive next-hop
*/
- ip46_address_t next_hop;
+ ip46_address_t next_hop;
/**
* The node index of the tunnel's post rewrite/TX function.
*/
- u32 tx_function_node;
+ u32 tx_function_node;
/**
* The next DPO to use
*/
- dpo_id_t next_dpo;
+ dpo_id_t next_dpo;
/**
* A function to perform the post-rewrite fixup
*/
- adj_midchain_fixup_t fixup_func;
- } midchain;
+ adj_midchain_fixup_t fixup_func;
+ } midchain;
/**
* IP_LOOKUP_NEXT_GLEAN
*
* Glean the address to ARP for from the packet's destination
*/
- struct {
- ip46_address_t receive_addr;
- } glean;
+ struct
+ {
+ ip46_address_t receive_addr;
+ } glean;
} sub_type;
- CLIB_CACHE_LINE_ALIGN_MARK(cacheline1);
+ CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
/* Rewrite in second/third cache lines */
- vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
+ vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
/*
* member not accessed in the data plane are relgated to the
@@ -273,17 +282,18 @@ typedef struct ip_adjacency_t_ {
} ip_adjacency_t;
-STATIC_ASSERT((STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0) == 0),
- "IP adjacency cachline 0 is not offset");
-STATIC_ASSERT((STRUCT_OFFSET_OF(ip_adjacency_t, cacheline1) ==
- CLIB_CACHE_LINE_BYTES),
- "IP adjacency cachline 1 is more than one cachline size offset");
+STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0),
+ "IP adjacency cachline 0 is not offset");
+STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline1) ==
+ CLIB_CACHE_LINE_BYTES),
+ "IP adjacency cachline 1 is more than one cachline size offset");
/* An all zeros address */
extern const ip46_address_t zero_addr;
/* IP multicast adjacency. */
-typedef struct {
+typedef struct
+{
/* Handle for this adjacency in adjacency heap. */
u32 heap_handle;
@@ -291,31 +301,36 @@ typedef struct {
u32 n_adj;
/* Rewrite string. */
- vnet_declare_rewrite (64 - 2*sizeof(u32));
-} ip_multicast_rewrite_t;
+ vnet_declare_rewrite (64 - 2 * sizeof (u32));
+}
+ip_multicast_rewrite_t;
-typedef struct {
+typedef struct
+{
/* ip4-multicast-rewrite next index. */
u32 next_index;
u8 n_rewrite_bytes;
- u8 rewrite_string[64 - 1*sizeof(u32) - 1*sizeof(u8)];
-} ip_multicast_rewrite_string_t;
+ u8 rewrite_string[64 - 1 * sizeof (u32) - 1 * sizeof (u8)];
+}
+ip_multicast_rewrite_string_t;
-typedef struct {
- ip_multicast_rewrite_t * rewrite_heap;
+typedef struct
+{
+ ip_multicast_rewrite_t *rewrite_heap;
- ip_multicast_rewrite_string_t * rewrite_strings;
+ ip_multicast_rewrite_string_t *rewrite_strings;
/* Negative rewrite string index; >= 0 sw_if_index.
Sorted. Used to hash. */
- i32 ** adjacency_id_vector;
+ i32 **adjacency_id_vector;
- uword * adjacency_by_id_vector;
+ uword *adjacency_by_id_vector;
} ip_multicast_lookup_main_t;
-typedef struct {
+typedef struct
+{
/* Key for mhash; in fact, just a byte offset into mhash key vector. */
u32 address_key;
@@ -337,7 +352,8 @@ typedef struct {
u32 prev_this_sw_interface;
} ip_interface_address_t;
-typedef enum {
+typedef enum
+{
IP_LOCAL_NEXT_DROP,
IP_LOCAL_NEXT_PUNT,
IP_LOCAL_NEXT_UDP_LOOKUP,
@@ -347,25 +363,26 @@ typedef enum {
struct ip_lookup_main_t;
-typedef struct ip_lookup_main_t {
+typedef struct ip_lookup_main_t
+{
/* Adjacency heap. */
- ip_adjacency_t * adjacency_heap;
+ ip_adjacency_t *adjacency_heap;
/** load-balance packet/byte counters indexed by LB index. */
vlib_combined_counter_main_t load_balance_counters;
/** Pool of addresses that are assigned to interfaces. */
- ip_interface_address_t * if_address_pool;
+ ip_interface_address_t *if_address_pool;
/** Hash table mapping address to index in interface address pool. */
mhash_t address_to_if_address_index;
/** Head of doubly linked list of interface addresses for each software interface.
~0 means this interface has no address. */
- u32 * if_address_pool_index_by_sw_if_index;
+ u32 *if_address_pool_index_by_sw_if_index;
/** First table index to use for this interface, ~0 => none */
- u32 * classify_table_index_by_sw_if_index;
+ u32 *classify_table_index_by_sw_if_index;
/** Feature arc indices */
u8 mcast_feature_arc_index;
@@ -376,16 +393,16 @@ typedef struct ip_lookup_main_t {
sizeof (uword). First word is always adjacency index. */
u32 fib_result_n_bytes, fib_result_n_words;
- format_function_t * format_fib_result;
+ format_function_t *format_fib_result;
/** 1 for ip6; 0 for ip4. */
u32 is_ip6;
/** Either format_ip4_address_and_length or format_ip6_address_and_length. */
- format_function_t * format_address_and_length;
+ format_function_t *format_address_and_length;
/** Special adjacency format functions */
- format_function_t ** special_adjacency_format_functions;
+ format_function_t **special_adjacency_format_functions;
/** Table mapping ip protocol to ip[46]-local node next index. */
u8 local_next_by_ip_protocol[256];
@@ -395,10 +412,9 @@ typedef struct ip_lookup_main_t {
} ip_lookup_main_t;
always_inline ip_adjacency_t *
-ip_get_adjacency (ip_lookup_main_t * lm,
- u32 adj_index)
+ip_get_adjacency (ip_lookup_main_t * lm, u32 adj_index)
{
- ip_adjacency_t * adj;
+ ip_adjacency_t *adj;
adj = vec_elt_at_index (lm->adjacency_heap, adj_index);
@@ -412,38 +428,35 @@ do { \
} while (0)
/* Create new block of given number of contiguous adjacencies. */
-ip_adjacency_t *
-ip_add_adjacency (ip_lookup_main_t * lm,
- ip_adjacency_t * adj,
- u32 n_adj,
- u32 * adj_index_result);
-
-clib_error_t *
-ip_interface_address_add_del (ip_lookup_main_t * lm,
- u32 sw_if_index,
- void * address,
- u32 address_length,
- u32 is_del,
- u32 * result_index);
-
-u8 *
-format_ip_flow_hash_config (u8 * s, va_list * args);
+ip_adjacency_t *ip_add_adjacency (ip_lookup_main_t * lm,
+ ip_adjacency_t * adj,
+ u32 n_adj, u32 * adj_index_result);
+
+clib_error_t *ip_interface_address_add_del (ip_lookup_main_t * lm,
+ u32 sw_if_index,
+ void *address,
+ u32 address_length,
+ u32 is_del, u32 * result_index);
+
+u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
always_inline ip_interface_address_t *
-ip_get_interface_address (ip_lookup_main_t * lm, void * addr_fib)
+ip_get_interface_address (ip_lookup_main_t * lm, void *addr_fib)
{
- uword * p = mhash_get (&lm->address_to_if_address_index, addr_fib);
+ uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib);
return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
}
-u32
-fib_table_id_find_fib_index (fib_protocol_t proto,
- u32 table_id);
+u32 fib_table_id_find_fib_index (fib_protocol_t proto, u32 table_id);
always_inline void *
-ip_interface_address_get_address (ip_lookup_main_t * lm, ip_interface_address_t * a)
-{ return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key); }
+ip_interface_address_get_address (ip_lookup_main_t * lm,
+ ip_interface_address_t * a)
+{
+ return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key);
+}
+/* *INDENT-OFF* */
#define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
do { \
vnet_main_t *_vnm = vnet_get_main(); \
@@ -470,7 +483,16 @@ do { \
body; \
} \
} while (0)
+/* *INDENT-ON* */
void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
#endif /* included_ip_lookup_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ping.c b/vnet/vnet/ip/ping.c
index 08e770132f0..68dbe759ebc 100644
--- a/vnet/vnet/ip/ping.c
+++ b/vnet/vnet/ip/ping.c
@@ -36,9 +36,8 @@ format_icmp_echo_trace (u8 * s, va_list * va)
icmp_echo_trace_t *t = va_arg (*va, icmp_echo_trace_t *);
s = format (s, "ICMP echo id %d seq %d%s",
- clib_net_to_host_u16(t->id),
- clib_net_to_host_u16(t->seq),
- t->bound ? "" : " (unknown)");
+ clib_net_to_host_u16 (t->id),
+ clib_net_to_host_u16 (t->seq), t->bound ? "" : " (unknown)");
return s;
}
@@ -54,7 +53,7 @@ format_icmp_echo_trace (u8 * s, va_list * va)
static int
signal_ip46_icmp_reply_event (vlib_main_t * vm,
- u8 event_type, vlib_buffer_t * b0)
+ u8 event_type, vlib_buffer_t * b0)
{
ping_main_t *pm = &ping_main;
u16 net_icmp_id = 0;
@@ -64,14 +63,14 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm,
{
case PING_RESPONSE_IP4:
{
- icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
- net_icmp_id = h0->icmp_echo.id;
+ icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+ net_icmp_id = h0->icmp_echo.id;
}
break;
case PING_RESPONSE_IP6:
{
- icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
- net_icmp_id = h0->icmp_echo.id;
+ icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+ net_icmp_id = h0->icmp_echo.id;
}
break;
default:
@@ -79,7 +78,7 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm,
}
uword *p = hash_get (pm->ping_run_by_icmp_id,
- clib_net_to_host_u16 (net_icmp_id));
+ clib_net_to_host_u16 (net_icmp_id));
if (!p)
return 0;
@@ -100,12 +99,12 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm,
*/
static uword
ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
u32 n_left_from, *from;
- from = vlib_frame_vector_args (frame); /* array of buffer indices */
- n_left_from = frame->n_vectors; /* number of buffer indices */
+ from = vlib_frame_vector_args (frame); /* array of buffer indices */
+ n_left_from = frame->n_vectors; /* number of buffer indices */
while (n_left_from > 0)
{
@@ -117,16 +116,16 @@ ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP6, b0) ?
- ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
+ ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
- icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
- tr->id = h0->icmp_echo.id;
- tr->seq = h0->icmp_echo.seq;
- tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
- }
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+ icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->id = h0->icmp_echo.id;
+ tr->seq = h0->icmp_echo.seq;
+ tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
+ }
/* push this pkt to the next graph node */
vlib_set_next_frame_buffer (vm, node, next0, bi0);
@@ -158,12 +157,12 @@ VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) =
*/
static uword
ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
u32 n_left_from, *from;
- from = vlib_frame_vector_args (frame); /* array of buffer indices */
- n_left_from = frame->n_vectors; /* number of buffer indices */
+ from = vlib_frame_vector_args (frame); /* array of buffer indices */
+ n_left_from = frame->n_vectors; /* number of buffer indices */
while (n_left_from > 0)
{
@@ -175,16 +174,16 @@ ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP4, b0) ?
- ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
+ ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
- icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
- tr->id = h0->icmp_echo.id;
- tr->seq = h0->icmp_echo.seq;
- tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
- }
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+ icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->id = h0->icmp_echo.id;
+ tr->seq = h0->icmp_echo.seq;
+ tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
+ }
/* push this pkt to the next graph node */
vlib_set_next_frame_buffer (vm, node, next0, bi0);
@@ -222,23 +221,23 @@ ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
ip_interface_address_t *ia = 0;
ip6_address_t *result = 0;
+ /* *INDENT-OFF* */
foreach_ip_interface_address (lm, ia, sw_if_index,
1 /* honor unnumbered */ ,
- (
- {
- ip6_address_t * a =
- ip_interface_address_get_address (lm, ia);
- result = a;
- break;
- }
- ));
+ ({
+ ip6_address_t * a =
+ ip_interface_address_get_address (lm, ia);
+ result = a;
+ break;
+ }));
+ /* *INDENT-ON* */
return result;
}
/* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
static u16
init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
- u16 seq_host, u16 id_host, u16 data_len)
+ u16 seq_host, u16 id_host, u16 data_len)
{
int i;
icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
@@ -258,9 +257,9 @@ init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
static send_ip46_ping_result_t
send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
- u32 table_id, ip6_address_t * pa6,
- u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
- u8 verbose)
+ u32 table_id, ip6_address_t * pa6,
+ u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
+ u8 verbose)
{
icmp6_echo_request_header_t *h0;
u32 bi0 = 0;
@@ -283,16 +282,16 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
fib_node_index_t fib_entry_index;
u32 fib_index;
- fib_index = ip6_fib_index_from_table_id(table_id);
+ fib_index = ip6_fib_index_from_table_id (table_id);
if (~0 == fib_index)
- {
- vlib_buffer_free (vm, &bi0, 1);
- return SEND_PING_NO_TABLE;
- }
+ {
+ vlib_buffer_free (vm, &bi0, 1);
+ return SEND_PING_NO_TABLE;
+ }
- fib_entry_index = ip6_fib_table_lookup(fib_index, pa6, 128);
- sw_if_index = fib_entry_get_resolving_interface(fib_entry_index);
+ fib_entry_index = ip6_fib_table_lookup (fib_index, pa6, 128);
+ sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
/*
* Set the TX interface to force ip-lookup to use its table ID
*/
@@ -305,7 +304,7 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
* source interface.
*/
vnet_buffer (p0)->sw_if_index[VLIB_TX] =
- ip6_fib_table_get_index_for_sw_if_index(sw_if_index);
+ ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
}
if (~0 == sw_if_index)
@@ -321,7 +320,7 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
/* Fill in ip6 header fields */
h0->ip6.ip_version_traffic_class_and_flow_label =
clib_host_to_net_u32 (0x6 << 28);
- h0->ip6.payload_length = 0; /* Set below */
+ h0->ip6.payload_length = 0; /* Set below */
h0->ip6.protocol = IP_PROTOCOL_ICMP6;
h0->ip6.hop_limit = 255;
h0->ip6.dst_address = *pa6;
@@ -364,11 +363,11 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
static send_ip46_ping_result_t
send_ip4_ping (vlib_main_t * vm,
- ip4_main_t * im,
- u32 table_id,
- ip4_address_t * pa4,
- u32 sw_if_index,
- u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
+ ip4_main_t * im,
+ u32 table_id,
+ ip4_address_t * pa4,
+ u32 sw_if_index,
+ u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
{
icmp4_echo_request_header_t *h0;
u32 bi0 = 0;
@@ -388,20 +387,21 @@ send_ip4_ping (vlib_main_t * vm,
* that the destination resolves via.
*/
if (~0 == sw_if_index)
- {
+ {
fib_node_index_t fib_entry_index;
u32 fib_index;
- fib_index = ip4_fib_index_from_table_id(table_id);
+ fib_index = ip4_fib_index_from_table_id (table_id);
if (~0 == fib_index)
- {
- vlib_buffer_free (vm, &bi0, 1);
- return SEND_PING_NO_TABLE;
- }
-
- fib_entry_index = ip4_fib_table_lookup(ip4_fib_get(fib_index), pa4, 32);
- sw_if_index = fib_entry_get_resolving_interface(fib_entry_index);
+ {
+ vlib_buffer_free (vm, &bi0, 1);
+ return SEND_PING_NO_TABLE;
+ }
+
+ fib_entry_index =
+ ip4_fib_table_lookup (ip4_fib_get (fib_index), pa4, 32);
+ sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
/*
* Set the TX interface to force ip-lookup to use the user's table ID
*/
@@ -414,7 +414,7 @@ send_ip4_ping (vlib_main_t * vm,
* source interface.
*/
vnet_buffer (p0)->sw_if_index[VLIB_TX] =
- ip4_fib_table_get_index_for_sw_if_index(sw_if_index);
+ ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
}
if (~0 == sw_if_index)
@@ -431,7 +431,7 @@ send_ip4_ping (vlib_main_t * vm,
h0->ip4.checksum = 0;
h0->ip4.ip_version_and_header_length = 0x45;
h0->ip4.tos = 0;
- h0->ip4.length = 0; /* Set below */
+ h0->ip4.length = 0; /* Set below */
h0->ip4.fragment_id = 0;
h0->ip4.flags_and_fragment_offset = 0;
h0->ip4.ttl = 0xff;
@@ -444,14 +444,14 @@ send_ip4_ping (vlib_main_t * vm,
if (PREDICT_TRUE (if_add_index0 != ~0))
{
ip_interface_address_t *if_add =
- pool_elt_at_index (lm->if_address_pool, if_add_index0);
+ pool_elt_at_index (lm->if_address_pool, if_add_index0);
ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
h0->ip4.src_address = *if_ip;
if (verbose)
- {
- vlib_cli_output (vm, "Source address: %U",
- format_ip4_address, &h0->ip4.src_address);
- }
+ {
+ vlib_cli_output (vm, "Source address: %U",
+ format_ip4_address, &h0->ip4.src_address);
+ }
}
/* Fill in icmp fields */
@@ -466,7 +466,7 @@ send_ip4_ping (vlib_main_t * vm,
/* Fix up the lengths */
h0->ip4.length =
clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t) +
- sizeof (ip4_header_t));
+ sizeof (ip4_header_t));
p0->current_length = clib_net_to_host_u16 (h0->ip4.length);
@@ -474,7 +474,8 @@ send_ip4_ping (vlib_main_t * vm,
h0->ip4.checksum = ip4_header_checksum (&(h0->ip4));
h0->icmp.checksum =
~ip_csum_fold (ip_incremental_checksum (0, &(h0->icmp),
- p0->current_length - sizeof (ip4_header_t)));
+ p0->current_length -
+ sizeof (ip4_header_t)));
/* Enqueue the packet right now */
f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
@@ -490,25 +491,23 @@ send_ip4_ping (vlib_main_t * vm,
static void
print_ip6_icmp_reply (vlib_main_t * vm, u32 bi0)
{
- vlib_buffer_t *b0 = vlib_get_buffer (vm,
- bi0);
+ vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent;
vlib_cli_output (vm,
- "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
- clib_host_to_net_u16 (h0->ip6.payload_length),
- format_ip6_address,
- &h0->ip6.src_address,
- clib_host_to_net_u16 (h0->icmp_echo.seq),
- h0->ip6.hop_limit, rtt * 1000.0);
+ "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
+ clib_host_to_net_u16 (h0->ip6.payload_length),
+ format_ip6_address,
+ &h0->ip6.src_address,
+ clib_host_to_net_u16 (h0->icmp_echo.seq),
+ h0->ip6.hop_limit, rtt * 1000.0);
}
static void
print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
{
- vlib_buffer_t *b0 = vlib_get_buffer (vm,
- bi0);
+ vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent;
u32 rcvd_icmp_len =
@@ -516,12 +515,12 @@ print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
(4 * (0xF & h0->ip4.ip_version_and_header_length));
vlib_cli_output (vm,
- "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
- rcvd_icmp_len,
- format_ip4_address,
- &h0->ip4.src_address,
- clib_host_to_net_u16 (h0->icmp_echo.seq),
- h0->ip4.ttl, rtt * 1000.0);
+ "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
+ rcvd_icmp_len,
+ format_ip4_address,
+ &h0->ip4.src_address,
+ clib_host_to_net_u16 (h0->icmp_echo.seq),
+ h0->ip4.ttl, rtt * 1000.0);
}
@@ -534,9 +533,9 @@ print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
static void
run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
- ip6_address_t * pa6, u32 sw_if_index,
- f64 ping_interval, u32 ping_repeat, u32 data_len,
- u32 verbose)
+ ip6_address_t * pa6, u32 sw_if_index,
+ f64 ping_interval, u32 ping_repeat, u32 data_len,
+ u32 verbose)
{
int i;
ping_main_t *pm = &ping_main;
@@ -549,10 +548,10 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
static u32 rand_seed = 0;
- if (PREDICT_FALSE(!rand_seed))
- rand_seed = random_default_seed();
+ if (PREDICT_FALSE (!rand_seed))
+ rand_seed = random_default_seed ();
- icmp_id = random_u32(&rand_seed) & 0xffff;
+ icmp_id = random_u32 (&rand_seed) & 0xffff;
while (hash_get (pm->ping_run_by_icmp_id, icmp_id))
{
@@ -572,78 +571,78 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
pr->curr_seq = i;
if (pa6 &&
- (SEND_PING_OK == send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6,
- sw_if_index, i, icmp_id, data_len,
- verbose)))
- {
- n_requests++;
- }
+ (SEND_PING_OK ==
+ send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6, sw_if_index,
+ i, icmp_id, data_len, verbose)))
+ {
+ n_requests++;
+ }
if (pa4 &&
- (SEND_PING_OK == send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4,
- sw_if_index, i, icmp_id, data_len,
- verbose)))
- {
- n_requests++;
- }
+ (SEND_PING_OK ==
+ send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, sw_if_index,
+ i, icmp_id, data_len, verbose)))
+ {
+ n_requests++;
+ }
while ((i <= ping_repeat)
- &&
- ((sleep_interval =
- time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
- {
- uword event_type, *event_data = 0;
- vlib_process_wait_for_event_or_clock (vm, sleep_interval);
- event_type = vlib_process_get_events (vm, &event_data);
- switch (event_type)
- {
- case ~0: /* no events => timeout */
- break;
- case PING_RESPONSE_IP6:
- {
- int i;
- for (i = 0; i < vec_len (event_data); i++)
- {
- u32 bi0 = event_data[0];
- print_ip6_icmp_reply (vm, bi0);
- n_replies++;
- if (0 != bi0)
- {
- vlib_buffer_free (vm, &bi0, 1);
- }
- }
- }
- break;
- case PING_RESPONSE_IP4:
- {
- int i;
- for (i = 0; i < vec_len (event_data); i++)
- {
- u32 bi0 = event_data[0];
- print_ip4_icmp_reply (vm, bi0);
- n_replies++;
- if (0 != bi0)
- {
- vlib_buffer_free (vm, &bi0, 1);
- }
- }
- }
- break;
- default:
- /* someone pressed a key, abort */
- vlib_cli_output (vm, "Aborted due to a keypress.");
- i = 1 + ping_repeat;
- break;
- }
- }
+ &&
+ ((sleep_interval =
+ time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
+ {
+ uword event_type, *event_data = 0;
+ vlib_process_wait_for_event_or_clock (vm, sleep_interval);
+ event_type = vlib_process_get_events (vm, &event_data);
+ switch (event_type)
+ {
+ case ~0: /* no events => timeout */
+ break;
+ case PING_RESPONSE_IP6:
+ {
+ int i;
+ for (i = 0; i < vec_len (event_data); i++)
+ {
+ u32 bi0 = event_data[0];
+ print_ip6_icmp_reply (vm, bi0);
+ n_replies++;
+ if (0 != bi0)
+ {
+ vlib_buffer_free (vm, &bi0, 1);
+ }
+ }
+ }
+ break;
+ case PING_RESPONSE_IP4:
+ {
+ int i;
+ for (i = 0; i < vec_len (event_data); i++)
+ {
+ u32 bi0 = event_data[0];
+ print_ip4_icmp_reply (vm, bi0);
+ n_replies++;
+ if (0 != bi0)
+ {
+ vlib_buffer_free (vm, &bi0, 1);
+ }
+ }
+ }
+ break;
+ default:
+ /* someone pressed a key, abort */
+ vlib_cli_output (vm, "Aborted due to a keypress.");
+ i = 1 + ping_repeat;
+ break;
+ }
+ }
}
vlib_cli_output (vm, "\n");
{
float loss =
(0 ==
n_requests) ? 0 : 100.0 * ((float) n_requests -
- (float) n_replies) / (float) n_requests;
+ (float) n_replies) / (float) n_requests;
vlib_cli_output (vm,
- "Statistics: %u sent, %u received, %f%% packet loss\n",
- n_requests, n_replies, loss);
+ "Statistics: %u sent, %u received, %f%% packet loss\n",
+ n_requests, n_replies, loss);
/* Reset pr: running ping in other process could have changed pm->ping_runs */
pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
hash_unset (pm->ping_run_by_icmp_id, icmp_id);
@@ -657,7 +656,7 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
static clib_error_t *
ping_ip_address (vlib_main_t * vm,
- unformat_input_t * input, vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
ip4_address_t a4;
ip6_address_t a6;
@@ -685,37 +684,37 @@ ping_ip_address (vlib_main_t * vm,
else if (unformat (input, "ipv4"))
{
if (unformat (input, "%U", unformat_ip4_address, &a4))
- {
- ping_ip4 = 1;
- }
+ {
+ ping_ip4 = 1;
+ }
else
- {
- error =
- clib_error_return (0,
- "expecting IPv4 address but got `%U'",
- format_unformat_error, input);
- }
+ {
+ error =
+ clib_error_return (0,
+ "expecting IPv4 address but got `%U'",
+ format_unformat_error, input);
+ }
}
else if (unformat (input, "ipv6"))
{
if (unformat (input, "%U", unformat_ip6_address, &a6))
- {
- ping_ip6 = 1;
- }
+ {
+ ping_ip6 = 1;
+ }
else
- {
- error =
- clib_error_return (0,
- "expecting IPv6 address but got `%U'",
- format_unformat_error, input);
- }
+ {
+ error =
+ clib_error_return (0,
+ "expecting IPv6 address but got `%U'",
+ format_unformat_error, input);
+ }
}
else
{
error =
- clib_error_return (0,
- "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
- format_unformat_error, input);
+ clib_error_return (0,
+ "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
+ format_unformat_error, input);
goto done;
}
@@ -723,92 +722,92 @@ ping_ip_address (vlib_main_t * vm,
if (!ping_ip4 && (unformat (input, "ipv4")))
{
if (unformat (input, "%U", unformat_ip4_address, &a4))
- {
- ping_ip4 = 1;
- }
+ {
+ ping_ip4 = 1;
+ }
}
else if (!ping_ip6 && (unformat (input, "ipv6")))
{
if (unformat (input, "%U", unformat_ip6_address, &a6))
- {
- ping_ip6 = 1;
- }
+ {
+ ping_ip6 = 1;
+ }
}
/* parse the rest of the parameters in a cycle */
while (!unformat_eof (input, NULL))
{
if (unformat (input, "source"))
- {
- if (!unformat_user
- (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
- {
- error =
- clib_error_return (0,
- "unknown interface `%U'",
- format_unformat_error, input);
- goto done;
- }
- }
+ {
+ if (!unformat_user
+ (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+ {
+ error =
+ clib_error_return (0,
+ "unknown interface `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+ }
else if (unformat (input, "size"))
- {
- if (!unformat (input, "%u", &data_len))
- {
- error =
- clib_error_return (0,
- "expecting size but got `%U'",
- format_unformat_error, input);
- goto done;
- }
- }
+ {
+ if (!unformat (input, "%u", &data_len))
+ {
+ error =
+ clib_error_return (0,
+ "expecting size but got `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+ }
else if (unformat (input, "table-id"))
- {
- if (!unformat (input, "du", &table_id))
- {
- error =
- clib_error_return (0,
- "expecting table-id but got `%U'",
- format_unformat_error, input);
- goto done;
- }
- }
+ {
+ if (!unformat (input, "du", &table_id))
+ {
+ error =
+ clib_error_return (0,
+ "expecting table-id but got `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+ }
else if (unformat (input, "interval"))
- {
- if (!unformat (input, "%f", &ping_interval))
- {
- error =
- clib_error_return (0,
- "expecting interval (floating point number) got `%U'",
- format_unformat_error, input);
- goto done;
- }
- }
+ {
+ if (!unformat (input, "%f", &ping_interval))
+ {
+ error =
+ clib_error_return (0,
+ "expecting interval (floating point number) got `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+ }
else if (unformat (input, "repeat"))
- {
- if (!unformat (input, "%u", &ping_repeat))
- {
- error =
- clib_error_return (0,
- "expecting repeat count but got `%U'",
- format_unformat_error, input);
- goto done;
- }
- }
+ {
+ if (!unformat (input, "%u", &ping_repeat))
+ {
+ error =
+ clib_error_return (0,
+ "expecting repeat count but got `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+ }
else if (unformat (input, "verbose"))
- {
- verbose = 1;
- }
+ {
+ verbose = 1;
+ }
else
- {
- error = clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
- goto done;
- }
+ {
+ error = clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
}
- run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL, ping_ip6 ? &a6 : NULL,
- sw_if_index, ping_interval, ping_repeat, data_len,
- verbose);
+ run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
+ ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
+ ping_repeat, data_len, verbose);
done:
return error;
}
@@ -859,7 +858,10 @@ VLIB_CLI_COMMAND (ping_command, static) =
{
.path = "ping",
.function = ping_ip_address,
- .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>} [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>] [size <pktsize>] [interval <sec>] [repeat <cnt>] [table-id <id>] [verbose]",
+ .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
+ " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
+ " [size <pktsize>] [interval <sec>] [repeat <cnt>] [table-id <id>]"
+ " [verbose]",
};
/* *INDENT-ON* */
@@ -871,8 +873,16 @@ ping_cli_init (vlib_main_t * vm)
pm->ip4_main = &ip4_main;
icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
ip4_icmp_register_type (vm, ICMP4_echo_reply,
- ip4_icmp_echo_reply_node.index);
+ ip4_icmp_echo_reply_node.index);
return 0;
}
VLIB_INIT_FUNCTION (ping_cli_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/ping.h b/vnet/vnet/ip/ping.h
index 58c6f4b4b6b..8f41f45c5f9 100644
--- a/vnet/vnet/ip/ping.h
+++ b/vnet/vnet/ip/ping.h
@@ -20,12 +20,14 @@
#include <vnet/ip/lookup.h>
-typedef enum {
+typedef enum
+{
PING_RESPONSE_IP6 = 42,
PING_RESPONSE_IP4,
} ping_response_type_t;
-typedef enum {
+typedef enum
+{
SEND_PING_OK = 0,
SEND_PING_ALLOC_FAIL,
SEND_PING_NO_INTERFACE,
@@ -35,13 +37,15 @@ typedef enum {
/*
* Currently running ping command.
*/
-typedef struct ping_run_t {
+typedef struct ping_run_t
+{
u16 icmp_id;
u16 curr_seq;
uword cli_process_id;
} ping_run_t;
-typedef struct ping_main_t {
+typedef struct ping_main_t
+{
ip6_main_t *ip6_main;
ip4_main_t *ip4_main;
ping_run_t *ping_runs;
@@ -57,28 +61,28 @@ ping_main_t ping_main;
#define PING_MAXIMUM_DATA_SIZE 2000
-typedef CLIB_PACKED (struct {
- u16 id;
- u16 seq;
- f64 time_sent;
- u8 data[PING_MAXIMUM_DATA_SIZE];
-}) icmp46_echo_request_t;
+typedef CLIB_PACKED (struct
+ {
+ u16 id;
+ u16 seq; f64 time_sent; u8 data[PING_MAXIMUM_DATA_SIZE];
+ }) icmp46_echo_request_t;
-typedef CLIB_PACKED (struct {
- ip6_header_t ip6;
- icmp46_header_t icmp;
- icmp46_echo_request_t icmp_echo;
-}) icmp6_echo_request_header_t;
+typedef CLIB_PACKED (struct
+ {
+ ip6_header_t ip6;
+ icmp46_header_t icmp; icmp46_echo_request_t icmp_echo;
+ }) icmp6_echo_request_header_t;
-typedef CLIB_PACKED(struct {
- ip4_header_t ip4;
- icmp46_header_t icmp;
- icmp46_echo_request_t icmp_echo;
-}) icmp4_echo_request_header_t;
+typedef CLIB_PACKED (struct
+ {
+ ip4_header_t ip4;
+ icmp46_header_t icmp; icmp46_echo_request_t icmp_echo;
+ }) icmp4_echo_request_header_t;
-typedef struct {
+typedef struct
+{
u16 id;
u16 seq;
u8 bound;
@@ -87,13 +91,15 @@ typedef struct {
-typedef enum {
+typedef enum
+{
ICMP6_ECHO_REPLY_NEXT_DROP,
ICMP6_ECHO_REPLY_NEXT_PUNT,
ICMP6_ECHO_REPLY_N_NEXT,
} icmp6_echo_reply_next_t;
-typedef enum {
+typedef enum
+{
ICMP4_ECHO_REPLY_NEXT_DROP,
ICMP4_ECHO_REPLY_NEXT_PUNT,
ICMP4_ECHO_REPLY_N_NEXT,
diff --git a/vnet/vnet/ip/punt.c b/vnet/vnet/ip/punt.c
index 30d3deb6fa5..9c735128a3b 100644
--- a/vnet/vnet/ip/punt.c
+++ b/vnet/vnet/ip/punt.c
@@ -176,7 +176,7 @@ VLIB_REGISTER_NODE (udp4_punt_node) = {
},
};
-VLIB_NODE_FUNCTION_MULTIARCH (udp4_punt_node, udp4_punt)
+VLIB_NODE_FUNCTION_MULTIARCH (udp4_punt_node, udp4_punt);
VLIB_REGISTER_NODE (udp6_punt_node) = {
.function = udp6_punt,
@@ -194,10 +194,10 @@ VLIB_REGISTER_NODE (udp6_punt_node) = {
#undef _
},
};
-
-VLIB_NODE_FUNCTION_MULTIARCH (udp6_punt_node, udp6_punt)
/* *INDENT-ON* */
+VLIB_NODE_FUNCTION_MULTIARCH (udp6_punt_node, udp6_punt);;
+
/**
* @brief Request IP traffic punt to the local TCP/IP stack.
*
diff --git a/vnet/vnet/ip/tcp_packet.h b/vnet/vnet/ip/tcp_packet.h
index 5a9a420ebc5..ed402403592 100644
--- a/vnet/vnet/ip/tcp_packet.h
+++ b/vnet/vnet/ip/tcp_packet.h
@@ -51,23 +51,28 @@
_ (ECE) \
_ (CWR)
-enum {
+enum
+{
#define _(f) TCP_FLAG_BIT_##f,
foreach_tcp_flag
#undef _
- TCP_N_FLAG_BITS,
+ TCP_N_FLAG_BITS,
#define _(f) TCP_FLAG_##f = 1 << TCP_FLAG_BIT_##f,
foreach_tcp_flag
#undef _
};
-typedef struct {
+typedef struct
+{
/* Source and destination port. */
- union {
- union {
- struct {
- u16 src, dst;
+ union
+ {
+ union
+ {
+ struct
+ {
+ u16 src, dst;
};
u32 src_and_dst;
} ports;
@@ -96,10 +101,13 @@ typedef struct {
always_inline int
tcp_header_bytes (tcp_header_t * t)
-{ return (t->tcp_header_u32s_and_reserved >> 4) * sizeof (u32); }
+{
+ return (t->tcp_header_u32s_and_reserved >> 4) * sizeof (u32);
+}
/* TCP options. */
-typedef enum tcp_option_type {
+typedef enum tcp_option_type
+{
TCP_OPTION_END = 0,
TCP_OPTION_NOP = 1,
TCP_OPTION_MSS = 2,
@@ -110,8 +118,9 @@ typedef enum tcp_option_type {
} tcp_option_type_t;
/* All except NOP and END have 1 byte length field. */
-typedef struct {
- tcp_option_type_t type : 8;
+typedef struct
+{
+ tcp_option_type_t type:8;
/* Length of this option in bytes. */
u8 length;
@@ -119,3 +128,11 @@ typedef struct {
#endif /* included_tcp_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/udp.h b/vnet/vnet/ip/udp.h
index f8ff777e275..03c62e0b684 100644
--- a/vnet/vnet/ip/udp.h
+++ b/vnet/vnet/ip/udp.h
@@ -26,7 +26,8 @@
#include <vnet/pg/pg.h>
#include <vnet/ip/format.h>
-typedef enum {
+typedef enum
+{
#define udp_error(n,s) UDP_ERROR_##n,
#include <vnet/ip/udp_error.def>
#undef udp_error
@@ -56,22 +57,24 @@ _ (4342, lisp_cp6) \
_ (4790, vxlan6_gpe) \
_ (6633, vpath6_3)
-typedef enum {
+typedef enum
+{
#define _(n,f) UDP_DST_PORT_##f = n,
- foreach_udp4_dst_port
- foreach_udp6_dst_port
+ foreach_udp4_dst_port foreach_udp6_dst_port
#undef _
} udp_dst_port_t;
-typedef enum {
+typedef enum
+{
#define _(n,f) UDP6_DST_PORT_##f = n,
foreach_udp6_dst_port
#undef _
} udp6_dst_port_t;
-typedef struct {
+typedef struct
+{
/* Name (a c string). */
- char * name;
+ char *name;
/* GRE protocol type in host byte order. */
udp_dst_port_t dst_port;
@@ -83,27 +86,29 @@ typedef struct {
u32 next_index;
} udp_dst_port_info_t;
-typedef enum {
+typedef enum
+{
UDP_IP6 = 0,
- UDP_IP4, /* the code is full of is_ip4... */
+ UDP_IP4, /* the code is full of is_ip4... */
N_UDP_AF,
} udp_af_t;
-typedef struct {
- udp_dst_port_info_t * dst_port_infos [N_UDP_AF];
+typedef struct
+{
+ udp_dst_port_info_t *dst_port_infos[N_UDP_AF];
/* Hash tables mapping name/protocol to protocol info index. */
- uword * dst_port_info_by_name[N_UDP_AF];
- uword * dst_port_info_by_dst_port[N_UDP_AF];
+ uword *dst_port_info_by_name[N_UDP_AF];
+ uword *dst_port_info_by_dst_port[N_UDP_AF];
/* convenience */
- vlib_main_t * vlib_main;
+ vlib_main_t *vlib_main;
} udp_main_t;
always_inline udp_dst_port_info_t *
udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4)
{
- uword * p = hash_get (um->dst_port_info_by_dst_port[is_ip4], dst_port);
+ uword *p = hash_get (um->dst_port_info_by_dst_port[is_ip4], dst_port);
return p ? vec_elt_at_index (um->dst_port_infos[is_ip4], p[0]) : 0;
}
@@ -113,108 +118,108 @@ format_function_t format_udp_rx_trace;
unformat_function_t unformat_udp_header;
void udp_register_dst_port (vlib_main_t * vm,
- udp_dst_port_t dst_port,
- u32 node_index, u8 is_ip4);
+ udp_dst_port_t dst_port,
+ u32 node_index, u8 is_ip4);
-void udp_punt_unknown(vlib_main_t * vm, u8 is_ip4, u8 is_add);
+void udp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add);
always_inline void
-ip_udp_fixup_one (vlib_main_t * vm,
- vlib_buffer_t * b0,
- u8 is_ip4)
+ip_udp_fixup_one (vlib_main_t * vm, vlib_buffer_t * b0, u8 is_ip4)
{
u16 new_l0;
- udp_header_t * udp0;
+ udp_header_t *udp0;
if (is_ip4)
{
- ip4_header_t * ip0;
+ ip4_header_t *ip0;
ip_csum_t sum0;
u16 old_l0 = 0;
- ip0 = vlib_buffer_get_current(b0);
+ ip0 = vlib_buffer_get_current (b0);
/* fix the <bleep>ing outer-IP checksum */
sum0 = ip0->checksum;
/* old_l0 always 0, see the rewrite setup */
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
- sum0 = ip_csum_update(sum0, old_l0, new_l0, ip4_header_t,
- length /* changed member */);
+ sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
+ length /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
ip0->length = new_l0;
/* Fix UDP length */
- udp0 = (udp_header_t *)(ip0+1);
+ udp0 = (udp_header_t *) (ip0 + 1);
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
- - sizeof (*ip0));
+ - sizeof (*ip0));
udp0->length = new_l0;
}
else
{
- ip6_header_t * ip0;
+ ip6_header_t *ip0;
int bogus0;
- ip0 = vlib_buffer_get_current(b0);
+ ip0 = vlib_buffer_get_current (b0);
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
- - sizeof (*ip0));
+ - sizeof (*ip0));
ip0->payload_length = new_l0;
/* Fix UDP length */
- udp0 = (udp_header_t *)(ip0+1);
+ udp0 = (udp_header_t *) (ip0 + 1);
udp0->length = new_l0;
- udp0->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0);
- ASSERT(bogus0 == 0);
+ udp0->checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0);
+ ASSERT (bogus0 == 0);
if (udp0->checksum == 0)
- udp0->checksum = 0xffff;
+ udp0->checksum = 0xffff;
}
}
+
always_inline void
ip_udp_encap_one (vlib_main_t * vm, vlib_buffer_t * b0, u8 * ec0, word ec_len,
- u8 is_ip4)
+ u8 is_ip4)
{
- vlib_buffer_advance (b0, - ec_len);
+ vlib_buffer_advance (b0, -ec_len);
if (is_ip4)
{
- ip4_header_t * ip0;
+ ip4_header_t *ip0;
- ip0 = vlib_buffer_get_current(b0);
+ ip0 = vlib_buffer_get_current (b0);
/* Apply the encap string. */
- clib_memcpy(ip0, ec0, ec_len);
- ip_udp_fixup_one(vm, b0, 1);
+ clib_memcpy (ip0, ec0, ec_len);
+ ip_udp_fixup_one (vm, b0, 1);
}
else
{
- ip6_header_t * ip0;
+ ip6_header_t *ip0;
- ip0 = vlib_buffer_get_current(b0);
+ ip0 = vlib_buffer_get_current (b0);
/* Apply the encap string. */
- clib_memcpy(ip0, ec0, ec_len);
- ip_udp_fixup_one(vm, b0, 0);
+ clib_memcpy (ip0, ec0, ec_len);
+ ip_udp_fixup_one (vm, b0, 0);
}
}
always_inline void
ip_udp_encap_two (vlib_main_t * vm, vlib_buffer_t * b0, vlib_buffer_t * b1,
- u8 * ec0, u8 * ec1, word ec_len, u8 is_v4)
+ u8 * ec0, u8 * ec1, word ec_len, u8 is_v4)
{
u16 new_l0, new_l1;
- udp_header_t * udp0, *udp1;
+ udp_header_t *udp0, *udp1;
- ASSERT(_vec_len(ec0) == _vec_len(ec1));
+ ASSERT (_vec_len (ec0) == _vec_len (ec1));
vlib_buffer_advance (b0, -ec_len);
vlib_buffer_advance (b1, -ec_len);
if (is_v4)
{
- ip4_header_t * ip0, *ip1;
+ ip4_header_t *ip0, *ip1;
ip_csum_t sum0, sum1;
u16 old_l0 = 0, old_l1 = 0;
@@ -233,10 +238,10 @@ ip_udp_encap_two (vlib_main_t * vm, vlib_buffer_t * b0, vlib_buffer_t * b1,
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1));
- sum0 = ip_csum_update(sum0, old_l0, new_l0, ip4_header_t,
- length /* changed member */);
- sum1 = ip_csum_update(sum1, old_l1, new_l1, ip4_header_t,
- length /* changed member */);
+ sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
+ length /* changed member */ );
+ sum1 = ip_csum_update (sum1, old_l1, new_l1, ip4_header_t,
+ length /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
ip1->checksum = ip_csum_fold (sum1);
@@ -248,49 +253,61 @@ ip_udp_encap_two (vlib_main_t * vm, vlib_buffer_t * b0, vlib_buffer_t * b1,
udp0 = (udp_header_t *) (ip0 + 1);
udp1 = (udp_header_t *) (ip1 + 1);
- new_l0 = clib_host_to_net_u16 (
- vlib_buffer_length_in_chain (vm, b0) - sizeof(*ip0));
- new_l1 = clib_host_to_net_u16 (
- vlib_buffer_length_in_chain (vm, b1) - sizeof(*ip1));
+ new_l0 =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
+ sizeof (*ip0));
+ new_l1 =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1) -
+ sizeof (*ip1));
udp0->length = new_l0;
udp1->length = new_l1;
}
else
{
- ip6_header_t * ip0, * ip1;
+ ip6_header_t *ip0, *ip1;
int bogus0, bogus1;
- ip0 = vlib_buffer_get_current(b0);
- ip1 = vlib_buffer_get_current(b1);
+ ip0 = vlib_buffer_get_current (b0);
+ ip1 = vlib_buffer_get_current (b1);
/* Apply the encap string. */
- clib_memcpy(ip0, ec0, ec_len);
- clib_memcpy(ip1, ec1, ec_len);
+ clib_memcpy (ip0, ec0, ec_len);
+ clib_memcpy (ip1, ec1, ec_len);
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
- - sizeof (*ip0));
+ - sizeof (*ip0));
new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1)
- - sizeof (*ip1));
+ - sizeof (*ip1));
ip0->payload_length = new_l0;
ip1->payload_length = new_l1;
/* Fix UDP length */
- udp0 = (udp_header_t *)(ip0+1);
- udp1 = (udp_header_t *)(ip1+1);
+ udp0 = (udp_header_t *) (ip0 + 1);
+ udp1 = (udp_header_t *) (ip1 + 1);
udp0->length = new_l0;
udp1->length = new_l1;
- udp0->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0);
- udp1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b1, ip1, &bogus1);
- ASSERT(bogus0 == 0);
- ASSERT(bogus1 == 0);
+ udp0->checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0);
+ udp1->checksum =
+ ip6_tcp_udp_icmp_compute_checksum (vm, b1, ip1, &bogus1);
+ ASSERT (bogus0 == 0);
+ ASSERT (bogus1 == 0);
if (udp0->checksum == 0)
- udp0->checksum = 0xffff;
+ udp0->checksum = 0xffff;
if (udp1->checksum == 0)
- udp1->checksum = 0xffff;
+ udp1->checksum = 0xffff;
}
}
#endif /* included_udp_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/udp_format.c b/vnet/vnet/ip/udp_format.c
index dd54095908c..abdf561e8c9 100644
--- a/vnet/vnet/ip/udp_format.c
+++ b/vnet/vnet/ip/udp_format.c
@@ -40,9 +40,10 @@
#include <vnet/ip/ip.h>
/* Format UDP header. */
-u8 * format_udp_header (u8 * s, va_list * args)
+u8 *
+format_udp_header (u8 * s, va_list * args)
{
- udp_header_t * udp = va_arg (*args, udp_header_t *);
+ udp_header_t *udp = va_arg (*args, udp_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
uword indent;
u32 header_bytes = sizeof (udp[0]);
@@ -66,18 +67,25 @@ u8 * format_udp_header (u8 * s, va_list * args)
/* Recurse into next protocol layer. */
if (max_header_bytes != 0 && header_bytes < max_header_bytes)
{
- ip_main_t * im = &ip_main;
- tcp_udp_port_info_t * pi;
+ ip_main_t *im = &ip_main;
+ tcp_udp_port_info_t *pi;
pi = ip_get_tcp_udp_port_info (im, udp->dst_port);
if (pi && pi->format_header)
s = format (s, "\n%U%U",
- format_white_space, indent - 2,
- pi->format_header,
+ format_white_space, indent - 2, pi->format_header,
/* next protocol header */ (udp + 1),
max_header_bytes - sizeof (udp[0]));
}
return s;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/udp_init.c b/vnet/vnet/ip/udp_init.c
index 40ca032923c..1241ca4ab32 100644
--- a/vnet/vnet/ip/udp_init.c
+++ b/vnet/vnet/ip/udp_init.c
@@ -42,17 +42,17 @@
clib_error_t *
udp_init (vlib_main_t * vm)
{
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi;
- clib_error_t * error;
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi;
+ clib_error_t *error;
error = vlib_call_init_function (vm, ip_main_init);
- if (! error)
+ if (!error)
{
pi = ip_get_protocol_info (im, IP_PROTOCOL_UDP);
if (pi == 0)
- return clib_error_return (0, "UDP protocol info AWOL");
+ return clib_error_return (0, "UDP protocol info AWOL");
pi->format_header = format_udp_header;
pi->unformat_pg_edit = unformat_pg_udp_header;
}
@@ -61,3 +61,11 @@ udp_init (vlib_main_t * vm)
}
VLIB_INIT_FUNCTION (udp_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/udp_local.c b/vnet/vnet/ip/udp_local.c
index e4f64a5efe6..13ab6e4fb32 100644
--- a/vnet/vnet/ip/udp_local.c
+++ b/vnet/vnet/ip/udp_local.c
@@ -29,36 +29,40 @@ udp_main_t udp_main;
_ (ICMP4_ERROR, "ip4-icmp-error") \
_ (ICMP6_ERROR, "ip6-icmp-error")
-typedef enum {
+typedef enum
+{
#define _(s,n) UDP_INPUT_NEXT_##s,
foreach_udp_input_next
#undef _
- UDP_INPUT_N_NEXT,
+ UDP_INPUT_N_NEXT,
} udp_input_next_t;
-typedef struct {
+typedef struct
+{
u16 src_port;
u16 dst_port;
u8 bound;
} udp_rx_trace_t;
-u8 * format_udp_rx_trace (u8 * s, va_list * args)
+u8 *
+format_udp_rx_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 *);
- udp_rx_trace_t * t = va_arg (*args, udp_rx_trace_t *);
-
+ udp_rx_trace_t *t = va_arg (*args, udp_rx_trace_t *);
+
s = format (s, "UDP: src-port %d dst-port %d%s",
- clib_net_to_host_u16(t->src_port),
- clib_net_to_host_u16(t->dst_port),
- t->bound ? "" : " (no listener)");
+ clib_net_to_host_u16 (t->src_port),
+ clib_net_to_host_u16 (t->dst_port),
+ t->bound ? "" : " (no listener)");
return s;
}
-typedef struct {
+typedef struct
+{
/* Sparse vector mapping udp dst_port in network byte order
to next index. */
- u16 * next_by_dst_port;
+ u16 *next_by_dst_port;
u8 punt_unknown;
} udp_input_runtime_t;
@@ -67,14 +71,13 @@ vlib_node_registration_t udp6_input_node;
always_inline uword
udp46_input_inline (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame,
- int is_ip4)
+ vlib_node_runtime_t * node,
+ vlib_frame_t * from_frame, int is_ip4)
{
- udp_input_runtime_t * rt = is_ip4 ?
+ udp_input_runtime_t *rt = is_ip4 ?
(void *) vlib_node_get_runtime_data (vm, udp4_input_node.index)
: (void *) vlib_node_get_runtime_data (vm, udp6_input_node.index);
- __attribute__((unused)) u32 n_left_from, next_index, * from, * to_next;
+ __attribute__ ((unused)) u32 n_left_from, next_index, *from, *to_next;
word n_no_listener = 0;
u8 punt_unknown = rt->punt_unknown;
@@ -87,21 +90,20 @@ udp46_input_inline (vlib_main_t * vm,
{
u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
u32 bi0, bi1;
- vlib_buffer_t * b0, * b1;
- udp_header_t * h0 = 0, * h1 = 0;
+ vlib_buffer_t *b0, *b1;
+ udp_header_t *h0 = 0, *h1 = 0;
u32 i0, i1, dst_port0, dst_port1;
- u32 advance0, advance1;
- u32 error0, next0, error1, next1;
+ u32 advance0, advance1;
+ u32 error0, next0, error1, next1;
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -125,165 +127,173 @@ udp46_input_inline (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
b1 = vlib_get_buffer (vm, bi1);
- /* ip4/6_local hands us the ip header, not the udp header */
- if (is_ip4)
- {
- advance0 = sizeof(ip4_header_t);
- advance1 = sizeof(ip4_header_t);
- }
- else
- {
- advance0 = sizeof(ip6_header_t);
- advance1 = sizeof(ip6_header_t);
- }
-
- if (PREDICT_FALSE(b0->current_length < advance0 + sizeof (*h0)))
- {
- error0 = UDP_ERROR_LENGTH_ERROR;
- next0 = UDP_INPUT_NEXT_DROP;
- }
- else
- {
- vlib_buffer_advance (b0, advance0);
- h0 = vlib_buffer_get_current (b0);
- error0 = next0 = 0;
- if (PREDICT_FALSE(clib_net_to_host_u16(h0->length) >
- vlib_buffer_length_in_chain(vm, b0)))
- {
+ /* ip4/6_local hands us the ip header, not the udp header */
+ if (is_ip4)
+ {
+ advance0 = sizeof (ip4_header_t);
+ advance1 = sizeof (ip4_header_t);
+ }
+ else
+ {
+ advance0 = sizeof (ip6_header_t);
+ advance1 = sizeof (ip6_header_t);
+ }
+
+ if (PREDICT_FALSE (b0->current_length < advance0 + sizeof (*h0)))
+ {
+ error0 = UDP_ERROR_LENGTH_ERROR;
+ next0 = UDP_INPUT_NEXT_DROP;
+ }
+ else
+ {
+ vlib_buffer_advance (b0, advance0);
+ h0 = vlib_buffer_get_current (b0);
+ error0 = next0 = 0;
+ if (PREDICT_FALSE (clib_net_to_host_u16 (h0->length) >
+ vlib_buffer_length_in_chain (vm, b0)))
+ {
error0 = UDP_ERROR_LENGTH_ERROR;
next0 = UDP_INPUT_NEXT_DROP;
- }
- }
-
- if (PREDICT_FALSE(b1->current_length < advance1 + sizeof (*h1)))
- {
- error1 = UDP_ERROR_LENGTH_ERROR;
- next1 = UDP_INPUT_NEXT_DROP;
- }
- else
- {
- vlib_buffer_advance (b1, advance1);
- h1 = vlib_buffer_get_current (b1);
- error1 = next1 = 0;
- if (PREDICT_FALSE(clib_net_to_host_u16(h1->length) >
- vlib_buffer_length_in_chain(vm, b1)))
- {
+ }
+ }
+
+ if (PREDICT_FALSE (b1->current_length < advance1 + sizeof (*h1)))
+ {
+ error1 = UDP_ERROR_LENGTH_ERROR;
+ next1 = UDP_INPUT_NEXT_DROP;
+ }
+ else
+ {
+ vlib_buffer_advance (b1, advance1);
+ h1 = vlib_buffer_get_current (b1);
+ error1 = next1 = 0;
+ if (PREDICT_FALSE (clib_net_to_host_u16 (h1->length) >
+ vlib_buffer_length_in_chain (vm, b1)))
+ {
error1 = UDP_ERROR_LENGTH_ERROR;
next1 = UDP_INPUT_NEXT_DROP;
- }
- }
+ }
+ }
/* Index sparse array with network byte order. */
dst_port0 = (error0 == 0) ? h0->dst_port : 0;
dst_port1 = (error1 == 0) ? h1->dst_port : 0;
sparse_vec_index2 (rt->next_by_dst_port, dst_port0, dst_port1,
- &i0, &i1);
- next0 = (error0 == 0) ? vec_elt(rt->next_by_dst_port, i0) : next0;
- next1 = (error1 == 0) ? vec_elt(rt->next_by_dst_port, i1) : next1;
-
- if (PREDICT_FALSE(i0 == SPARSE_VEC_INVALID_INDEX))
- {
- // move the pointer back so icmp-error can find the
- // ip packet header
- vlib_buffer_advance (b0, - (word)advance0);
-
- if (PREDICT_FALSE(punt_unknown))
- {
- b0->error = node->errors[UDP_ERROR_PUNT];
+ &i0, &i1);
+ next0 = (error0 == 0) ? vec_elt (rt->next_by_dst_port, i0) : next0;
+ next1 = (error1 == 0) ? vec_elt (rt->next_by_dst_port, i1) : next1;
+
+ if (PREDICT_FALSE (i0 == SPARSE_VEC_INVALID_INDEX))
+ {
+ // move the pointer back so icmp-error can find the
+ // ip packet header
+ vlib_buffer_advance (b0, -(word) advance0);
+
+ if (PREDICT_FALSE (punt_unknown))
+ {
+ b0->error = node->errors[UDP_ERROR_PUNT];
next0 = UDP_INPUT_NEXT_PUNT;
}
- else if (is_ip4)
- {
- icmp4_error_set_vnet_buffer(b0, ICMP4_destination_unreachable,
- ICMP4_destination_unreachable_port_unreachable, 0);
- next0 = UDP_INPUT_NEXT_ICMP4_ERROR;
- n_no_listener ++;
- }
- else
- {
- icmp6_error_set_vnet_buffer(b0, ICMP6_destination_unreachable,
- ICMP6_destination_unreachable_port_unreachable, 0);
- next0 = UDP_INPUT_NEXT_ICMP6_ERROR;
- n_no_listener ++;
- }
- }
- else
- {
- b0->error = node->errors[UDP_ERROR_NONE];
- // advance to the payload
- vlib_buffer_advance (b0, sizeof (*h0));
- }
-
- if (PREDICT_FALSE(i1 == SPARSE_VEC_INVALID_INDEX))
- {
- // move the pointer back so icmp-error can find the
- // ip packet header
- vlib_buffer_advance (b1, - (word)advance1);
-
- if (PREDICT_FALSE(punt_unknown))
- {
- b1->error = node->errors[UDP_ERROR_PUNT];
+ else if (is_ip4)
+ {
+ icmp4_error_set_vnet_buffer (b0,
+ ICMP4_destination_unreachable,
+ ICMP4_destination_unreachable_port_unreachable,
+ 0);
+ next0 = UDP_INPUT_NEXT_ICMP4_ERROR;
+ n_no_listener++;
+ }
+ else
+ {
+ icmp6_error_set_vnet_buffer (b0,
+ ICMP6_destination_unreachable,
+ ICMP6_destination_unreachable_port_unreachable,
+ 0);
+ next0 = UDP_INPUT_NEXT_ICMP6_ERROR;
+ n_no_listener++;
+ }
+ }
+ else
+ {
+ b0->error = node->errors[UDP_ERROR_NONE];
+ // advance to the payload
+ vlib_buffer_advance (b0, sizeof (*h0));
+ }
+
+ if (PREDICT_FALSE (i1 == SPARSE_VEC_INVALID_INDEX))
+ {
+ // move the pointer back so icmp-error can find the
+ // ip packet header
+ vlib_buffer_advance (b1, -(word) advance1);
+
+ if (PREDICT_FALSE (punt_unknown))
+ {
+ b1->error = node->errors[UDP_ERROR_PUNT];
next1 = UDP_INPUT_NEXT_PUNT;
}
- else if (is_ip4)
- {
- icmp4_error_set_vnet_buffer(b1, ICMP4_destination_unreachable,
- ICMP4_destination_unreachable_port_unreachable, 0);
- next1 = UDP_INPUT_NEXT_ICMP4_ERROR;
- n_no_listener ++;
- }
- else
- {
- icmp6_error_set_vnet_buffer(b1, ICMP6_destination_unreachable,
- ICMP6_destination_unreachable_port_unreachable, 0);
- next1 = UDP_INPUT_NEXT_ICMP6_ERROR;
- n_no_listener ++;
- }
- }
- else
- {
- b1->error = node->errors[UDP_ERROR_NONE];
- // advance to the payload
- vlib_buffer_advance (b1, sizeof (*h1));
- }
-
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- udp_rx_trace_t *tr = vlib_add_trace (vm, node,
- b0, sizeof (*tr));
- if (b0->error != node->errors[UDP_ERROR_LENGTH_ERROR])
- {
- tr->src_port = h0 ? h0->src_port : 0;
- tr->dst_port = h0 ? h0->dst_port : 0;
- tr->bound = (next0 != UDP_INPUT_NEXT_ICMP4_ERROR &&
- next0 != UDP_INPUT_NEXT_ICMP6_ERROR);
- }
- }
- if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
- {
- udp_rx_trace_t *tr = vlib_add_trace (vm, node,
- b1, sizeof (*tr));
- if (b1->error != node->errors[UDP_ERROR_LENGTH_ERROR])
- {
- tr->src_port = h1 ? h1->src_port : 0;
- tr->dst_port = h1 ? h1->dst_port : 0;
- tr->bound = (next1 != UDP_INPUT_NEXT_ICMP4_ERROR &&
- next1 != UDP_INPUT_NEXT_ICMP6_ERROR);
- }
- }
+ else if (is_ip4)
+ {
+ icmp4_error_set_vnet_buffer (b1,
+ ICMP4_destination_unreachable,
+ ICMP4_destination_unreachable_port_unreachable,
+ 0);
+ next1 = UDP_INPUT_NEXT_ICMP4_ERROR;
+ n_no_listener++;
+ }
+ else
+ {
+ icmp6_error_set_vnet_buffer (b1,
+ ICMP6_destination_unreachable,
+ ICMP6_destination_unreachable_port_unreachable,
+ 0);
+ next1 = UDP_INPUT_NEXT_ICMP6_ERROR;
+ n_no_listener++;
+ }
+ }
+ else
+ {
+ b1->error = node->errors[UDP_ERROR_NONE];
+ // advance to the payload
+ vlib_buffer_advance (b1, sizeof (*h1));
+ }
+
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ udp_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
+ if (b0->error != node->errors[UDP_ERROR_LENGTH_ERROR])
+ {
+ tr->src_port = h0 ? h0->src_port : 0;
+ tr->dst_port = h0 ? h0->dst_port : 0;
+ tr->bound = (next0 != UDP_INPUT_NEXT_ICMP4_ERROR &&
+ next0 != UDP_INPUT_NEXT_ICMP6_ERROR);
+ }
+ }
+ if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ udp_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b1, sizeof (*tr));
+ if (b1->error != node->errors[UDP_ERROR_LENGTH_ERROR])
+ {
+ tr->src_port = h1 ? h1->src_port : 0;
+ tr->dst_port = h1 ? h1->dst_port : 0;
+ tr->bound = (next1 != UDP_INPUT_NEXT_ICMP4_ERROR &&
+ next1 != UDP_INPUT_NEXT_ICMP6_ERROR);
+ }
+ }
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
bi0, bi1, next0, next1);
}
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
- vlib_buffer_t * b0;
- udp_header_t * h0 = 0;
+ vlib_buffer_t *b0;
+ udp_header_t *h0 = 0;
u32 i0, next0;
- u32 advance0;
+ u32 advance0;
bi0 = from[0];
to_next[0] = bi0;
@@ -294,81 +304,85 @@ udp46_input_inline (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
- /* ip4/6_local hands us the ip header, not the udp header */
- if (is_ip4)
- advance0 = sizeof(ip4_header_t);
- else
- advance0 = sizeof(ip6_header_t);
+ /* ip4/6_local hands us the ip header, not the udp header */
+ if (is_ip4)
+ advance0 = sizeof (ip4_header_t);
+ else
+ advance0 = sizeof (ip6_header_t);
- if (PREDICT_FALSE(b0->current_length < advance0 + sizeof (*h0)))
- {
- b0->error = node->errors[UDP_ERROR_LENGTH_ERROR];
- next0 = UDP_INPUT_NEXT_DROP;
- goto trace_x1;
- }
+ if (PREDICT_FALSE (b0->current_length < advance0 + sizeof (*h0)))
+ {
+ b0->error = node->errors[UDP_ERROR_LENGTH_ERROR];
+ next0 = UDP_INPUT_NEXT_DROP;
+ goto trace_x1;
+ }
- vlib_buffer_advance (b0, advance0);
+ vlib_buffer_advance (b0, advance0);
h0 = vlib_buffer_get_current (b0);
- if (PREDICT_TRUE(clib_net_to_host_u16(h0->length) <=
- vlib_buffer_length_in_chain(vm, b0)))
- {
- i0 = sparse_vec_index (rt->next_by_dst_port, h0->dst_port);
- next0 = vec_elt(rt->next_by_dst_port, i0);
-
- if (PREDICT_FALSE(i0 == SPARSE_VEC_INVALID_INDEX))
- {
- // move the pointer back so icmp-error can find the
- // ip packet header
- vlib_buffer_advance (b0, - (word)advance0);
-
- if (PREDICT_FALSE(punt_unknown))
- {
- b0->error = node->errors[UDP_ERROR_PUNT];
- next0 = UDP_INPUT_NEXT_PUNT;
+ if (PREDICT_TRUE (clib_net_to_host_u16 (h0->length) <=
+ vlib_buffer_length_in_chain (vm, b0)))
+ {
+ i0 = sparse_vec_index (rt->next_by_dst_port, h0->dst_port);
+ next0 = vec_elt (rt->next_by_dst_port, i0);
+
+ if (PREDICT_FALSE (i0 == SPARSE_VEC_INVALID_INDEX))
+ {
+ // move the pointer back so icmp-error can find the
+ // ip packet header
+ vlib_buffer_advance (b0, -(word) advance0);
+
+ if (PREDICT_FALSE (punt_unknown))
+ {
+ b0->error = node->errors[UDP_ERROR_PUNT];
+ next0 = UDP_INPUT_NEXT_PUNT;
+ }
+ else if (is_ip4)
+ {
+ icmp4_error_set_vnet_buffer (b0,
+ ICMP4_destination_unreachable,
+ ICMP4_destination_unreachable_port_unreachable,
+ 0);
+ next0 = UDP_INPUT_NEXT_ICMP4_ERROR;
+ n_no_listener++;
}
- else if (is_ip4)
- {
- icmp4_error_set_vnet_buffer(b0, ICMP4_destination_unreachable,
- ICMP4_destination_unreachable_port_unreachable, 0);
- next0 = UDP_INPUT_NEXT_ICMP4_ERROR;
- n_no_listener ++;
- }
- else
- {
- icmp6_error_set_vnet_buffer(b0, ICMP6_destination_unreachable,
- ICMP6_destination_unreachable_port_unreachable, 0);
- next0 = UDP_INPUT_NEXT_ICMP6_ERROR;
- n_no_listener ++;
- }
- }
- else
- {
- b0->error = node->errors[UDP_ERROR_NONE];
- // advance to the payload
- vlib_buffer_advance (b0, sizeof (*h0));
- }
- }
- else
- {
- b0->error = node->errors[UDP_ERROR_LENGTH_ERROR];
- next0 = UDP_INPUT_NEXT_DROP;
- }
-
- trace_x1:
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- udp_rx_trace_t *tr = vlib_add_trace (vm, node,
- b0, sizeof (*tr));
- if (b0->error != node->errors[UDP_ERROR_LENGTH_ERROR])
- {
- tr->src_port = h0->src_port;
- tr->dst_port = h0->dst_port;
- tr->bound = (next0 != UDP_INPUT_NEXT_ICMP4_ERROR &&
- next0 != UDP_INPUT_NEXT_ICMP6_ERROR);
- }
- }
+ else
+ {
+ icmp6_error_set_vnet_buffer (b0,
+ ICMP6_destination_unreachable,
+ ICMP6_destination_unreachable_port_unreachable,
+ 0);
+ next0 = UDP_INPUT_NEXT_ICMP6_ERROR;
+ n_no_listener++;
+ }
+ }
+ else
+ {
+ b0->error = node->errors[UDP_ERROR_NONE];
+ // advance to the payload
+ vlib_buffer_advance (b0, sizeof (*h0));
+ }
+ }
+ else
+ {
+ b0->error = node->errors[UDP_ERROR_LENGTH_ERROR];
+ next0 = UDP_INPUT_NEXT_DROP;
+ }
+
+ trace_x1:
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ udp_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
+ if (b0->error != node->errors[UDP_ERROR_LENGTH_ERROR])
+ {
+ tr->src_port = h0->src_port;
+ tr->dst_port = h0->dst_port;
+ tr->bound = (next0 != UDP_INPUT_NEXT_ICMP4_ERROR &&
+ next0 != UDP_INPUT_NEXT_ICMP6_ERROR);
+ }
+ }
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
@@ -377,11 +391,12 @@ udp46_input_inline (vlib_main_t * vm,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_error_count(vm, node->node_index, UDP_ERROR_NO_LISTENER, n_no_listener);
+ vlib_error_count (vm, node->node_index, UDP_ERROR_NO_LISTENER,
+ n_no_listener);
return from_frame->n_vectors;
}
-static char * udp_error_strings[] = {
+static char *udp_error_strings[] = {
#define udp_error(n,s) s,
#include "udp_error.def"
#undef udp_error
@@ -389,21 +404,20 @@ static char * udp_error_strings[] = {
static uword
udp4_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
- return udp46_input_inline (vm, node, from_frame, 1 /* is_ip4 */);
+ return udp46_input_inline (vm, node, from_frame, 1 /* is_ip4 */ );
}
static uword
udp6_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
- return udp46_input_inline (vm, node, from_frame, 0 /* is_ip4 */);
+ return udp46_input_inline (vm, node, from_frame, 0 /* is_ip4 */ );
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (udp4_input_node) = {
.function = udp4_input,
.name = "ip4-udp-lookup",
@@ -426,9 +440,11 @@ VLIB_REGISTER_NODE (udp4_input_node) = {
.format_trace = format_udp_rx_trace,
.unformat_buffer = unformat_udp_header,
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (udp4_input_node, udp4_input)
+VLIB_NODE_FUNCTION_MULTIARCH (udp4_input_node, udp4_input);
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (udp6_input_node) = {
.function = udp6_input,
.name = "ip6-udp-lookup",
@@ -451,14 +467,15 @@ VLIB_REGISTER_NODE (udp6_input_node) = {
.format_trace = format_udp_rx_trace,
.unformat_buffer = unformat_udp_header,
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (udp6_input_node, udp6_input)
+VLIB_NODE_FUNCTION_MULTIARCH (udp6_input_node, udp6_input);
-static void add_dst_port (udp_main_t * um,
- udp_dst_port_t dst_port,
- char * dst_port_name, u8 is_ip4)
+static void
+add_dst_port (udp_main_t * um,
+ udp_dst_port_t dst_port, char *dst_port_name, u8 is_ip4)
{
- udp_dst_port_info_t * pi;
+ udp_dst_port_info_t *pi;
u32 i;
vec_add2 (um->dst_port_infos[is_ip4], pi, 1);
@@ -467,7 +484,7 @@ static void add_dst_port (udp_main_t * um,
pi->name = dst_port_name;
pi->dst_port = dst_port;
pi->next_index = pi->node_index = ~0;
-
+
hash_set (um->dst_port_info_by_dst_port[is_ip4], dst_port, i);
if (pi->name)
@@ -476,70 +493,69 @@ static void add_dst_port (udp_main_t * um,
void
udp_register_dst_port (vlib_main_t * vm,
- udp_dst_port_t dst_port,
- u32 node_index, u8 is_ip4)
+ udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
{
- udp_main_t * um = &udp_main;
- udp_dst_port_info_t * pi;
- udp_input_runtime_t * rt;
- u16 * n;
+ udp_main_t *um = &udp_main;
+ udp_dst_port_info_t *pi;
+ udp_input_runtime_t *rt;
+ u16 *n;
{
- clib_error_t * error = vlib_call_init_function (vm, udp_local_init);
+ clib_error_t *error = vlib_call_init_function (vm, udp_local_init);
if (error)
clib_error_report (error);
}
pi = udp_get_dst_port_info (um, dst_port, is_ip4);
- if (! pi)
+ if (!pi)
{
add_dst_port (um, dst_port, 0, is_ip4);
pi = udp_get_dst_port_info (um, dst_port, is_ip4);
ASSERT (pi);
}
-
+
pi->node_index = node_index;
- pi->next_index = vlib_node_add_next (vm,
- is_ip4 ? udp4_input_node.index
- : udp6_input_node.index,
- node_index);
+ pi->next_index = vlib_node_add_next (vm,
+ is_ip4 ? udp4_input_node.index
+ : udp6_input_node.index, node_index);
/* Setup udp protocol -> next index sparse vector mapping. */
- rt = vlib_node_get_runtime_data
- (vm, is_ip4 ? udp4_input_node.index: udp6_input_node.index);
- n = sparse_vec_validate (rt->next_by_dst_port,
- clib_host_to_net_u16 (dst_port));
+ rt = vlib_node_get_runtime_data
+ (vm, is_ip4 ? udp4_input_node.index : udp6_input_node.index);
+ n = sparse_vec_validate (rt->next_by_dst_port,
+ clib_host_to_net_u16 (dst_port));
n[0] = pi->next_index;
}
void
-udp_punt_unknown(vlib_main_t * vm, u8 is_ip4, u8 is_add)
+udp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add)
{
- udp_input_runtime_t * rt;
+ udp_input_runtime_t *rt;
{
- clib_error_t * error = vlib_call_init_function (vm, udp_local_init);
+ clib_error_t *error = vlib_call_init_function (vm, udp_local_init);
if (error)
clib_error_report (error);
}
- rt = vlib_node_get_runtime_data
- (vm, is_ip4 ? udp4_input_node.index: udp6_input_node.index);
+ rt = vlib_node_get_runtime_data
+ (vm, is_ip4 ? udp4_input_node.index : udp6_input_node.index);
rt->punt_unknown = is_add;
}
/* Parse a UDP header. */
-uword unformat_udp_header (unformat_input_t * input, va_list * args)
+uword
+unformat_udp_header (unformat_input_t * input, va_list * args)
{
- u8 ** result = va_arg (*args, u8 **);
- udp_header_t * udp;
- __attribute__((unused)) int old_length;
+ u8 **result = va_arg (*args, u8 **);
+ udp_header_t *udp;
+ __attribute__ ((unused)) int old_length;
u16 src_port, dst_port;
/* Allocate space for IP header. */
{
- void * p;
+ void *p;
old_length = vec_len (*result);
vec_add2 (*result, p, sizeof (ip4_header_t));
@@ -547,8 +563,7 @@ uword unformat_udp_header (unformat_input_t * input, va_list * args)
}
memset (udp, 0, sizeof (udp[0]));
- if (unformat (input, "src-port %d dst-port %d",
- &src_port, &dst_port))
+ if (unformat (input, "src-port %d dst-port %d", &src_port, &dst_port))
{
udp->src_port = clib_host_to_net_u16 (src_port);
udp->dst_port = clib_host_to_net_u16 (dst_port);
@@ -560,22 +575,23 @@ uword unformat_udp_header (unformat_input_t * input, va_list * args)
static void
udp_setup_node (vlib_main_t * vm, u32 node_index)
{
- vlib_node_t * n = vlib_get_node (vm, node_index);
- pg_node_t * pn = pg_get_node (node_index);
+ vlib_node_t *n = vlib_get_node (vm, node_index);
+ pg_node_t *pn = pg_get_node (node_index);
n->format_buffer = format_udp_header;
n->unformat_buffer = unformat_udp_header;
pn->unformat_edit = unformat_pg_udp_header;
}
-clib_error_t * udp_local_init (vlib_main_t * vm)
+clib_error_t *
+udp_local_init (vlib_main_t * vm)
{
- udp_input_runtime_t * rt;
- udp_main_t * um = &udp_main;
+ udp_input_runtime_t *rt;
+ udp_main_t *um = &udp_main;
int i;
{
- clib_error_t * error;
+ clib_error_t *error;
error = vlib_call_init_function (vm, udp_init);
if (error)
clib_error_report (error);
@@ -584,8 +600,8 @@ clib_error_t * udp_local_init (vlib_main_t * vm)
for (i = 0; i < 2; i++)
{
- um->dst_port_info_by_name[i] = hash_create_string (0, sizeof(uword));
- um->dst_port_info_by_dst_port[i] = hash_create (0, sizeof(uword));
+ um->dst_port_info_by_name[i] = hash_create_string (0, sizeof (uword));
+ um->dst_port_info_by_dst_port[i] = hash_create (0, sizeof (uword));
}
udp_setup_node (vm, udp4_input_node.index);
@@ -594,7 +610,7 @@ clib_error_t * udp_local_init (vlib_main_t * vm)
rt = vlib_node_get_runtime_data (vm, udp4_input_node.index);
rt->next_by_dst_port = sparse_vec_new
- (/* elt bytes */ sizeof (rt->next_by_dst_port[0]),
+ ( /* elt bytes */ sizeof (rt->next_by_dst_port[0]),
/* bits in index */ BITS (((udp_header_t *) 0)->dst_port));
rt->punt_unknown = 0;
@@ -602,11 +618,10 @@ clib_error_t * udp_local_init (vlib_main_t * vm)
#define _(n,s) add_dst_port (um, UDP_DST_PORT_##s, #s, 1 /* is_ip4 */);
foreach_udp4_dst_port
#undef _
-
- rt = vlib_node_get_runtime_data (vm, udp6_input_node.index);
+ rt = vlib_node_get_runtime_data (vm, udp6_input_node.index);
rt->next_by_dst_port = sparse_vec_new
- (/* elt bytes */ sizeof (rt->next_by_dst_port[0]),
+ ( /* elt bytes */ sizeof (rt->next_by_dst_port[0]),
/* bits in index */ BITS (((udp_header_t *) 0)->dst_port));
rt->punt_unknown = 0;
@@ -614,10 +629,17 @@ clib_error_t * udp_local_init (vlib_main_t * vm)
#define _(n,s) add_dst_port (um, UDP_DST_PORT_##s, #s, 0 /* is_ip4 */);
foreach_udp6_dst_port
#undef _
-
- ip4_register_protocol (IP_PROTOCOL_UDP, udp4_input_node.index);
+ ip4_register_protocol (IP_PROTOCOL_UDP, udp4_input_node.index);
/* Note: ip6 differs from ip4, UDP is hotwired to ip6-udp-lookup */
return 0;
}
VLIB_INIT_FUNCTION (udp_local_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/udp_packet.h b/vnet/vnet/ip/udp_packet.h
index 21c30c6eb71..beea3059246 100644
--- a/vnet/vnet/ip/udp_packet.h
+++ b/vnet/vnet/ip/udp_packet.h
@@ -40,7 +40,8 @@
#ifndef included_udp_packet_h
#define included_udp_packet_h
-typedef struct {
+typedef struct
+{
/* Source and destination port. */
u16 src_port, dst_port;
@@ -54,3 +55,11 @@ typedef struct {
#endif /* included_udp_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ip/udp_pg.c b/vnet/vnet/ip/udp_pg.c
index 76383a9a9c2..c9d8d38ca4a 100644
--- a/vnet/vnet/ip/udp_pg.c
+++ b/vnet/vnet/ip/udp_pg.c
@@ -38,7 +38,7 @@
*/
#include <vnet/pg/pg.h>
-#include <vnet/ip/ip.h> /* for unformat_udp_udp_port */
+#include <vnet/ip/ip.h> /* for unformat_udp_udp_port */
#define UDP_PG_EDIT_LENGTH (1 << 0)
#define UDP_PG_EDIT_CHECKSUM (1 << 1)
@@ -47,21 +47,19 @@ always_inline void
udp_pg_edit_function_inline (pg_main_t * pg,
pg_stream_t * s,
pg_edit_group_t * g,
- u32 * packets,
- u32 n_packets,
- u32 flags)
+ u32 * packets, u32 n_packets, u32 flags)
{
- vlib_main_t * vm = vlib_get_main();
+ vlib_main_t *vm = vlib_get_main ();
u32 ip_offset, udp_offset;
udp_offset = g->start_byte_offset;
- ip_offset = (g-1)->start_byte_offset;
+ ip_offset = (g - 1)->start_byte_offset;
while (n_packets >= 1)
{
- vlib_buffer_t * p0;
- ip4_header_t * ip0;
- udp_header_t * udp0;
+ vlib_buffer_t *p0;
+ ip4_header_t *ip0;
+ udp_header_t *udp0;
u32 udp_len0;
p0 = vlib_get_buffer (vm, packets[0]);
@@ -73,9 +71,9 @@ udp_pg_edit_function_inline (pg_main_t * pg,
udp_len0 = clib_net_to_host_u16 (ip0->length) - sizeof (ip0[0]);
if (flags & UDP_PG_EDIT_LENGTH)
- udp0->length =
- clib_net_to_host_u16 (vlib_buffer_length_in_chain (vm, p0)
- - ip_offset);
+ udp0->length =
+ clib_net_to_host_u16 (vlib_buffer_length_in_chain (vm, p0)
+ - ip_offset);
/* Initialize checksum with header. */
if (flags & UDP_PG_EDIT_CHECKSUM)
@@ -90,9 +88,11 @@ udp_pg_edit_function_inline (pg_main_t * pg,
/* Invalidate possibly old checksum. */
udp0->checksum = 0;
- sum0 = ip_incremental_checksum_buffer (vm, p0, udp_offset, udp_len0, sum0);
+ sum0 =
+ ip_incremental_checksum_buffer (vm, p0, udp_offset, udp_len0,
+ sum0);
- sum0 = ~ ip_csum_fold (sum0);
+ sum0 = ~ip_csum_fold (sum0);
/* Zero checksum means checksumming disabled. */
sum0 = sum0 != 0 ? sum0 : 0xffff;
@@ -105,9 +105,7 @@ udp_pg_edit_function_inline (pg_main_t * pg,
static void
udp_pg_edit_function (pg_main_t * pg,
pg_stream_t * s,
- pg_edit_group_t * g,
- u32 * packets,
- u32 n_packets)
+ pg_edit_group_t * g, u32 * packets, u32 n_packets)
{
switch (g->edit_function_opaque)
{
@@ -132,7 +130,8 @@ udp_pg_edit_function (pg_main_t * pg,
}
}
-typedef struct {
+typedef struct
+{
pg_edit_t src_port, dst_port;
pg_edit_t length;
pg_edit_t checksum;
@@ -143,20 +142,20 @@ pg_udp_header_init (pg_udp_header_t * p)
{
/* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, udp_header_t, f);
- _ (src_port);
- _ (dst_port);
- _ (length);
- _ (checksum);
+ _(src_port);
+ _(dst_port);
+ _(length);
+ _(checksum);
#undef _
}
uword
unformat_pg_udp_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_udp_header_t * p;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_udp_header_t *p;
u32 group_index;
-
+
p = pg_create_edit_group (s, sizeof (p[0]), sizeof (udp_header_t),
&group_index);
pg_udp_header_init (p);
@@ -165,24 +164,21 @@ unformat_pg_udp_header (unformat_input_t * input, va_list * args)
p->checksum.type = PG_EDIT_UNSPECIFIED;
p->length.type = PG_EDIT_UNSPECIFIED;
- if (! unformat (input, "UDP: %U -> %U",
- unformat_pg_edit,
- unformat_tcp_udp_port, &p->src_port,
- unformat_pg_edit,
- unformat_tcp_udp_port, &p->dst_port))
+ if (!unformat (input, "UDP: %U -> %U",
+ unformat_pg_edit,
+ unformat_tcp_udp_port, &p->src_port,
+ unformat_pg_edit, unformat_tcp_udp_port, &p->dst_port))
goto error;
/* Parse options. */
while (1)
{
if (unformat (input, "length %U",
- unformat_pg_edit,
- unformat_pg_number, &p->length))
+ unformat_pg_edit, unformat_pg_number, &p->length))
;
else if (unformat (input, "checksum %U",
- unformat_pg_edit,
- unformat_pg_number, &p->checksum))
+ unformat_pg_edit, unformat_pg_number, &p->checksum))
;
/* Can't parse input: try next protocol level. */
@@ -191,9 +187,9 @@ unformat_pg_udp_header (unformat_input_t * input, va_list * args)
}
{
- ip_main_t * im = &ip_main;
+ ip_main_t *im = &ip_main;
u16 dst_port;
- tcp_udp_port_info_t * pi;
+ tcp_udp_port_info_t *pi;
pi = 0;
if (p->dst_port.type == PG_EDIT_FIXED)
@@ -206,14 +202,14 @@ unformat_pg_udp_header (unformat_input_t * input, va_list * args)
&& unformat_user (input, pi->unformat_pg_edit, s))
;
- else if (! unformat_user (input, unformat_pg_payload, s))
+ else if (!unformat_user (input, unformat_pg_payload, s))
goto error;
p = pg_get_edit_group (s, group_index);
if (p->checksum.type == PG_EDIT_UNSPECIFIED
|| p->length.type == PG_EDIT_UNSPECIFIED)
{
- pg_edit_group_t * g = pg_stream_get_group (s, group_index);
+ pg_edit_group_t *g = pg_stream_get_group (s, group_index);
g->edit_function = udp_pg_edit_function;
g->edit_function_opaque = 0;
if (p->checksum.type == PG_EDIT_UNSPECIFIED)
@@ -225,9 +221,17 @@ unformat_pg_udp_header (unformat_input_t * input, va_list * args)
return 1;
}
- error:
+error:
/* Free up any edits we may have added. */
pg_free_edit_group (s);
return 0;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */