netlink: add policy validation function for binary attributes
Johannes Berg
maintainerRFC 1/1 netlink: add policy validation function for binary attributes
From: Johannes Berg <[email protected]>
Add the ability to have an arbitrary validation function attached to NLA_BINARY.
NOTE: obviously, the nl80211 part should be split off, that's just
to show how it might be used - saves ~1.2KiB there (x86-64)
NOTE: should probably allow this for the exact length fields, and
perhaps even provide a general NLA_POLICY_VALID_ETH_ADDR define and similar?
--- include/net/netlink.h | 6 +++++ lib/nlattr.c | 6 +++++ net/wireless/nl80211.c | 67 ++++++++++++++------------------------------------ 3 files changed, 31 insertions(+), 48 deletions(-)
include/net/netlink.h +6 -0
@@ -256,6 +256,10 @@ enum {* of s16 - do that as usual in the code instead. * All other Unused - but note that it's a union * +* Meaning of `validate' field: +* NLA_BINARY Validation function called for the binary attribute +* All other Unused - but note that it's a union +* * Example: * static const struct nla_policy my_policy[ATTR_MAX+1] = { * [ATTR_FOO] = { .type = NLA_U16 },
@@ -272,6 +276,8 @@ struct nla_policy {struct {s16 min, max; }; +int (*validate)(const struct nlattr *attr, +struct netlink_ext_ack *extack); }; };
lib/nlattr.c +6 -0
@@ -175,6 +175,12 @@ static int validate_nla(const struct nlattr *nla, int maxtype,case NLA_BINARY :if (pt->len && attrlen > pt->len) goto out_err; + +if (pt->len && pt->validate) { + err = pt->validate (nla, extack); +if (err) +return err; + }break ;case NLA_NESTED :
net/wireless/nl80211.c +19 -48
195 lines not on this page · raw message
Signature · 1 line
2.14.4