Linux 2.6.20.13
[linux/fpc-iii.git] / include / net / genetlink.h
blobadff4c898d50ea40d5a4b09afedbf708c0c508f8
1 #ifndef __NET_GENERIC_NETLINK_H
2 #define __NET_GENERIC_NETLINK_H
4 #include <linux/genetlink.h>
5 #include <net/netlink.h>
7 /**
8 * struct genl_family - generic netlink family
9 * @id: protocol family idenfitier
10 * @hdrsize: length of user specific header in bytes
11 * @name: name of family
12 * @version: protocol version
13 * @maxattr: maximum number of attributes supported
14 * @attrbuf: buffer to store parsed attributes
15 * @ops_list: list of all assigned operations
16 * @family_list: family list
18 struct genl_family
20 unsigned int id;
21 unsigned int hdrsize;
22 char name[GENL_NAMSIZ];
23 unsigned int version;
24 unsigned int maxattr;
25 struct nlattr ** attrbuf; /* private */
26 struct list_head ops_list; /* private */
27 struct list_head family_list; /* private */
30 /**
31 * struct genl_info - receiving information
32 * @snd_seq: sending sequence number
33 * @snd_pid: netlink pid of sender
34 * @nlhdr: netlink message header
35 * @genlhdr: generic netlink message header
36 * @userhdr: user specific header
37 * @attrs: netlink attributes
39 struct genl_info
41 u32 snd_seq;
42 u32 snd_pid;
43 struct nlmsghdr * nlhdr;
44 struct genlmsghdr * genlhdr;
45 void * userhdr;
46 struct nlattr ** attrs;
49 /**
50 * struct genl_ops - generic netlink operations
51 * @cmd: command identifier
52 * @flags: flags
53 * @policy: attribute validation policy
54 * @doit: standard command callback
55 * @dumpit: callback for dumpers
56 * @done: completion callback for dumps
57 * @ops_list: operations list
59 struct genl_ops
61 u8 cmd;
62 unsigned int flags;
63 struct nla_policy *policy;
64 int (*doit)(struct sk_buff *skb,
65 struct genl_info *info);
66 int (*dumpit)(struct sk_buff *skb,
67 struct netlink_callback *cb);
68 int (*done)(struct netlink_callback *cb);
69 struct list_head ops_list;
72 extern int genl_register_family(struct genl_family *family);
73 extern int genl_unregister_family(struct genl_family *family);
74 extern int genl_register_ops(struct genl_family *, struct genl_ops *ops);
75 extern int genl_unregister_ops(struct genl_family *, struct genl_ops *ops);
77 extern struct sock *genl_sock;
79 /**
80 * genlmsg_put - Add generic netlink header to netlink message
81 * @skb: socket buffer holding the message
82 * @pid: netlink pid the message is addressed to
83 * @seq: sequence number (usually the one of the sender)
84 * @family: generic netlink family
85 * @flags netlink message flags
86 * @cmd: generic netlink command
88 * Returns pointer to user specific header
90 static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq,
91 struct genl_family *family, int flags, u8 cmd)
93 struct nlmsghdr *nlh;
94 struct genlmsghdr *hdr;
96 nlh = nlmsg_put(skb, pid, seq, family->id, GENL_HDRLEN +
97 family->hdrsize, flags);
98 if (nlh == NULL)
99 return NULL;
101 hdr = nlmsg_data(nlh);
102 hdr->cmd = cmd;
103 hdr->version = family->version;
104 hdr->reserved = 0;
106 return (char *) hdr + GENL_HDRLEN;
110 * genlmsg_put_reply - Add generic netlink header to a reply message
111 * @skb: socket buffer holding the message
112 * @info: receiver info
113 * @family: generic netlink family
114 * @flags: netlink message flags
115 * @cmd: generic netlink command
117 * Returns pointer to user specific header
119 static inline void *genlmsg_put_reply(struct sk_buff *skb,
120 struct genl_info *info,
121 struct genl_family *family,
122 int flags, u8 cmd)
124 return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
125 flags, cmd);
129 * genlmsg_end - Finalize a generic netlink message
130 * @skb: socket buffer the message is stored in
131 * @hdr: user specific header
133 static inline int genlmsg_end(struct sk_buff *skb, void *hdr)
135 return nlmsg_end(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN);
139 * genlmsg_cancel - Cancel construction of a generic netlink message
140 * @skb: socket buffer the message is stored in
141 * @hdr: generic netlink message header
143 static inline int genlmsg_cancel(struct sk_buff *skb, void *hdr)
145 return nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN);
149 * genlmsg_multicast - multicast a netlink message
150 * @skb: netlink message as socket buffer
151 * @pid: own netlink pid to avoid sending to yourself
152 * @group: multicast group id
153 * @flags: allocation flags
155 static inline int genlmsg_multicast(struct sk_buff *skb, u32 pid,
156 unsigned int group, gfp_t flags)
158 return nlmsg_multicast(genl_sock, skb, pid, group, flags);
162 * genlmsg_unicast - unicast a netlink message
163 * @skb: netlink message as socket buffer
164 * @pid: netlink pid of the destination socket
166 static inline int genlmsg_unicast(struct sk_buff *skb, u32 pid)
168 return nlmsg_unicast(genl_sock, skb, pid);
172 * genlmsg_reply - reply to a request
173 * @skb: netlink message to be sent back
174 * @info: receiver information
176 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
178 return genlmsg_unicast(skb, info->snd_pid);
182 * gennlmsg_data - head of message payload
183 * @gnlh: genetlink messsage header
185 static inline void *genlmsg_data(const struct genlmsghdr *gnlh)
187 return ((unsigned char *) gnlh + GENL_HDRLEN);
191 * genlmsg_len - length of message payload
192 * @gnlh: genetlink message header
194 static inline int genlmsg_len(const struct genlmsghdr *gnlh)
196 struct nlmsghdr *nlh = (struct nlmsghdr *)((unsigned char *)gnlh -
197 NLMSG_HDRLEN);
198 return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN);
202 * genlmsg_msg_size - length of genetlink message not including padding
203 * @payload: length of message payload
205 static inline int genlmsg_msg_size(int payload)
207 return GENL_HDRLEN + payload;
211 * genlmsg_total_size - length of genetlink message including padding
212 * @payload: length of message payload
214 static inline int genlmsg_total_size(int payload)
216 return NLMSG_ALIGN(genlmsg_msg_size(payload));
220 * genlmsg_new - Allocate a new generic netlink message
221 * @payload: size of the message payload
222 * @flags: the type of memory to allocate.
224 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
226 return nlmsg_new(genlmsg_total_size(payload), flags);
230 #endif /* __NET_GENERIC_NETLINK_H */