xref: /kernel/linux/linux-5.10/net/ipv6/ila/ila.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2015 Tom Herbert <tom@herbertland.com>
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __ILA_H
78c2ecf20Sopenharmony_ci#define __ILA_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/errno.h>
108c2ecf20Sopenharmony_ci#include <linux/ip.h>
118c2ecf20Sopenharmony_ci#include <linux/kernel.h>
128c2ecf20Sopenharmony_ci#include <linux/module.h>
138c2ecf20Sopenharmony_ci#include <linux/socket.h>
148c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
158c2ecf20Sopenharmony_ci#include <linux/types.h>
168c2ecf20Sopenharmony_ci#include <net/checksum.h>
178c2ecf20Sopenharmony_ci#include <net/genetlink.h>
188c2ecf20Sopenharmony_ci#include <net/ip.h>
198c2ecf20Sopenharmony_ci#include <net/protocol.h>
208c2ecf20Sopenharmony_ci#include <uapi/linux/ila.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistruct ila_locator {
238c2ecf20Sopenharmony_ci	union {
248c2ecf20Sopenharmony_ci		__u8            v8[8];
258c2ecf20Sopenharmony_ci		__be16          v16[4];
268c2ecf20Sopenharmony_ci		__be32          v32[2];
278c2ecf20Sopenharmony_ci		__be64		v64;
288c2ecf20Sopenharmony_ci	};
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct ila_identifier {
328c2ecf20Sopenharmony_ci	union {
338c2ecf20Sopenharmony_ci		struct {
348c2ecf20Sopenharmony_ci#if defined(__LITTLE_ENDIAN_BITFIELD)
358c2ecf20Sopenharmony_ci			u8 __space:4;
368c2ecf20Sopenharmony_ci			u8 csum_neutral:1;
378c2ecf20Sopenharmony_ci			u8 type:3;
388c2ecf20Sopenharmony_ci#elif defined(__BIG_ENDIAN_BITFIELD)
398c2ecf20Sopenharmony_ci			u8 type:3;
408c2ecf20Sopenharmony_ci			u8 csum_neutral:1;
418c2ecf20Sopenharmony_ci			u8 __space:4;
428c2ecf20Sopenharmony_ci#else
438c2ecf20Sopenharmony_ci#error  "Adjust your <asm/byteorder.h> defines"
448c2ecf20Sopenharmony_ci#endif
458c2ecf20Sopenharmony_ci			u8 __space2[7];
468c2ecf20Sopenharmony_ci		};
478c2ecf20Sopenharmony_ci		__u8            v8[8];
488c2ecf20Sopenharmony_ci		__be16          v16[4];
498c2ecf20Sopenharmony_ci		__be32          v32[2];
508c2ecf20Sopenharmony_ci		__be64		v64;
518c2ecf20Sopenharmony_ci	};
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define CSUM_NEUTRAL_FLAG	htonl(0x10000000)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct ila_addr {
578c2ecf20Sopenharmony_ci	union {
588c2ecf20Sopenharmony_ci		struct in6_addr addr;
598c2ecf20Sopenharmony_ci		struct {
608c2ecf20Sopenharmony_ci			struct ila_locator loc;
618c2ecf20Sopenharmony_ci			struct ila_identifier ident;
628c2ecf20Sopenharmony_ci		};
638c2ecf20Sopenharmony_ci	};
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic inline struct ila_addr *ila_a2i(struct in6_addr *addr)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	return (struct ila_addr *)addr;
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistruct ila_params {
728c2ecf20Sopenharmony_ci	struct ila_locator locator;
738c2ecf20Sopenharmony_ci	struct ila_locator locator_match;
748c2ecf20Sopenharmony_ci	__wsum csum_diff;
758c2ecf20Sopenharmony_ci	u8 csum_mode;
768c2ecf20Sopenharmony_ci	u8 ident_type;
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	__be32 diff[] = {
828c2ecf20Sopenharmony_ci		~from[0], ~from[1], to[0], to[1],
838c2ecf20Sopenharmony_ci	};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	return csum_partial(diff, sizeof(diff), 0);
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic inline bool ila_csum_neutral_set(struct ila_identifier ident)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	return !!(ident.csum_neutral);
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_civoid ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,
948c2ecf20Sopenharmony_ci			     bool set_csum_neutral);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_civoid ila_init_saved_csum(struct ila_params *p);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistruct ila_net {
998c2ecf20Sopenharmony_ci	struct {
1008c2ecf20Sopenharmony_ci		struct rhashtable rhash_table;
1018c2ecf20Sopenharmony_ci		spinlock_t *locks; /* Bucket locks for entry manipulation */
1028c2ecf20Sopenharmony_ci		unsigned int locks_mask;
1038c2ecf20Sopenharmony_ci		bool hooks_registered;
1048c2ecf20Sopenharmony_ci	} xlat;
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint ila_lwt_init(void);
1088c2ecf20Sopenharmony_civoid ila_lwt_fini(void);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciint ila_xlat_init_net(struct net *net);
1118c2ecf20Sopenharmony_civoid ila_xlat_exit_net(struct net *net);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciint ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info);
1148c2ecf20Sopenharmony_ciint ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info);
1158c2ecf20Sopenharmony_ciint ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info);
1168c2ecf20Sopenharmony_ciint ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info);
1178c2ecf20Sopenharmony_ciint ila_xlat_nl_dump_start(struct netlink_callback *cb);
1188c2ecf20Sopenharmony_ciint ila_xlat_nl_dump_done(struct netlink_callback *cb);
1198c2ecf20Sopenharmony_ciint ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ciextern unsigned int ila_net_id;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciextern struct genl_family ila_nl_family;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#endif /* __ILA_H */
126