ported some hard-to-merge cherries back to trunk :-/
[strongswan.git] / src / charon / config / traffic_selector.c
1 /*
2 * Copyright (C) 2007 Tobias Brunner
3 * Copyright (C) 2005-2007 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * $Id$
18 */
19
20 #include <arpa/inet.h>
21 #include <string.h>
22 #include <netdb.h>
23 #include <stdio.h>
24 #include <printf.h>
25
26 #include "traffic_selector.h"
27
28 #include <daemon.h>
29 #include <utils/linked_list.h>
30 #include <utils/identification.h>
31
32 ENUM(ts_type_name, TS_IPV4_ADDR_RANGE, TS_IPV6_ADDR_RANGE,
33 "TS_IPV4_ADDR_RANGE",
34 "TS_IPV6_ADDR_RANGE",
35 );
36
37 typedef struct private_traffic_selector_t private_traffic_selector_t;
38
39 /**
40 * Private data of an traffic_selector_t object
41 */
42 struct private_traffic_selector_t {
43
44 /**
45 * Public part
46 */
47 traffic_selector_t public;
48
49 /**
50 * Type of address
51 */
52 ts_type_t type;
53
54 /**
55 * IP protocol (UDP, TCP, ICMP, ...)
56 */
57 u_int8_t protocol;
58
59 /**
60 * narrow this traffic selector to hosts external ip
61 * if set, from and to have no meaning until set_address() is called
62 */
63 bool dynamic;
64
65 /**
66 * begin of address range, network order
67 */
68 union {
69 /** dummy char for common address manipulation */
70 char from[0];
71 /** IPv4 address */
72 u_int32_t from4[1];
73 /** IPv6 address */
74 u_int32_t from6[4];
75 };
76
77 /**
78 * end of address range, network order
79 */
80 union {
81 /** dummy char for common address manipulation */
82 char to[0];
83 /** IPv4 address */
84 u_int32_t to4[1];
85 /** IPv6 address */
86 u_int32_t to6[4];
87 };
88
89 /**
90 * begin of port range
91 */
92 u_int16_t from_port;
93
94 /**
95 * end of port range
96 */
97 u_int16_t to_port;
98 };
99
100 /**
101 * calculate to "to"-address for the "from" address and a subnet size
102 */
103 static void calc_range(private_traffic_selector_t *this, u_int8_t netbits)
104 {
105 int byte;
106 size_t size = (this->type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
107
108 /* go through the from address, starting at the tail. While we
109 * have not processed the bits belonging to the host, set them to 1 on
110 * the to address. If we reach the bits for the net, copy them from "from". */
111 for (byte = size - 1; byte >=0; byte--)
112 {
113 u_char mask = 0x00;
114 int shift;
115
116 shift = (byte+1) * 8 - netbits;
117 if (shift > 0)
118 {
119 mask = 1 << shift;
120 if (mask != 0xFF)
121 {
122 mask--;
123 }
124 }
125 this->to[byte] = this->from[byte] | mask;
126 }
127 }
128
129 /**
130 * calculate to subnet size from "to"- and "from"-address
131 */
132 static u_int8_t calc_netbits(private_traffic_selector_t *this)
133 {
134 int byte, bit;
135 size_t size = (this->type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
136
137 /* go trough all bits of the addresses, beginning in the front.
138 * as long as they are equal, the subnet gets larger
139 */
140 for (byte = 0; byte < size; byte++)
141 {
142 for (bit = 7; bit >= 0; bit--)
143 {
144 if ((1<<bit & this->from[byte]) != (1<<bit & this->to[byte]))
145 {
146 return ((7 - bit) + (byte * 8));
147 }
148 }
149 }
150 /* single host, netmask is 32/128 */
151 return (size * 8);
152 }
153
154 /**
155 * internal generic constructor
156 */
157 static private_traffic_selector_t *traffic_selector_create(u_int8_t protocol, ts_type_t type, u_int16_t from_port, u_int16_t to_port);
158
159 /**
160 * output handler in printf()
161 */
162 static int print(FILE *stream, const struct printf_info *info,
163 const void *const *args)
164 {
165 private_traffic_selector_t *this = *((private_traffic_selector_t**)(args[0]));
166 linked_list_t *list = *((linked_list_t**)(args[0]));
167 iterator_t *iterator;
168 char addr_str[INET6_ADDRSTRLEN] = "";
169 char *serv_proto = NULL;
170 u_int8_t mask;
171 bool has_proto;
172 bool has_ports;
173 size_t written = 0;
174 u_int32_t from[4], to[4];
175
176 if (this == NULL)
177 {
178 return fprintf(stream, "(null)");
179 }
180
181 if (info->alt)
182 {
183 iterator = list->create_iterator(list, TRUE);
184 while (iterator->iterate(iterator, (void**)&this))
185 {
186 /* call recursivly */
187 written += fprintf(stream, "%R ", this);
188 }
189 iterator->destroy(iterator);
190 return written;
191 }
192
193 memset(from, 0, sizeof(from));
194 memset(to, 0xFF, sizeof(to));
195 if (this->dynamic &&
196 memeq(this->from, from, this->type == TS_IPV4_ADDR_RANGE ? 4 : 16) &&
197 memeq(this->to, to, this->type == TS_IPV4_ADDR_RANGE ? 4 : 16))
198 {
199 written += fprintf(stream, "dynamic/%d",
200 this->type == TS_IPV4_ADDR_RANGE ? 32 : 128);
201 }
202 else
203 {
204 if (this->type == TS_IPV4_ADDR_RANGE)
205 {
206 inet_ntop(AF_INET, &this->from4, addr_str, sizeof(addr_str));
207 }
208 else
209 {
210 inet_ntop(AF_INET6, &this->from6, addr_str, sizeof(addr_str));
211 }
212 mask = calc_netbits(this);
213 written += fprintf(stream, "%s/%d", addr_str, mask);
214 }
215
216 /* check if we have protocol and/or port selectors */
217 has_proto = this->protocol != 0;
218 has_ports = !(this->from_port == 0 && this->to_port == 0xFFFF);
219
220 if (!has_proto && !has_ports)
221 {
222 return written;
223 }
224
225 written += fprintf(stream, "[");
226
227 /* build protocol string */
228 if (has_proto)
229 {
230 struct protoent *proto = getprotobynumber(this->protocol);
231
232 if (proto)
233 {
234 written += fprintf(stream, "%s", proto->p_name);
235 serv_proto = proto->p_name;
236 }
237 else
238 {
239 written += fprintf(stream, "%d", this->protocol);
240 }
241 }
242
243 if (has_proto && has_ports)
244 {
245 written += fprintf(stream, "/");
246 }
247
248 /* build port string */
249 if (has_ports)
250 {
251 if (this->from_port == this->to_port)
252 {
253 struct servent *serv = getservbyport(htons(this->from_port), serv_proto);
254
255 if (serv)
256 {
257 written += fprintf(stream, "%s", serv->s_name);
258 }
259 else
260 {
261 written += fprintf(stream, "%d", this->from_port);
262 }
263 }
264 else
265 {
266 written += fprintf(stream, "%d-%d", this->from_port, this->to_port);
267 }
268 }
269
270 written += fprintf(stream, "]");
271
272 return written;
273 }
274
275 /**
276 * arginfo handler for printf() traffic selector
277 */
278 static int arginfo(const struct printf_info *info, size_t n, int *argtypes)
279 {
280 if (n > 0)
281 {
282 argtypes[0] = PA_POINTER;
283 }
284 return 1;
285 }
286
287 /**
288 * return printf hook functions for a chunk
289 */
290 printf_hook_functions_t traffic_selector_get_printf_hooks()
291 {
292 printf_hook_functions_t hooks = {print, arginfo};
293
294 return hooks;
295 }
296
297 /**
298 * implements traffic_selector_t.get_subset
299 */
300 static traffic_selector_t *get_subset(private_traffic_selector_t *this, private_traffic_selector_t *other)
301 {
302 if (this->type == other->type && (this->protocol == other->protocol ||
303 this->protocol == 0 || other->protocol == 0))
304 {
305 u_int16_t from_port, to_port;
306 u_char *from, *to;
307 u_int8_t protocol;
308 size_t size;
309 private_traffic_selector_t *new_ts;
310
311 /* calculate the maximum port range allowed for both */
312 from_port = max(this->from_port, other->from_port);
313 to_port = min(this->to_port, other->to_port);
314 if (from_port > to_port)
315 {
316 return NULL;
317 }
318 /* select protocol, which is not zero */
319 protocol = max(this->protocol, other->protocol);
320
321 switch (this->type)
322 {
323 case TS_IPV4_ADDR_RANGE:
324 size = sizeof(this->from4);
325 break;
326 case TS_IPV6_ADDR_RANGE:
327 size = sizeof(this->from6);
328 break;
329 default:
330 return NULL;
331 }
332
333 /* get higher from-address */
334 if (memcmp(this->from, other->from, size) > 0)
335 {
336 from = this->from;
337 }
338 else
339 {
340 from = other->from;
341 }
342 /* get lower to-address */
343 if (memcmp(this->to, other->to, size) > 0)
344 {
345 to = other->to;
346 }
347 else
348 {
349 to = this->to;
350 }
351 /* if "from" > "to", we don't have a match */
352 if (memcmp(from, to, size) > 0)
353 {
354 return NULL;
355 }
356
357 /* we have a match in protocol, port, and address: return it... */
358 new_ts = traffic_selector_create(protocol, this->type, from_port, to_port);
359 new_ts->type = this->type;
360 new_ts->dynamic = this->dynamic || other->dynamic;
361 memcpy(new_ts->from, from, size);
362 memcpy(new_ts->to, to, size);
363
364 return &new_ts->public;
365 }
366 return NULL;
367 }
368
369 /**
370 * implements traffic_selector_t.equals
371 */
372 static bool equals(private_traffic_selector_t *this, private_traffic_selector_t *other)
373 {
374 if (this->type != other->type)
375 {
376 return FALSE;
377 }
378 if (!(this->from_port == other->from_port &&
379 this->to_port == other->to_port &&
380 this->protocol == other->protocol))
381 {
382 return FALSE;
383 }
384 switch (this->type)
385 {
386 case TS_IPV4_ADDR_RANGE:
387 if (memeq(this->from4, other->from4, sizeof(this->from4)))
388 {
389 return TRUE;
390 }
391 break;
392 case TS_IPV6_ADDR_RANGE:
393 if (memeq(this->from6, other->from6, sizeof(this->from6)))
394 {
395 return TRUE;
396 }
397 break;
398 default:
399 break;
400 }
401 return FALSE;
402 }
403
404 /**
405 * Implements traffic_selector_t.get_from_address.
406 */
407 static chunk_t get_from_address(private_traffic_selector_t *this)
408 {
409 switch (this->type)
410 {
411 case TS_IPV4_ADDR_RANGE:
412 return chunk_create(this->from, sizeof(this->from4));
413 case TS_IPV6_ADDR_RANGE:
414 return chunk_create(this->from, sizeof(this->from6));
415 default:
416 return chunk_empty;
417 }
418 }
419
420 /**
421 * Implements traffic_selector_t.get_to_address.
422 */
423 static chunk_t get_to_address(private_traffic_selector_t *this)
424 {
425 switch (this->type)
426 {
427 case TS_IPV4_ADDR_RANGE:
428 return chunk_create(this->to, sizeof(this->to4));
429 case TS_IPV6_ADDR_RANGE:
430 return chunk_create(this->to, sizeof(this->to6));
431 default:
432 return chunk_empty;
433 }
434 }
435
436 /**
437 * Implements traffic_selector_t.get_from_port.
438 */
439 static u_int16_t get_from_port(private_traffic_selector_t *this)
440 {
441 return this->from_port;
442 }
443
444 /**
445 * Implements traffic_selector_t.get_to_port.
446 */
447 static u_int16_t get_to_port(private_traffic_selector_t *this)
448 {
449 return this->to_port;
450 }
451
452 /**
453 * Implements traffic_selector_t.get_type.
454 */
455 static ts_type_t get_type(private_traffic_selector_t *this)
456 {
457 return this->type;
458 }
459
460 /**
461 * Implements traffic_selector_t.get_protocol.
462 */
463 static u_int8_t get_protocol(private_traffic_selector_t *this)
464 {
465 return this->protocol;
466 }
467
468 /**
469 * Implements traffic_selector_t.is_host.
470 */
471 static bool is_host(private_traffic_selector_t *this, host_t *host)
472 {
473 if (host)
474 {
475 chunk_t addr;
476 int family = host->get_family(host);
477
478 if ((family == AF_INET && this->type == TS_IPV4_ADDR_RANGE) ||
479 (family == AF_INET6 && this->type == TS_IPV6_ADDR_RANGE))
480 {
481 addr = host->get_address(host);
482 if (memeq(addr.ptr, this->from, addr.len) &&
483 memeq(addr.ptr, this->to, addr.len))
484 {
485 return TRUE;
486 }
487 }
488 }
489 else
490 {
491 size_t length = (this->type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
492
493 if (this->dynamic)
494 {
495 return TRUE;
496 }
497
498 if (memeq(this->from, this->to, length))
499 {
500 return TRUE;
501 }
502 }
503 return FALSE;
504 }
505
506 /**
507 * Implementation of traffic_selector_t.is_dynamic
508 */
509 static bool is_dynamic(private_traffic_selector_t *this)
510 {
511 return this->dynamic;
512 }
513
514 /**
515 * Implements traffic_selector_t.set_address.
516 */
517 static void set_address(private_traffic_selector_t *this, host_t *host)
518 {
519 if (this->dynamic)
520 {
521 this->type = host->get_family(host) == AF_INET ?
522 TS_IPV4_ADDR_RANGE : TS_IPV6_ADDR_RANGE;
523
524 chunk_t from = host->get_address(host);
525 memcpy(this->from, from.ptr, from.len);
526 memcpy(this->to, from.ptr, from.len);
527 }
528 }
529
530 /**
531 * Implements traffic_selector_t.is_contained_in.
532 */
533 static bool is_contained_in(private_traffic_selector_t *this,
534 private_traffic_selector_t *other)
535 {
536 private_traffic_selector_t *subset;
537 bool contained_in = FALSE;
538
539 subset = (private_traffic_selector_t*)get_subset(this, other);
540
541 if (subset)
542 {
543 if (equals(subset, this))
544 {
545 contained_in = TRUE;
546 }
547 free(subset);
548 }
549 return contained_in;
550 }
551
552 /**
553 * Implements traffic_selector_t.includes.
554 */
555 static bool includes(private_traffic_selector_t *this, host_t *host)
556 {
557 chunk_t addr;
558 int family = host->get_family(host);
559
560 if ((family == AF_INET && this->type == TS_IPV4_ADDR_RANGE) ||
561 (family == AF_INET6 && this->type == TS_IPV6_ADDR_RANGE))
562 {
563 addr = host->get_address(host);
564
565 return memcmp(this->from, addr.ptr, addr.len) <= 0 &&
566 memcmp(this->to, addr.ptr, addr.len) >= 0;
567 }
568
569 return FALSE;
570 }
571
572 /**
573 * Implements traffic_selector_t.to_subnet.
574 */
575 static void to_subnet(private_traffic_selector_t *this, host_t **net, u_int8_t *mask)
576 {
577 /* there is no way to do this cleanly, as the address range may
578 * be anything else but a subnet. We use from_addr as subnet
579 * and try to calculate a usable subnet mask.
580 */
581 int family, byte;
582 u_int16_t port = 0;
583 chunk_t net_chunk;
584
585 *mask = calc_netbits(this);
586
587 switch (this->type)
588 {
589 case TS_IPV4_ADDR_RANGE:
590 {
591 family = AF_INET;
592 net_chunk.len = sizeof(this->from4);
593 break;
594 }
595 case TS_IPV6_ADDR_RANGE:
596 {
597 family = AF_INET6;
598 net_chunk.len = sizeof(this->from6);
599 break;
600 }
601 default:
602 {
603 /* unreachable */
604 return;
605 }
606 }
607
608 net_chunk.ptr = malloc(net_chunk.len);
609 memcpy(net_chunk.ptr, this->from, net_chunk.len);
610
611 for (byte = net_chunk.len - 1; byte >= (*mask / 8); --byte)
612 {
613 int shift = (byte + 1) * 8 - *mask;
614 net_chunk.ptr[byte] = net_chunk.ptr[byte] & (0xFF << shift);
615 }
616
617 if (this->to_port == this->from_port)
618 {
619 port = this->to_port;
620 }
621
622 *net = host_create_from_chunk(family, net_chunk, port);
623 chunk_free(&net_chunk);
624 }
625
626 /**
627 * Implements traffic_selector_t.clone.
628 */
629 static traffic_selector_t *clone_(private_traffic_selector_t *this)
630 {
631 private_traffic_selector_t *clone;
632
633 clone = traffic_selector_create(this->protocol, this->type,
634 this->from_port, this->to_port);
635
636 clone->dynamic = this->dynamic;
637 switch (clone->type)
638 {
639 case TS_IPV4_ADDR_RANGE:
640 {
641 memcpy(clone->from4, this->from4, sizeof(this->from4));
642 memcpy(clone->to4, this->to4, sizeof(this->to4));
643 return &clone->public;
644 }
645 case TS_IPV6_ADDR_RANGE:
646 {
647 memcpy(clone->from6, this->from6, sizeof(this->from6));
648 memcpy(clone->to6, this->to6, sizeof(this->to6));
649 return &clone->public;
650 }
651 default:
652 {
653 /* unreachable */
654 return &clone->public;
655 }
656 }
657 }
658
659 /**
660 * Implements traffic_selector_t.destroy.
661 */
662 static void destroy(private_traffic_selector_t *this)
663 {
664 free(this);
665 }
666
667 /*
668 * see header
669 */
670 traffic_selector_t *traffic_selector_create_from_bytes(u_int8_t protocol,
671 ts_type_t type,
672 chunk_t from, u_int16_t from_port,
673 chunk_t to, u_int16_t to_port)
674 {
675 private_traffic_selector_t *this = traffic_selector_create(protocol, type,
676 from_port, to_port);
677
678 switch (type)
679 {
680 case TS_IPV4_ADDR_RANGE:
681 {
682 if (from.len != 4 || to.len != 4)
683 {
684 free(this);
685 return NULL;
686 }
687 memcpy(this->from4, from.ptr, from.len);
688 memcpy(this->to4, to.ptr, to.len);
689 break;
690 }
691 case TS_IPV6_ADDR_RANGE:
692 {
693 if (from.len != 16 || to.len != 16)
694 {
695 free(this);
696 return NULL;
697 }
698 memcpy(this->from6, from.ptr, from.len);
699 memcpy(this->to6, to.ptr, to.len);
700 break;
701 }
702 default:
703 {
704 free(this);
705 return NULL;
706 }
707 }
708 return (&this->public);
709 }
710
711 /*
712 * see header
713 */
714 traffic_selector_t *traffic_selector_create_from_subnet(host_t *net,
715 u_int8_t netbits, u_int8_t protocol, u_int16_t port)
716 {
717 private_traffic_selector_t *this = traffic_selector_create(protocol, 0, 0, 65535);
718
719 switch (net->get_family(net))
720 {
721 case AF_INET:
722 {
723 chunk_t from;
724
725 this->type = TS_IPV4_ADDR_RANGE;
726 from = net->get_address(net);
727 memcpy(this->from4, from.ptr, from.len);
728 if (this->from4[0] == 0)
729 {
730 /* use /0 for 0.0.0.0 */
731 this->to4[0] = ~0;
732 }
733 else
734 {
735 calc_range(this, netbits);
736 }
737 break;
738 }
739 case AF_INET6:
740 {
741 chunk_t from;
742
743 this->type = TS_IPV6_ADDR_RANGE;
744 from = net->get_address(net);
745 memcpy(this->from6, from.ptr, from.len);
746 if (this->from6[0] == 0 && this->from6[1] == 0 &&
747 this->from6[2] == 0 && this->from6[3] == 0)
748 {
749 /* use /0 for ::0 */
750 this->to6[0] = ~0;
751 this->to6[1] = ~0;
752 this->to6[2] = ~0;
753 this->to6[3] = ~0;
754 }
755 else
756 {
757 calc_range(this, netbits);
758 }
759 break;
760 }
761 default:
762 {
763 net->destroy(net);
764 free(this);
765 return NULL;
766 }
767 }
768 if (port)
769 {
770 this->from_port = port;
771 this->to_port = port;
772 }
773 net->destroy(net);
774 return (&this->public);
775 }
776
777 /*
778 * see header
779 */
780 traffic_selector_t *traffic_selector_create_from_string(
781 u_int8_t protocol, ts_type_t type,
782 char *from_addr, u_int16_t from_port,
783 char *to_addr, u_int16_t to_port)
784 {
785 private_traffic_selector_t *this = traffic_selector_create(protocol, type,
786 from_port, to_port);
787
788 this->type = type;
789 switch (type)
790 {
791 case TS_IPV4_ADDR_RANGE:
792 {
793 if (inet_pton(AF_INET, from_addr, (struct in_addr*)this->from4) < 0)
794 {
795 free(this);
796 return NULL;
797 }
798 if (inet_pton(AF_INET, to_addr, (struct in_addr*)this->to4) < 0)
799 {
800 free(this);
801 return NULL;
802 }
803 break;
804 }
805 case TS_IPV6_ADDR_RANGE:
806 {
807 if (inet_pton(AF_INET6, from_addr, (struct in6_addr*)this->from6) < 0)
808 {
809 free(this);
810 return NULL;
811 }
812 if (inet_pton(AF_INET6, to_addr, (struct in6_addr*)this->to6) < 0)
813 {
814 free(this);
815 return NULL;
816 }
817 break;
818 }
819 }
820 return (&this->public);
821 }
822
823 /*
824 * see header
825 */
826 traffic_selector_t *traffic_selector_create_dynamic(u_int8_t protocol,
827 u_int16_t from_port, u_int16_t to_port)
828 {
829 private_traffic_selector_t *this = traffic_selector_create(
830 protocol, TS_IPV4_ADDR_RANGE, from_port, to_port);
831
832 memset(this->from6, 0, sizeof(this->from6));
833 memset(this->to6, 0xFF, sizeof(this->to6));
834
835 this->dynamic = TRUE;
836
837 return &this->public;
838 }
839
840 /*
841 * see declaration
842 */
843 static private_traffic_selector_t *traffic_selector_create(u_int8_t protocol,
844 ts_type_t type, u_int16_t from_port, u_int16_t to_port)
845 {
846 private_traffic_selector_t *this = malloc_thing(private_traffic_selector_t);
847
848 /* public functions */
849 this->public.get_subset = (traffic_selector_t*(*)(traffic_selector_t*,traffic_selector_t*))get_subset;
850 this->public.equals = (bool(*)(traffic_selector_t*,traffic_selector_t*))equals;
851 this->public.get_from_address = (chunk_t(*)(traffic_selector_t*))get_from_address;
852 this->public.get_to_address = (chunk_t(*)(traffic_selector_t*))get_to_address;
853 this->public.get_from_port = (u_int16_t(*)(traffic_selector_t*))get_from_port;
854 this->public.get_to_port = (u_int16_t(*)(traffic_selector_t*))get_to_port;
855 this->public.get_type = (ts_type_t(*)(traffic_selector_t*))get_type;
856 this->public.get_protocol = (u_int8_t(*)(traffic_selector_t*))get_protocol;
857 this->public.is_host = (bool(*)(traffic_selector_t*,host_t*))is_host;
858 this->public.is_dynamic = (bool(*)(traffic_selector_t*))is_dynamic;
859 this->public.is_contained_in = (bool(*)(traffic_selector_t*,traffic_selector_t*))is_contained_in;
860 this->public.includes = (bool(*)(traffic_selector_t*,host_t*))includes;
861 this->public.set_address = (void(*)(traffic_selector_t*,host_t*))set_address;
862 this->public.to_subnet = (void(*)(traffic_selector_t*,host_t**,u_int8_t*))to_subnet;
863 this->public.clone = (traffic_selector_t*(*)(traffic_selector_t*))clone_;
864 this->public.destroy = (void(*)(traffic_selector_t*))destroy;
865
866 this->from_port = from_port;
867 this->to_port = to_port;
868 this->protocol = protocol;
869 this->type = type;
870 this->dynamic = FALSE;
871
872 return this;
873 }
874