lwt: Add cfg argument to build_state
authorTom Herbert <tom@herbertland.com>
Mon, 24 Aug 2015 16:45:41 +0000 (09:45 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 24 Aug 2015 17:34:40 +0000 (10:34 -0700)
Add cfg and family arguments to lwt build state functions. cfg is a void
pointer and will either be a pointer to a fib_config or fib6_config
structure. The family parameter indicates which one (either AF_INET
or AF_INET6).

LWT encpasulation implementation may use the fib configuration to build
the LWT state.

Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/lwtunnel.h
net/core/lwtunnel.c
net/ipv4/fib_semantics.c
net/ipv4/ip_tunnel_core.c
net/ipv6/ila.c
net/ipv6/route.c
net/mpls/mpls_iptunnel.c

index 84348988444839280e64026bd9c28a1af1cdfc45..fce0e35e74d075cd77f23a84efc6c36885c93ba9 100644 (file)
@@ -26,6 +26,7 @@ struct lwtunnel_state {
 
 struct lwtunnel_encap_ops {
        int (*build_state)(struct net_device *dev, struct nlattr *encap,
+                          unsigned int family, const void *cfg,
                           struct lwtunnel_state **ts);
        int (*output)(struct sock *sk, struct sk_buff *skb);
        int (*input)(struct sk_buff *skb);
@@ -80,6 +81,7 @@ int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
                           unsigned int num);
 int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
                         struct nlattr *encap,
+                        unsigned int family, const void *cfg,
                         struct lwtunnel_state **lws);
 int lwtunnel_fill_encap(struct sk_buff *skb,
                        struct lwtunnel_state *lwtstate);
@@ -130,6 +132,7 @@ static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
 
 static inline int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
                                       struct nlattr *encap,
+                                      unsigned int family, const void *cfg,
                                       struct lwtunnel_state **lws)
 {
        return -EOPNOTSUPP;
index e924c2e08554094e824449e3829d42f148906e4a..dfb1a9ca08354fef353bf274415528d2d4ca269a 100644 (file)
@@ -72,7 +72,8 @@ int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *ops,
 EXPORT_SYMBOL(lwtunnel_encap_del_ops);
 
 int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
-                        struct nlattr *encap, struct lwtunnel_state **lws)
+                        struct nlattr *encap, unsigned int family,
+                        const void *cfg, struct lwtunnel_state **lws)
 {
        const struct lwtunnel_encap_ops *ops;
        int ret = -EINVAL;
@@ -85,7 +86,7 @@ int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
        rcu_read_lock();
        ops = rcu_dereference(lwtun_encaps[encap_type]);
        if (likely(ops && ops->build_state))
-               ret = ops->build_state(dev, encap, lws);
+               ret = ops->build_state(dev, encap, family, cfg, lws);
        rcu_read_unlock();
 
        return ret;
index 01f1c7dcd329ca6ec6f281328e52db7bb256ae9b..1b2d01170a4de8665b0bc5bedbb596058f15e41c 100644 (file)
@@ -511,7 +511,8 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
                                        dev = __dev_get_by_index(net, cfg->fc_oif);
                                ret = lwtunnel_build_state(dev, nla_get_u16(
                                                           nla_entype),
-                                                          nla, &lwtstate);
+                                                          nla,  AF_INET, cfg,
+                                                          &lwtstate);
                                if (ret)
                                        goto errout;
                                nexthop_nh->nh_lwtstate =
@@ -535,7 +536,8 @@ errout:
 
 static int fib_encap_match(struct net *net, u16 encap_type,
                           struct nlattr *encap,
-                          int oif, const struct fib_nh *nh)
+                          int oif, const struct fib_nh *nh,
+                          const struct fib_config *cfg)
 {
        struct lwtunnel_state *lwtstate;
        struct net_device *dev = NULL;
@@ -546,8 +548,8 @@ static int fib_encap_match(struct net *net, u16 encap_type,
 
        if (oif)
                dev = __dev_get_by_index(net, oif);
-       ret = lwtunnel_build_state(dev, encap_type,
-                                  encap, &lwtstate);
+       ret = lwtunnel_build_state(dev, encap_type, encap,
+                                  AF_INET, cfg, &lwtstate);
        if (!ret) {
                result = lwtunnel_cmp_encap(lwtstate, nh->nh_lwtstate);
                lwtstate_free(lwtstate);
@@ -571,7 +573,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
                if (cfg->fc_encap) {
                        if (fib_encap_match(net, cfg->fc_encap_type,
                                            cfg->fc_encap, cfg->fc_oif,
-                                           fi->fib_nh))
+                                           fi->fib_nh, cfg))
                            return 1;
                }
                if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->nh_oif) &&
@@ -663,7 +665,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
 static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
                        struct fib_nh *nh)
 {
-       int err;
+       int err = 0;
        struct net *net;
        struct net_device *dev;
 
@@ -1005,7 +1007,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
                        if (cfg->fc_oif)
                                dev = __dev_get_by_index(net, cfg->fc_oif);
                        err = lwtunnel_build_state(dev, cfg->fc_encap_type,
-                                                  cfg->fc_encap, &lwtstate);
+                                                  cfg->fc_encap, AF_INET, cfg,
+                                                  &lwtstate);
                        if (err)
                                goto failure;
 
index 289b6c26ce377d2dc094b9ae028a7f2cebc00e4c..934f2ac8ad610838b8a6611a4fecac5849f3afef 100644 (file)
@@ -204,6 +204,7 @@ static const struct nla_policy ip_tun_policy[LWTUNNEL_IP_MAX + 1] = {
 };
 
 static int ip_tun_build_state(struct net_device *dev, struct nlattr *attr,
+                             unsigned int family, const void *cfg,
                              struct lwtunnel_state **ts)
 {
        struct ip_tunnel_info *tun_info;
@@ -311,6 +312,7 @@ static const struct nla_policy ip6_tun_policy[LWTUNNEL_IP6_MAX + 1] = {
 };
 
 static int ip6_tun_build_state(struct net_device *dev, struct nlattr *attr,
+                              unsigned int family, const void *cfg,
                               struct lwtunnel_state **ts)
 {
        struct ip_tunnel_info *tun_info;
index f011c3d5ca40c3fb46cc4d3e6eada952c6536c9a..ffe4dcad6088c446141f6912d53dbfcf8943cacf 100644 (file)
@@ -123,6 +123,7 @@ static struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
 };
 
 static int ila_build_state(struct net_device *dev, struct nlattr *nla,
+                          unsigned int family, const void *cfg,
                           struct lwtunnel_state **ts)
 {
        struct ila_params *p;
index e476f01add87c62295a52fef641c806caca7d09a..df3e353a012d081699df247482c9932a9f69ee9c 100644 (file)
@@ -1819,7 +1819,8 @@ int ip6_route_add(struct fib6_config *cfg)
                struct lwtunnel_state *lwtstate;
 
                err = lwtunnel_build_state(dev, cfg->fc_encap_type,
-                                          cfg->fc_encap, &lwtstate);
+                                          cfg->fc_encap, AF_INET6, cfg,
+                                          &lwtstate);
                if (err)
                        goto out;
                rt->dst.lwtstate = lwtstate_get(lwtstate);
index 3da5ca3ba5638e2cbc30b875c2e0ccae347de954..21e70bc9af989355521f8fd99ea3bc07730626c8 100644 (file)
@@ -123,6 +123,7 @@ drop:
 }
 
 static int mpls_build_state(struct net_device *dev, struct nlattr *nla,
+                           unsigned int family, const void *cfg,
                            struct lwtunnel_state **ts)
 {
        struct mpls_iptunnel_encap *tun_encap_info;