Path: blob/master/net/netlabel/netlabel_addrlist.h
15109 views
/*1* NetLabel Network Address Lists2*3* This file contains network address list functions used to manage ordered4* lists of network addresses for use by the NetLabel subsystem. The NetLabel5* system manages static and dynamic label mappings for network protocols such6* as CIPSO and RIPSO.7*8* Author: Paul Moore <[email protected]>9*10*/1112/*13* (c) Copyright Hewlett-Packard Development Company, L.P., 200814*15* This program is free software; you can redistribute it and/or modify16* it under the terms of the GNU General Public License as published by17* the Free Software Foundation; either version 2 of the License, or18* (at your option) any later version.19*20* This program is distributed in the hope that it will be useful,21* but WITHOUT ANY WARRANTY; without even the implied warranty of22* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See23* the GNU General Public License for more details.24*25* You should have received a copy of the GNU General Public License26* along with this program; if not, write to the Free Software27* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA28*29*/3031#ifndef _NETLABEL_ADDRLIST_H32#define _NETLABEL_ADDRLIST_H3334#include <linux/types.h>35#include <linux/rcupdate.h>36#include <linux/list.h>37#include <linux/in6.h>38#include <linux/audit.h>3940/**41* struct netlbl_af4list - NetLabel IPv4 address list42* @addr: IPv4 address43* @mask: IPv4 address mask44* @valid: valid flag45* @list: list structure, used internally46*/47struct netlbl_af4list {48__be32 addr;49__be32 mask;5051u32 valid;52struct list_head list;53};5455/**56* struct netlbl_af6list - NetLabel IPv6 address list57* @addr: IPv6 address58* @mask: IPv6 address mask59* @valid: valid flag60* @list: list structure, used internally61*/62struct netlbl_af6list {63struct in6_addr addr;64struct in6_addr mask;6566u32 valid;67struct list_head list;68};6970#define __af4list_entry(ptr) container_of(ptr, struct netlbl_af4list, list)7172static inline struct netlbl_af4list *__af4list_valid(struct list_head *s,73struct list_head *h)74{75struct list_head *i = s;76struct netlbl_af4list *n = __af4list_entry(s);77while (i != h && !n->valid) {78i = i->next;79n = __af4list_entry(i);80}81return n;82}8384static inline struct netlbl_af4list *__af4list_valid_rcu(struct list_head *s,85struct list_head *h)86{87struct list_head *i = s;88struct netlbl_af4list *n = __af4list_entry(s);89while (i != h && !n->valid) {90i = rcu_dereference(i->next);91n = __af4list_entry(i);92}93return n;94}9596#define netlbl_af4list_foreach(iter, head) \97for (iter = __af4list_valid((head)->next, head); \98&iter->list != (head); \99iter = __af4list_valid(iter->list.next, head))100101#define netlbl_af4list_foreach_rcu(iter, head) \102for (iter = __af4list_valid_rcu((head)->next, head); \103&iter->list != (head); \104iter = __af4list_valid_rcu(iter->list.next, head))105106#define netlbl_af4list_foreach_safe(iter, tmp, head) \107for (iter = __af4list_valid((head)->next, head), \108tmp = __af4list_valid(iter->list.next, head); \109&iter->list != (head); \110iter = tmp, tmp = __af4list_valid(iter->list.next, head))111112int netlbl_af4list_add(struct netlbl_af4list *entry,113struct list_head *head);114struct netlbl_af4list *netlbl_af4list_remove(__be32 addr, __be32 mask,115struct list_head *head);116void netlbl_af4list_remove_entry(struct netlbl_af4list *entry);117struct netlbl_af4list *netlbl_af4list_search(__be32 addr,118struct list_head *head);119struct netlbl_af4list *netlbl_af4list_search_exact(__be32 addr,120__be32 mask,121struct list_head *head);122123#ifdef CONFIG_AUDIT124void netlbl_af4list_audit_addr(struct audit_buffer *audit_buf,125int src, const char *dev,126__be32 addr, __be32 mask);127#else128static inline void netlbl_af4list_audit_addr(struct audit_buffer *audit_buf,129int src, const char *dev,130__be32 addr, __be32 mask)131{132}133#endif134135#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)136137#define __af6list_entry(ptr) container_of(ptr, struct netlbl_af6list, list)138139static inline struct netlbl_af6list *__af6list_valid(struct list_head *s,140struct list_head *h)141{142struct list_head *i = s;143struct netlbl_af6list *n = __af6list_entry(s);144while (i != h && !n->valid) {145i = i->next;146n = __af6list_entry(i);147}148return n;149}150151static inline struct netlbl_af6list *__af6list_valid_rcu(struct list_head *s,152struct list_head *h)153{154struct list_head *i = s;155struct netlbl_af6list *n = __af6list_entry(s);156while (i != h && !n->valid) {157i = rcu_dereference(i->next);158n = __af6list_entry(i);159}160return n;161}162163#define netlbl_af6list_foreach(iter, head) \164for (iter = __af6list_valid((head)->next, head); \165&iter->list != (head); \166iter = __af6list_valid(iter->list.next, head))167168#define netlbl_af6list_foreach_rcu(iter, head) \169for (iter = __af6list_valid_rcu((head)->next, head); \170&iter->list != (head); \171iter = __af6list_valid_rcu(iter->list.next, head))172173#define netlbl_af6list_foreach_safe(iter, tmp, head) \174for (iter = __af6list_valid((head)->next, head), \175tmp = __af6list_valid(iter->list.next, head); \176&iter->list != (head); \177iter = tmp, tmp = __af6list_valid(iter->list.next, head))178179int netlbl_af6list_add(struct netlbl_af6list *entry,180struct list_head *head);181struct netlbl_af6list *netlbl_af6list_remove(const struct in6_addr *addr,182const struct in6_addr *mask,183struct list_head *head);184void netlbl_af6list_remove_entry(struct netlbl_af6list *entry);185struct netlbl_af6list *netlbl_af6list_search(const struct in6_addr *addr,186struct list_head *head);187struct netlbl_af6list *netlbl_af6list_search_exact(const struct in6_addr *addr,188const struct in6_addr *mask,189struct list_head *head);190191#ifdef CONFIG_AUDIT192void netlbl_af6list_audit_addr(struct audit_buffer *audit_buf,193int src,194const char *dev,195const struct in6_addr *addr,196const struct in6_addr *mask);197#else198static inline void netlbl_af6list_audit_addr(struct audit_buffer *audit_buf,199int src,200const char *dev,201const struct in6_addr *addr,202const struct in6_addr *mask)203{204}205#endif206#endif /* IPV6 */207208#endif209210211