Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sfe_cm.h |
| 3 | * Shortcut forwarding engine. |
| 4 | * |
Xiaoping Fan | a42c68b | 2015-08-07 18:00:39 -0700 | [diff] [blame] | 5 | * Copyright (c) 2013-2015 The Linux Foundation. All rights reserved. |
| 6 | * Permission to use, copy, modify, and/or distribute this software for |
| 7 | * any purpose with or without fee is hereby granted, provided that the |
| 8 | * above copyright notice and this permission notice appear in all copies. |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 15 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * connection flags. |
| 20 | */ |
| 21 | #define SFE_CREATE_FLAG_NO_SEQ_CHECK 0x1 |
| 22 | /* Indicates that we should not check sequence numbers */ |
| 23 | |
| 24 | /* |
| 25 | * IPv6 address structure |
| 26 | */ |
| 27 | struct sfe_ipv6_addr { |
| 28 | __be32 addr[4]; |
| 29 | }; |
| 30 | |
| 31 | typedef union { |
| 32 | __be32 ip; |
| 33 | struct sfe_ipv6_addr ip6[1]; |
| 34 | } sfe_ip_addr_t; |
| 35 | |
| 36 | /* |
| 37 | * connection creation structure. |
| 38 | */ |
| 39 | struct sfe_connection_create { |
| 40 | int protocol; |
| 41 | struct net_device *src_dev; |
| 42 | struct net_device *dest_dev; |
| 43 | uint32_t flags; |
| 44 | uint32_t src_mtu; |
| 45 | uint32_t dest_mtu; |
| 46 | sfe_ip_addr_t src_ip; |
| 47 | sfe_ip_addr_t src_ip_xlate; |
| 48 | sfe_ip_addr_t dest_ip; |
| 49 | sfe_ip_addr_t dest_ip_xlate; |
| 50 | __be16 src_port; |
| 51 | __be16 src_port_xlate; |
| 52 | __be16 dest_port; |
| 53 | __be16 dest_port_xlate; |
| 54 | uint8_t src_mac[ETH_ALEN]; |
| 55 | uint8_t src_mac_xlate[ETH_ALEN]; |
| 56 | uint8_t dest_mac[ETH_ALEN]; |
| 57 | uint8_t dest_mac_xlate[ETH_ALEN]; |
| 58 | uint8_t src_td_window_scale; |
| 59 | uint32_t src_td_max_window; |
| 60 | uint32_t src_td_end; |
| 61 | uint32_t src_td_max_end; |
| 62 | uint8_t dest_td_window_scale; |
| 63 | uint32_t dest_td_max_window; |
| 64 | uint32_t dest_td_end; |
| 65 | uint32_t dest_td_max_end; |
| 66 | uint32_t mark; |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 67 | #ifdef CONFIG_XFRM |
| 68 | uint32_t original_accel; |
| 69 | uint32_t reply_accel; |
| 70 | #endif |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame^] | 71 | uint32_t src_priority; |
| 72 | uint32_t dest_priority; |
| 73 | uint32_t src_dscp; |
| 74 | uint32_t dest_dscp; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * connection destruction structure. |
| 79 | */ |
| 80 | struct sfe_connection_destroy { |
| 81 | int protocol; |
| 82 | sfe_ip_addr_t src_ip; |
| 83 | sfe_ip_addr_t dest_ip; |
| 84 | __be16 src_port; |
| 85 | __be16 dest_port; |
| 86 | }; |
| 87 | |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame^] | 88 | typedef enum sfe_sync_reason { |
| 89 | SFE_SYNC_REASON_STATS, /* Sync is to synchronize stats */ |
| 90 | SFE_SYNC_REASON_FLUSH, /* Sync is to flush a entry */ |
| 91 | SFE_SYNC_REASON_DESTROY /* Sync is to destroy a entry(requested by connection manager) */ |
| 92 | } sfe_sync_reason_t; |
| 93 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 94 | /* |
| 95 | * Structure used to sync connection stats/state back within the system. |
| 96 | * |
| 97 | * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing. |
| 98 | * 'src' is the creator of the connection. |
| 99 | */ |
| 100 | struct sfe_connection_sync { |
| 101 | struct net_device *src_dev; |
| 102 | struct net_device *dest_dev; |
| 103 | int is_v6; /* Is it for ipv6? */ |
| 104 | int protocol; /* IP protocol number (IPPROTO_...) */ |
| 105 | sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame^] | 106 | sfe_ip_addr_t src_ip_xlate; /* NATed source address */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 107 | __be16 src_port; /* Non-NAT source port */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame^] | 108 | __be16 src_port_xlate; /* NATed source port */ |
| 109 | sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */ |
| 110 | sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 111 | __be16 dest_port; /* Non-NAT destination port */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame^] | 112 | __be16 dest_port_xlate; /* NATed destination port */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 113 | uint32_t src_td_max_window; |
| 114 | uint32_t src_td_end; |
| 115 | uint32_t src_td_max_end; |
| 116 | uint64_t src_packet_count; |
| 117 | uint64_t src_byte_count; |
| 118 | uint32_t src_new_packet_count; |
| 119 | uint32_t src_new_byte_count; |
| 120 | uint32_t dest_td_max_window; |
| 121 | uint32_t dest_td_end; |
| 122 | uint32_t dest_td_max_end; |
| 123 | uint64_t dest_packet_count; |
| 124 | uint64_t dest_byte_count; |
| 125 | uint32_t dest_new_packet_count; |
| 126 | uint32_t dest_new_byte_count; |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame^] | 127 | uint32_t reason; /* reason for stats sync message, i.e. destroy, flush, period sync */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 128 | uint64_t delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */ |
| 129 | }; |
| 130 | |
| 131 | /* |
| 132 | * connection mark structure |
| 133 | */ |
| 134 | struct sfe_connection_mark { |
| 135 | int protocol; |
| 136 | sfe_ip_addr_t src_ip; |
| 137 | sfe_ip_addr_t dest_ip; |
| 138 | __be16 src_port; |
| 139 | __be16 dest_port; |
| 140 | uint32_t mark; |
| 141 | }; |
| 142 | |
| 143 | /* |
| 144 | * Type used for a sync rule callback. |
| 145 | */ |
| 146 | typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *); |
| 147 | |
| 148 | /* |
| 149 | * IPv4 APIs used by connection manager |
| 150 | */ |
| 151 | extern int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb); |
| 152 | extern int sfe_ipv4_create_rule(struct sfe_connection_create *sic); |
| 153 | extern void sfe_ipv4_destroy_rule(struct sfe_connection_destroy *sid); |
| 154 | extern void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev); |
| 155 | extern void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback); |
| 156 | extern void sfe_ipv4_update_rule(struct sfe_connection_create *sic); |
| 157 | extern void sfe_ipv4_mark_rule(struct sfe_connection_mark *mark); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 158 | |
| 159 | #ifdef SFE_SUPPORT_IPV6 |
| 160 | /* |
| 161 | * IPv6 APIs used by connection manager |
| 162 | */ |
| 163 | extern int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb); |
| 164 | extern int sfe_ipv6_create_rule(struct sfe_connection_create *sic); |
| 165 | extern void sfe_ipv6_destroy_rule(struct sfe_connection_destroy *sid); |
| 166 | extern void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev); |
| 167 | extern void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback); |
| 168 | extern void sfe_ipv6_update_rule(struct sfe_connection_create *sic); |
| 169 | extern void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark); |
| 170 | #else |
| 171 | static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb) |
| 172 | { |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static inline int sfe_ipv6_create_rule(struct sfe_connection_create *sic) |
| 177 | { |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | static inline void sfe_ipv6_destroy_rule(struct sfe_connection_destroy *sid) |
| 182 | { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev) |
| 187 | { |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback) |
| 192 | { |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | static inline void sfe_ipv6_update_rule(struct sfe_connection_create *sic) |
| 197 | { |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | static inline void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark) |
| 202 | { |
| 203 | return; |
| 204 | } |
| 205 | #endif |