summaryrefslogtreecommitdiffstats
path: root/src/plugins/gbp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/gbp')
-rw-r--r--src/plugins/gbp/gbp.api4
-rw-r--r--src/plugins/gbp/gbp_api.c11
-rw-r--r--src/plugins/gbp/gbp_contract.c46
3 files changed, 45 insertions, 16 deletions
diff --git a/src/plugins/gbp/gbp.api b/src/plugins/gbp/gbp.api
index 303ea1c15cc..ae45159d705 100644
--- a/src/plugins/gbp/gbp.api
+++ b/src/plugins/gbp/gbp.api
@@ -299,10 +299,10 @@ typedef gbp_contract
u16 sclass;
u16 dclass;
u32 acl_index;
+ u8 n_ether_types;
+ u16 allowed_ethertypes[16];
u8 n_rules;
vl_api_gbp_rule_t rules[n_rules];
- u8 n_ether_types;
- u16 allowed_ethertypes[n_ether_types];
};
autoreply define gbp_contract_add_del
diff --git a/src/plugins/gbp/gbp_api.c b/src/plugins/gbp/gbp_api.c
index 3f35555efd1..8878119d766 100644
--- a/src/plugins/gbp/gbp_api.c
+++ b/src/plugins/gbp/gbp_api.c
@@ -931,8 +931,7 @@ vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
u16 *allowed_ethertypes;
index_t *rules;
int ii, rv = 0;
- u8 *data, n_et;
- u16 *et;
+ u8 n_et;
if (mp->is_add)
{
@@ -944,19 +943,15 @@ vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
allowed_ethertypes = NULL;
/*
- * move past the variable legnth array of rules to get to the
* allowed ether types
*/
- data = (((u8 *) & mp->contract.n_ether_types) +
- (sizeof (mp->contract.rules[0]) * mp->contract.n_rules));
- n_et = *data;
- et = (u16 *) (++data);
+ n_et = mp->contract.n_ether_types;
vec_validate (allowed_ethertypes, n_et - 1);
for (ii = 0; ii < n_et; ii++)
{
/* leave the ether types in network order */
- allowed_ethertypes[ii] = et[ii];
+ allowed_ethertypes[ii] = mp->contract.allowed_ethertypes[ii];
}
rv = gbp_contract_update (ntohs (mp->contract.sclass),
diff --git a/src/plugins/gbp/gbp_contract.c b/src/plugins/gbp/gbp_contract.c
index 805e9b23d09..e4ac611b16e 100644
--- a/src/plugins/gbp/gbp_contract.c
+++ b/src/plugins/gbp/gbp_contract.c
@@ -612,8 +612,8 @@ format_gbp_contract (u8 * s, va_list * args)
gc = gbp_contract_get (gci);
- s = format (s, "%U: acl-index:%d",
- format_gbp_contract_key, &gc->gc_key, gc->gc_acl_index);
+ s = format (s, "[%d] %U: acl-index:%d",
+ gci, format_gbp_contract_key, &gc->gc_key, gc->gc_acl_index);
vec_foreach (gui, gc->gc_rules)
{
@@ -624,7 +624,8 @@ format_gbp_contract (u8 * s, va_list * args)
vec_foreach (et, gc->gc_allowed_ethertypes)
{
int host_et = clib_net_to_host_u16 (*et);
- s = format (s, "0x%x, ", host_et);
+ if (0 != host_et)
+ s = format (s, "0x%x, ", host_et);
}
s = format (s, "]");
@@ -635,14 +636,47 @@ static clib_error_t *
gbp_contract_show (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
+ gbp_contract_t *gc;
+ u32 src, dst;
index_t gci;
+ src = dst = SCLASS_INVALID;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "src %d", &src))
+ ;
+ else if (unformat (input, "dst %d", &dst))
+ ;
+ else
+ break;
+ }
+
vlib_cli_output (vm, "Contracts:");
/* *INDENT-OFF* */
- pool_foreach_index (gci, gbp_contract_pool,
+ pool_foreach (gc, gbp_contract_pool,
({
- vlib_cli_output (vm, " [%d] %U", gci, format_gbp_contract, gci);
+ gci = gc - gbp_contract_pool;
+
+ if (SCLASS_INVALID != src && SCLASS_INVALID != dst)
+ {
+ if (gc->gc_key.gck_src == src &&
+ gc->gc_key.gck_dst == dst)
+ vlib_cli_output (vm, " %U", format_gbp_contract, gci);
+ }
+ else if (SCLASS_INVALID != src)
+ {
+ if (gc->gc_key.gck_src == src)
+ vlib_cli_output (vm, " %U", format_gbp_contract, gci);
+ }
+ else if (SCLASS_INVALID != dst)
+ {
+ if (gc->gc_key.gck_dst == dst)
+ vlib_cli_output (vm, " %U", format_gbp_contract, gci);
+ }
+ else
+ vlib_cli_output (vm, " %U", format_gbp_contract, gci);
}));
/* *INDENT-ON* */
@@ -659,7 +693,7 @@ gbp_contract_show (vlib_main_t * vm,
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (gbp_contract_show_node, static) = {
.path = "show gbp contract",
- .short_help = "show gbp contract\n",
+ .short_help = "show gbp contract [src <SRC>] [dst <DST>]\n",
.function = gbp_contract_show,
};
/* *INDENT-ON* */