xref: /titanic_44/usr/src/uts/common/inet/ilb/ilb_nat.h (revision 1e4c938b57d1656808e4112127ff1dce3eba5314)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
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 #ifndef _INET_ILB_NAT_H
28 #define	_INET_ILB_NAT_H
29 
30 #include <sys/vmem.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* Maximum number of NAT source address of a rule. */
37 #define	ILB_MAX_NAT_SRC	10
38 
39 /* NAT source address hash table. */
40 typedef struct ilb_nat_src_hash_s {
41 	list_t		nsh_head;
42 	kmutex_t	nsh_lock;
43 	char		nsh_pad[64 - sizeof (list_t) - sizeof (kmutex_t)];
44 } ilb_nat_src_hash_t;
45 
46 /*
47  * NAT source entry.  Hold the port space for a source addr/back end server
48  * pair.
49  */
50 typedef struct ilb_nat_src_entry_s {
51 	in6_addr_t	nse_src_addr;
52 	in6_addr_t	nse_serv_addr;
53 	in_port_t	nse_port;
54 	vmem_t		*nse_port_arena;
55 	uint32_t	nse_refcnt;
56 	kmutex_t	*nse_nsh_lock;
57 	list_node_t	nse_link;
58 } ilb_nat_src_entry_t;
59 
60 /* Struct to hold all NAT source entry of a back end server. */
61 typedef struct ilb_nat_src_s {
62 	uint16_t		cur;
63 	uint16_t		num_src;
64 	ilb_nat_src_entry_t	*src_list[ILB_MAX_NAT_SRC];
65 } ilb_nat_src_t;
66 
67 extern int ilb_create_nat_src(ilb_stack_t *ilbs, ilb_nat_src_t **,
68     const in6_addr_t *, in_port_t, const in6_addr_t *, int);
69 extern void ilb_destroy_nat_src(ilb_nat_src_t **);
70 extern void ilb_nat_src_timer(void *);
71 extern void ilb_nat_src_init(ilb_stack_t *);
72 extern void ilb_nat_src_fini(ilb_stack_t *);
73 
74 extern ilb_nat_src_entry_t *ilb_alloc_nat_addr(ilb_nat_src_t *, in6_addr_t *,
75     in_port_t *, uint16_t *);
76 
77 extern void ilb_full_nat(int, void *, int, void *, ilb_nat_info_t *, uint32_t,
78     uint32_t, boolean_t);
79 extern void ilb_half_nat(int, void *, int, void *, ilb_nat_info_t *, uint32_t,
80     uint32_t, boolean_t);
81 
82 extern void ilb_nat_icmpv4(mblk_t *, ipha_t *, icmph_t *, ipha_t *,
83     in_port_t *, in_port_t *, ilb_nat_info_t *, uint32_t, boolean_t);
84 extern void ilb_nat_icmpv6(mblk_t *, ip6_t *, icmp6_t *, ip6_t *,
85     in_port_t *, in_port_t *, ilb_nat_info_t *, boolean_t);
86 
87 extern uint32_t ilb_pseudo_sum_v6(ip6_t *, uint8_t);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* _INET_ILB_NAT_H */
94