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/types.h>
28 #include <sys/conf.h>
29 #include <sys/time.h>
30 #include <sys/taskq.h>
31 #include <sys/cmn_err.h>
32 #include <sys/sdt.h>
33 #include <sys/atomic.h>
34 #include <netinet/in.h>
35 #include <inet/ip.h>
36 #include <inet/ip6.h>
37 #include <inet/tcp.h>
38 #include <inet/udp_impl.h>
39 #include <inet/ilb.h>
40
41 #include "ilb_stack.h"
42 #include "ilb_impl.h"
43 #include "ilb_conn.h"
44 #include "ilb_nat.h"
45
46 /*
283 mutex_exit(&timer->tid_lock);
284 } else {
285 timer->tid = timeout(ilb_conn_timer, arg,
286 SEC_TO_TICK(ilb_conn_cache_timeout));
287 mutex_exit(&timer->tid_lock);
288 }
289 }
290
291 void
292 ilb_conn_hash_init(ilb_stack_t *ilbs)
293 {
294 extern pri_t minclsyspri;
295 int i, part;
296 ilb_timer_t *tm;
297 char tq_name[TASKQ_NAMELEN];
298
299 /*
300 * If ilbs->ilbs_conn_hash_size is not a power of 2, bump it up to
301 * the next power of 2.
302 */
303 if (ilbs->ilbs_conn_hash_size & (ilbs->ilbs_conn_hash_size - 1)) {
304 for (i = 0; i < 31; i++) {
305 if (ilbs->ilbs_conn_hash_size < (1 << i))
306 break;
307 }
308 ilbs->ilbs_conn_hash_size = 1 << i;
309 }
310
311 /*
312 * Can sleep since this should be called when a rule is being added,
313 * hence we are not in interrupt context.
314 */
315 ilbs->ilbs_c2s_conn_hash = kmem_zalloc(sizeof (ilb_conn_hash_t) *
316 ilbs->ilbs_conn_hash_size, KM_SLEEP);
317 ilbs->ilbs_s2c_conn_hash = kmem_zalloc(sizeof (ilb_conn_hash_t) *
318 ilbs->ilbs_conn_hash_size, KM_SLEEP);
319
320 for (i = 0; i < ilbs->ilbs_conn_hash_size; i++) {
321 mutex_init(&ilbs->ilbs_c2s_conn_hash[i].ilb_conn_hash_lock,
322 NULL, MUTEX_DEFAULT, NULL);
323 }
1342 (void) taskq_dispatch(timer->ilbs->ilbs_sticky_taskq,
1343 ilb_sticky_cleanup, arg, TQ_SLEEP);
1344 mutex_enter(&timer->tid_lock);
1345 if (timer->tid == 0) {
1346 mutex_exit(&timer->tid_lock);
1347 } else {
1348 timer->tid = timeout(ilb_sticky_timer, arg,
1349 SEC_TO_TICK(ilb_sticky_timeout));
1350 mutex_exit(&timer->tid_lock);
1351 }
1352 }
1353
1354 void
1355 ilb_sticky_hash_init(ilb_stack_t *ilbs)
1356 {
1357 extern pri_t minclsyspri;
1358 int i, part;
1359 char tq_name[TASKQ_NAMELEN];
1360 ilb_timer_t *tm;
1361
1362 if (ilbs->ilbs_sticky_hash_size & (ilbs->ilbs_sticky_hash_size - 1)) {
1363 for (i = 0; i < 31; i++) {
1364 if (ilbs->ilbs_sticky_hash_size < (1 << i))
1365 break;
1366 }
1367 ilbs->ilbs_sticky_hash_size = 1 << i;
1368 }
1369
1370 ilbs->ilbs_sticky_hash = kmem_zalloc(sizeof (ilb_sticky_hash_t) *
1371 ilbs->ilbs_sticky_hash_size, KM_SLEEP);
1372 for (i = 0; i < ilbs->ilbs_sticky_hash_size; i++) {
1373 mutex_init(&ilbs->ilbs_sticky_hash[i].sticky_lock, NULL,
1374 MUTEX_DEFAULT, NULL);
1375 list_create(&ilbs->ilbs_sticky_hash[i].sticky_head,
1376 sizeof (ilb_sticky_t),
1377 offsetof(ilb_sticky_t, list));
1378 }
1379
1380 if (ilb_sticky_cache == NULL)
1381 ilb_sticky_cache_init();
1382
|
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/types.h>
29 #include <sys/conf.h>
30 #include <sys/time.h>
31 #include <sys/taskq.h>
32 #include <sys/cmn_err.h>
33 #include <sys/sdt.h>
34 #include <sys/atomic.h>
35 #include <netinet/in.h>
36 #include <inet/ip.h>
37 #include <inet/ip6.h>
38 #include <inet/tcp.h>
39 #include <inet/udp_impl.h>
40 #include <inet/ilb.h>
41
42 #include "ilb_stack.h"
43 #include "ilb_impl.h"
44 #include "ilb_conn.h"
45 #include "ilb_nat.h"
46
47 /*
284 mutex_exit(&timer->tid_lock);
285 } else {
286 timer->tid = timeout(ilb_conn_timer, arg,
287 SEC_TO_TICK(ilb_conn_cache_timeout));
288 mutex_exit(&timer->tid_lock);
289 }
290 }
291
292 void
293 ilb_conn_hash_init(ilb_stack_t *ilbs)
294 {
295 extern pri_t minclsyspri;
296 int i, part;
297 ilb_timer_t *tm;
298 char tq_name[TASKQ_NAMELEN];
299
300 /*
301 * If ilbs->ilbs_conn_hash_size is not a power of 2, bump it up to
302 * the next power of 2.
303 */
304 if (!ISP2(ilbs->ilbs_conn_hash_size)) {
305 for (i = 0; i < 31; i++) {
306 if (ilbs->ilbs_conn_hash_size < (1 << i))
307 break;
308 }
309 ilbs->ilbs_conn_hash_size = 1 << i;
310 }
311
312 /*
313 * Can sleep since this should be called when a rule is being added,
314 * hence we are not in interrupt context.
315 */
316 ilbs->ilbs_c2s_conn_hash = kmem_zalloc(sizeof (ilb_conn_hash_t) *
317 ilbs->ilbs_conn_hash_size, KM_SLEEP);
318 ilbs->ilbs_s2c_conn_hash = kmem_zalloc(sizeof (ilb_conn_hash_t) *
319 ilbs->ilbs_conn_hash_size, KM_SLEEP);
320
321 for (i = 0; i < ilbs->ilbs_conn_hash_size; i++) {
322 mutex_init(&ilbs->ilbs_c2s_conn_hash[i].ilb_conn_hash_lock,
323 NULL, MUTEX_DEFAULT, NULL);
324 }
1343 (void) taskq_dispatch(timer->ilbs->ilbs_sticky_taskq,
1344 ilb_sticky_cleanup, arg, TQ_SLEEP);
1345 mutex_enter(&timer->tid_lock);
1346 if (timer->tid == 0) {
1347 mutex_exit(&timer->tid_lock);
1348 } else {
1349 timer->tid = timeout(ilb_sticky_timer, arg,
1350 SEC_TO_TICK(ilb_sticky_timeout));
1351 mutex_exit(&timer->tid_lock);
1352 }
1353 }
1354
1355 void
1356 ilb_sticky_hash_init(ilb_stack_t *ilbs)
1357 {
1358 extern pri_t minclsyspri;
1359 int i, part;
1360 char tq_name[TASKQ_NAMELEN];
1361 ilb_timer_t *tm;
1362
1363 if (!ISP2(ilbs->ilbs_sticky_hash_size)) {
1364 for (i = 0; i < 31; i++) {
1365 if (ilbs->ilbs_sticky_hash_size < (1 << i))
1366 break;
1367 }
1368 ilbs->ilbs_sticky_hash_size = 1 << i;
1369 }
1370
1371 ilbs->ilbs_sticky_hash = kmem_zalloc(sizeof (ilb_sticky_hash_t) *
1372 ilbs->ilbs_sticky_hash_size, KM_SLEEP);
1373 for (i = 0; i < ilbs->ilbs_sticky_hash_size; i++) {
1374 mutex_init(&ilbs->ilbs_sticky_hash[i].sticky_lock, NULL,
1375 MUTEX_DEFAULT, NULL);
1376 list_create(&ilbs->ilbs_sticky_hash[i].sticky_head,
1377 sizeof (ilb_sticky_t),
1378 offsetof(ilb_sticky_t, list));
1379 }
1380
1381 if (ilb_sticky_cache == NULL)
1382 ilb_sticky_cache_init();
1383
|