netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: netdev@vger.kernel.org, davem@davemloft.net
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>, Hans Wippel <ndev@hwipl.net>
Subject: [PATCH net v2 1/8] net: ip_tunnel: add header_ops for layer 3 devices
Date: Mon, 29 Jun 2020 19:06:18 -0600	[thread overview]
Message-ID: <20200630010625.469202-2-Jason@zx2c4.com> (raw)
In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com>

Some devices that take straight up layer 3 packets benefit from having a
shared header_ops so that AF_PACKET sockets can inject packets that are
recognized. This shared infrastructure will be used by other drivers
that currently can't inject packets using AF_PACKET. It also exposes the
parser function, as it is useful in standalone form too.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
Changes v1->v2:
- [Willem] Remove added copyright header from v1.

 include/net/ip_tunnels.h  |  3 +++
 net/ipv4/ip_tunnel_core.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 076e5d7db7d3..36025dea7612 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -290,6 +290,9 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
 		      struct ip_tunnel_parm *p, __u32 fwmark);
 void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);
 
+extern const struct header_ops ip_tunnel_header_ops;
+__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
+
 struct ip_tunnel_encap_ops {
 	size_t (*encap_hlen)(struct ip_tunnel_encap *e);
 	int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 181b7a2a0247..f8b419e2475c 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -844,3 +844,21 @@ void ip_tunnel_unneed_metadata(void)
 	static_branch_dec(&ip_tunnel_metadata_cnt);
 }
 EXPORT_SYMBOL_GPL(ip_tunnel_unneed_metadata);
+
+/* Returns either the correct skb->protocol value, or 0 if invalid. */
+__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb)
+{
+	if (skb_network_header(skb) >= skb->head &&
+	    (skb_network_header(skb) + sizeof(struct iphdr)) <= skb_tail_pointer(skb) &&
+	    ip_hdr(skb)->version == 4)
+		return htons(ETH_P_IP);
+	if (skb_network_header(skb) >= skb->head &&
+	    (skb_network_header(skb) + sizeof(struct ipv6hdr)) <= skb_tail_pointer(skb) &&
+	    ipv6_hdr(skb)->version == 6)
+		return htons(ETH_P_IPV6);
+	return 0;
+}
+EXPORT_SYMBOL(ip_tunnel_parse_protocol);
+
+const struct header_ops ip_tunnel_header_ops = { .parse_protocol = ip_tunnel_parse_protocol };
+EXPORT_SYMBOL(ip_tunnel_header_ops);
-- 
2.27.0


  reply	other threads:[~2020-06-30  1:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30  1:06 [PATCH net v2 0/8] support AF_PACKET for layer 3 devices Jason A. Donenfeld
2020-06-30  1:06 ` Jason A. Donenfeld [this message]
2020-06-30 15:40   ` [PATCH net v2 1/8] net: ip_tunnel: add header_ops " Willem de Bruijn
2020-06-30  1:06 ` [PATCH net v2 2/8] net: ipip: implement header_ops->parse_protocol for AF_PACKET Jason A. Donenfeld
2020-06-30 16:02   ` Willem de Bruijn
2020-06-30  1:06 ` [PATCH net v2 3/8] wireguard: " Jason A. Donenfeld
2020-06-30  1:06 ` [PATCH net v2 4/8] wireguard: queueing: make use of ip_tunnel_parse_protocol Jason A. Donenfeld
2020-06-30  1:06 ` [PATCH net v2 5/8] tun: implement header_ops->parse_protocol for AF_PACKET Jason A. Donenfeld
2020-06-30  1:06 ` [PATCH net v2 6/8] net: vti: " Jason A. Donenfeld
2020-06-30  1:06 ` [PATCH net v2 7/8] net: sit: " Jason A. Donenfeld
2020-06-30  1:06 ` [PATCH net v2 8/8] net: xfrmi: " Jason A. Donenfeld
2020-06-30 19:30 ` [PATCH net v2 0/8] support AF_PACKET for layer 3 devices David Miller

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=20200630010625.469202-2-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=ndev@hwipl.net \
    --cc=netdev@vger.kernel.org \
    /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).