Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 66815
b: refs/heads/master
c: e373057
h: refs/heads/master
i:
  66813: a8db2d3
  66811: 2b7733a
  66807: 50cd0f1
  66799: c141122
  66783: 757c446
  66751: f4e184b
  66687: 50b1ed2
  66559: f6416ee
v: v3
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Oct 10, 2007
1 parent 0aa6d30 commit df0a3b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 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: dd82185f2c55e9dc2247c83d78517ef14e71d30e
refs/heads/master: e3730578285fcf0c628f08b0dc89425cfeafd4ba
3 changes: 2 additions & 1 deletion trunk/include/linux/netfilter/nfnetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct nfnl_callback
{
int (*call)(struct sock *nl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nlattr *cda[]);
u_int16_t attr_count; /* number of nlattr's */
const struct nla_policy *policy; /* netlink attribute policy */
const u_int16_t attr_count; /* number of nlattr's */
};

struct nfnetlink_subsystem
Expand Down
48 changes: 13 additions & 35 deletions trunk/net/netfilter/nfnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ nfnetlink_find_client(u_int16_t type, const struct nfnetlink_subsystem *ss)
return &ss->cb[cb_id];
}

/**
* nfnetlink_check_attributes - check and parse nfnetlink attributes
*
* subsys: nfnl subsystem for which this message is to be parsed
* nlmsghdr: netlink message to be checked/parsed
* cda: array of pointers, needs to be at least subsys->attr_count+1 big
*
*/
static int
nfnetlink_check_attributes(const struct nfnetlink_subsystem *subsys,
struct nlmsghdr *nlh, struct nlattr *cda[])
{
int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
u_int16_t attr_count = subsys->cb[cb_id].attr_count;

/* check attribute lengths. */
if (likely(nlh->nlmsg_len > min_len)) {
struct nlattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
nla_parse(cda, attr_count, attr, attrlen, NULL);
}

/* implicit: if nlmsg_len == min_len, we return 0, and an empty
* (zeroed) cda[] array. The message is valid, but empty. */

return 0;
}

int nfnetlink_has_listeners(unsigned int group)
{
return netlink_has_listeners(nfnl, group);
Expand Down Expand Up @@ -192,15 +163,22 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
return -EINVAL;

{
u_int16_t attr_count =
ss->cb[NFNL_MSG_TYPE(nlh->nlmsg_type)].attr_count;
int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
u_int16_t attr_count = ss->cb[cb_id].attr_count;
struct nlattr *cda[attr_count+1];

memset(cda, 0, sizeof(struct nlattr *) * attr_count);
if (likely(nlh->nlmsg_len >= min_len)) {
struct nlattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);

err = nla_parse(cda, attr_count, attr, attrlen,
ss->cb[cb_id].policy);
if (err < 0)
return err;
} else
return -EINVAL;

err = nfnetlink_check_attributes(ss, nlh, cda);
if (err < 0)
return err;
return nc->call(nfnl, skb, nlh, cda);
}
}
Expand Down

0 comments on commit df0a3b0

Please sign in to comment.