netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: netdev@vger.kernel.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Sabrina Dubroca <sd@queasysnail.net>
Subject: [PATCH net-next v5 4/6] esp4: prepare esp_input_done2 for non-UDP encapsulation
Date: Tue, 12 Nov 2019 16:18:41 +0100	[thread overview]
Message-ID: <165ce1ac9f99a86a5b13c3e481647a1004af1366.1573487190.git.sd@queasysnail.net> (raw)
In-Reply-To: <cover.1573487190.git.sd@queasysnail.net>

For espintcp encapsulation, we will need to get the source port from the
TCP header instead of UDP. Introduce a variable to hold the port.

Co-developed-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/ipv4/esp4.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 5c967764041f..c5d826642229 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -601,6 +601,18 @@ int esp_input_done2(struct sk_buff *skb, int err)
 	if (x->encap) {
 		struct xfrm_encap_tmpl *encap = x->encap;
 		struct udphdr *uh = (void *)(skb_network_header(skb) + ihl);
+		__be16 source;
+
+		switch (x->encap->encap_type) {
+		case UDP_ENCAP_ESPINUDP:
+		case UDP_ENCAP_ESPINUDP_NON_IKE:
+			source = uh->source;
+			break;
+		default:
+			WARN_ON_ONCE(1);
+			err = -EINVAL;
+			goto out;
+		}
 
 		/*
 		 * 1) if the NAT-T peer's IP or port changed then
@@ -609,11 +621,11 @@ int esp_input_done2(struct sk_buff *skb, int err)
 		 *    SRC ports.
 		 */
 		if (iph->saddr != x->props.saddr.a4 ||
-		    uh->source != encap->encap_sport) {
+		    source != encap->encap_sport) {
 			xfrm_address_t ipaddr;
 
 			ipaddr.a4 = iph->saddr;
-			km_new_mapping(x, &ipaddr, uh->source);
+			km_new_mapping(x, &ipaddr, source);
 
 			/* XXX: perhaps add an extra
 			 * policy check here, to see
-- 
2.23.0


  parent reply	other threads:[~2019-11-12 15:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-12 15:18 [PATCH net-next v5 0/6] ipsec: add TCP encapsulation support (RFC 8229) Sabrina Dubroca
2019-11-12 15:18 ` [PATCH net-next v5 1/6] net: add queue argument to __skb_wait_for_more_packets and __skb_{,try_}recv_datagram Sabrina Dubroca
2019-11-12 17:54   ` Eric Dumazet
2019-11-13 10:57     ` Sabrina Dubroca
2019-11-12 15:18 ` [PATCH net-next v5 2/6] xfrm: introduce xfrm_trans_queue_net Sabrina Dubroca
2019-11-12 15:18 ` [PATCH net-next v5 3/6] xfrm: add route lookup to xfrm4_rcv_encap Sabrina Dubroca
2019-11-12 15:18 ` Sabrina Dubroca [this message]
2019-11-12 15:18 ` [PATCH net-next v5 5/6] esp4: split esp_output_udp_encap and introduce esp_output_encap Sabrina Dubroca
2019-11-12 15:18 ` [PATCH net-next v5 6/6] xfrm: add espintcp (RFC 8229) Sabrina Dubroca
2019-11-12 20:23 ` [PATCH net-next v5 0/6] ipsec: add TCP encapsulation support " David Miller
2019-11-21  5:51 ` Steffen Klassert
2019-11-21  9:35   ` Sabrina Dubroca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165ce1ac9f99a86a5b13c3e481647a1004af1366.1573487190.git.sd@queasysnail.net \
    --to=sd@queasysnail.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).