summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRobin Jarry <[email protected]>2024-10-18 16:05:40 +0200
committerDavid Marchand <[email protected]>2024-10-18 17:47:00 +0200
commit89b5642d0d45c22c0ceab57efe3fab3b49ff4324 (patch)
treed269b6e818bb0c5660c6ae0f071a0f7d0b5359d5 /examples
parentca786def84caa9c4f1f36f516477e9a5f58389b5 (diff)
net: use IPv6 address structure for packet headers
The rte_ipv6_hdr uses ad-hoc uint8_t[16] arrays to represent addresses. Replace these arrays with the newly added rte_ipv6_addr structure. Adapt all code accordingly. Signed-off-by: Robin Jarry <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/ip_fragmentation/main.c2
-rw-r--r--examples/ip_pipeline/pipeline.c16
-rw-r--r--examples/ip_reassembly/main.c2
-rw-r--r--examples/ipsec-secgw/flow.c33
-rw-r--r--examples/ipsec-secgw/ipsec.c8
-rw-r--r--examples/ipsec-secgw/sa.c4
-rw-r--r--examples/ipsec-secgw/sad.h9
-rw-r--r--examples/l3fwd/l3fwd_fib.c2
-rw-r--r--examples/l3fwd/l3fwd_lpm.c4
9 files changed, 30 insertions, 50 deletions
diff --git a/examples/ip_fragmentation/main.c b/examples/ip_fragmentation/main.c
index 736eae6f05..4c0fa5054a 100644
--- a/examples/ip_fragmentation/main.c
+++ b/examples/ip_fragmentation/main.c
@@ -311,7 +311,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
ip_hdr = rte_pktmbuf_mtod(m, struct rte_ipv6_hdr *);
/* Find destination port */
- if (rte_lpm6_lookup(rxq->lpm6, ip_hdr->dst_addr,
+ if (rte_lpm6_lookup(rxq->lpm6, ip_hdr->dst_addr.a,
&next_hop) == 0 &&
(enabled_port_mask & 1 << next_hop) != 0) {
port_out = next_hop;
diff --git a/examples/ip_pipeline/pipeline.c b/examples/ip_pipeline/pipeline.c
index 63352257c6..792aab0059 100644
--- a/examples/ip_pipeline/pipeline.c
+++ b/examples/ip_pipeline/pipeline.c
@@ -637,7 +637,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 1,
.input_index = 1,
- .offset = offsetof(struct rte_ipv6_hdr, src_addr[0]),
+ .offset = offsetof(struct rte_ipv6_hdr, src_addr.a[0]),
},
[2] = {
@@ -645,7 +645,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 2,
.input_index = 2,
- .offset = offsetof(struct rte_ipv6_hdr, src_addr[4]),
+ .offset = offsetof(struct rte_ipv6_hdr, src_addr.a[4]),
},
[3] = {
@@ -653,7 +653,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 3,
.input_index = 3,
- .offset = offsetof(struct rte_ipv6_hdr, src_addr[8]),
+ .offset = offsetof(struct rte_ipv6_hdr, src_addr.a[8]),
},
[4] = {
@@ -661,7 +661,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 4,
.input_index = 4,
- .offset = offsetof(struct rte_ipv6_hdr, src_addr[12]),
+ .offset = offsetof(struct rte_ipv6_hdr, src_addr.a[12]),
},
/* Destination IP address (IPv6) */
@@ -670,7 +670,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 5,
.input_index = 5,
- .offset = offsetof(struct rte_ipv6_hdr, dst_addr[0]),
+ .offset = offsetof(struct rte_ipv6_hdr, dst_addr.a[0]),
},
[6] = {
@@ -678,7 +678,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 6,
.input_index = 6,
- .offset = offsetof(struct rte_ipv6_hdr, dst_addr[4]),
+ .offset = offsetof(struct rte_ipv6_hdr, dst_addr.a[4]),
},
[7] = {
@@ -686,7 +686,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 7,
.input_index = 7,
- .offset = offsetof(struct rte_ipv6_hdr, dst_addr[8]),
+ .offset = offsetof(struct rte_ipv6_hdr, dst_addr.a[8]),
},
[8] = {
@@ -694,7 +694,7 @@ static const struct rte_acl_field_def table_acl_field_format_ipv6[] = {
.size = sizeof(uint32_t),
.field_index = 8,
.input_index = 8,
- .offset = offsetof(struct rte_ipv6_hdr, dst_addr[12]),
+ .offset = offsetof(struct rte_ipv6_hdr, dst_addr.a[12]),
},
/* Source Port */
diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c
index c7019078f7..4da692eb23 100644
--- a/examples/ip_reassembly/main.c
+++ b/examples/ip_reassembly/main.c
@@ -400,7 +400,7 @@ reassemble(struct rte_mbuf *m, uint16_t portid, uint32_t queue,
}
/* Find destination port */
- if (rte_lpm6_lookup(rxq->lpm6, ip_hdr->dst_addr,
+ if (rte_lpm6_lookup(rxq->lpm6, ip_hdr->dst_addr.a,
&next_hop) == 0 &&
(enabled_port_mask & 1 << next_hop) != 0) {
dst_port = next_hop;
diff --git a/examples/ipsec-secgw/flow.c b/examples/ipsec-secgw/flow.c
index 05a62c3020..3f7630f5fd 100644
--- a/examples/ipsec-secgw/flow.c
+++ b/examples/ipsec-secgw/flow.c
@@ -83,29 +83,8 @@ ipv4_addr_cpy(rte_be32_t *spec, rte_be32_t *mask, char *token,
static void
ipv6_hdr_print(struct rte_ipv6_hdr *hdr)
{
- uint8_t *addr;
-
- addr = hdr->src_addr;
- printf("src: %4hx:%4hx:%4hx:%4hx:%4hx:%4hx:%4hx:%4hx \t",
- (uint16_t)((addr[0] << 8) | addr[1]),
- (uint16_t)((addr[2] << 8) | addr[3]),
- (uint16_t)((addr[4] << 8) | addr[5]),
- (uint16_t)((addr[6] << 8) | addr[7]),
- (uint16_t)((addr[8] << 8) | addr[9]),
- (uint16_t)((addr[10] << 8) | addr[11]),
- (uint16_t)((addr[12] << 8) | addr[13]),
- (uint16_t)((addr[14] << 8) | addr[15]));
-
- addr = hdr->dst_addr;
- printf("dst: %4hx:%4hx:%4hx:%4hx:%4hx:%4hx:%4hx:%4hx",
- (uint16_t)((addr[0] << 8) | addr[1]),
- (uint16_t)((addr[2] << 8) | addr[3]),
- (uint16_t)((addr[4] << 8) | addr[5]),
- (uint16_t)((addr[6] << 8) | addr[7]),
- (uint16_t)((addr[8] << 8) | addr[9]),
- (uint16_t)((addr[10] << 8) | addr[11]),
- (uint16_t)((addr[12] << 8) | addr[13]),
- (uint16_t)((addr[14] << 8) | addr[15]));
+ printf("src: " RTE_IPV6_ADDR_FMT " \t", RTE_IPV6_ADDR_SPLIT(&hdr->src_addr));
+ printf("dst: " RTE_IPV6_ADDR_FMT, RTE_IPV6_ADDR_SPLIT(&hdr->dst_addr));
}
static int
@@ -196,8 +175,8 @@ parse_flow_tokens(char **tokens, uint32_t n_tokens,
INCREMENT_TOKEN_INDEX(ti, n_tokens, status);
if (status->status < 0)
return;
- if (ipv6_addr_cpy(rule->ipv6.spec.hdr.src_addr,
- rule->ipv6.mask.hdr.src_addr,
+ if (ipv6_addr_cpy(rule->ipv6.spec.hdr.src_addr.a,
+ rule->ipv6.mask.hdr.src_addr.a,
tokens[ti], status))
return;
}
@@ -205,8 +184,8 @@ parse_flow_tokens(char **tokens, uint32_t n_tokens,
INCREMENT_TOKEN_INDEX(ti, n_tokens, status);
if (status->status < 0)
return;
- if (ipv6_addr_cpy(rule->ipv6.spec.hdr.dst_addr,
- rule->ipv6.mask.hdr.dst_addr,
+ if (ipv6_addr_cpy(rule->ipv6.spec.hdr.dst_addr.a,
+ rule->ipv6.mask.hdr.dst_addr.a,
tokens[ti], status))
return;
}
diff --git a/examples/ipsec-secgw/ipsec.c b/examples/ipsec-secgw/ipsec.c
index b52b0ffc3d..ebde28639c 100644
--- a/examples/ipsec-secgw/ipsec.c
+++ b/examples/ipsec-secgw/ipsec.c
@@ -529,9 +529,9 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,
sa->pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
sa->pattern[1].spec = &sa->ipv6_spec;
- memcpy(sa->ipv6_spec.hdr.dst_addr,
+ memcpy(&sa->ipv6_spec.hdr.dst_addr,
sa->dst.ip.ip6.ip6_b, 16);
- memcpy(sa->ipv6_spec.hdr.src_addr,
+ memcpy(&sa->ipv6_spec.hdr.src_addr,
sa->src.ip.ip6.ip6_b, 16);
} else if (IS_IP4(sa->flags)) {
sa->pattern[1].mask = &rte_flow_item_ipv4_mask;
@@ -735,9 +735,9 @@ create_ipsec_esp_flow(struct ipsec_sa *sa)
sa->pattern[1].mask = &rte_flow_item_ipv6_mask;
sa->pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
sa->pattern[1].spec = &sa->ipv6_spec;
- memcpy(sa->ipv6_spec.hdr.dst_addr,
+ memcpy(&sa->ipv6_spec.hdr.dst_addr,
sa->dst.ip.ip6.ip6_b, sizeof(sa->dst.ip.ip6.ip6_b));
- memcpy(sa->ipv6_spec.hdr.src_addr,
+ memcpy(&sa->ipv6_spec.hdr.src_addr,
sa->src.ip.ip6.ip6_b, sizeof(sa->src.ip.ip6.ip6_b));
sa->pattern[2].type = RTE_FLOW_ITEM_TYPE_ESP;
sa->pattern[2].spec = &sa->esp_spec;
diff --git a/examples/ipsec-secgw/sa.c b/examples/ipsec-secgw/sa.c
index c4bac17cd7..1a0afd2ed2 100644
--- a/examples/ipsec-secgw/sa.c
+++ b/examples/ipsec-secgw/sa.c
@@ -1571,8 +1571,8 @@ ipsec_sa_init(struct ipsec_sa *lsa, struct rte_ipsec_sa *sa, uint32_t sa_size,
};
if (IS_IP6_TUNNEL(lsa->flags)) {
- memcpy(v6.src_addr, lsa->src.ip.ip6.ip6_b, sizeof(v6.src_addr));
- memcpy(v6.dst_addr, lsa->dst.ip.ip6.ip6_b, sizeof(v6.dst_addr));
+ memcpy(&v6.src_addr, lsa->src.ip.ip6.ip6_b, sizeof(v6.src_addr));
+ memcpy(&v6.dst_addr, lsa->dst.ip.ip6.ip6_b, sizeof(v6.dst_addr));
}
rc = fill_ipsec_sa_prm(&prm, lsa, &v4, &v6);
diff --git a/examples/ipsec-secgw/sad.h b/examples/ipsec-secgw/sad.h
index 3224b6252c..b619aa1034 100644
--- a/examples/ipsec-secgw/sad.h
+++ b/examples/ipsec-secgw/sad.h
@@ -5,6 +5,7 @@
#ifndef __SAD_H__
#define __SAD_H__
+#include <rte_ip.h>
#include <rte_ipsec_sad.h>
#define SA_CACHE_SZ 128
@@ -37,8 +38,8 @@ cmp_sa_key(struct ipsec_sa *sa, int is_v4, struct rte_ipv4_hdr *ipv4,
(sa->dst.ip.ip4 == ipv4->dst_addr)) ||
/* IPv6 check */
(!is_v4 && (sa_type == IP6_TUNNEL) &&
- (!memcmp(sa->src.ip.ip6.ip6, ipv6->src_addr, 16)) &&
- (!memcmp(sa->dst.ip.ip6.ip6, ipv6->dst_addr, 16))))
+ (!memcmp(sa->src.ip.ip6.ip6, &ipv6->src_addr, 16)) &&
+ (!memcmp(sa->dst.ip.ip6.ip6, &ipv6->dst_addr, 16))))
return 1;
return 0;
@@ -128,9 +129,9 @@ sad_lookup(struct ipsec_sad *sad, struct rte_mbuf *pkts[],
}
}
v6[nb_v6].spi = esp->spi;
- memcpy(v6[nb_v6].dip, ipv6->dst_addr,
+ memcpy(v6[nb_v6].dip, &ipv6->dst_addr,
sizeof(ipv6->dst_addr));
- memcpy(v6[nb_v6].sip, ipv6->src_addr,
+ memcpy(v6[nb_v6].sip, &ipv6->src_addr,
sizeof(ipv6->src_addr));
keys_v6[nb_v6] = (const union rte_ipsec_sad_key *)
&v6[nb_v6];
diff --git a/examples/l3fwd/l3fwd_fib.c b/examples/l3fwd/l3fwd_fib.c
index 993e36cec2..85f862dd5b 100644
--- a/examples/l3fwd/l3fwd_fib.c
+++ b/examples/l3fwd/l3fwd_fib.c
@@ -65,7 +65,7 @@ fib_parse_packet(struct rte_mbuf *mbuf,
/* IPv6 */
else {
ipv6_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1);
- rte_mov16(ipv6, (const uint8_t *)ipv6_hdr->dst_addr);
+ rte_mov16(ipv6, ipv6_hdr->dst_addr.a);
*ip_type = 0;
(*ipv6_cnt)++;
}
diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index e8fd95aae9..422fdb7005 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -62,7 +62,7 @@ lpm_get_ipv6_dst_port(const struct rte_ipv6_hdr *ipv6_hdr,
uint16_t portid,
struct rte_lpm6 *ipv6_l3fwd_lookup_struct)
{
- const uint8_t *dst_ip = ipv6_hdr->dst_addr;
+ const uint8_t *dst_ip = ipv6_hdr->dst_addr.a;
uint32_t next_hop;
if (rte_lpm6_lookup(ipv6_l3fwd_lookup_struct, dst_ip, &next_hop) == 0)
@@ -122,7 +122,7 @@ lpm_get_dst_port_with_ipv4(const struct lcore_conf *qconf, struct rte_mbuf *pkt,
ipv6_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1);
return (uint16_t) ((rte_lpm6_lookup(qconf->ipv6_lookup_struct,
- ipv6_hdr->dst_addr, &next_hop) == 0)
+ ipv6_hdr->dst_addr.a, &next_hop) == 0)
? next_hop : portid);
}