2 * NetLabel NETLINK Interface
4 * This file defines the NETLINK interface for the NetLabel system. The
5 * NetLabel system manages static and dynamic label mappings for network
6 * protocols such as CIPSO and RIPSO.
8 * Author: Paul Moore <paul.moore@hp.com>
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
23 * the GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef _NETLABEL_USER_H
32 #define _NETLABEL_USER_H
34 #include <linux/types.h>
35 #include <linux/skbuff.h>
36 #include <linux/capability.h>
37 #include <net/netlink.h>
38 #include <net/genetlink.h>
39 #include <net/netlabel.h>
41 /* NetLabel NETLINK helper functions */
44 * netlbl_netlink_cap_check - Check the NETLINK msg capabilities
45 * @skb: the NETLINK buffer
46 * @req_cap: the required capability
49 * Check the NETLINK buffer's capabilities against the required capabilities.
50 * Returns zero on success, negative values on failure.
53 static inline int netlbl_netlink_cap_check(const struct sk_buff *skb,
56 if (cap_raised(NETLINK_CB(skb).eff_cap, req_cap))
62 * netlbl_getinc_u8 - Read a u8 value from a nlattr stream and move on
64 * @rem_len: remaining length
67 * Return a u8 value pointed to by @nla and advance it to the next attribute.
70 static inline u8 netlbl_getinc_u8(struct nlattr **nla, int *rem_len)
72 u8 val = nla_get_u8(*nla);
73 *nla = nla_next(*nla, rem_len);
78 * netlbl_getinc_u16 - Read a u16 value from a nlattr stream and move on
80 * @rem_len: remaining length
83 * Return a u16 value pointed to by @nla and advance it to the next attribute.
86 static inline u16 netlbl_getinc_u16(struct nlattr **nla, int *rem_len)
88 u16 val = nla_get_u16(*nla);
89 *nla = nla_next(*nla, rem_len);
94 * netlbl_getinc_u32 - Read a u32 value from a nlattr stream and move on
96 * @rem_len: remaining length
99 * Return a u32 value pointed to by @nla and advance it to the next attribute.
102 static inline u32 netlbl_getinc_u32(struct nlattr **nla, int *rem_len)
104 u32 val = nla_get_u32(*nla);
105 *nla = nla_next(*nla, rem_len);
110 * netlbl_netlink_hdr_put - Write the NETLINK buffers into a sk_buff
112 * @pid: the PID of the receipient
113 * @seq: the sequence number
114 * @type: the generic NETLINK message family type
118 * Write both a NETLINK nlmsghdr structure and a Generic NETLINK genlmsghdr
119 * struct to the packet. Returns a pointer to the start of the payload buffer
120 * on success or NULL on failure.
123 static inline void *netlbl_netlink_hdr_put(struct sk_buff *skb,
129 return genlmsg_put(skb,
136 NETLBL_PROTO_VERSION);
140 * netlbl_netlink_hdr_push - Write the NETLINK buffers into a sk_buff
142 * @pid: the PID of the receipient
143 * @seq: the sequence number
144 * @type: the generic NETLINK message family type
148 * Write both a NETLINK nlmsghdr structure and a Generic NETLINK genlmsghdr
149 * struct to the packet.
152 static inline void netlbl_netlink_hdr_push(struct sk_buff *skb,
159 struct nlmsghdr *nlh;
160 struct genlmsghdr *hdr;
162 nlh = (struct nlmsghdr *)skb_push(skb, NLMSG_SPACE(GENL_HDRLEN));
163 nlh->nlmsg_type = type;
164 nlh->nlmsg_len = skb->len;
165 nlh->nlmsg_flags = 0;
166 nlh->nlmsg_pid = pid;
167 nlh->nlmsg_seq = seq;
169 hdr = nlmsg_data(nlh);
171 hdr->version = NETLBL_PROTO_VERSION;
176 * netlbl_netlink_payload_len - Return the length of the payload
177 * @skb: the NETLINK buffer
180 * This function returns the length of the NetLabel payload.
183 static inline u32 netlbl_netlink_payload_len(const struct sk_buff *skb)
185 return nlmsg_len((struct nlmsghdr *)skb->data) - GENL_HDRLEN;
189 * netlbl_netlink_payload_data - Returns a pointer to the start of the payload
190 * @skb: the NETLINK buffer
193 * This function returns a pointer to the start of the NetLabel payload.
196 static inline void *netlbl_netlink_payload_data(const struct sk_buff *skb)
198 return (unsigned char *)nlmsg_data((struct nlmsghdr *)skb->data) +
202 /* NetLabel common protocol functions */
204 void netlbl_netlink_send_ack(const struct genl_info *info,
209 /* NetLabel NETLINK I/O functions */
211 int netlbl_netlink_init(void);
212 int netlbl_netlink_snd(struct sk_buff *skb, u32 pid);
213 int netlbl_netlink_snd_multicast(struct sk_buff *skb, u32 pid, u32 group);