suricata
detect-engine-address-ipv6.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * IPV6 Address part of the detection engine.
24  */
25 
26 #include "suricata-common.h"
27 
28 #include "decode.h"
29 #include "detect.h"
30 #include "flow-var.h"
31 
32 #include "util-cidr.h"
33 #include "util-unittest.h"
34 
35 #include "detect-engine-address.h"
37 #include "detect-engine-siggroup.h"
38 #include "detect-engine-port.h"
39 
40 #include "util-debug.h"
41 
42 /**
43  * \brief Compares 2 ipv6 addresses and returns if the first address(a) is less
44  * than the second address(b) or not.
45  *
46  * \param a The first ipv6 address to be compared.
47  * \param b The second ipv6 address to be compared.
48  *
49  * \retval 1 If a < b.
50  * \retval 0 Otherwise, i.e. a >= b.
51  */
52 int AddressIPv6Lt(const Address *a, const Address *b)
53 {
54  int i = 0;
55 
56  for (i = 0; i < 4; i++) {
57  if (SCNtohl(a->addr_data32[i]) < SCNtohl(b->addr_data32[i]))
58  return 1;
59  if (SCNtohl(a->addr_data32[i]) > SCNtohl(b->addr_data32[i]))
60  break;
61  }
62 
63  return 0;
64 }
65 
66 int AddressIPv6LtU32(uint32_t *a, uint32_t *b)
67 {
68  int i = 0;
69 
70  for (i = 0; i < 4; i++) {
71  if (SCNtohl(a[i]) < SCNtohl(b[i]))
72  return 1;
73  if (SCNtohl(a[i]) > SCNtohl(b[i]))
74  break;
75  }
76 
77  return 0;
78 }
79 
80 /**
81  * \brief Compares 2 ipv6 addresses and returns if the first address(a) is
82  * greater than the second address(b) or not.
83  *
84  * \param a The first ipv6 address to be compared.
85  * \param b The second ipv6 address to be compared.
86  *
87  * \retval 1 If a > b.
88  * \retval 0 Otherwise, i.e. a <= b.
89  */
90 int AddressIPv6Gt(const Address *a, const Address *b)
91 {
92  int i = 0;
93 
94  for (i = 0; i < 4; i++) {
95  if (SCNtohl(a->addr_data32[i]) > SCNtohl(b->addr_data32[i]))
96  return 1;
97  if (SCNtohl(a->addr_data32[i]) < SCNtohl(b->addr_data32[i]))
98  break;
99  }
100 
101  return 0;
102 }
103 
104 int AddressIPv6GtU32(uint32_t *a, uint32_t *b)
105 {
106  int i = 0;
107 
108  for (i = 0; i < 4; i++) {
109  if (SCNtohl(a[i]) > SCNtohl(b[i]))
110  return 1;
111  if (SCNtohl(a[i]) < SCNtohl(b[i]))
112  break;
113  }
114 
115  return 0;
116 }
117 
118 /**
119  * \brief Compares 2 ipv6 addresses and returns if the addresses are equal
120  * or not.
121  *
122  * \param a The first ipv6 address to be compared.
123  * \param b The second ipv6 address to be compared.
124  *
125  * \retval 1 If a == b.
126  * \retval 0 Otherwise.
127  */
128 int AddressIPv6Eq(const Address *a, const Address *b)
129 {
130  int i = 0;
131 
132  for (i = 0; i < 4; i++) {
133  if (a->addr_data32[i] != b->addr_data32[i])
134  return 0;
135  }
136 
137  return 1;
138 }
139 
140 int AddressIPv6EqU32(uint32_t *a, uint32_t *b)
141 {
142  int i = 0;
143 
144  for (i = 0; i < 4; i++) {
145  if (a[i] != b[i])
146  return 0;
147  }
148 
149  return 1;
150 }
151 
152 /**
153  * \brief Compares 2 ipv6 addresses and returns if the first address(a) is less
154  * than or equal to the second address(b) or not.
155  *
156  * \param a The first ipv6 address to be compared.
157  * \param b The second ipv6 address to be compared.
158  *
159  * \retval 1 If a <= b.
160  * \retval 0 Otherwise, i.e. a > b.
161  */
162 int AddressIPv6Le(const Address *a, const Address *b)
163 {
164 
165  if (AddressIPv6Eq(a, b) == 1)
166  return 1;
167  if (AddressIPv6Lt(a, b) == 1)
168  return 1;
169 
170  return 0;
171 }
172 
173 int AddressIPv6LeU32(uint32_t *a, uint32_t *b)
174 {
175 
176  if (AddressIPv6EqU32(a, b) == 1)
177  return 1;
178  if (AddressIPv6LtU32(a, b) == 1)
179  return 1;
180 
181  return 0;
182 }
183 
184 /**
185  * \brief Compares 2 ipv6 addresses and returns if the first address(a) is
186  * greater than or equal to the second address(b) or not.
187  *
188  * \param a The first ipv6 address to be compared.
189  * \param b The second ipv6 address to be compared.
190  *
191  * \retval 1 If a >= b.
192  * \retval 0 Otherwise, i.e. a < b.
193  */
194 int AddressIPv6Ge(const Address *a, const Address *b)
195 {
196 
197  if (AddressIPv6Eq(a, b) == 1)
198  return 1;
199  if (AddressIPv6Gt(a, b) == 1)
200  return 1;
201 
202  return 0;
203 }
204 
205 int AddressIPv6GeU32(uint32_t *a, uint32_t *b)
206 {
207 
208  if (AddressIPv6EqU32(a, b) == 1)
209  return 1;
210  if (AddressIPv6GtU32(a, b) == 1)
211  return 1;
212 
213  return 0;
214 }
215 
216 /**
217  * \brief Compares 2 addresses(address ranges) and returns the relationship
218  * between the 2 addresses.
219  *
220  * \param a Pointer to the first address instance to be compared.
221  * \param b Pointer to the second address instance to be compared.
222  *
223  * \retval ADDRESS_EQ If the 2 address ranges a and b, are equal.
224  * \retval ADDRESS_ES b encapsulates a. b_ip1[...a_ip1...a_ip2...]b_ip2.
225  * \retval ADDRESS_EB a encapsulates b. a_ip1[...b_ip1....b_ip2...]a_ip2.
226  * \retval ADDRESS_LE a_ip1(...b_ip1==a_ip2...)b_ip2
227  * \retval ADDRESS_LT a_ip1(...b_ip1...a_ip2...)b_ip2
228  * \retval ADDRESS_GE b_ip1(...a_ip1==b_ip2...)a_ip2
229  * \retval ADDRESS_GT a_ip1 > b_ip2, i.e. the address range for 'a' starts only
230  * after the end of the address range for 'b'
231  */
233 {
234  if (AddressIPv6Eq(&a->ip, &b->ip) == 1 &&
235  AddressIPv6Eq(&a->ip2, &b->ip2) == 1) {
236  return ADDRESS_EQ;
237  } else if (AddressIPv6Ge(&a->ip, &b->ip) == 1 &&
238  AddressIPv6Le(&a->ip, &b->ip2) == 1 &&
239  AddressIPv6Le(&a->ip2, &b->ip2) == 1) {
240  return ADDRESS_ES;
241  } else if (AddressIPv6Le(&a->ip, &b->ip) == 1 &&
242  AddressIPv6Ge(&a->ip2, &b->ip2) == 1) {
243  return ADDRESS_EB;
244  } else if (AddressIPv6Lt(&a->ip, &b->ip) == 1 &&
245  AddressIPv6Lt(&a->ip2, &b->ip2) == 1 &&
246  AddressIPv6Ge(&a->ip2, &b->ip) == 1) {
247  return ADDRESS_LE;
248  } else if (AddressIPv6Lt(&a->ip, &b->ip) == 1 &&
249  AddressIPv6Lt(&a->ip2, &b->ip2) == 1) {
250  return ADDRESS_LT;
251  } else if (AddressIPv6Gt(&a->ip, &b->ip) == 1 &&
252  AddressIPv6Le(&a->ip, &b->ip2) == 1 &&
253  AddressIPv6Gt(&a->ip2, &b->ip2) == 1) {
254  return ADDRESS_GE;
255  } else if (AddressIPv6Gt(&a->ip, &b->ip2) == 1) {
256  return ADDRESS_GT;
257  } else {
258  /* should be unreachable */
259  SCLogDebug("Internal Error: should be unreachable\n");
260  }
261 
262  return ADDRESS_ER;
263 }
264 
265 /**
266  * \brief Takes an IPv6 address in a, and returns in b an IPv6 address which is
267  * one less than the IPv6 address in a. The address sent in a is in host
268  * order, and the address in b will be returned in network order!
269  *
270  * \param a Pointer to an IPv6 address in host order.
271  * \param b Pointer to an IPv6 address store in memory which has to be updated
272  * with the new address(a - 1).
273  */
274 static void AddressCutIPv6CopySubOne(uint32_t *a, uint32_t *b)
275 {
276  uint32_t t = a[3];
277 
278  b[0] = a[0];
279  b[1] = a[1];
280  b[2] = a[2];
281  b[3] = a[3];
282 
283  b[3]--;
284  if (b[3] > t) {
285  t = b[2];
286  b[2]--;
287  if (b[2] > t) {
288  t = b[1];
289  b[1]--;
290  if (b[1] > t)
291  b[0]--;
292  }
293  }
294 
295  b[0] = htonl(b[0]);
296  b[1] = htonl(b[1]);
297  b[2] = htonl(b[2]);
298  b[3] = htonl(b[3]);
299 }
300 
301 /**
302  * \brief Takes an IPv6 address in a, and returns in b an IPv6 address which is
303  * one more than the IPv6 address in a. The address sent in a is in host
304  * order, and the address in b will be returned in network order!
305  *
306  * \param a Pointer to an IPv6 address in host order.
307  * \param b Pointer to an IPv6 address store in memory which has to be updated
308  * with the new address(a + 1).
309  */
310 static void AddressCutIPv6CopyAddOne(uint32_t *a, uint32_t *b)
311 {
312  uint32_t t = a[3];
313 
314  b[0] = a[0];
315  b[1] = a[1];
316  b[2] = a[2];
317  b[3] = a[3];
318 
319  b[3]++;
320  if (b[3] < t) {
321  t = b[2];
322  b[2]++;
323  if (b[2] < t) {
324  t = b[1];
325  b[1]++;
326  if (b[1] < t)
327  b[0]++;
328  }
329  }
330 
331  b[0] = htonl(b[0]);
332  b[1] = htonl(b[1]);
333  b[2] = htonl(b[2]);
334  b[3] = htonl(b[3]);
335 }
336 
337 /**
338  * \brief Copies an IPv6 address in a to the b. The address in a is in host
339  * order and will be copied in network order to b!
340  *
341  * \param a Pointer to the IPv6 address to be copied.
342  * \param b Pointer to an IPv6 address in memory which will be updated with the
343  * address in a.
344  */
345 static void AddressCutIPv6Copy(uint32_t *a, uint32_t *b)
346 {
347  b[0] = htonl(a[0]);
348  b[1] = htonl(a[1]);
349  b[2] = htonl(a[2]);
350  b[3] = htonl(a[3]);
351 }
352 
355 {
356  uint32_t a_ip1[4] = { SCNtohl(a->ip.addr_data32[0]), SCNtohl(a->ip.addr_data32[1]),
357  SCNtohl(a->ip.addr_data32[2]), SCNtohl(a->ip.addr_data32[3]) };
358  uint32_t a_ip2[4] = { SCNtohl(a->ip2.addr_data32[0]), SCNtohl(a->ip2.addr_data32[1]),
359  SCNtohl(a->ip2.addr_data32[2]), SCNtohl(a->ip2.addr_data32[3]) };
360  uint32_t b_ip1[4] = { SCNtohl(b->ip.addr_data32[0]), SCNtohl(b->ip.addr_data32[1]),
361  SCNtohl(b->ip.addr_data32[2]), SCNtohl(b->ip.addr_data32[3]) };
362  uint32_t b_ip2[4] = { SCNtohl(b->ip2.addr_data32[0]), SCNtohl(b->ip2.addr_data32[1]),
363  SCNtohl(b->ip2.addr_data32[2]), SCNtohl(b->ip2.addr_data32[3]) };
364 
365  /* default to NULL */
366  *c = NULL;
367 
368  int r = DetectAddressCmpIPv6(a, b);
369  if (r != ADDRESS_ES && r != ADDRESS_EB && r != ADDRESS_LE && r != ADDRESS_GE) {
370  goto error;
371  }
372 
373  /* we have 3 parts: [aaa[abab]bbb]
374  * part a: a_ip1 <-> b_ip1 - 1
375  * part b: b_ip1 <-> a_ip2
376  * part c: a_ip2 + 1 <-> b_ip2
377  */
378  if (r == ADDRESS_LE) {
379  AddressCutIPv6Copy(a_ip1, a->ip.addr_data32);
380  AddressCutIPv6CopySubOne(b_ip1, a->ip2.addr_data32);
381 
382  AddressCutIPv6Copy(b_ip1, b->ip.addr_data32);
383  AddressCutIPv6Copy(a_ip2, b->ip2.addr_data32);
384 
385  DetectAddress *tmp_c;
386  tmp_c = DetectAddressInit();
387  if (tmp_c == NULL)
388  goto error;
389  tmp_c->ip.family = AF_INET6;
390 
391  AddressCutIPv6CopyAddOne(a_ip2, tmp_c->ip.addr_data32);
392  AddressCutIPv6Copy(b_ip2, tmp_c->ip2.addr_data32);
393 
394  *c = tmp_c;
395 
396  /* we have 3 parts: [bbb[baba]aaa]
397  * part a: b_ip1 <-> a_ip1 - 1
398  * part b: a_ip1 <-> b_ip2
399  * part c: b_ip2 + 1 <-> a_ip2
400  */
401  } else if (r == ADDRESS_GE) {
402  AddressCutIPv6Copy(b_ip1, a->ip.addr_data32);
403  AddressCutIPv6CopySubOne(a_ip1, a->ip2.addr_data32);
404 
405  AddressCutIPv6Copy(a_ip1, b->ip.addr_data32);
406  AddressCutIPv6Copy(b_ip2, b->ip2.addr_data32);
407 
408  DetectAddress *tmp_c;
409  tmp_c = DetectAddressInit();
410  if (tmp_c == NULL)
411  goto error;
412  tmp_c->ip.family = AF_INET6;
413 
414  AddressCutIPv6CopyAddOne(b_ip2, tmp_c->ip.addr_data32);
415  AddressCutIPv6Copy(a_ip2, tmp_c->ip2.addr_data32);
416  *c = tmp_c;
417 
418  /* we have 2 or three parts:
419  *
420  * 2 part: [[abab]bbb] or [bbb[baba]]
421  * part a: a_ip1 <-> a_ip2
422  * part b: a_ip2 + 1 <-> b_ip2
423  *
424  * part a: b_ip1 <-> a_ip1 - 1
425  * part b: a_ip1 <-> a_ip2
426  *
427  * 3 part [bbb[aaa]bbb]
428  * part a: b_ip1 <-> a_ip1 - 1
429  * part b: a_ip1 <-> a_ip2
430  * part c: a_ip2 + 1 <-> b_ip2
431  */
432  } else if (r == ADDRESS_ES) {
433  if (AddressIPv6EqU32(a_ip1, b_ip1) == 1) {
434  AddressCutIPv6Copy(a_ip1, a->ip.addr_data32);
435  AddressCutIPv6Copy(a_ip2, a->ip2.addr_data32);
436 
437  AddressCutIPv6CopyAddOne(a_ip2, b->ip.addr_data32);
438  AddressCutIPv6Copy(b_ip2, b->ip2.addr_data32);
439 
440  } else if (AddressIPv6EqU32(a_ip2, b_ip2) == 1) {
441  AddressCutIPv6Copy(b_ip1, a->ip.addr_data32);
442  AddressCutIPv6CopySubOne(a_ip1, a->ip2.addr_data32);
443 
444  AddressCutIPv6Copy(a_ip1, b->ip.addr_data32);
445  AddressCutIPv6Copy(a_ip2, b->ip2.addr_data32);
446 
447  } else {
448  AddressCutIPv6Copy(b_ip1, a->ip.addr_data32);
449  AddressCutIPv6CopySubOne(a_ip1, a->ip2.addr_data32);
450 
451  AddressCutIPv6Copy(a_ip1, b->ip.addr_data32);
452  AddressCutIPv6Copy(a_ip2, b->ip2.addr_data32);
453 
454  DetectAddress *tmp_c;
455  tmp_c = DetectAddressInit();
456  if (tmp_c == NULL) {
457  goto error;
458  }
459  tmp_c->ip.family = AF_INET6;
460  AddressCutIPv6CopyAddOne(a_ip2, tmp_c->ip.addr_data32);
461  AddressCutIPv6Copy(b_ip2, tmp_c->ip2.addr_data32);
462  *c = tmp_c;
463 
464  }
465  /* we have 2 or three parts:
466  *
467  * 2 part: [[baba]aaa] or [aaa[abab]]
468  * part a: b_ip1 <-> b_ip2
469  * part b: b_ip2 + 1 <-> a_ip2
470  *
471  * part a: a_ip1 <-> b_ip1 - 1
472  * part b: b_ip1 <-> b_ip2
473  *
474  * 3 part [aaa[bbb]aaa]
475  * part a: a_ip1 <-> b_ip2 - 1
476  * part b: b_ip1 <-> b_ip2
477  * part c: b_ip2 + 1 <-> a_ip2
478  */
479  } else if (r == ADDRESS_EB) {
480  if (AddressIPv6EqU32(a_ip1, b_ip1) == 1) {
481  AddressCutIPv6Copy(b_ip1, a->ip.addr_data32);
482  AddressCutIPv6Copy(b_ip2, a->ip2.addr_data32);
483 
484  AddressCutIPv6CopyAddOne(b_ip2, b->ip.addr_data32);
485  AddressCutIPv6Copy(a_ip2, b->ip2.addr_data32);
486  } else if (AddressIPv6EqU32(a_ip2, b_ip2) == 1) {
487  AddressCutIPv6Copy(a_ip1, a->ip.addr_data32);
488  AddressCutIPv6CopySubOne(b_ip1, a->ip2.addr_data32);
489 
490  AddressCutIPv6Copy(b_ip1, b->ip.addr_data32);
491  AddressCutIPv6Copy(b_ip2, b->ip2.addr_data32);
492  } else {
493  AddressCutIPv6Copy(a_ip1, a->ip.addr_data32);
494  AddressCutIPv6CopySubOne(b_ip1, a->ip2.addr_data32);
495 
496  AddressCutIPv6Copy(b_ip1, b->ip.addr_data32);
497  AddressCutIPv6Copy(b_ip2, b->ip2.addr_data32);
498 
499  DetectAddress *tmp_c;
500  tmp_c = DetectAddressInit();
501  if (tmp_c == NULL)
502  goto error;
503 
504  tmp_c->ip.family = AF_INET6;
505  AddressCutIPv6CopyAddOne(b_ip2, tmp_c->ip.addr_data32);
506  AddressCutIPv6Copy(a_ip2, tmp_c->ip2.addr_data32);
507  *c = tmp_c;
508  }
509  }
510 
511  return 0;
512 
513 error:
514  return -1;
515 }
516 
517 #if 0
518 int DetectAddressCutIPv6(DetectAddressData *a, DetectAddressData *b,
519  DetectAddressData **c)
520 {
521  uint32_t a_ip1[4] = { SCNtohl(a->ip[0]), SCNtohl(a->ip[1]),
522  SCNtohl(a->ip[2]), SCNtohl(a->ip[3]) };
523  uint32_t a_ip2[4] = { SCNtohl(a->ip2[0]), SCNtohl(a->ip2[1]),
524  SCNtohl(a->ip2[2]), SCNtohl(a->ip2[3]) };
525  uint32_t b_ip1[4] = { SCNtohl(b->ip[0]), SCNtohl(b->ip[1]),
526  SCNtohl(b->ip[2]), SCNtohl(b->ip[3]) };
527  uint32_t b_ip2[4] = { SCNtohl(b->ip2[0]), SCNtohl(b->ip2[1]),
528  SCNtohl(b->ip2[2]), SCNtohl(b->ip2[3]) };
529 
530  /* default to NULL */
531  *c = NULL;
532 
533  int r = DetectAddressCmpIPv6(a, b);
534  if (r != ADDRESS_ES && r != ADDRESS_EB && r != ADDRESS_LE && r != ADDRESS_GE) {
535  goto error;
536  }
537 
538  /* we have 3 parts: [aaa[abab]bbb]
539  * part a: a_ip1 <-> b_ip1 - 1
540  * part b: b_ip1 <-> a_ip2
541  * part c: a_ip2 + 1 <-> b_ip2
542  */
543  if (r == ADDRESS_LE) {
544  AddressCutIPv6Copy(a_ip1, a->ip);
545  AddressCutIPv6CopySubOne(b_ip1, a->ip2);
546 
547  AddressCutIPv6Copy(b_ip1, b->ip);
548  AddressCutIPv6Copy(a_ip2, b->ip2);
549 
550  DetectAddressData *tmp_c;
551  tmp_c = DetectAddressDataInit();
552  if (tmp_c == NULL)
553  goto error;
554  tmp_c->family = AF_INET6;
555 
556  AddressCutIPv6CopyAddOne(a_ip2, tmp_c->ip);
557  AddressCutIPv6Copy(b_ip2, tmp_c->ip2);
558 
559  *c = tmp_c;
560 
561  /* we have 3 parts: [bbb[baba]aaa]
562  * part a: b_ip1 <-> a_ip1 - 1
563  * part b: a_ip1 <-> b_ip2
564  * part c: b_ip2 + 1 <-> a_ip2
565  */
566  } else if (r == ADDRESS_GE) {
567  AddressCutIPv6Copy(b_ip1, a->ip);
568  AddressCutIPv6CopySubOne(a_ip1, a->ip2);
569 
570  AddressCutIPv6Copy(a_ip1, b->ip);
571  AddressCutIPv6Copy(b_ip2, b->ip2);
572 
573  DetectAddressData *tmp_c;
574  tmp_c = DetectAddressDataInit();
575  if (tmp_c == NULL)
576  goto error;
577  tmp_c->family = AF_INET6;
578 
579  AddressCutIPv6CopyAddOne(b_ip2, tmp_c->ip);
580  AddressCutIPv6Copy(a_ip2, tmp_c->ip2);
581 
582  *c = tmp_c;
583 
584  /* we have 2 or three parts:
585  *
586  * 2 part: [[abab]bbb] or [bbb[baba]]
587  * part a: a_ip1 <-> a_ip2
588  * part b: a_ip2 + 1 <-> b_ip2
589  *
590  * part a: b_ip1 <-> a_ip1 - 1
591  * part b: a_ip1 <-> a_ip2
592  *
593  * 3 part [bbb[aaa]bbb]
594  * part a: b_ip1 <-> a_ip1 - 1
595  * part b: a_ip1 <-> a_ip2
596  * part c: a_ip2 + 1 <-> b_ip2
597  */
598  } else if (r == ADDRESS_ES) {
599  if (AddressIPv6Eq(a_ip1,b_ip1) == 1) {
600  AddressCutIPv6Copy(a_ip1, a->ip);
601  AddressCutIPv6Copy(a_ip2, a->ip2);
602 
603  AddressCutIPv6CopyAddOne(a_ip2, b->ip);
604  AddressCutIPv6Copy(b_ip2, b->ip2);
605  } else if (AddressIPv6Eq(a_ip2, b_ip2) == 1) {
606  AddressCutIPv6Copy(b_ip1, a->ip);
607  AddressCutIPv6CopySubOne(a_ip1, a->ip2);
608 
609  AddressCutIPv6Copy(a_ip1, b->ip);
610  AddressCutIPv6Copy(a_ip2, b->ip2);
611  } else {
612  AddressCutIPv6Copy(b_ip1, a->ip);
613  AddressCutIPv6CopySubOne(a_ip1, a->ip2);
614 
615  AddressCutIPv6Copy(a_ip1, b->ip);
616  AddressCutIPv6Copy(a_ip2, b->ip2);
617 
618  DetectAddressData *tmp_c;
619  tmp_c = DetectAddressDataInit();
620  if (tmp_c == NULL)
621  goto error;
622 
623  tmp_c->family = AF_INET6;
624 
625  AddressCutIPv6CopyAddOne(a_ip2, tmp_c->ip);
626  AddressCutIPv6Copy(b_ip2, tmp_c->ip2);
627  *c = tmp_c;
628  }
629  /* we have 2 or three parts:
630  *
631  * 2 part: [[baba]aaa] or [aaa[abab]]
632  * part a: b_ip1 <-> b_ip2
633  * part b: b_ip2 + 1 <-> a_ip2
634  *
635  * part a: a_ip1 <-> b_ip1 - 1
636  * part b: b_ip1 <-> b_ip2
637  *
638  * 3 part [aaa[bbb]aaa]
639  * part a: a_ip1 <-> b_ip2 - 1
640  * part b: b_ip1 <-> b_ip2
641  * part c: b_ip2 + 1 <-> a_ip2
642  */
643  } else if (r == ADDRESS_EB) {
644  if (AddressIPv6Eq(a_ip1, b_ip1) == 1) {
645  AddressCutIPv6Copy(b_ip1, a->ip);
646  AddressCutIPv6Copy(b_ip2, a->ip2);
647 
648  AddressCutIPv6CopyAddOne(b_ip2, b->ip);
649  AddressCutIPv6Copy(a_ip2, b->ip2);
650  } else if (AddressIPv6Eq(a_ip2, b_ip2) == 1) {
651  AddressCutIPv6Copy(a_ip1, a->ip);
652  AddressCutIPv6CopySubOne(b_ip1, a->ip2);
653 
654  AddressCutIPv6Copy(b_ip1, b->ip);
655  AddressCutIPv6Copy(b_ip2, b->ip2);
656  } else {
657  AddressCutIPv6Copy(a_ip1, a->ip);
658  AddressCutIPv6CopySubOne(b_ip1, a->ip2);
659 
660  AddressCutIPv6Copy(b_ip1, b->ip);
661  AddressCutIPv6Copy(b_ip2, b->ip2);
662 
663  DetectAddressData *tmp_c;
664  tmp_c = DetectAddressDataInit();
665  if (tmp_c == NULL)
666  goto error;
667  tmp_c->family = AF_INET6;
668 
669  AddressCutIPv6CopyAddOne(b_ip2, tmp_c->ip);
670  AddressCutIPv6Copy(a_ip2, tmp_c->ip2);
671  *c = tmp_c;
672  }
673  }
674 
675  return 0;
676 
677 error:
678  return -1;
679 }
680 #endif
681 
682 /**
683  * \brief Cuts and returns an address range, which is the complement of the
684  * address range that is supplied as the argument.
685  *
686  * For example:
687  *
688  * If a = ::-2000::,
689  * then a = 2000::1-FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF and b = NULL
690  * If a = 2000::1-FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF,
691  * then a = ::-2000:: and b = NULL
692  * If a = 2000::1-20FF::2,
693  * then a = ::-2000:: and
694  * b = 20FF::3-FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
695  *
696  * \param a Pointer to an address range (DetectAddress) instance whose complement
697  * has to be returned in a and b.
698  * \param b Pointer to DetectAddress pointer, that will be supplied back with a
699  * new DetectAddress instance, if the complement demands so.
700  *
701  * \retval 0 On success.
702  * \retval -1 On failure.
703  */
705 {
706  uint32_t a_ip1[4] = { SCNtohl(a->ip.addr_data32[0]), SCNtohl(a->ip.addr_data32[1]),
707  SCNtohl(a->ip.addr_data32[2]), SCNtohl(a->ip.addr_data32[3]) };
708  uint32_t a_ip2[4] = { SCNtohl(a->ip2.addr_data32[0]), SCNtohl(a->ip2.addr_data32[1]),
709  SCNtohl(a->ip2.addr_data32[2]), SCNtohl(a->ip2.addr_data32[3]) };
710  uint32_t ip_nul[4] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 };
711  uint32_t ip_max[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
712 
713  /* default to NULL */
714  *b = NULL;
715 
716  if (!(a_ip1[0] == 0x00000000 && a_ip1[1] == 0x00000000 &&
717  a_ip1[2] == 0x00000000 && a_ip1[3] == 0x00000000) &&
718  !(a_ip2[0] == 0xFFFFFFFF && a_ip2[1] == 0xFFFFFFFF &&
719  a_ip2[2] == 0xFFFFFFFF && a_ip2[3] == 0xFFFFFFFF)) {
720  AddressCutIPv6Copy(ip_nul, a->ip.addr_data32);
721  AddressCutIPv6CopySubOne(a_ip1, a->ip2.addr_data32);
722 
723  DetectAddress *tmp_b = DetectAddressInit();
724  if (tmp_b == NULL)
725  goto error;
726 
727  tmp_b->ip.family = AF_INET6;
728  AddressCutIPv6CopyAddOne(a_ip2, tmp_b->ip.addr_data32);
729  AddressCutIPv6Copy(ip_max, tmp_b->ip2.addr_data32);
730  *b = tmp_b;
731  } else if ((a_ip1[0] == 0x00000000 && a_ip1[1] == 0x00000000 &&
732  a_ip1[2] == 0x00000000 && a_ip1[3] == 0x00000000) &&
733  !(a_ip2[0] == 0xFFFFFFFF && a_ip2[1] == 0xFFFFFFFF &&
734  a_ip2[2] == 0xFFFFFFFF && a_ip2[3] == 0xFFFFFFFF)) {
735  AddressCutIPv6CopyAddOne(a_ip2, a->ip.addr_data32);
736  AddressCutIPv6Copy(ip_max, a->ip2.addr_data32);
737  } else if (!(a_ip1[0] == 0x00000000 && a_ip1[1] == 0x00000000 &&
738  a_ip1[2] == 0x00000000 && a_ip1[3] == 0x00000000) &&
739  (a_ip2[0] == 0xFFFFFFFF && a_ip2[1] == 0xFFFFFFFF &&
740  a_ip2[2] == 0xFFFFFFFF && a_ip2[3] == 0xFFFFFFFF)) {
741  AddressCutIPv6Copy(ip_nul, a->ip.addr_data32);
742  AddressCutIPv6CopySubOne(a_ip1, a->ip2.addr_data32);
743  } else {
744  goto error;
745  }
746 
747  return 0;
748 
749 error:
750  return -1;
751 }
752 
753 
754 /***************************************Unittests******************************/
755 
756 #ifdef UNITTESTS
757 
758 static int AddressTestIPv6Gt01(void)
759 {
760  uint32_t a[4] = { 1, 2, 3, 4 };
761  uint32_t b[4] = { 0, 2, 3, 4 };
762 
763  FAIL_IF_NOT(AddressIPv6GtU32(a, b) == 1);
764  PASS;
765 }
766 
767 static int AddressTestIPv6Gt02(void)
768 {
769  uint32_t a[4] = { 0, 2, 3, 4 };
770  uint32_t b[4] = { 1, 2, 3, 4 };
771 
772  FAIL_IF_NOT(AddressIPv6GtU32(a, b) == 0);
773  PASS;
774 }
775 
776 static int AddressTestIPv6Gt03(void)
777 {
778  uint32_t a[4] = { 1, 2, 3, 4 };
779  uint32_t b[4] = { 1, 2, 3, 4 };
780 
781  FAIL_IF_NOT(AddressIPv6GtU32(a, b) == 0);
782  PASS;
783 }
784 
785 static int AddressTestIPv6Gt04(void)
786 {
787  uint32_t a[4] = { 1, 2, 3, 5 };
788  uint32_t b[4] = { 1, 2, 3, 4 };
789 
790  FAIL_IF_NOT(AddressIPv6GtU32(a, b) == 1);
791  PASS;
792 }
793 
794 static int AddressTestIPv6Lt01(void)
795 {
796  uint32_t a[4] = { 0, 2, 3, 4 };
797  uint32_t b[4] = { 1, 2, 3, 4 };
798 
799  FAIL_IF_NOT(AddressIPv6LtU32(a, b) == 1);
800  PASS;
801 }
802 
803 static int AddressTestIPv6Lt02(void)
804 {
805  uint32_t a[4] = { 1, 2, 3, 4 };
806  uint32_t b[4] = { 0, 2, 3, 4 };
807 
808  FAIL_IF_NOT(AddressIPv6LtU32(a, b) == 0);
809  PASS;
810 }
811 
812 static int AddressTestIPv6Lt03(void)
813 {
814  uint32_t a[4] = { 1, 2, 3, 4 };
815  uint32_t b[4] = { 1, 2, 3, 4 };
816 
817  FAIL_IF_NOT(AddressIPv6LtU32(a, b) == 0);
818  PASS;
819 }
820 
821 static int AddressTestIPv6Lt04(void)
822 {
823  uint32_t a[4] = { 1, 2, 3, 4 };
824  uint32_t b[4] = { 1, 2, 3, 5 };
825 
826  FAIL_IF_NOT(AddressIPv6LtU32(a, b) == 1);
827  PASS;
828 }
829 
830 static int AddressTestIPv6Eq01(void)
831 {
832  uint32_t a[4] = { 0, 2, 3, 4 };
833  uint32_t b[4] = { 1, 2, 3, 4 };
834 
835  FAIL_IF_NOT(AddressIPv6EqU32(a, b) == 0);
836  PASS;
837 }
838 
839 static int AddressTestIPv6Eq02(void)
840 {
841  uint32_t a[4] = { 1, 2, 3, 4 };
842  uint32_t b[4] = { 0, 2, 3, 4 };
843 
844  FAIL_IF_NOT(AddressIPv6EqU32(a, b) == 0);
845  PASS;
846 }
847 
848 static int AddressTestIPv6Eq03(void)
849 {
850  uint32_t a[4] = { 1, 2, 3, 4 };
851  uint32_t b[4] = { 1, 2, 3, 4 };
852 
853  FAIL_IF_NOT(AddressIPv6EqU32(a, b) == 1);
854  PASS;
855 }
856 
857 static int AddressTestIPv6Eq04(void)
858 {
859  uint32_t a[4] = { 1, 2, 3, 4 };
860  uint32_t b[4] = { 1, 2, 3, 5 };
861 
862  FAIL_IF_NOT(AddressIPv6EqU32(a, b) == 0);
863  PASS;
864 }
865 
866 static int AddressTestIPv6Le01(void)
867 {
868  uint32_t a[4] = { 0, 2, 3, 4 };
869  uint32_t b[4] = { 1, 2, 3, 4 };
870 
871  FAIL_IF_NOT(AddressIPv6LeU32(a, b) == 1);
872  PASS;
873 }
874 
875 static int AddressTestIPv6Le02(void)
876 {
877  uint32_t a[4] = { 1, 2, 3, 4 };
878  uint32_t b[4] = { 0, 2, 3, 4 };
879 
880  FAIL_IF_NOT(AddressIPv6LeU32(a, b) == 0);
881  PASS;
882 }
883 
884 static int AddressTestIPv6Le03(void)
885 {
886  uint32_t a[4] = { 1, 2, 3, 4 };
887  uint32_t b[4] = { 1, 2, 3, 4 };
888 
889  FAIL_IF_NOT(AddressIPv6LeU32(a, b) == 1);
890  PASS;
891 }
892 
893 static int AddressTestIPv6Le04(void)
894 {
895  uint32_t a[4] = { 1, 2, 3, 4 };
896  uint32_t b[4] = { 1, 2, 3, 5 };
897 
898  FAIL_IF_NOT(AddressIPv6LeU32(a, b) == 1);
899  PASS;
900 }
901 
902 static int AddressTestIPv6Le05(void)
903 {
904  uint32_t a[4];
905  uint32_t b[4];
906  struct in6_addr in6;
907 
908  FAIL_IF(inet_pton(AF_INET6, "1999:ffff:ffff:ffff:ffff:ffff:ffff:ffff", &in6) != 1);
909  memcpy(&a, &in6.s6_addr, sizeof(in6.s6_addr));
910 
911  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
912  memcpy(&b, &in6.s6_addr, sizeof(in6.s6_addr));
913 
914  FAIL_IF_NOT(AddressIPv6LeU32(a, b) == 1);
915  PASS;
916 }
917 
918 static int AddressTestIPv6Ge01(void)
919 {
920  uint32_t a[4] = { 0, 2, 3, 4 };
921  uint32_t b[4] = { 1, 2, 3, 4 };
922 
923  FAIL_IF_NOT(AddressIPv6GeU32(a, b) == 0);
924  PASS;
925 }
926 
927 static int AddressTestIPv6Ge02(void)
928 {
929  uint32_t a[4] = { 1, 2, 3, 4 };
930  uint32_t b[4] = { 0, 2, 3, 4 };
931 
932  FAIL_IF_NOT(AddressIPv6GeU32(a, b) == 1);
933  PASS;
934 }
935 
936 static int AddressTestIPv6Ge03(void)
937 {
938  uint32_t a[4] = { 1, 2, 3, 4 };
939  uint32_t b[4] = { 1, 2, 3, 4 };
940 
941  FAIL_IF_NOT(AddressIPv6GeU32(a, b) == 1);
942  PASS;
943 }
944 
945 static int AddressTestIPv6Ge04(void)
946 {
947  uint32_t a[4] = { 1, 2, 3, 4 };
948  uint32_t b[4] = { 1, 2, 3, 5 };
949 
950  FAIL_IF_NOT(AddressIPv6GeU32(a, b) == 0);
951  PASS;
952 }
953 
954 static int AddressTestIPv6Ge05(void)
955 {
956  uint32_t a[4];
957  uint32_t b[4];
958  struct in6_addr in6;
959 
960  FAIL_IF(inet_pton(AF_INET6, "1999:ffff:ffff:ffff:ffff:ffff:ffff:ffff", &in6) != 1);
961  memcpy(&a, &in6.s6_addr, sizeof(in6.s6_addr));
962 
963  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
964  memcpy(&b, &in6.s6_addr, sizeof(in6.s6_addr));
965 
966  FAIL_IF_NOT(AddressIPv6GeU32(a, b) == 0);
967  PASS;
968 }
969 
970 static int AddressTestIPv6SubOne01(void)
971 {
972  uint32_t a[4], b[4];
973  struct in6_addr in6;
974 
975  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
976  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
977 
978  a[0] = SCNtohl(a[0]);
979  a[1] = SCNtohl(a[1]);
980  a[2] = SCNtohl(a[2]);
981  a[3] = SCNtohl(a[3]);
982 
983  AddressCutIPv6CopySubOne(a, b);
984 
985  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
986  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
987  FAIL_IF(b[0] != a[0]);
988  FAIL_IF(b[1] != a[1]);
989  FAIL_IF(b[2] != a[2]);
990  FAIL_IF(b[3] != a[3]);
991  PASS;
992 }
993 
994 static int AddressTestIPv6SubOne02(void)
995 {
996  uint32_t a[4], b[4];
997  struct in6_addr in6;
998 
999  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1000  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
1001 
1002  a[0] = SCNtohl(a[0]);
1003  a[1] = SCNtohl(a[1]);
1004  a[2] = SCNtohl(a[2]);
1005  a[3] = SCNtohl(a[3]);
1006 
1007  AddressCutIPv6CopySubOne(a, b);
1008 
1009  FAIL_IF(inet_pton(AF_INET6, "1FFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1010  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
1011  FAIL_IF(b[0] != a[0]);
1012  FAIL_IF(b[1] != a[1]);
1013  FAIL_IF(b[2] != a[2]);
1014  FAIL_IF(b[3] != a[3]);
1015  PASS;
1016 }
1017 
1018 static int AddressTestIPv6AddOne01(void)
1019 {
1020  uint32_t a[4], b[4];
1021  struct in6_addr in6;
1022 
1023  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1024  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
1025 
1026  a[0] = SCNtohl(a[0]);
1027  a[1] = SCNtohl(a[1]);
1028  a[2] = SCNtohl(a[2]);
1029  a[3] = SCNtohl(a[3]);
1030 
1031  AddressCutIPv6CopyAddOne(a, b);
1032 
1033  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1034  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
1035  FAIL_IF(b[0] != a[0]);
1036  FAIL_IF(b[1] != a[1]);
1037  FAIL_IF(b[2] != a[2]);
1038  FAIL_IF(b[3] != a[3]);
1039  PASS;
1040 }
1041 
1042 static int AddressTestIPv6AddOne02(void)
1043 {
1044  uint32_t a[4], b[4];
1045  struct in6_addr in6;
1046 
1047  FAIL_IF(inet_pton(AF_INET6, "1FFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1048  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
1049 
1050  a[0] = SCNtohl(a[0]);
1051  a[1] = SCNtohl(a[1]);
1052  a[2] = SCNtohl(a[2]);
1053  a[3] = SCNtohl(a[3]);
1054 
1055  AddressCutIPv6CopyAddOne(a, b);
1056 
1057  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1058  memcpy(a, in6.s6_addr, sizeof(in6.s6_addr));
1059  FAIL_IF(b[0] != a[0]);
1060  FAIL_IF(b[1] != a[1]);
1061  FAIL_IF(b[2] != a[2]);
1062  FAIL_IF(b[3] != a[3]);
1063  PASS;
1064 }
1065 
1066 static int AddressTestIPv6AddressCmp01(void)
1067 {
1070  struct in6_addr in6;
1071 
1072  FAIL_IF_NULL(a);
1073  FAIL_IF_NULL(b);
1074 
1075  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1076  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1077  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1078  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1079  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1080  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1081  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1082  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1084 
1085  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1086  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1087  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1088  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1089  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1090  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1091  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1092  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1094 
1095  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1096  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1097  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1098  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1099  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1100  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1101  FAIL_IF(inet_pton(AF_INET6, "2000::11", &in6) != 1);
1102  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1104 
1105  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1106  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1107  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1108  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1109  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1110  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1111  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1112  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1114 
1115  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1116  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1117  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1118  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1119  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1120  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1121  FAIL_IF(inet_pton(AF_INET6, "2000::11", &in6) != 1);
1122  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1124 
1125  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1126  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1127  FAIL_IF(inet_pton(AF_INET6, "2000::11", &in6) != 1);
1128  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1129  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1130  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1131  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1132  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1134 
1135  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1136  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1137  FAIL_IF(inet_pton(AF_INET6, "2000::11", &in6) != 1);
1138  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1139  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1140  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1141  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1142  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1144 
1145  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1146  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1147  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1148  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1149  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1150  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1151  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1152  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1154 
1155  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1156  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1157  FAIL_IF(inet_pton(AF_INET6, "2000::11", &in6) != 1);
1158  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1159  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1160  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1161  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1162  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1164 
1165  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1166  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1167  FAIL_IF(inet_pton(AF_INET6, "2000::11", &in6) != 1);
1168  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1169  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1170  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1171  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1172  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1174 
1175  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1176  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1177  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1178  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1179  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1180  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1181  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1182  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1184 
1185  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1186  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1187  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1188  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1189  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1190  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1191  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1192  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1194 
1195  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1196  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1197  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1198  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1199  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1200  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1201  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1202  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1204 
1205  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1206  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1207  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1208  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1209  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1210  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1211  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1212  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1214 
1215  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1216  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1217  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1218  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1219  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1220  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1221  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1222  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1224 
1225  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1226  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1227  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1228  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1229  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1230  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1231  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1232  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1234 
1235  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1236  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1237  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1238  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1239  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1240  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1241  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1242  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1243  /* we could get a LE */
1245 
1246  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1247  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1248  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1249  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1250  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1251  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1252  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1253  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1254  /* we could get a LE */
1256 
1257  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1258  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1259  FAIL_IF(inet_pton(AF_INET6, "2000::19", &in6) != 1);
1260  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1261  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1262  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1263  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1264  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1266 
1267  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1268  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1269  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1270  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1271  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1272  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1273  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1274  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1276 
1277  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1278  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1279  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1280  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1281  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1282  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1283  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1284  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1286 
1287  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1288  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1289  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1290  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1291  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1292  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1293  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1294  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1296 
1297  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1298  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1299  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1300  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1301  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1302  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1303  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1304  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1306 
1307  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1308  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1309  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1310  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1311  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1312  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1313  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1314  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1316 
1317  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1318  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1319  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1320  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1321  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1322  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1323  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1324  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1326 
1327  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1328  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1329  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1330  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1331  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1332  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1333  FAIL_IF(inet_pton(AF_INET6, "2000::19", &in6) != 1);
1334  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1336 
1337  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1338  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1339  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1340  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1341  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1342  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1343  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1344  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1346 
1347  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1348  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1349  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1350  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1351  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1352  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1353  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1354  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1356 
1357  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1358  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1359  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1360  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1361  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1362  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1363  FAIL_IF(inet_pton(AF_INET6, "2000::15", &in6) != 1);
1364  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1366 
1367  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1368  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1369  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1370  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1371  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1372  memcpy(&b->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1373  FAIL_IF(inet_pton(AF_INET6, "2000::10", &in6) != 1);
1374  memcpy(&b->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1376 
1377  DetectAddressFree(a);
1378  DetectAddressFree(b);
1379  PASS;
1380 }
1381 
1382 static int AddressTestIPv6CutNot01(void)
1383 {
1384  struct in6_addr in6;
1386  FAIL_IF_NULL(a);
1387 
1388  FAIL_IF(inet_pton(AF_INET6, "::", &in6) != 1);
1389  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1390  FAIL_IF(inet_pton(AF_INET6, "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1391  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1392 
1393  DetectAddress *b = NULL;
1394  FAIL_IF_NOT(DetectAddressCutNotIPv6(a, &b) == -1);
1395  FAIL_IF_NOT_NULL(b);
1396 
1397  DetectAddressFree(a);
1398  PASS;
1399 }
1400 
1401 static int AddressTestIPv6CutNot02(void)
1402 {
1403  struct in6_addr in6;
1405  FAIL_IF_NULL(a);
1406  DetectAddress *temp = DetectAddressInit();
1407  FAIL_IF_NULL(temp);
1408 
1409  FAIL_IF(inet_pton(AF_INET6, "::", &in6) != 1);
1410  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1411  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1412  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1413 
1414  DetectAddress *b = NULL;
1415  FAIL_IF_NOT(DetectAddressCutNotIPv6(a, &b) == 0);
1416  FAIL_IF(b != NULL);
1417 
1418  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1419  memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1420  FAIL_IF(inet_pton(AF_INET6, "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1421  memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1422 
1424 
1425  DetectAddressFree(a);
1426  DetectAddressFree(temp);
1427  PASS;
1428 }
1429 
1430 static int AddressTestIPv6CutNot03(void)
1431 {
1432  struct in6_addr in6;
1434  FAIL_IF_NULL(a);
1435  DetectAddress *temp = DetectAddressInit();
1436  FAIL_IF_NULL(temp);
1437 
1438  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1439  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1440  FAIL_IF(inet_pton(AF_INET6, "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1441  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1442 
1443  DetectAddress *b = NULL;
1444  FAIL_IF_NOT(DetectAddressCutNotIPv6(a, &b) == 0);
1445  FAIL_IF(b != NULL);
1446 
1447  FAIL_IF(inet_pton(AF_INET6, "::", &in6) != 1);
1448  memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1449  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1450  memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1451 
1453 
1454  DetectAddressFree(a);
1455  DetectAddressFree(temp);
1456  PASS;
1457 }
1458 
1459 static int AddressTestIPv6CutNot04(void)
1460 {
1461  struct in6_addr in6;
1463  FAIL_IF_NULL(a);
1464  DetectAddress *temp = DetectAddressInit();
1465  FAIL_IF_NULL(temp);
1466 
1467  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1468  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1469  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1470  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1471 
1472  DetectAddress *b = NULL;
1473  FAIL_IF_NOT(DetectAddressCutNotIPv6(a, &b) == 0);
1474 
1475  FAIL_IF(inet_pton(AF_INET6, "::", &in6) != 1);
1476  memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1477  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1478  memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1480 
1481  FAIL_IF_NULL(b);
1482  FAIL_IF(inet_pton(AF_INET6, "2000::2", &in6) != 1);
1483  memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1484  FAIL_IF(inet_pton(AF_INET6, "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1485  memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1487 
1488  DetectAddressFree(a);
1489  DetectAddressFree(b);
1490  DetectAddressFree(temp);
1491  PASS;
1492 }
1493 
1494 static int AddressTestIPv6CutNot05(void)
1495 {
1496  struct in6_addr in6;
1498  FAIL_IF_NULL(a);
1499  DetectAddress *temp = DetectAddressInit();
1500  FAIL_IF_NULL(temp);
1501 
1502  FAIL_IF(inet_pton(AF_INET6, "2000::1", &in6) != 1);
1503  memcpy(&a->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1504  FAIL_IF(inet_pton(AF_INET6, "2000::20", &in6) != 1);
1505  memcpy(&a->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1506 
1507  DetectAddress *b = NULL;
1508  FAIL_IF_NOT(DetectAddressCutNotIPv6(a, &b) == 0);
1509 
1510  FAIL_IF(inet_pton(AF_INET6, "::", &in6) != 1);
1511  memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1512  FAIL_IF(inet_pton(AF_INET6, "2000::0", &in6) != 1);
1513  memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1515 
1516  FAIL_IF_NULL(b);
1517  FAIL_IF(inet_pton(AF_INET6, "2000::21", &in6) != 1);
1518  memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1519  FAIL_IF(inet_pton(AF_INET6, "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", &in6) != 1);
1520  memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1522 
1523  DetectAddressFree(a);
1524  DetectAddressFree(b);
1525  DetectAddressFree(temp);
1526  PASS;
1527 }
1528 
1529 #endif /* UNITTESTS */
1530 
1532 {
1533 
1534 #ifdef UNITTESTS
1535  UtRegisterTest("AddressTestIPv6Gt01", AddressTestIPv6Gt01);
1536  UtRegisterTest("AddressTestIPv6Gt02", AddressTestIPv6Gt02);
1537  UtRegisterTest("AddressTestIPv6Gt03", AddressTestIPv6Gt03);
1538  UtRegisterTest("AddressTestIPv6Gt04", AddressTestIPv6Gt04);
1539 
1540  UtRegisterTest("AddressTestIPv6Lt01", AddressTestIPv6Lt01);
1541  UtRegisterTest("AddressTestIPv6Lt02", AddressTestIPv6Lt02);
1542  UtRegisterTest("AddressTestIPv6Lt03", AddressTestIPv6Lt03);
1543  UtRegisterTest("AddressTestIPv6Lt04", AddressTestIPv6Lt04);
1544 
1545  UtRegisterTest("AddressTestIPv6Eq01", AddressTestIPv6Eq01);
1546  UtRegisterTest("AddressTestIPv6Eq02", AddressTestIPv6Eq02);
1547  UtRegisterTest("AddressTestIPv6Eq03", AddressTestIPv6Eq03);
1548  UtRegisterTest("AddressTestIPv6Eq04", AddressTestIPv6Eq04);
1549 
1550  UtRegisterTest("AddressTestIPv6Le01", AddressTestIPv6Le01);
1551  UtRegisterTest("AddressTestIPv6Le02", AddressTestIPv6Le02);
1552  UtRegisterTest("AddressTestIPv6Le03", AddressTestIPv6Le03);
1553  UtRegisterTest("AddressTestIPv6Le04", AddressTestIPv6Le04);
1554  UtRegisterTest("AddressTestIPv6Le05", AddressTestIPv6Le05);
1555 
1556  UtRegisterTest("AddressTestIPv6Ge01", AddressTestIPv6Ge01);
1557  UtRegisterTest("AddressTestIPv6Ge02", AddressTestIPv6Ge02);
1558  UtRegisterTest("AddressTestIPv6Ge03", AddressTestIPv6Ge03);
1559  UtRegisterTest("AddressTestIPv6Ge04", AddressTestIPv6Ge04);
1560  UtRegisterTest("AddressTestIPv6Ge05", AddressTestIPv6Ge05);
1561 
1562  UtRegisterTest("AddressTestIPv6SubOne01", AddressTestIPv6SubOne01);
1563  UtRegisterTest("AddressTestIPv6SubOne02", AddressTestIPv6SubOne02);
1564 
1565  UtRegisterTest("AddressTestIPv6AddOne01", AddressTestIPv6AddOne01);
1566  UtRegisterTest("AddressTestIPv6AddOne02", AddressTestIPv6AddOne02);
1567 
1568  UtRegisterTest("AddressTestIPv6AddressCmp01", AddressTestIPv6AddressCmp01);
1569 
1570  UtRegisterTest("AddressTestIPv6CutNot01", AddressTestIPv6CutNot01);
1571  UtRegisterTest("AddressTestIPv6CutNot02", AddressTestIPv6CutNot02);
1572  UtRegisterTest("AddressTestIPv6CutNot03", AddressTestIPv6CutNot03);
1573  UtRegisterTest("AddressTestIPv6CutNot04", AddressTestIPv6CutNot04);
1574  UtRegisterTest("AddressTestIPv6CutNot05", AddressTestIPv6CutNot05);
1575 #endif /* UNITTESTS */
1576 }
DetectAddress_::ip
Address ip
Definition: detect.h:170
DetectAddressFree
void DetectAddressFree(DetectAddress *ag)
Frees a DetectAddress instance.
Definition: detect-engine-address.c:82
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
ADDRESS_EB
@ ADDRESS_EB
Definition: detect.h:157
ADDRESS_LE
@ ADDRESS_LE
Definition: detect.h:154
DetectAddressCutIPv6
int DetectAddressCutIPv6(DetectEngineCtx *de_ctx, DetectAddress *a, DetectAddress *b, DetectAddress **c)
Definition: detect-engine-address-ipv6.c:353
detect-engine-siggroup.h
AddressIPv6Le
int AddressIPv6Le(const Address *a, const Address *b)
Compares 2 ipv6 addresses and returns if the first address(a) is less than or equal to the second add...
Definition: detect-engine-address-ipv6.c:162
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DetectAddress_
address structure for use in the detection engine.
Definition: detect.h:168
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
AddressIPv6Eq
int AddressIPv6Eq(const Address *a, const Address *b)
Compares 2 ipv6 addresses and returns if the addresses are equal or not.
Definition: detect-engine-address-ipv6.c:128
ADDRESS_LT
@ ADDRESS_LT
Definition: detect.h:153
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:932
ADDRESS_EQ
@ ADDRESS_EQ
Definition: detect.h:155
Address_
Definition: decode.h:112
util-unittest.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
util-cidr.h
decode.h
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
ADDRESS_GE
@ ADDRESS_GE
Definition: detect.h:158
detect.h
detect-engine-port.h
DetectAddress_::ip2
Address ip2
Definition: detect.h:171
Address_::address
union Address_::@30 address
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
AddressIPv6EqU32
int AddressIPv6EqU32(uint32_t *a, uint32_t *b)
Definition: detect-engine-address-ipv6.c:140
AddressIPv6GeU32
int AddressIPv6GeU32(uint32_t *a, uint32_t *b)
Definition: detect-engine-address-ipv6.c:205
detect-engine-address-ipv6.h
DetectAddressCmpIPv6
int DetectAddressCmpIPv6(DetectAddress *a, DetectAddress *b)
Compares 2 addresses(address ranges) and returns the relationship between the 2 addresses.
Definition: detect-engine-address-ipv6.c:232
SCNtohl
#define SCNtohl(x)
Definition: suricata-common.h:430
AddressIPv6Lt
int AddressIPv6Lt(const Address *a, const Address *b)
Compares 2 ipv6 addresses and returns if the first address(a) is less than the second address(b) or n...
Definition: detect-engine-address-ipv6.c:52
AddressIPv6LeU32
int AddressIPv6LeU32(uint32_t *a, uint32_t *b)
Definition: detect-engine-address-ipv6.c:173
DetectAddressCutNotIPv6
int DetectAddressCutNotIPv6(DetectAddress *a, DetectAddress **b)
Cuts and returns an address range, which is the complement of the address range that is supplied as t...
Definition: detect-engine-address-ipv6.c:704
Address_::family
char family
Definition: decode.h:113
ADDRESS_ES
@ ADDRESS_ES
Definition: detect.h:156
AddressIPv6GtU32
int AddressIPv6GtU32(uint32_t *a, uint32_t *b)
Definition: detect-engine-address-ipv6.c:104
DetectAddressIPv6Tests
void DetectAddressIPv6Tests(void)
Definition: detect-engine-address-ipv6.c:1531
AddressIPv6Gt
int AddressIPv6Gt(const Address *a, const Address *b)
Compares 2 ipv6 addresses and returns if the first address(a) is greater than the second address(b) o...
Definition: detect-engine-address-ipv6.c:90
AddressIPv6LtU32
int AddressIPv6LtU32(uint32_t *a, uint32_t *b)
Definition: detect-engine-address-ipv6.c:66
AddressIPv6Ge
int AddressIPv6Ge(const Address *a, const Address *b)
Compares 2 ipv6 addresses and returns if the first address(a) is greater than or equal to the second ...
Definition: detect-engine-address-ipv6.c:194
flow-var.h
detect-engine-address.h
DetectAddressInit
DetectAddress * DetectAddressInit(void)
Creates and returns a new instance of a DetectAddress.
Definition: detect-engine-address.c:69
ADDRESS_ER
@ ADDRESS_ER
Definition: detect.h:152
ADDRESS_GT
@ ADDRESS_GT
Definition: detect.h:159