blob: 56e45ae7b996cf6dc52903b6f8e4da521335ef91 [file] [log] [blame]
Paul Moored15c3452006-08-03 16:48:37 -07001/*
2 * NetLabel Domain Hash Table
3 *
4 * This file manages the domain hash table that NetLabel uses to determine
5 * which network labeling protocol to use for a given domain. The NetLabel
6 * system manages static and dynamic label mappings for network protocols such
7 * as CIPSO and RIPSO.
8 *
Paul Moore82c21bf2011-08-01 11:10:33 +00009 * Author: Paul Moore <paul@paul-moore.com>
Paul Moored15c3452006-08-03 16:48:37 -070010 *
11 */
12
13/*
Paul Moore63c41682008-10-10 10:16:32 -040014 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
Paul Moored15c3452006-08-03 16:48:37 -070015 *
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.
20 *
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.
25 *
26 * You should have received a copy of the GNU General Public License
Jeff Kirsherd484ff12013-12-06 09:13:41 -080027 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Paul Moored15c3452006-08-03 16:48:37 -070028 *
29 */
30
31#ifndef _NETLABEL_DOMAINHASH_H
32#define _NETLABEL_DOMAINHASH_H
33
Paul Moore7a0e1d62006-08-29 17:56:04 -070034#include <linux/types.h>
35#include <linux/rcupdate.h>
36#include <linux/list.h>
37
Paul Moore63c41682008-10-10 10:16:32 -040038#include "netlabel_addrlist.h"
39
Paul Moored15c3452006-08-03 16:48:37 -070040/* Domain hash table size */
41/* XXX - currently this number is an uneducated guess */
42#define NETLBL_DOMHSH_BITSIZE 7
43
Paul Moore63c41682008-10-10 10:16:32 -040044/* Domain mapping definition structures */
Paul Moore6a8b7f02013-08-02 14:45:08 -040045struct netlbl_domaddr_map {
46 struct list_head list4;
47 struct list_head list6;
48};
49struct netlbl_dommap_def {
50 u32 type;
51 union {
52 struct netlbl_domaddr_map *addrsel;
53 struct cipso_v4_doi *cipso;
54 };
55};
Paul Moore63c41682008-10-10 10:16:32 -040056#define netlbl_domhsh_addr4_entry(iter) \
57 container_of(iter, struct netlbl_domaddr4_map, list)
58struct netlbl_domaddr4_map {
Paul Moore6a8b7f02013-08-02 14:45:08 -040059 struct netlbl_dommap_def def;
Paul Moore63c41682008-10-10 10:16:32 -040060
61 struct netlbl_af4list list;
62};
63#define netlbl_domhsh_addr6_entry(iter) \
64 container_of(iter, struct netlbl_domaddr6_map, list)
65struct netlbl_domaddr6_map {
Paul Moore6a8b7f02013-08-02 14:45:08 -040066 struct netlbl_dommap_def def;
Paul Moore63c41682008-10-10 10:16:32 -040067
68 struct netlbl_af6list list;
69};
Paul Moore6a8b7f02013-08-02 14:45:08 -040070
Paul Moored15c3452006-08-03 16:48:37 -070071struct netlbl_dom_map {
72 char *domain;
Huw Davies8f18e672016-06-27 15:02:46 -040073 u16 family;
Paul Moore6a8b7f02013-08-02 14:45:08 -040074 struct netlbl_dommap_def def;
Paul Moored15c3452006-08-03 16:48:37 -070075
76 u32 valid;
77 struct list_head list;
78 struct rcu_head rcu;
79};
80
81/* init function */
82int netlbl_domhsh_init(u32 size);
83
84/* Manipulate the domain hash table */
Paul Moore95d4e6b2006-09-29 17:05:05 -070085int netlbl_domhsh_add(struct netlbl_dom_map *entry,
86 struct netlbl_audit *audit_info);
87int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
88 struct netlbl_audit *audit_info);
Paul Mooreb1edeb12008-10-10 10:16:31 -040089int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
90 struct netlbl_audit *audit_info);
Paul Moore6c2e8ac2008-12-31 12:54:11 -050091int netlbl_domhsh_remove_af4(const char *domain,
92 const struct in_addr *addr,
93 const struct in_addr *mask,
94 struct netlbl_audit *audit_info);
Huw Davies8f18e672016-06-27 15:02:46 -040095int netlbl_domhsh_remove(const char *domain, u16 family,
96 struct netlbl_audit *audit_info);
97int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info);
98struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family);
Paul Moore6a8b7f02013-08-02 14:45:08 -040099struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain,
100 __be32 addr);
101#if IS_ENABLED(CONFIG_IPV6)
102struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain,
103 const struct in6_addr *addr);
104#endif /* IPv6 */
105
Paul Moorefcd48282006-09-25 15:56:09 -0700106int netlbl_domhsh_walk(u32 *skip_bkt,
107 u32 *skip_chain,
108 int (*callback) (struct netlbl_dom_map *entry, void *arg),
109 void *cb_arg);
Paul Moored15c3452006-08-03 16:48:37 -0700110
Paul Moored15c3452006-08-03 16:48:37 -0700111#endif