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