diff options
author | Johannes Berg <johannes.berg@intel.com> | 2010-10-04 15:14:03 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2010-10-05 13:35:30 -0400 |
commit | ff4c92d85c6f2777d2067f8552e7fefb4d1754ae (patch) | |
tree | 77e35603821e5602e96c90644e42e70f097ad79c /include/net/genetlink.h | |
parent | 2ee4e27cf25ab647137713ca16377d8d9e138ea2 (diff) |
genetlink: introduce pre_doit/post_doit hooks
Each family may have some amount of boilerplate
locking code that applies to most, or even all,
commands.
This allows a family to handle such things in
a more generic way, by allowing it to
a) include private flags in each operation
b) specify a pre_doit hook that is called,
before an operation's doit() callback and
may return an error directly,
c) specify a post_doit hook that can undo
locking or similar things done by pre_doit,
and finally
d) include two private pointers in each info
struct passed between all these operations
including doit(). (It's two because I'll
need two in nl80211 -- can be extended.)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'include/net/genetlink.h')
-rw-r--r-- | include/net/genetlink.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/net/genetlink.h b/include/net/genetlink.h index f7dcd2c70412..8a64b811a39a 100644 --- a/include/net/genetlink.h +++ b/include/net/genetlink.h | |||
@@ -20,6 +20,9 @@ struct genl_multicast_group { | |||
20 | u32 id; | 20 | u32 id; |
21 | }; | 21 | }; |
22 | 22 | ||
23 | struct genl_ops; | ||
24 | struct genl_info; | ||
25 | |||
23 | /** | 26 | /** |
24 | * struct genl_family - generic netlink family | 27 | * struct genl_family - generic netlink family |
25 | * @id: protocol family idenfitier | 28 | * @id: protocol family idenfitier |
@@ -29,6 +32,10 @@ struct genl_multicast_group { | |||
29 | * @maxattr: maximum number of attributes supported | 32 | * @maxattr: maximum number of attributes supported |
30 | * @netnsok: set to true if the family can handle network | 33 | * @netnsok: set to true if the family can handle network |
31 | * namespaces and should be presented in all of them | 34 | * namespaces and should be presented in all of them |
35 | * @pre_doit: called before an operation's doit callback, it may | ||
36 | * do additional, common, filtering and return an error | ||
37 | * @post_doit: called after an operation's doit callback, it may | ||
38 | * undo operations done by pre_doit, for example release locks | ||
32 | * @attrbuf: buffer to store parsed attributes | 39 | * @attrbuf: buffer to store parsed attributes |
33 | * @ops_list: list of all assigned operations | 40 | * @ops_list: list of all assigned operations |
34 | * @family_list: family list | 41 | * @family_list: family list |
@@ -41,6 +48,12 @@ struct genl_family { | |||
41 | unsigned int version; | 48 | unsigned int version; |
42 | unsigned int maxattr; | 49 | unsigned int maxattr; |
43 | bool netnsok; | 50 | bool netnsok; |
51 | int (*pre_doit)(struct genl_ops *ops, | ||
52 | struct sk_buff *skb, | ||
53 | struct genl_info *info); | ||
54 | void (*post_doit)(struct genl_ops *ops, | ||
55 | struct sk_buff *skb, | ||
56 | struct genl_info *info); | ||
44 | struct nlattr ** attrbuf; /* private */ | 57 | struct nlattr ** attrbuf; /* private */ |
45 | struct list_head ops_list; /* private */ | 58 | struct list_head ops_list; /* private */ |
46 | struct list_head family_list; /* private */ | 59 | struct list_head family_list; /* private */ |
@@ -55,6 +68,8 @@ struct genl_family { | |||
55 | * @genlhdr: generic netlink message header | 68 | * @genlhdr: generic netlink message header |
56 | * @userhdr: user specific header | 69 | * @userhdr: user specific header |
57 | * @attrs: netlink attributes | 70 | * @attrs: netlink attributes |
71 | * @_net: network namespace | ||
72 | * @user_ptr: user pointers | ||
58 | */ | 73 | */ |
59 | struct genl_info { | 74 | struct genl_info { |
60 | u32 snd_seq; | 75 | u32 snd_seq; |
@@ -66,6 +81,7 @@ struct genl_info { | |||
66 | #ifdef CONFIG_NET_NS | 81 | #ifdef CONFIG_NET_NS |
67 | struct net * _net; | 82 | struct net * _net; |
68 | #endif | 83 | #endif |
84 | void * user_ptr[2]; | ||
69 | }; | 85 | }; |
70 | 86 | ||
71 | static inline struct net *genl_info_net(struct genl_info *info) | 87 | static inline struct net *genl_info_net(struct genl_info *info) |
@@ -81,6 +97,7 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net) | |||
81 | /** | 97 | /** |
82 | * struct genl_ops - generic netlink operations | 98 | * struct genl_ops - generic netlink operations |
83 | * @cmd: command identifier | 99 | * @cmd: command identifier |
100 | * @internal_flags: flags used by the family | ||
84 | * @flags: flags | 101 | * @flags: flags |
85 | * @policy: attribute validation policy | 102 | * @policy: attribute validation policy |
86 | * @doit: standard command callback | 103 | * @doit: standard command callback |
@@ -90,6 +107,7 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net) | |||
90 | */ | 107 | */ |
91 | struct genl_ops { | 108 | struct genl_ops { |
92 | u8 cmd; | 109 | u8 cmd; |
110 | u8 internal_flags; | ||
93 | unsigned int flags; | 111 | unsigned int flags; |
94 | const struct nla_policy *policy; | 112 | const struct nla_policy *policy; |
95 | int (*doit)(struct sk_buff *skb, | 113 | int (*doit)(struct sk_buff *skb, |