Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Moore | 82c21bf | 2011-08-01 11:10:33 +0000 | [diff] [blame] | 9 | * Author: Paul Moore <paul@paul-moore.com> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 10 | * |
| 11 | */ |
| 12 | |
| 13 | /* |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 14 | * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008 |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 15 | * |
| 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 Kirsher | d484ff1 | 2013-12-06 09:13:41 -0800 | [diff] [blame] | 27 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 28 | * |
| 29 | */ |
| 30 | |
| 31 | #ifndef _NETLABEL_DOMAINHASH_H |
| 32 | #define _NETLABEL_DOMAINHASH_H |
| 33 | |
Paul Moore | 7a0e1d6 | 2006-08-29 17:56:04 -0700 | [diff] [blame] | 34 | #include <linux/types.h> |
| 35 | #include <linux/rcupdate.h> |
| 36 | #include <linux/list.h> |
| 37 | |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 38 | #include "netlabel_addrlist.h" |
| 39 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 40 | /* Domain hash table size */ |
| 41 | /* XXX - currently this number is an uneducated guess */ |
| 42 | #define NETLBL_DOMHSH_BITSIZE 7 |
| 43 | |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 44 | /* Domain mapping definition structures */ |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 45 | struct netlbl_domaddr_map { |
| 46 | struct list_head list4; |
| 47 | struct list_head list6; |
| 48 | }; |
| 49 | struct netlbl_dommap_def { |
| 50 | u32 type; |
| 51 | union { |
| 52 | struct netlbl_domaddr_map *addrsel; |
| 53 | struct cipso_v4_doi *cipso; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 54 | struct calipso_doi *calipso; |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 55 | }; |
| 56 | }; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 57 | #define netlbl_domhsh_addr4_entry(iter) \ |
| 58 | container_of(iter, struct netlbl_domaddr4_map, list) |
| 59 | struct netlbl_domaddr4_map { |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 60 | struct netlbl_dommap_def def; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 61 | |
| 62 | struct netlbl_af4list list; |
| 63 | }; |
| 64 | #define netlbl_domhsh_addr6_entry(iter) \ |
| 65 | container_of(iter, struct netlbl_domaddr6_map, list) |
| 66 | struct netlbl_domaddr6_map { |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 67 | struct netlbl_dommap_def def; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 68 | |
| 69 | struct netlbl_af6list list; |
| 70 | }; |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 71 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 72 | struct netlbl_dom_map { |
| 73 | char *domain; |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 74 | u16 family; |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 75 | struct netlbl_dommap_def def; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 76 | |
| 77 | u32 valid; |
| 78 | struct list_head list; |
| 79 | struct rcu_head rcu; |
| 80 | }; |
| 81 | |
| 82 | /* init function */ |
| 83 | int netlbl_domhsh_init(u32 size); |
| 84 | |
| 85 | /* Manipulate the domain hash table */ |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 86 | int netlbl_domhsh_add(struct netlbl_dom_map *entry, |
| 87 | struct netlbl_audit *audit_info); |
| 88 | int netlbl_domhsh_add_default(struct netlbl_dom_map *entry, |
| 89 | struct netlbl_audit *audit_info); |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 90 | int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry, |
| 91 | struct netlbl_audit *audit_info); |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 92 | int netlbl_domhsh_remove_af4(const char *domain, |
| 93 | const struct in_addr *addr, |
| 94 | const struct in_addr *mask, |
| 95 | struct netlbl_audit *audit_info); |
Huw Davies | 3f09354 | 2016-06-27 15:06:18 -0400 | [diff] [blame] | 96 | int netlbl_domhsh_remove_af6(const char *domain, |
| 97 | const struct in6_addr *addr, |
| 98 | const struct in6_addr *mask, |
| 99 | struct netlbl_audit *audit_info); |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 100 | int netlbl_domhsh_remove(const char *domain, u16 family, |
| 101 | struct netlbl_audit *audit_info); |
| 102 | int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info); |
| 103 | struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 104 | struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain, |
| 105 | __be32 addr); |
| 106 | #if IS_ENABLED(CONFIG_IPV6) |
| 107 | struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain, |
| 108 | const struct in6_addr *addr); |
Huw Davies | 3f09354 | 2016-06-27 15:06:18 -0400 | [diff] [blame] | 109 | int netlbl_domhsh_remove_af6(const char *domain, |
| 110 | const struct in6_addr *addr, |
| 111 | const struct in6_addr *mask, |
| 112 | struct netlbl_audit *audit_info); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 113 | #endif /* IPv6 */ |
| 114 | |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 115 | int netlbl_domhsh_walk(u32 *skip_bkt, |
| 116 | u32 *skip_chain, |
| 117 | int (*callback) (struct netlbl_dom_map *entry, void *arg), |
| 118 | void *cb_arg); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 119 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 120 | #endif |