// SPDX-License-Identifier: GPL-2.0-or-later/* * CALIPSO - Common Architecture Label IPv6 Security Option * * This is an implementation of the CALIPSO protocol as specified in * RFC 5570. * * Authors: Paul Moore <paul.moore@hp.com> * Huw Davies <huw@codeweavers.com> *//* (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008 * (c) Copyright Huw Davies <huw@codeweavers.com>, 2015 */#include<linux/init.h>#include<linux/types.h>#include<linux/rcupdate.h>#include<linux/list.h>#include<linux/spinlock.h>#include<linux/string.h>#include<linux/jhash.h>#include<linux/audit.h>#include<linux/slab.h>#include<net/ip.h>#include<net/icmp.h>#include<net/tcp.h>#include<net/netlabel.h>#include<net/calipso.h>#include<linux/atomic.h>#include<linux/bug.h>#include<asm/unaligned.h>#include<linux/crc-ccitt.h>/* Maximium size of the calipso option including * the two-byte TLV header. */#define CALIPSO_OPT_LEN_MAX (2 + 252)/* Size of the minimum calipso option including * the two-byte TLV header. */#define CALIPSO_HDR_LEN (2 + 8)/* Maximium size of the calipso option including * the two-byte TLV header and upto 3 bytes of * leading pad and 7 bytes of trailing pad. */#define CALIPSO_OPT_LEN_MAX_WITH_PAD (3 + CALIPSO_OPT_LEN_MAX + 7)/* Maximium size of u32 aligned buffer required to hold calipso * option. Max of 3 initial pad bytes starting from buffer + 3. * i.e. the worst case is when the previous tlv finishes on 4n + 3. */#define CALIPSO_MAX_BUFFER (6 + CALIPSO_OPT_LEN_MAX)/* List of available DOI definitions */staticDEFINE_SPINLOCK(calipso_doi_list_lock);staticLIST_HEAD(calipso_doi_list);/* Label mapping cache */intcalipso_cache_enabled=1;intcalipso_cache_bucketsize=10;#define CALIPSO_CACHE_BUCKETBITS 7#define CALIPSO_CACHE_BUCKETS BIT(CALIPSO_CACHE_BUCKETBITS)#define CALIPSO_CACHE_REORDERLIMIT 10structcalipso_map_cache_bkt{spinlock_tlock;u32size;structlist_headlist;};structcalipso_map_cache_entry{u32hash;unsignedchar*key;size_tkey_len;structnetlbl_lsm_cache*lsm_data;u32activity