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