Skip to content

Commit

Permalink
[NETLINK]: introduce NLA_BINARY type
Browse files Browse the repository at this point in the history
This patch introduces a new NLA_BINARY attribute policy type with the
verification of simply checking the maximum length of the payload.

It also fixes a small typo in the example.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Johannes Berg authored and David S. Miller committed Apr 26, 2007
1 parent 7033157 commit d30045a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum {
NLA_MSECS,
NLA_NESTED,
NLA_NUL_STRING,
NLA_BINARY,
__NLA_TYPE_MAX,
};

Expand All @@ -188,12 +189,13 @@ enum {
* NLA_STRING Maximum length of string
* NLA_NUL_STRING Maximum length of string (excluding NUL)
* NLA_FLAG Unused
* NLA_BINARY Maximum length of attribute payload
* All other Exact length of attribute payload
*
* Example:
* static struct nla_policy my_policy[ATTR_MAX+1] __read_mostly = {
* [ATTR_FOO] = { .type = NLA_U16 },
* [ATTR_BAR] = { .type = NLA_STRING, len = BARSIZ },
* [ATTR_BAR] = { .type = NLA_STRING, .len = BARSIZ },
* [ATTR_BAZ] = { .len = sizeof(struct mystruct) },
* };
*/
Expand Down
5 changes: 5 additions & 0 deletions net/netlink/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ static int validate_nla(struct nlattr *nla, int maxtype,
}
break;

case NLA_BINARY:
if (pt->len && attrlen > pt->len)
return -ERANGE;
break;

default:
if (pt->len)
minlen = pt->len;
Expand Down

0 comments on commit d30045a

Please sign in to comment.