Commit a1f10abe authored by David Ahern's avatar David Ahern Committed by David S. Miller

net: Fill in extack for mpls lwt encap

Fill in extack for errors in build_state for mpls lwt encap including
passing extack to nla_get_labels and adding error messages for failures
in it.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9ae28727
...@@ -728,8 +728,8 @@ static int mpls_nh_build(struct net *net, struct mpls_route *rt, ...@@ -728,8 +728,8 @@ static int mpls_nh_build(struct net *net, struct mpls_route *rt,
goto errout; goto errout;
if (newdst) { if (newdst) {
err = nla_get_labels(newdst, max_labels, err = nla_get_labels(newdst, max_labels, &nh->nh_labels,
&nh->nh_labels, nh->nh_label); nh->nh_label, NULL);
if (err) if (err)
goto errout; goto errout;
} }
...@@ -782,7 +782,8 @@ static u8 mpls_count_nexthops(struct rtnexthop *rtnh, int len, ...@@ -782,7 +782,8 @@ static u8 mpls_count_nexthops(struct rtnexthop *rtnh, int len,
nla = nla_find(attrs, attrlen, RTA_NEWDST); nla = nla_find(attrs, attrlen, RTA_NEWDST);
if (nla && if (nla &&
nla_get_labels(nla, MAX_NEW_LABELS, &n_labels, NULL) != 0) nla_get_labels(nla, MAX_NEW_LABELS, &n_labels,
NULL, NULL) != 0)
return 0; return 0;
*max_labels = max_t(u8, *max_labels, n_labels); *max_labels = max_t(u8, *max_labels, n_labels);
...@@ -1541,8 +1542,8 @@ int nla_put_labels(struct sk_buff *skb, int attrtype, ...@@ -1541,8 +1542,8 @@ int nla_put_labels(struct sk_buff *skb, int attrtype,
} }
EXPORT_SYMBOL_GPL(nla_put_labels); EXPORT_SYMBOL_GPL(nla_put_labels);
int nla_get_labels(const struct nlattr *nla, int nla_get_labels(const struct nlattr *nla, u8 max_labels, u8 *labels,
u8 max_labels, u8 *labels, u32 label[]) u32 label[], struct netlink_ext_ack *extack)
{ {
unsigned len = nla_len(nla); unsigned len = nla_len(nla);
struct mpls_shim_hdr *nla_label; struct mpls_shim_hdr *nla_label;
...@@ -1553,13 +1554,18 @@ int nla_get_labels(const struct nlattr *nla, ...@@ -1553,13 +1554,18 @@ int nla_get_labels(const struct nlattr *nla,
/* len needs to be an even multiple of 4 (the label size). Number /* len needs to be an even multiple of 4 (the label size). Number
* of labels is a u8 so check for overflow. * of labels is a u8 so check for overflow.
*/ */
if (len & 3 || len / 4 > 255) if (len & 3 || len / 4 > 255) {
NL_SET_ERR_MSG_ATTR(extack, nla,
"Invalid length for labels attribute");
return -EINVAL; return -EINVAL;
}
/* Limit the number of new labels allowed */ /* Limit the number of new labels allowed */
nla_labels = len/4; nla_labels = len/4;
if (nla_labels > max_labels) if (nla_labels > max_labels) {
NL_SET_ERR_MSG(extack, "Too many labels");
return -EINVAL; return -EINVAL;
}
/* when label == NULL, caller wants number of labels */ /* when label == NULL, caller wants number of labels */
if (!label) if (!label)
...@@ -1574,8 +1580,29 @@ int nla_get_labels(const struct nlattr *nla, ...@@ -1574,8 +1580,29 @@ int nla_get_labels(const struct nlattr *nla,
/* Ensure the bottom of stack flag is properly set /* Ensure the bottom of stack flag is properly set
* and ttl and tc are both clear. * and ttl and tc are both clear.
*/ */
if ((dec.bos != bos) || dec.ttl || dec.tc) if (dec.ttl) {
NL_SET_ERR_MSG_ATTR(extack, nla,
"TTL in label must be 0");
return -EINVAL;
}
if (dec.tc) {
NL_SET_ERR_MSG_ATTR(extack, nla,
"Traffic class in label must be 0");
return -EINVAL; return -EINVAL;
}
if (dec.bos != bos) {
NL_SET_BAD_ATTR(extack, nla);
if (bos) {
NL_SET_ERR_MSG(extack,
"BOS bit must be set in first label");
} else {
NL_SET_ERR_MSG(extack,
"BOS bit can only be set in first label");
}
return -EINVAL;
}
switch (dec.label) { switch (dec.label) {
case MPLS_LABEL_IMPLNULL: case MPLS_LABEL_IMPLNULL:
...@@ -1583,6 +1610,8 @@ int nla_get_labels(const struct nlattr *nla, ...@@ -1583,6 +1610,8 @@ int nla_get_labels(const struct nlattr *nla,
* assign and distribute, but which never * assign and distribute, but which never
* actually appears in the encapsulation. * actually appears in the encapsulation.
*/ */
NL_SET_ERR_MSG_ATTR(extack, nla,
"Implicit NULL Label (3) can not be used in encapsulation");
return -EINVAL; return -EINVAL;
} }
...@@ -1696,14 +1725,14 @@ static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1696,14 +1725,14 @@ static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh,
case RTA_NEWDST: case RTA_NEWDST:
if (nla_get_labels(nla, MAX_NEW_LABELS, if (nla_get_labels(nla, MAX_NEW_LABELS,
&cfg->rc_output_labels, &cfg->rc_output_labels,
cfg->rc_output_label)) cfg->rc_output_label, NULL))
goto errout; goto errout;
break; break;
case RTA_DST: case RTA_DST:
{ {
u8 label_count; u8 label_count;
if (nla_get_labels(nla, 1, &label_count, if (nla_get_labels(nla, 1, &label_count,
&cfg->rc_label)) &cfg->rc_label, NULL))
goto errout; goto errout;
/* Reserved labels may not be set */ /* Reserved labels may not be set */
......
...@@ -203,7 +203,7 @@ static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev) ...@@ -203,7 +203,7 @@ static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)
int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels, int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
const u32 label[]); const u32 label[]);
int nla_get_labels(const struct nlattr *nla, u8 max_labels, u8 *labels, int nla_get_labels(const struct nlattr *nla, u8 max_labels, u8 *labels,
u32 label[]); u32 label[], struct netlink_ext_ack *extack);
int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table, int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
u8 via[]); u8 via[]);
bool mpls_output_possible(const struct net_device *dev); bool mpls_output_possible(const struct net_device *dev);
......
...@@ -173,13 +173,14 @@ static int mpls_build_state(struct nlattr *nla, ...@@ -173,13 +173,14 @@ static int mpls_build_state(struct nlattr *nla,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!tb[MPLS_IPTUNNEL_DST]) if (!tb[MPLS_IPTUNNEL_DST]) {
NL_SET_ERR_MSG(extack, "MPLS_IPTUNNEL_DST attribute is missing");
return -EINVAL; return -EINVAL;
}
/* determine number of labels */ /* determine number of labels */
if (nla_get_labels(tb[MPLS_IPTUNNEL_DST], if (nla_get_labels(tb[MPLS_IPTUNNEL_DST], MAX_NEW_LABELS,
MAX_NEW_LABELS, &n_labels, NULL)) &n_labels, NULL, extack))
return -EINVAL; return -EINVAL;
newts = lwtunnel_state_alloc(sizeof(*tun_encap_info) + newts = lwtunnel_state_alloc(sizeof(*tun_encap_info) +
...@@ -189,7 +190,8 @@ static int mpls_build_state(struct nlattr *nla, ...@@ -189,7 +190,8 @@ static int mpls_build_state(struct nlattr *nla,
tun_encap_info = mpls_lwtunnel_encap(newts); tun_encap_info = mpls_lwtunnel_encap(newts);
ret = nla_get_labels(tb[MPLS_IPTUNNEL_DST], n_labels, ret = nla_get_labels(tb[MPLS_IPTUNNEL_DST], n_labels,
&tun_encap_info->labels, tun_encap_info->label); &tun_encap_info->labels, tun_encap_info->label,
extack);
if (ret) if (ret)
goto errout; goto errout;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment