Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 111320
b: refs/heads/master
c: 2c10b32
h: refs/heads/master
v: v3
  • Loading branch information
Thomas Graf authored and David S. Miller committed Sep 3, 2008
1 parent 6389975 commit 5d2a9b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 90 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b171e19ed08c8ba832e5325fadf1be493f56665d
refs/heads/master: 2c10b32bf57db7ec6d4cca4c4aa3d86bacb01c8a
82 changes: 0 additions & 82 deletions trunk/include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@
* Nested Attributes Construction:
* nla_nest_start(skb, type) start a nested attribute
* nla_nest_end(skb, nla) finalize a nested attribute
* nla_nest_compat_start(skb, type, start a nested compat attribute
* len, data)
* nla_nest_compat_end(skb, type) finalize a nested compat attribute
* nla_nest_cancel(skb, nla) cancel nested attribute construction
*
* Attribute Length Calculations:
Expand Down Expand Up @@ -156,7 +153,6 @@
* nla_find_nested() find attribute in nested attributes
* nla_parse() parse and validate stream of attrs
* nla_parse_nested() parse nested attribuets
* nla_parse_nested_compat() parse nested compat attributes
* nla_for_each_attr() loop over all attributes
* nla_for_each_nested() loop over the nested attributes
*=========================================================================
Expand Down Expand Up @@ -751,39 +747,6 @@ static inline int nla_parse_nested(struct nlattr *tb[], int maxtype,
return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
}

/**
* nla_parse_nested_compat - parse nested compat attributes
* @tb: destination array with maxtype+1 elements
* @maxtype: maximum attribute type to be expected
* @nla: attribute containing the nested attributes
* @data: pointer to point to contained structure
* @len: length of contained structure
* @policy: validation policy
*
* Parse a nested compat attribute. The compat attribute contains a structure
* and optionally a set of nested attributes. On success the data pointer
* points to the nested data and tb contains the parsed attributes
* (see nla_parse).
*/
static inline int __nla_parse_nested_compat(struct nlattr *tb[], int maxtype,
struct nlattr *nla,
const struct nla_policy *policy,
int len)
{
int nested_len = nla_len(nla) - NLA_ALIGN(len);

if (nested_len < 0)
return -EINVAL;
if (nested_len >= nla_attr_size(0))
return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len),
nested_len, policy);
memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
return 0;
}

#define nla_parse_nested_compat(tb, maxtype, nla, policy, data, len) \
({ data = nla_len(nla) >= len ? nla_data(nla) : NULL; \
__nla_parse_nested_compat(tb, maxtype, nla, policy, len); })
/**
* nla_put_u8 - Add a u8 netlink attribute to a socket buffer
* @skb: socket buffer to add attribute to
Expand Down Expand Up @@ -1030,51 +993,6 @@ static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start)
return skb->len;
}

/**
* nla_nest_compat_start - Start a new level of nested compat attributes
* @skb: socket buffer to add attributes to
* @attrtype: attribute type of container
* @attrlen: length of structure
* @data: pointer to structure
*
* Start a nested compat attribute that contains both a structure and
* a set of nested attributes.
*
* Returns the container attribute
*/
static inline struct nlattr *nla_nest_compat_start(struct sk_buff *skb,
int attrtype, int attrlen,
const void *data)
{
struct nlattr *start = (struct nlattr *)skb_tail_pointer(skb);

if (nla_put(skb, attrtype, attrlen, data) < 0)
return NULL;
if (nla_nest_start(skb, attrtype) == NULL) {
nlmsg_trim(skb, start);
return NULL;
}
return start;
}

/**
* nla_nest_compat_end - Finalize nesting of compat attributes
* @skb: socket buffer the attributes are stored in
* @start: container attribute
*
* Corrects the container attribute header to include the all
* appeneded attributes.
*
* Returns the total data length of the skb.
*/
static inline int nla_nest_compat_end(struct sk_buff *skb, struct nlattr *start)
{
struct nlattr *nest = (void *)start + NLMSG_ALIGN(start->nla_len);

start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start;
return nla_nest_end(skb, nest);
}

/**
* nla_nest_cancel - Cancel nesting of attributes
* @skb: socket buffer the message is stored in
Expand Down
18 changes: 16 additions & 2 deletions trunk/net/sched/sch_netem.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,20 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
[TCA_NETEM_CORRUPT] = { .len = sizeof(struct tc_netem_corrupt) },
};

static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
const struct nla_policy *policy, int len)
{
int nested_len = nla_len(nla) - NLA_ALIGN(len);

if (nested_len < 0)
return -EINVAL;
if (nested_len >= nla_attr_size(0))
return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len),
nested_len, policy);
memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
return 0;
}

/* Parse netlink message to set options */
static int netem_change(struct Qdisc *sch, struct nlattr *opt)
{
Expand All @@ -399,8 +413,8 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
if (opt == NULL)
return -EINVAL;

ret = nla_parse_nested_compat(tb, TCA_NETEM_MAX, opt, netem_policy,
qopt, sizeof(*qopt));
qopt = nla_data(opt);
ret = parse_attr(tb, TCA_NETEM_MAX, opt, netem_policy, sizeof(*qopt));
if (ret < 0)
return ret;

Expand Down
6 changes: 1 addition & 5 deletions trunk/net/sched/sch_prio.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,12 @@ static int prio_dump(struct Qdisc *sch, struct sk_buff *skb)
{
struct prio_sched_data *q = qdisc_priv(sch);
unsigned char *b = skb_tail_pointer(skb);
struct nlattr *nest;
struct tc_prio_qopt opt;

opt.bands = q->bands;
memcpy(&opt.priomap, q->prio2band, TC_PRIO_MAX+1);

nest = nla_nest_compat_start(skb, TCA_OPTIONS, sizeof(opt), &opt);
if (nest == NULL)
goto nla_put_failure;
nla_nest_compat_end(skb, nest);
NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);

return skb->len;

Expand Down

0 comments on commit 5d2a9b6

Please sign in to comment.