^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NetLabel Domain Hash Table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file manages the domain hash table that NetLabel uses to determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * which network labeling protocol to use for a given domain. The NetLabel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * system manages static and dynamic label mappings for network protocols such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * as CIPSO and RIPSO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Author: Paul Moore <paul@paul-moore.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #ifndef _NETLABEL_DOMAINHASH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define _NETLABEL_DOMAINHASH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "netlabel_addrlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* Domain hash table size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* XXX - currently this number is an uneducated guess */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define NETLBL_DOMHSH_BITSIZE 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Domain mapping definition structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct netlbl_domaddr_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct list_head list4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct list_head list6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct netlbl_dommap_def {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct netlbl_domaddr_map *addrsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct cipso_v4_doi *cipso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct calipso_doi *calipso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define netlbl_domhsh_addr4_entry(iter) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) container_of(iter, struct netlbl_domaddr4_map, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct netlbl_domaddr4_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct netlbl_dommap_def def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct netlbl_af4list list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define netlbl_domhsh_addr6_entry(iter) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) container_of(iter, struct netlbl_domaddr6_map, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct netlbl_domaddr6_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct netlbl_dommap_def def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct netlbl_af6list list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct netlbl_dom_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) char *domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u16 family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct netlbl_dommap_def def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u32 valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* init function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int netlbl_domhsh_init(u32 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Manipulate the domain hash table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int netlbl_domhsh_add(struct netlbl_dom_map *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int netlbl_domhsh_remove_af4(const char *domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) const struct in_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const struct in_addr *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int netlbl_domhsh_remove_af6(const char *domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) const struct in6_addr *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int netlbl_domhsh_remove(const char *domain, u16 family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) __be32 addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) const struct in6_addr *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int netlbl_domhsh_remove_af6(const char *domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) const struct in6_addr *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct netlbl_audit *audit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif /* IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int netlbl_domhsh_walk(u32 *skip_bkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u32 *skip_chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int (*callback) (struct netlbl_dom_map *entry, void *arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void *cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #endif