net: Move ipv4 set_lwt_redirect helper to lwtunnel
authorDavid Ahern <dsahern@gmail.com>
Wed, 14 Feb 2018 04:32:04 +0000 (20:32 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 14 Feb 2018 19:43:32 +0000 (14:43 -0500)
IPv4 uses set_lwt_redirect to set the lwtunnel redirect functions as
needed. Move it to lwtunnel.h as lwtunnel_set_redirect and change
IPv6 to also use it.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/lwtunnel.h
net/ipv4/route.c
net/ipv6/route.c

index d747ef975cd80a15105288b2c2235b41b71be7b6..33fd9ba7e0e5a29d5dd1705112a9213f08531612 100644 (file)
@@ -127,6 +127,17 @@ int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb);
 int lwtunnel_input(struct sk_buff *skb);
 int lwtunnel_xmit(struct sk_buff *skb);
 
+static inline void lwtunnel_set_redirect(struct dst_entry *dst)
+{
+       if (lwtunnel_output_redirect(dst->lwtstate)) {
+               dst->lwtstate->orig_output = dst->output;
+               dst->output = lwtunnel_output;
+       }
+       if (lwtunnel_input_redirect(dst->lwtstate)) {
+               dst->lwtstate->orig_input = dst->input;
+               dst->input = lwtunnel_input;
+       }
+}
 #else
 
 static inline void lwtstate_free(struct lwtunnel_state *lws)
@@ -158,6 +169,10 @@ static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate)
        return false;
 }
 
+static inline void lwtunnel_set_redirect(struct dst_entry *dst)
+{
+}
+
 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate,
                                             unsigned int mtu)
 {
index b0ef4cc3e875dc6fdceda184e6b4e7363af5a8a9..6ce623e3e2ab0e7eaae16b9bdebf56385d59b716 100644 (file)
@@ -1645,19 +1645,6 @@ static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr)
        spin_unlock_bh(&fnhe_lock);
 }
 
-static void set_lwt_redirect(struct rtable *rth)
-{
-       if (lwtunnel_output_redirect(rth->dst.lwtstate)) {
-               rth->dst.lwtstate->orig_output = rth->dst.output;
-               rth->dst.output = lwtunnel_output;
-       }
-
-       if (lwtunnel_input_redirect(rth->dst.lwtstate)) {
-               rth->dst.lwtstate->orig_input = rth->dst.input;
-               rth->dst.input = lwtunnel_input;
-       }
-}
-
 /* called in rcu_read_lock() section */
 static int __mkroute_input(struct sk_buff *skb,
                           const struct fib_result *res,
@@ -1748,7 +1735,7 @@ rt_cache:
 
        rt_set_nexthop(rth, daddr, res, fnhe, res->fi, res->type, itag,
                       do_cache);
-       set_lwt_redirect(rth);
+       lwtunnel_set_redirect(&rth->dst);
        skb_dst_set(skb, &rth->dst);
 out:
        err = 0;
@@ -2267,7 +2254,7 @@ add:
        }
 
        rt_set_nexthop(rth, fl4->daddr, res, fnhe, fi, type, 0, do_cache);
-       set_lwt_redirect(rth);
+       lwtunnel_set_redirect(&rth->dst);
 
        return rth;
 }
index 9dcfadddd800557e6c710a8e848dbfdb7d186393..f0baae26db8f6139cb71769c312a7099f04401ea 100644 (file)
@@ -2671,14 +2671,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
                if (err)
                        goto out;
                rt->dst.lwtstate = lwtstate_get(lwtstate);
-               if (lwtunnel_output_redirect(rt->dst.lwtstate)) {
-                       rt->dst.lwtstate->orig_output = rt->dst.output;
-                       rt->dst.output = lwtunnel_output;
-               }
-               if (lwtunnel_input_redirect(rt->dst.lwtstate)) {
-                       rt->dst.lwtstate->orig_input = rt->dst.input;
-                       rt->dst.input = lwtunnel_input;
-               }
+               lwtunnel_set_redirect(&rt->dst);
        }
 
        ipv6_addr_prefix(&rt->rt6i_dst.addr, &cfg->fc_dst, cfg->fc_dst_len);