blob: 031af986a8c146443fc9eb8722e857b1b136cfa8 [file] [log] [blame]
Xiaoping Fand44a5b42015-05-26 17:37:37 -07001/*
2 * sfe_cm.h
3 * Shortcut forwarding engine.
4 *
Xiaoping Fana42c68b2015-08-07 18:00:39 -07005 * 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 Fand44a5b42015-05-26 17:37:37 -070016 */
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 */
27struct sfe_ipv6_addr {
28 __be32 addr[4];
29};
30
31typedef union {
32 __be32 ip;
33 struct sfe_ipv6_addr ip6[1];
34} sfe_ip_addr_t;
35
36/*
37 * connection creation structure.
38 */
39struct 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 Chen8748eb32015-06-18 12:58:48 -070067#ifdef CONFIG_XFRM
68 uint32_t original_accel;
69 uint32_t reply_accel;
70#endif
Xiaoping Fand44a5b42015-05-26 17:37:37 -070071};
72
73/*
74 * connection destruction structure.
75 */
76struct sfe_connection_destroy {
77 int protocol;
78 sfe_ip_addr_t src_ip;
79 sfe_ip_addr_t dest_ip;
80 __be16 src_port;
81 __be16 dest_port;
82};
83
84/*
85 * Structure used to sync connection stats/state back within the system.
86 *
87 * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing.
88 * 'src' is the creator of the connection.
89 */
90struct sfe_connection_sync {
91 struct net_device *src_dev;
92 struct net_device *dest_dev;
93 int is_v6; /* Is it for ipv6? */
94 int protocol; /* IP protocol number (IPPROTO_...) */
95 sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */
96 __be16 src_port; /* Non-NAT source port */
97 sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */
98 __be16 dest_port; /* Non-NAT destination port */
99 uint32_t src_td_max_window;
100 uint32_t src_td_end;
101 uint32_t src_td_max_end;
102 uint64_t src_packet_count;
103 uint64_t src_byte_count;
104 uint32_t src_new_packet_count;
105 uint32_t src_new_byte_count;
106 uint32_t dest_td_max_window;
107 uint32_t dest_td_end;
108 uint32_t dest_td_max_end;
109 uint64_t dest_packet_count;
110 uint64_t dest_byte_count;
111 uint32_t dest_new_packet_count;
112 uint32_t dest_new_byte_count;
113 uint64_t delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */
114};
115
116/*
117 * connection mark structure
118 */
119struct sfe_connection_mark {
120 int protocol;
121 sfe_ip_addr_t src_ip;
122 sfe_ip_addr_t dest_ip;
123 __be16 src_port;
124 __be16 dest_port;
125 uint32_t mark;
126};
127
128/*
129 * Type used for a sync rule callback.
130 */
131typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *);
132
133/*
134 * IPv4 APIs used by connection manager
135 */
136extern int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb);
137extern int sfe_ipv4_create_rule(struct sfe_connection_create *sic);
138extern void sfe_ipv4_destroy_rule(struct sfe_connection_destroy *sid);
139extern void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev);
140extern void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
141extern void sfe_ipv4_update_rule(struct sfe_connection_create *sic);
142extern void sfe_ipv4_mark_rule(struct sfe_connection_mark *mark);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700143
144#ifdef SFE_SUPPORT_IPV6
145/*
146 * IPv6 APIs used by connection manager
147 */
148extern int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb);
149extern int sfe_ipv6_create_rule(struct sfe_connection_create *sic);
150extern void sfe_ipv6_destroy_rule(struct sfe_connection_destroy *sid);
151extern void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev);
152extern void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
153extern void sfe_ipv6_update_rule(struct sfe_connection_create *sic);
154extern void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark);
155#else
156static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb)
157{
158 return 0;
159}
160
161static inline int sfe_ipv6_create_rule(struct sfe_connection_create *sic)
162{
163 return -1;
164}
165
166static inline void sfe_ipv6_destroy_rule(struct sfe_connection_destroy *sid)
167{
168 return;
169}
170
171static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev)
172{
173 return;
174}
175
176static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback)
177{
178 return;
179}
180
181static inline void sfe_ipv6_update_rule(struct sfe_connection_create *sic)
182{
183 return;
184}
185
186static inline void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark)
187{
188 return;
189}
190#endif