blob: 5703c14e93ebcac9649cf4d464c7086633479215 [file] [log] [blame]
Ben Menchaca84f36632014-02-28 20:57:38 +00001/*
2 **************************************************************************
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17#include <linux/types.h>
18#include <linux/ip.h>
19#include <linux/tcp.h>
20#include <linux/module.h>
21#include <linux/skbuff.h>
22#include <linux/icmp.h>
23#include <linux/sysctl.h>
24#include <linux/kthread.h>
Murat Sezgin1f381852014-11-20 09:51:07 -080025#include <linux/device.h>
Ben Menchaca84f36632014-02-28 20:57:38 +000026#include <linux/fs.h>
27#include <linux/pkt_sched.h>
28#include <linux/string.h>
29#include <net/route.h>
30#include <net/ip.h>
31#include <net/tcp.h>
32#include <asm/unaligned.h>
33#include <asm/uaccess.h> /* for put_user */
34#include <net/ipv6.h>
35#include <linux/inet.h>
36#include <linux/in.h>
37#include <linux/udp.h>
38#include <linux/tcp.h>
39
40#include <linux/netfilter_ipv4.h>
41#include <linux/netfilter_bridge.h>
42#include <net/netfilter/nf_conntrack.h>
43#include <net/netfilter/nf_conntrack_helper.h>
44#include <net/netfilter/nf_conntrack_l4proto.h>
45#include <net/netfilter/nf_conntrack_l3proto.h>
46#include <net/netfilter/nf_conntrack_core.h>
47#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
48#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
49
50/*
51 * Debug output levels
52 * 0 = OFF
53 * 1 = ASSERTS / ERRORS
54 * 2 = 1 + WARN
55 * 3 = 2 + INFO
56 * 4 = 3 + TRACE
57 */
58#define DEBUG_LEVEL ECM_TRACKER_DEBUG_LEVEL
59
60#include "ecm_types.h"
61#include "ecm_db_types.h"
62#include "ecm_tracker.h"
63
64int ecm_tracker_data_total = 0; /* Data total for all skb list instances */
65int ecm_tracker_data_buffer_total = 0; /* Data buffer total allocated for all skb list instances */
66int ecm_tracker_data_limit = ECM_TRACKER_GLOBAL_DATA_LIMIT_DEFAULT;
67int ecm_tracker_data_buffer_limit = ECM_TRACKER_GLOBAL_DATA_BUFFER_LIMIT_DEFAULT;
68 /* Tracked limit for data across all instances */
69spinlock_t ecm_tracker_lock; /* Global lock for the tracker globals */
70
71struct ecm_tracker_ip_protocols;
72
73typedef bool (*ecm_tracker_ip_header_helper_method_t)(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
74 /* A header helper method is used to inspect a protocol header, determine if it is valid, its size etc. and where any next header will be esp. important for IPv6 */
75
76/*
77 * Forward references for the header helpers
78 */
79static bool ecm_tracker_ip_header_helper_tcp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
80static bool ecm_tracker_ip_header_helper_udp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
81static bool ecm_tracker_ip_header_helper_icmp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
82static bool ecm_tracker_ip_header_helper_unknown(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
83static bool ecm_tracker_ip_header_helper_ipv6_generic(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
84static bool ecm_tracker_ip_header_helper_ipv6_fragment(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
85static bool ecm_tracker_ip_header_helper_gre(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
86static bool ecm_tracker_ip_header_helper_ah(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
87static bool ecm_tracker_ip_header_helper_ipv6_icmp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr);
88
89/*
90 * struct ecm_tracker_ip_protocols_known[]
91 * A list of protocols known to the tracker and which it will record the location of in its ecm_tracker_ip_header.
92 *
93 * This is especially important for IPv6 which can have multiple headers in its packet.
94 */
95static struct ecm_tracker_ip_protocols {
96 uint8_t ip_protocol; /* The IP protocol we want to detect and record its information */
97 ecm_tracker_ip_protocol_type_t ecm_ip_protocol; /* The ECM Tracker protocol identifier equivalent */
98 char *name; /* Visual name of the protocol */
99 ecm_tracker_ip_header_helper_method_t header_helper; /* A function used to help process the header, e.g. its size etc. When a NULL helper is located, header processing stops. */
100} ecm_tracker_ip_protocols_known[256] =
101{
102 {0, ECM_TRACKER_IP_PROTOCOL_TYPE_IPV6_HBH, "ipv6_hbh", ecm_tracker_ip_header_helper_ipv6_generic},
103 {1, ECM_TRACKER_IP_PROTOCOL_TYPE_ICMP, "icmp", ecm_tracker_ip_header_helper_icmp},
104 {2, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "2", ecm_tracker_ip_header_helper_unknown},
105 {3, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "3", ecm_tracker_ip_header_helper_unknown},
106 {4, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "4", ecm_tracker_ip_header_helper_unknown},
107 {5, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "5", ecm_tracker_ip_header_helper_unknown},
108 {6, ECM_TRACKER_IP_PROTOCOL_TYPE_TCP, "tcp", ecm_tracker_ip_header_helper_tcp},
109 {7, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "7", ecm_tracker_ip_header_helper_unknown},
110 {8, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "8", ecm_tracker_ip_header_helper_unknown},
111 {9, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "9", ecm_tracker_ip_header_helper_unknown},
112 {10, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "10", ecm_tracker_ip_header_helper_unknown},
113 {11, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "11", ecm_tracker_ip_header_helper_unknown},
114 {12, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "12", ecm_tracker_ip_header_helper_unknown},
115 {13, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "13", ecm_tracker_ip_header_helper_unknown},
116 {14, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "14", ecm_tracker_ip_header_helper_unknown},
117 {15, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "15", ecm_tracker_ip_header_helper_unknown},
118 {16, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "16", ecm_tracker_ip_header_helper_unknown},
119 {17, ECM_TRACKER_IP_PROTOCOL_TYPE_UDP, "udp", ecm_tracker_ip_header_helper_udp},
120 {18, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "18", ecm_tracker_ip_header_helper_unknown},
121 {19, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "19", ecm_tracker_ip_header_helper_unknown},
122 {20, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "20", ecm_tracker_ip_header_helper_unknown},
123 {21, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "21", ecm_tracker_ip_header_helper_unknown},
124 {22, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "22", ecm_tracker_ip_header_helper_unknown},
125 {23, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "23", ecm_tracker_ip_header_helper_unknown},
126 {24, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "24", ecm_tracker_ip_header_helper_unknown},
127 {25, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "25", ecm_tracker_ip_header_helper_unknown},
128 {26, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "26", ecm_tracker_ip_header_helper_unknown},
129 {27, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "27", ecm_tracker_ip_header_helper_unknown},
130 {28, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "28", ecm_tracker_ip_header_helper_unknown},
131 {29, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "29", ecm_tracker_ip_header_helper_unknown},
132 {30, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "30", ecm_tracker_ip_header_helper_unknown},
133 {31, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "31", ecm_tracker_ip_header_helper_unknown},
134 {32, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "32", ecm_tracker_ip_header_helper_unknown},
135 {33, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "33", ecm_tracker_ip_header_helper_unknown},
136 {34, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "34", ecm_tracker_ip_header_helper_unknown},
137 {35, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "35", ecm_tracker_ip_header_helper_unknown},
138 {36, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "36", ecm_tracker_ip_header_helper_unknown},
139 {37, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "37", ecm_tracker_ip_header_helper_unknown},
140 {38, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "38", ecm_tracker_ip_header_helper_unknown},
141 {39, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "39", ecm_tracker_ip_header_helper_unknown},
142 {40, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "40", ecm_tracker_ip_header_helper_unknown},
143 {41, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "41", ecm_tracker_ip_header_helper_unknown},
144 {42, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "42", ecm_tracker_ip_header_helper_unknown},
145 {43, ECM_TRACKER_IP_PROTOCOL_TYPE_IPV6_ROUTING, "ipv6_routing", ecm_tracker_ip_header_helper_ipv6_generic},
146 {44, ECM_TRACKER_IP_PROTOCOL_TYPE_IPV6_FRAGMENT, "ipv6_fragment", ecm_tracker_ip_header_helper_ipv6_fragment},
147 {45, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "45", ecm_tracker_ip_header_helper_unknown},
148 {46, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "46", ecm_tracker_ip_header_helper_unknown},
149 {47, ECM_TRACKER_IP_PROTOCOL_TYPE_GRE, "gre", ecm_tracker_ip_header_helper_gre},
150 {48, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "48", ecm_tracker_ip_header_helper_unknown},
151 {49, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "49", ecm_tracker_ip_header_helper_unknown},
152 {50, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "50", ecm_tracker_ip_header_helper_unknown},
153 {51, ECM_TRACKER_IP_PROTOCOL_TYPE_AH, "ah", ecm_tracker_ip_header_helper_ah},
154 {52, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "52", ecm_tracker_ip_header_helper_unknown},
155 {53, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "53", ecm_tracker_ip_header_helper_unknown},
156 {54, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "54", ecm_tracker_ip_header_helper_unknown},
157 {55, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "55", ecm_tracker_ip_header_helper_unknown},
158 {56, ECM_TRACKER_IP_PROTOCOL_TYPE_IPV6_ICMP, "ipv6_icmp", ecm_tracker_ip_header_helper_ipv6_icmp},
159 {57, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "57", ecm_tracker_ip_header_helper_unknown},
160 {58, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "58", ecm_tracker_ip_header_helper_unknown},
161 {59, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "59", ecm_tracker_ip_header_helper_unknown},
162 {60, ECM_TRACKER_IP_PROTOCOL_TYPE_IPV6_DO, "ipv6_do", ecm_tracker_ip_header_helper_ipv6_generic},
163 {61, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "61", ecm_tracker_ip_header_helper_unknown},
164 {62, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "62", ecm_tracker_ip_header_helper_unknown},
165 {63, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "63", ecm_tracker_ip_header_helper_unknown},
166 {64, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "64", ecm_tracker_ip_header_helper_unknown},
167 {65, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "65", ecm_tracker_ip_header_helper_unknown},
168 {66, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "66", ecm_tracker_ip_header_helper_unknown},
169 {67, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "67", ecm_tracker_ip_header_helper_unknown},
170 {68, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "68", ecm_tracker_ip_header_helper_unknown},
171 {69, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "69", ecm_tracker_ip_header_helper_unknown},
172 {70, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "70", ecm_tracker_ip_header_helper_unknown},
173 {71, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "71", ecm_tracker_ip_header_helper_unknown},
174 {72, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "72", ecm_tracker_ip_header_helper_unknown},
175 {73, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "73", ecm_tracker_ip_header_helper_unknown},
176 {74, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "74", ecm_tracker_ip_header_helper_unknown},
177 {75, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "75", ecm_tracker_ip_header_helper_unknown},
178 {76, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "76", ecm_tracker_ip_header_helper_unknown},
179 {77, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "77", ecm_tracker_ip_header_helper_unknown},
180 {78, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "78", ecm_tracker_ip_header_helper_unknown},
181 {79, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "79", ecm_tracker_ip_header_helper_unknown},
182 {80, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "80", ecm_tracker_ip_header_helper_unknown},
183 {81, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "81", ecm_tracker_ip_header_helper_unknown},
184 {82, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "82", ecm_tracker_ip_header_helper_unknown},
185 {83, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "83", ecm_tracker_ip_header_helper_unknown},
186 {84, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "84", ecm_tracker_ip_header_helper_unknown},
187 {85, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "85", ecm_tracker_ip_header_helper_unknown},
188 {86, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "86", ecm_tracker_ip_header_helper_unknown},
189 {87, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "87", ecm_tracker_ip_header_helper_unknown},
190 {88, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "88", ecm_tracker_ip_header_helper_unknown},
191 {89, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "89", ecm_tracker_ip_header_helper_unknown},
192 {90, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "90", ecm_tracker_ip_header_helper_unknown},
193 {91, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "91", ecm_tracker_ip_header_helper_unknown},
194 {92, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "92", ecm_tracker_ip_header_helper_unknown},
195 {93, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "93", ecm_tracker_ip_header_helper_unknown},
196 {94, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "94", ecm_tracker_ip_header_helper_unknown},
197 {95, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "95", ecm_tracker_ip_header_helper_unknown},
198 {96, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "96", ecm_tracker_ip_header_helper_unknown},
199 {97, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "97", ecm_tracker_ip_header_helper_unknown},
200 {98, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "98", ecm_tracker_ip_header_helper_unknown},
201 {99, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "99", ecm_tracker_ip_header_helper_unknown},
202 {100, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "100", ecm_tracker_ip_header_helper_unknown},
203 {101, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "101", ecm_tracker_ip_header_helper_unknown},
204 {102, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "102", ecm_tracker_ip_header_helper_unknown},
205 {103, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "103", ecm_tracker_ip_header_helper_unknown},
206 {104, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "104", ecm_tracker_ip_header_helper_unknown},
207 {105, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "105", ecm_tracker_ip_header_helper_unknown},
208 {106, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "106", ecm_tracker_ip_header_helper_unknown},
209 {107, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "107", ecm_tracker_ip_header_helper_unknown},
210 {108, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "108", ecm_tracker_ip_header_helper_unknown},
211 {109, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "109", ecm_tracker_ip_header_helper_unknown},
212 {110, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "110", ecm_tracker_ip_header_helper_unknown},
213 {111, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "111", ecm_tracker_ip_header_helper_unknown},
214 {112, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "112", ecm_tracker_ip_header_helper_unknown},
215 {113, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "113", ecm_tracker_ip_header_helper_unknown},
216 {114, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "114", ecm_tracker_ip_header_helper_unknown},
217 {115, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "115", ecm_tracker_ip_header_helper_unknown},
218 {116, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "116", ecm_tracker_ip_header_helper_unknown},
219 {117, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "117", ecm_tracker_ip_header_helper_unknown},
220 {118, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "118", ecm_tracker_ip_header_helper_unknown},
221 {119, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "119", ecm_tracker_ip_header_helper_unknown},
222 {120, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "120", ecm_tracker_ip_header_helper_unknown},
223 {121, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "121", ecm_tracker_ip_header_helper_unknown},
224 {122, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "122", ecm_tracker_ip_header_helper_unknown},
225 {123, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "123", ecm_tracker_ip_header_helper_unknown},
226 {124, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "124", ecm_tracker_ip_header_helper_unknown},
227 {125, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "125", ecm_tracker_ip_header_helper_unknown},
228 {126, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "126", ecm_tracker_ip_header_helper_unknown},
229 {127, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "127", ecm_tracker_ip_header_helper_unknown},
230 {128, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "128", ecm_tracker_ip_header_helper_unknown},
231 {129, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "129", ecm_tracker_ip_header_helper_unknown},
232 {130, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "130", ecm_tracker_ip_header_helper_unknown},
233 {131, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "131", ecm_tracker_ip_header_helper_unknown},
234 {132, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "132", ecm_tracker_ip_header_helper_unknown},
235 {133, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "133", ecm_tracker_ip_header_helper_unknown},
236 {134, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "134", ecm_tracker_ip_header_helper_unknown},
237 {135, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "135", ecm_tracker_ip_header_helper_unknown},
238 {136, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "136", ecm_tracker_ip_header_helper_unknown},
239 {137, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "137", ecm_tracker_ip_header_helper_unknown},
240 {138, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "138", ecm_tracker_ip_header_helper_unknown},
241 {139, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "139", ecm_tracker_ip_header_helper_unknown},
242 {140, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "140", ecm_tracker_ip_header_helper_unknown},
243 {141, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "141", ecm_tracker_ip_header_helper_unknown},
244 {142, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "142", ecm_tracker_ip_header_helper_unknown},
245 {143, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "143", ecm_tracker_ip_header_helper_unknown},
246 {144, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "144", ecm_tracker_ip_header_helper_unknown},
247 {145, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "145", ecm_tracker_ip_header_helper_unknown},
248 {146, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "146", ecm_tracker_ip_header_helper_unknown},
249 {147, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "147", ecm_tracker_ip_header_helper_unknown},
250 {148, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "148", ecm_tracker_ip_header_helper_unknown},
251 {149, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "149", ecm_tracker_ip_header_helper_unknown},
252 {150, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "150", ecm_tracker_ip_header_helper_unknown},
253 {151, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "151", ecm_tracker_ip_header_helper_unknown},
254 {152, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "152", ecm_tracker_ip_header_helper_unknown},
255 {153, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "153", ecm_tracker_ip_header_helper_unknown},
256 {154, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "154", ecm_tracker_ip_header_helper_unknown},
257 {155, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "155", ecm_tracker_ip_header_helper_unknown},
258 {156, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "156", ecm_tracker_ip_header_helper_unknown},
259 {157, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "157", ecm_tracker_ip_header_helper_unknown},
260 {158, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "158", ecm_tracker_ip_header_helper_unknown},
261 {159, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "159", ecm_tracker_ip_header_helper_unknown},
262 {160, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "160", ecm_tracker_ip_header_helper_unknown},
263 {161, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "161", ecm_tracker_ip_header_helper_unknown},
264 {162, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "162", ecm_tracker_ip_header_helper_unknown},
265 {163, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "163", ecm_tracker_ip_header_helper_unknown},
266 {164, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "164", ecm_tracker_ip_header_helper_unknown},
267 {165, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "165", ecm_tracker_ip_header_helper_unknown},
268 {166, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "166", ecm_tracker_ip_header_helper_unknown},
269 {167, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "167", ecm_tracker_ip_header_helper_unknown},
270 {168, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "168", ecm_tracker_ip_header_helper_unknown},
271 {169, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "169", ecm_tracker_ip_header_helper_unknown},
272 {170, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "170", ecm_tracker_ip_header_helper_unknown},
273 {171, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "171", ecm_tracker_ip_header_helper_unknown},
274 {172, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "172", ecm_tracker_ip_header_helper_unknown},
275 {173, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "173", ecm_tracker_ip_header_helper_unknown},
276 {174, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "174", ecm_tracker_ip_header_helper_unknown},
277 {175, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "175", ecm_tracker_ip_header_helper_unknown},
278 {176, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "176", ecm_tracker_ip_header_helper_unknown},
279 {177, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "177", ecm_tracker_ip_header_helper_unknown},
280 {178, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "178", ecm_tracker_ip_header_helper_unknown},
281 {179, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "179", ecm_tracker_ip_header_helper_unknown},
282 {180, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "180", ecm_tracker_ip_header_helper_unknown},
283 {181, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "181", ecm_tracker_ip_header_helper_unknown},
284 {182, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "182", ecm_tracker_ip_header_helper_unknown},
285 {183, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "183", ecm_tracker_ip_header_helper_unknown},
286 {184, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "184", ecm_tracker_ip_header_helper_unknown},
287 {185, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "185", ecm_tracker_ip_header_helper_unknown},
288 {186, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "186", ecm_tracker_ip_header_helper_unknown},
289 {187, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "187", ecm_tracker_ip_header_helper_unknown},
290 {188, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "188", ecm_tracker_ip_header_helper_unknown},
291 {189, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "189", ecm_tracker_ip_header_helper_unknown},
292 {190, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "190", ecm_tracker_ip_header_helper_unknown},
293 {191, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "191", ecm_tracker_ip_header_helper_unknown},
294 {192, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "192", ecm_tracker_ip_header_helper_unknown},
295 {193, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "193", ecm_tracker_ip_header_helper_unknown},
296 {194, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "194", ecm_tracker_ip_header_helper_unknown},
297 {195, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "195", ecm_tracker_ip_header_helper_unknown},
298 {196, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "196", ecm_tracker_ip_header_helper_unknown},
299 {197, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "197", ecm_tracker_ip_header_helper_unknown},
300 {198, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "198", ecm_tracker_ip_header_helper_unknown},
301 {199, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "199", ecm_tracker_ip_header_helper_unknown},
302 {200, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "200", ecm_tracker_ip_header_helper_unknown},
303 {201, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "201", ecm_tracker_ip_header_helper_unknown},
304 {202, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "202", ecm_tracker_ip_header_helper_unknown},
305 {203, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "203", ecm_tracker_ip_header_helper_unknown},
306 {204, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "204", ecm_tracker_ip_header_helper_unknown},
307 {205, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "205", ecm_tracker_ip_header_helper_unknown},
308 {206, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "206", ecm_tracker_ip_header_helper_unknown},
309 {207, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "207", ecm_tracker_ip_header_helper_unknown},
310 {208, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "208", ecm_tracker_ip_header_helper_unknown},
311 {209, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "209", ecm_tracker_ip_header_helper_unknown},
312 {210, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "210", ecm_tracker_ip_header_helper_unknown},
313 {211, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "211", ecm_tracker_ip_header_helper_unknown},
314 {212, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "212", ecm_tracker_ip_header_helper_unknown},
315 {213, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "213", ecm_tracker_ip_header_helper_unknown},
316 {214, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "214", ecm_tracker_ip_header_helper_unknown},
317 {215, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "215", ecm_tracker_ip_header_helper_unknown},
318 {216, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "216", ecm_tracker_ip_header_helper_unknown},
319 {217, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "217", ecm_tracker_ip_header_helper_unknown},
320 {218, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "218", ecm_tracker_ip_header_helper_unknown},
321 {219, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "219", ecm_tracker_ip_header_helper_unknown},
322 {220, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "220", ecm_tracker_ip_header_helper_unknown},
323 {221, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "221", ecm_tracker_ip_header_helper_unknown},
324 {222, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "222", ecm_tracker_ip_header_helper_unknown},
325 {223, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "223", ecm_tracker_ip_header_helper_unknown},
326 {224, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "224", ecm_tracker_ip_header_helper_unknown},
327 {225, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "225", ecm_tracker_ip_header_helper_unknown},
328 {226, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "226", ecm_tracker_ip_header_helper_unknown},
329 {227, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "227", ecm_tracker_ip_header_helper_unknown},
330 {228, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "228", ecm_tracker_ip_header_helper_unknown},
331 {229, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "229", ecm_tracker_ip_header_helper_unknown},
332 {230, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "230", ecm_tracker_ip_header_helper_unknown},
333 {231, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "231", ecm_tracker_ip_header_helper_unknown},
334 {232, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "232", ecm_tracker_ip_header_helper_unknown},
335 {233, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "233", ecm_tracker_ip_header_helper_unknown},
336 {234, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "234", ecm_tracker_ip_header_helper_unknown},
337 {235, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "235", ecm_tracker_ip_header_helper_unknown},
338 {236, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "236", ecm_tracker_ip_header_helper_unknown},
339 {237, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "237", ecm_tracker_ip_header_helper_unknown},
340 {238, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "238", ecm_tracker_ip_header_helper_unknown},
341 {239, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "239", ecm_tracker_ip_header_helper_unknown},
342 {240, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "240", ecm_tracker_ip_header_helper_unknown},
343 {241, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "241", ecm_tracker_ip_header_helper_unknown},
344 {242, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "242", ecm_tracker_ip_header_helper_unknown},
345 {243, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "243", ecm_tracker_ip_header_helper_unknown},
346 {244, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "244", ecm_tracker_ip_header_helper_unknown},
347 {245, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "245", ecm_tracker_ip_header_helper_unknown},
348 {246, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "246", ecm_tracker_ip_header_helper_unknown},
349 {247, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "247", ecm_tracker_ip_header_helper_unknown},
350 {248, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "248", ecm_tracker_ip_header_helper_unknown},
351 {249, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "249", ecm_tracker_ip_header_helper_unknown},
352 {250, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "250", ecm_tracker_ip_header_helper_unknown},
353 {251, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "251", ecm_tracker_ip_header_helper_unknown},
354 {252, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "252", ecm_tracker_ip_header_helper_unknown},
355 {253, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "253", ecm_tracker_ip_header_helper_unknown},
356 {254, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "254", ecm_tracker_ip_header_helper_unknown},
357 {255, ECM_TRACKER_IP_PROTOCOL_TYPE_UNKNOWN, "255", ecm_tracker_ip_header_helper_unknown}
358};
359
Nicolas Costa1d9eb992014-05-15 10:01:03 -0500360static char *ecm_tracker_sender_state_strings[] = {
361 "Unknown",
362 "Establishing",
363 "Established",
364 "Closing",
365 "Closed",
366 "Fault"
367};
368
369static char *ecm_tracker_connection_state_strings[] = {
370 "Establishing",
371 "Established",
372 "Closing",
373 "Closed",
374 "Fault"
375};
376
Ben Menchaca84f36632014-02-28 20:57:38 +0000377/*
378 * ecm_tracker_ip_check_header_and_read()
379 * Check that we have a complete network-level IPv4 or V6 header, check it and return true if so.
380 */
381bool ecm_tracker_ip_check_header_and_read(struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb)
382{
Matthew McClintock0ffc52e2014-09-19 14:41:23 -0500383 struct iphdr *v4_hdr = NULL;
384 struct ipv6hdr *v6_hdr = NULL;
Ben Menchaca84f36632014-02-28 20:57:38 +0000385 int16_t this_header;
386 uint32_t offset;
387 uint16_t remain;
388
389 memset(ip_hdr, 0, sizeof(*ip_hdr));
390
391 ip_hdr->skb = skb;
392
393 /*
394 * Dealing with IPv4 or IPv6?
395 */
396 v4_hdr = skb_header_pointer(skb, 0, sizeof(struct iphdr), &ip_hdr->h.v4_hdr);
397 if (v4_hdr && (v4_hdr->version == 4)) {
398 DEBUG_TRACE("%p: skb: %p is ipv4\n", ip_hdr, skb);
399 ip_hdr->is_v4 = true;
400 } else {
401 /*
402 * Try V6
403 */
404 DEBUG_TRACE("skb: %p contains no v4 header\n", skb);
405 v6_hdr = skb_header_pointer(skb, 0, sizeof(struct ipv6hdr), &ip_hdr->h.v6_hdr);
406 if (!v6_hdr || (v6_hdr->version != 6)) {
407 DEBUG_TRACE("skb: %p contains no v6 header\n", skb);
408 return false;
409 }
410 DEBUG_TRACE("%p: skb: %p is ipv6\n", ip_hdr, skb);
411 ip_hdr->is_v4 = false;
412 }
413
414 if (ip_hdr->is_v4) {
415 uint8_t protocol;
416 int16_t next_unused;
417 ecm_tracker_ip_protocol_type_t ecm_ip_protocol;
418 struct ecm_tracker_ip_protocols *etip;
419 struct ecm_tracker_ip_protocol_header *etiph;
420
421 DEBUG_TRACE("%p: skb: %p ipv4\n", ip_hdr, skb);
422
423 /*
424 * Process IPv4
425 */
426 ECM_NIN4_ADDR_TO_IP_ADDR(ip_hdr->src_addr, v4_hdr->saddr);
427 ECM_NIN4_ADDR_TO_IP_ADDR(ip_hdr->dest_addr, v4_hdr->daddr);
428 ip_hdr->ip_header_length = v4_hdr->ihl;
429 ip_hdr->ip_header_length <<= 2;
430 if (ip_hdr->ip_header_length < 20) {
431 DEBUG_WARN("%p: v4 invalid ip hdr len %d\n", skb, ip_hdr->ip_header_length);
432 return false;
433 }
434 ip_hdr->total_length = ntohs(v4_hdr->tot_len);
435 if (skb->len < ip_hdr->total_length) {
436 DEBUG_WARN("%p: v4 invalid total len: %u skb len: %u\n", skb, ip_hdr->total_length, skb->len);
437 return false;
438 }
439 remain = ip_hdr->total_length - ip_hdr->ip_header_length;
440
441 /*
442 * Fragmented?
443 */
444 ip_hdr->fragmented = (ntohs(v4_hdr->frag_off) & 0x3fff)? true : false;
445
446 /*
Gareth Williams8932a912014-06-11 18:06:25 -0700447 * DS field
448 */
449 ip_hdr->ds = ipv4_get_dsfield(v4_hdr);
450
451 /*
Ben Menchaca84f36632014-02-28 20:57:38 +0000452 * Get the protocol and where the header info will be stored
453 */
454 protocol = v4_hdr->protocol;
455 ip_hdr->protocol = (int)v4_hdr->protocol;
456 etip = &ecm_tracker_ip_protocols_known[protocol]; /* Get header helper */
457 ecm_ip_protocol = etip->ecm_ip_protocol;
458 etiph = &ip_hdr->headers[ecm_ip_protocol]; /* Get where the header detail is stored in ip_hdr->headers[] */
459
460 DEBUG_TRACE("%p: v4 skb: %p, len: %d, ip_header_length: %u, total_length: %u, remain: %u, fragmented: %04x, protocol: %u, ecm_ip_protocol: %d src_addr: "
461 ECM_IP_ADDR_DOT_FMT ", dest addr: " ECM_IP_ADDR_DOT_FMT "\n",
462 ip_hdr,
463 skb,
464 skb->len,
465 ip_hdr->ip_header_length,
466 ip_hdr->total_length,
467 remain,
468 ip_hdr->fragmented,
469 ip_hdr->protocol,
470 ecm_ip_protocol,
471 ECM_IP_ADDR_TO_DOT(ip_hdr->src_addr),
472 ECM_IP_ADDR_TO_DOT(ip_hdr->dest_addr));
473
474 /*
475 * Populate protocol detail
476 * IPv4 can only have one.
477 */
478 if (!etip->header_helper(
479 etip,
480 etiph,
481 ip_hdr,
482 skb,
483 (uint8_t)ip_hdr->protocol,
484 ecm_ip_protocol,
485 ip_hdr->ip_header_length,
486 remain,
487 &next_unused)) {
488 DEBUG_WARN("%p: v4 header helper failed for: %u\n", skb, protocol);
489 return false;
490 }
Nicolas Costa585002e2014-05-15 09:46:04 -0500491
Ben Menchaca84f36632014-02-28 20:57:38 +0000492 return true;
493 }
494
495 /*
496 * IPv6
497 */
498 ECM_NIN6_ADDR_TO_IP_ADDR(ip_hdr->src_addr, v6_hdr->saddr);
499 ECM_NIN6_ADDR_TO_IP_ADDR(ip_hdr->dest_addr, v6_hdr->daddr);
500 ip_hdr->ip_header_length = 40;
501 remain = ntohs(v6_hdr->payload_len);
502 ip_hdr->total_length = remain + 40;
503 if (skb->len < ip_hdr->total_length) {
504 DEBUG_WARN("%p: v6 invalid total len: %u skb len: %u\n", skb, ip_hdr->total_length, skb->len);
505 return false;
506 }
507
508 /*
Gareth Williams8932a912014-06-11 18:06:25 -0700509 * DS field
510 */
511 ip_hdr->ds = ipv6_get_dsfield(v6_hdr);
512
513 /*
Ben Menchaca84f36632014-02-28 20:57:38 +0000514 * Process headers until we run out of space, error, or we get the no next header marker for v6 (protocol 59).
515 */
516 offset = 40;
517 this_header = (int16_t)v6_hdr->nexthdr;
518 while ((remain > 0) && (this_header >= 0) && (this_header != 59)) {
519 struct ecm_tracker_ip_protocols *etip;
520 struct ecm_tracker_ip_protocol_header *etiph;
521 ecm_tracker_ip_protocol_type_t ecm_ip_protocol;
522 int16_t next_header;
523
524 etip = &ecm_tracker_ip_protocols_known[this_header]; /* Get header helper */
525 ecm_ip_protocol = etip->ecm_ip_protocol;
526 etiph = &ip_hdr->headers[ecm_ip_protocol]; /* Get where the header detail is stored in ip_hdr->headers[] */
527
528 /*
529 * If this IP header has already been seen then we abort
530 */
531 if (etiph->size) {
532 DEBUG_WARN("v6 skb: %p, protocol: %d already seen at offset: %u, size: %u\n",
533 skb, this_header, etiph->offset, etiph->size);
534 return false;
535 }
536 if (!etip->header_helper(
537 etip,
538 etiph,
539 ip_hdr,
540 skb,
541 (uint8_t)this_header,
542 ecm_ip_protocol,
543 offset,
544 remain,
545 &next_header)) {
546 DEBUG_WARN("%p: v6 header helper failed for: %d\n", skb, this_header);
547 return false;
548 }
549
550 offset += etiph->size;
551 DEBUG_ASSERT(remain >= etiph->size, "v6 remain: %u goes negative after header size: %u", remain, etiph->size);
552 remain -= etiph->size;
553
554 this_header = next_header;
555 }
556
557 /*
558 * Generally the last protocol seen is the upper layer protocol
559 */
560 ip_hdr->protocol = (int)this_header;
561
562 return ip_hdr;
563}
564EXPORT_SYMBOL(ecm_tracker_ip_check_header_and_read);
565
566/*
567 * ecm_tracker_ip_header_helper_ipv6_generic()
568 * Interpret a Generic IPv6 extension header
569 */
570static bool ecm_tracker_ip_header_helper_ipv6_generic(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
571 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
572{
573 struct ipv6_gen_hdr {
574 uint8_t next_protocol;
575 uint8_t header_ext_len;
576 } gen_header_buffer;
577 struct ipv6_gen_hdr *gen_header;
578 uint16_t hdr_size;
579
580 /*
581 * At least 8 bytes
582 */
583 if (remain < 8) {
584 return false;
585 }
586
587 gen_header = skb_header_pointer(skb, offset, sizeof(struct ipv6_gen_hdr), &gen_header_buffer);
588 if (!gen_header) {
589 return false;
590 }
591 hdr_size = gen_header->header_ext_len;
592 hdr_size <<= 3;
593 hdr_size += 8;
594 if (remain < hdr_size) {
595 DEBUG_WARN("IPv6 extension: %p packet remain: %u too small for tcp header: %u\n", skb, remain, hdr_size);
596 return false;
597 }
598 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
599 DEBUG_WARN("TCP packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
600 return false;
601 }
602
603 etiph->protocol_number = protocol;
604 etiph->header_size = hdr_size;
605 etiph->size = hdr_size;
606 etiph->offset = offset;
607
608 *next_hdr = (int16_t)gen_header->next_protocol;
Nicolas Costa585002e2014-05-15 09:46:04 -0500609 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000610}
611
612/*
613 * ecm_tracker_ip_header_helper_ipv6_fragment()
614 * Interpret a Generic IPv6 fragment header
615 */
616static bool ecm_tracker_ip_header_helper_ipv6_fragment(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
617 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
618{
619 struct ipv6_gen_hdr {
620 uint8_t next_protocol;
621 uint8_t reserved;
622 } gen_header_buffer;
623 struct ipv6_gen_hdr *gen_header;
624
625 /*
626 * At least 8 bytes
627 */
628 if (remain < 8) {
629 return false;
630 }
631
632 gen_header = skb_header_pointer(skb, offset, sizeof(struct ipv6_gen_hdr), &gen_header_buffer);
633 if (!gen_header) {
634 return false;
635 }
636 if (unlikely(ip_hdr->total_length < (offset + 8))) {
637 DEBUG_WARN("TCP packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + 8);
638 return false;
639 }
640
641 /*
642 * The very presence of a fragmemt header says it's fragmented
643 */
644 ip_hdr->fragmented = true;
645
646 etiph->protocol_number = protocol;
647 etiph->header_size = 8;
648 etiph->size = 8;
649 etiph->offset = offset;
650
651 *next_hdr = (int16_t)gen_header->next_protocol;
Nicolas Costa585002e2014-05-15 09:46:04 -0500652 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000653}
654
655/*
656 * ecm_tracker_ip_header_helper_tcp()
657 * Interpret a TCP header
658 */
659static bool ecm_tracker_ip_header_helper_tcp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
660 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
661{
662 struct tcphdr tcp_header_buffer;
663 struct tcphdr *tcp_header;
664 uint16_t hdr_size;
665
666 DEBUG_ASSERT((protocol == IPPROTO_TCP) && (ecm_ip_protocol == ECM_TRACKER_IP_PROTOCOL_TYPE_TCP), "Bad protocol: %u or ecm_ip_protocol: %d", protocol, ecm_ip_protocol);
667
668 if (remain < 20) {
669 return false;
670 }
671
672 tcp_header = skb_header_pointer(skb, offset, sizeof(struct tcphdr), &tcp_header_buffer);
673 if (!tcp_header) {
674 return false;
675 }
676 hdr_size = tcp_header->doff;
677 hdr_size <<= 2;
678 if (hdr_size < 20) {
679 return false;
680 }
681 if (remain < hdr_size) {
682 DEBUG_WARN("TCP packet: %p packet remain: %u too small for tcp header: %u\n", skb, remain, hdr_size);
683 return false;
684 }
685 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
686 DEBUG_WARN("TCP packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
687 return false;
688 }
689
690 etiph->protocol_number = protocol;
691 etiph->header_size = hdr_size;
692 etiph->size = remain;
693 etiph->offset = offset;
694
695 /*
696 * There is no header following a TCP header
697 */
698 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500699 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000700}
701
702/*
703 * ecm_tracker_ip_header_helper_gre()
704 * Interpret a GRE header
705 */
706static bool ecm_tracker_ip_header_helper_gre(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
707 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
708{
709 uint32_t gre_hdr_buffer;
710 uint32_t *gre_hdr_ptr;
711 uint32_t gre_hdr;
712 uint16_t hdr_size;
713
714 DEBUG_ASSERT((protocol == IPPROTO_GRE) && (ecm_ip_protocol == ECM_TRACKER_IP_PROTOCOL_TYPE_GRE), "Bad protocol: %u or ecm_ip_protocol: %d", protocol, ecm_ip_protocol);
715
716 if (remain < 4) {
717 return false;
718 }
719
720 gre_hdr_ptr = skb_header_pointer(skb, offset, sizeof(gre_hdr_buffer), &gre_hdr_buffer);
721 if (!gre_hdr_ptr) {
722 return false;
723 }
724 gre_hdr = ntohl(*gre_hdr_ptr);
725 hdr_size = 4;
726 if (gre_hdr & 0x80000000) {
727 /*
728 * Checksum
729 */
730 hdr_size += 4;
731 }
732 if (gre_hdr & 0x20000000) {
733 /*
734 * Key
735 */
736 hdr_size += 4;
737 }
738 if (gre_hdr & 0x10000000) {
739 /*
740 * Sequence
741 */
742 hdr_size += 4;
743 }
744 if (remain < hdr_size) {
745 DEBUG_WARN("GRE packet: %p packet remain: %u too small for tcp header: %u\n", skb, remain, hdr_size);
746 return false;
747 }
748 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
749 DEBUG_WARN("GRE packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
750 return false;
751 }
752
753 etiph->protocol_number = protocol;
754 etiph->header_size = hdr_size;
755 etiph->size = remain;
756 etiph->offset = offset;
757
758 /*
759 * There is no header following a GRE header
760 */
761 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500762 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000763}
764
765/*
766 * ecm_tracker_ip_header_helper_ah()
767 * Interpret an Authentication Header
768 */
769static bool ecm_tracker_ip_header_helper_ah(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
770 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
771{
772 struct ah_gen_hdr {
773 uint8_t next_protocol;
774 uint8_t header_len;
775 } gen_header_buffer;
776 struct ah_gen_hdr *gen_header;
777 uint16_t hdr_size;
778
779 /*
780 * At least 8 bytes
781 */
782 if (remain < 8) {
783 return false;
784 }
785
786 gen_header = skb_header_pointer(skb, offset, sizeof(struct ah_gen_hdr), &gen_header_buffer);
787 if (!gen_header) {
788 return false;
789 }
790
791 hdr_size = gen_header->header_len + 2;
792 hdr_size <<= 2;
793
794 if (!ip_hdr->is_v4) {
795 /*
796 * hdr_size needs to be a multiple of 8 in a v6 frame
797 */
798 if (hdr_size % 8) {
799 DEBUG_WARN("AH packet %p not multiple of 8 for v6 frame: %u\n", skb, hdr_size);
800 return false;
801 }
802 }
803
804 if (remain < hdr_size) {
805 DEBUG_WARN("AH packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
806 return false;
807 }
808 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
809 DEBUG_WARN("AH packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
810 return false;
811 }
812
813 /*
814 * What header follows this one?
815 */
816 *next_hdr = gen_header->next_protocol;
817
818 etiph->protocol_number = protocol;
819 etiph->header_size = hdr_size;
820 etiph->size = hdr_size;
821 etiph->offset = offset;
Nicolas Costa585002e2014-05-15 09:46:04 -0500822 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000823}
824
825/*
826 * ecm_tracker_ip_header_helper_udp()
827 * Interpret a UDP header
828 */
829static bool ecm_tracker_ip_header_helper_udp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
830 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
831{
832 DEBUG_ASSERT((protocol == IPPROTO_UDP) && (ecm_ip_protocol == ECM_TRACKER_IP_PROTOCOL_TYPE_UDP), "Bad protocol: %u or ecm_ip_protocol: %d", protocol, ecm_ip_protocol);
833
834 DEBUG_TRACE("udp helper skb: %p, protocol: %u, ecm_ip_proto: %d, offset: %u, remain: %u\n", skb, protocol, ecm_ip_protocol, offset, remain);
835 if (remain < 8) {
836 DEBUG_TRACE("not enough UDP header: %u\n", remain);
837 return false;
838 }
839
840 etiph->protocol_number = protocol;
841 etiph->header_size = 8;
842 etiph->size = remain;
843 etiph->offset = offset;
844
845 /*
846 * There is no header following a UDP header
847 */
848 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500849 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000850}
851
852/*
853 * ecm_tracker_ip_header_helper_unknown()
854 * Interpret a unknown header
855 */
856static bool ecm_tracker_ip_header_helper_unknown(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
857 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
858{
859 /*
860 * There is no header following an unknown header
861 */
862 *next_hdr = -1;
863 etiph->protocol_number = protocol;
864 etiph->header_size = remain;
865 etiph->size = remain;
866 etiph->offset = offset;
Nicolas Costa585002e2014-05-15 09:46:04 -0500867 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000868}
869
870/*
871 * ecm_tracker_ip_header_helper_icmp()
872 * Interpret a ICMP V4 header
873 */
874static bool ecm_tracker_ip_header_helper_icmp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
875 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
876{
877 struct icmphdr icmp_header_buffer;
878 struct icmphdr *icmp_header;
879
880 DEBUG_ASSERT((protocol == IPPROTO_ICMP) && (ecm_ip_protocol == ECM_TRACKER_IP_PROTOCOL_TYPE_ICMP), "Bad protocol: %u or ecm_ip_protocol: %d", protocol, ecm_ip_protocol);
881
882 if (remain < 8) {
883 return false;
884 }
885
886 icmp_header = skb_header_pointer(skb, offset, sizeof(struct icmphdr), &icmp_header_buffer);
887 if (!icmp_header) {
888 return false;
889 }
890 switch(icmp_header->type) {
891 case ICMP_SOURCE_QUENCH:
892 case ICMP_REDIRECT:
893 case ICMP_TIME_EXCEEDED:
894 case ICMP_DEST_UNREACH:
895 /*
896 * Should be at least our 8 bytes and minimum 20 bytes for an IP header.
897 * NOTE: We are not looking at options that extend this header!
898 */
899 if (remain < 28) {
900 DEBUG_WARN("icmp skb: %p type: %u too small: %u\n", skb, icmp_header->type, remain);
901 return false;
902 }
903 etiph->header_size = 8;
904 etiph->size = remain;
905 break;
906
907 case ICMP_ADDRESS:
908 case ICMP_ADDRESSREPLY:
909 case ICMP_TIMESTAMP:
910 if (remain < 12) {
911 DEBUG_WARN("icmp skb: %p type: %u too small: %u\n", skb, icmp_header->type, remain);
912 return false;
913 }
914 etiph->header_size = 12;
915 etiph->size = remain;
916 break;
917 case ICMP_TIMESTAMPREPLY:
918 if (remain < 20) {
919 DEBUG_WARN("icmp skb: %p type: %u too small: %u\n", skb, icmp_header->type, remain);
920 return false;
921 }
922 etiph->header_size = 20;
923 etiph->size = remain;
924 break;
925 case ICMP_PARAMETERPROB:
926 case ICMP_INFO_REQUEST:
927 case ICMP_INFO_REPLY:
928 default:
929 etiph->header_size = 8;
930 etiph->size = remain;
931 }
932 etiph->protocol_number = protocol;
933 etiph->offset = offset;
934
935 /*
936 * There is no header following a ICMP header
937 */
938 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500939 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000940}
941
942/*
943 * ecm_tracker_ip_header_helper_ipv6_icmp()
944 * Interpret a ICMP V6 header
945 */
946static bool ecm_tracker_ip_header_helper_ipv6_icmp(struct ecm_tracker_ip_protocols *etip, struct ecm_tracker_ip_protocol_header *etiph, struct ecm_tracker_ip_header *ip_hdr,
947 struct sk_buff *skb, uint8_t protocol, ecm_tracker_ip_protocol_type_t ecm_ip_protocol, uint32_t offset, uint32_t remain, int16_t *next_hdr)
948{
949 if (remain < 4) {
950 DEBUG_WARN("v6 icmp: %p too small: %u\n", skb, remain);
951 return false;
952 }
953
954 etiph->protocol_number = protocol;
955 etiph->header_size = 4;
956 etiph->size = remain;
957 etiph->offset = offset;
958
959 /*
960 * There is no header following a V6 ICMP header
961 */
962 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500963 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000964}
965
966/*
967 * ecm_tracker_data_limit_set()
968 * Set global tracked data limit
969 */
970void ecm_tracker_data_limit_set(uint32_t limit)
971{
972 int data_limit = (int)limit;
973 DEBUG_ASSERT(data_limit > 0, "Invalid limit %d\n", data_limit);
974 spin_lock_bh(&ecm_tracker_lock);
975 ecm_tracker_data_limit = data_limit;
976 spin_unlock_bh(&ecm_tracker_lock);
977}
978EXPORT_SYMBOL(ecm_tracker_data_limit_set);
979
980/*
981 * ecm_tracker_data_limit_get()
982 * Return global tracked data limit
983 */
984uint32_t ecm_tracker_data_limit_get(void)
985{
986 uint32_t data_total;
987 spin_lock_bh(&ecm_tracker_lock);
988 data_total = (uint32_t)ecm_tracker_data_limit;
989 spin_unlock_bh(&ecm_tracker_lock);
990 return data_total;
991}
992EXPORT_SYMBOL(ecm_tracker_data_limit_get);
993
994/*
995 * ecm_tracker_data_total_get()
996 * Return global tracked data quantity
997 */
998uint32_t ecm_tracker_data_total_get(void)
999{
1000 uint32_t data_total;
1001 spin_lock_bh(&ecm_tracker_lock);
1002 data_total = (uint32_t)ecm_tracker_data_total;
1003 spin_unlock_bh(&ecm_tracker_lock);
1004 return data_total;
1005}
1006EXPORT_SYMBOL(ecm_tracker_data_total_get);
1007
1008/*
1009 * ecm_tracker_data_buffer_total_get()
1010 * Return global tracked data buffer size
1011 */
1012uint32_t ecm_tracker_data_buffer_total_get(void)
1013{
1014 uint32_t data_buffer_total;
1015 spin_lock_bh(&ecm_tracker_lock);
1016 data_buffer_total = (uint32_t)ecm_tracker_data_buffer_total;
1017 spin_unlock_bh(&ecm_tracker_lock);
1018 return data_buffer_total;
1019}
1020EXPORT_SYMBOL(ecm_tracker_data_buffer_total_get);
1021
1022/*
1023 * ecm_tracker_data_total_increase()
1024 * Increase global tracked data quantity
1025 *
1026 * If this function returns false then the increase has been denied and tracking of that data should not occur.
1027 * Therefore call this function BEFORE tracking the actual data.
1028 */
1029bool ecm_tracker_data_total_increase(uint32_t n, uint32_t data_buffer_size)
1030{
1031 spin_lock_bh(&ecm_tracker_lock);
1032
1033 /*
1034 * Would we exceed our global limit?
1035 */
1036 DEBUG_ASSERT((ecm_tracker_data_total + (int)n) > 0, "bad total\n");
1037 if (((ecm_tracker_data_buffer_total + data_buffer_size) > ecm_tracker_data_buffer_limit)
1038 || ((ecm_tracker_data_total + n) > ecm_tracker_data_limit)) {
1039 spin_unlock_bh(&ecm_tracker_lock);
1040 return false;
1041 }
1042 ecm_tracker_data_buffer_total += data_buffer_size;
1043 ecm_tracker_data_total += (int)n;
1044 spin_unlock_bh(&ecm_tracker_lock);
1045 return true;
1046}
1047EXPORT_SYMBOL(ecm_tracker_data_total_increase);
1048
1049/*
1050 * ecm_tracker_data_total_decrease()
1051 * Decrease global tracked data quantity
1052 */
1053void ecm_tracker_data_total_decrease(uint32_t n, uint32_t data_buffer_size)
1054{
1055 spin_lock_bh(&ecm_tracker_lock);
1056 ecm_tracker_data_total -= (int)n;
1057 ecm_tracker_data_buffer_total -= data_buffer_size;
1058 DEBUG_ASSERT(ecm_tracker_data_total >= 0, "bad total\n");
1059 DEBUG_ASSERT(ecm_tracker_data_buffer_total >= 0, "bad total\n");
1060 spin_unlock_bh(&ecm_tracker_lock);
1061}
1062EXPORT_SYMBOL(ecm_tracker_data_total_decrease);
1063
1064/*
1065 * ecm_tracker_module_get()
1066 * Take a reference to the module
1067 */
1068void ecm_tracker_module_get(void)
1069{
1070 try_module_get(THIS_MODULE);
1071}
1072EXPORT_SYMBOL(ecm_tracker_module_get);
1073
1074/*
1075 * ecm_tracker_module_put()
1076 * Release a reference to the module
1077 */
1078void ecm_tracker_module_put(void)
1079{
1080 module_put(THIS_MODULE);
1081}
1082EXPORT_SYMBOL(ecm_tracker_module_put);
1083
Nicolas Costa1d9eb992014-05-15 10:01:03 -05001084const char *
1085ecm_tracker_sender_state_to_string(enum ecm_tracker_sender_states s)
1086{
1087 return ecm_tracker_sender_state_strings[s];
1088}
1089EXPORT_SYMBOL(ecm_tracker_sender_state_to_string);
1090
1091const char *
1092ecm_tracker_connection_state_to_string(enum ecm_tracker_connection_states s)
1093{
1094 return ecm_tracker_connection_state_strings[s];
1095}
1096EXPORT_SYMBOL(ecm_tracker_connection_state_to_string);
1097
Ben Menchaca84f36632014-02-28 20:57:38 +00001098/*
1099 * ecm_tracker_init()
1100 */
Nicolas Costaf46c33b2014-05-15 10:02:00 -05001101int ecm_tracker_init(void)
Ben Menchaca84f36632014-02-28 20:57:38 +00001102{
1103 DEBUG_INFO("Tracker Module init\n");
1104 spin_lock_init(&ecm_tracker_lock);
1105 return 0;
1106}
Nicolas Costaf46c33b2014-05-15 10:02:00 -05001107EXPORT_SYMBOL(ecm_tracker_init);
Ben Menchaca84f36632014-02-28 20:57:38 +00001108
1109/*
1110 * ecm_tracker_exit()
1111 */
Nicolas Costaf46c33b2014-05-15 10:02:00 -05001112void ecm_tracker_exit(void)
Ben Menchaca84f36632014-02-28 20:57:38 +00001113{
1114 DEBUG_INFO("Tracker Module exit\n");
1115}
Nicolas Costaf46c33b2014-05-15 10:02:00 -05001116EXPORT_SYMBOL(ecm_tracker_exit);