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