1 /* SPDX-License-Identifier: GPL-2.0-or-later * << 2 /* 1 /* 3 * Copyright (c) 2015 Tom Herbert <tom@herbert 2 * Copyright (c) 2015 Tom Herbert <tom@herbertland.com> >> 3 * >> 4 * This program is free software; you can redistribute it and/or >> 5 * modify it under the terms of the GNU General Public License as >> 6 * published by the Free Software Foundation; either version 2 of >> 7 * the License, or (at your option) any later version. >> 8 * 4 */ 9 */ 5 10 6 #ifndef __ILA_H 11 #ifndef __ILA_H 7 #define __ILA_H 12 #define __ILA_H 8 13 9 #include <linux/errno.h> 14 #include <linux/errno.h> 10 #include <linux/ip.h> 15 #include <linux/ip.h> 11 #include <linux/kernel.h> 16 #include <linux/kernel.h> 12 #include <linux/module.h> 17 #include <linux/module.h> 13 #include <linux/socket.h> 18 #include <linux/socket.h> 14 #include <linux/skbuff.h> 19 #include <linux/skbuff.h> 15 #include <linux/types.h> 20 #include <linux/types.h> 16 #include <net/checksum.h> 21 #include <net/checksum.h> 17 #include <net/genetlink.h> 22 #include <net/genetlink.h> 18 #include <net/ip.h> 23 #include <net/ip.h> 19 #include <net/protocol.h> 24 #include <net/protocol.h> 20 #include <uapi/linux/ila.h> 25 #include <uapi/linux/ila.h> 21 26 22 struct ila_locator { 27 struct ila_locator { 23 union { 28 union { 24 __u8 v8[8]; 29 __u8 v8[8]; 25 __be16 v16[4]; 30 __be16 v16[4]; 26 __be32 v32[2]; 31 __be32 v32[2]; 27 __be64 v64; 32 __be64 v64; 28 }; 33 }; 29 }; 34 }; 30 35 31 struct ila_identifier { 36 struct ila_identifier { 32 union { 37 union { 33 struct { 38 struct { 34 #if defined(__LITTLE_ENDIAN_BITFIELD) 39 #if defined(__LITTLE_ENDIAN_BITFIELD) 35 u8 __space:4; 40 u8 __space:4; 36 u8 csum_neutral:1; 41 u8 csum_neutral:1; 37 u8 type:3; 42 u8 type:3; 38 #elif defined(__BIG_ENDIAN_BITFIELD) 43 #elif defined(__BIG_ENDIAN_BITFIELD) 39 u8 type:3; 44 u8 type:3; 40 u8 csum_neutral:1; 45 u8 csum_neutral:1; 41 u8 __space:4; 46 u8 __space:4; 42 #else 47 #else 43 #error "Adjust your <asm/byteorder.h> defines 48 #error "Adjust your <asm/byteorder.h> defines" 44 #endif 49 #endif 45 u8 __space2[7]; 50 u8 __space2[7]; 46 }; 51 }; 47 __u8 v8[8]; 52 __u8 v8[8]; 48 __be16 v16[4]; 53 __be16 v16[4]; 49 __be32 v32[2]; 54 __be32 v32[2]; 50 __be64 v64; 55 __be64 v64; 51 }; 56 }; 52 }; 57 }; 53 58 54 #define CSUM_NEUTRAL_FLAG htonl(0x100000 59 #define CSUM_NEUTRAL_FLAG htonl(0x10000000) 55 60 56 struct ila_addr { 61 struct ila_addr { 57 union { 62 union { 58 struct in6_addr addr; 63 struct in6_addr addr; 59 struct { 64 struct { 60 struct ila_locator loc 65 struct ila_locator loc; 61 struct ila_identifier 66 struct ila_identifier ident; 62 }; 67 }; 63 }; 68 }; 64 }; 69 }; 65 70 66 static inline struct ila_addr *ila_a2i(struct 71 static inline struct ila_addr *ila_a2i(struct in6_addr *addr) 67 { 72 { 68 return (struct ila_addr *)addr; 73 return (struct ila_addr *)addr; 69 } 74 } 70 75 >> 76 static inline bool ila_addr_is_ila(struct ila_addr *iaddr) >> 77 { >> 78 return (iaddr->ident.type != ILA_ATYPE_IID); >> 79 } >> 80 71 struct ila_params { 81 struct ila_params { 72 struct ila_locator locator; 82 struct ila_locator locator; 73 struct ila_locator locator_match; 83 struct ila_locator locator_match; 74 __wsum csum_diff; 84 __wsum csum_diff; 75 u8 csum_mode; 85 u8 csum_mode; 76 u8 ident_type; 86 u8 ident_type; 77 }; 87 }; 78 88 79 static inline __wsum compute_csum_diff8(const 89 static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to) 80 { 90 { 81 __be32 diff[] = { 91 __be32 diff[] = { 82 ~from[0], ~from[1], to[0], to[ 92 ~from[0], ~from[1], to[0], to[1], 83 }; 93 }; 84 94 85 return csum_partial(diff, sizeof(diff) 95 return csum_partial(diff, sizeof(diff), 0); 86 } 96 } 87 97 88 static inline bool ila_csum_neutral_set(struct 98 static inline bool ila_csum_neutral_set(struct ila_identifier ident) 89 { 99 { 90 return !!(ident.csum_neutral); 100 return !!(ident.csum_neutral); 91 } 101 } 92 102 93 void ila_update_ipv6_locator(struct sk_buff *s 103 void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p, 94 bool set_csum_neu 104 bool set_csum_neutral); 95 105 96 void ila_init_saved_csum(struct ila_params *p) 106 void ila_init_saved_csum(struct ila_params *p); 97 107 98 struct ila_net { 108 struct ila_net { 99 struct { 109 struct { 100 struct rhashtable rhash_table; 110 struct rhashtable rhash_table; 101 spinlock_t *locks; /* Bucket l 111 spinlock_t *locks; /* Bucket locks for entry manipulation */ 102 unsigned int locks_mask; 112 unsigned int locks_mask; 103 bool hooks_registered; 113 bool hooks_registered; 104 } xlat; 114 } xlat; 105 }; 115 }; 106 116 107 int ila_lwt_init(void); 117 int ila_lwt_init(void); 108 void ila_lwt_fini(void); 118 void ila_lwt_fini(void); 109 119 110 int ila_xlat_init_net(struct net *net); 120 int ila_xlat_init_net(struct net *net); 111 void ila_xlat_pre_exit_net(struct net *net); << 112 void ila_xlat_exit_net(struct net *net); 121 void ila_xlat_exit_net(struct net *net); 113 122 114 int ila_xlat_nl_cmd_add_mapping(struct sk_buff 123 int ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info); 115 int ila_xlat_nl_cmd_del_mapping(struct sk_buff 124 int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info); 116 int ila_xlat_nl_cmd_get_mapping(struct sk_buff 125 int ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info); 117 int ila_xlat_nl_cmd_flush(struct sk_buff *skb, 126 int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info); 118 int ila_xlat_nl_dump_start(struct netlink_call 127 int ila_xlat_nl_dump_start(struct netlink_callback *cb); 119 int ila_xlat_nl_dump_done(struct netlink_callb 128 int ila_xlat_nl_dump_done(struct netlink_callback *cb); 120 int ila_xlat_nl_dump(struct sk_buff *skb, stru 129 int ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb); 121 130 122 extern unsigned int ila_net_id; 131 extern unsigned int ila_net_id; 123 132 124 extern struct genl_family ila_nl_family; 133 extern struct genl_family ila_nl_family; 125 134 126 #endif /* __ILA_H */ 135 #endif /* __ILA_H */ 127 136
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.