summaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorKeith Burns (alagalah) <alagalah@gmail.com>2016-08-15 18:33:19 -0700
committerKeith Burns (alagalah) <alagalah@gmail.com>2016-08-15 20:23:10 -0700
commite70dcc8676b6b2db74989e43f116bbb200239bf8 (patch)
tree4a582b7d9b2247111dfbc5d4179e3fc6e154f32f /vnet
parent81b52c5506ad3ded98dc82fbe4603eec7ad72b8a (diff)
VPP251 - Code style vnet/vnet/ethernet
Change-Id: I3e51ca70a8e1ac7f6584bc5b0271ee4daacc1084 Signed-off-by: Keith Burns (alagalah) <alagalah@gmail.com>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/ethernet/arp.c1715
-rw-r--r--vnet/vnet/ethernet/arp_packet.h30
-rw-r--r--vnet/vnet/ethernet/ethernet.h274
-rw-r--r--vnet/vnet/ethernet/format.c120
-rw-r--r--vnet/vnet/ethernet/init.c27
-rw-r--r--vnet/vnet/ethernet/interface.c357
-rw-r--r--vnet/vnet/ethernet/mac_swap.c415
-rw-r--r--vnet/vnet/ethernet/node.c1322
-rw-r--r--vnet/vnet/ethernet/packet.h32
-rw-r--r--vnet/vnet/ethernet/pg.c72
10 files changed, 2330 insertions, 2034 deletions
diff --git a/vnet/vnet/ethernet/arp.c b/vnet/vnet/ethernet/arp.c
index 68642d1798d..1346d605ea8 100644
--- a/vnet/vnet/ethernet/arp.c
+++ b/vnet/vnet/ethernet/arp.c
@@ -23,13 +23,15 @@
void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
-typedef struct {
+typedef struct
+{
u32 sw_if_index;
u32 fib_index;
ip4_address_t ip4_address;
} ethernet_arp_ip4_key_t;
-typedef struct {
+typedef struct
+{
ethernet_arp_ip4_key_t key;
u8 ethernet_address[6];
@@ -39,55 +41,59 @@ typedef struct {
u64 cpu_time_last_updated;
- u32 * adjacencies;
+ u32 *adjacencies;
} ethernet_arp_ip4_entry_t;
-typedef struct {
+typedef struct
+{
u32 lo_addr;
u32 hi_addr;
u32 fib_index;
} ethernet_proxy_arp_t;
-typedef struct {
+typedef struct
+{
u32 next_index;
uword node_index;
uword type_opaque;
uword data;
/* Used for arp 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 */
- uword * pending_resolutions_by_address;
- pending_resolution_t * pending_resolutions;
+ uword *pending_resolutions_by_address;
+ pending_resolution_t *pending_resolutions;
/* Mac address change notification */
- uword * mac_changes_by_address;
- pending_resolution_t * mac_changes;
+ uword *mac_changes_by_address;
+ pending_resolution_t *mac_changes;
- ethernet_arp_ip4_entry_t * ip4_entry_pool;
+ ethernet_arp_ip4_entry_t *ip4_entry_pool;
mhash_t ip4_entry_by_key;
-
+
/* ARP attack mitigation */
u32 arp_delete_rotor;
u32 limit_arp_cache_size;
/* Proxy arp vector */
- ethernet_proxy_arp_t * proxy_arps;
+ ethernet_proxy_arp_t *proxy_arps;
} ethernet_arp_main_t;
static ethernet_arp_main_t ethernet_arp_main;
-static u8 * format_ethernet_arp_hardware_type (u8 * s, va_list * va)
+static u8 *
+format_ethernet_arp_hardware_type (u8 * s, va_list * va)
{
ethernet_arp_hardware_type_t h = va_arg (*va, ethernet_arp_hardware_type_t);
- char * t = 0;
+ char *t = 0;
switch (h)
{
#define _(n,f) case n: t = #f; break;
@@ -101,10 +107,11 @@ static u8 * format_ethernet_arp_hardware_type (u8 * s, va_list * va)
return format (s, "%s", t);
}
-static u8 * format_ethernet_arp_opcode (u8 * s, va_list * va)
+static u8 *
+format_ethernet_arp_opcode (u8 * s, va_list * va)
{
ethernet_arp_opcode_t o = va_arg (*va, ethernet_arp_opcode_t);
- char * t = 0;
+ char *t = 0;
switch (o)
{
#define _(f) case ETHERNET_ARP_OPCODE_##f: t = #f; break;
@@ -122,13 +129,12 @@ static uword
unformat_ethernet_arp_opcode_host_byte_order (unformat_input_t * input,
va_list * args)
{
- int * result = va_arg (*args, int *);
- ethernet_arp_main_t * am = &ethernet_arp_main;
+ int *result = va_arg (*args, int *);
+ ethernet_arp_main_t *am = &ethernet_arp_main;
int x, i;
/* Numeric opcode. */
- if (unformat (input, "0x%x", &x)
- || unformat (input, "%d", &x))
+ if (unformat (input, "0x%x", &x) || unformat (input, "%d", &x))
{
if (x >= (1 << 16))
return 0;
@@ -151,17 +157,19 @@ static uword
unformat_ethernet_arp_opcode_net_byte_order (unformat_input_t * input,
va_list * args)
{
- int * result = va_arg (*args, int *);
- if (! unformat_user (input, unformat_ethernet_arp_opcode_host_byte_order, result))
+ int *result = va_arg (*args, int *);
+ if (!unformat_user
+ (input, unformat_ethernet_arp_opcode_host_byte_order, result))
return 0;
- *result = clib_host_to_net_u16 ((u16) *result);
+ *result = clib_host_to_net_u16 ((u16) * result);
return 1;
}
-static u8 * format_ethernet_arp_header (u8 * s, va_list * va)
+static u8 *
+format_ethernet_arp_header (u8 * s, va_list * va)
{
- ethernet_arp_header_t * a = va_arg (*va, ethernet_arp_header_t *);
+ ethernet_arp_header_t *a = va_arg (*va, ethernet_arp_header_t *);
u32 max_header_bytes = va_arg (*va, u32);
uword indent;
u16 l2_type, l3_type;
@@ -179,7 +187,7 @@ static u8 * format_ethernet_arp_header (u8 * s, va_list * va)
format_ethernet_arp_hardware_type, l2_type,
format_ethernet_type, l3_type,
a->n_l2_address_bytes, a->n_l3_address_bytes);
-
+
if (l2_type == ETHERNET_ARP_HARDWARE_TYPE_ethernet
&& l3_type == ETHERNET_TYPE_IP4)
{
@@ -196,58 +204,61 @@ static u8 * format_ethernet_arp_header (u8 * s, va_list * va)
uword n3 = a->n_l3_address_bytes;
s = format (s, "\n%U%U/%U -> %U/%U",
format_white_space, indent,
- format_hex_bytes, a->data + 0*n2 + 0*n3, n2,
- format_hex_bytes, a->data + 1*n2 + 0*n3, n3,
- format_hex_bytes, a->data + 1*n2 + 1*n3, n2,
- format_hex_bytes, a->data + 2*n2 + 1*n3, n3);
+ format_hex_bytes, a->data + 0 * n2 + 0 * n3, n2,
+ format_hex_bytes, a->data + 1 * n2 + 0 * n3, n3,
+ format_hex_bytes, a->data + 1 * n2 + 1 * n3, n2,
+ format_hex_bytes, a->data + 2 * n2 + 1 * n3, n3);
}
return s;
}
-static u8 * format_ethernet_arp_ip4_entry (u8 * s, va_list * va)
+static u8 *
+format_ethernet_arp_ip4_entry (u8 * s, va_list * va)
{
- vnet_main_t * vnm = va_arg (*va, vnet_main_t *);
- ethernet_arp_ip4_entry_t * e = va_arg (*va, ethernet_arp_ip4_entry_t *);
- vnet_sw_interface_t * si;
- ip4_fib_t * fib;
- u8 * flags = 0;
+ vnet_main_t *vnm = va_arg (*va, vnet_main_t *);
+ ethernet_arp_ip4_entry_t *e = va_arg (*va, ethernet_arp_ip4_entry_t *);
+ vnet_sw_interface_t *si;
+ ip4_fib_t *fib;
+ u8 *flags = 0;
- if (! e)
+ if (!e)
return format (s, "%=12s%=6s%=16s%=6s%=20s%=24s", "Time", "FIB", "IP4",
- "Flags", "Ethernet", "Interface");
+ "Flags", "Ethernet", "Interface");
fib = find_ip4_fib_by_table_index_or_id (&ip4_main, e->key.fib_index,
- IP4_ROUTE_FLAG_FIB_INDEX);
+ IP4_ROUTE_FLAG_FIB_INDEX);
si = vnet_get_sw_interface (vnm, e->key.sw_if_index);
if (e->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_GLEAN)
- flags = format(flags, "G");
+ flags = format (flags, "G");
if (e->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC)
- flags = format(flags, "S");
+ flags = format (flags, "S");
s = format (s, "%=12U%=6u%=16U%=6s%=20U%=24U",
format_vlib_cpu_time, vnm->vlib_main, e->cpu_time_last_updated,
- fib->table_id,
+ fib->table_id,
format_ip4_address, &e->key.ip4_address,
flags ? (char *) flags : "",
format_ethernet_address, e->ethernet_address,
format_vnet_sw_interface_name, vnm, si);
- vec_free(flags);
+ vec_free (flags);
return s;
}
-typedef struct {
+typedef struct
+{
u8 packet_data[64];
} ethernet_arp_input_trace_t;
-static u8 * format_ethernet_arp_input_trace (u8 * s, va_list * va)
+static u8 *
+format_ethernet_arp_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 *);
- ethernet_arp_input_trace_t * t = va_arg (*va, ethernet_arp_input_trace_t *);
+ ethernet_arp_input_trace_t *t = va_arg (*va, ethernet_arp_input_trace_t *);
s = format (s, "%U",
format_ethernet_arp_header,
@@ -258,18 +269,19 @@ static u8 * format_ethernet_arp_input_trace (u8 * s, va_list * va)
clib_error_t *
ethernet_arp_sw_interface_up_down (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 flags)
+ u32 sw_if_index, u32 flags)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ethernet_arp_ip4_entry_t * e;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ethernet_arp_ip4_entry_t *e;
u32 i;
- u32 * to_add_del = 0;
+ u32 *to_add_del = 0;
- pool_foreach (e, am->ip4_entry_pool, ({
+ /* *INDENT-OFF* */
+ pool_foreach (e, am->ip4_entry_pool, ({
if (e->key.sw_if_index == sw_if_index)
vec_add1 (to_add_del, e - am->ip4_entry_pool);
}));
+ /* *INDENT-ON* */
for (i = 0; i < vec_len (to_add_del); i++)
{
@@ -280,16 +292,19 @@ ethernet_arp_sw_interface_up_down (vnet_main_t * vnm,
arp_add.ip4.as_u32 = e->key.ip4_address.as_u32;
if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
- {
+ {
vnet_arp_set_ip4_over_ethernet (vnm,
- e->key.sw_if_index, e->key.fib_index, &arp_add,
- e->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC);
- }
+ e->key.sw_if_index,
+ e->key.fib_index, &arp_add,
+ e->flags &
+ ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC);
+ }
else if ((e->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) == 0)
- {
+ {
vnet_arp_unset_ip4_over_ethernet (vnm,
- e->key.sw_if_index, e->key.fib_index, &arp_add);
- }
+ e->key.sw_if_index,
+ e->key.fib_index, &arp_add);
+ }
}
vec_free (to_add_del);
@@ -302,50 +317,45 @@ static int
vnet_arp_set_ip4_over_ethernet_internal (vnet_main_t * vnm,
u32 sw_if_index,
u32 fib_index,
- void * a_arg,
- int is_static);
+ void *a_arg, int is_static);
static int
vnet_arp_unset_ip4_over_ethernet_internal (vnet_main_t * vnm,
u32 sw_if_index,
- u32 fib_index,
- void * a_arg);
+ u32 fib_index, void *a_arg);
-typedef struct {
+typedef struct
+{
u32 sw_if_index;
u32 fib_index;
ethernet_arp_ip4_over_ethernet_address_t a;
int is_static;
- int is_remove; /* set is_remove=1 to clear arp entry */
+ int is_remove; /* set is_remove=1 to clear arp entry */
} vnet_arp_set_ip4_over_ethernet_rpc_args_t;
-static void set_ip4_over_ethernet_rpc_callback
-( vnet_arp_set_ip4_over_ethernet_rpc_args_t * a)
+static void set_ip4_over_ethernet_rpc_callback
+ (vnet_arp_set_ip4_over_ethernet_rpc_args_t * a)
{
- vnet_main_t * vm = vnet_get_main();
- ASSERT(os_get_cpu_number() == 0);
+ vnet_main_t *vm = vnet_get_main ();
+ ASSERT (os_get_cpu_number () == 0);
if (a->is_remove)
- vnet_arp_unset_ip4_over_ethernet_internal(vm,
- a->sw_if_index,
- a->fib_index,
- &(a->a));
+ vnet_arp_unset_ip4_over_ethernet_internal (vm,
+ a->sw_if_index,
+ a->fib_index, &(a->a));
else
vnet_arp_set_ip4_over_ethernet_internal (vm,
a->sw_if_index,
a->fib_index,
- &(a->a),
- a->is_static);
+ &(a->a), a->is_static);
}
int
vnet_arp_set_ip4_over_ethernet (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 fib_index,
- void * a_arg,
- int is_static)
+ u32 sw_if_index,
+ u32 fib_index, void *a_arg, int is_static)
{
- ethernet_arp_ip4_over_ethernet_address_t * a = a_arg;
+ ethernet_arp_ip4_over_ethernet_address_t *a = a_arg;
vnet_arp_set_ip4_over_ethernet_rpc_args_t args;
args.sw_if_index = sw_if_index;
@@ -354,8 +364,8 @@ vnet_arp_set_ip4_over_ethernet (vnet_main_t * vnm,
args.is_remove = 0;
clib_memcpy (&args.a, a, sizeof (*a));
- vl_api_rpc_call_main_thread (set_ip4_over_ethernet_rpc_callback,
- (u8 *) &args, sizeof (args));
+ vl_api_rpc_call_main_thread (set_ip4_over_ethernet_rpc_callback,
+ (u8 *) & args, sizeof (args));
return 0;
}
@@ -363,26 +373,25 @@ int
vnet_arp_set_ip4_over_ethernet_internal (vnet_main_t * vnm,
u32 sw_if_index,
u32 fib_index,
- void * a_arg,
- int is_static)
+ void *a_arg, int is_static)
{
ethernet_arp_ip4_key_t k;
- ethernet_arp_ip4_entry_t * e = 0;
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ethernet_arp_ip4_over_ethernet_address_t * a = a_arg;
- vlib_main_t * vm = vlib_get_main();
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- int make_new_arp_cache_entry=1;
- uword * p;
+ ethernet_arp_ip4_entry_t *e = 0;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ethernet_arp_ip4_over_ethernet_address_t *a = a_arg;
+ vlib_main_t *vm = vlib_get_main ();
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ int make_new_arp_cache_entry = 1;
+ uword *p;
ip4_add_del_route_args_t args;
- ip_adjacency_t adj, * existing_adj;
- pending_resolution_t * pr, * mc;
-
+ ip_adjacency_t adj, *existing_adj;
+ pending_resolution_t *pr, *mc;
+
u32 next_index;
u32 adj_index;
- fib_index = (fib_index != (u32)~0)
+ fib_index = (fib_index != (u32) ~ 0)
? fib_index : im->fib_index_by_sw_if_index[sw_if_index];
k.sw_if_index = sw_if_index;
@@ -395,46 +404,40 @@ vnet_arp_set_ip4_over_ethernet_internal (vnet_main_t * vnm,
e = pool_elt_at_index (am->ip4_entry_pool, p[0]);
/* Refuse to over-write static arp. */
- if (!is_static &&
- (e->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC))
+ if (!is_static && (e->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC))
return -2;
make_new_arp_cache_entry = 0;
}
/* Note: always install the route. It might have been deleted */
- memset(&adj, 0, sizeof(adj));
+ memset (&adj, 0, sizeof (adj));
adj.lookup_next_index = IP_LOOKUP_NEXT_REWRITE;
- adj.n_adj = 1; /* otherwise signature compare fails */
+ adj.n_adj = 1; /* otherwise signature compare fails */
- vnet_rewrite_for_sw_interface
- (vnm,
- VNET_L3_PACKET_TYPE_IP4,
- sw_if_index,
- ip4_rewrite_node.index,
- a->ethernet, /* destination address */
- &adj.rewrite_header,
- sizeof (adj.rewrite_data));
+ vnet_rewrite_for_sw_interface (vnm, VNET_L3_PACKET_TYPE_IP4, sw_if_index, ip4_rewrite_node.index, a->ethernet, /* destination address */
+ &adj.rewrite_header,
+ sizeof (adj.rewrite_data));
/* result of this lookup should be next-hop adjacency */
adj_index = ip4_fib_lookup_with_table (im, fib_index, &a->ip4, 0);
- existing_adj = ip_get_adjacency(lm, adj_index);
+ existing_adj = ip_get_adjacency (lm, adj_index);
if (existing_adj->lookup_next_index == IP_LOOKUP_NEXT_ARP &&
existing_adj->arp.next_hop.ip4.as_u32 == a->ip4.as_u32)
{
- u32 * ai;
- u32 * adjs = vec_dup(e->adjacencies);
+ u32 *ai;
+ u32 *adjs = vec_dup (e->adjacencies);
/* Update all adj assigned to this arp entry */
- vec_foreach(ai, adjs)
- {
- int i;
- ip_adjacency_t * uadj = ip_get_adjacency(lm, *ai);
- for (i = 0; i < uadj->n_adj; i++)
- if (uadj[i].lookup_next_index == IP_LOOKUP_NEXT_ARP &&
- uadj[i].arp.next_hop.ip4.as_u32 == a->ip4.as_u32)
- ip_update_adjacency (lm, *ai + i, &adj);
- }
- vec_free(adjs);
+ vec_foreach (ai, adjs)
+ {
+ int i;
+ ip_adjacency_t *uadj = ip_get_adjacency (lm, *ai);
+ for (i = 0; i < uadj->n_adj; i++)
+ if (uadj[i].lookup_next_index == IP_LOOKUP_NEXT_ARP &&
+ uadj[i].arp.next_hop.ip4.as_u32 == a->ip4.as_u32)
+ ip_update_adjacency (lm, *ai + i, &adj);
+ }
+ vec_free (adjs);
}
else
{
@@ -443,30 +446,33 @@ vnet_arp_set_ip4_over_ethernet_internal (vnet_main_t * vnm,
* exactly the same info, its technically a new adjacency with
* new counters, but to user it appears as counters reset.
*/
- if (vnet_ip_adjacency_share_compare (&adj, existing_adj) == 0) {
- /* create new adj */
- args.table_index_or_table_id = fib_index;
- args.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_ADD | IP4_ROUTE_FLAG_NEIGHBOR;
- args.dst_address = a->ip4;
- args.dst_address_length = 32;
- args.adj_index = ~0;
- args.add_adj = &adj;
- args.n_add_adj = 1;
- ip4_add_del_route (im, &args);
- }
+ if (vnet_ip_adjacency_share_compare (&adj, existing_adj) == 0)
+ {
+ /* create new adj */
+ args.table_index_or_table_id = fib_index;
+ args.flags =
+ IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_ADD |
+ IP4_ROUTE_FLAG_NEIGHBOR;
+ args.dst_address = a->ip4;
+ args.dst_address_length = 32;
+ args.adj_index = ~0;
+ args.add_adj = &adj;
+ args.n_add_adj = 1;
+ ip4_add_del_route (im, &args);
+ }
}
if (make_new_arp_cache_entry)
{
pool_get (am->ip4_entry_pool, e);
- mhash_set (&am->ip4_entry_by_key, &k,
- e - am->ip4_entry_pool,
- /* old value */ 0);
+ mhash_set (&am->ip4_entry_by_key, &k, e - am->ip4_entry_pool,
+ /* old value */ 0);
e->key = k;
}
/* Update time stamp and ethernet address. */
- clib_memcpy (e->ethernet_address, a->ethernet, sizeof (e->ethernet_address));
+ clib_memcpy (e->ethernet_address, a->ethernet,
+ sizeof (e->ethernet_address));
e->cpu_time_last_updated = clib_cpu_time_now ();
if (is_static)
e->flags |= ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC;
@@ -477,16 +483,15 @@ vnet_arp_set_ip4_over_ethernet_internal (vnet_main_t * vnm,
{
next_index = p[0];
- while (next_index != (u32)~0)
- {
- pr = pool_elt_at_index (am->pending_resolutions, next_index);
- vlib_process_signal_event (vm, pr->node_index,
- pr->type_opaque,
- pr->data);
- next_index = pr->next_index;
- pool_put (am->pending_resolutions, pr);
- }
-
+ while (next_index != (u32) ~ 0)
+ {
+ pr = pool_elt_at_index (am->pending_resolutions, next_index);
+ vlib_process_signal_event (vm, pr->node_index,
+ pr->type_opaque, pr->data);
+ next_index = pr->next_index;
+ pool_put (am->pending_resolutions, pr);
+ }
+
hash_unset (am->pending_resolutions_by_address, a->ip4.as_u32);
}
@@ -496,43 +501,42 @@ vnet_arp_set_ip4_over_ethernet_internal (vnet_main_t * vnm,
{
next_index = p[0];
- while (next_index != (u32)~0)
- {
- int (*fp)(u32, u8 *, u32, u32);
- int rv = 1;
- mc = pool_elt_at_index (am->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, a->ethernet, sw_if_index, 0);
-
- /*
- * 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, u32);
+ int rv = 1;
+ mc = pool_elt_at_index (am->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, a->ethernet, sw_if_index, 0);
+
+ /*
+ * 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;
}
-void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
- void * address_arg,
- uword node_index,
- uword type_opaque,
- uword data)
+void
+vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
+ void *address_arg,
+ uword node_index,
+ uword type_opaque, uword data)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ip4_address_t * address = address_arg;
- uword * p;
- pending_resolution_t * pr;
-
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ip4_address_t *address = address_arg;
+ uword *p;
+ pending_resolution_t *pr;
+
pool_get (am->pending_resolutions, pr);
pr->next_index = ~0;
@@ -548,25 +552,25 @@ void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
pr->next_index = p[0];
hash_unset (am->pending_resolutions_by_address, address->as_u32);
}
-
- hash_set (am->pending_resolutions_by_address, address->as_u32,
- pr - am->pending_resolutions);
+
+ hash_set (am->pending_resolutions_by_address, address->as_u32,
+ pr - am->pending_resolutions);
}
-int vnet_add_del_ip4_arp_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)
+int
+vnet_add_del_ip4_arp_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)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ip4_address_t * address = address_arg;
- uword * p;
- pending_resolution_t * mc;
- void (*fp)(u32, u8 *) = data_callback;
-
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ip4_address_t *address = address_arg;
+ uword *p;
+ pending_resolution_t *mc;
+ void (*fp) (u32, u8 *) = data_callback;
+
if (is_add)
{
pool_get (am->mac_changes, mc);
@@ -577,67 +581,67 @@ int vnet_add_del_ip4_arp_change_event (vnet_main_t * vnm,
mc->data = data;
mc->data_callback = data_callback;
mc->pid = pid;
-
+
p = hash_get (am->mac_changes_by_address, address->as_u32);
if (p)
- {
- /* Insert new resolution at the head of the list */
- mc->next_index = p[0];
- hash_unset (am->mac_changes_by_address, address->as_u32);
- }
-
- hash_set (am->mac_changes_by_address, address->as_u32,
- mc - am->mac_changes);
+ {
+ /* Insert new resolution at the head of the list */
+ mc->next_index = p[0];
+ hash_unset (am->mac_changes_by_address, address->as_u32);
+ }
+
+ hash_set (am->mac_changes_by_address, address->as_u32,
+ mc - am->mac_changes);
return 0;
}
else
{
u32 index;
- pending_resolution_t * mc_last = 0;
+ pending_resolution_t *mc_last = 0;
p = hash_get (am->mac_changes_by_address, address->as_u32);
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 (am->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])
- {
- hash_unset (am->mac_changes_by_address, address->as_u32);
- if (mc->next_index != ~0)
- hash_set (am->mac_changes_by_address, address->as_u32,
- mc->next_index);
- pool_put (am->mac_changes, mc);
- return 0;
- }
- else
- {
- ASSERT(mc_last);
- mc_last->next_index = mc->next_index;
- pool_put (am->mac_changes, mc);
- return 0;
- }
- }
- mc_last = mc;
- index = mc->next_index;
- }
-
+ while (index != (u32) ~ 0)
+ {
+ mc = pool_elt_at_index (am->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])
+ {
+ hash_unset (am->mac_changes_by_address, address->as_u32);
+ if (mc->next_index != ~0)
+ hash_set (am->mac_changes_by_address, address->as_u32,
+ mc->next_index);
+ pool_put (am->mac_changes, mc);
+ return 0;
+ }
+ else
+ {
+ ASSERT (mc_last);
+ mc_last->next_index = mc->next_index;
+ pool_put (am->mac_changes, mc);
+ return 0;
+ }
+ }
+ mc_last = mc;
+ index = mc->next_index;
+ }
+
return VNET_API_ERROR_NO_SUCH_ENTRY;
}
}
/* Either we drop the packet or we send a reply to the sender. */
-typedef enum {
+typedef enum
+{
ARP_INPUT_NEXT_DROP,
ARP_INPUT_NEXT_REPLY_TX,
ARP_INPUT_N_NEXT,
@@ -658,40 +662,45 @@ typedef enum {
_ (missing_interface_address, "ARP missing interface address") \
_ (gratuitous_arp, "ARP probe or announcement dropped") \
-typedef enum {
+typedef enum
+{
#define _(sym,string) ETHERNET_ARP_ERROR_##sym,
foreach_ethernet_arp_error
#undef _
- ETHERNET_ARP_N_ERROR,
+ ETHERNET_ARP_N_ERROR,
} ethernet_arp_input_error_t;
/* 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 */,
+ /* *INDENT-OFF* */
+ 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;
+ ip4_address_t * a =
+ ip_interface_address_get_address (lm, ia);
+ result = a; break;
}));
+ /* *INDENT-ON* */
+
if (result_ia)
*result_ia = result ? ia : 0;
return result;
}
-static void unset_random_arp_entry (void)
+static void
+unset_random_arp_entry (void)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ethernet_arp_ip4_entry_t * e;
- vnet_main_t * vnm = vnet_get_main();
- ethernet_arp_ip4_over_ethernet_address_t delme;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ethernet_arp_ip4_entry_t *e;
+ vnet_main_t *vnm = vnet_get_main ();
+ ethernet_arp_ip4_over_ethernet_address_t delme;
u32 index;
index = pool_next_index (am->ip4_entry_pool, am->arp_delete_rotor);
@@ -709,140 +718,150 @@ static void unset_random_arp_entry (void)
return;
e = pool_elt_at_index (am->ip4_entry_pool, index);
-
+
clib_memcpy (&delme.ethernet, e->ethernet_address, 6);
delme.ip4.as_u32 = e->key.ip4_address.as_u32;
-
+
vnet_arp_unset_ip4_over_ethernet (vnm, e->key.sw_if_index,
- e->key.fib_index, &delme);
+ e->key.fib_index, &delme);
}
-
-static void arp_unnumbered (vlib_buffer_t * p0,
- u32 pi0,
- ethernet_header_t * eth0,
- ip_interface_address_t * ifa0)
+
+static void
+arp_unnumbered (vlib_buffer_t * p0,
+ u32 pi0,
+ ethernet_header_t * eth0, ip_interface_address_t * ifa0)
{
- vlib_main_t * vm = vlib_get_main();
- vnet_main_t * vnm = vnet_get_main();
- vnet_interface_main_t * vim = &vnm->interface_main;
- vnet_sw_interface_t * si;
- vnet_hw_interface_t * hi;
+ vlib_main_t *vm = vlib_get_main ();
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_interface_main_t *vim = &vnm->interface_main;
+ vnet_sw_interface_t *si;
+ vnet_hw_interface_t *hi;
u32 unnum_src_sw_if_index;
- u32 * broadcast_swifs = 0;
- u32 * buffers = 0;
+ u32 *broadcast_swifs = 0;
+ u32 *buffers = 0;
u32 n_alloc = 0;
- vlib_buffer_t * b0;
+ vlib_buffer_t *b0;
int i;
u8 dst_mac_address[6];
i16 header_size;
- ethernet_arp_header_t * arp0;
+ ethernet_arp_header_t *arp0;
/* Save the dst mac address */
- clib_memcpy(dst_mac_address, eth0->dst_address, sizeof (dst_mac_address));
+ clib_memcpy (dst_mac_address, eth0->dst_address, sizeof (dst_mac_address));
/* Figure out which sw_if_index supplied the address */
unnum_src_sw_if_index = ifa0->sw_if_index;
/* Track down all users of the unnumbered source */
- pool_foreach (si, vim->sw_interfaces,
+ /* *INDENT-OFF* */
+ pool_foreach (si, vim->sw_interfaces,
({
if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED &&
- (si->unnumbered_sw_if_index == unnum_src_sw_if_index))
+ (si->unnumbered_sw_if_index == unnum_src_sw_if_index))
{
- vec_add1 (broadcast_swifs, si->sw_if_index);
+ vec_add1 (broadcast_swifs, si->sw_if_index);
}
}));
-
+ /* *INDENT-ON* */
- ASSERT (vec_len(broadcast_swifs));
+ ASSERT (vec_len (broadcast_swifs));
/* Allocate buffering if we need it */
- if (vec_len(broadcast_swifs) > 1)
+ if (vec_len (broadcast_swifs) > 1)
{
- vec_validate (buffers, vec_len(broadcast_swifs)-2);
- n_alloc = vlib_buffer_alloc (vm, buffers, vec_len(buffers));
+ vec_validate (buffers, vec_len (broadcast_swifs) - 2);
+ n_alloc = vlib_buffer_alloc (vm, buffers, vec_len (buffers));
_vec_len (buffers) = n_alloc;
for (i = 0; i < n_alloc; i++)
- {
- b0 = vlib_get_buffer (vm, buffers[i]);
-
- /* xerox (partially built) ARP pkt */
- clib_memcpy (b0->data, p0->data, p0->current_length + p0->current_data);
- b0->current_data = p0->current_data;
- b0->current_length = p0->current_length;
- vnet_buffer(b0)->sw_if_index[VLIB_RX] =
- vnet_buffer(p0)->sw_if_index[VLIB_RX];
- }
+ {
+ b0 = vlib_get_buffer (vm, buffers[i]);
+
+ /* xerox (partially built) ARP pkt */
+ clib_memcpy (b0->data, p0->data,
+ p0->current_length + p0->current_data);
+ b0->current_data = p0->current_data;
+ b0->current_length = p0->current_length;
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] =
+ vnet_buffer (p0)->sw_if_index[VLIB_RX];
+ }
}
vec_insert (buffers, 1, 0);
buffers[0] = pi0;
-
- for (i = 0; i < vec_len(buffers); i++)
+
+ for (i = 0; i < vec_len (buffers); i++)
{
- b0 = vlib_get_buffer(vm, buffers[i]);
+ b0 = vlib_get_buffer (vm, buffers[i]);
arp0 = vlib_buffer_get_current (b0);
hi = vnet_get_sup_hw_interface (vnm, broadcast_swifs[i]);
si = vnet_get_sw_interface (vnm, broadcast_swifs[i]);
/* For decoration, most likely */
- vnet_buffer(b0)->sw_if_index[VLIB_TX] = hi->sw_if_index;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] = hi->sw_if_index;
/* Fix ARP pkt src address */
clib_memcpy (arp0->ip4_over_ethernet[0].ethernet, hi->hw_address, 6);
/* Build L2 encaps for this swif */
header_size = sizeof (ethernet_header_t);
- if (si->sub.eth.flags.one_tag)
- header_size += 4;
+ if (si->sub.eth.flags.one_tag)
+ header_size += 4;
else if (si->sub.eth.flags.two_tags)
- header_size += 8;
-
+ header_size += 8;
+
vlib_buffer_advance (b0, -header_size);
eth0 = vlib_buffer_get_current (b0);
- if (si->sub.eth.flags.one_tag) {
- ethernet_vlan_header_t * outer = (void *) (eth0 + 1);
-
- eth0->type = si->sub.eth.flags.dot1ad ?
- clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
- clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
- outer->priority_cfi_and_id =
- clib_host_to_net_u16 (si->sub.eth.outer_vlan_id);
- outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_ARP);
-
- } else if (si->sub.eth.flags.two_tags) {
- ethernet_vlan_header_t * outer = (void *) (eth0 + 1);
- ethernet_vlan_header_t * inner = (void *) (outer + 1);
-
- eth0->type = si->sub.eth.flags.dot1ad ?
- clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
- clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
- outer->priority_cfi_and_id =
- clib_host_to_net_u16 (si->sub.eth.outer_vlan_id);
- outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
- inner->priority_cfi_and_id =
- clib_host_to_net_u16 (si->sub.eth.inner_vlan_id);
- inner->type = clib_host_to_net_u16 (ETHERNET_TYPE_ARP);
-
- } else {
- eth0->type = clib_host_to_net_u16 (ETHERNET_TYPE_ARP);
- }
-
+ if (si->sub.eth.flags.one_tag)
+ {
+ ethernet_vlan_header_t *outer = (void *) (eth0 + 1);
+
+ eth0->type = si->sub.eth.flags.dot1ad ?
+ clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
+ clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
+ outer->priority_cfi_and_id =
+ clib_host_to_net_u16 (si->sub.eth.outer_vlan_id);
+ outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_ARP);
+
+ }
+ else if (si->sub.eth.flags.two_tags)
+ {
+ ethernet_vlan_header_t *outer = (void *) (eth0 + 1);
+ ethernet_vlan_header_t *inner = (void *) (outer + 1);
+
+ eth0->type = si->sub.eth.flags.dot1ad ?
+ clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
+ clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
+ outer->priority_cfi_and_id =
+ clib_host_to_net_u16 (si->sub.eth.outer_vlan_id);
+ outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
+ inner->priority_cfi_and_id =
+ clib_host_to_net_u16 (si->sub.eth.inner_vlan_id);
+ inner->type = clib_host_to_net_u16 (ETHERNET_TYPE_ARP);
+
+ }
+ else
+ {
+ eth0->type = clib_host_to_net_u16 (ETHERNET_TYPE_ARP);
+ }
+
/* Restore the original dst address, set src address */
- clib_memcpy (eth0->dst_address, dst_mac_address, sizeof (eth0->dst_address));
- clib_memcpy (eth0->src_address, hi->hw_address, sizeof (eth0->src_address));
-
+ clib_memcpy (eth0->dst_address, dst_mac_address,
+ sizeof (eth0->dst_address));
+ clib_memcpy (eth0->src_address, hi->hw_address,
+ sizeof (eth0->src_address));
+
/* Transmit replicas */
if (i > 0)
- {
- 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] = buffers[i];
- 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] = buffers[i];
+ f->n_vectors = 1;
+ vlib_put_frame_to_node (vm, hi->output_node_index, f);
+ }
}
/* The regular path outputs the original pkt.. */
@@ -853,14 +872,12 @@ static void arp_unnumbered (vlib_buffer_t * p0,
}
static uword
-arp_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+arp_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- vnet_main_t * vnm = vnet_get_main();
- ip4_main_t * im4 = &ip4_main;
- u32 n_left_from, next_index, * from, * to_next;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ ip4_main_t *im4 = &ip4_main;
+ u32 n_left_from, next_index, *from, *to_next;
u32 n_replies_sent = 0, n_proxy_arp_replies_sent = 0;
from = vlib_frame_vector_args (frame);
@@ -876,22 +893,21 @@ arp_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 > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- vnet_hw_interface_t * hw_if0;
- ethernet_arp_header_t * arp0;
- ethernet_header_t * eth0;
- ip_interface_address_t * ifa0;
- ip_adjacency_t * adj0;
- ip4_address_t * if_addr0;
- ip4_address_t proxy_src;
+ vlib_buffer_t *p0;
+ vnet_hw_interface_t *hw_if0;
+ ethernet_arp_header_t *arp0;
+ ethernet_header_t *eth0;
+ ip_interface_address_t *ifa0;
+ ip_adjacency_t *adj0;
+ ip4_address_t *if_addr0;
+ ip4_address_t proxy_src;
u32 pi0, error0, next0, sw_if_index0;
u8 is_request0, src_is_local0, dst_is_local0, is_unnum0;
- ethernet_proxy_arp_t * pa;
+ ethernet_proxy_arp_t *pa;
pi0 = from[0];
to_next[0] = pi0;
@@ -903,17 +919,19 @@ arp_input (vlib_main_t * vm,
p0 = vlib_get_buffer (vm, pi0);
arp0 = vlib_buffer_get_current (p0);
- is_request0 = arp0->opcode
- == clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_request);
+ is_request0 = arp0->opcode
+ == clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_request);
error0 = ETHERNET_ARP_ERROR_replies_sent;
- error0 = (arp0->l2_type != clib_net_to_host_u16 (ETHERNET_ARP_HARDWARE_TYPE_ethernet)
- ? ETHERNET_ARP_ERROR_l2_type_not_ethernet
- : error0);
- error0 = (arp0->l3_type != clib_net_to_host_u16 (ETHERNET_TYPE_IP4)
- ? ETHERNET_ARP_ERROR_l3_type_not_ip4
- : error0);
+ error0 =
+ (arp0->l2_type !=
+ clib_net_to_host_u16 (ETHERNET_ARP_HARDWARE_TYPE_ethernet) ?
+ ETHERNET_ARP_ERROR_l2_type_not_ethernet : error0);
+ error0 =
+ (arp0->l3_type !=
+ clib_net_to_host_u16 (ETHERNET_TYPE_IP4) ?
+ ETHERNET_ARP_ERROR_l3_type_not_ip4 : error0);
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
@@ -921,74 +939,81 @@ arp_input (vlib_main_t * vm,
goto drop1;
/* Check that IP address is local and matches incoming interface. */
- if_addr0 = ip4_interface_address_matching_destination (im4,
- &arp0->ip4_over_ethernet[1].ip4,
- sw_if_index0,
- &ifa0);
- if (! if_addr0)
+ if_addr0 =
+ ip4_interface_address_matching_destination (im4,
+ &arp0->
+ ip4_over_ethernet[1].
+ ip4, sw_if_index0,
+ &ifa0);
+ if (!if_addr0)
{
error0 = ETHERNET_ARP_ERROR_l3_dst_address_not_local;
goto drop1;
}
- /* Honor unnumbered interface, if any */
- is_unnum0 = sw_if_index0 != ifa0->sw_if_index;
+ /* Honor unnumbered interface, if any */
+ is_unnum0 = sw_if_index0 != ifa0->sw_if_index;
/* Source must also be local to subnet of matching interface address. */
- if (! ip4_destination_matches_interface (im4, &arp0->ip4_over_ethernet[0].ip4, ifa0))
+ if (!ip4_destination_matches_interface
+ (im4, &arp0->ip4_over_ethernet[0].ip4, ifa0))
{
error0 = ETHERNET_ARP_ERROR_l3_src_address_not_local;
goto drop1;
}
/* Reject requests/replies with our local interface address. */
- src_is_local0 = if_addr0->as_u32 == arp0->ip4_over_ethernet[0].ip4.as_u32;
+ src_is_local0 =
+ if_addr0->as_u32 == arp0->ip4_over_ethernet[0].ip4.as_u32;
if (src_is_local0)
{
error0 = ETHERNET_ARP_ERROR_l3_src_address_is_local;
goto drop1;
}
- dst_is_local0 = if_addr0->as_u32 == arp0->ip4_over_ethernet[1].ip4.as_u32;
+ dst_is_local0 =
+ if_addr0->as_u32 == arp0->ip4_over_ethernet[1].ip4.as_u32;
/* Fill in ethernet header. */
eth0 = ethernet_buffer_get_header (p0);
- /* Trash ARP packets whose ARP-level source addresses do not
- match their L2-frame-level source addresses */
- if (memcmp (eth0->src_address, arp0->ip4_over_ethernet[0].ethernet,
- sizeof (eth0->src_address)))
- {
- error0 = ETHERNET_ARP_ERROR_l2_address_mismatch;
- goto drop2;
- }
+ /* Trash ARP packets whose ARP-level source addresses do not
+ match their L2-frame-level source addresses */
+ if (memcmp (eth0->src_address, arp0->ip4_over_ethernet[0].ethernet,
+ sizeof (eth0->src_address)))
+ {
+ error0 = ETHERNET_ARP_ERROR_l2_address_mismatch;
+ goto drop2;
+ }
/* Learn or update sender's mapping only for requests or unicasts
that don't match local interface address. */
- if (ethernet_address_cast (eth0->dst_address) == ETHERNET_ADDRESS_UNICAST
- || is_request0)
- {
- if (am->limit_arp_cache_size &&
- pool_elts (am->ip4_entry_pool) >= am->limit_arp_cache_size)
- unset_random_arp_entry();
-
- vnet_arp_set_ip4_over_ethernet (vnm, sw_if_index0,
- (u32)~0 /* default fib */,
- &arp0->ip4_over_ethernet[0],
- 0 /* is_static */);
+ if (ethernet_address_cast (eth0->dst_address) ==
+ ETHERNET_ADDRESS_UNICAST || is_request0)
+ {
+ if (am->limit_arp_cache_size &&
+ pool_elts (am->ip4_entry_pool) >= am->limit_arp_cache_size)
+ unset_random_arp_entry ();
+
+ vnet_arp_set_ip4_over_ethernet (vnm, sw_if_index0,
+ (u32) ~ 0 /* default fib */ ,
+ &arp0->ip4_over_ethernet[0],
+ 0 /* is_static */ );
error0 = ETHERNET_ARP_ERROR_l3_src_address_learned;
- }
+ }
/* Only send a reply for requests sent which match a local interface. */
- if (! (is_request0 && dst_is_local0))
+ if (!(is_request0 && dst_is_local0))
{
- error0 = (arp0->opcode == clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply)
- ? ETHERNET_ARP_ERROR_replies_received : error0);
+ error0 =
+ (arp0->opcode ==
+ clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply) ?
+ ETHERNET_ARP_ERROR_replies_received : error0);
goto drop1;
}
/* Send a reply. */
- send_reply:
+ send_reply:
vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
@@ -1000,8 +1025,10 @@ arp_input (vlib_main_t * vm,
arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0];
- clib_memcpy (arp0->ip4_over_ethernet[0].ethernet, hw_if0->hw_address, 6);
- clib_mem_unaligned (&arp0->ip4_over_ethernet[0].ip4.data_u32, u32) = if_addr0->data_u32;
+ clib_memcpy (arp0->ip4_over_ethernet[0].ethernet,
+ hw_if0->hw_address, 6);
+ clib_mem_unaligned (&arp0->ip4_over_ethernet[0].ip4.data_u32, u32) =
+ if_addr0->data_u32;
/* Hardware must be ethernet-like. */
ASSERT (vec_len (hw_if0->hw_address) == 6);
@@ -1010,151 +1037,150 @@ arp_input (vlib_main_t * vm,
clib_memcpy (eth0->src_address, hw_if0->hw_address, 6);
/* Figure out how much to rewind current data from adjacency. */
- if (ifa0)
- {
- adj0 = ip_get_adjacency (&ip4_main.lookup_main,
- ifa0->neighbor_probe_adj_index);
- if (adj0->lookup_next_index != IP_LOOKUP_NEXT_ARP)
- {
- error0 = ETHERNET_ARP_ERROR_missing_interface_address;
- goto drop2;
- }
- if (is_unnum0)
- arp_unnumbered (p0, pi0, eth0, ifa0);
- else
- vlib_buffer_advance (p0, -adj0->rewrite_header.data_bytes);
- }
-
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,to_next,
- n_left_to_next,pi0,next0);
+ if (ifa0)
+ {
+ adj0 = ip_get_adjacency (&ip4_main.lookup_main,
+ ifa0->neighbor_probe_adj_index);
+ if (adj0->lookup_next_index != IP_LOOKUP_NEXT_ARP)
+ {
+ error0 = ETHERNET_ARP_ERROR_missing_interface_address;
+ goto drop2;
+ }
+ if (is_unnum0)
+ arp_unnumbered (p0, pi0, eth0, ifa0);
+ else
+ vlib_buffer_advance (p0, -adj0->rewrite_header.data_bytes);
+ }
+
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, pi0, next0);
n_replies_sent += 1;
continue;
drop1:
- if (0 == arp0->ip4_over_ethernet[0].ip4.as_u32 ||
- (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
- arp0->ip4_over_ethernet[1].ip4.as_u32))
- {
- error0 = ETHERNET_ARP_ERROR_gratuitous_arp;
- goto drop2;
- }
- /* See if proxy arp is configured for the address */
- if (is_request0)
- {
- vnet_sw_interface_t * si;
- u32 this_addr = clib_net_to_host_u32
- (arp0->ip4_over_ethernet[1].ip4.as_u32);
- u32 fib_index0;
-
- si = vnet_get_sw_interface (vnm, sw_if_index0);
-
- if (!(si->flags & VNET_SW_INTERFACE_FLAG_PROXY_ARP))
- goto drop2;
-
- fib_index0 = vec_elt (im4->fib_index_by_sw_if_index,
- sw_if_index0);
-
- vec_foreach (pa, am->proxy_arps)
- {
- u32 lo_addr = clib_net_to_host_u32 (pa->lo_addr);
- u32 hi_addr = clib_net_to_host_u32 (pa->hi_addr);
-
- /* an ARP request hit in the proxy-arp table? */
- if ((this_addr >= lo_addr && this_addr <= hi_addr) &&
- (fib_index0 == pa->fib_index))
- {
- eth0 = ethernet_buffer_get_header (p0);
- proxy_src.as_u32 =
- arp0->ip4_over_ethernet[1].ip4.data_u32;
-
- /*
- * Rewind buffer, direct code above not to
- * think too hard about it.
- * $$$ is the answer ever anything other than
- * vlib_buffer_reset(..)?
- */
- ifa0 = 0;
- if_addr0 = &proxy_src;
- vlib_buffer_reset (p0);
- n_proxy_arp_replies_sent++;
- goto send_reply;
- }
- }
- }
-
- drop2:
+ if (0 == arp0->ip4_over_ethernet[0].ip4.as_u32 ||
+ (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
+ arp0->ip4_over_ethernet[1].ip4.as_u32))
+ {
+ error0 = ETHERNET_ARP_ERROR_gratuitous_arp;
+ goto drop2;
+ }
+ /* See if proxy arp is configured for the address */
+ if (is_request0)
+ {
+ vnet_sw_interface_t *si;
+ u32 this_addr = clib_net_to_host_u32
+ (arp0->ip4_over_ethernet[1].ip4.as_u32);
+ u32 fib_index0;
+
+ si = vnet_get_sw_interface (vnm, sw_if_index0);
+
+ if (!(si->flags & VNET_SW_INTERFACE_FLAG_PROXY_ARP))
+ goto drop2;
+
+ fib_index0 = vec_elt (im4->fib_index_by_sw_if_index,
+ sw_if_index0);
+
+ vec_foreach (pa, am->proxy_arps)
+ {
+ u32 lo_addr = clib_net_to_host_u32 (pa->lo_addr);
+ u32 hi_addr = clib_net_to_host_u32 (pa->hi_addr);
+
+ /* an ARP request hit in the proxy-arp table? */
+ if ((this_addr >= lo_addr && this_addr <= hi_addr) &&
+ (fib_index0 == pa->fib_index))
+ {
+ eth0 = ethernet_buffer_get_header (p0);
+ proxy_src.as_u32 =
+ arp0->ip4_over_ethernet[1].ip4.data_u32;
+
+ /*
+ * Rewind buffer, direct code above not to
+ * think too hard about it.
+ * $$$ is the answer ever anything other than
+ * vlib_buffer_reset(..)?
+ */
+ ifa0 = 0;
+ if_addr0 = &proxy_src;
+ vlib_buffer_reset (p0);
+ n_proxy_arp_replies_sent++;
+ goto send_reply;
+ }
+ }
+ }
+
+ drop2:
next0 = ARP_INPUT_NEXT_DROP;
p0->error = node->errors[error0];
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,to_next,
- n_left_to_next,pi0,next0);
+ 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_error_count (vm, node->node_index,
- ETHERNET_ARP_ERROR_replies_sent,
- n_replies_sent - n_proxy_arp_replies_sent);
-
+ ETHERNET_ARP_ERROR_replies_sent,
+ n_replies_sent - n_proxy_arp_replies_sent);
+
vlib_error_count (vm, node->node_index,
- ETHERNET_ARP_ERROR_proxy_arp_replies_sent,
- n_proxy_arp_replies_sent);
+ ETHERNET_ARP_ERROR_proxy_arp_replies_sent,
+ n_proxy_arp_replies_sent);
return frame->n_vectors;
}
-static char * ethernet_arp_error_strings[] = {
+static char *ethernet_arp_error_strings[] = {
#define _(sym,string) string,
foreach_ethernet_arp_error
#undef _
};
-VLIB_REGISTER_NODE (arp_input_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (arp_input_node, static) =
+{
.function = arp_input,
.name = "arp-input",
.vector_size = sizeof (u32),
-
.n_errors = ETHERNET_ARP_N_ERROR,
.error_strings = ethernet_arp_error_strings,
-
.n_next_nodes = ARP_INPUT_N_NEXT,
.next_nodes = {
[ARP_INPUT_NEXT_DROP] = "error-drop",
[ARP_INPUT_NEXT_REPLY_TX] = "interface-output",
},
-
.format_buffer = format_ethernet_arp_header,
.format_trace = format_ethernet_arp_input_trace,
};
+/* *INDENT-ON* */
static int
ip4_arp_entry_sort (void *a1, void *a2)
{
- ethernet_arp_ip4_entry_t * e1 = a1;
- ethernet_arp_ip4_entry_t * e2 = a2;
+ ethernet_arp_ip4_entry_t *e1 = a1;
+ ethernet_arp_ip4_entry_t *e2 = a2;
int cmp;
- vnet_main_t * vnm = vnet_get_main();
+ vnet_main_t *vnm = vnet_get_main ();
- cmp = vnet_sw_interface_compare
+ cmp = vnet_sw_interface_compare
(vnm, e1->key.sw_if_index, e2->key.sw_if_index);
- if (! cmp)
+ if (!cmp)
cmp = ip4_address_compare (&e1->key.ip4_address, &e2->key.ip4_address);
return cmp;
}
static clib_error_t *
show_ip4_arp (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();
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ethernet_arp_ip4_entry_t * e, * es;
- ethernet_proxy_arp_t * pa;
- clib_error_t * error = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ethernet_arp_ip4_entry_t *e, *es;
+ ethernet_proxy_arp_t *pa;
+ clib_error_t *error = 0;
u32 sw_if_index;
/* Filter entries by interface if given. */
@@ -1162,15 +1188,22 @@ show_ip4_arp (vlib_main_t * vm,
(void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index);
es = 0;
- pool_foreach (e, am->ip4_entry_pool, ({ vec_add1 (es, e[0]); }));
- if ( es )
+ /* *INDENT-OFF* */
+ pool_foreach (e, am->ip4_entry_pool,
+ ({
+ vec_add1 (es, e[0]);
+ }));
+ /* *INDENT-ON* */
+
+ if (es)
{
vec_sort_with_function (es, ip4_arp_entry_sort);
vlib_cli_output (vm, "%U", format_ethernet_arp_ip4_entry, vnm, 0);
- vec_foreach (e, es) {
- if (sw_if_index != ~0 && e->key.sw_if_index != sw_if_index)
- continue;
- vlib_cli_output (vm, "%U", format_ethernet_arp_ip4_entry, vnm, e);
+ vec_foreach (e, es)
+ {
+ if (sw_if_index != ~0 && e->key.sw_if_index != sw_if_index)
+ continue;
+ vlib_cli_output (vm, "%U", format_ethernet_arp_ip4_entry, vnm, e);
}
vec_free (es);
}
@@ -1178,29 +1211,33 @@ show_ip4_arp (vlib_main_t * vm,
if (vec_len (am->proxy_arps))
{
vlib_cli_output (vm, "Proxy arps enabled for:");
- vec_foreach(pa, am->proxy_arps)
- {
- vlib_cli_output (vm, "Fib_index %d %U - %U ",
- pa->fib_index,
- format_ip4_address, &pa->lo_addr,
- format_ip4_address, &pa->hi_addr);
- }
+ vec_foreach (pa, am->proxy_arps)
+ {
+ vlib_cli_output (vm, "Fib_index %d %U - %U ",
+ pa->fib_index,
+ format_ip4_address, &pa->lo_addr,
+ format_ip4_address, &pa->hi_addr);
+ }
}
-
+
return error;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_ip4_arp_command, static) = {
.path = "show ip arp",
.function = show_ip4_arp,
.short_help = "Show ARP table",
};
+/* *INDENT-ON* */
-typedef struct {
+typedef struct
+{
pg_edit_t l2_type, l3_type;
pg_edit_t n_l2_address_bytes, n_l3_address_bytes;
pg_edit_t opcode;
- struct {
+ struct
+ {
pg_edit_t ethernet;
pg_edit_t ip4;
} ip4_over_ethernet[2];
@@ -1211,25 +1248,25 @@ pg_ethernet_arp_header_init (pg_ethernet_arp_header_t * p)
{
/* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, ethernet_arp_header_t, f);
- _ (l2_type);
- _ (l3_type);
- _ (n_l2_address_bytes);
- _ (n_l3_address_bytes);
- _ (opcode);
- _ (ip4_over_ethernet[0].ethernet);
- _ (ip4_over_ethernet[0].ip4);
- _ (ip4_over_ethernet[1].ethernet);
- _ (ip4_over_ethernet[1].ip4);
+ _(l2_type);
+ _(l3_type);
+ _(n_l2_address_bytes);
+ _(n_l3_address_bytes);
+ _(opcode);
+ _(ip4_over_ethernet[0].ethernet);
+ _(ip4_over_ethernet[0].ip4);
+ _(ip4_over_ethernet[1].ethernet);
+ _(ip4_over_ethernet[1].ip4);
#undef _
}
uword
unformat_pg_arp_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_ethernet_arp_header_t * p;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_ethernet_arp_header_t *p;
u32 group_index;
-
+
p = pg_create_edit_group (s, sizeof (p[0]), sizeof (ethernet_arp_header_t),
&group_index);
pg_ethernet_arp_header_init (p);
@@ -1240,17 +1277,17 @@ unformat_pg_arp_header (unformat_input_t * input, va_list * args)
pg_edit_set_fixed (&p->n_l2_address_bytes, 6);
pg_edit_set_fixed (&p->n_l3_address_bytes, 4);
- if (! unformat (input, "%U: %U/%U -> %U/%U",
- unformat_pg_edit,
- unformat_ethernet_arp_opcode_net_byte_order, &p->opcode,
- unformat_pg_edit,
- unformat_ethernet_address, &p->ip4_over_ethernet[0].ethernet,
- unformat_pg_edit,
- unformat_ip4_address, &p->ip4_over_ethernet[0].ip4,
- unformat_pg_edit,
- unformat_ethernet_address, &p->ip4_over_ethernet[1].ethernet,
- unformat_pg_edit,
- unformat_ip4_address, &p->ip4_over_ethernet[1].ip4))
+ if (!unformat (input, "%U: %U/%U -> %U/%U",
+ unformat_pg_edit,
+ unformat_ethernet_arp_opcode_net_byte_order, &p->opcode,
+ unformat_pg_edit,
+ unformat_ethernet_address, &p->ip4_over_ethernet[0].ethernet,
+ unformat_pg_edit,
+ unformat_ip4_address, &p->ip4_over_ethernet[0].ip4,
+ unformat_pg_edit,
+ unformat_ethernet_address, &p->ip4_over_ethernet[1].ethernet,
+ unformat_pg_edit,
+ unformat_ip4_address, &p->ip4_over_ethernet[1].ip4))
{
/* Free up any edits we may have added. */
pg_free_edit_group (s);
@@ -1259,63 +1296,64 @@ unformat_pg_arp_header (unformat_input_t * input, va_list * args)
return 1;
}
-clib_error_t *ip4_set_arp_limit (u32 arp_limit)
+clib_error_t *
+ip4_set_arp_limit (u32 arp_limit)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
am->limit_arp_cache_size = arp_limit;
return 0;
}
static void
-arp_ip4_entry_del_adj(ethernet_arp_ip4_entry_t *e, u32 adj_index)
+arp_ip4_entry_del_adj (ethernet_arp_ip4_entry_t * e, u32 adj_index)
{
int done = 0;
int i;
while (!done)
{
- vec_foreach_index(i, e->adjacencies)
- if (vec_elt(e->adjacencies, i) == adj_index)
- {
- vec_del1(e->adjacencies, i);
- continue;
- }
+ vec_foreach_index (i, e->adjacencies)
+ if (vec_elt (e->adjacencies, i) == adj_index)
+ {
+ vec_del1 (e->adjacencies, i);
+ continue;
+ }
done = 1;
}
}
static void
-arp_ip4_entry_add_adj(ethernet_arp_ip4_entry_t *e, u32 adj_index)
+arp_ip4_entry_add_adj (ethernet_arp_ip4_entry_t * e, u32 adj_index)
{
int i;
- vec_foreach_index(i, e->adjacencies)
- if (vec_elt(e->adjacencies, i) == adj_index)
- return;
- vec_add1(e->adjacencies, adj_index);
+ vec_foreach_index (i, e->adjacencies)
+ if (vec_elt (e->adjacencies, i) == adj_index)
+ return;
+ vec_add1 (e->adjacencies, adj_index);
}
static void
-arp_add_del_adj_cb (struct ip_lookup_main_t * lm,
- u32 adj_index,
- ip_adjacency_t * adj,
- u32 is_del)
+arp_add_del_adj_cb (struct ip_lookup_main_t *lm,
+ u32 adj_index, ip_adjacency_t * adj, u32 is_del)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ip4_main_t * im = &ip4_main;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ip4_main_t *im = &ip4_main;
ethernet_arp_ip4_key_t k;
- ethernet_arp_ip4_entry_t * e = 0;
- uword * p;
+ ethernet_arp_ip4_entry_t *e = 0;
+ uword *p;
u32 ai;
- for(ai = adj->heap_handle; ai < adj->heap_handle + adj->n_adj ; ai++)
+ for (ai = adj->heap_handle; ai < adj->heap_handle + adj->n_adj; ai++)
{
adj = ip_get_adjacency (lm, ai);
- if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP && adj->arp.next_hop.ip4.as_u32)
+ if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
+ && adj->arp.next_hop.ip4.as_u32)
{
k.sw_if_index = adj->rewrite_header.sw_if_index;
k.ip4_address.as_u32 = adj->arp.next_hop.ip4.as_u32;
- k.fib_index = im->fib_index_by_sw_if_index[adj->rewrite_header.sw_if_index];
+ k.fib_index =
+ im->fib_index_by_sw_if_index[adj->rewrite_header.sw_if_index];
p = mhash_get (&am->ip4_entry_by_key, &k);
if (p)
e = pool_elt_at_index (am->ip4_entry_pool, p[0]);
@@ -1326,29 +1364,32 @@ arp_add_del_adj_cb (struct ip_lookup_main_t * lm,
if (is_del)
{
if (!e)
- clib_warning("Adjacency contains unknown ARP next hop %U (del)",
- format_ip46_address, &adj->arp.next_hop, IP46_TYPE_IP4);
+ clib_warning ("Adjacency contains unknown ARP next hop %U (del)",
+ format_ip46_address, &adj->arp.next_hop,
+ IP46_TYPE_IP4);
else
- arp_ip4_entry_del_adj(e, adj->heap_handle);
+ arp_ip4_entry_del_adj (e, adj->heap_handle);
}
- else /* add */
+ else /* add */
{
if (!e)
- clib_warning("Adjacency contains unknown ARP next hop %U (add)",
- format_ip46_address, &adj->arp.next_hop, IP46_TYPE_IP4);
+ clib_warning ("Adjacency contains unknown ARP next hop %U (add)",
+ format_ip46_address, &adj->arp.next_hop,
+ IP46_TYPE_IP4);
else
- arp_ip4_entry_add_adj(e, adj->heap_handle);
+ arp_ip4_entry_add_adj (e, adj->heap_handle);
}
}
}
-static clib_error_t * ethernet_arp_init (vlib_main_t * vm)
+static clib_error_t *
+ethernet_arp_init (vlib_main_t * vm)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- pg_node_t * pn;
- clib_error_t * error;
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ pg_node_t *pn;
+ clib_error_t *error;
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
if ((error = vlib_call_init_function (vm, ethernet_init)))
return error;
@@ -1375,7 +1416,7 @@ static clib_error_t * ethernet_arp_init (vlib_main_t * vm)
/* don't trace ARP error packets */
{
- vlib_node_runtime_t *rt =
+ vlib_node_runtime_t *rt =
vlib_node_get_runtime (vm, arp_input_node.index);
#define _(a,b) \
@@ -1386,19 +1427,18 @@ static clib_error_t * ethernet_arp_init (vlib_main_t * vm)
#undef _
}
- ip_register_add_del_adjacency_callback(lm, arp_add_del_adj_cb);
+ ip_register_add_del_adjacency_callback (lm, arp_add_del_adj_cb);
return 0;
}
VLIB_INIT_FUNCTION (ethernet_arp_init);
-int
+int
vnet_arp_unset_ip4_over_ethernet (vnet_main_t * vnm,
- u32 sw_if_index, u32 fib_index,
- void * a_arg)
+ u32 sw_if_index, u32 fib_index, void *a_arg)
{
- ethernet_arp_ip4_over_ethernet_address_t * a = a_arg;
+ ethernet_arp_ip4_over_ethernet_address_t *a = a_arg;
vnet_arp_set_ip4_over_ethernet_rpc_args_t args;
args.sw_if_index = sw_if_index;
@@ -1406,36 +1446,35 @@ vnet_arp_unset_ip4_over_ethernet (vnet_main_t * vnm,
args.is_remove = 1;
clib_memcpy (&args.a, a, sizeof (*a));
- vl_api_rpc_call_main_thread (set_ip4_over_ethernet_rpc_callback,
- (u8 *) &args, sizeof (args));
+ vl_api_rpc_call_main_thread (set_ip4_over_ethernet_rpc_callback,
+ (u8 *) & args, sizeof (args));
return 0;
}
-static inline int
+static inline int
vnet_arp_unset_ip4_over_ethernet_internal (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 fib_index,
- void * a_arg)
+ u32 sw_if_index,
+ u32 fib_index, void *a_arg)
{
- ethernet_arp_ip4_entry_t * e;
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ethernet_arp_ip4_over_ethernet_address_t * a = a_arg;
+ ethernet_arp_ip4_entry_t *e;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ethernet_arp_ip4_over_ethernet_address_t *a = a_arg;
ethernet_arp_ip4_key_t k;
- uword * p;
+ uword *p;
ip4_add_del_route_args_t args;
- 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;
u32 adj_index;
- ip_adjacency_t * adj;
+ ip_adjacency_t *adj;
k.sw_if_index = sw_if_index;
k.ip4_address = a->ip4;
k.fib_index = fib_index;
p = mhash_get (&am->ip4_entry_by_key, &k);
- if (! p)
+ if (!p)
return -1;
- memset(&args, 0, sizeof(args));
+ memset (&args, 0, sizeof (args));
/*
* Make sure that the route actually exists before we try to delete it,
@@ -1449,12 +1488,13 @@ vnet_arp_unset_ip4_over_ethernet_internal (vnet_main_t * vnm,
* See also ip4_del_interface_routes (...)
* -> ip4_delete_matching_routes (...).
*/
-
- adj_index = ip4_fib_lookup_with_table
- (im, fib_index, &a->ip4, 1 /* disable default route */);
+
+ adj_index = ip4_fib_lookup_with_table
+ (im, fib_index, &a->ip4, 1 /* disable default route */ );
/* Miss adj? Forget it... */
- if (adj_index != lm->miss_adj_index) {
+ if (adj_index != lm->miss_adj_index)
+ {
adj = ip_get_adjacency (lm, adj_index);
/*
* Stupid control-plane trick:
@@ -1463,16 +1503,17 @@ vnet_arp_unset_ip4_over_ethernet_internal (vnet_main_t * vnm,
* then remove the arp cache entry (yuck). When that happens,
* the adj we find here will be the interface subnet ARP adj.
*/
- if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE) {
- args.table_index_or_table_id = fib_index;
- args.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL
- | IP4_ROUTE_FLAG_NEIGHBOR;
- args.dst_address = a->ip4;
- args.dst_address_length = 32;
- ip4_add_del_route (im, &args);
- ip4_maybe_remap_adjacencies (im, fib_index, args.flags);
- }
- }
+ if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE)
+ {
+ args.table_index_or_table_id = fib_index;
+ args.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL
+ | IP4_ROUTE_FLAG_NEIGHBOR;
+ args.dst_address = a->ip4;
+ args.dst_address_length = 32;
+ ip4_add_del_route (im, &args);
+ ip4_maybe_remap_adjacencies (im, fib_index, args.flags);
+ }
+ }
e = pool_elt_at_index (am->ip4_entry_pool, p[0]);
mhash_unset (&am->ip4_entry_by_key, &e->key, 0);
@@ -1480,18 +1521,18 @@ vnet_arp_unset_ip4_over_ethernet_internal (vnet_main_t * vnm,
return 0;
}
-static void
-increment_ip4_and_mac_address (ethernet_arp_ip4_over_ethernet_address_t *a)
+static void
+increment_ip4_and_mac_address (ethernet_arp_ip4_over_ethernet_address_t * a)
{
u8 old;
int i;
- for (i = 3; i >= 0; i--)
+ for (i = 3; i >= 0; i--)
{
old = a->ip4.as_u8[i];
a->ip4.as_u8[i] += 1;
if (old < a->ip4.as_u8[i])
- break;
+ break;
}
for (i = 5; i >= 0; i--)
@@ -1499,34 +1540,33 @@ increment_ip4_and_mac_address (ethernet_arp_ip4_over_ethernet_address_t *a)
old = a->ethernet[i];
a->ethernet[i] += 1;
if (old < a->ethernet[i])
- break;
+ break;
}
}
-int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
- ip4_address_t *hi_addr,
- u32 fib_index, int is_del)
+int
+vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
+ ip4_address_t * hi_addr, u32 fib_index, int is_del)
{
ethernet_arp_main_t *am = &ethernet_arp_main;
ethernet_proxy_arp_t *pa;
u32 found_at_index = ~0;
vec_foreach (pa, am->proxy_arps)
- {
- if (pa->lo_addr == lo_addr->as_u32
- && pa->hi_addr == hi_addr->as_u32
- && pa->fib_index == fib_index)
- {
- found_at_index = pa - am->proxy_arps;
- break;
- }
- }
+ {
+ if (pa->lo_addr == lo_addr->as_u32
+ && pa->hi_addr == hi_addr->as_u32 && pa->fib_index == fib_index)
+ {
+ found_at_index = pa - am->proxy_arps;
+ break;
+ }
+ }
if (found_at_index != ~0)
{
/* Delete, otherwise it's already in the table */
if (is_del)
- vec_delete (am->proxy_arps, 1, found_at_index);
+ vec_delete (am->proxy_arps, 1, found_at_index);
return 0;
}
/* delete, no such entry */
@@ -1545,54 +1585,55 @@ int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
* Remove any proxy arp entries asdociated with the
* specificed fib.
*/
-int vnet_proxy_arp_fib_reset (u32 fib_id)
+int
+vnet_proxy_arp_fib_reset (u32 fib_id)
{
- ip4_main_t * im = &ip4_main;
+ ip4_main_t *im = &ip4_main;
ethernet_arp_main_t *am = &ethernet_arp_main;
ethernet_proxy_arp_t *pa;
- u32 * entries_to_delete = 0;
+ u32 *entries_to_delete = 0;
u32 fib_index;
- uword * p;
+ uword *p;
int i;
p = hash_get (im->fib_index_by_table_id, fib_id);
- if (! p)
- return VNET_API_ERROR_NO_SUCH_ENTRY;
+ if (!p)
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
fib_index = p[0];
vec_foreach (pa, am->proxy_arps)
- {
- if (pa->fib_index == fib_index)
- {
- vec_add1 (entries_to_delete, pa - am->proxy_arps);
- }
- }
+ {
+ if (pa->fib_index == fib_index)
+ {
+ vec_add1 (entries_to_delete, pa - am->proxy_arps);
+ }
+ }
- for (i = 0; i < vec_len(entries_to_delete); i++)
+ for (i = 0; i < vec_len (entries_to_delete); i++)
{
- vec_delete (am->proxy_arps, 1, entries_to_delete[i]);
- }
+ vec_delete (am->proxy_arps, 1, entries_to_delete[i]);
+ }
vec_free (entries_to_delete);
- return 0;
+ return 0;
}
u32
-vnet_arp_glean_add(u32 fib_index, void * next_hop_arg)
+vnet_arp_glean_add (u32 fib_index, void *next_hop_arg)
{
- ethernet_arp_main_t * am = &ethernet_arp_main;
- ip4_main_t * im = &ip4_main;
- ip_lookup_main_t * lm = &im->lookup_main;
- ip4_address_t * next_hop = next_hop_arg;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ ip4_main_t *im = &ip4_main;
+ ip_lookup_main_t *lm = &im->lookup_main;
+ ip4_address_t *next_hop = next_hop_arg;
ip_adjacency_t add_adj, *adj;
ip4_add_del_route_args_t args;
- ethernet_arp_ip4_entry_t * e;
+ ethernet_arp_ip4_entry_t *e;
ethernet_arp_ip4_key_t k;
u32 adj_index;
- adj_index = ip4_fib_lookup_with_table(im, fib_index, next_hop, 0);
- adj = ip_get_adjacency(lm, adj_index);
+ adj_index = ip4_fib_lookup_with_table (im, fib_index, next_hop, 0);
+ adj = ip_get_adjacency (lm, adj_index);
if (!adj || adj->lookup_next_index != IP_LOOKUP_NEXT_ARP)
return ~0;
@@ -1608,16 +1649,18 @@ vnet_arp_glean_add(u32 fib_index, void * next_hop_arg)
return adj_index;
pool_get (am->ip4_entry_pool, e);
- mhash_set (&am->ip4_entry_by_key, &k, e - am->ip4_entry_pool, /* old value */ 0);
+ mhash_set (&am->ip4_entry_by_key, &k, e - am->ip4_entry_pool,
+ /* old value */ 0);
e->key = k;
e->cpu_time_last_updated = clib_cpu_time_now ();
e->flags = ETHERNET_ARP_IP4_ENTRY_FLAG_GLEAN;
- memset(&args, 0, sizeof(args));
- clib_memcpy(&add_adj, adj, sizeof(add_adj));
- ip46_address_set_ip4(&add_adj.arp.next_hop, next_hop); /* install neighbor /32 route */
+ memset (&args, 0, sizeof (args));
+ clib_memcpy (&add_adj, adj, sizeof (add_adj));
+ ip46_address_set_ip4 (&add_adj.arp.next_hop, next_hop); /* install neighbor /32 route */
args.table_index_or_table_id = fib_index;
- args.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_ADD| IP4_ROUTE_FLAG_NEIGHBOR;
+ args.flags =
+ IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_ADD | IP4_ROUTE_FLAG_NEIGHBOR;
args.dst_address.as_u32 = next_hop->as_u32;
args.dst_address_length = 32;
args.adj_index = ~0;
@@ -1629,10 +1672,9 @@ vnet_arp_glean_add(u32 fib_index, void * next_hop_arg)
static clib_error_t *
ip_arp_add_del_command_fn (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 ();
u32 sw_if_index;
ethernet_arp_ip4_over_ethernet_address_t lo_addr, hi_addr, addr;
int addr_valid = 0;
@@ -1643,145 +1685,151 @@ ip_arp_add_del_command_fn (vlib_main_t * vm,
int is_static = 0;
int is_proxy = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
/* set ip arp TenGigE1/1/0/1 1.2.3.4 aa:bb:... or aabb.ccdd... */
if (unformat (input, "%U %U %U",
- unformat_vnet_sw_interface, vnm, &sw_if_index,
- unformat_ip4_address, &addr.ip4,
- unformat_ethernet_address, &addr.ethernet))
- addr_valid = 1;
+ unformat_vnet_sw_interface, vnm, &sw_if_index,
+ unformat_ip4_address, &addr.ip4,
+ unformat_ethernet_address, &addr.ethernet))
+ 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 if (unformat (input, "count %d", &count))
- ;
+ ;
else if (unformat (input, "fib-id %d", &fib_id))
- {
- ip4_main_t * im = &ip4_main;
- uword * p = hash_get (im->fib_index_by_table_id, fib_id);
- if (! p)
- return clib_error_return (0, "fib ID %d doesn't exist\n",
- fib_id);
- fib_index = p[0];
- }
-
- else if (unformat (input, "proxy %U - %U",
- unformat_ip4_address, &lo_addr.ip4,
- unformat_ip4_address, &hi_addr.ip4))
- is_proxy = 1;
+ {
+ ip4_main_t *im = &ip4_main;
+ uword *p = hash_get (im->fib_index_by_table_id, fib_id);
+ if (!p)
+ return clib_error_return (0, "fib ID %d doesn't exist\n", fib_id);
+ fib_index = p[0];
+ }
+
+ else if (unformat (input, "proxy %U - %U",
+ unformat_ip4_address, &lo_addr.ip4,
+ unformat_ip4_address, &hi_addr.ip4))
+ is_proxy = 1;
else
- break;
+ break;
}
-
+
if (is_proxy)
{
- (void) vnet_proxy_arp_add_del (&lo_addr.ip4, &hi_addr.ip4,
- fib_index, is_del);
+ (void) vnet_proxy_arp_add_del (&lo_addr.ip4, &hi_addr.ip4,
+ fib_index, is_del);
return 0;
}
- if (addr_valid)
+ if (addr_valid)
{
int i;
- for (i = 0; i < count; i++)
- {
- if (is_del == 0)
- {
- uword event_type, * event_data = 0;
-
- /* Park the debug CLI until the arp entry is installed */
- vnet_register_ip4_arp_resolution_event
- (vnm, &addr.ip4, vlib_current_process(vm),
- 1 /* type */, 0 /* data */);
-
- vnet_arp_set_ip4_over_ethernet
- (vnm, sw_if_index, fib_index, &addr, is_static);
-
- vlib_process_wait_for_event (vm);
- event_type = vlib_process_get_events (vm, &event_data);
- vec_reset_length(event_data);
- if (event_type != 1)
- clib_warning ("event type %d unexpected", event_type);
- }
- else
- vnet_arp_unset_ip4_over_ethernet
- (vnm, sw_if_index, fib_index, &addr);
-
- increment_ip4_and_mac_address (&addr);
- }
+ for (i = 0; i < count; i++)
+ {
+ if (is_del == 0)
+ {
+ uword event_type, *event_data = 0;
+
+ /* Park the debug CLI until the arp entry is installed */
+ vnet_register_ip4_arp_resolution_event
+ (vnm, &addr.ip4, vlib_current_process (vm),
+ 1 /* type */ , 0 /* data */ );
+
+ vnet_arp_set_ip4_over_ethernet
+ (vnm, sw_if_index, fib_index, &addr, is_static);
+
+ vlib_process_wait_for_event (vm);
+ event_type = vlib_process_get_events (vm, &event_data);
+ vec_reset_length (event_data);
+ if (event_type != 1)
+ clib_warning ("event type %d unexpected", event_type);
+ }
+ else
+ vnet_arp_unset_ip4_over_ethernet
+ (vnm, sw_if_index, fib_index, &addr);
+
+ increment_ip4_and_mac_address (&addr);
+ }
}
else
{
return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
}
-
+
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (ip_arp_add_del_command, static) = {
- .path = "set ip arp",
- .short_help = "set ip arp [del] <intfc> <ip-address> <mac-address> [static] [count <count>] [fib-id <fib-id>] [proxy <lo-addr> - <hi-addr>]",
- .function = ip_arp_add_del_command_fn,
+ .path = "set ip arp",
+ .short_help =
+ "set ip arp [del] <intfc> <ip-address> <mac-address> [static] [count <count>] [fib-id <fib-id>] [proxy <lo-addr> - <hi-addr>]",
+ .function = ip_arp_add_del_command_fn,
};
+/* *INDENT-ON* */
static clib_error_t *
set_int_proxy_arp_command_fn (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 ();
u32 sw_if_index;
- vnet_sw_interface_t * si;
+ vnet_sw_interface_t *si;
int enable = 0;
int intfc_set = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "%U", unformat_vnet_sw_interface,
- vnm, &sw_if_index))
- intfc_set = 1;
+ if (unformat (input, "%U", unformat_vnet_sw_interface,
+ vnm, &sw_if_index))
+ intfc_set = 1;
else if (unformat (input, "enable") || unformat (input, "on"))
- enable = 1;
+ enable = 1;
else if (unformat (input, "disable") || unformat (input, "off"))
- enable = 0;
+ enable = 0;
else
- break;
+ break;
}
if (intfc_set == 0)
return clib_error_return (0, "unknown input '%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
si = vnet_get_sw_interface (vnm, sw_if_index);
- ASSERT(si);
+ ASSERT (si);
if (enable)
si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
- else
+ else
si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
-
+
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (set_int_proxy_enable_command, static) = {
- .path = "set interface proxy-arp",
- .short_help = "set interface proxy-arp <intfc> [enable|disable]",
- .function = set_int_proxy_arp_command_fn,
+ .path = "set interface proxy-arp",
+ .short_help =
+ "set interface proxy-arp <intfc> [enable|disable]",
+ .function = set_int_proxy_arp_command_fn,
};
+/* *INDENT-ON* */
/*
* ARP Termination in a L2 Bridge Domain based on an
* IP4 to MAC hash table mac_by_ip4 for each BD.
*/
-typedef enum {
+typedef enum
+{
ARP_TERM_NEXT_L2_OUTPUT,
ARP_TERM_NEXT_DROP,
ARP_TERM_N_NEXT,
@@ -1791,15 +1839,14 @@ u32 arp_term_next_node_index[32];
static uword
arp_term_l2bd (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- l2input_main_t * l2im = &l2input_main;
- u32 n_left_from, next_index, * from, * to_next;
+ l2input_main_t *l2im = &l2input_main;
+ u32 n_left_from, next_index, *from, *to_next;
u32 n_replies_sent = 0;
u16 last_bd_index = ~0;
- l2_bridge_domain_t * last_bd_config = 0;
- l2_input_config_t * cfg0;
+ l2_bridge_domain_t *last_bd_config = 0;
+ l2_input_config_t *cfg0;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -1809,20 +1856,19 @@ arp_term_l2bd (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 > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * p0;
- ethernet_header_t * eth0;
- ethernet_arp_header_t * arp0;
- u8 * l3h0;
+ vlib_buffer_t *p0;
+ ethernet_header_t *eth0;
+ ethernet_arp_header_t *arp0;
+ u8 *l3h0;
u32 pi0, error0, next0, sw_if_index0;
u16 ethertype0;
u16 bd_index0;
u32 ip0;
- u8 * macp0;
+ u8 *macp0;
pi0 = from[0];
to_next[0] = pi0;
@@ -1833,90 +1879,94 @@ arp_term_l2bd (vlib_main_t * vm,
p0 = vlib_get_buffer (vm, pi0);
eth0 = vlib_buffer_get_current (p0);
- l3h0 = (u8 *)eth0 + vnet_buffer(p0)->l2.l2_len;
- ethertype0 = clib_net_to_host_u16(*(u16 *)(l3h0 - 2));
+ l3h0 = (u8 *) eth0 + vnet_buffer (p0)->l2.l2_len;
+ ethertype0 = clib_net_to_host_u16 (*(u16 *) (l3h0 - 2));
arp0 = (ethernet_arp_header_t *) l3h0;
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
(p0->flags & VLIB_BUFFER_IS_TRACED)))
{
- u8 *t0 = vlib_add_trace (
- vm, node, p0, sizeof(ethernet_arp_input_trace_t));
- clib_memcpy (t0, l3h0, sizeof(ethernet_arp_input_trace_t));
+ u8 *t0 = vlib_add_trace (vm, node, p0,
+ sizeof (ethernet_arp_input_trace_t));
+ clib_memcpy (t0, l3h0, sizeof (ethernet_arp_input_trace_t));
}
- if (PREDICT_FALSE (
- (ethertype0 != ETHERNET_TYPE_ARP) ||
- (arp0->opcode != clib_host_to_net_u16(ETHERNET_ARP_OPCODE_request))))
+ if (PREDICT_FALSE ((ethertype0 != ETHERNET_TYPE_ARP) ||
+ (arp0->opcode !=
+ clib_host_to_net_u16
+ (ETHERNET_ARP_OPCODE_request))))
goto next_l2_feature;
error0 = ETHERNET_ARP_ERROR_replies_sent;
- error0 = (arp0->l2_type != clib_net_to_host_u16 (ETHERNET_ARP_HARDWARE_TYPE_ethernet)
- ? ETHERNET_ARP_ERROR_l2_type_not_ethernet
- : error0);
- error0 = (arp0->l3_type != clib_net_to_host_u16 (ETHERNET_TYPE_IP4)
- ? ETHERNET_ARP_ERROR_l3_type_not_ip4
- : error0);
+ error0 =
+ (arp0->l2_type !=
+ clib_net_to_host_u16 (ETHERNET_ARP_HARDWARE_TYPE_ethernet) ?
+ ETHERNET_ARP_ERROR_l2_type_not_ethernet : error0);
+ error0 =
+ (arp0->l3_type !=
+ clib_net_to_host_u16 (ETHERNET_TYPE_IP4) ?
+ ETHERNET_ARP_ERROR_l3_type_not_ip4 : error0);
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
if (error0)
goto drop;
- // Trash ARP packets whose ARP-level source addresses do not
- // match their L2-frame-level source addresses */
- if (PREDICT_FALSE (
- memcmp (eth0->src_address, arp0->ip4_over_ethernet[0].ethernet,
- sizeof (eth0->src_address))))
- {
- error0 = ETHERNET_ARP_ERROR_l2_address_mismatch;
- goto drop;
- }
+ // Trash ARP packets whose ARP-level source addresses do not
+ // match their L2-frame-level source addresses */
+ if (PREDICT_FALSE
+ (memcmp
+ (eth0->src_address, arp0->ip4_over_ethernet[0].ethernet,
+ sizeof (eth0->src_address))))
+ {
+ error0 = ETHERNET_ARP_ERROR_l2_address_mismatch;
+ goto drop;
+ }
// Check if anyone want ARP request events for L2 BDs
{
- pending_resolution_t * mc;
- ethernet_arp_main_t * am = &ethernet_arp_main;
- uword *p = hash_get (am->mac_changes_by_address, 0);
- if (p && (vnet_buffer(p0)->l2.shg == 0))
- { // Only SHG 0 interface which is more likely local
- u32 next_index = p[0];
- while (next_index != (u32)~0)
- {
- int (*fp)(u32, u8 *, u32, u32);
- int rv = 1;
- mc = pool_elt_at_index (am->mac_changes, next_index);
- fp = mc->data_callback;
- // Call the callback, return 1 to suppress dup events */
- if (fp) rv = (*fp)(mc->data,
- arp0->ip4_over_ethernet[0].ethernet,
- sw_if_index0,
- arp0->ip4_over_ethernet[0].ip4.as_u32);
- // Signal the resolver process
- if (rv == 0)
- vlib_process_signal_event (vm, mc->node_index,
- mc->type_opaque,
- mc->data);
- next_index = mc->next_index;
- }
- }
+ pending_resolution_t *mc;
+ ethernet_arp_main_t *am = &ethernet_arp_main;
+ uword *p = hash_get (am->mac_changes_by_address, 0);
+ if (p && (vnet_buffer (p0)->l2.shg == 0))
+ { // Only SHG 0 interface which is more likely local
+ u32 next_index = p[0];
+ while (next_index != (u32) ~ 0)
+ {
+ int (*fp) (u32, u8 *, u32, u32);
+ int rv = 1;
+ mc = pool_elt_at_index (am->mac_changes, next_index);
+ fp = mc->data_callback;
+ // Call the callback, return 1 to suppress dup events */
+ if (fp)
+ rv = (*fp) (mc->data,
+ arp0->ip4_over_ethernet[0].ethernet,
+ sw_if_index0,
+ arp0->ip4_over_ethernet[0].ip4.as_u32);
+ // Signal the resolver process
+ if (rv == 0)
+ vlib_process_signal_event (vm, mc->node_index,
+ mc->type_opaque, mc->data);
+ next_index = mc->next_index;
+ }
+ }
}
// lookup BD mac_by_ip4 hash table for MAC entry
ip0 = arp0->ip4_over_ethernet[1].ip4.as_u32;
- bd_index0 = vnet_buffer(p0)->l2.bd_index;
- if (PREDICT_FALSE (
- (bd_index0 != last_bd_index) || (last_bd_index == (u16) ~0)))
+ bd_index0 = vnet_buffer (p0)->l2.bd_index;
+ if (PREDICT_FALSE ((bd_index0 != last_bd_index)
+ || (last_bd_index == (u16) ~ 0)))
{
last_bd_index = bd_index0;
- last_bd_config = vec_elt_at_index(l2im->bd_configs, bd_index0);
+ last_bd_config = vec_elt_at_index (l2im->bd_configs, bd_index0);
}
macp0 = (u8 *) hash_get (last_bd_config->mac_by_ip4, ip0);
- if (PREDICT_FALSE(!macp0))
- goto next_l2_feature; // MAC not found
+ if (PREDICT_FALSE (!macp0))
+ goto next_l2_feature; // MAC not found
- // MAC found, send ARP reply -
+ // MAC found, send ARP reply -
// Convert ARP request packet to ARP reply
arp0->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply);
arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0];
@@ -1928,10 +1978,10 @@ arp_term_l2bd (vlib_main_t * vm,
// For BVI, need to use l2-fwd node to send ARP reply as
// l2-output node cannot output packet to BVI properly
- cfg0 = vec_elt_at_index(l2im->configs, sw_if_index0);
+ cfg0 = vec_elt_at_index (l2im->configs, sw_if_index0);
if (PREDICT_FALSE (cfg0->bvi))
{
- vnet_buffer(p0)->l2.feature_bitmap |= L2INPUT_FEAT_FWD;
+ vnet_buffer (p0)->l2.feature_bitmap |= L2INPUT_FEAT_FWD;
vnet_buffer (p0)->sw_if_index[VLIB_RX] = 0;
goto next_l2_feature;
}
@@ -1945,71 +1995,78 @@ arp_term_l2bd (vlib_main_t * vm,
// required, however, can just clear the SHG in packet as follows:
// vnet_buffer(p0)->l2.shg = 0;
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,to_next,
- n_left_to_next,pi0,next0);
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, pi0, next0);
continue;
next_l2_feature:
{
u32 feature_bitmap0 =
- vnet_buffer(p0)->l2.feature_bitmap & ~L2INPUT_FEAT_ARP_TERM;
- vnet_buffer(p0)->l2.feature_bitmap = feature_bitmap0;
- next0 = feat_bitmap_get_next_node_index(arp_term_next_node_index,
- feature_bitmap0);
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,to_next,
- n_left_to_next,pi0,next0);
+ vnet_buffer (p0)->l2.feature_bitmap & ~L2INPUT_FEAT_ARP_TERM;
+ vnet_buffer (p0)->l2.feature_bitmap = feature_bitmap0;
+ next0 = feat_bitmap_get_next_node_index (arp_term_next_node_index,
+ feature_bitmap0);
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, pi0, next0);
continue;
}
drop:
- if (0 == arp0->ip4_over_ethernet[0].ip4.as_u32 ||
- (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
- arp0->ip4_over_ethernet[1].ip4.as_u32))
- {
- error0 = ETHERNET_ARP_ERROR_gratuitous_arp;
- }
+ if (0 == arp0->ip4_over_ethernet[0].ip4.as_u32 ||
+ (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
+ arp0->ip4_over_ethernet[1].ip4.as_u32))
+ {
+ error0 = ETHERNET_ARP_ERROR_gratuitous_arp;
+ }
next0 = ARP_TERM_NEXT_DROP;
p0->error = node->errors[error0];
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,to_next,
- n_left_to_next,pi0,next0);
+ 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_error_count (vm, node->node_index,
- ETHERNET_ARP_ERROR_replies_sent,
- n_replies_sent);
+ ETHERNET_ARP_ERROR_replies_sent, n_replies_sent);
return frame->n_vectors;
}
-VLIB_REGISTER_NODE (arp_term_l2bd_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (arp_term_l2bd_node, static) = {
.function = arp_term_l2bd,
.name = "arp-term-l2bd",
.vector_size = sizeof (u32),
-
.n_errors = ETHERNET_ARP_N_ERROR,
.error_strings = ethernet_arp_error_strings,
-
.n_next_nodes = ARP_TERM_N_NEXT,
.next_nodes = {
[ARP_TERM_NEXT_L2_OUTPUT] = "l2-output",
[ARP_TERM_NEXT_DROP] = "error-drop",
},
-
.format_buffer = format_ethernet_arp_header,
.format_trace = format_ethernet_arp_input_trace,
};
+/* *INDENT-ON* */
-clib_error_t *arp_term_init (vlib_main_t *vm)
-{ // Initialize the feature next-node indexes
- feat_bitmap_init_next_nodes(vm,
- arp_term_l2bd_node.index,
- L2INPUT_N_FEAT,
- l2input_get_feat_names(),
- arp_term_next_node_index);
+clib_error_t *
+arp_term_init (vlib_main_t * vm)
+{ // Initialize the feature next-node indexes
+ feat_bitmap_init_next_nodes (vm,
+ arp_term_l2bd_node.index,
+ L2INPUT_N_FEAT,
+ l2input_get_feat_names (),
+ arp_term_next_node_index);
return 0;
}
VLIB_INIT_FUNCTION (arp_term_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/arp_packet.h b/vnet/vnet/ethernet/arp_packet.h
index b3447c5e1c1..8befb6c5115 100644
--- a/vnet/vnet/ethernet/arp_packet.h
+++ b/vnet/vnet/ethernet/arp_packet.h
@@ -86,25 +86,29 @@
_ (exp1) \
_ (exp2)
-typedef enum {
+typedef enum
+{
#define _(n,f) ETHERNET_ARP_HARDWARE_TYPE_##f = (n),
foreach_ethernet_arp_hardware_type
#undef _
} ethernet_arp_hardware_type_t;
-typedef enum {
+typedef enum
+{
#define _(f) ETHERNET_ARP_OPCODE_##f,
foreach_ethernet_arp_opcode
#undef _
- ETHERNET_ARP_N_OPCODE,
+ ETHERNET_ARP_N_OPCODE,
} ethernet_arp_opcode_t;
-typedef enum {
+typedef enum
+{
IP4_ARP_NEXT_DROP,
IP4_ARP_N_NEXT,
} ip4_arp_next_t;
-typedef enum {
+typedef enum
+{
IP4_ARP_ERROR_DROP,
IP4_ARP_ERROR_REQUEST_SENT,
IP4_ARP_ERROR_NON_ARP_ADJ,
@@ -113,18 +117,22 @@ typedef enum {
IP4_ARP_ERROR_NO_SOURCE_ADDRESS,
} ip4_arp_error_t;
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
u8 ethernet[6];
ip4_address_t ip4;
}) ethernet_arp_ip4_over_ethernet_address_t;
+/* *INDENT-ON* */
-typedef struct {
+typedef struct
+{
u16 l2_type;
u16 l3_type;
u8 n_l2_address_bytes;
u8 n_l3_address_bytes;
u16 opcode;
- union {
+ union
+ {
ethernet_arp_ip4_over_ethernet_address_t ip4_over_ethernet[2];
/* Others... */
@@ -133,3 +141,11 @@ typedef struct {
} ethernet_arp_header_t;
#endif /* included_ethernet_arp_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/ethernet.h b/vnet/vnet/ethernet/ethernet.h
index 4735e20b851..be5b99c74b6 100644
--- a/vnet/vnet/ethernet/ethernet.h
+++ b/vnet/vnet/ethernet/ethernet.h
@@ -46,20 +46,23 @@
always_inline u64
ethernet_mac_address_u64 (u8 * a)
-{ return (((u64) a[0] << (u64) (5*8))
- | ((u64) a[1] << (u64) (4*8))
- | ((u64) a[2] << (u64) (3*8))
- | ((u64) a[3] << (u64) (2*8))
- | ((u64) a[4] << (u64) (1*8))
- | ((u64) a[5] << (u64) (0*8))); }
-
-static inline int ethernet_mac_address_is_multicast_u64 (u64 a)
{
- return (a & (1ULL<<(5*8))) != 0;
+ return (((u64) a[0] << (u64) (5 * 8))
+ | ((u64) a[1] << (u64) (4 * 8))
+ | ((u64) a[2] << (u64) (3 * 8))
+ | ((u64) a[3] << (u64) (2 * 8))
+ | ((u64) a[4] << (u64) (1 * 8)) | ((u64) a[5] << (u64) (0 * 8)));
+}
+
+static inline int
+ethernet_mac_address_is_multicast_u64 (u64 a)
+{
+ return (a & (1ULL << (5 * 8))) != 0;
}
/* Max. sized ethernet/vlan header for parsing. */
-typedef struct {
+typedef struct
+{
ethernet_header_t ethernet;
/* Allow up to 2 stacked vlan headers. */
@@ -69,13 +72,14 @@ typedef struct {
struct vnet_hw_interface_t;
/* Ethernet flag change callback. */
typedef u32 (ethernet_flag_change_function_t)
-(vnet_main_t * vnm, struct vnet_hw_interface_t * hi, u32 flags);
+ (vnet_main_t * vnm, struct vnet_hw_interface_t * hi, u32 flags);
#define ETHERNET_MIN_PACKET_BYTES 64
#define ETHERNET_MAX_PACKET_BYTES 9216
/* Ethernet interface instance. */
-typedef struct ethernet_interface {
+typedef struct ethernet_interface
+{
/* Accept all packets (promiscuous mode). */
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL (1 << 0)
@@ -88,7 +92,7 @@ typedef struct ethernet_interface {
((flags) & ETHERNET_INTERFACE_FLAG_MTU)
/* Callback, e.g. to turn on/off promiscuous mode */
- ethernet_flag_change_function_t * flag_change;
+ ethernet_flag_change_function_t *flag_change;
u32 driver_instance;
@@ -98,9 +102,10 @@ typedef struct ethernet_interface {
extern vnet_hw_interface_class_t ethernet_hw_interface_class;
-typedef struct {
+typedef struct
+{
/* Name (a c string). */
- char * name;
+ char *name;
/* Ethernet type in host byte order. */
ethernet_type_t type;
@@ -112,7 +117,8 @@ typedef struct {
u32 next_index;
} ethernet_type_info_t;
-typedef enum {
+typedef enum
+{
#define ethernet_error(n,c,s) ETHERNET_ERROR_##n,
#include <vnet/ethernet/error.def>
#undef ethernet_error
@@ -122,9 +128,10 @@ typedef enum {
// Structs used when parsing packet to find sw_if_index
-typedef struct {
+typedef struct
+{
u32 sw_if_index;
- u32 flags;
+ u32 flags;
// config entry is-valid flag
// exact match flags (valid if packet has 0/1/2/3 tags)
// L2 vs L3 forwarding mode
@@ -138,44 +145,51 @@ typedef struct {
} subint_config_t;
always_inline u32
-eth_create_valid_subint_match_flags (u32 num_tags) {
+eth_create_valid_subint_match_flags (u32 num_tags)
+{
return SUBINT_CONFIG_VALID | (1 << num_tags);
}
-typedef struct {
+typedef struct
+{
subint_config_t untagged_subint;
subint_config_t default_subint;
- u16 dot1q_vlans; // pool id for vlan table
- u16 dot1ad_vlans; // pool id for vlan table
+ u16 dot1q_vlans; // pool id for vlan table
+ u16 dot1ad_vlans; // pool id for vlan table
} main_intf_t;
-typedef struct {
+typedef struct
+{
subint_config_t single_tag_subint;
subint_config_t inner_any_subint;
- u32 qinqs; // pool id for qinq table
+ u32 qinqs; // pool id for qinq table
} vlan_intf_t;
-typedef struct {
+typedef struct
+{
vlan_intf_t vlans[ETHERNET_N_VLAN];
} vlan_table_t;
-typedef struct {
+typedef struct
+{
subint_config_t subint;
} qinq_intf_t;
-typedef struct {
+typedef struct
+{
qinq_intf_t vlans[ETHERNET_N_VLAN];
} qinq_table_t;
// Structure mapping to a next index based on ethertype.
// Common ethertypes are stored explicitly, others are
// stored in a sparse table.
-typedef struct {
+typedef struct
+{
/* Sparse vector mapping ethernet type in network byte order
to next index. */
- u16 * input_next_by_type;
- u32 * sparse_index_by_input_next_index;
+ u16 *input_next_by_type;
+ u32 *sparse_index_by_input_next_index;
/* cached next indexes for common ethertypes */
u32 input_next_ip4;
@@ -184,8 +198,9 @@ typedef struct {
} next_by_ethertype_t;
-typedef struct {
- vlib_main_t * vlib_main;
+typedef struct
+{
+ vlib_main_t *vlib_main;
/* next node index for the L3 input node of each ethertype */
next_by_ethertype_t l3_next;
@@ -198,22 +213,22 @@ typedef struct {
u32 redirect_l3_next;
/* Pool of ethernet interface instances. */
- ethernet_interface_t * interfaces;
+ ethernet_interface_t *interfaces;
- ethernet_type_info_t * type_infos;
+ ethernet_type_info_t *type_infos;
/* Hash tables mapping name/type to type info index. */
- uword * type_info_by_name, * type_info_by_type;
+ uword *type_info_by_name, *type_info_by_type;
// The root of the vlan parsing tables. A vector with one element
// for each main interface, indexed by hw_if_index.
- main_intf_t * main_intfs;
+ main_intf_t *main_intfs;
// Pool of vlan tables
- vlan_table_t * vlan_pool;
+ vlan_table_t *vlan_pool;
// Pool of qinq tables;
- qinq_table_t * qinq_pool;
+ qinq_table_t *qinq_pool;
/* Set to one to use AB.CD.EF instead of A:B:C:D:E:F as ethernet format. */
int format_ethernet_address_16bit;
@@ -228,49 +243,43 @@ ethernet_main_t ethernet_main;
always_inline ethernet_type_info_t *
ethernet_get_type_info (ethernet_main_t * em, ethernet_type_t type)
{
- uword * p = hash_get (em->type_info_by_type, type);
+ uword *p = hash_get (em->type_info_by_type, type);
return p ? vec_elt_at_index (em->type_infos, p[0]) : 0;
}
-ethernet_interface_t *
-ethernet_get_interface (ethernet_main_t * em, u32 hw_if_index);
+ethernet_interface_t *ethernet_get_interface (ethernet_main_t * em,
+ u32 hw_if_index);
-clib_error_t *
-ethernet_register_interface (vnet_main_t * vnm,
- u32 dev_class_index,
- u32 dev_instance,
- u8 * address,
- u32 * hw_if_index_return,
- ethernet_flag_change_function_t flag_change);
+clib_error_t *ethernet_register_interface (vnet_main_t * vnm,
+ u32 dev_class_index,
+ u32 dev_instance,
+ u8 * address,
+ u32 * hw_if_index_return,
+ ethernet_flag_change_function_t
+ flag_change);
void ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index);
/* Register given node index to take input for given ethernet type. */
void
ethernet_register_input_type (vlib_main_t * vm,
- ethernet_type_t type,
- u32 node_index);
+ ethernet_type_t type, u32 node_index);
/* Register given node index to take input for packet from L2 interfaces. */
-void
-ethernet_register_l2_input (vlib_main_t * vm,
- u32 node_index);
+void ethernet_register_l2_input (vlib_main_t * vm, u32 node_index);
/* Register given node index to take redirected L3 traffic, and enable L3 redirect */
-void
-ethernet_register_l3_redirect (vlib_main_t * vm,
- u32 node_index);
+void ethernet_register_l3_redirect (vlib_main_t * vm, u32 node_index);
/* Formats ethernet address X:X:X:X:X:X */
-u8 * format_ethernet_address (u8 * s, va_list * args);
-u8 * format_ethernet_type (u8 * s, va_list * args);
-u8 * format_ethernet_vlan_tci (u8 * s, va_list * va);
-u8 * format_ethernet_header (u8 * s, va_list * args);
-u8 * format_ethernet_header_with_length (u8 * s, va_list * args);
+u8 *format_ethernet_address (u8 * s, va_list * args);
+u8 *format_ethernet_type (u8 * s, va_list * args);
+u8 *format_ethernet_vlan_tci (u8 * s, va_list * va);
+u8 *format_ethernet_header (u8 * s, va_list * args);
+u8 *format_ethernet_header_with_length (u8 * s, va_list * args);
/* Parse ethernet address in either X:X:X:X:X:X unix or X.X.X cisco format. */
-uword
-unformat_ethernet_address (unformat_input_t * input, va_list * args);
+uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
/* Parse ethernet type as 0xXXXX or type name from ethernet/types.def.
In either host or network byte order. */
@@ -282,8 +291,7 @@ unformat_ethernet_type_net_byte_order (unformat_input_t * input,
va_list * args);
/* Parse ethernet header. */
-uword
-unformat_ethernet_header (unformat_input_t * input, va_list * args);
+uword unformat_ethernet_header (unformat_input_t * input, va_list * args);
/* Parse ethernet interface name; return hw_if_index. */
uword unformat_ethernet_interface (unformat_input_t * input, va_list * args);
@@ -293,8 +301,8 @@ uword unformat_pg_ethernet_header (unformat_input_t * input, va_list * args);
always_inline void
ethernet_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_ethernet_header_with_length;
n->unformat_buffer = unformat_ethernet_header;
@@ -305,8 +313,7 @@ always_inline ethernet_header_t *
ethernet_buffer_get_header (vlib_buffer_t * b)
{
return (void *)
- (b->data
- + vnet_buffer (b)->ethernet.start_of_ethernet_header);
+ (b->data + vnet_buffer (b)->ethernet.start_of_ethernet_header);
}
/** Returns the number of VLAN headers in the current Ethernet frame in the
@@ -353,48 +360,47 @@ ethernet_buffer_get_header (vlib_buffer_t * b)
sizeof(ethernet_header_t) \
)
-ethernet_main_t * ethernet_get_main (vlib_main_t * vm);
+ethernet_main_t *ethernet_get_main (vlib_main_t * vm);
u32 ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags);
-void ethernet_sw_interface_set_l2_mode (vnet_main_t * vnm, u32 sw_if_index, u32 l2);
-void ethernet_sw_interface_set_l2_mode_noport (vnet_main_t * vnm, u32 sw_if_index, u32 l2);
-void ethernet_set_rx_redirect (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 enable);
+void ethernet_sw_interface_set_l2_mode (vnet_main_t * vnm, u32 sw_if_index,
+ u32 l2);
+void ethernet_sw_interface_set_l2_mode_noport (vnet_main_t * vnm,
+ u32 sw_if_index, u32 l2);
+void ethernet_set_rx_redirect (vnet_main_t * vnm, vnet_hw_interface_t * hi,
+ u32 enable);
int
vnet_arp_set_ip4_over_ethernet (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 fib_index,
- void *a_arg,
- int is_static);
+ u32 sw_if_index,
+ u32 fib_index, void *a_arg, int is_static);
int
vnet_arp_unset_ip4_over_ethernet (vnet_main_t * vnm,
- u32 sw_if_index, u32 fib_index,
- void * a_arg);
+ u32 sw_if_index, u32 fib_index,
+ void *a_arg);
int vnet_proxy_arp_fib_reset (u32 fib_id);
-clib_error_t * next_by_ethertype_init (next_by_ethertype_t * l3_next);
-clib_error_t * next_by_ethertype_register (next_by_ethertype_t * l3_next,
- u32 ethertype,
- u32 next_index);
+clib_error_t *next_by_ethertype_init (next_by_ethertype_t * l3_next);
+clib_error_t *next_by_ethertype_register (next_by_ethertype_t * l3_next,
+ u32 ethertype, u32 next_index);
-int vnet_create_loopback_interface (u32 * sw_if_indexp, u8 *mac_address);
+int vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address);
int vnet_delete_loopback_interface (u32 sw_if_index);
// Perform ethernet subinterface classification table lookups given
// the ports's sw_if_index and fields extracted from the ethernet header.
// The resulting tables are used by identify_subint().
always_inline void
-eth_vlan_table_lookups (ethernet_main_t *em,
- vnet_main_t * vnm,
- u32 port_sw_if_index0,
- u16 first_ethertype,
- u16 outer_id,
- u16 inner_id,
- vnet_hw_interface_t ** hi,
- main_intf_t **main_intf,
- vlan_intf_t **vlan_intf,
- qinq_intf_t **qinq_intf)
+eth_vlan_table_lookups (ethernet_main_t * em,
+ vnet_main_t * vnm,
+ u32 port_sw_if_index0,
+ u16 first_ethertype,
+ u16 outer_id,
+ u16 inner_id,
+ vnet_hw_interface_t ** hi,
+ main_intf_t ** main_intf,
+ vlan_intf_t ** vlan_intf, qinq_intf_t ** qinq_intf)
{
vlan_table_t *vlan_table;
qinq_table_t *qinq_table;
@@ -411,8 +417,7 @@ eth_vlan_table_lookups (ethernet_main_t *em,
// many tags on the packet. This makes the lookups and comparisons
// easier (and less branchy).
vlan_table_id = (first_ethertype == ETHERNET_TYPE_DOT1AD) ?
- (*main_intf)->dot1ad_vlans :
- (*main_intf)->dot1q_vlans;
+ (*main_intf)->dot1ad_vlans : (*main_intf)->dot1q_vlans;
vlan_table = vec_elt_at_index (em->vlan_pool, vlan_table_id);
*vlan_intf = &vlan_table->vlans[outer_id];
@@ -427,47 +432,50 @@ eth_vlan_table_lookups (ethernet_main_t *em,
// Returns 1 if a matching subinterface was found, otherwise returns 0.
always_inline u32
eth_identify_subint (vnet_hw_interface_t * hi,
- vlib_buffer_t * b0,
- u32 match_flags,
- main_intf_t * main_intf,
- vlan_intf_t * vlan_intf,
- qinq_intf_t * qinq_intf,
- u32 * new_sw_if_index,
- u8 * error0,
- u32 * is_l2)
+ vlib_buffer_t * b0,
+ u32 match_flags,
+ main_intf_t * main_intf,
+ vlan_intf_t * vlan_intf,
+ qinq_intf_t * qinq_intf,
+ u32 * new_sw_if_index, u8 * error0, u32 * is_l2)
{
- subint_config_t * subint;
+ subint_config_t *subint;
// Each comparison is checking both the valid flag and the number of tags
// (incorporating exact-match/non-exact-match).
// check for specific double tag
subint = &qinq_intf->subint;
- if ((subint->flags & match_flags) == match_flags) goto matched;
+ if ((subint->flags & match_flags) == match_flags)
+ goto matched;
// check for specific outer and 'any' inner
subint = &vlan_intf->inner_any_subint;
- if ((subint->flags & match_flags) == match_flags) goto matched;
+ if ((subint->flags & match_flags) == match_flags)
+ goto matched;
// check for specific single tag
subint = &vlan_intf->single_tag_subint;
- if ((subint->flags & match_flags) == match_flags) goto matched;
+ if ((subint->flags & match_flags) == match_flags)
+ goto matched;
// check for untagged interface
subint = &main_intf->untagged_subint;
- if ((subint->flags & match_flags) == match_flags) goto matched;
+ if ((subint->flags & match_flags) == match_flags)
+ goto matched;
// check for default interface
subint = &main_intf->default_subint;
- if ((subint->flags & match_flags) == match_flags) goto matched;
+ if ((subint->flags & match_flags) == match_flags)
+ goto matched;
// No matching subinterface
*new_sw_if_index = ~0;
*error0 = ETHERNET_ERROR_UNKNOWN_VLAN;
*is_l2 = 0;
return 0;
-
- matched:
+
+matched:
*new_sw_if_index = subint->sw_if_index;
*is_l2 = subint->flags & SUBINT_CONFIG_L2;
return 1;
@@ -475,35 +483,43 @@ eth_identify_subint (vnet_hw_interface_t * hi,
// Compare two ethernet macs. Return 1 if they are the same, 0 if different
always_inline u32
-eth_mac_equal (u8 * mac1, u8 * mac2) {
- return (*((u32 *)(mac1+0)) == *((u32 *)(mac2+0)) &&
- *((u32 *)(mac1+2)) == *((u32 *)(mac2+2)));
+eth_mac_equal (u8 * mac1, u8 * mac2)
+{
+ return (*((u32 *) (mac1 + 0)) == *((u32 *) (mac2 + 0)) &&
+ *((u32 *) (mac1 + 2)) == *((u32 *) (mac2 + 2)));
}
-always_inline ethernet_main_t *
+always_inline ethernet_main_t *
vnet_get_ethernet_main (void)
{
return &ethernet_main;
}
-void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
- void * address_arg,
- uword node_index,
- uword type_opaque,
- uword data);
+void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
+ void *address_arg,
+ uword node_index,
+ uword type_opaque, uword data);
-int vnet_add_del_ip4_arp_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);
+int vnet_add_del_ip4_arp_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);
-u32 vnet_arp_glean_add(u32 fib_index, void * next_hop_arg);
+u32 vnet_arp_glean_add (u32 fib_index, void *next_hop_arg);
extern vlib_node_registration_t ethernet_input_node;
#endif /* included_ethernet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/format.c b/vnet/vnet/ethernet/format.c
index 175d7fb6352..1b6712773e9 100644
--- a/vnet/vnet/ethernet/format.c
+++ b/vnet/vnet/ethernet/format.c
@@ -40,10 +40,11 @@
#include <vlib/vlib.h>
#include <vnet/ethernet/ethernet.h>
-u8 * format_ethernet_address (u8 * s, va_list * args)
+u8 *
+format_ethernet_address (u8 * s, va_list * args)
{
- ethernet_main_t * em = &ethernet_main;
- u8 * a = va_arg (*args, u8 *);
+ ethernet_main_t *em = &ethernet_main;
+ u8 *a = va_arg (*args, u8 *);
if (em->format_ethernet_address_16bit)
return format (s, "%02x%02x.%02x%02x.%02x%02x",
@@ -53,11 +54,12 @@ u8 * format_ethernet_address (u8 * s, va_list * args)
a[0], a[1], a[2], a[3], a[4], a[5]);
}
-u8 * format_ethernet_type (u8 * s, va_list * args)
+u8 *
+format_ethernet_type (u8 * s, va_list * args)
{
ethernet_type_t type = va_arg (*args, u32);
- ethernet_main_t * em = &ethernet_main;
- ethernet_type_info_t * t = ethernet_get_type_info (em, type);
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_type_info_t *t = ethernet_get_type_info (em, type);
if (t)
s = format (s, "%s", t->name);
@@ -67,32 +69,34 @@ u8 * format_ethernet_type (u8 * s, va_list * args)
return s;
}
-u8 * format_ethernet_vlan_tci (u8 * s, va_list * va)
+u8 *
+format_ethernet_vlan_tci (u8 * s, va_list * va)
{
- u32 vlan_tci = va_arg (*va, u32);
+ u32 vlan_tci = va_arg (*va, u32);
- u32 vid = (vlan_tci & 0xfff);
- u32 cfi = (vlan_tci >> 12) & 1;
- u32 pri = (vlan_tci >> 13);
+ u32 vid = (vlan_tci & 0xfff);
+ u32 cfi = (vlan_tci >> 12) & 1;
+ u32 pri = (vlan_tci >> 13);
- s = format (s, "%d", vid);
- if (pri != 0)
- s = format (s, " priority %d", pri);
- if (cfi != 0)
- s = format (s, " cfi");
+ s = format (s, "%d", vid);
+ if (pri != 0)
+ s = format (s, " priority %d", pri);
+ if (cfi != 0)
+ s = format (s, " cfi");
- return s;
+ return s;
}
-u8 * format_ethernet_header_with_length (u8 * s, va_list * args)
+u8 *
+format_ethernet_header_with_length (u8 * s, va_list * args)
{
- ethernet_max_header_t * m = va_arg (*args, ethernet_max_header_t *);
+ ethernet_max_header_t *m = va_arg (*args, ethernet_max_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
- ethernet_main_t * em = &ethernet_main;
- ethernet_header_t * e = &m->ethernet;
- ethernet_vlan_header_t * v;
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_header_t *e = &m->ethernet;
+ ethernet_vlan_header_t *v;
ethernet_type_t type = clib_net_to_host_u16 (e->type);
- ethernet_type_t vlan_type[ARRAY_LEN(m->vlan)];
+ ethernet_type_t vlan_type[ARRAY_LEN (m->vlan)];
u32 n_vlan = 0, i, header_bytes;
uword indent;
@@ -120,19 +124,19 @@ u8 * format_ethernet_header_with_length (u8 * s, va_list * args)
{
u32 v = clib_net_to_host_u16 (m->vlan[i].priority_cfi_and_id);
if (*vlan_type == ETHERNET_TYPE_VLAN)
- s = format (s, " 802.1q vlan %U", format_ethernet_vlan_tci, v);
+ s = format (s, " 802.1q vlan %U", format_ethernet_vlan_tci, v);
else
- s = format (s, " 802.1ad vlan %U", format_ethernet_vlan_tci, v);
+ s = format (s, " 802.1ad vlan %U", format_ethernet_vlan_tci, v);
}
if (max_header_bytes != 0 && header_bytes < max_header_bytes)
{
- ethernet_type_info_t * ti;
- vlib_node_t * node = 0;
+ ethernet_type_info_t *ti;
+ vlib_node_t *node = 0;
ti = ethernet_get_type_info (em, type);
if (ti && ti->node_index != ~0)
- node = vlib_get_node (em->vlib_main, ti->node_index);
+ node = vlib_get_node (em->vlib_main, ti->node_index);
if (node && node->format_buffer)
s = format (s, "\n%U%U",
format_white_space, indent,
@@ -143,9 +147,10 @@ u8 * format_ethernet_header_with_length (u8 * s, va_list * args)
return s;
}
-u8 * format_ethernet_header (u8 * s, va_list * args)
+u8 *
+format_ethernet_header (u8 * s, va_list * args)
{
- ethernet_max_header_t * m = va_arg (*args, ethernet_max_header_t *);
+ ethernet_max_header_t *m = va_arg (*args, ethernet_max_header_t *);
return format (s, "%U", format_ethernet_header_with_length, m, 0);
}
@@ -153,11 +158,11 @@ u8 * format_ethernet_header (u8 * s, va_list * args)
static uword
unformat_ethernet_address_unix (unformat_input_t * input, va_list * args)
{
- u8 * result = va_arg (*args, u8 *);
+ u8 *result = va_arg (*args, u8 *);
u32 i, a[6];
- if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
- &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
+ if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
+ &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
return 0;
/* Check range. */
@@ -175,10 +180,10 @@ unformat_ethernet_address_unix (unformat_input_t * input, va_list * args)
static uword
unformat_ethernet_address_cisco (unformat_input_t * input, va_list * args)
{
- u8 * result = va_arg (*args, u8 *);
+ u8 *result = va_arg (*args, u8 *);
u32 i, a[3];
- if (! unformat (input, "%_%x.%x.%x%_", &a[0], &a[1], &a[2]))
+ if (!unformat (input, "%_%x.%x.%x%_", &a[0], &a[1], &a[2]))
return 0;
/* Check range. */
@@ -200,7 +205,7 @@ unformat_ethernet_address_cisco (unformat_input_t * input, va_list * args)
uword
unformat_ethernet_address (unformat_input_t * input, va_list * args)
{
- u8 * result = va_arg (*args, u8 *);
+ u8 *result = va_arg (*args, u8 *);
return (unformat_user (input, unformat_ethernet_address_unix, result)
|| unformat_user (input, unformat_ethernet_address_cisco, result));
}
@@ -210,13 +215,12 @@ uword
unformat_ethernet_type_host_byte_order (unformat_input_t * input,
va_list * args)
{
- u16 * result = va_arg (*args, u16 *);
- ethernet_main_t * em = &ethernet_main;
+ u16 *result = va_arg (*args, u16 *);
+ ethernet_main_t *em = &ethernet_main;
int type, i;
/* Numeric type. */
- if (unformat (input, "0x%x", &type)
- || unformat (input, "%d", &type))
+ if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
{
if (type >= (1 << 16))
return 0;
@@ -228,7 +232,7 @@ unformat_ethernet_type_host_byte_order (unformat_input_t * input,
if (unformat_user (input, unformat_vlib_number_by_name,
em->type_info_by_name, &i))
{
- ethernet_type_info_t * ti = vec_elt_at_index (em->type_infos, i);
+ ethernet_type_info_t *ti = vec_elt_at_index (em->type_infos, i);
*result = ti->type;
return 1;
}
@@ -240,27 +244,27 @@ uword
unformat_ethernet_type_net_byte_order (unformat_input_t * input,
va_list * args)
{
- u16 * result = va_arg (*args, u16 *);
- if (! unformat_user (input, unformat_ethernet_type_host_byte_order, result))
+ u16 *result = va_arg (*args, u16 *);
+ if (!unformat_user (input, unformat_ethernet_type_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_ethernet_header (unformat_input_t * input, va_list * args)
{
- u8 ** result = va_arg (*args, u8 **);
- ethernet_max_header_t _m, * m = &_m;
- ethernet_header_t * e = &m->ethernet;
+ u8 **result = va_arg (*args, u8 **);
+ ethernet_max_header_t _m, *m = &_m;
+ ethernet_header_t *e = &m->ethernet;
u16 type;
u32 n_vlan;
- if (! unformat (input, "%U: %U -> %U",
- unformat_ethernet_type_host_byte_order, &type,
- unformat_ethernet_address, &e->src_address,
- unformat_ethernet_address, &e->dst_address))
+ if (!unformat (input, "%U: %U -> %U",
+ unformat_ethernet_type_host_byte_order, &type,
+ unformat_ethernet_address, &e->src_address,
+ unformat_ethernet_address, &e->dst_address))
return 0;
n_vlan = 0;
@@ -268,7 +272,7 @@ unformat_ethernet_header (unformat_input_t * input, va_list * args)
{
u32 id, priority;
- if (! unformat_user (input, unformat_vlib_number, &id)
+ if (!unformat_user (input, unformat_vlib_number, &id)
|| id >= ETHERNET_N_VLAN)
return 0;
@@ -304,12 +308,20 @@ unformat_ethernet_header (unformat_input_t * input, va_list * args)
/* Add header to result. */
{
- void * p;
+ void *p;
u32 n_bytes = sizeof (e[0]) + n_vlan * sizeof (m->vlan[0]);
vec_add2 (*result, p, n_bytes);
clib_memcpy (p, m, n_bytes);
}
-
+
return 1;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/init.c b/vnet/vnet/ethernet/init.c
index 9206524e953..b561a36144e 100644
--- a/vnet/vnet/ethernet/init.c
+++ b/vnet/vnet/ethernet/init.c
@@ -43,11 +43,10 @@
/* Global main structure. */
ethernet_main_t ethernet_main;
-static void add_type (ethernet_main_t * em,
- ethernet_type_t type,
- char * type_name)
+static void
+add_type (ethernet_main_t * em, ethernet_type_t type, char *type_name)
{
- ethernet_type_info_t * ti;
+ ethernet_type_info_t *ti;
u32 i;
vec_add2 (em->type_infos, ti, 1);
@@ -61,16 +60,17 @@ static void add_type (ethernet_main_t * em,
hash_set_mem (em->type_info_by_name, ti->name, i);
}
-static clib_error_t * ethernet_init (vlib_main_t * vm)
+static clib_error_t *
+ethernet_init (vlib_main_t * vm)
{
- ethernet_main_t * em = &ethernet_main;
- clib_error_t * error;
+ ethernet_main_t *em = &ethernet_main;
+ clib_error_t *error;
/*
* Set up the L2 path now, or we'll wipe out the L2 ARP
* registration set up by ethernet_arp_init.
*/
- if ((error = vlib_call_init_function(vm, l2_init)))
+ if ((error = vlib_call_init_function (vm, l2_init)))
return error;
em->vlib_main = vm;
@@ -92,9 +92,18 @@ static clib_error_t * ethernet_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (ethernet_init);
-ethernet_main_t * ethernet_get_main (vlib_main_t * vm)
+ethernet_main_t *
+ethernet_get_main (vlib_main_t * vm)
{
vlib_call_init_function (vm, ethernet_init);
return &ethernet_main;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/interface.c b/vnet/vnet/ethernet/interface.c
index cc0afb7f40b..9723ad9f7ff 100644
--- a/vnet/vnet/ethernet/interface.c
+++ b/vnet/vnet/ethernet/interface.c
@@ -43,87 +43,102 @@
#include <vnet/ethernet/ethernet.h>
#include <vnet/l2/l2_input.h>
-static uword ethernet_set_rewrite (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 l3_type,
- void * dst_address,
- void * rewrite,
- uword max_rewrite_bytes)
+static uword
+ethernet_set_rewrite (vnet_main_t * vnm,
+ u32 sw_if_index,
+ u32 l3_type,
+ void *dst_address,
+ void *rewrite, uword max_rewrite_bytes)
{
- vnet_sw_interface_t * sub_sw = vnet_get_sw_interface (vnm, sw_if_index);
- vnet_sw_interface_t * sup_sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
- vnet_hw_interface_t * hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
- ethernet_main_t * em = &ethernet_main;
- ethernet_interface_t * ei;
- ethernet_header_t * h = rewrite;
+ vnet_sw_interface_t *sub_sw = vnet_get_sw_interface (vnm, sw_if_index);
+ vnet_sw_interface_t *sup_sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
+ vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_interface_t *ei;
+ ethernet_header_t *h = rewrite;
ethernet_type_t type;
uword n_bytes = sizeof (h[0]);
- if (sub_sw != sup_sw) {
- if (sub_sw->sub.eth.flags.one_tag) {
- n_bytes += sizeof (ethernet_vlan_header_t);
- } else if (sub_sw->sub.eth.flags.two_tags) {
- n_bytes += 2 * (sizeof (ethernet_vlan_header_t));
- }
- // Check for encaps that are not supported for L3 interfaces
- if (!(sub_sw->sub.eth.flags.exact_match) ||
- (sub_sw->sub.eth.flags.default_sub) ||
- (sub_sw->sub.eth.flags.outer_vlan_id_any) ||
- (sub_sw->sub.eth.flags.inner_vlan_id_any)) {
- return 0;
+ if (sub_sw != sup_sw)
+ {
+ if (sub_sw->sub.eth.flags.one_tag)
+ {
+ n_bytes += sizeof (ethernet_vlan_header_t);
+ }
+ else if (sub_sw->sub.eth.flags.two_tags)
+ {
+ n_bytes += 2 * (sizeof (ethernet_vlan_header_t));
+ }
+ // Check for encaps that are not supported for L3 interfaces
+ if (!(sub_sw->sub.eth.flags.exact_match) ||
+ (sub_sw->sub.eth.flags.default_sub) ||
+ (sub_sw->sub.eth.flags.outer_vlan_id_any) ||
+ (sub_sw->sub.eth.flags.inner_vlan_id_any))
+ {
+ return 0;
+ }
}
- }
if (n_bytes > max_rewrite_bytes)
return 0;
- switch (l3_type) {
+ switch (l3_type)
+ {
#define _(a,b) case VNET_L3_PACKET_TYPE_##a: type = ETHERNET_TYPE_##b; break
- _ (IP4, IP4);
- _ (IP6, IP6);
- _ (MPLS_UNICAST, MPLS_UNICAST);
- _ (MPLS_MULTICAST, MPLS_MULTICAST);
- _ (ARP, ARP);
+ _(IP4, IP4);
+ _(IP6, IP6);
+ _(MPLS_UNICAST, MPLS_UNICAST);
+ _(MPLS_MULTICAST, MPLS_MULTICAST);
+ _(ARP, ARP);
#undef _
- default:
- return 0;
- }
+ default:
+ return 0;
+ }
ei = pool_elt_at_index (em->interfaces, hw->hw_instance);
clib_memcpy (h->src_address, ei->address, sizeof (h->src_address));
if (dst_address)
clib_memcpy (h->dst_address, dst_address, sizeof (h->dst_address));
else
- memset (h->dst_address, ~0, sizeof (h->dst_address)); /* broadcast */
-
- if (sub_sw->sub.eth.flags.one_tag) {
- ethernet_vlan_header_t * outer = (void *) (h + 1);
-
- h->type = sub_sw->sub.eth.flags.dot1ad ?
- clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
- clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
- outer->priority_cfi_and_id = clib_host_to_net_u16 (sub_sw->sub.eth.outer_vlan_id);
- outer->type = clib_host_to_net_u16 (type);
-
- } else if (sub_sw->sub.eth.flags.two_tags) {
- ethernet_vlan_header_t * outer = (void *) (h + 1);
- ethernet_vlan_header_t * inner = (void *) (outer + 1);
-
- h->type = sub_sw->sub.eth.flags.dot1ad ?
- clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
- clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
- outer->priority_cfi_and_id = clib_host_to_net_u16 (sub_sw->sub.eth.outer_vlan_id);
- outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
- inner->priority_cfi_and_id = clib_host_to_net_u16 (sub_sw->sub.eth.inner_vlan_id);
- inner->type = clib_host_to_net_u16 (type);
-
- } else {
- h->type = clib_host_to_net_u16 (type);
- }
+ memset (h->dst_address, ~0, sizeof (h->dst_address)); /* broadcast */
+
+ if (sub_sw->sub.eth.flags.one_tag)
+ {
+ ethernet_vlan_header_t *outer = (void *) (h + 1);
+
+ h->type = sub_sw->sub.eth.flags.dot1ad ?
+ clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
+ clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
+ outer->priority_cfi_and_id =
+ clib_host_to_net_u16 (sub_sw->sub.eth.outer_vlan_id);
+ outer->type = clib_host_to_net_u16 (type);
+
+ }
+ else if (sub_sw->sub.eth.flags.two_tags)
+ {
+ ethernet_vlan_header_t *outer = (void *) (h + 1);
+ ethernet_vlan_header_t *inner = (void *) (outer + 1);
+
+ h->type = sub_sw->sub.eth.flags.dot1ad ?
+ clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) :
+ clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
+ outer->priority_cfi_and_id =
+ clib_host_to_net_u16 (sub_sw->sub.eth.outer_vlan_id);
+ outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
+ inner->priority_cfi_and_id =
+ clib_host_to_net_u16 (sub_sw->sub.eth.inner_vlan_id);
+ inner->type = clib_host_to_net_u16 (type);
+
+ }
+ else
+ {
+ h->type = clib_host_to_net_u16 (type);
+ }
return n_bytes;
}
+/* *INDENT-OFF* */
VNET_HW_INTERFACE_CLASS (ethernet_hw_interface_class) = {
.name = "Ethernet",
.format_address = format_ethernet_address,
@@ -132,22 +147,24 @@ VNET_HW_INTERFACE_CLASS (ethernet_hw_interface_class) = {
.unformat_header = unformat_ethernet_header,
.set_rewrite = ethernet_set_rewrite,
};
+/* *INDENT-ON* */
-uword unformat_ethernet_interface (unformat_input_t * input, va_list * args)
+uword
+unformat_ethernet_interface (unformat_input_t * input, va_list * args)
{
- vnet_main_t * vnm = va_arg (*args, vnet_main_t *);
- u32 * result = va_arg (*args, u32 *);
+ vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
+ u32 *result = va_arg (*args, u32 *);
u32 hw_if_index;
- ethernet_main_t * em = &ethernet_main;
- ethernet_interface_t * eif;
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_interface_t *eif;
- if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
+ if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
return 0;
eif = ethernet_get_interface (em, hw_if_index);
if (eif)
{
- *result = hw_if_index;
+ *result = hw_if_index;
return 1;
}
return 0;
@@ -158,13 +175,13 @@ ethernet_register_interface (vnet_main_t * vnm,
u32 dev_class_index,
u32 dev_instance,
u8 * address,
- u32 * hw_if_index_return,
- ethernet_flag_change_function_t flag_change)
+ u32 * hw_if_index_return,
+ ethernet_flag_change_function_t flag_change)
{
- ethernet_main_t * em = &ethernet_main;
- ethernet_interface_t * ei;
- vnet_hw_interface_t * hi;
- clib_error_t * error = 0;
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_interface_t *ei;
+ vnet_hw_interface_t *hi;
+ clib_error_t *error = 0;
u32 hw_if_index;
pool_get (em->interfaces, ei);
@@ -173,16 +190,17 @@ ethernet_register_interface (vnet_main_t * vnm,
hw_if_index = vnet_register_interface
(vnm,
dev_class_index, dev_instance,
- ethernet_hw_interface_class.index,
- ei - em->interfaces);
+ ethernet_hw_interface_class.index, ei - em->interfaces);
*hw_if_index_return = hw_if_index;
hi = vnet_get_hw_interface (vnm, hw_if_index);
ethernet_setup_node (vnm->vlib_main, hi->output_node_index);
- hi->min_packet_bytes = hi->min_supported_packet_bytes = ETHERNET_MIN_PACKET_BYTES;
- hi->max_packet_bytes = hi->max_supported_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
+ hi->min_packet_bytes = hi->min_supported_packet_bytes =
+ ETHERNET_MIN_PACKET_BYTES;
+ hi->max_packet_bytes = hi->max_supported_packet_bytes =
+ ETHERNET_MAX_PACKET_BYTES;
hi->per_packet_overhead_bytes =
/* preamble */ 8 + /* inter frame gap */ 12;
@@ -200,52 +218,58 @@ ethernet_register_interface (vnet_main_t * vnm,
}
return error;
}
-
+
void
ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index)
{
- ethernet_main_t * em = &ethernet_main;
- ethernet_interface_t * ei;
- vnet_hw_interface_t * hi;
- main_intf_t * main_intf;
- vlan_table_t * vlan_table;
- u32 idx;
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_interface_t *ei;
+ vnet_hw_interface_t *hi;
+ main_intf_t *main_intf;
+ vlan_table_t *vlan_table;
+ u32 idx;
hi = vnet_get_hw_interface (vnm, hw_if_index);
ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
/* Delete vlan mapping table for dot1q and dot1ad. */
main_intf = vec_elt_at_index (em->main_intfs, hi->hw_if_index);
- if (main_intf->dot1q_vlans) {
- vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1q_vlans);
- for (idx=0; idx<ETHERNET_N_VLAN; idx++ ) {
- if (vlan_table->vlans[idx].qinqs) {
- pool_put_index(em->qinq_pool, vlan_table->vlans[idx].qinqs);
- }
+ if (main_intf->dot1q_vlans)
+ {
+ vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1q_vlans);
+ for (idx = 0; idx < ETHERNET_N_VLAN; idx++)
+ {
+ if (vlan_table->vlans[idx].qinqs)
+ {
+ pool_put_index (em->qinq_pool, vlan_table->vlans[idx].qinqs);
+ }
+ }
+ pool_put_index (em->vlan_pool, main_intf->dot1q_vlans);
}
- pool_put_index(em->vlan_pool, main_intf->dot1q_vlans);
- }
- if (main_intf->dot1ad_vlans) {
- vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1ad_vlans);
- for (idx=0; idx<ETHERNET_N_VLAN; idx++ ) {
- if (vlan_table->vlans[idx].qinqs) {
- pool_put_index(em->qinq_pool, vlan_table->vlans[idx].qinqs);
- }
+ if (main_intf->dot1ad_vlans)
+ {
+ vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1ad_vlans);
+ for (idx = 0; idx < ETHERNET_N_VLAN; idx++)
+ {
+ if (vlan_table->vlans[idx].qinqs)
+ {
+ pool_put_index (em->qinq_pool, vlan_table->vlans[idx].qinqs);
+ }
+ }
+ pool_put_index (em->vlan_pool, main_intf->dot1ad_vlans);
}
- pool_put_index(em->vlan_pool, main_intf->dot1ad_vlans);
- }
-
+
vnet_delete_hw_interface (vnm, hw_if_index);
pool_put (em->interfaces, ei);
}
-u32
+u32
ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
- ethernet_main_t * em = &ethernet_main;
- vnet_hw_interface_t * hi;
- ethernet_interface_t * ei;
-
+ ethernet_main_t *em = &ethernet_main;
+ vnet_hw_interface_t *hi;
+ ethernet_interface_t *ei;
+
hi = vnet_get_hw_interface (vnm, hw_if_index);
ASSERT (hi->hw_class_index == ethernet_hw_interface_class.index);
@@ -253,7 +277,7 @@ ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
if (ei->flag_change)
return ei->flag_change (vnm, hi, flags);
- return (u32)~0;
+ return (u32) ~ 0;
}
/* Echo packets back to ethernet/l2-input. */
@@ -262,23 +286,23 @@ simulated_ethernet_interface_tx (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
- u32 n_left_from, n_left_to_next, n_copy, * from, * to_next;
+ u32 n_left_from, n_left_to_next, n_copy, *from, *to_next;
u32 next_index = VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT;
u32 i, next_node_index, bvi_flag, sw_if_index;
u32 n_pkts = 0, n_bytes = 0;
u32 cpu_index = vm->cpu_index;
- vnet_main_t * vnm = vnet_get_main();
- vnet_interface_main_t * im = &vnm->interface_main;
- vlib_node_main_t * nm = &vm->node_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_interface_main_t *im = &vnm->interface_main;
+ vlib_node_main_t *nm = &vm->node_main;
vlib_node_t *loop_node;
- vlib_buffer_t * b;
+ vlib_buffer_t *b;
// check tx node index, it is ethernet-input on loopback create
// but can be changed to l2-input if loopback is configured as
// BVI of a BD (Bridge Domain).
loop_node = vec_elt (nm->nodes, node->node_index);
next_node_index = loop_node->next_nodes[next_index];
- bvi_flag = (next_node_index == l2input_node.index)? 1 : 0;
+ bvi_flag = (next_node_index == l2input_node.index) ? 1 : 0;
n_left_from = frame->n_vectors;
from = vlib_frame_args (frame);
@@ -294,50 +318,57 @@ simulated_ethernet_interface_tx (vlib_main_t * vm,
n_left_from -= n_copy;
i = 0;
b = vlib_get_buffer (vm, from[i]);
- sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
+ sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
while (1)
{
// Set up RX and TX indices as if received from a real driver
// unless loopback is used as a BVI. For BVI case, leave TX index
// and update l2_len in packet as required for l2 forwarding path
vnet_buffer (b)->sw_if_index[VLIB_RX] = sw_if_index;
- if (bvi_flag) vnet_update_l2_len(b);
- else vnet_buffer (b)->sw_if_index[VLIB_TX] = (u32) ~0;
+ if (bvi_flag)
+ vnet_update_l2_len (b);
+ else
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = (u32) ~ 0;
i++;
n_pkts++;
n_bytes += vlib_buffer_length_in_chain (vm, b);
- if (i < n_copy) b = vlib_get_buffer (vm, from[i]);
- else break;
+ if (i < n_copy)
+ b = vlib_get_buffer (vm, from[i]);
+ else
+ break;
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
/* increment TX interface stat */
- vlib_increment_combined_counter (
- im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX,
- cpu_index, sw_if_index, n_pkts, n_bytes);
+ vlib_increment_combined_counter (im->combined_sw_if_counters +
+ VNET_INTERFACE_COUNTER_TX, cpu_index,
+ sw_if_index, n_pkts, n_bytes);
}
return n_left_from;
}
-static u8 * format_simulated_ethernet_name (u8 * s, va_list * args)
+static u8 *
+format_simulated_ethernet_name (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
return format (s, "loop%d", dev_instance);
}
static clib_error_t *
-simulated_ethernet_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
+simulated_ethernet_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
+ u32 flags)
{
u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
- VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
+ VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
return 0;
}
+/* *INDENT-OFF* */
VNET_DEVICE_CLASS (ethernet_simulated_device_class) = {
.name = "Loopback",
.format_device_name = format_simulated_ethernet_name,
@@ -345,22 +376,24 @@ VNET_DEVICE_CLASS (ethernet_simulated_device_class) = {
.admin_up_down_function = simulated_ethernet_admin_up_down,
.no_flatten_output_chains = 1,
};
+/* *INDENT-ON* */
-int vnet_create_loopback_interface (u32 * sw_if_indexp, u8 *mac_address)
+int
+vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address)
{
- vnet_main_t * vnm = vnet_get_main();
- vlib_main_t * vm = vlib_get_main();
- clib_error_t * error;
+ vnet_main_t *vnm = vnet_get_main ();
+ vlib_main_t *vm = vlib_get_main ();
+ clib_error_t *error;
static u32 instance;
u8 address[6];
u32 hw_if_index;
- vnet_hw_interface_t * hw_if;
+ vnet_hw_interface_t *hw_if;
u32 slot;
int rv = 0;
- ASSERT(sw_if_indexp);
+ ASSERT (sw_if_indexp);
- *sw_if_indexp = (u32)~0;
+ *sw_if_indexp = (u32) ~ 0;
memset (address, 0, sizeof (address));
@@ -380,28 +413,24 @@ int vnet_create_loopback_interface (u32 * sw_if_indexp, u8 *mac_address)
error = ethernet_register_interface
(vnm,
- ethernet_simulated_device_class.index,
- instance++,
- address,
- &hw_if_index,
+ ethernet_simulated_device_class.index, instance++, address, &hw_if_index,
/* flag change */ 0);
if (error)
{
rv = VNET_API_ERROR_INVALID_REGISTRATION;
- clib_error_report(error);
+ clib_error_report (error);
return rv;
}
hw_if = vnet_get_hw_interface (vnm, hw_if_index);
slot = vlib_node_add_named_next_with_slot
(vm, hw_if->tx_node_index,
- "ethernet-input",
- VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
+ "ethernet-input", VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
ASSERT (slot == VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
{
- vnet_sw_interface_t * si = vnet_get_hw_sw_interface (vnm, hw_if_index);
+ vnet_sw_interface_t *si = vnet_get_hw_sw_interface (vnm, hw_if_index);
*sw_if_indexp = si->sw_if_index;
}
@@ -422,9 +451,9 @@ create_simulated_ethernet_interfaces (vlib_main_t * vm,
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "mac %U", unformat_ethernet_address, mac_address))
- ;
+ ;
else
- break;
+ break;
}
rv = vnet_create_loopback_interface (&sw_if_index, mac_address);
@@ -432,38 +461,44 @@ create_simulated_ethernet_interfaces (vlib_main_t * vm,
if (rv)
return clib_error_return (0, "vnet_create_loopback_interface failed");
- vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
+ vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (),
+ sw_if_index);
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (create_simulated_ethernet_interface_command, static) = {
.path = "loopback create-interface",
.short_help = "Create Loopback ethernet interface [mac <mac-addr>]",
.function = create_simulated_ethernet_interfaces,
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (create_loopback_interface_command, static) = {
.path = "create loopback interface",
.short_help = "create loopback interface [mac <mac-addr>]",
.function = create_simulated_ethernet_interfaces,
};
+/* *INDENT-ON* */
ethernet_interface_t *
ethernet_get_interface (ethernet_main_t * em, u32 hw_if_index)
{
- vnet_hw_interface_t * i = vnet_get_hw_interface (vnet_get_main(), hw_if_index);
- return (i->hw_class_index == ethernet_hw_interface_class.index
- ? pool_elt_at_index (em->interfaces, i->hw_instance)
- : 0);
+ vnet_hw_interface_t *i =
+ vnet_get_hw_interface (vnet_get_main (), hw_if_index);
+ return (i->hw_class_index ==
+ ethernet_hw_interface_class.
+ index ? pool_elt_at_index (em->interfaces, i->hw_instance) : 0);
}
-int vnet_delete_loopback_interface (u32 sw_if_index)
+int
+vnet_delete_loopback_interface (u32 sw_if_index)
{
- vnet_main_t * vnm = vnet_get_main();
- vnet_sw_interface_t * si;
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_sw_interface_t *si;
- if (pool_is_free_index (vnm->interface_main.sw_interfaces,
- sw_if_index))
+ if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
si = vnet_get_sw_interface (vnm, sw_if_index);
@@ -479,15 +514,15 @@ delete_simulated_ethernet_interfaces (vlib_main_t * vm,
{
int rv;
u32 sw_if_index = ~0;
- vnet_main_t * vnm = vnet_get_main();
+ vnet_main_t *vnm = vnet_get_main ();
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "intfc %U",
- unformat_vnet_sw_interface, vnm, &sw_if_index))
- ;
+ unformat_vnet_sw_interface, vnm, &sw_if_index))
+ ;
else
- break;
+ break;
}
if (sw_if_index == ~0)
@@ -501,14 +536,26 @@ delete_simulated_ethernet_interfaces (vlib_main_t * vm,
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (delete_simulated_ethernet_interface_command, static) = {
.path = "loopback delete-interface",
.short_help = "Delete Loopback ethernet interface intfc <interface>",
.function = delete_simulated_ethernet_interfaces,
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (delete_loopback_interface_command, static) = {
.path = "delete loopback interface",
.short_help = "delete loopback interface intfc <interface>",
.function = delete_simulated_ethernet_interfaces,
};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/mac_swap.c b/vnet/vnet/ethernet/mac_swap.c
index f3949390521..34dfdf7e09e 100644
--- a/vnet/vnet/ethernet/mac_swap.c
+++ b/vnet/vnet/ethernet/mac_swap.c
@@ -20,19 +20,21 @@
#include <vnet/devices/pci/ixge.h>
#include <vnet/devices/pci/ixgev.h>
-typedef struct {
+typedef struct
+{
u32 cached_next_index;
u32 cached_sw_if_index;
/* Hash table to map sw_if_index to next node index */
- uword * next_node_index_by_sw_if_index;
+ uword *next_node_index_by_sw_if_index;
/* convenience */
- vlib_main_t * vlib_main;
- vnet_main_t * vnet_main;
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
} mac_swap_main_t;
-typedef struct {
+typedef struct
+{
u8 src[6];
u8 dst[6];
u32 sw_if_index;
@@ -40,17 +42,16 @@ typedef struct {
} swap_trace_t;
/* packet trace format function */
-static u8 * format_swap_trace (u8 * s, va_list * args)
+static u8 *
+format_swap_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 *);
- swap_trace_t * t = va_arg (*args, swap_trace_t *);
-
+ swap_trace_t *t = va_arg (*args, swap_trace_t *);
+
s = format (s, "SWAP: dst now %U src now %U sw_if_index %d next_index %d",
- format_ethernet_address, t->dst,
- format_ethernet_address, t->src,
- t->sw_if_index,
- t->next_index);
+ format_ethernet_address, t->dst,
+ format_ethernet_address, t->src, t->sw_if_index, t->next_index);
return s;
}
@@ -66,14 +67,15 @@ static vlib_node_registration_t mac_swap_node;
#define foreach_mac_swap_error \
_(SWAPS, "mac addresses swapped")
-typedef enum {
+typedef enum
+{
#define _(sym,str) MAC_SWAP_ERROR_##sym,
foreach_mac_swap_error
#undef _
- MAC_SWAP_N_ERROR,
+ MAC_SWAP_N_ERROR,
} mac_swap_error_t;
-static char * mac_swap_error_strings[] = {
+static char *mac_swap_error_strings[] = {
#define _(sym,string) string,
foreach_mac_swap_error
#undef _
@@ -94,22 +96,22 @@ static char * mac_swap_error_strings[] = {
*
*/
-typedef enum {
+typedef enum
+{
MAC_SWAP_NEXT_DROP,
MAC_SWAP_N_NEXT,
} mac_swap_next_t;
static uword
mac_swap_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, * to_next;
+ u32 n_left_from, *from, *to_next;
mac_swap_next_t next_index;
- mac_swap_main_t * msm = &mac_swap_main;
+ mac_swap_main_t *msm = &mac_swap_main;
vlib_node_t *n = vlib_get_node (vm, mac_swap_node.index);
u32 node_counter_base_index = n->error_heap_index;
- vlib_error_main_t * em = &vm->error_main;
+ vlib_error_main_t *em = &vm->error_main;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -119,28 +121,27 @@ mac_swap_node_fn (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;
- u32 next0, next1;
- u32 sw_if_index0, sw_if_index1;
- uword * p0, * p1;
- u64 tmp0a, tmp0b;
- u64 tmp1a, tmp1b;
- ethernet_header_t * h0, *h1;
-
-
+ u32 bi0, bi1;
+ vlib_buffer_t *b0, *b1;
+ u32 next0, next1;
+ u32 sw_if_index0, sw_if_index1;
+ uword *p0, *p1;
+ u64 tmp0a, tmp0b;
+ u64 tmp1a, tmp1b;
+ ethernet_header_t *h0, *h1;
+
+
/* 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]);
-
+
vlib_prefetch_buffer_header (p2, LOAD);
vlib_prefetch_buffer_header (p3, LOAD);
@@ -158,112 +159,116 @@ mac_swap_node_fn (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
b1 = vlib_get_buffer (vm, bi1);
- sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
- next0 = msm->cached_next_index;
- sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_RX];
- next1 = msm->cached_next_index;
-
- if (PREDICT_FALSE (msm->cached_sw_if_index != sw_if_index0))
- {
- p0 = hash_get (msm->next_node_index_by_sw_if_index, sw_if_index0);
- if (p0 == 0)
- {
- vnet_hw_interface_t *hw0;
-
- hw0 = vnet_get_sup_hw_interface (msm->vnet_main,
- sw_if_index0);
-
- next0 = vlib_node_add_next (msm->vlib_main,
- mac_swap_node.index,
- hw0->output_node_index);
- hash_set (msm->next_node_index_by_sw_if_index,
- sw_if_index0, next0);
- }
- else
- next0 = p0[0];
- msm->cached_sw_if_index = sw_if_index0;
- msm->cached_next_index = next0;
- next1 = next0;
- }
- if (PREDICT_FALSE (msm->cached_sw_if_index != sw_if_index1))
- {
- p1 = hash_get (msm->next_node_index_by_sw_if_index, sw_if_index1);
- if (p1 == 0)
- {
- vnet_hw_interface_t *hw1;
-
- hw1 = vnet_get_sup_hw_interface (msm->vnet_main,
- sw_if_index1);
-
- next1 = vlib_node_add_next (msm->vlib_main,
- mac_swap_node.index,
- hw1->output_node_index);
- hash_set (msm->next_node_index_by_sw_if_index,
- sw_if_index1, next1);
- }
- else
- next1 = p1[0];
- msm->cached_sw_if_index = sw_if_index1;
- msm->cached_next_index = next1;
- }
-
- em->counters[node_counter_base_index + MAC_SWAP_ERROR_SWAPS] += 2;
-
- /* reset buffer so we always point at the MAC hdr */
- vlib_buffer_reset (b0);
- vlib_buffer_reset (b1);
- h0 = vlib_buffer_get_current (b0);
- h1 = vlib_buffer_get_current (b1);
-
- /* Swap 2 x src and dst mac addresses using 8-byte load/stores */
- tmp0a = clib_net_to_host_u64(((u64 *)(h0->dst_address))[0]);
- tmp1a = clib_net_to_host_u64(((u64 *)(h1->dst_address))[0]);
- tmp0b = clib_net_to_host_u64(((u64 *)(h0->src_address))[0]);
- tmp1b = clib_net_to_host_u64(((u64 *)(h1->src_address))[0]);
- ((u64 *)(h0->dst_address))[0] = clib_host_to_net_u64(tmp0b);
- ((u64 *)(h1->dst_address))[0] = clib_host_to_net_u64(tmp1b);
- /* Move the ethertype from "b" to "a" */
- tmp0a &= ~(0xFFFF);
- tmp1a &= ~(0xFFFF);
- tmp0a |= tmp0b & 0xFFFF;
- ((u64 *)(h0->src_address))[0] = clib_host_to_net_u64(tmp0a);
- tmp1a |= tmp1b & 0xFFFF;
- ((u64 *)(h1->src_address))[0] = clib_host_to_net_u64(tmp1a);
-
- if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)))
- {
- if (b0->flags & VLIB_BUFFER_IS_TRACED)
- {
- swap_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
- clib_memcpy (t->src, h0->src_address, 6);
- clib_memcpy (t->dst, h0->dst_address, 6);
- t->sw_if_index = sw_if_index0;
- t->next_index = next0;
- }
- if (b1->flags & VLIB_BUFFER_IS_TRACED)
- {
- swap_trace_t *t = vlib_add_trace (vm, node, b1, sizeof (*t));
- clib_memcpy (t->src, h1->src_address, 6);
- clib_memcpy (t->dst, h1->dst_address, 6);
- t->sw_if_index = sw_if_index1;
- t->next_index = next1;
- }
- }
-
- vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, bi1, next0, next1);
- }
-
+ sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+ next0 = msm->cached_next_index;
+ sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
+ next1 = msm->cached_next_index;
+
+ if (PREDICT_FALSE (msm->cached_sw_if_index != sw_if_index0))
+ {
+ p0 =
+ hash_get (msm->next_node_index_by_sw_if_index, sw_if_index0);
+ if (p0 == 0)
+ {
+ vnet_hw_interface_t *hw0;
+
+ hw0 = vnet_get_sup_hw_interface (msm->vnet_main,
+ sw_if_index0);
+
+ next0 = vlib_node_add_next (msm->vlib_main,
+ mac_swap_node.index,
+ hw0->output_node_index);
+ hash_set (msm->next_node_index_by_sw_if_index,
+ sw_if_index0, next0);
+ }
+ else
+ next0 = p0[0];
+ msm->cached_sw_if_index = sw_if_index0;
+ msm->cached_next_index = next0;
+ next1 = next0;
+ }
+ if (PREDICT_FALSE (msm->cached_sw_if_index != sw_if_index1))
+ {
+ p1 =
+ hash_get (msm->next_node_index_by_sw_if_index, sw_if_index1);
+ if (p1 == 0)
+ {
+ vnet_hw_interface_t *hw1;
+
+ hw1 = vnet_get_sup_hw_interface (msm->vnet_main,
+ sw_if_index1);
+
+ next1 = vlib_node_add_next (msm->vlib_main,
+ mac_swap_node.index,
+ hw1->output_node_index);
+ hash_set (msm->next_node_index_by_sw_if_index,
+ sw_if_index1, next1);
+ }
+ else
+ next1 = p1[0];
+ msm->cached_sw_if_index = sw_if_index1;
+ msm->cached_next_index = next1;
+ }
+
+ em->counters[node_counter_base_index + MAC_SWAP_ERROR_SWAPS] += 2;
+
+ /* reset buffer so we always point at the MAC hdr */
+ vlib_buffer_reset (b0);
+ vlib_buffer_reset (b1);
+ h0 = vlib_buffer_get_current (b0);
+ h1 = vlib_buffer_get_current (b1);
+
+ /* Swap 2 x src and dst mac addresses using 8-byte load/stores */
+ tmp0a = clib_net_to_host_u64 (((u64 *) (h0->dst_address))[0]);
+ tmp1a = clib_net_to_host_u64 (((u64 *) (h1->dst_address))[0]);
+ tmp0b = clib_net_to_host_u64 (((u64 *) (h0->src_address))[0]);
+ tmp1b = clib_net_to_host_u64 (((u64 *) (h1->src_address))[0]);
+ ((u64 *) (h0->dst_address))[0] = clib_host_to_net_u64 (tmp0b);
+ ((u64 *) (h1->dst_address))[0] = clib_host_to_net_u64 (tmp1b);
+ /* Move the ethertype from "b" to "a" */
+ tmp0a &= ~(0xFFFF);
+ tmp1a &= ~(0xFFFF);
+ tmp0a |= tmp0b & 0xFFFF;
+ ((u64 *) (h0->src_address))[0] = clib_host_to_net_u64 (tmp0a);
+ tmp1a |= tmp1b & 0xFFFF;
+ ((u64 *) (h1->src_address))[0] = clib_host_to_net_u64 (tmp1a);
+
+ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
+ {
+ if (b0->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ swap_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ clib_memcpy (t->src, h0->src_address, 6);
+ clib_memcpy (t->dst, h0->dst_address, 6);
+ t->sw_if_index = sw_if_index0;
+ t->next_index = next0;
+ }
+ if (b1->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ swap_trace_t *t =
+ vlib_add_trace (vm, node, b1, sizeof (*t));
+ clib_memcpy (t->src, h1->src_address, 6);
+ clib_memcpy (t->dst, h1->dst_address, 6);
+ t->sw_if_index = sw_if_index1;
+ t->next_index = next1;
+ }
+ }
+
+ 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;
- u32 next0;
- u32 sw_if_index0;
- uword * p0;
- u64 tmp0a, tmp0b;
- ethernet_header_t * h0;
+ u32 bi0;
+ vlib_buffer_t *b0;
+ u32 next0;
+ u32 sw_if_index0;
+ uword *p0;
+ u64 tmp0a, tmp0b;
+ ethernet_header_t *h0;
bi0 = from[0];
to_next[0] = bi0;
@@ -274,55 +279,57 @@ mac_swap_node_fn (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
- sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
- next0 = msm->cached_next_index;
-
- if (PREDICT_FALSE (msm->cached_sw_if_index != sw_if_index0))
- {
- p0 = hash_get (msm->next_node_index_by_sw_if_index, sw_if_index0);
- if (p0 == 0)
- {
- vnet_hw_interface_t *hw0;
-
- hw0 = vnet_get_sup_hw_interface (msm->vnet_main,
- sw_if_index0);
-
- next0 = vlib_node_add_next (msm->vlib_main,
- mac_swap_node.index,
- hw0->output_node_index);
- hash_set (msm->next_node_index_by_sw_if_index,
- sw_if_index0, next0);
- }
- else
- next0 = p0[0];
- msm->cached_sw_if_index = sw_if_index0;
- msm->cached_next_index = next0;
- }
-
- em->counters[node_counter_base_index + MAC_SWAP_ERROR_SWAPS] += 1;
-
- /* reset buffer so we always point at the MAC hdr */
- vlib_buffer_reset (b0);
- h0 = vlib_buffer_get_current (b0);
-
- /* Exchange src and dst, preserve the ethertype */
- tmp0a = clib_net_to_host_u64(((u64 *)(h0->dst_address))[0]);
- tmp0b = clib_net_to_host_u64(((u64 *)(h0->src_address))[0]);
- ((u64 *)(h0->dst_address))[0] = clib_host_to_net_u64(tmp0b);
- tmp0a &= ~(0xFFFF);
- tmp0a |= tmp0b & 0xFFFF;
- ((u64 *)(h0->src_address))[0] = clib_host_to_net_u64(tmp0a);
-
- /* ship it */
- if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
- && (b0->flags & VLIB_BUFFER_IS_TRACED))) {
- swap_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
- clib_memcpy (t->src, h0->src_address, 6);
- clib_memcpy (t->dst, h0->dst_address, 6);
- t->sw_if_index = sw_if_index0;
- t->next_index = next0;
- }
-
+ sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+ next0 = msm->cached_next_index;
+
+ if (PREDICT_FALSE (msm->cached_sw_if_index != sw_if_index0))
+ {
+ p0 =
+ hash_get (msm->next_node_index_by_sw_if_index, sw_if_index0);
+ if (p0 == 0)
+ {
+ vnet_hw_interface_t *hw0;
+
+ hw0 = vnet_get_sup_hw_interface (msm->vnet_main,
+ sw_if_index0);
+
+ next0 = vlib_node_add_next (msm->vlib_main,
+ mac_swap_node.index,
+ hw0->output_node_index);
+ hash_set (msm->next_node_index_by_sw_if_index,
+ sw_if_index0, next0);
+ }
+ else
+ next0 = p0[0];
+ msm->cached_sw_if_index = sw_if_index0;
+ msm->cached_next_index = next0;
+ }
+
+ em->counters[node_counter_base_index + MAC_SWAP_ERROR_SWAPS] += 1;
+
+ /* reset buffer so we always point at the MAC hdr */
+ vlib_buffer_reset (b0);
+ h0 = vlib_buffer_get_current (b0);
+
+ /* Exchange src and dst, preserve the ethertype */
+ tmp0a = clib_net_to_host_u64 (((u64 *) (h0->dst_address))[0]);
+ tmp0b = clib_net_to_host_u64 (((u64 *) (h0->src_address))[0]);
+ ((u64 *) (h0->dst_address))[0] = clib_host_to_net_u64 (tmp0b);
+ tmp0a &= ~(0xFFFF);
+ tmp0a |= tmp0b & 0xFFFF;
+ ((u64 *) (h0->src_address))[0] = clib_host_to_net_u64 (tmp0a);
+
+ /* ship it */
+ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
+ && (b0->flags & VLIB_BUFFER_IS_TRACED)))
+ {
+ swap_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
+ clib_memcpy (t->src, h0->src_address, 6);
+ clib_memcpy (t->dst, h0->dst_address, 6);
+ t->sw_if_index = sw_if_index0;
+ t->next_index = next0;
+ }
+
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
@@ -334,6 +341,7 @@ mac_swap_node_fn (vlib_main_t * vm,
return frame->n_vectors;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (mac_swap_node,static) = {
.function = mac_swap_node_fn,
.name = "mac-swap",
@@ -351,30 +359,39 @@ VLIB_REGISTER_NODE (mac_swap_node,static) = {
[MAC_SWAP_NEXT_DROP] = "error-drop",
},
};
+/* *INDENT-ON* */
-clib_error_t *mac_swap_init (vlib_main_t *vm)
+clib_error_t *
+mac_swap_init (vlib_main_t * vm)
{
- mac_swap_main_t * msm = &mac_swap_main;
-
+ mac_swap_main_t *msm = &mac_swap_main;
+
msm->next_node_index_by_sw_if_index = hash_create (0, sizeof (uword));
- msm->cached_next_index = (u32)~0;
- msm->cached_sw_if_index = (u32)~0;
+ msm->cached_next_index = (u32) ~ 0;
+ msm->cached_sw_if_index = (u32) ~ 0;
msm->vlib_main = vm;
- msm->vnet_main = vnet_get_main();
+ msm->vnet_main = vnet_get_main ();
/* Driver RX nodes send pkts here... */
#define _(a) ixge_set_next_node (IXGE_RX_NEXT_##a##_INPUT, "mac-swap");
foreach_hw_driver_next
#undef _
#define _(a) ixgev_set_next_node (IXGEV_RX_NEXT_##a##_INPUT, "mac-swap");
- foreach_hw_driver_next
+ foreach_hw_driver_next
#undef _
#define _(a) ige_set_next_node (IGE_RX_NEXT_##a##_INPUT, "mac-swap");
- foreach_hw_driver_next
+ foreach_hw_driver_next
#undef _
-
- return 0;
+ return 0;
}
VLIB_INIT_FUNCTION (mac_swap_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/node.c b/vnet/vnet/ethernet/node.c
index eae0a2b4c7b..0261815a1c2 100644
--- a/vnet/vnet/ethernet/node.c
+++ b/vnet/vnet/ethernet/node.c
@@ -47,24 +47,27 @@
#define foreach_ethernet_input_next \
_ (PUNT, "error-punt") \
_ (DROP, "error-drop") \
- _ (LLC, "llc-input")
+ _ (LLC, "llc-input")
-typedef enum {
+typedef enum
+{
#define _(s,n) ETHERNET_INPUT_NEXT_##s,
foreach_ethernet_input_next
#undef _
- ETHERNET_INPUT_N_NEXT,
+ ETHERNET_INPUT_N_NEXT,
} ethernet_input_next_t;
-typedef struct {
+typedef struct
+{
u8 packet_data[32];
} ethernet_input_trace_t;
-static u8 * format_ethernet_input_trace (u8 * s, va_list * va)
+static u8 *
+format_ethernet_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 *);
- ethernet_input_trace_t * t = va_arg (*va, ethernet_input_trace_t *);
+ ethernet_input_trace_t *t = va_arg (*va, ethernet_input_trace_t *);
s = format (s, "%U", format_ethernet_header, t->packet_data);
@@ -73,7 +76,8 @@ static u8 * format_ethernet_input_trace (u8 * s, va_list * va)
vlib_node_registration_t ethernet_input_node;
-typedef enum {
+typedef enum
+{
ETHERNET_INPUT_VARIANT_ETHERNET,
ETHERNET_INPUT_VARIANT_ETHERNET_TYPE,
ETHERNET_INPUT_VARIANT_NOT_L2,
@@ -83,35 +87,37 @@ typedef enum {
// Parse the ethernet header to extract vlan tags and innermost ethertype
static_always_inline void
parse_header (ethernet_input_variant_t variant,
- vlib_buffer_t * b0,
- u16 * type,
- u16 * orig_type,
- u16 * outer_id,
- u16 * inner_id,
- u32 * match_flags) {
+ vlib_buffer_t * b0,
+ u16 * type,
+ u16 * orig_type,
+ u16 * outer_id, u16 * inner_id, u32 * match_flags)
+{
u8 vlan_count;
- if (variant == ETHERNET_INPUT_VARIANT_ETHERNET
- || variant == ETHERNET_INPUT_VARIANT_NOT_L2) {
- ethernet_header_t * e0;
+ if (variant == ETHERNET_INPUT_VARIANT_ETHERNET
+ || variant == ETHERNET_INPUT_VARIANT_NOT_L2)
+ {
+ ethernet_header_t *e0;
- e0 = (void *) (b0->data + b0->current_data);
+ e0 = (void *) (b0->data + b0->current_data);
- vnet_buffer (b0)->ethernet.start_of_ethernet_header = b0->current_data;
+ vnet_buffer (b0)->ethernet.start_of_ethernet_header = b0->current_data;
- vlib_buffer_advance (b0, sizeof (e0[0]));
+ vlib_buffer_advance (b0, sizeof (e0[0]));
- *type = clib_net_to_host_u16(e0->type);
- } else if (variant == ETHERNET_INPUT_VARIANT_ETHERNET_TYPE) {
- // here when prior node was LLC/SNAP processing
- u16 * e0;
+ *type = clib_net_to_host_u16 (e0->type);
+ }
+ else if (variant == ETHERNET_INPUT_VARIANT_ETHERNET_TYPE)
+ {
+ // here when prior node was LLC/SNAP processing
+ u16 *e0;
- e0 = (void *) (b0->data + b0->current_data);
+ e0 = (void *) (b0->data + b0->current_data);
- vlib_buffer_advance (b0, sizeof (e0[0]));
+ vlib_buffer_advance (b0, sizeof (e0[0]));
- *type = clib_net_to_host_u16(e0[0]);
- }
+ *type = clib_net_to_host_u16 (e0[0]);
+ }
// save for distinguishing between dot1q and dot1ad later
*orig_type = *type;
@@ -128,46 +134,48 @@ parse_header (ethernet_input_variant_t variant,
(*type == ETHERNET_TYPE_DOT1AD) ||
(*type == ETHERNET_TYPE_VLAN_9100) ||
(*type == ETHERNET_TYPE_VLAN_9200))
- {
- ethernet_vlan_header_t * h0;
- u16 tag;
-
- *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_1_TAG;
+ {
+ ethernet_vlan_header_t *h0;
+ u16 tag;
- h0 = (void *) (b0->data + b0->current_data);
+ *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_1_TAG;
- tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
+ h0 = (void *) (b0->data + b0->current_data);
- *outer_id = tag & 0xfff;
+ tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
- *type = clib_net_to_host_u16(h0->type);
+ *outer_id = tag & 0xfff;
- vlib_buffer_advance (b0, sizeof (h0[0]));
- vlan_count = 1;
+ *type = clib_net_to_host_u16 (h0->type);
- if (*type == ETHERNET_TYPE_VLAN) {
- // Double tagged packet
- *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_2_TAG;
+ vlib_buffer_advance (b0, sizeof (h0[0]));
+ vlan_count = 1;
- h0 = (void *) (b0->data + b0->current_data);
+ if (*type == ETHERNET_TYPE_VLAN)
+ {
+ // Double tagged packet
+ *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_2_TAG;
- tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
+ h0 = (void *) (b0->data + b0->current_data);
- *inner_id = tag & 0xfff;
+ tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
- *type = clib_net_to_host_u16(h0->type);
+ *inner_id = tag & 0xfff;
- vlib_buffer_advance (b0, sizeof (h0[0]));
- vlan_count = 2;
+ *type = clib_net_to_host_u16 (h0->type);
+
+ vlib_buffer_advance (b0, sizeof (h0[0]));
+ vlan_count = 2;
- if (*type == ETHERNET_TYPE_VLAN) {
- // More than double tagged packet
- *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_3_TAG;
- vlan_count = 3; // "unknown" number, aka, 3-or-more
- }
+ if (*type == ETHERNET_TYPE_VLAN)
+ {
+ // More than double tagged packet
+ *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_3_TAG;
+ vlan_count = 3; // "unknown" number, aka, 3-or-more
+ }
+ }
}
- }
- ethernet_buffer_set_vlan_count(b0, vlan_count);
+ ethernet_buffer_set_vlan_count (b0, vlan_count);
}
// Determine the subinterface for this packet, given the result of the
@@ -175,86 +183,103 @@ parse_header (ethernet_input_variant_t variant,
// matches first.
static_always_inline void
identify_subint (vnet_hw_interface_t * hi,
- vlib_buffer_t * b0,
- u32 match_flags,
- main_intf_t * main_intf,
- vlan_intf_t * vlan_intf,
- qinq_intf_t * qinq_intf,
- u32 * new_sw_if_index,
- u8 * error0,
- u32 * is_l2)
+ vlib_buffer_t * b0,
+ u32 match_flags,
+ main_intf_t * main_intf,
+ vlan_intf_t * vlan_intf,
+ qinq_intf_t * qinq_intf,
+ u32 * new_sw_if_index, u8 * error0, u32 * is_l2)
{
u32 matched;
- matched = eth_identify_subint (hi, b0, match_flags,
- main_intf, vlan_intf, qinq_intf,
- new_sw_if_index, error0, is_l2);
+ matched = eth_identify_subint (hi, b0, match_flags,
+ main_intf, vlan_intf, qinq_intf,
+ new_sw_if_index, error0, is_l2);
- if (matched) {
+ if (matched)
+ {
- // Perform L3 my-mac filter
- // A unicast packet arriving on an L3 interface must have a dmac matching the interface mac.
- // This is required for promiscuous mode, else we will forward packets we aren't supposed to.
- if (!(*is_l2)) {
- ethernet_header_t * e0;
- e0 = (void *) (b0->data + vnet_buffer (b0)->ethernet.start_of_ethernet_header);
+ // Perform L3 my-mac filter
+ // A unicast packet arriving on an L3 interface must have a dmac matching the interface mac.
+ // This is required for promiscuous mode, else we will forward packets we aren't supposed to.
+ if (!(*is_l2))
+ {
+ ethernet_header_t *e0;
+ e0 =
+ (void *) (b0->data +
+ vnet_buffer (b0)->ethernet.start_of_ethernet_header);
+
+ if (!(ethernet_address_cast (e0->dst_address)))
+ {
+ if (!eth_mac_equal ((u8 *) e0, hi->hw_address))
+ {
+ *error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
+ }
+ }
+ }
- if (!(ethernet_address_cast(e0->dst_address))) {
- if (!eth_mac_equal((u8 *)e0, hi->hw_address)) {
- *error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
- }
- }
+ // Check for down subinterface
+ *error0 = (*new_sw_if_index) != ~0 ? (*error0) : ETHERNET_ERROR_DOWN;
}
-
- // Check for down subinterface
- *error0 = (*new_sw_if_index) != ~0 ? (*error0) : ETHERNET_ERROR_DOWN;
- }
}
static_always_inline void
determine_next_node (ethernet_main_t * em,
- ethernet_input_variant_t variant,
- u32 is_l20,
- u32 type0,
- vlib_buffer_t * b0,
- u8 * error0,
- u8 * next0)
+ ethernet_input_variant_t variant,
+ u32 is_l20,
+ u32 type0, vlib_buffer_t * b0, u8 * error0, u8 * next0)
{
- if (PREDICT_FALSE (*error0 != ETHERNET_ERROR_NONE)) {
- // some error occurred
- *next0 = ETHERNET_INPUT_NEXT_DROP;
- } else if (is_l20) {
- *next0 = em->l2_next;
- // record the L2 len and reset the buffer so the L2 header is preserved
- vnet_buffer(b0)->l2.l2_len = b0->current_data;
- vlib_buffer_advance(b0, - ethernet_buffer_header_size(b0));
-
- // check for common IP/MPLS ethertypes
- } else if (type0 == ETHERNET_TYPE_IP4) {
- *next0 = em->l3_next.input_next_ip4;
- } else if (type0 == ETHERNET_TYPE_IP6) {
- *next0 = em->l3_next.input_next_ip6;
- } else if (type0 == ETHERNET_TYPE_MPLS_UNICAST) {
- *next0 = em->l3_next.input_next_mpls;
-
- } else if (em->redirect_l3) {
- // L3 Redirect is on, the cached common next nodes will be
- // pointing to the redirect node, catch the uncommon types here
- *next0 = em->redirect_l3_next;
- } else {
- // uncommon ethertype, check table
- u32 i0;
- i0 = sparse_vec_index (em->l3_next.input_next_by_type, type0);
- *next0 = vec_elt (em->l3_next.input_next_by_type, i0);
- *error0 = i0 == SPARSE_VEC_INVALID_INDEX ? ETHERNET_ERROR_UNKNOWN_TYPE : *error0;
-
- // The table is not populated with LLC values, so check that now.
- // If variant is variant_ethernet then we came from LLC processing. Don't
- // go back there; drop instead using by keeping the drop/bad table result.
- if ((type0 < 0x600) && (variant == ETHERNET_INPUT_VARIANT_ETHERNET)) {
- *next0 = ETHERNET_INPUT_NEXT_LLC;
+ if (PREDICT_FALSE (*error0 != ETHERNET_ERROR_NONE))
+ {
+ // some error occurred
+ *next0 = ETHERNET_INPUT_NEXT_DROP;
+ }
+ else if (is_l20)
+ {
+ *next0 = em->l2_next;
+ // record the L2 len and reset the buffer so the L2 header is preserved
+ vnet_buffer (b0)->l2.l2_len = b0->current_data;
+ vlib_buffer_advance (b0, -ethernet_buffer_header_size (b0));
+
+ // check for common IP/MPLS ethertypes
+ }
+ else if (type0 == ETHERNET_TYPE_IP4)
+ {
+ *next0 = em->l3_next.input_next_ip4;
+ }
+ else if (type0 == ETHERNET_TYPE_IP6)
+ {
+ *next0 = em->l3_next.input_next_ip6;
+ }
+ else if (type0 == ETHERNET_TYPE_MPLS_UNICAST)
+ {
+ *next0 = em->l3_next.input_next_mpls;
+
+ }
+ else if (em->redirect_l3)
+ {
+ // L3 Redirect is on, the cached common next nodes will be
+ // pointing to the redirect node, catch the uncommon types here
+ *next0 = em->redirect_l3_next;
+ }
+ else
+ {
+ // uncommon ethertype, check table
+ u32 i0;
+ i0 = sparse_vec_index (em->l3_next.input_next_by_type, type0);
+ *next0 = vec_elt (em->l3_next.input_next_by_type, i0);
+ *error0 =
+ i0 ==
+ SPARSE_VEC_INVALID_INDEX ? ETHERNET_ERROR_UNKNOWN_TYPE : *error0;
+
+ // The table is not populated with LLC values, so check that now.
+ // If variant is variant_ethernet then we came from LLC processing. Don't
+ // go back there; drop instead using by keeping the drop/bad table result.
+ if ((type0 < 0x600) && (variant == ETHERNET_INPUT_VARIANT_ETHERNET))
+ {
+ *next0 = ETHERNET_INPUT_NEXT_LLC;
+ }
}
- }
}
static_always_inline uword
@@ -263,12 +288,12 @@ ethernet_input_inline (vlib_main_t * vm,
vlib_frame_t * from_frame,
ethernet_input_variant_t variant)
{
- vnet_main_t * vnm = vnet_get_main();
- ethernet_main_t * em = &ethernet_main;
- vlib_node_runtime_t * error_node;
- u32 n_left_from, next_index, * from, * to_next;
+ vnet_main_t *vnm = vnet_get_main ();
+ ethernet_main_t *em = &ethernet_main;
+ vlib_node_runtime_t *error_node;
+ u32 n_left_from, next_index, *from, *to_next;
u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
- u32 cpu_index = os_get_cpu_number();
+ u32 cpu_index = os_get_cpu_number ();
if (variant != ETHERNET_INPUT_VARIANT_ETHERNET)
error_node = vlib_node_get_runtime (vm, ethernet_input_node.index);
@@ -298,21 +323,22 @@ ethernet_input_inline (vlib_main_t * vm,
while (n_left_from >= 4 && n_left_to_next >= 2)
{
u32 bi0, bi1;
- vlib_buffer_t * b0, * b1;
+ vlib_buffer_t *b0, *b1;
u8 next0, next1, error0, error1;
- u16 type0, orig_type0, type1, orig_type1;
- u16 outer_id0, inner_id0, outer_id1, inner_id1;
- u32 match_flags0, match_flags1;
- u32 old_sw_if_index0, new_sw_if_index0, len0, old_sw_if_index1, new_sw_if_index1, len1;
- vnet_hw_interface_t * hi0, * hi1;
- main_intf_t * main_intf0, * main_intf1;
- vlan_intf_t * vlan_intf0, * vlan_intf1;
- qinq_intf_t * qinq_intf0, * qinq_intf1;
- u32 is_l20, is_l21;
+ u16 type0, orig_type0, type1, orig_type1;
+ u16 outer_id0, inner_id0, outer_id1, inner_id1;
+ u32 match_flags0, match_flags1;
+ u32 old_sw_if_index0, new_sw_if_index0, len0, old_sw_if_index1,
+ new_sw_if_index1, len1;
+ vnet_hw_interface_t *hi0, *hi1;
+ main_intf_t *main_intf0, *main_intf1;
+ vlan_intf_t *vlan_intf0, *vlan_intf1;
+ qinq_intf_t *qinq_intf0, *qinq_intf1;
+ u32 is_l20, is_l21;
/* 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]);
@@ -338,116 +364,110 @@ ethernet_input_inline (vlib_main_t * vm,
error0 = error1 = ETHERNET_ERROR_NONE;
- parse_header (variant,
- b0,
- &type0,
- &orig_type0,
- &outer_id0,
- &inner_id0,
- &match_flags0);
-
- parse_header (variant,
- b1,
- &type1,
- &orig_type1,
- &outer_id1,
- &inner_id1,
- &match_flags1);
-
- old_sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
- old_sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
-
- eth_vlan_table_lookups (em,
- vnm,
- old_sw_if_index0,
- orig_type0,
- outer_id0,
- inner_id0,
- &hi0,
- &main_intf0,
- &vlan_intf0,
- &qinq_intf0);
-
- eth_vlan_table_lookups (em,
- vnm,
- old_sw_if_index1,
- orig_type1,
- outer_id1,
- inner_id1,
- &hi1,
- &main_intf1,
- &vlan_intf1,
- &qinq_intf1);
+ parse_header (variant,
+ b0,
+ &type0,
+ &orig_type0, &outer_id0, &inner_id0, &match_flags0);
+
+ parse_header (variant,
+ b1,
+ &type1,
+ &orig_type1, &outer_id1, &inner_id1, &match_flags1);
+
+ old_sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+ old_sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
+
+ eth_vlan_table_lookups (em,
+ vnm,
+ old_sw_if_index0,
+ orig_type0,
+ outer_id0,
+ inner_id0,
+ &hi0,
+ &main_intf0, &vlan_intf0, &qinq_intf0);
+
+ eth_vlan_table_lookups (em,
+ vnm,
+ old_sw_if_index1,
+ orig_type1,
+ outer_id1,
+ inner_id1,
+ &hi1,
+ &main_intf1, &vlan_intf1, &qinq_intf1);
identify_subint (hi0,
- b0,
- match_flags0,
- main_intf0,
- vlan_intf0,
- qinq_intf0,
- &new_sw_if_index0,
- &error0,
- &is_l20);
+ b0,
+ match_flags0,
+ main_intf0,
+ vlan_intf0,
+ qinq_intf0, &new_sw_if_index0, &error0, &is_l20);
identify_subint (hi1,
- b1,
- match_flags1,
- main_intf1,
- vlan_intf1,
- qinq_intf1,
- &new_sw_if_index1,
- &error1,
- &is_l21);
-
- // Save RX sw_if_index for later nodes
- vnet_buffer (b0)->sw_if_index[VLIB_RX] = error0 != ETHERNET_ERROR_NONE ? old_sw_if_index0 : new_sw_if_index0;
- vnet_buffer (b1)->sw_if_index[VLIB_RX] = error1 != ETHERNET_ERROR_NONE ? old_sw_if_index1 : new_sw_if_index1;
-
- // Check if there is a stat to take (valid and non-main sw_if_index for pkt 0 or pkt 1)
- if (((new_sw_if_index0 != ~0) && (new_sw_if_index0 != old_sw_if_index0)) ||
- ((new_sw_if_index1 != ~0) && (new_sw_if_index1 != old_sw_if_index1))) {
-
- len0 = vlib_buffer_length_in_chain (vm, b0) + b0->current_data
- - vnet_buffer (b0)->ethernet.start_of_ethernet_header;
- len1 = vlib_buffer_length_in_chain (vm, b1) + b1->current_data
- - vnet_buffer (b1)->ethernet.start_of_ethernet_header;
-
- stats_n_packets += 2;
- stats_n_bytes += len0 + len1;
-
- if (PREDICT_FALSE (! (new_sw_if_index0 == stats_sw_if_index && new_sw_if_index1 == stats_sw_if_index)))
+ b1,
+ match_flags1,
+ main_intf1,
+ vlan_intf1,
+ qinq_intf1, &new_sw_if_index1, &error1, &is_l21);
+
+ // Save RX sw_if_index for later nodes
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] =
+ error0 !=
+ ETHERNET_ERROR_NONE ? old_sw_if_index0 : new_sw_if_index0;
+ vnet_buffer (b1)->sw_if_index[VLIB_RX] =
+ error1 !=
+ ETHERNET_ERROR_NONE ? old_sw_if_index1 : new_sw_if_index1;
+
+ // Check if there is a stat to take (valid and non-main sw_if_index for pkt 0 or pkt 1)
+ if (((new_sw_if_index0 != ~0)
+ && (new_sw_if_index0 != old_sw_if_index0))
+ || ((new_sw_if_index1 != ~0)
+ && (new_sw_if_index1 != old_sw_if_index1)))
+ {
+
+ len0 = vlib_buffer_length_in_chain (vm, b0) + b0->current_data
+ - vnet_buffer (b0)->ethernet.start_of_ethernet_header;
+ len1 = vlib_buffer_length_in_chain (vm, b1) + b1->current_data
+ - vnet_buffer (b1)->ethernet.start_of_ethernet_header;
+
+ stats_n_packets += 2;
+ stats_n_bytes += len0 + len1;
+
+ if (PREDICT_FALSE
+ (!(new_sw_if_index0 == stats_sw_if_index
+ && new_sw_if_index1 == stats_sw_if_index)))
{
stats_n_packets -= 2;
stats_n_bytes -= len0 + len1;
- if (new_sw_if_index0 != old_sw_if_index0 && new_sw_if_index0 != ~0)
- vlib_increment_combined_counter
- (vnm->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- cpu_index,
- new_sw_if_index0,
- 1,
- len0);
- if (new_sw_if_index1 != old_sw_if_index1 && new_sw_if_index1 != ~0)
- vlib_increment_combined_counter
- (vnm->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- cpu_index,
- new_sw_if_index1,
- 1,
- len1);
+ if (new_sw_if_index0 != old_sw_if_index0
+ && new_sw_if_index0 != ~0)
+ vlib_increment_combined_counter (vnm->
+ interface_main.combined_sw_if_counters
+ +
+ VNET_INTERFACE_COUNTER_RX,
+ cpu_index,
+ new_sw_if_index0, 1,
+ len0);
+ if (new_sw_if_index1 != old_sw_if_index1
+ && new_sw_if_index1 != ~0)
+ vlib_increment_combined_counter (vnm->
+ interface_main.combined_sw_if_counters
+ +
+ VNET_INTERFACE_COUNTER_RX,
+ cpu_index,
+ new_sw_if_index1, 1,
+ len1);
if (new_sw_if_index0 == new_sw_if_index1)
{
if (stats_n_packets > 0)
{
- vlib_increment_combined_counter
- (vnm->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- cpu_index,
- stats_sw_if_index,
- stats_n_packets,
- stats_n_bytes);
+ vlib_increment_combined_counter
+ (vnm->interface_main.combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ cpu_index,
+ stats_sw_if_index,
+ stats_n_packets, stats_n_bytes);
stats_n_packets = stats_n_bytes = 0;
}
stats_sw_if_index = new_sw_if_index0;
@@ -455,44 +475,49 @@ ethernet_input_inline (vlib_main_t * vm,
}
}
- if (variant == ETHERNET_INPUT_VARIANT_NOT_L2)
- is_l20 = is_l21 = 0;
+ if (variant == ETHERNET_INPUT_VARIANT_NOT_L2)
+ is_l20 = is_l21 = 0;
+
+ determine_next_node (em, variant, is_l20, type0, b0, &error0,
+ &next0);
+ determine_next_node (em, variant, is_l21, type1, b1, &error1,
+ &next1);
- determine_next_node(em, variant, is_l20, type0, b0, &error0, &next0);
- determine_next_node(em, variant, is_l21, type1, b1, &error1, &next1);
-
b0->error = error_node->errors[error0];
b1->error = error_node->errors[error1];
- // verify speculative enqueue
- vlib_validate_buffer_enqueue_x2(vm,node,next_index,to_next,n_left_to_next,bi0,bi1,next0,next1);
+ // verify speculative enqueue
+ 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;
+ vlib_buffer_t *b0;
u8 error0, next0;
- u16 type0, orig_type0;
- u16 outer_id0, inner_id0;
- u32 match_flags0;
- u32 old_sw_if_index0, new_sw_if_index0, len0;
- vnet_hw_interface_t * hi0;
- main_intf_t * main_intf0;
- vlan_intf_t * vlan_intf0;
- qinq_intf_t * qinq_intf0;
- u32 is_l20;
-
- // Prefetch next iteration
- if (n_left_from > 1) {
- vlib_buffer_t * p2;
-
- p2 = vlib_get_buffer (vm, from[1]);
- vlib_prefetch_buffer_header (p2, STORE);
- CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
- }
+ u16 type0, orig_type0;
+ u16 outer_id0, inner_id0;
+ u32 match_flags0;
+ u32 old_sw_if_index0, new_sw_if_index0, len0;
+ vnet_hw_interface_t *hi0;
+ main_intf_t *main_intf0;
+ vlan_intf_t *vlan_intf0;
+ qinq_intf_t *qinq_intf0;
+ u32 is_l20;
+
+ // Prefetch next iteration
+ if (n_left_from > 1)
+ {
+ vlib_buffer_t *p2;
+
+ p2 = vlib_get_buffer (vm, from[1]);
+ vlib_prefetch_buffer_header (p2, STORE);
+ CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ }
- bi0 = from[0];
+ bi0 = from[0];
to_next[0] = bi0;
from += 1;
to_next += 1;
@@ -503,93 +528,87 @@ ethernet_input_inline (vlib_main_t * vm,
error0 = ETHERNET_ERROR_NONE;
- parse_header (variant,
- b0,
- &type0,
- &orig_type0,
- &outer_id0,
- &inner_id0,
- &match_flags0);
-
- old_sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
-
- eth_vlan_table_lookups (em,
- vnm,
- old_sw_if_index0,
- orig_type0,
- outer_id0,
- inner_id0,
- &hi0,
- &main_intf0,
- &vlan_intf0,
- &qinq_intf0);
+ parse_header (variant,
+ b0,
+ &type0,
+ &orig_type0, &outer_id0, &inner_id0, &match_flags0);
+
+ old_sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+
+ eth_vlan_table_lookups (em,
+ vnm,
+ old_sw_if_index0,
+ orig_type0,
+ outer_id0,
+ inner_id0,
+ &hi0,
+ &main_intf0, &vlan_intf0, &qinq_intf0);
identify_subint (hi0,
- b0,
- match_flags0,
- main_intf0,
- vlan_intf0,
- qinq_intf0,
- &new_sw_if_index0,
- &error0,
- &is_l20);
-
- // Save RX sw_if_index for later nodes
- vnet_buffer (b0)->sw_if_index[VLIB_RX] = error0 != ETHERNET_ERROR_NONE ? old_sw_if_index0 : new_sw_if_index0;
-
- // Increment subinterface stats
- // Note that interface-level counters have already been incremented
- // prior to calling this function. Thus only subinterface counters
- // are incremented here.
- //
- // Interface level counters include packets received on the main
- // interface and all subinterfaces. Subinterface level counters
- // include only those packets received on that subinterface
+ b0,
+ match_flags0,
+ main_intf0,
+ vlan_intf0,
+ qinq_intf0, &new_sw_if_index0, &error0, &is_l20);
+
+ // Save RX sw_if_index for later nodes
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] =
+ error0 !=
+ ETHERNET_ERROR_NONE ? old_sw_if_index0 : new_sw_if_index0;
+
+ // Increment subinterface stats
+ // Note that interface-level counters have already been incremented
+ // prior to calling this function. Thus only subinterface counters
+ // are incremented here.
+ //
+ // Interface level counters include packets received on the main
+ // interface and all subinterfaces. Subinterface level counters
+ // include only those packets received on that subinterface
// Increment stats if the subint is valid and it is not the main intf
- if ((new_sw_if_index0 != ~0) && (new_sw_if_index0 != old_sw_if_index0)) {
-
- len0 = vlib_buffer_length_in_chain (vm, b0) + b0->current_data
- - vnet_buffer (b0)->ethernet.start_of_ethernet_header;
-
- stats_n_packets += 1;
- stats_n_bytes += len0;
-
- // Batch stat increments from the same subinterface so counters
- // don't need to be incremented for every packet.
- if (PREDICT_FALSE (new_sw_if_index0 != stats_sw_if_index)) {
- stats_n_packets -= 1;
- stats_n_bytes -= len0;
-
- if (new_sw_if_index0 != ~0)
- vlib_increment_combined_counter
- (vnm->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- cpu_index,
- new_sw_if_index0,
- 1,
- len0);
- if (stats_n_packets > 0) {
- vlib_increment_combined_counter
- (vnm->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- cpu_index,
- stats_sw_if_index,
- stats_n_packets,
- stats_n_bytes);
- stats_n_packets = stats_n_bytes = 0;
- }
- stats_sw_if_index = new_sw_if_index0;
+ if ((new_sw_if_index0 != ~0)
+ && (new_sw_if_index0 != old_sw_if_index0))
+ {
+
+ len0 = vlib_buffer_length_in_chain (vm, b0) + b0->current_data
+ - vnet_buffer (b0)->ethernet.start_of_ethernet_header;
+
+ stats_n_packets += 1;
+ stats_n_bytes += len0;
+
+ // Batch stat increments from the same subinterface so counters
+ // don't need to be incremented for every packet.
+ if (PREDICT_FALSE (new_sw_if_index0 != stats_sw_if_index))
+ {
+ stats_n_packets -= 1;
+ stats_n_bytes -= len0;
+
+ if (new_sw_if_index0 != ~0)
+ vlib_increment_combined_counter
+ (vnm->interface_main.combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ cpu_index, new_sw_if_index0, 1, len0);
+ if (stats_n_packets > 0)
+ {
+ vlib_increment_combined_counter
+ (vnm->interface_main.combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ cpu_index,
+ stats_sw_if_index, stats_n_packets, stats_n_bytes);
+ stats_n_packets = stats_n_bytes = 0;
+ }
+ stats_sw_if_index = new_sw_if_index0;
+ }
}
- }
- if (variant == ETHERNET_INPUT_VARIANT_NOT_L2)
- is_l20 = 0;
+ if (variant == ETHERNET_INPUT_VARIANT_NOT_L2)
+ is_l20 = 0;
+
+ determine_next_node (em, variant, is_l20, type0, b0, &error0,
+ &next0);
- determine_next_node(em, variant, is_l20, type0, b0, &error0, &next0);
+ b0->error = error_node->errors[error0];
- b0->error = error_node->errors[error0];
-
- // verify speculative enqueue
+ // verify speculative enqueue
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
@@ -598,16 +617,13 @@ ethernet_input_inline (vlib_main_t * vm,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- // Increment any remaining batched stats
- if (stats_n_packets > 0)
+ // Increment any remaining batched stats
+ if (stats_n_packets > 0)
{
- vlib_increment_combined_counter
- (vnm->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- cpu_index,
- stats_sw_if_index,
- stats_n_packets,
- stats_n_bytes);
+ vlib_increment_combined_counter
+ (vnm->interface_main.combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ cpu_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
node->runtime_data[0] = stats_sw_if_index;
}
@@ -616,21 +632,27 @@ ethernet_input_inline (vlib_main_t * vm,
static uword
ethernet_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
-{ return ethernet_input_inline (vm, node, from_frame, ETHERNET_INPUT_VARIANT_ETHERNET); }
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
+{
+ return ethernet_input_inline (vm, node, from_frame,
+ ETHERNET_INPUT_VARIANT_ETHERNET);
+}
static uword
ethernet_input_type (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
-{ return ethernet_input_inline (vm, node, from_frame, ETHERNET_INPUT_VARIANT_ETHERNET_TYPE); }
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
+{
+ return ethernet_input_inline (vm, node, from_frame,
+ ETHERNET_INPUT_VARIANT_ETHERNET_TYPE);
+}
static uword
ethernet_input_not_l2 (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
-{ return ethernet_input_inline (vm, node, from_frame, ETHERNET_INPUT_VARIANT_NOT_L2); }
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
+{
+ return ethernet_input_inline (vm, node, from_frame,
+ ETHERNET_INPUT_VARIANT_NOT_L2);
+}
// Return the subinterface config struct for the given sw_if_index
@@ -639,23 +661,24 @@ ethernet_input_not_l2 (vlib_main_t * vm,
// On error (unsupported or not ethernet) return 0.
static subint_config_t *
ethernet_sw_interface_get_config (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 * flags,
- u32 * unsupported) {
- ethernet_main_t * em = &ethernet_main;
- vnet_hw_interface_t * hi;
- vnet_sw_interface_t * si;
- main_intf_t * main_intf;
- vlan_table_t * vlan_table;
- qinq_table_t * qinq_table;
- subint_config_t * subint = 0;
-
+ u32 sw_if_index,
+ u32 * flags, u32 * unsupported)
+{
+ ethernet_main_t *em = &ethernet_main;
+ vnet_hw_interface_t *hi;
+ vnet_sw_interface_t *si;
+ main_intf_t *main_intf;
+ vlan_table_t *vlan_table;
+ qinq_table_t *qinq_table;
+ subint_config_t *subint = 0;
+
hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
- if (!hi || (hi->hw_class_index != ethernet_hw_interface_class.index)) {
- *unsupported = 0;
- goto done; // non-ethernet interface
- }
+ if (!hi || (hi->hw_class_index != ethernet_hw_interface_class.index))
+ {
+ *unsupported = 0;
+ goto done; // non-ethernet interface
+ }
// ensure there's an entry for the main intf (shouldn't really be necessary)
vec_validate (em->main_intfs, hi->hw_if_index);
@@ -664,123 +687,162 @@ ethernet_sw_interface_get_config (vnet_main_t * vnm,
// Locate the subint for the given ethernet config
si = vnet_get_sw_interface (vnm, sw_if_index);
- if (si->sub.eth.flags.default_sub) {
- subint = &main_intf->default_subint;
- *flags = SUBINT_CONFIG_MATCH_0_TAG |
- SUBINT_CONFIG_MATCH_1_TAG |
- SUBINT_CONFIG_MATCH_2_TAG |
- SUBINT_CONFIG_MATCH_3_TAG;
- } else if ((si->sub.eth.flags.no_tags) ||
- (si->sub.eth.raw_flags == 0)) {
- // if no flags are set then this is a main interface
- // so treat as untagged
- subint = &main_intf->untagged_subint;
- *flags = SUBINT_CONFIG_MATCH_0_TAG;
- } else {
- // one or two tags
- // first get the vlan table
- if (si->sub.eth.flags.dot1ad) {
- if (main_intf->dot1ad_vlans == 0) {
- // Allocate a vlan table from the pool
- pool_get(em->vlan_pool, vlan_table);
- main_intf->dot1ad_vlans = vlan_table - em->vlan_pool;
- } else {
- // Get ptr to existing vlan table
- vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1ad_vlans);
- }
- } else { // dot1q
- if (main_intf->dot1q_vlans == 0) {
- // Allocate a vlan table from the pool
- pool_get(em->vlan_pool, vlan_table);
- main_intf->dot1q_vlans = vlan_table - em->vlan_pool;
- } else {
- // Get ptr to existing vlan table
- vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1q_vlans);
- }
+ if (si->sub.eth.flags.default_sub)
+ {
+ subint = &main_intf->default_subint;
+ *flags = SUBINT_CONFIG_MATCH_0_TAG |
+ SUBINT_CONFIG_MATCH_1_TAG |
+ SUBINT_CONFIG_MATCH_2_TAG | SUBINT_CONFIG_MATCH_3_TAG;
}
+ else if ((si->sub.eth.flags.no_tags) || (si->sub.eth.raw_flags == 0))
+ {
+ // if no flags are set then this is a main interface
+ // so treat as untagged
+ subint = &main_intf->untagged_subint;
+ *flags = SUBINT_CONFIG_MATCH_0_TAG;
+ }
+ else
+ {
+ // one or two tags
+ // first get the vlan table
+ if (si->sub.eth.flags.dot1ad)
+ {
+ if (main_intf->dot1ad_vlans == 0)
+ {
+ // Allocate a vlan table from the pool
+ pool_get (em->vlan_pool, vlan_table);
+ main_intf->dot1ad_vlans = vlan_table - em->vlan_pool;
+ }
+ else
+ {
+ // Get ptr to existing vlan table
+ vlan_table =
+ vec_elt_at_index (em->vlan_pool, main_intf->dot1ad_vlans);
+ }
+ }
+ else
+ { // dot1q
+ if (main_intf->dot1q_vlans == 0)
+ {
+ // Allocate a vlan table from the pool
+ pool_get (em->vlan_pool, vlan_table);
+ main_intf->dot1q_vlans = vlan_table - em->vlan_pool;
+ }
+ else
+ {
+ // Get ptr to existing vlan table
+ vlan_table =
+ vec_elt_at_index (em->vlan_pool, main_intf->dot1q_vlans);
+ }
+ }
+
+ if (si->sub.eth.flags.one_tag)
+ {
+ *flags = si->sub.eth.flags.exact_match ?
+ SUBINT_CONFIG_MATCH_1_TAG :
+ (SUBINT_CONFIG_MATCH_1_TAG |
+ SUBINT_CONFIG_MATCH_2_TAG | SUBINT_CONFIG_MATCH_3_TAG);
+
+ if (si->sub.eth.flags.outer_vlan_id_any)
+ {
+ // not implemented yet
+ *unsupported = 1;
+ goto done;
+ }
+ else
+ {
+ // a single vlan, a common case
+ subint =
+ &vlan_table->vlans[si->sub.eth.
+ outer_vlan_id].single_tag_subint;
+ }
+
+ }
+ else
+ {
+ // Two tags
+ *flags = si->sub.eth.flags.exact_match ?
+ SUBINT_CONFIG_MATCH_2_TAG :
+ (SUBINT_CONFIG_MATCH_2_TAG | SUBINT_CONFIG_MATCH_3_TAG);
+
+ if (si->sub.eth.flags.outer_vlan_id_any
+ && si->sub.eth.flags.inner_vlan_id_any)
+ {
+ // not implemented yet
+ *unsupported = 1;
+ goto done;
+ }
- if (si->sub.eth.flags.one_tag) {
- *flags = si->sub.eth.flags.exact_match ?
- SUBINT_CONFIG_MATCH_1_TAG :
- (SUBINT_CONFIG_MATCH_1_TAG |
- SUBINT_CONFIG_MATCH_2_TAG |
- SUBINT_CONFIG_MATCH_3_TAG);
-
- if (si->sub.eth.flags.outer_vlan_id_any) {
- // not implemented yet
- *unsupported =1;
- goto done;
- } else {
- // a single vlan, a common case
- subint = &vlan_table->vlans[si->sub.eth.outer_vlan_id].single_tag_subint;
- }
-
- } else {
- // Two tags
- *flags = si->sub.eth.flags.exact_match ?
- SUBINT_CONFIG_MATCH_2_TAG :
- (SUBINT_CONFIG_MATCH_2_TAG |
- SUBINT_CONFIG_MATCH_3_TAG);
-
- if (si->sub.eth.flags.outer_vlan_id_any && si->sub.eth.flags.inner_vlan_id_any) {
- // not implemented yet
- *unsupported = 1;
- goto done;
- }
-
- if (si->sub.eth.flags.inner_vlan_id_any) {
- // a specific outer and "any" inner
- // don't need a qinq table for this
- subint = &vlan_table->vlans[si->sub.eth.outer_vlan_id].inner_any_subint;
- if (si->sub.eth.flags.exact_match) {
- *flags = SUBINT_CONFIG_MATCH_2_TAG;
- } else {
- *flags = SUBINT_CONFIG_MATCH_2_TAG |
- SUBINT_CONFIG_MATCH_3_TAG;
- }
- } else {
- // a specific outer + specifc innner vlan id, a common case
-
- // get the qinq table
- if (vlan_table->vlans[si->sub.eth.outer_vlan_id].qinqs == 0) {
- // Allocate a qinq table from the pool
- pool_get(em->qinq_pool, qinq_table);
- vlan_table->vlans[si->sub.eth.outer_vlan_id].qinqs = qinq_table - em->qinq_pool;
- } else {
- // Get ptr to existing qinq table
- qinq_table = vec_elt_at_index (em->qinq_pool, vlan_table->vlans[si->sub.eth.outer_vlan_id].qinqs);
- }
- subint = &qinq_table->vlans[si->sub.eth.inner_vlan_id].subint;
- }
+ if (si->sub.eth.flags.inner_vlan_id_any)
+ {
+ // a specific outer and "any" inner
+ // don't need a qinq table for this
+ subint =
+ &vlan_table->vlans[si->sub.eth.
+ outer_vlan_id].inner_any_subint;
+ if (si->sub.eth.flags.exact_match)
+ {
+ *flags = SUBINT_CONFIG_MATCH_2_TAG;
+ }
+ else
+ {
+ *flags = SUBINT_CONFIG_MATCH_2_TAG |
+ SUBINT_CONFIG_MATCH_3_TAG;
+ }
+ }
+ else
+ {
+ // a specific outer + specifc innner vlan id, a common case
+
+ // get the qinq table
+ if (vlan_table->vlans[si->sub.eth.outer_vlan_id].qinqs == 0)
+ {
+ // Allocate a qinq table from the pool
+ pool_get (em->qinq_pool, qinq_table);
+ vlan_table->vlans[si->sub.eth.outer_vlan_id].qinqs =
+ qinq_table - em->qinq_pool;
+ }
+ else
+ {
+ // Get ptr to existing qinq table
+ qinq_table =
+ vec_elt_at_index (em->qinq_pool,
+ vlan_table->vlans[si->sub.
+ eth.outer_vlan_id].
+ qinqs);
+ }
+ subint = &qinq_table->vlans[si->sub.eth.inner_vlan_id].subint;
+ }
+ }
}
- }
- done:
+done:
return subint;
}
clib_error_t *
-ethernet_sw_interface_up_down (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 flags)
+ethernet_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
{
- subint_config_t * subint;
+ subint_config_t *subint;
u32 dummy_flags;
u32 dummy_unsup;
- clib_error_t * error = 0;
+ clib_error_t *error = 0;
// Find the config for this subinterface
- subint = ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags, &dummy_unsup);
+ subint =
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags,
+ &dummy_unsup);
- if (subint == 0) {
- // not implemented yet or not ethernet
- goto done;
- }
+ if (subint == 0)
+ {
+ // not implemented yet or not ethernet
+ goto done;
+ }
subint->sw_if_index =
((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? sw_if_index : ~0);
- done:
+done:
return error;
}
@@ -789,44 +851,48 @@ VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ethernet_sw_interface_up_down);
// Set the L2/L3 mode for the subinterface
void
-ethernet_sw_interface_set_l2_mode (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 l2)
+ethernet_sw_interface_set_l2_mode (vnet_main_t * vnm, u32 sw_if_index, u32 l2)
{
subint_config_t *subint;
u32 dummy_flags;
u32 dummy_unsup;
int is_port;
- vnet_sw_interface_t * sw = vnet_get_sw_interface (vnm, sw_if_index);
+ vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, sw_if_index);
is_port = !(sw->type == VNET_SW_INTERFACE_TYPE_SUB);
// Find the config for this subinterface
- subint = ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags, &dummy_unsup);
+ subint =
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags,
+ &dummy_unsup);
- if (subint == 0) {
- // unimplemented or not ethernet
- goto done;
- }
+ if (subint == 0)
+ {
+ // unimplemented or not ethernet
+ goto done;
+ }
// Double check that the config we found is for our interface (or the interface is down)
ASSERT ((subint->sw_if_index == sw_if_index) | (subint->sw_if_index == ~0));
- if (l2) {
- subint->flags |= SUBINT_CONFIG_L2;
- if (is_port)
- subint->flags |=
- SUBINT_CONFIG_MATCH_0_TAG | SUBINT_CONFIG_MATCH_1_TAG
- | SUBINT_CONFIG_MATCH_2_TAG | SUBINT_CONFIG_MATCH_3_TAG;
- } else {
- subint->flags &= ~SUBINT_CONFIG_L2;
- if (is_port)
- subint->flags &=
- ~(SUBINT_CONFIG_MATCH_1_TAG | SUBINT_CONFIG_MATCH_2_TAG
- | SUBINT_CONFIG_MATCH_3_TAG);
- }
+ if (l2)
+ {
+ subint->flags |= SUBINT_CONFIG_L2;
+ if (is_port)
+ subint->flags |=
+ SUBINT_CONFIG_MATCH_0_TAG | SUBINT_CONFIG_MATCH_1_TAG
+ | SUBINT_CONFIG_MATCH_2_TAG | SUBINT_CONFIG_MATCH_3_TAG;
+ }
+ else
+ {
+ subint->flags &= ~SUBINT_CONFIG_L2;
+ if (is_port)
+ subint->flags &=
+ ~(SUBINT_CONFIG_MATCH_1_TAG | SUBINT_CONFIG_MATCH_2_TAG
+ | SUBINT_CONFIG_MATCH_3_TAG);
+ }
- done:
+done:
return;
}
@@ -835,20 +901,22 @@ ethernet_sw_interface_set_l2_mode (vnet_main_t * vnm,
*/
void
ethernet_sw_interface_set_l2_mode_noport (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 l2)
+ u32 sw_if_index, u32 l2)
{
subint_config_t *subint;
u32 dummy_flags;
u32 dummy_unsup;
/* Find the config for this subinterface */
- subint = ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags, &dummy_unsup);
+ subint =
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags,
+ &dummy_unsup);
- if (subint == 0) {
- /* unimplemented or not ethernet */
- goto done;
- }
+ if (subint == 0)
+ {
+ /* unimplemented or not ethernet */
+ goto done;
+ }
/*
* Double check that the config we found is for our interface (or the
@@ -856,94 +924,105 @@ ethernet_sw_interface_set_l2_mode_noport (vnet_main_t * vnm,
*/
ASSERT ((subint->sw_if_index == sw_if_index) | (subint->sw_if_index == ~0));
- if (l2) {
- subint->flags |= SUBINT_CONFIG_L2;
- } else {
- subint->flags &= ~SUBINT_CONFIG_L2;
- }
+ if (l2)
+ {
+ subint->flags |= SUBINT_CONFIG_L2;
+ }
+ else
+ {
+ subint->flags &= ~SUBINT_CONFIG_L2;
+ }
- done:
+done:
return;
}
static clib_error_t *
ethernet_sw_interface_add_del (vnet_main_t * vnm,
- u32 sw_if_index,
- u32 is_create)
+ u32 sw_if_index, u32 is_create)
{
- clib_error_t * error = 0;
+ clib_error_t *error = 0;
subint_config_t *subint;
u32 match_flags;
- u32 unsupported=0;
+ u32 unsupported = 0;
// Find the config for this subinterface
- subint = ethernet_sw_interface_get_config (vnm, sw_if_index, &match_flags, &unsupported);
+ subint =
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &match_flags,
+ &unsupported);
- if (subint == 0) {
- // not implemented yet or not ethernet
- if (unsupported) {
- // this is the NYI case
- error = clib_error_return (0, "not implemented yet");
+ if (subint == 0)
+ {
+ // not implemented yet or not ethernet
+ if (unsupported)
+ {
+ // this is the NYI case
+ error = clib_error_return (0, "not implemented yet");
+ }
+ goto done;
}
- goto done;
- }
- if (!is_create) {
- subint->flags = 0;
- return error;
- }
+ if (!is_create)
+ {
+ subint->flags = 0;
+ return error;
+ }
// Initialize the subint
- if (subint->flags & SUBINT_CONFIG_VALID) {
- // Error vlan already in use
- error = clib_error_return (0, "vlan is already in use");
- } else {
- // Note that config is L3 by defaulty
- subint->flags = SUBINT_CONFIG_VALID | match_flags;
- subint->sw_if_index = ~0; // because interfaces are initially down
- }
+ if (subint->flags & SUBINT_CONFIG_VALID)
+ {
+ // Error vlan already in use
+ error = clib_error_return (0, "vlan is already in use");
+ }
+ else
+ {
+ // Note that config is L3 by defaulty
+ subint->flags = SUBINT_CONFIG_VALID | match_flags;
+ subint->sw_if_index = ~0; // because interfaces are initially down
+ }
- done:
+done:
return error;
}
VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ethernet_sw_interface_add_del);
-static char * ethernet_error_strings[] = {
+static char *ethernet_error_strings[] = {
#define ethernet_error(n,c,s) s,
#include "error.def"
#undef ethernet_error
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ethernet_input_node) = {
.function = ethernet_input,
.name = "ethernet-input",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
-
.n_errors = ETHERNET_N_ERROR,
.error_strings = ethernet_error_strings,
-
.n_next_nodes = ETHERNET_INPUT_N_NEXT,
.next_nodes = {
#define _(s,n) [ETHERNET_INPUT_NEXT_##s] = n,
foreach_ethernet_input_next
#undef _
},
-
.format_buffer = format_ethernet_header_with_length,
.format_trace = format_ethernet_input_trace,
.unformat_buffer = unformat_ethernet_header,
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_NODE_FUNCTION_MULTIARCH (ethernet_input_node, ethernet_input)
+/* *INDENT-ON* */
-VLIB_REGISTER_NODE (ethernet_input_type_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ethernet_input_type_node, static) = {
.function = ethernet_input_type,
.name = "ethernet-input-type",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
-
.n_next_nodes = ETHERNET_INPUT_N_NEXT,
.next_nodes = {
#define _(s,n) [ETHERNET_INPUT_NEXT_##s] = n,
@@ -951,15 +1030,18 @@ VLIB_REGISTER_NODE (ethernet_input_type_node,static) = {
#undef _
},
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_NODE_FUNCTION_MULTIARCH (ethernet_input_type_node, ethernet_input_type)
+/* *INDENT-ON* */
-VLIB_REGISTER_NODE (ethernet_input_not_l2_node,static) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ethernet_input_not_l2_node, static) = {
.function = ethernet_input_not_l2,
.name = "ethernet-input-not-l2",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
-
.n_next_nodes = ETHERNET_INPUT_N_NEXT,
.next_nodes = {
#define _(s,n) [ETHERNET_INPUT_NEXT_##s] = n,
@@ -967,17 +1049,23 @@ VLIB_REGISTER_NODE (ethernet_input_not_l2_node,static) = {
#undef _
},
};
+/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ethernet_input_not_l2_node, ethernet_input_not_l2)
-void ethernet_set_rx_redirect (vnet_main_t * vnm,
- vnet_hw_interface_t * hi,
- u32 enable)
+/* *INDENT-OFF* */
+VLIB_NODE_FUNCTION_MULTIARCH (ethernet_input_not_l2_node,
+ ethernet_input_not_l2)
+/* *INDENT-ON* */
+
+
+void
+ethernet_set_rx_redirect (vnet_main_t * vnm,
+ vnet_hw_interface_t * hi, u32 enable)
{
// Insure all packets go to ethernet-input (i.e. untagged ipv4 packets
// don't go directly to ip4-input)
- vnet_hw_interface_rx_redirect_to_node
- (vnm, hi->hw_if_index, enable ? ethernet_input_node.index : ~0);
+ vnet_hw_interface_rx_redirect_to_node
+ (vnm, hi->hw_if_index, enable ? ethernet_input_node.index : ~0);
}
@@ -985,44 +1073,47 @@ void ethernet_set_rx_redirect (vnet_main_t * vnm,
* Initialization and registration for the next_by_ethernet structure
*/
-clib_error_t * next_by_ethertype_init (next_by_ethertype_t * l3_next)
+clib_error_t *
+next_by_ethertype_init (next_by_ethertype_t * l3_next)
{
l3_next->input_next_by_type = sparse_vec_new
- (/* elt bytes */ sizeof (l3_next->input_next_by_type[0]),
+ ( /* elt bytes */ sizeof (l3_next->input_next_by_type[0]),
/* bits in index */ BITS (((ethernet_header_t *) 0)->type));
- vec_validate (l3_next->sparse_index_by_input_next_index, ETHERNET_INPUT_NEXT_DROP);
- vec_validate (l3_next->sparse_index_by_input_next_index, ETHERNET_INPUT_NEXT_PUNT);
- l3_next->sparse_index_by_input_next_index[ETHERNET_INPUT_NEXT_DROP]
- = SPARSE_VEC_INVALID_INDEX;
- l3_next->sparse_index_by_input_next_index[ETHERNET_INPUT_NEXT_PUNT]
- = SPARSE_VEC_INVALID_INDEX;
-
+ vec_validate (l3_next->sparse_index_by_input_next_index,
+ ETHERNET_INPUT_NEXT_DROP);
+ vec_validate (l3_next->sparse_index_by_input_next_index,
+ ETHERNET_INPUT_NEXT_PUNT);
+ l3_next->sparse_index_by_input_next_index[ETHERNET_INPUT_NEXT_DROP] =
+ SPARSE_VEC_INVALID_INDEX;
+ l3_next->sparse_index_by_input_next_index[ETHERNET_INPUT_NEXT_PUNT] =
+ SPARSE_VEC_INVALID_INDEX;
+
/*
* Make sure we don't wipe out an ethernet registration by mistake
* Can happen if init function ordering constraints are missing.
*/
if (CLIB_DEBUG > 0)
{
- ethernet_main_t * em = &ethernet_main;
- ASSERT(em->next_by_ethertype_register_called == 0);
+ ethernet_main_t *em = &ethernet_main;
+ ASSERT (em->next_by_ethertype_register_called == 0);
}
return 0;
}
// Add an ethertype -> next index mapping to the structure
-clib_error_t * next_by_ethertype_register (next_by_ethertype_t * l3_next,
- u32 ethertype,
- u32 next_index)
+clib_error_t *
+next_by_ethertype_register (next_by_ethertype_t * l3_next,
+ u32 ethertype, u32 next_index)
{
u32 i;
- u16 * n;
- ethernet_main_t * em = &ethernet_main;
+ u16 *n;
+ ethernet_main_t *em = &ethernet_main;
if (CLIB_DEBUG > 0)
{
- ethernet_main_t * em = &ethernet_main;
+ ethernet_main_t *em = &ethernet_main;
em->next_by_ethertype_register_called = 1;
}
@@ -1034,45 +1125,53 @@ clib_error_t * next_by_ethertype_register (next_by_ethertype_t * l3_next,
is updated. */
vec_validate (l3_next->sparse_index_by_input_next_index, next_index);
for (i = 1; i < vec_len (l3_next->input_next_by_type); i++)
- l3_next->sparse_index_by_input_next_index[l3_next->input_next_by_type[i]] = i;
+ l3_next->
+ sparse_index_by_input_next_index[l3_next->input_next_by_type[i]] = i;
// do not allow the cached next index's to be updated if L3
// redirect is enabled, as it will have overwritten them
- if (!em->redirect_l3) {
- // Cache common ethertypes directly
- if (ethertype == ETHERNET_TYPE_IP4) {
- l3_next->input_next_ip4 = next_index;
- } else if (ethertype == ETHERNET_TYPE_IP6) {
- l3_next->input_next_ip6 = next_index;
- } else if (ethertype == ETHERNET_TYPE_MPLS_UNICAST) {
- l3_next->input_next_mpls = next_index;
+ if (!em->redirect_l3)
+ {
+ // Cache common ethertypes directly
+ if (ethertype == ETHERNET_TYPE_IP4)
+ {
+ l3_next->input_next_ip4 = next_index;
+ }
+ else if (ethertype == ETHERNET_TYPE_IP6)
+ {
+ l3_next->input_next_ip6 = next_index;
+ }
+ else if (ethertype == ETHERNET_TYPE_MPLS_UNICAST)
+ {
+ l3_next->input_next_mpls = next_index;
+ }
}
- }
return 0;
}
-static clib_error_t * ethernet_input_init (vlib_main_t * vm)
+static clib_error_t *
+ethernet_input_init (vlib_main_t * vm)
{
- ethernet_main_t * em = &ethernet_main;
- __attribute__((unused)) vlan_table_t * invalid_vlan_table;
- __attribute__((unused)) qinq_table_t * invalid_qinq_table;
+ ethernet_main_t *em = &ethernet_main;
+ __attribute__ ((unused)) vlan_table_t *invalid_vlan_table;
+ __attribute__ ((unused)) qinq_table_t *invalid_qinq_table;
ethernet_setup_node (vm, ethernet_input_node.index);
ethernet_setup_node (vm, ethernet_input_type_node.index);
ethernet_setup_node (vm, ethernet_input_not_l2_node.index);
next_by_ethertype_init (&em->l3_next);
-
+
// Initialize pools and vector for vlan parsing
- vec_validate (em->main_intfs, 10); // 10 main interfaces
- pool_alloc(em->vlan_pool, 10);
- pool_alloc(em->qinq_pool, 1);
+ vec_validate (em->main_intfs, 10); // 10 main interfaces
+ pool_alloc (em->vlan_pool, 10);
+ pool_alloc (em->qinq_pool, 1);
// The first vlan pool will always be reserved for an invalid table
- pool_get(em->vlan_pool, invalid_vlan_table); // first id = 0
+ pool_get (em->vlan_pool, invalid_vlan_table); // first id = 0
// The first qinq pool will always be reserved for an invalid table
- pool_get(em->qinq_pool, invalid_qinq_table); // first id = 0
+ pool_get (em->qinq_pool, invalid_qinq_table); // first id = 0
return 0;
}
@@ -1081,32 +1180,26 @@ VLIB_INIT_FUNCTION (ethernet_input_init);
void
ethernet_register_input_type (vlib_main_t * vm,
- ethernet_type_t type,
- u32 node_index)
+ ethernet_type_t type, u32 node_index)
{
- ethernet_main_t * em = &ethernet_main;
- ethernet_type_info_t * ti;
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_type_info_t *ti;
u32 i;
{
- clib_error_t * error = vlib_call_init_function (vm, ethernet_init);
+ clib_error_t *error = vlib_call_init_function (vm, ethernet_init);
if (error)
clib_error_report (error);
}
ti = ethernet_get_type_info (em, type);
ti->node_index = node_index;
- ti->next_index = vlib_node_add_next (vm,
- ethernet_input_node.index,
- node_index);
- i = vlib_node_add_next (vm,
- ethernet_input_type_node.index,
- node_index);
+ ti->next_index = vlib_node_add_next (vm,
+ ethernet_input_node.index, node_index);
+ i = vlib_node_add_next (vm, ethernet_input_type_node.index, node_index);
ASSERT (i == ti->next_index);
- i = vlib_node_add_next (vm,
- ethernet_input_not_l2_node.index,
- node_index);
+ i = vlib_node_add_next (vm, ethernet_input_not_l2_node.index, node_index);
ASSERT (i == ti->next_index);
// Add the L3 node for this ethertype to the next nodes structure
@@ -1117,13 +1210,13 @@ ethernet_register_input_type (vlib_main_t * vm,
}
void
-ethernet_register_l2_input (vlib_main_t * vm,
- u32 node_index)
+ethernet_register_l2_input (vlib_main_t * vm, u32 node_index)
{
- ethernet_main_t * em = &ethernet_main;
+ ethernet_main_t *em = &ethernet_main;
u32 i;
- em->l2_next = vlib_node_add_next (vm, ethernet_input_node.index, node_index);
+ em->l2_next =
+ vlib_node_add_next (vm, ethernet_input_node.index, node_index);
/*
* Even if we never use these arcs, we have to align the next indices...
@@ -1132,24 +1225,21 @@ ethernet_register_l2_input (vlib_main_t * vm,
ASSERT (i == em->l2_next);
- i = vlib_node_add_next (vm,
- ethernet_input_not_l2_node.index,
- node_index);
+ i = vlib_node_add_next (vm, ethernet_input_not_l2_node.index, node_index);
ASSERT (i == em->l2_next);
}
// Register a next node for L3 redirect, and enable L3 redirect
void
-ethernet_register_l3_redirect (vlib_main_t * vm,
- u32 node_index)
+ethernet_register_l3_redirect (vlib_main_t * vm, u32 node_index)
{
- ethernet_main_t * em = &ethernet_main;
+ ethernet_main_t *em = &ethernet_main;
u32 i;
em->redirect_l3 = 1;
- em->redirect_l3_next = vlib_node_add_next(vm,
- ethernet_input_node.index,
- node_index);
+ em->redirect_l3_next = vlib_node_add_next (vm,
+ ethernet_input_node.index,
+ node_index);
/*
* Change the cached next nodes to the redirect node
*/
@@ -1164,3 +1254,11 @@ ethernet_register_l3_redirect (vlib_main_t * vm,
ASSERT (i == em->redirect_l3_next);
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/packet.h b/vnet/vnet/ethernet/packet.h
index b5d1dcba931..b50f9303f23 100644
--- a/vnet/vnet/ethernet/packet.h
+++ b/vnet/vnet/ethernet/packet.h
@@ -40,13 +40,15 @@
#ifndef included_ethernet_packet_h
#define included_ethernet_packet_h
-typedef enum {
+typedef enum
+{
#define ethernet_type(n,s) ETHERNET_TYPE_##s = n,
#include <vnet/ethernet/types.def>
#undef ethernet_type
} ethernet_type_t;
-typedef struct {
+typedef struct
+{
/* Source/destination address. */
u8 dst_address[6];
u8 src_address[6];
@@ -61,18 +63,25 @@ typedef struct {
/* I/G bit: individual (unicast)/group (broadcast/multicast). */
always_inline uword
ethernet_address_cast (u8 * a)
-{ return (a[0] >> 0) & 1; }
+{
+ return (a[0] >> 0) & 1;
+}
always_inline uword
ethernet_address_is_locally_administered (u8 * a)
-{ return (a[0] >> 1) & 1; }
+{
+ return (a[0] >> 1) & 1;
+}
always_inline void
ethernet_address_set_locally_administered (u8 * a)
-{ a[0] |= 1 << 1; }
+{
+ a[0] |= 1 << 1;
+}
/* For VLAN ethernet type. */
-typedef struct {
+typedef struct
+{
/* 3 bit priority, 1 bit CFI and 12 bit vlan id. */
u16 priority_cfi_and_id;
@@ -84,7 +93,8 @@ typedef struct {
/* VLAN with ethertype first and vlan id second */
-typedef struct {
+typedef struct
+{
/* vlan type */
u16 type;
@@ -93,3 +103,11 @@ typedef struct {
} ethernet_vlan_header_tv_t;
#endif /* included_ethernet_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/ethernet/pg.c b/vnet/vnet/ethernet/pg.c
index 838688db451..67ccfcf5fbe 100644
--- a/vnet/vnet/ethernet/pg.c
+++ b/vnet/vnet/ethernet/pg.c
@@ -41,7 +41,8 @@
#include <vnet/pg/pg.h>
#include <vnet/ethernet/ethernet.h>
-typedef struct {
+typedef struct
+{
pg_edit_t type;
pg_edit_t src_address;
pg_edit_t dst_address;
@@ -55,7 +56,8 @@ pg_ethernet_header_init (pg_ethernet_header_t * e)
pg_edit_init (&e->dst_address, ethernet_header_t, dst_address);
}
-typedef struct {
+typedef struct
+{
pg_edit_t type;
pg_edit_t id;
pg_edit_t cfi;
@@ -63,44 +65,40 @@ typedef struct {
} pg_ethernet_vlan_header_t;
static inline void
-pg_ethernet_vlan_header_init (pg_ethernet_vlan_header_t * v,
- int vlan_index)
+pg_ethernet_vlan_header_init (pg_ethernet_vlan_header_t * v, int vlan_index)
{
ASSERT (vlan_index < ARRAY_LEN (((ethernet_max_header_t *) 0)->vlan));
pg_edit_init (&v->type, ethernet_max_header_t, vlan[vlan_index].type);
pg_edit_init_bitfield (&v->id, ethernet_max_header_t,
- vlan[vlan_index].priority_cfi_and_id,
- 0, 12);
+ vlan[vlan_index].priority_cfi_and_id, 0, 12);
pg_edit_init_bitfield (&v->cfi, ethernet_max_header_t,
- vlan[vlan_index].priority_cfi_and_id,
- 12, 1);
+ vlan[vlan_index].priority_cfi_and_id, 12, 1);
pg_edit_init_bitfield (&v->priority, ethernet_max_header_t,
- vlan[vlan_index].priority_cfi_and_id,
- 13, 3);
+ vlan[vlan_index].priority_cfi_and_id, 13, 3);
}
uword
unformat_pg_ethernet_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_ethernet_header_t * e;
- pg_ethernet_vlan_header_t * v;
- pg_edit_t * ether_type_edit;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_ethernet_header_t *e;
+ pg_ethernet_vlan_header_t *v;
+ pg_edit_t *ether_type_edit;
u32 n_vlan, error, group_index;
-
+
e = pg_create_edit_group (s, sizeof (e[0]), sizeof (ethernet_header_t),
&group_index);
pg_ethernet_header_init (e);
error = 1;
- if (! unformat (input, "%U: %U -> %U",
- unformat_pg_edit,
- unformat_ethernet_type_net_byte_order, &e->type,
- unformat_pg_edit,
- unformat_ethernet_address, &e->src_address,
- unformat_pg_edit,
- unformat_ethernet_address, &e->dst_address))
+ if (!unformat (input, "%U: %U -> %U",
+ unformat_pg_edit,
+ unformat_ethernet_type_net_byte_order, &e->type,
+ unformat_pg_edit,
+ unformat_ethernet_address, &e->src_address,
+ unformat_pg_edit,
+ unformat_ethernet_address, &e->dst_address))
goto done;
n_vlan = 0;
@@ -110,16 +108,16 @@ unformat_pg_ethernet_header (unformat_input_t * input, va_list * args)
group_index);
pg_ethernet_vlan_header_init (v, n_vlan);
- if (! unformat_user (input, unformat_pg_edit,
- unformat_pg_number, &v->id))
+ if (!unformat_user (input, unformat_pg_edit,
+ unformat_pg_number, &v->id))
goto done;
- if (! unformat (input, "priority %U", unformat_pg_edit,
- unformat_pg_number, &v->priority))
+ if (!unformat (input, "priority %U", unformat_pg_edit,
+ unformat_pg_number, &v->priority))
pg_edit_set_fixed (&v->priority, 0);
- if (! unformat (input, "cfi %U", unformat_pg_edit,
- unformat_pg_number, &v->cfi))
+ if (!unformat (input, "cfi %U", unformat_pg_edit,
+ unformat_pg_number, &v->cfi))
pg_edit_set_fixed (&v->cfi, 0);
/* Too many vlans given. */
@@ -148,9 +146,9 @@ unformat_pg_ethernet_header (unformat_input_t * input, va_list * args)
}
{
- ethernet_main_t * em = &ethernet_main;
- ethernet_type_info_t * ti = 0;
- pg_node_t * pg_node = 0;
+ ethernet_main_t *em = &ethernet_main;
+ ethernet_type_info_t *ti = 0;
+ pg_node_t *pg_node = 0;
if (ether_type_edit->type == PG_EDIT_FIXED)
{
@@ -163,15 +161,23 @@ unformat_pg_ethernet_header (unformat_input_t * input, va_list * args)
if (pg_node && pg_node->unformat_edit
&& 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:
+ */