]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - net/ipv6/ila/ila.h
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-kernels.git] / net / ipv6 / ila / ila.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (c) 2015 Tom Herbert <tom@herbertland.com>
4 */
5
6 #ifndef __ILA_H
7 #define __ILA_H
8
9 #include <linux/errno.h>
10 #include <linux/ip.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/socket.h>
14 #include <linux/skbuff.h>
15 #include <linux/types.h>
16 #include <net/checksum.h>
17 #include <net/genetlink.h>
18 #include <net/ip.h>
19 #include <net/protocol.h>
20 #include <uapi/linux/ila.h>
21
22 struct ila_locator {
23 union {
24 __u8 v8[8];
25 __be16 v16[4];
26 __be32 v32[2];
27 __be64 v64;
28 };
29 };
30
31 struct ila_identifier {
32 union {
33 struct {
34 #if defined(__LITTLE_ENDIAN_BITFIELD)
35 u8 __space:4;
36 u8 csum_neutral:1;
37 u8 type:3;
38 #elif defined(__BIG_ENDIAN_BITFIELD)
39 u8 type:3;
40 u8 csum_neutral:1;
41 u8 __space:4;
42 #else
43 #error "Adjust your <asm/byteorder.h> defines"
44 #endif
45 u8 __space2[7];
46 };
47 __u8 v8[8];
48 __be16 v16[4];
49 __be32 v32[2];
50 __be64 v64;
51 };
52 };
53
54 #define CSUM_NEUTRAL_FLAG htonl(0x10000000)
55
56 struct ila_addr {
57 union {
58 struct in6_addr addr;
59 struct {
60 struct ila_locator loc;
61 struct ila_identifier ident;
62 };
63 };
64 };
65
66 static inline struct ila_addr *ila_a2i(struct in6_addr *addr)
67 {
68 return (struct ila_addr *)addr;
69 }
70
71 static inline bool ila_addr_is_ila(struct ila_addr *iaddr)
72 {
73 return (iaddr->ident.type != ILA_ATYPE_IID);
74 }
75
76 struct ila_params {
77 struct ila_locator locator;
78 struct ila_locator locator_match;
79 __wsum csum_diff;
80 u8 csum_mode;
81 u8 ident_type;
82 };
83
84 static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to)
85 {
86 __be32 diff[] = {
87 ~from[0], ~from[1], to[0], to[1],
88 };
89
90 return csum_partial(diff, sizeof(diff), 0);
91 }
92
93 static inline bool ila_csum_neutral_set(struct ila_identifier ident)
94 {
95 return !!(ident.csum_neutral);
96 }
97
98 void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,
99 bool set_csum_neutral);
100
101 void ila_init_saved_csum(struct ila_params *p);
102
103 struct ila_net {
104 struct {
105 struct rhashtable rhash_table;
106 spinlock_t *locks; /* Bucket locks for entry manipulation */
107 unsigned int locks_mask;
108 bool hooks_registered;
109 } xlat;
110 };
111
112 int ila_lwt_init(void);
113 void ila_lwt_fini(void);
114
115 int ila_xlat_init_net(struct net *net);
116 void ila_xlat_exit_net(struct net *net);
117
118 int ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info);
119 int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info);
120 int ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info);
121 int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info);
122 int ila_xlat_nl_dump_start(struct netlink_callback *cb);
123 int ila_xlat_nl_dump_done(struct netlink_callback *cb);
124 int ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb);
125
126 extern unsigned int ila_net_id;
127
128 extern struct genl_family ila_nl_family;
129
130 #endif /* __ILA_H */