net: lwtunnel: Add extack to encap attr validation
authorDavid Ahern <dsahern@gmail.com>
Sat, 27 May 2017 22:19:27 +0000 (16:19 -0600)
committerDavid S. Miller <davem@davemloft.net>
Tue, 30 May 2017 15:55:31 +0000 (11:55 -0400)
Pass extack down to lwtunnel_valid_encap_type and
lwtunnel_valid_encap_type_attr. Add messages for unknown
or unsupported encap types.

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

index ebfe237aad7e0fb4c9d165a0090708134768c239..ca6f002774ef6bfbb89eeb5d401b3d6e78e83c7c 100644 (file)
@@ -107,8 +107,10 @@ int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
                           unsigned int num);
 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
                           unsigned int num);
-int lwtunnel_valid_encap_type(u16 encap_type);
-int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len);
+int lwtunnel_valid_encap_type(u16 encap_type,
+                             struct netlink_ext_ack *extack);
+int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len,
+                                  struct netlink_ext_ack *extack);
 int lwtunnel_build_state(u16 encap_type,
                         struct nlattr *encap,
                         unsigned int family, const void *cfg,
@@ -172,11 +174,14 @@ static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
        return -EOPNOTSUPP;
 }
 
-static inline int lwtunnel_valid_encap_type(u16 encap_type)
+static inline int lwtunnel_valid_encap_type(u16 encap_type,
+                                           struct netlink_ext_ack *extack)
 {
+       NL_SET_ERR_MSG(extack, "CONFIG_LWTUNNEL is not enabled in this kernel");
        return -EOPNOTSUPP;
 }
-static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len)
+static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len,
+                                                struct netlink_ext_ack *extack)
 {
        /* return 0 since we are not walking attr looking for
         * RTA_ENCAP_TYPE attribute on nexthops.
index cfae3d5fe11f10035394aea48fb5332244058a03..ab840386a74df66c62eaa861b0fc5adbc1abc06d 100644 (file)
@@ -126,14 +126,16 @@ int lwtunnel_build_state(u16 encap_type,
 }
 EXPORT_SYMBOL(lwtunnel_build_state);
 
-int lwtunnel_valid_encap_type(u16 encap_type)
+int lwtunnel_valid_encap_type(u16 encap_type, struct netlink_ext_ack *extack)
 {
        const struct lwtunnel_encap_ops *ops;
        int ret = -EINVAL;
 
        if (encap_type == LWTUNNEL_ENCAP_NONE ||
-           encap_type > LWTUNNEL_ENCAP_MAX)
+           encap_type > LWTUNNEL_ENCAP_MAX) {
+               NL_SET_ERR_MSG(extack, "Unknown lwt encapsulation type");
                return ret;
+       }
 
        rcu_read_lock();
        ops = rcu_dereference(lwtun_encaps[encap_type]);
@@ -153,11 +155,16 @@ int lwtunnel_valid_encap_type(u16 encap_type)
                }
        }
 #endif
-       return ops ? 0 : -EOPNOTSUPP;
+       ret = ops ? 0 : -EOPNOTSUPP;
+       if (ret < 0)
+               NL_SET_ERR_MSG(extack, "lwt encapsulation type not supported");
+
+       return ret;
 }
 EXPORT_SYMBOL(lwtunnel_valid_encap_type);
 
-int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining)
+int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining,
+                                  struct netlink_ext_ack *extack)
 {
        struct rtnexthop *rtnh = (struct rtnexthop *)attr;
        struct nlattr *nla_entype;
@@ -174,7 +181,8 @@ int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining)
                        if (nla_entype) {
                                encap_type = nla_get_u16(nla_entype);
 
-                               if (lwtunnel_valid_encap_type(encap_type) != 0)
+                               if (lwtunnel_valid_encap_type(encap_type,
+                                                             extack) != 0)
                                        return -EOPNOTSUPP;
                        }
                }
index 715b7967d8ea4e9dcb9de7884263b1615763c1cc..4e678fa892ddcf1985fb37c3627a660a8f69da9d 100644 (file)
@@ -685,7 +685,8 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
                        break;
                case RTA_MULTIPATH:
                        err = lwtunnel_valid_encap_type_attr(nla_data(attr),
-                                                            nla_len(attr));
+                                                            nla_len(attr),
+                                                            extack);
                        if (err < 0)
                                goto errout;
                        cfg->fc_mp = nla_data(attr);
@@ -702,7 +703,8 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
                        break;
                case RTA_ENCAP_TYPE:
                        cfg->fc_encap_type = nla_get_u16(attr);
-                       err = lwtunnel_valid_encap_type(cfg->fc_encap_type);
+                       err = lwtunnel_valid_encap_type(cfg->fc_encap_type,
+                                                       extack);
                        if (err < 0)
                                goto errout;
                        break;
index 2fe84bdc4e603fd2b0487e48c3b411430208ed6a..524a76b5206e2e5742aab554010d13b9edb4cc9e 100644 (file)
@@ -3016,7 +3016,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
                cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]);
 
                err = lwtunnel_valid_encap_type_attr(cfg->fc_mp,
-                                                    cfg->fc_mp_len);
+                                                    cfg->fc_mp_len, extack);
                if (err < 0)
                        goto errout;
        }
@@ -3035,7 +3035,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
        if (tb[RTA_ENCAP_TYPE]) {
                cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]);
 
-               err = lwtunnel_valid_encap_type(cfg->fc_encap_type);
+               err = lwtunnel_valid_encap_type(cfg->fc_encap_type, extack);
                if (err < 0)
                        goto errout;
        }