summaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorCalvin <cference@incoybe.ca>2016-08-24 10:35:59 -0400
committerDamjan Marion <dmarion.lists@gmail.com>2016-08-25 00:26:38 +0000
commit151fb725636f192da8a04d0f74dc3455b58dd61c (patch)
tree59ee4f4618492bb01c13daf5587a12fd68731ceb /vnet
parent6d5bfb69f15653bc7032e9a8ffe4b0cecba9971c (diff)
VPP-262: Coding standards cleanup vnet/vnet/llc
Change-Id: I15d71ecf9e8ed37a52cbbd45cdc0fc4ee87c0e5f Signed-off-by: Calvin Ference <cference@inocybe.ca>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/llc/llc.c92
-rw-r--r--vnet/vnet/llc/llc.h45
-rw-r--r--vnet/vnet/llc/node.c87
-rw-r--r--vnet/vnet/llc/pg.c33
4 files changed, 154 insertions, 103 deletions
diff --git a/vnet/vnet/llc/llc.c b/vnet/vnet/llc/llc.c
index b6827d0f..0496e8d4 100644
--- a/vnet/vnet/llc/llc.c
+++ b/vnet/vnet/llc/llc.c
@@ -43,11 +43,12 @@
/* Global main structure. */
llc_main_t llc_main;
-u8 * format_llc_protocol (u8 * s, va_list * args)
+u8 *
+format_llc_protocol (u8 * s, va_list * args)
{
llc_protocol_t p = va_arg (*args, u32);
- llc_main_t * pm = &llc_main;
- llc_protocol_info_t * pi = llc_get_protocol_info (pm, p);
+ llc_main_t *pm = &llc_main;
+ llc_protocol_info_t *pi = llc_get_protocol_info (pm, p);
if (pi)
s = format (s, "%s", pi->name);
@@ -57,10 +58,11 @@ u8 * format_llc_protocol (u8 * s, va_list * args)
return s;
}
-u8 * format_llc_header_with_length (u8 * s, va_list * args)
+u8 *
+format_llc_header_with_length (u8 * s, va_list * args)
{
- llc_main_t * pm = &llc_main;
- llc_header_t * h = va_arg (*args, llc_header_t *);
+ llc_main_t *pm = &llc_main;
+ llc_header_t *h = va_arg (*args, llc_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
llc_protocol_t p = h->dst_sap;
uword indent, header_bytes;
@@ -80,8 +82,8 @@ u8 * format_llc_header_with_length (u8 * s, va_list * args)
if (max_header_bytes != 0 && header_bytes > max_header_bytes)
{
- llc_protocol_info_t * pi = llc_get_protocol_info (pm, p);
- vlib_node_t * node = vlib_get_node (pm->vlib_main, pi->node_index);
+ llc_protocol_info_t *pi = llc_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_llc_header_with_length (u8 * s, va_list * args)
return s;
}
-u8 * format_llc_header (u8 * s, va_list * args)
+u8 *
+format_llc_header (u8 * s, va_list * args)
{
- llc_header_t * h = va_arg (*args, llc_header_t *);
+ llc_header_t *h = va_arg (*args, llc_header_t *);
return format (s, "%U", format_llc_header_with_length, h, 0);
}
@@ -102,13 +105,12 @@ u8 * format_llc_header (u8 * s, va_list * args)
uword
unformat_llc_protocol (unformat_input_t * input, va_list * args)
{
- u8 * result = va_arg (*args, u8 *);
- llc_main_t * pm = &llc_main;
+ u8 *result = va_arg (*args, u8 *);
+ llc_main_t *pm = &llc_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 << 8))
return 0;
@@ -120,7 +122,7 @@ unformat_llc_protocol (unformat_input_t * input, va_list * args)
if (unformat_user (input, unformat_vlib_number_by_name,
pm->protocol_info_by_name, &i))
{
- llc_protocol_info_t * pi = vec_elt_at_index (pm->protocol_infos, i);
+ llc_protocol_info_t *pi = vec_elt_at_index (pm->protocol_infos, i);
*result = pi->protocol;
return 1;
}
@@ -131,11 +133,11 @@ unformat_llc_protocol (unformat_input_t * input, va_list * args)
uword
unformat_llc_header (unformat_input_t * input, va_list * args)
{
- u8 ** result = va_arg (*args, u8 **);
- llc_header_t _h, * h = &_h;
+ u8 **result = va_arg (*args, u8 **);
+ llc_header_t _h, *h = &_h;
u8 p;
- if (! unformat (input, "%U", unformat_llc_protocol, &p))
+ if (!unformat (input, "%U", unformat_llc_protocol, &p))
return 0;
h->src_sap = h->dst_sap = p;
@@ -143,55 +145,56 @@ unformat_llc_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 llc_set_rewrite (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 l3_type,
- void * dst_address,
- void * rewrite,
- uword max_rewrite_bytes)
+static uword
+llc_set_rewrite (vnet_main_t * vnm,
+ u32 sw_if_index,
+ u32 l3_type,
+ void *dst_address, void *rewrite, uword max_rewrite_bytes)
{
- llc_header_t * h = rewrite;
+ llc_header_t *h = rewrite;
llc_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 = LLC_PROTOCOL_##b; break
- _ (IP4, ip4);
+ _(IP4, ip4);
#undef _
- default:
- return 0;
- }
+ default:
+ return 0;
+ }
h->src_sap = h->dst_sap = protocol;
h->control = 0x3;
-
+
return sizeof (h[0]);
}
+/* *INDENT-OFF* */
VNET_HW_INTERFACE_CLASS (llc_hw_interface_class) = {
.name = "LLC",
.format_header = format_llc_header_with_length,
.unformat_header = unformat_llc_header,
.set_rewrite = llc_set_rewrite,
};
+/* *INDENT-ON* */
-static void add_protocol (llc_main_t * pm,
- llc_protocol_t protocol,
- char * protocol_name)
+static void
+add_protocol (llc_main_t * pm, llc_protocol_t protocol, char *protocol_name)
{
- llc_protocol_info_t * pi;
+ llc_protocol_info_t *pi;
u32 i;
vec_add2 (pm->protocol_infos, pi, 1);
@@ -205,10 +208,11 @@ static void add_protocol (llc_main_t * pm,
hash_set_mem (pm->protocol_info_by_name, pi->name, i);
}
-static clib_error_t * llc_init (vlib_main_t * vm)
+static clib_error_t *
+llc_init (vlib_main_t * vm)
{
- clib_error_t * error;
- llc_main_t * pm = &llc_main;
+ clib_error_t *error;
+ llc_main_t *pm = &llc_main;
memset (pm, 0, sizeof (pm[0]));
pm->vlib_main = vm;
@@ -228,3 +232,11 @@ static clib_error_t * llc_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (llc_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/llc/llc.h b/vnet/vnet/llc/llc.h
index 80131be5..0b85f5d8 100644
--- a/vnet/vnet/llc/llc.h
+++ b/vnet/vnet/llc/llc.h
@@ -68,13 +68,15 @@
_ (netbios, 0xf0) \
_ (global_dsap, 0xff)
-typedef enum {
+typedef enum
+{
#define _(f,n) LLC_PROTOCOL_##f = n,
foreach_llc_protocol
#undef _
} llc_protocol_t;
-typedef struct {
+typedef struct
+{
#define LLC_DST_SAP_IS_GROUP (1 << 0)
#define LLC_SRC_SAP_IS_RESPONSE (1 << 0)
u8 dst_sap, src_sap;
@@ -101,9 +103,10 @@ llc_header_length (llc_header_t * h)
return ((h->control & 3) != 3 ? 4 : 3);
}
-typedef struct {
+typedef struct
+{
/* Name (a c string). */
- char * name;
+ char *name;
/* LLC protocol (SAP type). */
llc_protocol_t protocol;
@@ -120,20 +123,22 @@ typedef struct {
_ (UNKNOWN_PROTOCOL, "unknown llc ssap/dsap") \
_ (UNKNOWN_CONTROL, "control != 0x3")
-typedef enum {
+typedef enum
+{
#define _(f,s) LLC_ERROR_##f,
foreach_llc_error
#undef _
- LLC_N_ERROR,
+ LLC_N_ERROR,
} llc_error_t;
-typedef struct {
- vlib_main_t * vlib_main;
+typedef struct
+{
+ vlib_main_t *vlib_main;
- llc_protocol_info_t * protocol_infos;
+ llc_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;
/* llc-input next index indexed by protocol. */
u8 input_next_by_protocol[256];
@@ -142,7 +147,7 @@ typedef struct {
always_inline llc_protocol_info_t *
llc_get_protocol_info (llc_main_t * m, llc_protocol_t protocol)
{
- uword * p = hash_get (m->protocol_info_by_protocol, protocol);
+ uword *p = hash_get (m->protocol_info_by_protocol, protocol);
return p ? vec_elt_at_index (m->protocol_infos, p[0]) : 0;
}
@@ -151,12 +156,10 @@ extern llc_main_t llc_main;
/* Register given node index to take input for given llc type. */
void
llc_register_input_protocol (vlib_main_t * vm,
- llc_protocol_t protocol,
- u32 node_index);
+ llc_protocol_t protocol, u32 node_index);
void llc_set_adjacency (vnet_rewrite_header_t * rw,
- uword max_data_bytes,
- llc_protocol_t protocol);
+ uword max_data_bytes, llc_protocol_t protocol);
format_function_t format_llc_protocol;
format_function_t format_llc_header;
@@ -172,8 +175,8 @@ unformat_function_t unformat_pg_llc_header;
always_inline void
llc_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_llc_header_with_length;
n->unformat_buffer = unformat_llc_header;
@@ -181,3 +184,11 @@ llc_setup_node (vlib_main_t * vm, u32 node_index)
}
#endif /* included_llc_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/llc/node.c b/vnet/vnet/llc/node.c
index 1c186feb..60b5c134 100644
--- a/vnet/vnet/llc/node.c
+++ b/vnet/vnet/llc/node.c
@@ -45,22 +45,25 @@
_ (PUNT, "error-punt") \
_ (DROP, "error-drop")
-typedef enum {
+typedef enum
+{
#define _(s,n) LLC_INPUT_NEXT_##s,
foreach_llc_input_next
#undef _
- LLC_INPUT_N_NEXT,
+ LLC_INPUT_N_NEXT,
} llc_input_next_t;
-typedef struct {
+typedef struct
+{
u8 packet_data[32];
} llc_input_trace_t;
-static u8 * format_llc_input_trace (u8 * s, va_list * va)
+static u8 *
+format_llc_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 *);
- llc_input_trace_t * t = va_arg (*va, llc_input_trace_t *);
+ llc_input_trace_t *t = va_arg (*va, llc_input_trace_t *);
s = format (s, "%U", format_llc_header, t->packet_data);
@@ -69,11 +72,10 @@ static u8 * format_llc_input_trace (u8 * s, va_list * va)
static uword
llc_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)
{
- llc_main_t * lm = &llc_main;
- u32 n_left_from, next_index, * from, * to_next;
+ llc_main_t *lm = &llc_main;
+ u32 n_left_from, next_index, *from, *to_next;
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
@@ -91,19 +93,18 @@ llc_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;
- llc_header_t * h0, * h1;
+ vlib_buffer_t *b0, *b1;
+ llc_header_t *h0, *h1;
u8 next0, next1, len0, len1, enqueue_code;
/* Prefetch next iteration. */
{
- vlib_buffer_t * b2, * b3;
+ vlib_buffer_t *b2, *b3;
b2 = vlib_get_buffer (vm, from[2]);
b3 = vlib_get_buffer (vm, from[3]);
@@ -142,10 +143,16 @@ llc_input (vlib_main_t * vm,
next0 = lm->input_next_by_protocol[h0->dst_sap];
next1 = lm->input_next_by_protocol[h1->dst_sap];
- b0->error = node->errors[next0 == LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL : LLC_ERROR_NONE];
- b1->error = node->errors[next1 == LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL : LLC_ERROR_NONE];
+ b0->error =
+ node->errors[next0 ==
+ LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL :
+ LLC_ERROR_NONE];
+ b1->error =
+ node->errors[next1 ==
+ LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL :
+ LLC_ERROR_NONE];
- enqueue_code = (next0 != next_index) + 2*(next1 != next_index);
+ enqueue_code = (next0 != next_index) + 2 * (next1 != next_index);
if (PREDICT_FALSE (enqueue_code != 0))
{
@@ -177,17 +184,18 @@ llc_input (vlib_main_t * vm,
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);
}
}
}
}
-
+
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
- vlib_buffer_t * b0;
- llc_header_t * h0;
+ vlib_buffer_t *b0;
+ llc_header_t *h0;
u8 next0, len0;
bi0 = from[0];
@@ -209,7 +217,10 @@ llc_input (vlib_main_t * vm,
next0 = lm->input_next_by_protocol[h0->dst_sap];
- b0->error = node->errors[next0 == LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL : LLC_ERROR_NONE];
+ b0->error =
+ node->errors[next0 ==
+ LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL :
+ LLC_ERROR_NONE];
/* Sent packet to wrong next? */
if (PREDICT_FALSE (next0 != next_index))
@@ -234,12 +245,13 @@ llc_input (vlib_main_t * vm,
return from_frame->n_vectors;
}
-static char * llc_error_strings[] = {
+static char *llc_error_strings[] = {
#define _(f,s) s,
foreach_llc_error
#undef _
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (llc_input_node) = {
.function = llc_input,
.name = "llc-input",
@@ -260,13 +272,15 @@ VLIB_REGISTER_NODE (llc_input_node) = {
.format_trace = format_llc_input_trace,
.unformat_buffer = unformat_llc_header,
};
+/* *INDENT-ON* */
-static clib_error_t * llc_input_init (vlib_main_t * vm)
+static clib_error_t *
+llc_input_init (vlib_main_t * vm)
{
- llc_main_t * lm = &llc_main;
+ llc_main_t *lm = &llc_main;
{
- clib_error_t * error = vlib_call_init_function (vm, llc_init);
+ clib_error_t *error = vlib_call_init_function (vm, llc_init);
if (error)
clib_error_report (error);
}
@@ -286,14 +300,13 @@ VLIB_INIT_FUNCTION (llc_input_init);
void
llc_register_input_protocol (vlib_main_t * vm,
- llc_protocol_t protocol,
- u32 node_index)
+ llc_protocol_t protocol, u32 node_index)
{
- llc_main_t * lm = &llc_main;
- llc_protocol_info_t * pi;
+ llc_main_t *lm = &llc_main;
+ llc_protocol_info_t *pi;
{
- clib_error_t * error = vlib_call_init_function (vm, llc_input_init);
+ clib_error_t *error = vlib_call_init_function (vm, llc_input_init);
if (error)
clib_error_report (error);
/* Otherwise, osi_input_init will wipe out e.g. the snap init */
@@ -304,9 +317,15 @@ llc_register_input_protocol (vlib_main_t * vm,
pi = llc_get_protocol_info (lm, protocol);
pi->node_index = node_index;
- pi->next_index = vlib_node_add_next (vm,
- llc_input_node.index,
- node_index);
+ pi->next_index = vlib_node_add_next (vm, llc_input_node.index, node_index);
lm->input_next_by_protocol[protocol] = pi->next_index;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/llc/pg.c b/vnet/vnet/llc/pg.c
index eb6c6a18..ad18a4b0 100644
--- a/vnet/vnet/llc/pg.c
+++ b/vnet/vnet/llc/pg.c
@@ -41,7 +41,8 @@
#include <vnet/pg/pg.h>
#include <vnet/llc/llc.h>
-typedef struct {
+typedef struct
+{
pg_edit_t dst_sap;
pg_edit_t src_sap;
pg_edit_t control;
@@ -58,10 +59,10 @@ pg_llc_header_init (pg_llc_header_t * e)
uword
unformat_pg_llc_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_llc_header_t * h;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_llc_header_t *h;
u32 group_index, error;
-
+
h = pg_create_edit_group (s, sizeof (h[0]), sizeof (llc_header_t),
&group_index);
pg_llc_header_init (h);
@@ -69,15 +70,15 @@ unformat_pg_llc_header (unformat_input_t * input, va_list * args)
pg_edit_set_fixed (&h->control, 0x03);
error = 1;
- if (! unformat (input, "%U -> %U",
- unformat_pg_edit,
- unformat_llc_protocol, &h->src_sap, &h->dst_sap))
+ if (!unformat (input, "%U -> %U",
+ unformat_pg_edit,
+ unformat_llc_protocol, &h->src_sap, &h->dst_sap))
goto done;
{
- llc_main_t * pm = &llc_main;
- llc_protocol_info_t * pi = 0;
- pg_node_t * pg_node = 0;
+ llc_main_t *pm = &llc_main;
+ llc_protocol_info_t *pi = 0;
+ pg_node_t *pg_node = 0;
if (h->dst_sap.type == PG_EDIT_FIXED)
{
@@ -91,14 +92,22 @@ unformat_pg_llc_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:
+ */