7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <sys/kmem.h>
28 #include <sys/ksynch.h>
29 #include <sys/systm.h>
30 #include <sys/socket.h>
31 #include <sys/disp.h>
32 #include <sys/taskq.h>
33 #include <sys/cmn_err.h>
34 #include <sys/strsun.h>
35 #include <sys/sdt.h>
36 #include <sys/atomic.h>
37 #include <netinet/in.h>
38 #include <inet/ip.h>
39 #include <inet/ip6.h>
40 #include <inet/tcp.h>
41 #include <inet/udp_impl.h>
42 #include <inet/kstatcom.h>
43
44 #include <inet/ilb_ip.h>
45 #include "ilb_alg.h"
46 #include "ilb_nat.h"
267
268 kstat_named_setstr(&server->iser_kstat.ip_address,
269 server->iser_ip_addr);
270 /* We never change the IP address */
271 ksp->ks_data_size += strlen(server->iser_ip_addr) + 1;
272
273 kstat_install(ksp);
274 return (ksp);
275 }
276
277 /* Initialize the rule hash table. */
278 static void
279 ilb_rule_hash_init(ilb_stack_t *ilbs)
280 {
281 int i;
282
283 /*
284 * If ilbs->ilbs_rule_hash_size is not a power of 2, bump it up to
285 * the next power of 2.
286 */
287 if (ilbs->ilbs_rule_hash_size & (ilbs->ilbs_rule_hash_size - 1)) {
288 for (i = 0; i < 31; i++) {
289 if (ilbs->ilbs_rule_hash_size < (1 << i))
290 break;
291 }
292 ilbs->ilbs_rule_hash_size = 1 << i;
293 }
294 ilbs->ilbs_g_hash = kmem_zalloc(sizeof (ilb_hash_t) *
295 ilbs->ilbs_rule_hash_size, KM_SLEEP);
296 for (i = 0; i < ilbs->ilbs_rule_hash_size; i++) {
297 mutex_init(&ilbs->ilbs_g_hash[i].ilb_hash_lock, NULL,
298 MUTEX_DEFAULT, NULL);
299 }
300 }
301
302 /* Clean up the rule hash table. */
303 static void
304 ilb_rule_hash_fini(ilb_stack_t *ilbs)
305 {
306 if (ilbs->ilbs_g_hash == NULL)
307 return;
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <sys/sysmacros.h>
28 #include <sys/kmem.h>
29 #include <sys/ksynch.h>
30 #include <sys/systm.h>
31 #include <sys/socket.h>
32 #include <sys/disp.h>
33 #include <sys/taskq.h>
34 #include <sys/cmn_err.h>
35 #include <sys/strsun.h>
36 #include <sys/sdt.h>
37 #include <sys/atomic.h>
38 #include <netinet/in.h>
39 #include <inet/ip.h>
40 #include <inet/ip6.h>
41 #include <inet/tcp.h>
42 #include <inet/udp_impl.h>
43 #include <inet/kstatcom.h>
44
45 #include <inet/ilb_ip.h>
46 #include "ilb_alg.h"
47 #include "ilb_nat.h"
268
269 kstat_named_setstr(&server->iser_kstat.ip_address,
270 server->iser_ip_addr);
271 /* We never change the IP address */
272 ksp->ks_data_size += strlen(server->iser_ip_addr) + 1;
273
274 kstat_install(ksp);
275 return (ksp);
276 }
277
278 /* Initialize the rule hash table. */
279 static void
280 ilb_rule_hash_init(ilb_stack_t *ilbs)
281 {
282 int i;
283
284 /*
285 * If ilbs->ilbs_rule_hash_size is not a power of 2, bump it up to
286 * the next power of 2.
287 */
288 if (!ISP2(ilbs->ilbs_rule_hash_size)) {
289 for (i = 0; i < 31; i++) {
290 if (ilbs->ilbs_rule_hash_size < (1 << i))
291 break;
292 }
293 ilbs->ilbs_rule_hash_size = 1 << i;
294 }
295 ilbs->ilbs_g_hash = kmem_zalloc(sizeof (ilb_hash_t) *
296 ilbs->ilbs_rule_hash_size, KM_SLEEP);
297 for (i = 0; i < ilbs->ilbs_rule_hash_size; i++) {
298 mutex_init(&ilbs->ilbs_g_hash[i].ilb_hash_lock, NULL,
299 MUTEX_DEFAULT, NULL);
300 }
301 }
302
303 /* Clean up the rule hash table. */
304 static void
305 ilb_rule_hash_fini(ilb_stack_t *ilbs)
306 {
307 if (ilbs->ilbs_g_hash == NULL)
308 return;
|