| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 1 | #ifndef __NET_GENERIC_NETLINK_H | 
|  | 2 | #define __NET_GENERIC_NETLINK_H | 
|  | 3 |  | 
|  | 4 | #include <linux/genetlink.h> | 
|  | 5 | #include <net/netlink.h> | 
|  | 6 |  | 
|  | 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 | 
|  | 17 | */ | 
|  | 18 | struct genl_family | 
|  | 19 | { | 
|  | 20 | unsigned int		id; | 
|  | 21 | unsigned int		hdrsize; | 
|  | 22 | char			name[GENL_NAMSIZ]; | 
|  | 23 | unsigned int		version; | 
|  | 24 | unsigned int		maxattr; | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 25 | struct nlattr **	attrbuf;	/* private */ | 
|  | 26 | struct list_head	ops_list;	/* private */ | 
|  | 27 | struct list_head	family_list;	/* private */ | 
|  | 28 | }; | 
|  | 29 |  | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 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 | 
|  | 38 | */ | 
|  | 39 | struct genl_info | 
|  | 40 | { | 
|  | 41 | u32			snd_seq; | 
|  | 42 | u32			snd_pid; | 
|  | 43 | struct nlmsghdr *	nlhdr; | 
|  | 44 | struct genlmsghdr *	genlhdr; | 
|  | 45 | void *			userhdr; | 
|  | 46 | struct nlattr **	attrs; | 
|  | 47 | }; | 
|  | 48 |  | 
|  | 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 | * @ops_list: operations list | 
|  | 57 | */ | 
|  | 58 | struct genl_ops | 
|  | 59 | { | 
| Per Liden | b461d2f | 2006-01-03 14:13:29 -0800 | [diff] [blame] | 60 | u8			cmd; | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 61 | unsigned int		flags; | 
|  | 62 | struct nla_policy	*policy; | 
|  | 63 | int		       (*doit)(struct sk_buff *skb, | 
|  | 64 | struct genl_info *info); | 
|  | 65 | int		       (*dumpit)(struct sk_buff *skb, | 
|  | 66 | struct netlink_callback *cb); | 
|  | 67 | struct list_head	ops_list; | 
|  | 68 | }; | 
|  | 69 |  | 
|  | 70 | extern int genl_register_family(struct genl_family *family); | 
|  | 71 | extern int genl_unregister_family(struct genl_family *family); | 
|  | 72 | extern int genl_register_ops(struct genl_family *, struct genl_ops *ops); | 
|  | 73 | extern int genl_unregister_ops(struct genl_family *, struct genl_ops *ops); | 
|  | 74 |  | 
|  | 75 | extern struct sock *genl_sock; | 
|  | 76 |  | 
|  | 77 | /** | 
|  | 78 | * genlmsg_put - Add generic netlink header to netlink message | 
|  | 79 | * @skb: socket buffer holding the message | 
|  | 80 | * @pid: netlink pid the message is addressed to | 
|  | 81 | * @seq: sequence number (usually the one of the sender) | 
|  | 82 | * @type: netlink message type | 
|  | 83 | * @hdrlen: length of the user specific header | 
|  | 84 | * @flags netlink message flags | 
|  | 85 | * @cmd: generic netlink command | 
|  | 86 | * @version: version | 
|  | 87 | * | 
|  | 88 | * Returns pointer to user specific header | 
|  | 89 | */ | 
|  | 90 | static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, | 
|  | 91 | int type, int hdrlen, int flags, | 
|  | 92 | u8 cmd, u8 version) | 
|  | 93 | { | 
|  | 94 | struct nlmsghdr *nlh; | 
|  | 95 | struct genlmsghdr *hdr; | 
|  | 96 |  | 
|  | 97 | nlh = nlmsg_put(skb, pid, seq, type, GENL_HDRLEN + hdrlen, flags); | 
|  | 98 | if (nlh == NULL) | 
|  | 99 | return NULL; | 
|  | 100 |  | 
|  | 101 | hdr = nlmsg_data(nlh); | 
|  | 102 | hdr->cmd = cmd; | 
|  | 103 | hdr->version = version; | 
|  | 104 | hdr->reserved = 0; | 
|  | 105 |  | 
|  | 106 | return (char *) hdr + GENL_HDRLEN; | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | /** | 
|  | 110 | * genlmsg_end - Finalize a generic netlink message | 
|  | 111 | * @skb: socket buffer the message is stored in | 
|  | 112 | * @hdr: user specific header | 
|  | 113 | */ | 
|  | 114 | static inline int genlmsg_end(struct sk_buff *skb, void *hdr) | 
|  | 115 | { | 
|  | 116 | return nlmsg_end(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | /** | 
|  | 120 | * genlmsg_cancel - Cancel construction of a generic netlink message | 
|  | 121 | * @skb: socket buffer the message is stored in | 
|  | 122 | * @hdr: generic netlink message header | 
|  | 123 | */ | 
|  | 124 | static inline int genlmsg_cancel(struct sk_buff *skb, void *hdr) | 
|  | 125 | { | 
|  | 126 | return nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN); | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | /** | 
|  | 130 | * genlmsg_multicast - multicast a netlink message | 
|  | 131 | * @skb: netlink message as socket buffer | 
|  | 132 | * @pid: own netlink pid to avoid sending to yourself | 
|  | 133 | * @group: multicast group id | 
| Thomas Graf | d387f6a | 2006-08-15 00:31:06 -0700 | [diff] [blame] | 134 | * @flags: allocation flags | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 135 | */ | 
|  | 136 | static inline int genlmsg_multicast(struct sk_buff *skb, u32 pid, | 
| Thomas Graf | d387f6a | 2006-08-15 00:31:06 -0700 | [diff] [blame] | 137 | unsigned int group, gfp_t flags) | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 138 | { | 
| Thomas Graf | d387f6a | 2006-08-15 00:31:06 -0700 | [diff] [blame] | 139 | return nlmsg_multicast(genl_sock, skb, pid, group, flags); | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 140 | } | 
|  | 141 |  | 
|  | 142 | /** | 
|  | 143 | * genlmsg_unicast - unicast a netlink message | 
|  | 144 | * @skb: netlink message as socket buffer | 
|  | 145 | * @pid: netlink pid of the destination socket | 
|  | 146 | */ | 
|  | 147 | static inline int genlmsg_unicast(struct sk_buff *skb, u32 pid) | 
|  | 148 | { | 
|  | 149 | return nlmsg_unicast(genl_sock, skb, pid); | 
|  | 150 | } | 
|  | 151 |  | 
| Balbir Singh | fb0ba6bd | 2006-07-14 00:24:39 -0700 | [diff] [blame] | 152 | /** | 
|  | 153 | * gennlmsg_data - head of message payload | 
|  | 154 | * @gnlh: genetlink messsage header | 
|  | 155 | */ | 
|  | 156 | static inline void *genlmsg_data(const struct genlmsghdr *gnlh) | 
|  | 157 | { | 
|  | 158 | return ((unsigned char *) gnlh + GENL_HDRLEN); | 
|  | 159 | } | 
|  | 160 |  | 
|  | 161 | /** | 
|  | 162 | * genlmsg_len - length of message payload | 
|  | 163 | * @gnlh: genetlink message header | 
|  | 164 | */ | 
|  | 165 | static inline int genlmsg_len(const struct genlmsghdr *gnlh) | 
|  | 166 | { | 
|  | 167 | struct nlmsghdr *nlh = (struct nlmsghdr *)((unsigned char *)gnlh - | 
|  | 168 | NLMSG_HDRLEN); | 
|  | 169 | return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN); | 
|  | 170 | } | 
|  | 171 |  | 
| Thomas Graf | 482a852 | 2005-11-10 02:25:56 +0100 | [diff] [blame] | 172 | #endif	/* __NET_GENERIC_NETLINK_H */ |