diff options
-rw-r--r-- | vnet/vnet/ppp/node.c | 125 | ||||
-rw-r--r-- | vnet/vnet/ppp/packet.h | 14 | ||||
-rw-r--r-- | vnet/vnet/ppp/pg.c | 33 | ||||
-rw-r--r-- | vnet/vnet/ppp/ppp.c | 106 | ||||
-rw-r--r-- | vnet/vnet/ppp/ppp.h | 40 |
5 files changed, 194 insertions, 124 deletions
diff --git a/vnet/vnet/ppp/node.c b/vnet/vnet/ppp/node.c index 4f813732df2..4f1f6a715e6 100644 --- a/vnet/vnet/ppp/node.c +++ b/vnet/vnet/ppp/node.c @@ -46,43 +46,46 @@ _ (PUNT, "error-punt") \ _ (DROP, "error-drop") -typedef enum { +typedef enum +{ #define _(s,n) PPP_INPUT_NEXT_##s, foreach_ppp_input_next #undef _ - PPP_INPUT_N_NEXT, + PPP_INPUT_N_NEXT, } ppp_input_next_t; -typedef struct { +typedef struct +{ u8 packet_data[32]; } ppp_input_trace_t; -static u8 * format_ppp_input_trace (u8 * s, va_list * va) +static u8 * +format_ppp_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 *); - ppp_input_trace_t * t = va_arg (*va, ppp_input_trace_t *); + ppp_input_trace_t *t = va_arg (*va, ppp_input_trace_t *); s = format (s, "%U", format_ppp_header, t->packet_data); return s; } -typedef struct { +typedef struct +{ /* Sparse vector mapping ppp protocol in network byte order to next index. */ - u16 * next_by_protocol; + u16 *next_by_protocol; - u32 * sparse_index_by_next_index; + u32 *sparse_index_by_next_index; } ppp_input_runtime_t; static uword ppp_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) { - ppp_input_runtime_t * rt = (void *) node->runtime_data; - u32 n_left_from, next_index, i_next, * from, * to_next; + ppp_input_runtime_t *rt = (void *) node->runtime_data; + u32 n_left_from, next_index, i_next, *from, *to_next; from = vlib_frame_vector_args (from_frame); n_left_from = from_frame->n_vectors; @@ -101,19 +104,18 @@ ppp_input (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; - ppp_header_t * h0, * h1; + vlib_buffer_t *b0, *b1; + ppp_header_t *h0, *h1; u32 i0, i1, protocol0, protocol1, enqueue_code; /* 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]); @@ -149,12 +151,19 @@ ppp_input (vlib_main_t * vm, /* Index sparse array with network byte order. */ protocol0 = h0->protocol; protocol1 = h1->protocol; - sparse_vec_index2 (rt->next_by_protocol, protocol0, protocol1, &i0, &i1); + sparse_vec_index2 (rt->next_by_protocol, protocol0, protocol1, &i0, + &i1); - b0->error = node->errors[i0 == SPARSE_VEC_INVALID_INDEX ? PPP_ERROR_UNKNOWN_PROTOCOL : PPP_ERROR_NONE]; - b1->error = node->errors[i1 == SPARSE_VEC_INVALID_INDEX ? PPP_ERROR_UNKNOWN_PROTOCOL : PPP_ERROR_NONE]; + b0->error = + node->errors[i0 == + SPARSE_VEC_INVALID_INDEX ? PPP_ERROR_UNKNOWN_PROTOCOL + : PPP_ERROR_NONE]; + b1->error = + node->errors[i1 == + SPARSE_VEC_INVALID_INDEX ? PPP_ERROR_UNKNOWN_PROTOCOL + : PPP_ERROR_NONE]; - enqueue_code = (i0 != i_next) + 2*(i1 != i_next); + enqueue_code = (i0 != i_next) + 2 * (i1 != i_next); if (PREDICT_FALSE (enqueue_code != 0)) { @@ -165,39 +174,48 @@ ppp_input (vlib_main_t * vm, to_next[-2] = bi1; to_next -= 1; n_left_to_next += 1; - vlib_set_next_frame_buffer (vm, node, vec_elt (rt->next_by_protocol, i0), bi0); + vlib_set_next_frame_buffer (vm, node, + vec_elt (rt->next_by_protocol, + i0), bi0); break; case 2: /* A A B */ to_next -= 1; n_left_to_next += 1; - vlib_set_next_frame_buffer (vm, node, vec_elt (rt->next_by_protocol, i1), bi1); + vlib_set_next_frame_buffer (vm, node, + vec_elt (rt->next_by_protocol, + i1), bi1); break; case 3: /* A B B or A B C */ to_next -= 2; n_left_to_next += 2; - vlib_set_next_frame_buffer (vm, node, vec_elt (rt->next_by_protocol, i0), bi0); - vlib_set_next_frame_buffer (vm, node, vec_elt (rt->next_by_protocol, i1), bi1); + vlib_set_next_frame_buffer (vm, node, + vec_elt (rt->next_by_protocol, + i0), bi0); + vlib_set_next_frame_buffer (vm, node, + vec_elt (rt->next_by_protocol, + i1), bi1); if (i0 == i1) { vlib_put_next_frame (vm, node, next_index, n_left_to_next); i_next = i1; next_index = vec_elt (rt->next_by_protocol, i_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 > 0 && n_left_to_next > 0) { u32 bi0; - vlib_buffer_t * b0; - ppp_header_t * h0; + vlib_buffer_t *b0; + ppp_header_t *h0; u32 i0, protocol0; bi0 = from[0]; @@ -217,8 +235,11 @@ ppp_input (vlib_main_t * vm, protocol0 = h0->protocol; i0 = sparse_vec_index (rt->next_by_protocol, protocol0); - b0->error = node->errors[i0 == SPARSE_VEC_INVALID_INDEX ? PPP_ERROR_UNKNOWN_PROTOCOL : PPP_ERROR_NONE]; - + b0->error = + node->errors[i0 == + SPARSE_VEC_INVALID_INDEX ? PPP_ERROR_UNKNOWN_PROTOCOL + : PPP_ERROR_NONE]; + /* Sent packet to wrong next? */ if (PREDICT_FALSE (i0 != i_next)) { @@ -242,12 +263,13 @@ ppp_input (vlib_main_t * vm, return from_frame->n_vectors; } -static char * ppp_error_strings[] = { +static char *ppp_error_strings[] = { #define ppp_error(n,s) s, #include "error.def" #undef ppp_error }; +/* *INDENT-OFF* */ VLIB_REGISTER_NODE (ppp_input_node) = { .function = ppp_input, .name = "ppp-input", @@ -270,13 +292,15 @@ VLIB_REGISTER_NODE (ppp_input_node) = { .format_trace = format_ppp_input_trace, .unformat_buffer = unformat_ppp_header, }; +/* *INDENT-ON* */ -static clib_error_t * ppp_input_init (vlib_main_t * vm) +static clib_error_t * +ppp_input_init (vlib_main_t * vm) { - ppp_input_runtime_t * rt; + ppp_input_runtime_t *rt; { - clib_error_t * error = vlib_call_init_function (vm, ppp_init); + clib_error_t *error = vlib_call_init_function (vm, ppp_init); if (error) clib_error_report (error); } @@ -286,7 +310,7 @@ static clib_error_t * ppp_input_init (vlib_main_t * vm) rt = vlib_node_get_runtime_data (vm, ppp_input_node.index); rt->next_by_protocol = sparse_vec_new - (/* elt bytes */ sizeof (rt->next_by_protocol[0]), + ( /* elt bytes */ sizeof (rt->next_by_protocol[0]), /* bits in index */ BITS (((ppp_header_t *) 0)->protocol)); vec_validate (rt->sparse_index_by_next_index, PPP_INPUT_NEXT_DROP); @@ -303,30 +327,29 @@ VLIB_INIT_FUNCTION (ppp_input_init); void ppp_register_input_protocol (vlib_main_t * vm, - ppp_protocol_t protocol, - u32 node_index) + ppp_protocol_t protocol, u32 node_index) { - ppp_main_t * em = &ppp_main; - ppp_protocol_info_t * pi; - ppp_input_runtime_t * rt; - u16 * n; + ppp_main_t *em = &ppp_main; + ppp_protocol_info_t *pi; + ppp_input_runtime_t *rt; + u16 *n; u32 i; { - clib_error_t * error = vlib_call_init_function (vm, ppp_input_init); + clib_error_t *error = vlib_call_init_function (vm, ppp_input_init); if (error) clib_error_report (error); } pi = ppp_get_protocol_info (em, protocol); pi->node_index = node_index; - pi->next_index = vlib_node_add_next (vm, - ppp_input_node.index, - node_index); + pi->next_index = vlib_node_add_next (vm, ppp_input_node.index, node_index); /* Setup ppp protocol -> next index sparse vector mapping. */ rt = vlib_node_get_runtime_data (vm, ppp_input_node.index); - n = sparse_vec_validate (rt->next_by_protocol, clib_host_to_net_u16 (protocol)); + n = + sparse_vec_validate (rt->next_by_protocol, + clib_host_to_net_u16 (protocol)); n[0] = pi->next_index; /* Rebuild next index -> sparse index inverse mapping when sparse vector @@ -335,3 +358,11 @@ ppp_register_input_protocol (vlib_main_t * vm, for (i = 1; i < vec_len (rt->next_by_protocol); i++) rt->sparse_index_by_next_index[rt->next_by_protocol[i]] = i; } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/ppp/packet.h b/vnet/vnet/ppp/packet.h index da034daecfa..cab9743de92 100644 --- a/vnet/vnet/ppp/packet.h +++ b/vnet/vnet/ppp/packet.h @@ -147,7 +147,8 @@ _ (0xc281, proprietary_authentication_a) \ _ (0xc283, proprietary_authentication_b) \ _ (0xc481, proprietary_node_id_authentication) -typedef enum { +typedef enum +{ #define _(n,f) PPP_PROTOCOL_##f = n, foreach_ppp_protocol #undef _ @@ -178,7 +179,8 @@ _ (13, time_remaining) \ _ (14, reset_request) \ _ (15, reset_reply) -typedef struct { +typedef struct +{ /* Set to 0xff 0x03 */ u8 address, control; @@ -187,3 +189,11 @@ typedef struct { } ppp_header_t; #endif /* included_vnet_ppp_packet_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/ppp/pg.c b/vnet/vnet/ppp/pg.c index 2662bdc1999..0b46ccb9052 100644 --- a/vnet/vnet/ppp/pg.c +++ b/vnet/vnet/ppp/pg.c @@ -41,7 +41,8 @@ #include <vnet/pg/pg.h> #include <vnet/ppp/ppp.h> -typedef struct { +typedef struct +{ pg_edit_t address; pg_edit_t control; pg_edit_t protocol; @@ -58,10 +59,10 @@ pg_ppp_header_init (pg_ppp_header_t * e) uword unformat_pg_ppp_header (unformat_input_t * input, va_list * args) { - pg_stream_t * s = va_arg (*args, pg_stream_t *); - pg_ppp_header_t * h; + pg_stream_t *s = va_arg (*args, pg_stream_t *); + pg_ppp_header_t *h; u32 group_index, error; - + h = pg_create_edit_group (s, sizeof (h[0]), sizeof (ppp_header_t), &group_index); pg_ppp_header_init (h); @@ -70,15 +71,15 @@ unformat_pg_ppp_header (unformat_input_t * input, va_list * args) pg_edit_set_fixed (&h->control, 0x03); error = 1; - if (! unformat (input, "%U", - unformat_pg_edit, - unformat_ppp_protocol_net_byte_order, &h->protocol)) + if (!unformat (input, "%U", + unformat_pg_edit, + unformat_ppp_protocol_net_byte_order, &h->protocol)) goto done; { - ppp_main_t * pm = &ppp_main; - ppp_protocol_info_t * pi = 0; - pg_node_t * pg_node = 0; + ppp_main_t *pm = &ppp_main; + ppp_protocol_info_t *pi = 0; + pg_node_t *pg_node = 0; if (h->protocol.type == PG_EDIT_FIXED) { @@ -92,14 +93,22 @@ unformat_pg_ppp_header (unformat_input_t * input, va_list * args) && unformat_user (input, pg_node->unformat_edit, s)) ; - else if (! unformat_user (input, unformat_pg_payload, s)) + else if (!unformat_user (input, unformat_pg_payload, s)) goto done; } error = 0; - done: +done: if (error) pg_free_edit_group (s); return error == 0; } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/ppp/ppp.c b/vnet/vnet/ppp/ppp.c index e124e11673d..427fd7b7a79 100644 --- a/vnet/vnet/ppp/ppp.c +++ b/vnet/vnet/ppp/ppp.c @@ -43,11 +43,12 @@ /* Global main structure. */ ppp_main_t ppp_main; -u8 * format_ppp_protocol (u8 * s, va_list * args) +u8 * +format_ppp_protocol (u8 * s, va_list * args) { ppp_protocol_t p = va_arg (*args, u32); - ppp_main_t * pm = &ppp_main; - ppp_protocol_info_t * pi = ppp_get_protocol_info (pm, p); + ppp_main_t *pm = &ppp_main; + ppp_protocol_info_t *pi = ppp_get_protocol_info (pm, p); if (pi) s = format (s, "%s", pi->name); @@ -57,10 +58,11 @@ u8 * format_ppp_protocol (u8 * s, va_list * args) return s; } -u8 * format_ppp_header_with_length (u8 * s, va_list * args) +u8 * +format_ppp_header_with_length (u8 * s, va_list * args) { - ppp_main_t * pm = &ppp_main; - ppp_header_t * h = va_arg (*args, ppp_header_t *); + ppp_main_t *pm = &ppp_main; + ppp_header_t *h = va_arg (*args, ppp_header_t *); u32 max_header_bytes = va_arg (*args, u32); ppp_protocol_t p = clib_net_to_host_u16 (h->protocol); uword indent, header_bytes; @@ -80,8 +82,8 @@ u8 * format_ppp_header_with_length (u8 * s, va_list * args) if (max_header_bytes != 0 && header_bytes > max_header_bytes) { - ppp_protocol_info_t * pi = ppp_get_protocol_info (pm, p); - vlib_node_t * node = vlib_get_node (pm->vlib_main, pi->node_index); + ppp_protocol_info_t *pi = ppp_get_protocol_info (pm, p); + vlib_node_t *node = vlib_get_node (pm->vlib_main, pi->node_index); if (node->format_buffer) s = format (s, "\n%U%U", format_white_space, indent, @@ -92,9 +94,10 @@ u8 * format_ppp_header_with_length (u8 * s, va_list * args) return s; } -u8 * format_ppp_header (u8 * s, va_list * args) +u8 * +format_ppp_header (u8 * s, va_list * args) { - ppp_header_t * h = va_arg (*args, ppp_header_t *); + ppp_header_t *h = va_arg (*args, ppp_header_t *); return format (s, "%U", format_ppp_header_with_length, h, 0); } @@ -103,13 +106,12 @@ uword unformat_ppp_protocol_host_byte_order (unformat_input_t * input, va_list * args) { - u16 * result = va_arg (*args, u16 *); - ppp_main_t * pm = &ppp_main; + u16 *result = va_arg (*args, u16 *); + ppp_main_t *pm = &ppp_main; int p, i; /* Numeric type. */ - if (unformat (input, "0x%x", &p) - || unformat (input, "%d", &p)) + if (unformat (input, "0x%x", &p) || unformat (input, "%d", &p)) { if (p >= (1 << 16)) return 0; @@ -121,7 +123,7 @@ unformat_ppp_protocol_host_byte_order (unformat_input_t * input, if (unformat_user (input, unformat_vlib_number_by_name, pm->protocol_info_by_name, &i)) { - ppp_protocol_info_t * pi = vec_elt_at_index (pm->protocol_infos, i); + ppp_protocol_info_t *pi = vec_elt_at_index (pm->protocol_infos, i); *result = pi->protocol; return 1; } @@ -133,22 +135,21 @@ uword unformat_ppp_protocol_net_byte_order (unformat_input_t * input, va_list * args) { - u16 * result = va_arg (*args, u16 *); - if (! unformat_user (input, unformat_ppp_protocol_host_byte_order, result)) + u16 *result = va_arg (*args, u16 *); + if (!unformat_user (input, unformat_ppp_protocol_host_byte_order, result)) return 0; - *result = clib_host_to_net_u16 ((u16) *result); + *result = clib_host_to_net_u16 ((u16) * result); return 1; } uword unformat_ppp_header (unformat_input_t * input, va_list * args) { - u8 ** result = va_arg (*args, u8 **); - ppp_header_t _h, * h = &_h; + u8 **result = va_arg (*args, u8 **); + ppp_header_t _h, *h = &_h; u16 p; - if (! unformat (input, "%U", - unformat_ppp_protocol_host_byte_order, &p)) + if (!unformat (input, "%U", unformat_ppp_protocol_host_byte_order, &p)) return 0; h->address = 0xff; @@ -157,59 +158,60 @@ unformat_ppp_header (unformat_input_t * input, va_list * args) /* Add header to result. */ { - void * p; + void *p; u32 n_bytes = sizeof (h[0]); vec_add2 (*result, p, n_bytes); clib_memcpy (p, h, n_bytes); } - + return 1; } -static uword ppp_set_rewrite (vnet_main_t * vnm, - u32 sw_if_index, - u32 l3_type, - void * dst_address, - void * rewrite, - uword max_rewrite_bytes) +static uword +ppp_set_rewrite (vnet_main_t * vnm, + u32 sw_if_index, + u32 l3_type, + void *dst_address, void *rewrite, uword max_rewrite_bytes) { - ppp_header_t * h = rewrite; + ppp_header_t *h = rewrite; ppp_protocol_t protocol; if (max_rewrite_bytes < sizeof (h[0])) return 0; - switch (l3_type) { + switch (l3_type) + { #define _(a,b) case VNET_L3_PACKET_TYPE_##a: protocol = PPP_PROTOCOL_##b; break - _ (IP4, ip4); - _ (IP6, ip6); - _ (MPLS_UNICAST, mpls_unicast); - _ (MPLS_MULTICAST, mpls_multicast); + _(IP4, ip4); + _(IP6, ip6); + _(MPLS_UNICAST, mpls_unicast); + _(MPLS_MULTICAST, mpls_multicast); #undef _ - default: - return 0; - } + default: + return 0; + } h->address = 0xff; h->control = 0x03; h->protocol = clib_host_to_net_u16 (protocol); - + return sizeof (h[0]); } +/* *INDENT-OFF* */ VNET_HW_INTERFACE_CLASS (ppp_hw_interface_class) = { .name = "PPP", .format_header = format_ppp_header_with_length, .unformat_header = unformat_ppp_header, .set_rewrite = ppp_set_rewrite, }; +/* *INDENT-ON* */ -static void add_protocol (ppp_main_t * pm, - ppp_protocol_t protocol, - char * protocol_name) +static void +add_protocol (ppp_main_t * pm, ppp_protocol_t protocol, char *protocol_name) { - ppp_protocol_info_t * pi; + ppp_protocol_info_t *pi; u32 i; vec_add2 (pm->protocol_infos, pi, 1); @@ -223,9 +225,10 @@ static void add_protocol (ppp_main_t * pm, hash_set_mem (pm->protocol_info_by_name, pi->name, i); } -static clib_error_t * ppp_init (vlib_main_t * vm) +static clib_error_t * +ppp_init (vlib_main_t * vm) { - ppp_main_t * pm = &ppp_main; + ppp_main_t *pm = &ppp_main; memset (pm, 0, sizeof (pm[0])); pm->vlib_main = vm; @@ -242,9 +245,18 @@ static clib_error_t * ppp_init (vlib_main_t * vm) VLIB_INIT_FUNCTION (ppp_init); -ppp_main_t * ppp_get_main (vlib_main_t * vm) +ppp_main_t * +ppp_get_main (vlib_main_t * vm) { vlib_call_init_function (vm, ppp_init); return &ppp_main; } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/ppp/ppp.h b/vnet/vnet/ppp/ppp.h index 690ae4fc00d..fdc205b61e7 100644 --- a/vnet/vnet/ppp/ppp.h +++ b/vnet/vnet/ppp/ppp.h @@ -46,16 +46,18 @@ extern vnet_hw_interface_class_t ppp_hw_interface_class; -typedef enum { +typedef enum +{ #define ppp_error(n,s) PPP_ERROR_##n, #include <vnet/ppp/error.def> #undef ppp_error PPP_N_ERROR, } ppp_error_t; -typedef struct { +typedef struct +{ /* Name (a c string). */ - char * name; + char *name; /* PPP protocol type in host byte order. */ ppp_protocol_t protocol; @@ -67,19 +69,20 @@ typedef struct { u32 next_index; } ppp_protocol_info_t; -typedef struct { - vlib_main_t * vlib_main; +typedef struct +{ + vlib_main_t *vlib_main; - ppp_protocol_info_t * protocol_infos; + ppp_protocol_info_t *protocol_infos; /* Hash tables mapping name/protocol to protocol info index. */ - uword * protocol_info_by_name, * protocol_info_by_protocol; + uword *protocol_info_by_name, *protocol_info_by_protocol; } ppp_main_t; always_inline ppp_protocol_info_t * ppp_get_protocol_info (ppp_main_t * em, ppp_protocol_t protocol) { - uword * p = hash_get (em->protocol_info_by_protocol, protocol); + uword *p = hash_get (em->protocol_info_by_protocol, protocol); return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0; } @@ -88,12 +91,10 @@ extern ppp_main_t ppp_main; /* Register given node index to take input for given ppp type. */ void ppp_register_input_type (vlib_main_t * vm, - ppp_protocol_t protocol, - u32 node_index); + ppp_protocol_t protocol, u32 node_index); void ppp_set_adjacency (vnet_rewrite_header_t * rw, - uword max_data_bytes, - ppp_protocol_t protocol); + uword max_data_bytes, ppp_protocol_t protocol); format_function_t format_ppp_protocol; format_function_t format_ppp_header; @@ -111,8 +112,8 @@ unformat_function_t unformat_pg_ppp_header; always_inline void ppp_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_ppp_header_with_length; n->unformat_buffer = unformat_ppp_header; @@ -121,7 +122,14 @@ ppp_setup_node (vlib_main_t * vm, u32 node_index) void ppp_register_input_protocol (vlib_main_t * vm, - ppp_protocol_t protocol, - u32 node_index); + ppp_protocol_t protocol, u32 node_index); #endif /* included_ppp_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |