diff options
author | Thomas Graf <tgr@deb.localdomain> | 2008-01-10 12:35:38 +0100 |
---|---|---|
committer | Thomas Graf <tgr@deb.localdomain> | 2008-01-10 12:35:38 +0100 |
commit | c8a0a5cdfba51f7de5d203aa13a97377b215515a (patch) | |
tree | 45f00d29489e27e29a9a0359339c3234bc5a9b3c /lib/msg.c | |
parent | 373bc7854537cf931a73b18ea126e75fd2f13935 (diff) |
Added additional parsing and validation functions for generic netlink
Also adds better example documentation for generic netlink
Diffstat (limited to 'lib/msg.c')
-rw-r--r-- | lib/msg.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -261,6 +261,14 @@ int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen) * @{ */ +int nlmsg_valid_hdr(const struct nlmsghdr *nlh, int hdrlen) +{ + if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) + return 0; + + return 1; +} + /** * check if the netlink message fits into the remaining bytes * @arg nlh netlink message header @@ -303,7 +311,7 @@ struct nlmsghdr *nlmsg_next(struct nlmsghdr *nlh, int *remaining) int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy) { - if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) + if (!nlmsg_valid_hdr(nlh, hdrlen)) return nl_errno(EINVAL); return nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen), @@ -334,7 +342,7 @@ struct nlattr *nlmsg_find_attr(struct nlmsghdr *nlh, int hdrlen, int attrtype) int nlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype, struct nla_policy *policy) { - if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) + if (!nlmsg_valid_hdr(nlh, hdrlen)) return nl_errno(EINVAL); return nla_validate(nlmsg_attrdata(nlh, hdrlen), |