summaryrefslogtreecommitdiff
path: root/lib/table
diff options
context:
space:
mode:
authorRobin Jarry <[email protected]>2024-10-18 16:05:41 +0200
committerDavid Marchand <[email protected]>2024-10-18 17:47:01 +0200
commite1a06e391ba74f9c4d46a6ecef6d8ee084f4229e (patch)
treea544690f794554f85939fccc63ffedd7b1723a89 /lib/table
parent89b5642d0d45c22c0ceab57efe3fab3b49ff4324 (diff)
lpm6: use IPv6 address structure and utils
Replace ad-hoc uint8_t[16] array types in the API of rte_lpm6 with rte_ipv6_addr structures. Replace duplicate functions and macros with common ones from rte_ip6.h. Update all code accordingly. NB: the conversion between 16 bytes arrays and RTE_IPV6() literals was done automatically with the following python script and adjusted manually afterwards: import argparse import re import struct ip = re.compile( r""" \{ [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]*, [\s\t\r\n]*([\da-fA-Fx]+)[\s\t\r\n]* \} """, re.VERBOSE, ) def repl(match): u8 = bytes(int(g, 0) for g in match.groups("0")) nums = [] for u16 in struct.unpack("!HHHHHHHH", u8): if u16: nums.append(f"0x{u16:04x}") else: nums.append("0") return f"RTE_IPV6({', '.join(nums)})" p = argparse.ArgumentParser() p.add_argument("args", nargs="+") args = p.parse_args() for a in args.args: with open(a) as f: buf = f.read() buf = ip.sub(repl, buf) with open(a, "w") as f: f.write(buf) Signed-off-by: Robin Jarry <[email protected]>
Diffstat (limited to 'lib/table')
-rw-r--r--lib/table/rte_table_lpm_ipv6.c12
-rw-r--r--lib/table/rte_table_lpm_ipv6.h7
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/table/rte_table_lpm_ipv6.c b/lib/table/rte_table_lpm_ipv6.c
index c1a7412f92..dea11130d3 100644
--- a/lib/table/rte_table_lpm_ipv6.c
+++ b/lib/table/rte_table_lpm_ipv6.c
@@ -207,7 +207,7 @@ rte_table_lpm_ipv6_entry_add(
}
/* Check if rule is already present in the table */
- status = rte_lpm6_is_rule_present(lpm->lpm, ip_prefix->ip,
+ status = rte_lpm6_is_rule_present(lpm->lpm, &ip_prefix->ip,
ip_prefix->depth, &nht_pos0);
nht_pos0_valid = status > 0;
@@ -225,7 +225,7 @@ rte_table_lpm_ipv6_entry_add(
}
/* Add rule to low level LPM table */
- if (rte_lpm6_add(lpm->lpm, ip_prefix->ip, ip_prefix->depth,
+ if (rte_lpm6_add(lpm->lpm, &ip_prefix->ip, ip_prefix->depth,
nht_pos) < 0) {
TABLE_LOG(ERR, "%s: LPM IPv6 rule add failed", __func__);
return -1;
@@ -270,7 +270,7 @@ rte_table_lpm_ipv6_entry_delete(
}
/* Return if rule is not present in the table */
- status = rte_lpm6_is_rule_present(lpm->lpm, ip_prefix->ip,
+ status = rte_lpm6_is_rule_present(lpm->lpm, &ip_prefix->ip,
ip_prefix->depth, &nht_pos);
if (status < 0) {
TABLE_LOG(ERR, "%s: LPM IPv6 algorithmic error",
@@ -283,7 +283,7 @@ rte_table_lpm_ipv6_entry_delete(
}
/* Delete rule from the low-level LPM table */
- status = rte_lpm6_delete(lpm->lpm, ip_prefix->ip, ip_prefix->depth);
+ status = rte_lpm6_delete(lpm->lpm, &ip_prefix->ip, ip_prefix->depth);
if (status) {
TABLE_LOG(ERR, "%s: LPM IPv6 rule delete failed",
__func__);
@@ -323,11 +323,11 @@ rte_table_lpm_ipv6_lookup(
if (pkt_mask & pkts_mask) {
struct rte_mbuf *pkt = pkts[i];
- uint8_t *ip = RTE_MBUF_METADATA_UINT8_PTR(pkt,
- lpm->offset);
+ const struct rte_ipv6_addr *ip;
int status;
uint32_t nht_pos;
+ ip = (struct rte_ipv6_addr *)RTE_MBUF_METADATA_UINT8_PTR(pkt, lpm->offset);
status = rte_lpm6_lookup(lpm->lpm, ip, &nht_pos);
if (status == 0) {
pkts_out_mask |= pkt_mask;
diff --git a/lib/table/rte_table_lpm_ipv6.h b/lib/table/rte_table_lpm_ipv6.h
index 166a5ba9ee..3ea8883606 100644
--- a/lib/table/rte_table_lpm_ipv6.h
+++ b/lib/table/rte_table_lpm_ipv6.h
@@ -39,13 +39,16 @@
#include <stdint.h>
+#include <rte_common.h>
+#include <rte_ip6.h>
+
#include "rte_table.h"
#ifdef __cplusplus
extern "C" {
#endif
-#define RTE_LPM_IPV6_ADDR_SIZE 16
+#define RTE_LPM_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_LPM_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE)
/** LPM table parameters */
struct rte_table_lpm_ipv6_params {
@@ -73,7 +76,7 @@ each rule covering for a multitude of lookup keys (destination IP addresses)
that share the same data (next hop). */
struct rte_table_lpm_ipv6_key {
/** IP address */
- uint8_t ip[RTE_LPM_IPV6_ADDR_SIZE];
+ struct rte_ipv6_addr ip;
/** IP address depth. The most significant "depth" bits of the IP
address specify the network part of the IP address, while the rest of