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@paul-moore.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, see <http://www.gnu.org/licenses/>.
31 #ifndef _NETLABEL_ADDRLIST_H
32 #define _NETLABEL_ADDRLIST_H
34 #include <linux/types.h>
35 #include <linux/rcupdate.h>
36 #include <linux/list.h>
37 #include <linux/in6.h>
38 #include <linux/audit.h>
41 * struct netlbl_af4list - NetLabel IPv4 address list
43 * @mask: IPv4 address mask
45 * @list: list structure, used internally
47 struct netlbl_af4list
{
52 struct list_head list
;
56 * struct netlbl_af6list - NetLabel IPv6 address list
58 * @mask: IPv6 address mask
60 * @list: list structure, used internally
62 struct netlbl_af6list
{
67 struct list_head list
;
70 #define __af4list_entry(ptr) container_of(ptr, struct netlbl_af4list, list)
72 static inline struct netlbl_af4list
*__af4list_valid(struct list_head
*s
,
75 struct list_head
*i
= s
;
76 struct netlbl_af4list
*n
= __af4list_entry(s
);
77 while (i
!= h
&& !n
->valid
) {
79 n
= __af4list_entry(i
);
84 static inline struct netlbl_af4list
*__af4list_valid_rcu(struct list_head
*s
,
87 struct list_head
*i
= s
;
88 struct netlbl_af4list
*n
= __af4list_entry(s
);
89 while (i
!= h
&& !n
->valid
) {
90 i
= rcu_dereference(list_next_rcu(i
));
91 n
= __af4list_entry(i
);
96 #define netlbl_af4list_foreach(iter, head) \
97 for (iter = __af4list_valid((head)->next, head); \
98 &iter->list != (head); \
99 iter = __af4list_valid(iter->list.next, head))
101 #define netlbl_af4list_foreach_rcu(iter, head) \
102 for (iter = __af4list_valid_rcu((head)->next, head); \
103 &iter->list != (head); \
104 iter = __af4list_valid_rcu(iter->list.next, head))
106 #define netlbl_af4list_foreach_safe(iter, tmp, head) \
107 for (iter = __af4list_valid((head)->next, head), \
108 tmp = __af4list_valid(iter->list.next, head); \
109 &iter->list != (head); \
110 iter = tmp, tmp = __af4list_valid(iter->list.next, head))
112 int netlbl_af4list_add(struct netlbl_af4list
*entry
,
113 struct list_head
*head
);
114 struct netlbl_af4list
*netlbl_af4list_remove(__be32 addr
, __be32 mask
,
115 struct list_head
*head
);
116 void netlbl_af4list_remove_entry(struct netlbl_af4list
*entry
);
117 struct netlbl_af4list
*netlbl_af4list_search(__be32 addr
,
118 struct list_head
*head
);
119 struct netlbl_af4list
*netlbl_af4list_search_exact(__be32 addr
,
121 struct list_head
*head
);
124 void netlbl_af4list_audit_addr(struct audit_buffer
*audit_buf
,
125 int src
, const char *dev
,
126 __be32 addr
, __be32 mask
);
128 static inline void netlbl_af4list_audit_addr(struct audit_buffer
*audit_buf
,
129 int src
, const char *dev
,
130 __be32 addr
, __be32 mask
)
135 #if IS_ENABLED(CONFIG_IPV6)
137 #define __af6list_entry(ptr) container_of(ptr, struct netlbl_af6list, list)
139 static inline struct netlbl_af6list
*__af6list_valid(struct list_head
*s
,
142 struct list_head
*i
= s
;
143 struct netlbl_af6list
*n
= __af6list_entry(s
);
144 while (i
!= h
&& !n
->valid
) {
146 n
= __af6list_entry(i
);
151 static inline struct netlbl_af6list
*__af6list_valid_rcu(struct list_head
*s
,
154 struct list_head
*i
= s
;
155 struct netlbl_af6list
*n
= __af6list_entry(s
);
156 while (i
!= h
&& !n
->valid
) {
157 i
= rcu_dereference(list_next_rcu(i
));
158 n
= __af6list_entry(i
);
163 #define netlbl_af6list_foreach(iter, head) \
164 for (iter = __af6list_valid((head)->next, head); \
165 &iter->list != (head); \
166 iter = __af6list_valid(iter->list.next, head))
168 #define netlbl_af6list_foreach_rcu(iter, head) \
169 for (iter = __af6list_valid_rcu((head)->next, head); \
170 &iter->list != (head); \
171 iter = __af6list_valid_rcu(iter->list.next, head))
173 #define netlbl_af6list_foreach_safe(iter, tmp, head) \
174 for (iter = __af6list_valid((head)->next, head), \
175 tmp = __af6list_valid(iter->list.next, head); \
176 &iter->list != (head); \
177 iter = tmp, tmp = __af6list_valid(iter->list.next, head))
179 int netlbl_af6list_add(struct netlbl_af6list
*entry
,
180 struct list_head
*head
);
181 struct netlbl_af6list
*netlbl_af6list_remove(const struct in6_addr
*addr
,
182 const struct in6_addr
*mask
,
183 struct list_head
*head
);
184 void netlbl_af6list_remove_entry(struct netlbl_af6list
*entry
);
185 struct netlbl_af6list
*netlbl_af6list_search(const struct in6_addr
*addr
,
186 struct list_head
*head
);
187 struct netlbl_af6list
*netlbl_af6list_search_exact(const struct in6_addr
*addr
,
188 const struct in6_addr
*mask
,
189 struct list_head
*head
);
192 void netlbl_af6list_audit_addr(struct audit_buffer
*audit_buf
,
195 const struct in6_addr
*addr
,
196 const struct in6_addr
*mask
);
198 static inline void netlbl_af6list_audit_addr(struct audit_buffer
*audit_buf
,
201 const struct in6_addr
*addr
,
202 const struct in6_addr
*mask
)