aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Uvarov <maxim.uvarov@linaro.org>2018-09-11 16:35:27 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-09-13 15:42:47 +0300
commitb44cbbbfc148261843b041fbb5b4ea8f8879f44e (patch)
tree5d2f83b25031aaccb4f9da6dcacc1617a417690c
parent461a16705242b1fd7e64b50fcaae57fce7cd7f79 (diff)
downloadodp-master.tar.gz
helper: iplookuptable fix puting values to tableHEADmaster
On putting values to table we have to validate input data and reject unaccepted data (cidr bits - Classless Inter-Domain Routing is in range of 0 to 32). Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
-rw-r--r--helper/iplookuptable.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/helper/iplookuptable.c b/helper/iplookuptable.c
index 61f63402..7102eb54 100644
--- a/helper/iplookuptable.c
+++ b/helper/iplookuptable.c
@@ -585,24 +585,25 @@ prefix_insert_into_lx(
odph_iplookup_table_impl *tbl, prefix_entry_t *entry,
uint8_t cidr, odp_buffer_t nexthop, uint8_t level)
{
- uint8_t ret = 0;
+ int ret = 0;
uint32_t i = 0, limit = (1 << (level - cidr));
prefix_entry_t *e = entry, *ne = NULL;
for (i = 0; i < limit; i++, e++) {
- if (e->child == 1) {
- if (e->cidr > cidr)
- continue;
+ if (e->cidr > cidr)
+ continue;
+ if (e->child == 1) {
e->cidr = cidr;
/* push to next level */
ne = (prefix_entry_t *)e->ptr;
ret = prefix_insert_into_lx(
tbl, ne, cidr, nexthop, cidr + 8);
+ if (ret == -1)
+ return -1;
+ if (ret == 0)
+ return ret;
} else {
- if (e->cidr > cidr)
- continue;
-
e->child = 0;
e->cidr = cidr;
e->nexthop = nexthop;
@@ -678,8 +679,9 @@ odph_iplookup_table_put_value(odph_table_t tbl, void *key, void *value)
nexthop = *((odp_buffer_t *)value);
- if (prefix->cidr == 0)
+ if (prefix->cidr == 0 || prefix->cidr > 32)
return -1;
+
prefix->ip = prefix->ip & (0xffffffff << (IP_LENGTH - prefix->cidr));
/* insert into trie */
@@ -899,7 +901,7 @@ odph_iplookup_table_remove_value(odph_table_t tbl, void *key)
ip = prefix->ip;
cidr = prefix->cidr;
- if (cidr == 0)
+ if (cidr == 0 || cidr > 32)
return -EINVAL;
prefix_entry_t *entry = &impl->l1e[ip >> 16];