Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 1 | /* |
| 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 | * |
| 9 | */ |
| 10 | |
| 11 | #ifndef __ILA_H |
| 12 | #define __ILA_H |
| 13 | |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/ip.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/socket.h> |
| 19 | #include <linux/skbuff.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <net/checksum.h> |
| 22 | #include <net/ip.h> |
| 23 | #include <net/protocol.h> |
| 24 | #include <uapi/linux/ila.h> |
| 25 | |
Tom Herbert | 351596a | 2016-04-23 11:46:55 -0700 | [diff] [blame] | 26 | struct ila_locator { |
| 27 | union { |
| 28 | __u8 v8[8]; |
| 29 | __be16 v16[4]; |
| 30 | __be32 v32[2]; |
| 31 | __be64 v64; |
| 32 | }; |
| 33 | }; |
| 34 | |
| 35 | struct ila_identifier { |
| 36 | union { |
| 37 | struct { |
| 38 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
Tom Herbert | 90bfe66 | 2016-04-23 11:46:57 -0700 | [diff] [blame] | 39 | u8 __space:4; |
| 40 | u8 csum_neutral:1; |
Tom Herbert | 351596a | 2016-04-23 11:46:55 -0700 | [diff] [blame] | 41 | u8 type:3; |
| 42 | #elif defined(__BIG_ENDIAN_BITFIELD) |
| 43 | u8 type:3; |
Tom Herbert | 90bfe66 | 2016-04-23 11:46:57 -0700 | [diff] [blame] | 44 | u8 csum_neutral:1; |
| 45 | u8 __space:4; |
Tom Herbert | 351596a | 2016-04-23 11:46:55 -0700 | [diff] [blame] | 46 | #else |
| 47 | #error "Adjust your <asm/byteorder.h> defines" |
| 48 | #endif |
| 49 | u8 __space2[7]; |
| 50 | }; |
| 51 | __u8 v8[8]; |
| 52 | __be16 v16[4]; |
| 53 | __be32 v32[2]; |
| 54 | __be64 v64; |
| 55 | }; |
| 56 | }; |
| 57 | |
| 58 | enum { |
| 59 | ILA_ATYPE_IID = 0, |
| 60 | ILA_ATYPE_LUID, |
| 61 | ILA_ATYPE_VIRT_V4, |
| 62 | ILA_ATYPE_VIRT_UNI_V6, |
| 63 | ILA_ATYPE_VIRT_MULTI_V6, |
| 64 | ILA_ATYPE_RSVD_1, |
| 65 | ILA_ATYPE_RSVD_2, |
| 66 | ILA_ATYPE_RSVD_3, |
| 67 | }; |
| 68 | |
Tom Herbert | 90bfe66 | 2016-04-23 11:46:57 -0700 | [diff] [blame] | 69 | #define CSUM_NEUTRAL_FLAG htonl(0x10000000) |
| 70 | |
Tom Herbert | 351596a | 2016-04-23 11:46:55 -0700 | [diff] [blame] | 71 | struct ila_addr { |
| 72 | union { |
| 73 | struct in6_addr addr; |
| 74 | struct { |
| 75 | struct ila_locator loc; |
| 76 | struct ila_identifier ident; |
| 77 | }; |
| 78 | }; |
| 79 | }; |
| 80 | |
| 81 | static inline struct ila_addr *ila_a2i(struct in6_addr *addr) |
| 82 | { |
| 83 | return (struct ila_addr *)addr; |
| 84 | } |
| 85 | |
| 86 | static inline bool ila_addr_is_ila(struct ila_addr *iaddr) |
| 87 | { |
| 88 | return (iaddr->ident.type != ILA_ATYPE_IID); |
| 89 | } |
| 90 | |
Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 91 | struct ila_params { |
Tom Herbert | 351596a | 2016-04-23 11:46:55 -0700 | [diff] [blame] | 92 | struct ila_locator locator; |
| 93 | struct ila_locator locator_match; |
Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 94 | __wsum csum_diff; |
Tom Herbert | 90bfe66 | 2016-04-23 11:46:57 -0700 | [diff] [blame] | 95 | u8 csum_mode; |
Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to) |
| 99 | { |
| 100 | __be32 diff[] = { |
| 101 | ~from[0], ~from[1], to[0], to[1], |
| 102 | }; |
| 103 | |
| 104 | return csum_partial(diff, sizeof(diff), 0); |
| 105 | } |
| 106 | |
Tom Herbert | 90bfe66 | 2016-04-23 11:46:57 -0700 | [diff] [blame] | 107 | static inline bool ila_csum_neutral_set(struct ila_identifier ident) |
| 108 | { |
| 109 | return !!(ident.csum_neutral); |
| 110 | } |
| 111 | |
Tom Herbert | 351596a | 2016-04-23 11:46:55 -0700 | [diff] [blame] | 112 | void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p); |
Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 113 | |
Tom Herbert | 90bfe66 | 2016-04-23 11:46:57 -0700 | [diff] [blame] | 114 | void ila_init_saved_csum(struct ila_params *p); |
| 115 | |
Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 116 | int ila_lwt_init(void); |
| 117 | void ila_lwt_fini(void); |
Tom Herbert | 7f00fea | 2015-12-15 15:41:38 -0800 | [diff] [blame] | 118 | int ila_xlat_init(void); |
| 119 | void ila_xlat_fini(void); |
Tom Herbert | 33f11d1 | 2015-12-15 15:41:35 -0800 | [diff] [blame] | 120 | |
| 121 | #endif /* __ILA_H */ |