1482a8524SThomas Graf #ifndef __NET_GENERIC_NETLINK_H 2482a8524SThomas Graf #define __NET_GENERIC_NETLINK_H 3482a8524SThomas Graf 4482a8524SThomas Graf #include <linux/genetlink.h> 5482a8524SThomas Graf #include <net/netlink.h> 6482a8524SThomas Graf 7482a8524SThomas Graf /** 8482a8524SThomas Graf * struct genl_family - generic netlink family 9482a8524SThomas Graf * @id: protocol family idenfitier 10482a8524SThomas Graf * @hdrsize: length of user specific header in bytes 11482a8524SThomas Graf * @name: name of family 12482a8524SThomas Graf * @version: protocol version 13482a8524SThomas Graf * @maxattr: maximum number of attributes supported 14482a8524SThomas Graf * @attrbuf: buffer to store parsed attributes 15482a8524SThomas Graf * @ops_list: list of all assigned operations 16482a8524SThomas Graf * @family_list: family list 17482a8524SThomas Graf */ 18482a8524SThomas Graf struct genl_family 19482a8524SThomas Graf { 20482a8524SThomas Graf unsigned int id; 21482a8524SThomas Graf unsigned int hdrsize; 22482a8524SThomas Graf char name[GENL_NAMSIZ]; 23482a8524SThomas Graf unsigned int version; 24482a8524SThomas Graf unsigned int maxattr; 25482a8524SThomas Graf struct module * owner; 26482a8524SThomas Graf struct nlattr ** attrbuf; /* private */ 27482a8524SThomas Graf struct list_head ops_list; /* private */ 28482a8524SThomas Graf struct list_head family_list; /* private */ 29482a8524SThomas Graf }; 30482a8524SThomas Graf 31482a8524SThomas Graf #define GENL_ADMIN_PERM 0x01 32482a8524SThomas Graf 33482a8524SThomas Graf /** 34482a8524SThomas Graf * struct genl_info - receiving information 35482a8524SThomas Graf * @snd_seq: sending sequence number 36482a8524SThomas Graf * @snd_pid: netlink pid of sender 37482a8524SThomas Graf * @nlhdr: netlink message header 38482a8524SThomas Graf * @genlhdr: generic netlink message header 39482a8524SThomas Graf * @userhdr: user specific header 40482a8524SThomas Graf * @attrs: netlink attributes 41482a8524SThomas Graf */ 42482a8524SThomas Graf struct genl_info 43482a8524SThomas Graf { 44482a8524SThomas Graf u32 snd_seq; 45482a8524SThomas Graf u32 snd_pid; 46482a8524SThomas Graf struct nlmsghdr * nlhdr; 47482a8524SThomas Graf struct genlmsghdr * genlhdr; 48482a8524SThomas Graf void * userhdr; 49482a8524SThomas Graf struct nlattr ** attrs; 50482a8524SThomas Graf }; 51482a8524SThomas Graf 52482a8524SThomas Graf /** 53482a8524SThomas Graf * struct genl_ops - generic netlink operations 54482a8524SThomas Graf * @cmd: command identifier 55482a8524SThomas Graf * @flags: flags 56482a8524SThomas Graf * @policy: attribute validation policy 57482a8524SThomas Graf * @doit: standard command callback 58482a8524SThomas Graf * @dumpit: callback for dumpers 59482a8524SThomas Graf * @ops_list: operations list 60482a8524SThomas Graf */ 61482a8524SThomas Graf struct genl_ops 62482a8524SThomas Graf { 63*b461d2f2SPer Liden u8 cmd; 64482a8524SThomas Graf unsigned int flags; 65482a8524SThomas Graf struct nla_policy *policy; 66482a8524SThomas Graf int (*doit)(struct sk_buff *skb, 67482a8524SThomas Graf struct genl_info *info); 68482a8524SThomas Graf int (*dumpit)(struct sk_buff *skb, 69482a8524SThomas Graf struct netlink_callback *cb); 70482a8524SThomas Graf struct list_head ops_list; 71482a8524SThomas Graf }; 72482a8524SThomas Graf 73482a8524SThomas Graf extern int genl_register_family(struct genl_family *family); 74482a8524SThomas Graf extern int genl_unregister_family(struct genl_family *family); 75482a8524SThomas Graf extern int genl_register_ops(struct genl_family *, struct genl_ops *ops); 76482a8524SThomas Graf extern int genl_unregister_ops(struct genl_family *, struct genl_ops *ops); 77482a8524SThomas Graf 78482a8524SThomas Graf extern struct sock *genl_sock; 79482a8524SThomas Graf 80482a8524SThomas Graf /** 81482a8524SThomas Graf * genlmsg_put - Add generic netlink header to netlink message 82482a8524SThomas Graf * @skb: socket buffer holding the message 83482a8524SThomas Graf * @pid: netlink pid the message is addressed to 84482a8524SThomas Graf * @seq: sequence number (usually the one of the sender) 85482a8524SThomas Graf * @type: netlink message type 86482a8524SThomas Graf * @hdrlen: length of the user specific header 87482a8524SThomas Graf * @flags netlink message flags 88482a8524SThomas Graf * @cmd: generic netlink command 89482a8524SThomas Graf * @version: version 90482a8524SThomas Graf * 91482a8524SThomas Graf * Returns pointer to user specific header 92482a8524SThomas Graf */ 93482a8524SThomas Graf static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, 94482a8524SThomas Graf int type, int hdrlen, int flags, 95482a8524SThomas Graf u8 cmd, u8 version) 96482a8524SThomas Graf { 97482a8524SThomas Graf struct nlmsghdr *nlh; 98482a8524SThomas Graf struct genlmsghdr *hdr; 99482a8524SThomas Graf 100482a8524SThomas Graf nlh = nlmsg_put(skb, pid, seq, type, GENL_HDRLEN + hdrlen, flags); 101482a8524SThomas Graf if (nlh == NULL) 102482a8524SThomas Graf return NULL; 103482a8524SThomas Graf 104482a8524SThomas Graf hdr = nlmsg_data(nlh); 105482a8524SThomas Graf hdr->cmd = cmd; 106482a8524SThomas Graf hdr->version = version; 107482a8524SThomas Graf hdr->reserved = 0; 108482a8524SThomas Graf 109482a8524SThomas Graf return (char *) hdr + GENL_HDRLEN; 110482a8524SThomas Graf } 111482a8524SThomas Graf 112482a8524SThomas Graf /** 113482a8524SThomas Graf * genlmsg_end - Finalize a generic netlink message 114482a8524SThomas Graf * @skb: socket buffer the message is stored in 115482a8524SThomas Graf * @hdr: user specific header 116482a8524SThomas Graf */ 117482a8524SThomas Graf static inline int genlmsg_end(struct sk_buff *skb, void *hdr) 118482a8524SThomas Graf { 119482a8524SThomas Graf return nlmsg_end(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN); 120482a8524SThomas Graf } 121482a8524SThomas Graf 122482a8524SThomas Graf /** 123482a8524SThomas Graf * genlmsg_cancel - Cancel construction of a generic netlink message 124482a8524SThomas Graf * @skb: socket buffer the message is stored in 125482a8524SThomas Graf * @hdr: generic netlink message header 126482a8524SThomas Graf */ 127482a8524SThomas Graf static inline int genlmsg_cancel(struct sk_buff *skb, void *hdr) 128482a8524SThomas Graf { 129482a8524SThomas Graf return nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN); 130482a8524SThomas Graf } 131482a8524SThomas Graf 132482a8524SThomas Graf /** 133482a8524SThomas Graf * genlmsg_multicast - multicast a netlink message 134482a8524SThomas Graf * @skb: netlink message as socket buffer 135482a8524SThomas Graf * @pid: own netlink pid to avoid sending to yourself 136482a8524SThomas Graf * @group: multicast group id 137482a8524SThomas Graf */ 138482a8524SThomas Graf static inline int genlmsg_multicast(struct sk_buff *skb, u32 pid, 139482a8524SThomas Graf unsigned int group) 140482a8524SThomas Graf { 141482a8524SThomas Graf return nlmsg_multicast(genl_sock, skb, pid, group); 142482a8524SThomas Graf } 143482a8524SThomas Graf 144482a8524SThomas Graf /** 145482a8524SThomas Graf * genlmsg_unicast - unicast a netlink message 146482a8524SThomas Graf * @skb: netlink message as socket buffer 147482a8524SThomas Graf * @pid: netlink pid of the destination socket 148482a8524SThomas Graf */ 149482a8524SThomas Graf static inline int genlmsg_unicast(struct sk_buff *skb, u32 pid) 150482a8524SThomas Graf { 151482a8524SThomas Graf return nlmsg_unicast(genl_sock, skb, pid); 152482a8524SThomas Graf } 153482a8524SThomas Graf 154482a8524SThomas Graf #endif /* __NET_GENERIC_NETLINK_H */ 155