diff mbox series

[API-NEXT,v2,9/15] linux-gen: ipsec: separate ipv4/ipv6 flags

Message ID 1519236011-14987-10-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [API-NEXT,v2,1/15] api: don't create special case for the tunnel-dummy packets | expand

Commit Message

Github ODP bot Feb. 21, 2018, 6 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 494 (lumag:ipsec-tfc-imp)
 ** https://github.com/Linaro/odp/pull/494
 ** Patch: https://github.com/Linaro/odp/pull/494.patch
 ** Base sha: ea2afab619ae74108a03798bc358fdfcd29fdd88
 ** Merge commit sha: 0b6ae2680a00027c3958ebcafbbcf92642a68f5e
 **/
 platform/linux-generic/odp_ipsec.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c
index cfdfa9dc9..55beb382e 100644
--- a/platform/linux-generic/odp_ipsec.c
+++ b/platform/linux-generic/odp_ipsec.c
@@ -269,6 +269,7 @@  typedef struct {
 	uint16_t ip_next_hdr_offset;
 	uint8_t  ip_next_hdr;
 	unsigned is_ipv4 : 1;
+	unsigned is_ipv6 : 1;
 	union {
 		struct {
 			uint32_t ip_flabel;
@@ -669,10 +670,13 @@  static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt,
 	 * state.is_ipv4 = odp_packet_has_ipv4(pkt);
 	 */
 	state.is_ipv4 = (((uint8_t *)state.ip)[0] >> 4) == 0x4;
+	state.is_ipv6 = (((uint8_t *)state.ip)[0] >> 4) == 0x6;
 	if (state.is_ipv4)
 		rc = ipsec_parse_ipv4(&state, pkt);
-	else
+	else if (state.is_ipv6)
 		rc = ipsec_parse_ipv6(&state, pkt);
+	else
+		rc = -1;
 	if (rc < 0 ||
 	    state.ip_tot_len + state.ip_offset > odp_packet_len(pkt)) {
 		status->error.alg = 1;
@@ -776,8 +780,10 @@  static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt,
 		state.ip_tot_len -= state.ip_hdr_len + state.in.hdr_len;
 		if (_ODP_IPPROTO_IPIP == state.ip_next_hdr) {
 			state.is_ipv4 = 1;
+			state.is_ipv6 = 0;
 		} else if (_ODP_IPPROTO_IPV6 == state.ip_next_hdr) {
 			state.is_ipv4 = 0;
+			state.is_ipv6 = 1;
 		} else {
 			status->error.proto = 1;
 			goto err;
@@ -802,7 +808,7 @@  static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt,
 		else
 			ipv4hdr->ttl -= ipsec_sa->dec_ttl;
 		_odp_ipv4_csum_update(pkt);
-	} else if (!state.is_ipv4 && odp_packet_len(pkt) > _ODP_IPV6HDR_LEN) {
+	} else if (state.is_ipv6 && odp_packet_len(pkt) > _ODP_IPV6HDR_LEN) {
 		_odp_ipv6hdr_t *ipv6hdr = odp_packet_l3_ptr(pkt, NULL);
 
 		if (ODP_IPSEC_MODE_TRANSPORT == ipsec_sa->mode)
@@ -816,9 +822,9 @@  static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt,
 		goto err;
 	}
 
-	parse_param.proto = state.is_ipv4 ?
-				ODP_PROTO_IPV4 :
-				ODP_PROTO_IPV6;
+	parse_param.proto = state.is_ipv4 ? ODP_PROTO_IPV4 :
+			    state.is_ipv6 ? ODP_PROTO_IPV6 :
+					    ODP_PROTO_NONE;
 	parse_param.last_layer = ipsec_config.inbound.parse_level;
 	parse_param.chksums = ipsec_config.inbound.chksums;
 
@@ -934,6 +940,7 @@  static int ipsec_out_tunnel_ipv4(odp_packet_t *pkt,
 		_ODP_IPV4HDR_PROTO_OFFSET;
 
 	state->is_ipv4 = 1;
+	state->is_ipv6 = 0;
 
 	return 0;
 }
@@ -990,6 +997,7 @@  static int ipsec_out_tunnel_ipv6(odp_packet_t *pkt,
 	state->ip_next_hdr_offset = state->ip_offset + _ODP_IPV6HDR_NHDR_OFFSET;
 
 	state->is_ipv4 = 0;
+	state->is_ipv6 = 1;
 
 	return 0;
 }
@@ -1320,20 +1328,25 @@  static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt,
 	memset(&param, 0, sizeof(param));
 
 	state.is_ipv4 = (((uint8_t *)state.ip)[0] >> 4) == 0x4;
+	state.is_ipv6 = (((uint8_t *)state.ip)[0] >> 4) == 0x6;
 
 	if (ODP_IPSEC_MODE_TRANSPORT == ipsec_sa->mode) {
 		if (state.is_ipv4)
 			rc = ipsec_parse_ipv4(&state, pkt);
-		else
+		else if (state.is_ipv6)
 			rc = ipsec_parse_ipv6(&state, pkt);
+		else
+			rc = -1;
 
 		if (state.ip_tot_len + state.ip_offset != odp_packet_len(pkt))
 			rc = -1;
 	} else {
 		if (state.is_ipv4)
 			rc = ipsec_out_tunnel_parse_ipv4(&state, ipsec_sa);
-		else
+		else if (state.is_ipv6)
 			rc = ipsec_out_tunnel_parse_ipv6(&state, ipsec_sa);
+		else
+			rc = -1;
 		if (rc < 0) {
 			status->error.alg = 1;
 			goto err;