From: Vidya Sagar Velumuri <vvelum...@marvell.com> Add support for custom port values for UDP encapsulation
Signed-off-by: Vidya Sagar Velumuri <vvelum...@marvell.com> --- drivers/common/cnxk/cnxk_security.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/common/cnxk/cnxk_security.c b/drivers/common/cnxk/cnxk_security.c index f8bdeabeac..f220d2577f 100644 --- a/drivers/common/cnxk/cnxk_security.c +++ b/drivers/common/cnxk/cnxk_security.c @@ -1219,6 +1219,7 @@ cnxk_on_ipsec_outb_sa_create(struct rte_security_ipsec_xform *ipsec, struct rte_ipv6_hdr *ip6; struct rte_ipv4_hdr *ip4; const uint8_t *auth_key; + uint16_t sport, dport; int auth_key_len = 0; size_t ctx_len; int ret; @@ -1266,10 +1267,20 @@ cnxk_on_ipsec_outb_sa_create(struct rte_security_ipsec_xform *ipsec, } ip4 = (struct rte_ipv4_hdr *)&template->ip4.ipv4_hdr; + /* If custom port values are provided, Overwrite default port values. */ if (ipsec->options.udp_encap) { + sport = 4500; + dport = 4500; + + if (ipsec->udp.sport) + sport = ipsec->udp.sport; + + if (ipsec->udp.dport) + dport = ipsec->udp.dport; + ip4->next_proto_id = IPPROTO_UDP; - template->ip4.udp_src = rte_be_to_cpu_16(4500); - template->ip4.udp_dst = rte_be_to_cpu_16(4500); + template->ip4.udp_src = rte_be_to_cpu_16(sport); + template->ip4.udp_dst = rte_be_to_cpu_16(dport); } else { if (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_AH) ip4->next_proto_id = IPPROTO_AH; @@ -1303,13 +1314,12 @@ cnxk_on_ipsec_outb_sa_create(struct rte_security_ipsec_xform *ipsec, ip6 = (struct rte_ipv6_hdr *)&template->ip6.ipv6_hdr; if (ipsec->options.udp_encap) { ip6->proto = IPPROTO_UDP; - template->ip6.udp_src = rte_be_to_cpu_16(4500); - template->ip6.udp_dst = rte_be_to_cpu_16(4500); + template->ip6.udp_src = rte_be_to_cpu_16(sport); + template->ip6.udp_dst = rte_be_to_cpu_16(dport); } else { - ip6->proto = (ipsec->proto == - RTE_SECURITY_IPSEC_SA_PROTO_ESP) ? - IPPROTO_ESP : - IPPROTO_AH; + ip6->proto = (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_ESP) ? + IPPROTO_ESP : + IPPROTO_AH; } ip6->vtc_flow = rte_cpu_to_be_32(0x60000000 | -- 2.25.1