[NETLINK]: introduce NLA_BINARY type
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 23 Mar 2007 18:37:48 +0000 (11:37 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 26 Apr 2007 05:28:05 +0000 (22:28 -0700)
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>
include/net/netlink.h
net/netlink/attr.c

index 1c11518fc8228fc6a30f24789eee8b80530e3d85..2e4c90a98a7f6293b94d907459082f77be9fb678 100644 (file)
@@ -171,6 +171,7 @@ enum {
        NLA_MSECS,
        NLA_NESTED,
        NLA_NUL_STRING,
+       NLA_BINARY,
        __NLA_TYPE_MAX,
 };
 
@@ -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) },
  * };
  */
index 004139557e09507f01969754cc779002e1fcfbc9..df5f820a4c325be1547b778031b1f9bfcd159ca7 100644 (file)
@@ -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;