]> git.baikalelectronics.ru Git - kernel.git/commitdiff
xfrm: remove extract_output indirection from xfrm_state_afinfo
authorFlorian Westphal <fw@strlen.de>
Mon, 4 May 2020 08:06:08 +0000 (10:06 +0200)
committerSteffen Klassert <steffen.klassert@secunet.com>
Wed, 6 May 2020 07:40:08 +0000 (09:40 +0200)
Move this to xfrm_output.c.  This avoids the state->extract_output
indirection.

This patch also removes the duplicated __xfrm6_extract_header helper
added in an earlier patch, we can now use the one from xfrm_inout.h .

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
include/net/xfrm.h
net/ipv6/xfrm6_output.c
net/ipv6/xfrm6_state.c
net/xfrm/xfrm_output.c

index 8f7fb033d5576b7a12f725b26f9cfff94698c4a4..db814a7e042f1fb25848ebbaa25ea74a758d38c3 100644 (file)
@@ -362,8 +362,6 @@ struct xfrm_state_afinfo {
 
        int                     (*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
        int                     (*output_finish)(struct sock *sk, struct sk_buff *skb);
-       int                     (*extract_output)(struct xfrm_state *x,
-                                                 struct sk_buff *skb);
        int                     (*transport_finish)(struct sk_buff *skb,
                                                    int async);
        void                    (*local_error)(struct sk_buff *skb, u32 mtu);
@@ -1601,7 +1599,6 @@ int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
 int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
 __be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
 __be32 xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr);
-int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
 int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
 int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb);
 int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
index be64f280510c95b8a53a1899a1bb294d8bc1ff72..b7d65b34467954b1afc40554ca37dcc3ce43e3ac 100644 (file)
@@ -47,64 +47,6 @@ void xfrm6_local_error(struct sk_buff *skb, u32 mtu)
        ipv6_local_error(sk, EMSGSIZE, &fl6, mtu);
 }
 
-static int xfrm6_tunnel_check_size(struct sk_buff *skb)
-{
-       int mtu, ret = 0;
-       struct dst_entry *dst = skb_dst(skb);
-
-       if (skb->ignore_df)
-               goto out;
-
-       mtu = dst_mtu(dst);
-       if (mtu < IPV6_MIN_MTU)
-               mtu = IPV6_MIN_MTU;
-
-       if ((!skb_is_gso(skb) && skb->len > mtu) ||
-           (skb_is_gso(skb) &&
-            !skb_gso_validate_network_len(skb, ip6_skb_dst_mtu(skb)))) {
-               skb->dev = dst->dev;
-               skb->protocol = htons(ETH_P_IPV6);
-
-               if (xfrm6_local_dontfrag(skb->sk))
-                       xfrm6_local_rxpmtu(skb, mtu);
-               else if (skb->sk)
-                       xfrm_local_error(skb, mtu);
-               else
-                       icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
-               ret = -EMSGSIZE;
-       }
-out:
-       return ret;
-}
-
-static void __xfrm6_extract_header(struct sk_buff *skb)
-{
-       struct ipv6hdr *iph = ipv6_hdr(skb);
-
-       XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
-       XFRM_MODE_SKB_CB(skb)->id = 0;
-       XFRM_MODE_SKB_CB(skb)->frag_off = htons(IP_DF);
-       XFRM_MODE_SKB_CB(skb)->tos = ipv6_get_dsfield(iph);
-       XFRM_MODE_SKB_CB(skb)->ttl = iph->hop_limit;
-       XFRM_MODE_SKB_CB(skb)->optlen = 0;
-       memcpy(XFRM_MODE_SKB_CB(skb)->flow_lbl, iph->flow_lbl,
-              sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
-}
-
-int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb)
-{
-       int err;
-
-       err = xfrm6_tunnel_check_size(skb);
-       if (err)
-               return err;
-
-       XFRM_MODE_SKB_CB(skb)->protocol = ipv6_hdr(skb)->nexthdr;
-
-       __xfrm6_extract_header(skb);
-       return 0;
-}
-
 int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb)
 {
        memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
index 8fbf5a68ee6e8c57e989e419610486bc9d9b7a62..15247f2f78e1bc8f9b927278f640065adf0c6fba 100644 (file)
@@ -19,7 +19,6 @@ static struct xfrm_state_afinfo xfrm6_state_afinfo = {
        .proto                  = IPPROTO_IPV6,
        .output                 = xfrm6_output,
        .output_finish          = xfrm6_output_finish,
-       .extract_output         = xfrm6_extract_output,
        .transport_finish       = xfrm6_transport_finish,
        .local_error            = xfrm6_local_error,
 };
index a7b3af7f7a1e097bab812397b86d8707b8638177..3a646df1318d6621845ec54b9e5051a700df71aa 100644 (file)
 #include <net/inet_ecn.h>
 #include <net/xfrm.h>
 
+#if IS_ENABLED(CONFIG_IPV6)
+#include <net/ip6_route.h>
+#include <net/ipv6_stubs.h>
+#endif
+
 #include "xfrm_inout.h"
 
 static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb);
@@ -651,11 +656,60 @@ static int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb)
        return 0;
 }
 
+#if IS_ENABLED(CONFIG_IPV6)
+static int xfrm6_tunnel_check_size(struct sk_buff *skb)
+{
+       int mtu, ret = 0;
+       struct dst_entry *dst = skb_dst(skb);
+
+       if (skb->ignore_df)
+               goto out;
+
+       mtu = dst_mtu(dst);
+       if (mtu < IPV6_MIN_MTU)
+               mtu = IPV6_MIN_MTU;
+
+       if ((!skb_is_gso(skb) && skb->len > mtu) ||
+           (skb_is_gso(skb) &&
+            !skb_gso_validate_network_len(skb, ip6_skb_dst_mtu(skb)))) {
+               skb->dev = dst->dev;
+               skb->protocol = htons(ETH_P_IPV6);
+
+               if (xfrm6_local_dontfrag(skb->sk))
+                       ipv6_stub->xfrm6_local_rxpmtu(skb, mtu);
+               else if (skb->sk)
+                       xfrm_local_error(skb, mtu);
+               else
+                       icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
+               ret = -EMSGSIZE;
+       }
+out:
+       return ret;
+}
+#endif
+
+static int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb)
+{
+#if IS_ENABLED(CONFIG_IPV6)
+       int err;
+
+       err = xfrm6_tunnel_check_size(skb);
+       if (err)
+               return err;
+
+       XFRM_MODE_SKB_CB(skb)->protocol = ipv6_hdr(skb)->nexthdr;
+
+       xfrm6_extract_header(skb);
+       return 0;
+#else
+       WARN_ON_ONCE(1);
+       return -EAFNOSUPPORT;
+#endif
+}
+
 static int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)
 {
-       const struct xfrm_state_afinfo *afinfo;
        const struct xfrm_mode *inner_mode;
-       int err = -EAFNOSUPPORT;
 
        if (x->sel.family == AF_UNSPEC)
                inner_mode = xfrm_ip2inner_mode(x,
@@ -669,14 +723,11 @@ static int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)
        switch (inner_mode->family) {
        case AF_INET:
                return xfrm4_extract_output(x, skb);
+       case AF_INET6:
+               return xfrm6_extract_output(x, skb);
        }
-       rcu_read_lock();
-       afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
-       if (likely(afinfo))
-               err = afinfo->extract_output(x, skb);
-       rcu_read_unlock();
 
-       return err;
+       return -EAFNOSUPPORT;
 }
 
 void xfrm_local_error(struct sk_buff *skb, int mtu)