2 * NetLabel Network Address Lists
4 * This file contains network address list functions used to manage ordered
5 * lists of network addresses for use by the NetLabel subsystem. The NetLabel
6 * system manages static and dynamic label mappings for network protocols such
9 * Author: Paul Moore <paul.moore@hp.com>
14 * (c) Copyright Hewlett-Packard Development Company, L.P., 2008
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
24 * the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef _NETLABEL_ADDRLIST_H
33 #define _NETLABEL_ADDRLIST_H
35 #include <linux/types.h>
36 #include <linux/rcupdate.h>
37 #include <linux/list.h>
38 #include <linux/in6.h>
39 #include <linux/audit.h>
42 * struct netlbl_af4list - NetLabel IPv4 address list
44 * @mask: IPv4 address mask
46 * @list: list structure, used internally
48 struct netlbl_af4list
{
53 struct list_head list
;
57 * struct netlbl_af6list - NetLabel IPv6 address list
59 * @mask: IPv6 address mask
61 * @list: list structure, used internally
63 struct netlbl_af6list
{
68 struct list_head list
;
71 #define __af4list_entry(ptr) container_of(ptr, struct netlbl_af4list, list)
73 static inline struct netlbl_af4list
*__af4list_valid(struct list_head
*s
,
76 struct list_head
*i
= s
;
77 struct netlbl_af4list
*n
= __af4list_entry(s
);
78 while (i
!= h
&& !n
->valid
) {
80 n
= __af4list_entry(i
);
85 static inline struct netlbl_af4list
*__af4list_valid_rcu(struct list_head
*s
,
88 struct list_head
*i
= s
;
89 struct netlbl_af4list
*n
= __af4list_entry(s
);
90 while (i
!= h
&& !n
->valid
) {
91 i
= rcu_dereference(i
->next
);
92 n
= __af4list_entry(i
);
97 #define netlbl_af4list_foreach(iter, head) \
98 for (iter = __af4list_valid((head)->next, head); \
99 prefetch(iter->list.next), &iter->list != (head); \
100 iter = __af4list_valid(iter->list.next, head))
102 #define netlbl_af4list_foreach_rcu(iter, head) \
103 for (iter = __af4list_valid_rcu((head)->next, head); \
104 prefetch(iter->list.next), &iter->list != (head); \
105 iter = __af4list_valid_rcu(iter->list.next, head))
107 #define netlbl_af4list_foreach_safe(iter, tmp, head) \
108 for (iter = __af4list_valid((head)->next, head), \
109 tmp = __af4list_valid(iter->list.next, head); \
110 &iter->list != (head); \
111 iter = tmp, tmp = __af4list_valid(iter->list.next, head))
113 int netlbl_af4list_add(struct netlbl_af4list
*entry
,
114 struct list_head
*head
);
115 struct netlbl_af4list
*netlbl_af4list_remove(__be32 addr
, __be32 mask
,
116 struct list_head
*head
);
117 void netlbl_af4list_remove_entry(struct netlbl_af4list
*entry
);
118 struct netlbl_af4list
*netlbl_af4list_search(__be32 addr
,
119 struct list_head
*head
);
120 struct netlbl_af4list
*netlbl_af4list_search_exact(__be32 addr
,
122 struct list_head
*head
);
125 void netlbl_af4list_audit_addr(struct audit_buffer
*audit_buf
,
126 int src
, const char *dev
,
127 __be32 addr
, __be32 mask
);
129 static inline void netlbl_af4list_audit_addr(struct audit_buffer
*audit_buf
,
130 int src
, const char *dev
,
131 __be32 addr
, __be32 mask
)
136 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
138 #define __af6list_entry(ptr) container_of(ptr, struct netlbl_af6list, list)
140 static inline struct netlbl_af6list
*__af6list_valid(struct list_head
*s
,
143 struct list_head
*i
= s
;
144 struct netlbl_af6list
*n
= __af6list_entry(s
);
145 while (i
!= h
&& !n
->valid
) {
147 n
= __af6list_entry(i
);
152 static inline struct netlbl_af6list
*__af6list_valid_rcu(struct list_head
*s
,
155 struct list_head
*i
= s
;
156 struct netlbl_af6list
*n
= __af6list_entry(s
);
157 while (i
!= h
&& !n
->valid
) {
158 i
= rcu_dereference(i
->next
);
159 n
= __af6list_entry(i
);
164 #define netlbl_af6list_foreach(iter, head) \
165 for (iter = __af6list_valid((head)->next, head); \
166 prefetch(iter->list.next), &iter->list != (head); \
167 iter = __af6list_valid(iter->list.next, head))
169 #define netlbl_af6list_foreach_rcu(iter, head) \
170 for (iter = __af6list_valid_rcu((head)->next, head); \
171 prefetch(iter->list.next), &iter->list != (head); \
172 iter = __af6list_valid_rcu(iter->list.next, head))
174 #define netlbl_af6list_foreach_safe(iter, tmp, head) \
175 for (iter = __af6list_valid((head)->next, head), \
176 tmp = __af6list_valid(iter->list.next, head); \
177 &iter->list != (head); \
178 iter = tmp, tmp = __af6list_valid(iter->list.next, head))
180 int netlbl_af6list_add(struct netlbl_af6list
*entry
,
181 struct list_head
*head
);
182 struct netlbl_af6list
*netlbl_af6list_remove(const struct in6_addr
*addr
,
183 const struct in6_addr
*mask
,
184 struct list_head
*head
);
185 void netlbl_af6list_remove_entry(struct netlbl_af6list
*entry
);
186 struct netlbl_af6list
*netlbl_af6list_search(const struct in6_addr
*addr
,
187 struct list_head
*head
);
188 struct netlbl_af6list
*netlbl_af6list_search_exact(const struct in6_addr
*addr
,
189 const struct in6_addr
*mask
,
190 struct list_head
*head
);
193 void netlbl_af6list_audit_addr(struct audit_buffer
*audit_buf
,
196 const struct in6_addr
*addr
,
197 const struct in6_addr
*mask
);
199 static inline void netlbl_af6list_audit_addr(struct audit_buffer
*audit_buf
,
202 const struct in6_addr
*addr
,
203 const struct in6_addr
*mask
)