| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ip_flow.c,v 1.59 2010/04/01 00:24:41 tls Exp $ */ | | 1 | /* $NetBSD: ip_flow.c,v 1.60 2012/01/19 13:13:48 liamjfoy Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by the 3am Software Foundry ("3am"). It was developed by Matt Thomas. | | 8 | * by the 3am Software Foundry ("3am"). It was developed by Matt Thomas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.59 2010/04/01 00:24:41 tls Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.60 2012/01/19 13:13:48 liamjfoy Exp $"); |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | #include <sys/malloc.h> | | 37 | #include <sys/malloc.h> |
38 | #include <sys/mbuf.h> | | 38 | #include <sys/mbuf.h> |
39 | #include <sys/domain.h> | | 39 | #include <sys/domain.h> |
40 | #include <sys/protosw.h> | | 40 | #include <sys/protosw.h> |
41 | #include <sys/socket.h> | | 41 | #include <sys/socket.h> |
42 | #include <sys/socketvar.h> | | 42 | #include <sys/socketvar.h> |
43 | #include <sys/errno.h> | | 43 | #include <sys/errno.h> |
44 | #include <sys/time.h> | | 44 | #include <sys/time.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/pool.h> | | 46 | #include <sys/pool.h> |
| @@ -65,27 +65,26 @@ __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v | | | @@ -65,27 +65,26 @@ __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v |
65 | | | 65 | |
66 | struct ipflow { | | 66 | struct ipflow { |
67 | LIST_ENTRY(ipflow) ipf_list; /* next in active list */ | | 67 | LIST_ENTRY(ipflow) ipf_list; /* next in active list */ |
68 | LIST_ENTRY(ipflow) ipf_hash; /* next ipflow in bucket */ | | 68 | LIST_ENTRY(ipflow) ipf_hash; /* next ipflow in bucket */ |
69 | struct in_addr ipf_dst; /* destination address */ | | 69 | struct in_addr ipf_dst; /* destination address */ |
70 | struct in_addr ipf_src; /* source address */ | | 70 | struct in_addr ipf_src; /* source address */ |
71 | uint8_t ipf_tos; /* type-of-service */ | | 71 | uint8_t ipf_tos; /* type-of-service */ |
72 | struct route ipf_ro; /* associated route entry */ | | 72 | struct route ipf_ro; /* associated route entry */ |
73 | u_long ipf_uses; /* number of uses in this period */ | | 73 | u_long ipf_uses; /* number of uses in this period */ |
74 | u_long ipf_last_uses; /* number of uses in last period */ | | 74 | u_long ipf_last_uses; /* number of uses in last period */ |
75 | u_long ipf_dropped; /* ENOBUFS retured by if_output */ | | 75 | u_long ipf_dropped; /* ENOBUFS retured by if_output */ |
76 | u_long ipf_errors; /* other errors returned by if_output */ | | 76 | u_long ipf_errors; /* other errors returned by if_output */ |
77 | u_int ipf_timer; /* lifetime timer */ | | 77 | u_int ipf_timer; /* lifetime timer */ |
78 | time_t ipf_start; /* creation time */ | | | |
79 | }; | | 78 | }; |
80 | | | 79 | |
81 | #define IPFLOW_HASHBITS 6 /* should not be a multiple of 8 */ | | 80 | #define IPFLOW_HASHBITS 6 /* should not be a multiple of 8 */ |
82 | | | 81 | |
83 | static struct pool ipflow_pool; | | 82 | static struct pool ipflow_pool; |
84 | | | 83 | |
85 | LIST_HEAD(ipflowhead, ipflow); | | 84 | LIST_HEAD(ipflowhead, ipflow); |
86 | | | 85 | |
87 | #define IPFLOW_TIMER (5 * PR_SLOWHZ) | | 86 | #define IPFLOW_TIMER (5 * PR_SLOWHZ) |
88 | #define IPFLOW_DEFAULT_HASHSIZE (1 << IPFLOW_HASHBITS) | | 87 | #define IPFLOW_DEFAULT_HASHSIZE (1 << IPFLOW_HASHBITS) |
89 | | | 88 | |
90 | static struct ipflowhead *ipflowtable = NULL; | | 89 | static struct ipflowhead *ipflowtable = NULL; |
91 | static struct ipflowhead ipflowlist; | | 90 | static struct ipflowhead ipflowlist; |
| @@ -471,27 +470,27 @@ ipflow_create(const struct route *ro, st | | | @@ -471,27 +470,27 @@ ipflow_create(const struct route *ro, st |
471 | rtcache_free(&ipf->ipf_ro); | | 470 | rtcache_free(&ipf->ipf_ro); |
472 | ipf->ipf_uses = ipf->ipf_last_uses = 0; | | 471 | ipf->ipf_uses = ipf->ipf_last_uses = 0; |
473 | ipf->ipf_errors = ipf->ipf_dropped = 0; | | 472 | ipf->ipf_errors = ipf->ipf_dropped = 0; |
474 | } | | 473 | } |
475 | | | 474 | |
476 | /* | | 475 | /* |
477 | * Fill in the updated information. | | 476 | * Fill in the updated information. |
478 | */ | | 477 | */ |
479 | rtcache_copy(&ipf->ipf_ro, ro); | | 478 | rtcache_copy(&ipf->ipf_ro, ro); |
480 | ipf->ipf_dst = ip->ip_dst; | | 479 | ipf->ipf_dst = ip->ip_dst; |
481 | ipf->ipf_src = ip->ip_src; | | 480 | ipf->ipf_src = ip->ip_src; |
482 | ipf->ipf_tos = ip->ip_tos; | | 481 | ipf->ipf_tos = ip->ip_tos; |
483 | PRT_SLOW_ARM(ipf->ipf_timer, IPFLOW_TIMER); | | 482 | PRT_SLOW_ARM(ipf->ipf_timer, IPFLOW_TIMER); |
484 | ipf->ipf_start = time_uptime; | | 483 | |
485 | /* | | 484 | /* |
486 | * Insert into the approriate bucket of the flow table. | | 485 | * Insert into the approriate bucket of the flow table. |
487 | */ | | 486 | */ |
488 | hash = ipflow_hash(ip); | | 487 | hash = ipflow_hash(ip); |
489 | s = splnet(); | | 488 | s = splnet(); |
490 | IPFLOW_INSERT(&ipflowtable[hash], ipf); | | 489 | IPFLOW_INSERT(&ipflowtable[hash], ipf); |
491 | splx(s); | | 490 | splx(s); |
492 | } | | 491 | } |
493 | | | 492 | |
494 | int | | 493 | int |
495 | ipflow_invalidate_all(int new_size) | | 494 | ipflow_invalidate_all(int new_size) |
496 | { | | 495 | { |
497 | struct ipflow *ipf, *next_ipf; | | 496 | struct ipflow *ipf, *next_ipf; |