blob: 9f80972ae39bafe7ff0ba8374e3ce8991f216549 [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Paul Moored15c3452006-08-03 16:48:37 -07002/*
3 * NetLabel Domain Hash Table
4 *
5 * This file manages the domain hash table that NetLabel uses to determine
6 * which network labeling protocol to use for a given domain. The NetLabel
7 * system manages static and dynamic label mappings for network protocols such
8 * as CIPSO and RIPSO.
9 *
Paul Moore82c21bf2011-08-01 11:10:33 +000010 * Author: Paul Moore <paul@paul-moore.com>
Paul Moored15c3452006-08-03 16:48:37 -070011 */
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
17#ifndef _NETLABEL_DOMAINHASH_H
18#define _NETLABEL_DOMAINHASH_H
19
Paul Moore7a0e1d62006-08-29 17:56:04 -070020#include <linux/types.h>
21#include <linux/rcupdate.h>
22#include <linux/list.h>
23
Paul Moore63c41682008-10-10 10:16:32 -040024#include "netlabel_addrlist.h"
25
Paul Moored15c3452006-08-03 16:48:37 -070026/* Domain hash table size */
27/* XXX - currently this number is an uneducated guess */
28#define NETLBL_DOMHSH_BITSIZE 7
29
Paul Moore63c41682008-10-10 10:16:32 -040030/* Domain mapping definition structures */
Paul Moore6a8b7f02013-08-02 14:45:08 -040031struct netlbl_domaddr_map {
32 struct list_head list4;
33 struct list_head list6;
34};
35struct netlbl_dommap_def {
36 u32 type;
37 union {
38 struct netlbl_domaddr_map *addrsel;
39 struct cipso_v4_doi *cipso;
Huw Daviesdc7de732016-06-27 15:02:49 -040040 struct calipso_doi *calipso;
Paul Moore6a8b7f02013-08-02 14:45:08 -040041 };
42};
Paul Moore63c41682008-10-10 10:16:32 -040043#define netlbl_domhsh_addr4_entry(iter) \
44 container_of(iter, struct netlbl_domaddr4_map, list)
45struct netlbl_domaddr4_map {
Paul Moore6a8b7f02013-08-02 14:45:08 -040046 struct netlbl_dommap_def def;
Paul Moore63c41682008-10-10 10:16:32 -040047
48 struct netlbl_af4list list;
49};
50#define netlbl_domhsh_addr6_entry(iter) \
51 container_of(iter, struct netlbl_domaddr6_map, list)
52struct netlbl_domaddr6_map {
Paul Moore6a8b7f02013-08-02 14:45:08 -040053 struct netlbl_dommap_def def;
Paul Moore63c41682008-10-10 10:16:32 -040054
55 struct netlbl_af6list list;
56};
Paul Moore6a8b7f02013-08-02 14:45:08 -040057
Paul Moored15c3452006-08-03 16:48:37 -070058struct netlbl_dom_map {
59 char *domain;
Huw Davies8f18e672016-06-27 15:02:46 -040060 u16 family;
Paul Moore6a8b7f02013-08-02 14:45:08 -040061 struct netlbl_dommap_def def;
Paul Moored15c3452006-08-03 16:48:37 -070062
63 u32 valid;
64 struct list_head list;
65 struct rcu_head rcu;
66};
67
68/* init function */
69int netlbl_domhsh_init(u32 size);
70
71/* Manipulate the domain hash table */
Paul Moore95d4e6b2006-09-29 17:05:05 -070072int netlbl_domhsh_add(struct netlbl_dom_map *entry,
73 struct netlbl_audit *audit_info);
74int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
75 struct netlbl_audit *audit_info);
Paul Mooreb1edeb12008-10-10 10:16:31 -040076int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
77 struct netlbl_audit *audit_info);
Paul Moore6c2e8ac2008-12-31 12:54:11 -050078int netlbl_domhsh_remove_af4(const char *domain,
79 const struct in_addr *addr,
80 const struct in_addr *mask,
81 struct netlbl_audit *audit_info);
Huw Davies3f093542016-06-27 15:06:18 -040082int netlbl_domhsh_remove_af6(const char *domain,
83 const struct in6_addr *addr,
84 const struct in6_addr *mask,
85 struct netlbl_audit *audit_info);
Huw Davies8f18e672016-06-27 15:02:46 -040086int netlbl_domhsh_remove(const char *domain, u16 family,
87 struct netlbl_audit *audit_info);
88int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info);
89struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family);
Paul Moore6a8b7f02013-08-02 14:45:08 -040090struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain,
91 __be32 addr);
92#if IS_ENABLED(CONFIG_IPV6)
93struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain,
94 const struct in6_addr *addr);
Huw Davies3f093542016-06-27 15:06:18 -040095int netlbl_domhsh_remove_af6(const char *domain,
96 const struct in6_addr *addr,
97 const struct in6_addr *mask,
98 struct netlbl_audit *audit_info);
Paul Moore6a8b7f02013-08-02 14:45:08 -040099#endif /* IPv6 */
100
Paul Moorefcd48282006-09-25 15:56:09 -0700101int netlbl_domhsh_walk(u32 *skip_bkt,
102 u32 *skip_chain,
103 int (*callback) (struct netlbl_dom_map *entry, void *arg),
104 void *cb_arg);
Paul Moored15c3452006-08-03 16:48:37 -0700105
Paul Moored15c3452006-08-03 16:48:37 -0700106#endif