blob: a057799600aa9978e4fac6a9c51f92160aca72e2 [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>
25#include <linux/sysdev.h>
26#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{
383 struct iphdr *v4_hdr;
384 struct ipv6hdr *v6_hdr;
385 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 /*
447 * Get the protocol and where the header info will be stored
448 */
449 protocol = v4_hdr->protocol;
450 ip_hdr->protocol = (int)v4_hdr->protocol;
451 etip = &ecm_tracker_ip_protocols_known[protocol]; /* Get header helper */
452 ecm_ip_protocol = etip->ecm_ip_protocol;
453 etiph = &ip_hdr->headers[ecm_ip_protocol]; /* Get where the header detail is stored in ip_hdr->headers[] */
454
455 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: "
456 ECM_IP_ADDR_DOT_FMT ", dest addr: " ECM_IP_ADDR_DOT_FMT "\n",
457 ip_hdr,
458 skb,
459 skb->len,
460 ip_hdr->ip_header_length,
461 ip_hdr->total_length,
462 remain,
463 ip_hdr->fragmented,
464 ip_hdr->protocol,
465 ecm_ip_protocol,
466 ECM_IP_ADDR_TO_DOT(ip_hdr->src_addr),
467 ECM_IP_ADDR_TO_DOT(ip_hdr->dest_addr));
468
469 /*
470 * Populate protocol detail
471 * IPv4 can only have one.
472 */
473 if (!etip->header_helper(
474 etip,
475 etiph,
476 ip_hdr,
477 skb,
478 (uint8_t)ip_hdr->protocol,
479 ecm_ip_protocol,
480 ip_hdr->ip_header_length,
481 remain,
482 &next_unused)) {
483 DEBUG_WARN("%p: v4 header helper failed for: %u\n", skb, protocol);
484 return false;
485 }
Nicolas Costa585002e2014-05-15 09:46:04 -0500486
Ben Menchaca84f36632014-02-28 20:57:38 +0000487 return true;
488 }
489
490 /*
491 * IPv6
492 */
493 ECM_NIN6_ADDR_TO_IP_ADDR(ip_hdr->src_addr, v6_hdr->saddr);
494 ECM_NIN6_ADDR_TO_IP_ADDR(ip_hdr->dest_addr, v6_hdr->daddr);
495 ip_hdr->ip_header_length = 40;
496 remain = ntohs(v6_hdr->payload_len);
497 ip_hdr->total_length = remain + 40;
498 if (skb->len < ip_hdr->total_length) {
499 DEBUG_WARN("%p: v6 invalid total len: %u skb len: %u\n", skb, ip_hdr->total_length, skb->len);
500 return false;
501 }
502
503 /*
504 * Process headers until we run out of space, error, or we get the no next header marker for v6 (protocol 59).
505 */
506 offset = 40;
507 this_header = (int16_t)v6_hdr->nexthdr;
508 while ((remain > 0) && (this_header >= 0) && (this_header != 59)) {
509 struct ecm_tracker_ip_protocols *etip;
510 struct ecm_tracker_ip_protocol_header *etiph;
511 ecm_tracker_ip_protocol_type_t ecm_ip_protocol;
512 int16_t next_header;
513
514 etip = &ecm_tracker_ip_protocols_known[this_header]; /* Get header helper */
515 ecm_ip_protocol = etip->ecm_ip_protocol;
516 etiph = &ip_hdr->headers[ecm_ip_protocol]; /* Get where the header detail is stored in ip_hdr->headers[] */
517
518 /*
519 * If this IP header has already been seen then we abort
520 */
521 if (etiph->size) {
522 DEBUG_WARN("v6 skb: %p, protocol: %d already seen at offset: %u, size: %u\n",
523 skb, this_header, etiph->offset, etiph->size);
524 return false;
525 }
526 if (!etip->header_helper(
527 etip,
528 etiph,
529 ip_hdr,
530 skb,
531 (uint8_t)this_header,
532 ecm_ip_protocol,
533 offset,
534 remain,
535 &next_header)) {
536 DEBUG_WARN("%p: v6 header helper failed for: %d\n", skb, this_header);
537 return false;
538 }
539
540 offset += etiph->size;
541 DEBUG_ASSERT(remain >= etiph->size, "v6 remain: %u goes negative after header size: %u", remain, etiph->size);
542 remain -= etiph->size;
543
544 this_header = next_header;
545 }
546
547 /*
548 * Generally the last protocol seen is the upper layer protocol
549 */
550 ip_hdr->protocol = (int)this_header;
551
552 return ip_hdr;
553}
554EXPORT_SYMBOL(ecm_tracker_ip_check_header_and_read);
555
556/*
557 * ecm_tracker_ip_header_helper_ipv6_generic()
558 * Interpret a Generic IPv6 extension header
559 */
560static 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,
561 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)
562{
563 struct ipv6_gen_hdr {
564 uint8_t next_protocol;
565 uint8_t header_ext_len;
566 } gen_header_buffer;
567 struct ipv6_gen_hdr *gen_header;
568 uint16_t hdr_size;
569
570 /*
571 * At least 8 bytes
572 */
573 if (remain < 8) {
574 return false;
575 }
576
577 gen_header = skb_header_pointer(skb, offset, sizeof(struct ipv6_gen_hdr), &gen_header_buffer);
578 if (!gen_header) {
579 return false;
580 }
581 hdr_size = gen_header->header_ext_len;
582 hdr_size <<= 3;
583 hdr_size += 8;
584 if (remain < hdr_size) {
585 DEBUG_WARN("IPv6 extension: %p packet remain: %u too small for tcp header: %u\n", skb, remain, hdr_size);
586 return false;
587 }
588 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
589 DEBUG_WARN("TCP packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
590 return false;
591 }
592
593 etiph->protocol_number = protocol;
594 etiph->header_size = hdr_size;
595 etiph->size = hdr_size;
596 etiph->offset = offset;
597
598 *next_hdr = (int16_t)gen_header->next_protocol;
Nicolas Costa585002e2014-05-15 09:46:04 -0500599 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000600}
601
602/*
603 * ecm_tracker_ip_header_helper_ipv6_fragment()
604 * Interpret a Generic IPv6 fragment header
605 */
606static 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,
607 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)
608{
609 struct ipv6_gen_hdr {
610 uint8_t next_protocol;
611 uint8_t reserved;
612 } gen_header_buffer;
613 struct ipv6_gen_hdr *gen_header;
614
615 /*
616 * At least 8 bytes
617 */
618 if (remain < 8) {
619 return false;
620 }
621
622 gen_header = skb_header_pointer(skb, offset, sizeof(struct ipv6_gen_hdr), &gen_header_buffer);
623 if (!gen_header) {
624 return false;
625 }
626 if (unlikely(ip_hdr->total_length < (offset + 8))) {
627 DEBUG_WARN("TCP packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + 8);
628 return false;
629 }
630
631 /*
632 * The very presence of a fragmemt header says it's fragmented
633 */
634 ip_hdr->fragmented = true;
635
636 etiph->protocol_number = protocol;
637 etiph->header_size = 8;
638 etiph->size = 8;
639 etiph->offset = offset;
640
641 *next_hdr = (int16_t)gen_header->next_protocol;
Nicolas Costa585002e2014-05-15 09:46:04 -0500642 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000643}
644
645/*
646 * ecm_tracker_ip_header_helper_tcp()
647 * Interpret a TCP header
648 */
649static 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,
650 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)
651{
652 struct tcphdr tcp_header_buffer;
653 struct tcphdr *tcp_header;
654 uint16_t hdr_size;
655
656 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);
657
658 if (remain < 20) {
659 return false;
660 }
661
662 tcp_header = skb_header_pointer(skb, offset, sizeof(struct tcphdr), &tcp_header_buffer);
663 if (!tcp_header) {
664 return false;
665 }
666 hdr_size = tcp_header->doff;
667 hdr_size <<= 2;
668 if (hdr_size < 20) {
669 return false;
670 }
671 if (remain < hdr_size) {
672 DEBUG_WARN("TCP packet: %p packet remain: %u too small for tcp header: %u\n", skb, remain, hdr_size);
673 return false;
674 }
675 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
676 DEBUG_WARN("TCP packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
677 return false;
678 }
679
680 etiph->protocol_number = protocol;
681 etiph->header_size = hdr_size;
682 etiph->size = remain;
683 etiph->offset = offset;
684
685 /*
686 * There is no header following a TCP header
687 */
688 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500689 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000690}
691
692/*
693 * ecm_tracker_ip_header_helper_gre()
694 * Interpret a GRE header
695 */
696static 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,
697 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)
698{
699 uint32_t gre_hdr_buffer;
700 uint32_t *gre_hdr_ptr;
701 uint32_t gre_hdr;
702 uint16_t hdr_size;
703
704 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);
705
706 if (remain < 4) {
707 return false;
708 }
709
710 gre_hdr_ptr = skb_header_pointer(skb, offset, sizeof(gre_hdr_buffer), &gre_hdr_buffer);
711 if (!gre_hdr_ptr) {
712 return false;
713 }
714 gre_hdr = ntohl(*gre_hdr_ptr);
715 hdr_size = 4;
716 if (gre_hdr & 0x80000000) {
717 /*
718 * Checksum
719 */
720 hdr_size += 4;
721 }
722 if (gre_hdr & 0x20000000) {
723 /*
724 * Key
725 */
726 hdr_size += 4;
727 }
728 if (gre_hdr & 0x10000000) {
729 /*
730 * Sequence
731 */
732 hdr_size += 4;
733 }
734 if (remain < hdr_size) {
735 DEBUG_WARN("GRE packet: %p packet remain: %u too small for tcp header: %u\n", skb, remain, hdr_size);
736 return false;
737 }
738 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
739 DEBUG_WARN("GRE packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
740 return false;
741 }
742
743 etiph->protocol_number = protocol;
744 etiph->header_size = hdr_size;
745 etiph->size = remain;
746 etiph->offset = offset;
747
748 /*
749 * There is no header following a GRE header
750 */
751 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500752 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000753}
754
755/*
756 * ecm_tracker_ip_header_helper_ah()
757 * Interpret an Authentication Header
758 */
759static 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,
760 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)
761{
762 struct ah_gen_hdr {
763 uint8_t next_protocol;
764 uint8_t header_len;
765 } gen_header_buffer;
766 struct ah_gen_hdr *gen_header;
767 uint16_t hdr_size;
768
769 /*
770 * At least 8 bytes
771 */
772 if (remain < 8) {
773 return false;
774 }
775
776 gen_header = skb_header_pointer(skb, offset, sizeof(struct ah_gen_hdr), &gen_header_buffer);
777 if (!gen_header) {
778 return false;
779 }
780
781 hdr_size = gen_header->header_len + 2;
782 hdr_size <<= 2;
783
784 if (!ip_hdr->is_v4) {
785 /*
786 * hdr_size needs to be a multiple of 8 in a v6 frame
787 */
788 if (hdr_size % 8) {
789 DEBUG_WARN("AH packet %p not multiple of 8 for v6 frame: %u\n", skb, hdr_size);
790 return false;
791 }
792 }
793
794 if (remain < hdr_size) {
795 DEBUG_WARN("AH packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
796 return false;
797 }
798 if (unlikely(ip_hdr->total_length < (offset + hdr_size))) {
799 DEBUG_WARN("AH packet %p too short (total_length: %u, require: %u)\n", skb, ip_hdr->total_length, offset + hdr_size);
800 return false;
801 }
802
803 /*
804 * What header follows this one?
805 */
806 *next_hdr = gen_header->next_protocol;
807
808 etiph->protocol_number = protocol;
809 etiph->header_size = hdr_size;
810 etiph->size = hdr_size;
811 etiph->offset = offset;
Nicolas Costa585002e2014-05-15 09:46:04 -0500812 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000813}
814
815/*
816 * ecm_tracker_ip_header_helper_udp()
817 * Interpret a UDP header
818 */
819static 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,
820 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)
821{
822 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);
823
824 DEBUG_TRACE("udp helper skb: %p, protocol: %u, ecm_ip_proto: %d, offset: %u, remain: %u\n", skb, protocol, ecm_ip_protocol, offset, remain);
825 if (remain < 8) {
826 DEBUG_TRACE("not enough UDP header: %u\n", remain);
827 return false;
828 }
829
830 etiph->protocol_number = protocol;
831 etiph->header_size = 8;
832 etiph->size = remain;
833 etiph->offset = offset;
834
835 /*
836 * There is no header following a UDP header
837 */
838 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500839 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000840}
841
842/*
843 * ecm_tracker_ip_header_helper_unknown()
844 * Interpret a unknown header
845 */
846static 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,
847 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)
848{
849 /*
850 * There is no header following an unknown header
851 */
852 *next_hdr = -1;
853 etiph->protocol_number = protocol;
854 etiph->header_size = remain;
855 etiph->size = remain;
856 etiph->offset = offset;
Nicolas Costa585002e2014-05-15 09:46:04 -0500857 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000858}
859
860/*
861 * ecm_tracker_ip_header_helper_icmp()
862 * Interpret a ICMP V4 header
863 */
864static 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,
865 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)
866{
867 struct icmphdr icmp_header_buffer;
868 struct icmphdr *icmp_header;
869
870 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);
871
872 if (remain < 8) {
873 return false;
874 }
875
876 icmp_header = skb_header_pointer(skb, offset, sizeof(struct icmphdr), &icmp_header_buffer);
877 if (!icmp_header) {
878 return false;
879 }
880 switch(icmp_header->type) {
881 case ICMP_SOURCE_QUENCH:
882 case ICMP_REDIRECT:
883 case ICMP_TIME_EXCEEDED:
884 case ICMP_DEST_UNREACH:
885 /*
886 * Should be at least our 8 bytes and minimum 20 bytes for an IP header.
887 * NOTE: We are not looking at options that extend this header!
888 */
889 if (remain < 28) {
890 DEBUG_WARN("icmp skb: %p type: %u too small: %u\n", skb, icmp_header->type, remain);
891 return false;
892 }
893 etiph->header_size = 8;
894 etiph->size = remain;
895 break;
896
897 case ICMP_ADDRESS:
898 case ICMP_ADDRESSREPLY:
899 case ICMP_TIMESTAMP:
900 if (remain < 12) {
901 DEBUG_WARN("icmp skb: %p type: %u too small: %u\n", skb, icmp_header->type, remain);
902 return false;
903 }
904 etiph->header_size = 12;
905 etiph->size = remain;
906 break;
907 case ICMP_TIMESTAMPREPLY:
908 if (remain < 20) {
909 DEBUG_WARN("icmp skb: %p type: %u too small: %u\n", skb, icmp_header->type, remain);
910 return false;
911 }
912 etiph->header_size = 20;
913 etiph->size = remain;
914 break;
915 case ICMP_PARAMETERPROB:
916 case ICMP_INFO_REQUEST:
917 case ICMP_INFO_REPLY:
918 default:
919 etiph->header_size = 8;
920 etiph->size = remain;
921 }
922 etiph->protocol_number = protocol;
923 etiph->offset = offset;
924
925 /*
926 * There is no header following a ICMP header
927 */
928 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500929 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000930}
931
932/*
933 * ecm_tracker_ip_header_helper_ipv6_icmp()
934 * Interpret a ICMP V6 header
935 */
936static 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,
937 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)
938{
939 if (remain < 4) {
940 DEBUG_WARN("v6 icmp: %p too small: %u\n", skb, remain);
941 return false;
942 }
943
944 etiph->protocol_number = protocol;
945 etiph->header_size = 4;
946 etiph->size = remain;
947 etiph->offset = offset;
948
949 /*
950 * There is no header following a V6 ICMP header
951 */
952 *next_hdr = -1;
Nicolas Costa585002e2014-05-15 09:46:04 -0500953 return true;
Ben Menchaca84f36632014-02-28 20:57:38 +0000954}
955
956/*
957 * ecm_tracker_data_limit_set()
958 * Set global tracked data limit
959 */
960void ecm_tracker_data_limit_set(uint32_t limit)
961{
962 int data_limit = (int)limit;
963 DEBUG_ASSERT(data_limit > 0, "Invalid limit %d\n", data_limit);
964 spin_lock_bh(&ecm_tracker_lock);
965 ecm_tracker_data_limit = data_limit;
966 spin_unlock_bh(&ecm_tracker_lock);
967}
968EXPORT_SYMBOL(ecm_tracker_data_limit_set);
969
970/*
971 * ecm_tracker_data_limit_get()
972 * Return global tracked data limit
973 */
974uint32_t ecm_tracker_data_limit_get(void)
975{
976 uint32_t data_total;
977 spin_lock_bh(&ecm_tracker_lock);
978 data_total = (uint32_t)ecm_tracker_data_limit;
979 spin_unlock_bh(&ecm_tracker_lock);
980 return data_total;
981}
982EXPORT_SYMBOL(ecm_tracker_data_limit_get);
983
984/*
985 * ecm_tracker_data_total_get()
986 * Return global tracked data quantity
987 */
988uint32_t ecm_tracker_data_total_get(void)
989{
990 uint32_t data_total;
991 spin_lock_bh(&ecm_tracker_lock);
992 data_total = (uint32_t)ecm_tracker_data_total;
993 spin_unlock_bh(&ecm_tracker_lock);
994 return data_total;
995}
996EXPORT_SYMBOL(ecm_tracker_data_total_get);
997
998/*
999 * ecm_tracker_data_buffer_total_get()
1000 * Return global tracked data buffer size
1001 */
1002uint32_t ecm_tracker_data_buffer_total_get(void)
1003{
1004 uint32_t data_buffer_total;
1005 spin_lock_bh(&ecm_tracker_lock);
1006 data_buffer_total = (uint32_t)ecm_tracker_data_buffer_total;
1007 spin_unlock_bh(&ecm_tracker_lock);
1008 return data_buffer_total;
1009}
1010EXPORT_SYMBOL(ecm_tracker_data_buffer_total_get);
1011
1012/*
1013 * ecm_tracker_data_total_increase()
1014 * Increase global tracked data quantity
1015 *
1016 * If this function returns false then the increase has been denied and tracking of that data should not occur.
1017 * Therefore call this function BEFORE tracking the actual data.
1018 */
1019bool ecm_tracker_data_total_increase(uint32_t n, uint32_t data_buffer_size)
1020{
1021 spin_lock_bh(&ecm_tracker_lock);
1022
1023 /*
1024 * Would we exceed our global limit?
1025 */
1026 DEBUG_ASSERT((ecm_tracker_data_total + (int)n) > 0, "bad total\n");
1027 if (((ecm_tracker_data_buffer_total + data_buffer_size) > ecm_tracker_data_buffer_limit)
1028 || ((ecm_tracker_data_total + n) > ecm_tracker_data_limit)) {
1029 spin_unlock_bh(&ecm_tracker_lock);
1030 return false;
1031 }
1032 ecm_tracker_data_buffer_total += data_buffer_size;
1033 ecm_tracker_data_total += (int)n;
1034 spin_unlock_bh(&ecm_tracker_lock);
1035 return true;
1036}
1037EXPORT_SYMBOL(ecm_tracker_data_total_increase);
1038
1039/*
1040 * ecm_tracker_data_total_decrease()
1041 * Decrease global tracked data quantity
1042 */
1043void ecm_tracker_data_total_decrease(uint32_t n, uint32_t data_buffer_size)
1044{
1045 spin_lock_bh(&ecm_tracker_lock);
1046 ecm_tracker_data_total -= (int)n;
1047 ecm_tracker_data_buffer_total -= data_buffer_size;
1048 DEBUG_ASSERT(ecm_tracker_data_total >= 0, "bad total\n");
1049 DEBUG_ASSERT(ecm_tracker_data_buffer_total >= 0, "bad total\n");
1050 spin_unlock_bh(&ecm_tracker_lock);
1051}
1052EXPORT_SYMBOL(ecm_tracker_data_total_decrease);
1053
1054/*
1055 * ecm_tracker_module_get()
1056 * Take a reference to the module
1057 */
1058void ecm_tracker_module_get(void)
1059{
1060 try_module_get(THIS_MODULE);
1061}
1062EXPORT_SYMBOL(ecm_tracker_module_get);
1063
1064/*
1065 * ecm_tracker_module_put()
1066 * Release a reference to the module
1067 */
1068void ecm_tracker_module_put(void)
1069{
1070 module_put(THIS_MODULE);
1071}
1072EXPORT_SYMBOL(ecm_tracker_module_put);
1073
Nicolas Costa1d9eb992014-05-15 10:01:03 -05001074const char *
1075ecm_tracker_sender_state_to_string(enum ecm_tracker_sender_states s)
1076{
1077 return ecm_tracker_sender_state_strings[s];
1078}
1079EXPORT_SYMBOL(ecm_tracker_sender_state_to_string);
1080
1081const char *
1082ecm_tracker_connection_state_to_string(enum ecm_tracker_connection_states s)
1083{
1084 return ecm_tracker_connection_state_strings[s];
1085}
1086EXPORT_SYMBOL(ecm_tracker_connection_state_to_string);
1087
Ben Menchaca84f36632014-02-28 20:57:38 +00001088/*
1089 * ecm_tracker_init()
1090 */
1091static int __init ecm_tracker_init(void)
1092{
1093 DEBUG_INFO("Tracker Module init\n");
1094 spin_lock_init(&ecm_tracker_lock);
1095 return 0;
1096}
1097
1098/*
1099 * ecm_tracker_exit()
1100 */
1101static void __exit ecm_tracker_exit(void)
1102{
1103 DEBUG_INFO("Tracker Module exit\n");
1104}
1105
1106module_init(ecm_tracker_init)
1107module_exit(ecm_tracker_exit)
1108
1109MODULE_AUTHOR("Qualcomm Atheros, Inc.");
1110MODULE_DESCRIPTION("ECM Tracker");
1111#ifdef MODULE_LICENSE
1112MODULE_LICENSE("Dual BSD/GPL");
1113#endif
1114