3 * Copyright (c) 2008, Centre for Advanced Internet Architectures
4 * Swinburne University of Technology, Melbourne, Australia
5 * (CRICOS number 00111D).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the authors, the "Centre for Advanced Internet Architectures"
16 * and "Swinburne University of Technology" may not be used to endorse
17 * or promote products derived from this software without specific
18 * prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Alias_sctp forms part of the libalias kernel module to handle
33 * Network Address Translation (NAT) for the SCTP protocol.
35 * This software was developed by David A. Hayes
36 * with leadership and advice from Jason But
38 * The design is outlined in CAIA technical report number 080618A
39 * (D. Hayes and J. But, "Alias_sctp Version 0.1: SCTP NAT implementation in IPFW")
41 * Development is part of the CAIA SONATA project,
42 * proposed by Jason But and Grenville Armitage:
43 * http://caia.swin.edu.au/urp/sonata/
46 * This project has been made possible in part by a grant from
47 * the Cisco University Research Program Fund at Community
48 * Foundation Silicon Valley.
54 #ifndef _ALIAS_SCTP_H_
55 #define _ALIAS_SCTP_H_
57 #include <sys/param.h>
59 #include <sys/malloc.h>
60 #include <sys/module.h>
61 #include <sys/kernel.h>
64 #include <sys/socketvar.h>
65 #include <sys/syslog.h>
66 #endif // #ifdef _KERNEL
67 #include <sys/types.h>
69 #include <sys/queue.h>
70 #include <sys/types.h>
73 #include <netinet/in_systm.h>
74 #include <netinet/in.h>
75 #include <netinet/ip.h>
78 * These are defined in sctp_os_bsd.h, but it can't be included due to its local file
79 * inclusion, so I'm defining them here.
82 #include <machine/cpufunc.h>
83 #include <machine/cpu.h>
84 /* The packed define for 64 bit platforms */
86 #define SCTP_PACKED __attribute__((packed))
87 #endif //#ifndef SCTP_PACKED
89 #define SCTP_UNUSED __attribute__((unused))
90 #endif //#ifndef SCTP_UNUSED
93 #include <netinet/sctp.h>
94 //#include <netinet/sctp_os_bsd.h> --might be needed later for mbuf stuff
95 #include <netinet/sctp_header.h>
101 #endif //#ifdef _KERNEL
104 #define LINK_SCTP IPPROTO_SCTP
107 #define SN_TO_LOCAL 0 /**< packet traveling from global to local */
108 #define SN_TO_GLOBAL 1 /**< packet traveling from local to global */
109 #define SN_TO_NODIR 99 /**< used where direction is not important */
111 #define SN_NAT_PKT 0x0000 /**< Network Address Translate packet */
112 #define SN_DROP_PKT 0x0001 /**< drop packet (don't forward it) */
113 #define SN_PROCESSING_ERROR 0x0003 /**< Packet processing error */
114 #define SN_REPLY_ABORT 0x0010 /**< Reply with ABORT to sender (don't forward it) */
115 #define SN_SEND_ABORT 0x0020 /**< Send ABORT to destination */
116 #define SN_TX_ABORT 0x0030 /**< mask for transmitting abort */
117 #define SN_REFLECT_ERROR 0x0100 /**< Reply with ERROR to sender on OOTB packet Tbit set */
118 #define SN_REPLY_ERROR 0x0200 /**< Reply with ERROR to sender on ASCONF clash */
119 #define SN_TX_ERROR 0x0300 /**< mask for transmitting error */
122 #define PKT_ALIAS_RESPOND 0x1000 /**< Signal to libalias that there is a response packet to send */
128 * @brief sctp association information
130 * Structure that contains information about a particular sctp association
131 * currently under Network Address Translation.
132 * Information is stored in network byte order (as is libalias)***
134 struct sctp_nat_assoc {
135 uint32_t l_vtag; /**< local side verification tag */
136 uint16_t l_port; /**< local side port number */
137 uint32_t g_vtag; /**< global side verification tag */
138 uint16_t g_port; /**< global side port number */
139 struct in_addr l_addr; /**< local ip address */
140 struct in_addr a_addr; /**< alias ip address */
141 int state; /**< current state of NAT association */
142 int TableRegister; /**< stores which look up tables association is registered in */
143 int exp; /**< timer expiration in seconds from uptime */
144 int exp_loc; /**< current location in timer_Q */
145 int num_Gaddr; /**< number of global IP addresses in the list */
146 LIST_HEAD(sctpGlobalAddresshead,sctp_GlobalAddress) Gaddr; /**< List of global addresses */
147 LIST_ENTRY (sctp_nat_assoc) list_L; /**< Linked list of pointers for Local table*/
148 LIST_ENTRY (sctp_nat_assoc) list_G; /**< Linked list of pointers for Global table */
149 LIST_ENTRY (sctp_nat_assoc) timer_Q; /**< Linked list of pointers for timer Q */
150 //Using libalias locking
153 struct sctp_GlobalAddress {
154 struct in_addr g_addr;
155 LIST_ENTRY (sctp_GlobalAddress) list_Gaddr; /**< Linked list of pointers for Global table */
159 * @brief SCTP chunk of interest
161 * The only chunks whose contents are of any interest are the INIT and ASCONF_AddIP
163 union sctpChunkOfInt {
164 struct sctp_init *Init; /**< Pointer to Init Chunk */
165 struct sctp_init_ack *InitAck; /**< Pointer to Init Chunk */
166 struct sctp_paramhdr *Asconf; /**< Pointer to ASCONF chunk */
171 * @brief SCTP message
173 * Structure containing the relevant information from the SCTP message
175 struct sctp_nat_msg {
176 uint16_t msg; /**< one of the key messages defined above */
178 // struct ip6_hdr *ip_hdr; /**< pointer to ip packet header */ /*no inet6 support yet*/
180 struct ip *ip_hdr; /**< pointer to ip packet header */
181 #endif //#ifdef INET6
182 struct sctphdr *sctp_hdr; /**< pointer to sctp common header */
183 union sctpChunkOfInt sctpchnk; /**< union of pointers to the chunk of interest */
184 int chunk_length; /**< length of chunk of interest */
189 * @brief sctp nat timer queue structure
193 struct sctp_nat_timer {
194 int loc_time; /**< time in seconds for the current location in the queue */
195 int cur_loc; /**< index of the current location in the circular queue */
196 LIST_HEAD(sctpTimerQ,sctp_nat_assoc) *TimerQ; /**< List of associations at this position in the timer Q */
201 #endif //#ifndef _ALIAS_SCTP_H