alias_sctp.h revision 188294
1186543Spiso/** 2186543Spiso * @file alias_sctp.h 3186543Spiso * Copyright (c) 2008, Centre for Advanced Internet Architectures 4186543Spiso * Swinburne University of Technology, Melbourne, Australia 5186543Spiso * (CRICOS number 00111D). 6186543Spiso * 7186543Spiso * Redistribution and use in source and binary forms, with or without 8186543Spiso * modification, are permitted provided that the following conditions 9186543Spiso * are met: 10186543Spiso * 1. Redistributions of source code must retain the above copyright 11186543Spiso * notice, this list of conditions and the following disclaimer. 12186543Spiso * 2. Redistributions in binary form must reproduce the above copyright 13186543Spiso * notice, this list of conditions and the following disclaimer in the 14186543Spiso * documentation and/or other materials provided with the distribution. 15186543Spiso * 3. The names of the authors, the "Centre for Advanced Internet Architectures" 16186543Spiso * and "Swinburne University of Technology" may not be used to endorse 17186543Spiso * or promote products derived from this software without specific 18186543Spiso * prior written permission. 19186543Spiso * 20186543Spiso * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND 21186543Spiso * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22186543Spiso * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23186543Spiso * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 24186543Spiso * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25186543Spiso * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26186543Spiso * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27186543Spiso * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28186543Spiso * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29186543Spiso * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30186543Spiso * SUCH DAMAGE. 31186543Spiso * 32188294Spiso * Alias_sctp forms part of the libalias kernel module to handle 33188294Spiso * Network Address Translation (NAT) for the SCTP protocol. 34188294Spiso * 35188294Spiso * This software was developed by David A. Hayes 36188294Spiso * with leadership and advice from Jason But 37188294Spiso * 38188294Spiso * The design is outlined in CAIA technical report number 080618A 39188294Spiso * (D. Hayes and J. But, "Alias_sctp Version 0.1: SCTP NAT implementation in IPFW") 40188294Spiso * 41188294Spiso * Development is part of the CAIA SONATA project, 42188294Spiso * proposed by Jason But and Grenville Armitage: 43188294Spiso * http://caia.swin.edu.au/urp/sonata/ 44188294Spiso * 45188294Spiso * 46188294Spiso * This project has been made possible in part by a grant from 47188294Spiso * the Cisco University Research Program Fund at Community 48188294Spiso * Foundation Silicon Valley. 49188294Spiso * 50186543Spiso */ 51188294Spiso 52188294Spiso/* $FreeBSD: head/sys/netinet/libalias/alias_sctp.h 188294 2009-02-07 18:49:42Z piso $ */ 53188294Spiso 54186543Spiso#ifndef _ALIAS_SCTP_H_ 55186543Spiso#define _ALIAS_SCTP_H_ 56186543Spiso 57186543Spiso#include <sys/param.h> 58186543Spiso#ifdef _KERNEL 59186543Spiso#include <sys/malloc.h> 60186543Spiso#include <sys/module.h> 61186543Spiso#include <sys/kernel.h> 62186543Spiso#include <sys/proc.h> 63186543Spiso#include <sys/uio.h> 64186543Spiso#include <sys/socketvar.h> 65186543Spiso#include <sys/syslog.h> 66186543Spiso#endif // #ifdef _KERNEL 67186543Spiso#include <sys/types.h> 68186543Spiso 69186543Spiso#include <sys/queue.h> 70186543Spiso#include <sys/types.h> 71186543Spiso#include <sys/time.h> 72186543Spiso 73186543Spiso#include <netinet/in_systm.h> 74186543Spiso#include <netinet/in.h> 75186543Spiso#include <netinet/ip.h> 76186543Spiso 77186543Spiso/** 78186543Spiso * These are defined in sctp_os_bsd.h, but it can't be included due to its local file 79186543Spiso * inclusion, so I'm defining them here. 80186543Spiso * 81186543Spiso */ 82186543Spiso#include <machine/cpufunc.h> 83186543Spiso#include <machine/cpu.h> 84186543Spiso/* The packed define for 64 bit platforms */ 85186543Spiso#ifndef SCTP_PACKED 86186543Spiso#define SCTP_PACKED __attribute__((packed)) 87186543Spiso#endif //#ifndef SCTP_PACKED 88186543Spiso#ifndef SCTP_UNUSED 89186543Spiso#define SCTP_UNUSED __attribute__((unused)) 90186543Spiso#endif //#ifndef SCTP_UNUSED 91186543Spiso 92186543Spiso 93186543Spiso#include <netinet/sctp.h> 94186543Spiso//#include <netinet/sctp_os_bsd.h> --might be needed later for mbuf stuff 95186543Spiso#include <netinet/sctp_header.h> 96186543Spiso 97186543Spiso#ifndef _KERNEL 98186543Spiso#include <stdlib.h> 99186543Spiso#include <stdio.h> 100186543Spiso#include <curses.h> 101186543Spiso#endif //#ifdef _KERNEL 102186543Spiso 103186543Spiso 104186543Spiso#define LINK_SCTP IPPROTO_SCTP 105186543Spiso 106186543Spiso 107186543Spiso#define SN_TO_LOCAL 0 /**< packet traveling from global to local */ 108186543Spiso#define SN_TO_GLOBAL 1 /**< packet traveling from local to global */ 109186543Spiso#define SN_TO_NODIR 99 /**< used where direction is not important */ 110186543Spiso 111186543Spiso#define SN_NAT_PKT 0x0000 /**< Network Address Translate packet */ 112186543Spiso#define SN_DROP_PKT 0x0001 /**< drop packet (don't forward it) */ 113186543Spiso#define SN_PROCESSING_ERROR 0x0003 /**< Packet processing error */ 114186543Spiso#define SN_REPLY_ABORT 0x0010 /**< Reply with ABORT to sender (don't forward it) */ 115186543Spiso#define SN_SEND_ABORT 0x0020 /**< Send ABORT to destination */ 116186543Spiso#define SN_TX_ABORT 0x0030 /**< mask for transmitting abort */ 117186543Spiso#define SN_REFLECT_ERROR 0x0100 /**< Reply with ERROR to sender on OOTB packet Tbit set */ 118186543Spiso#define SN_REPLY_ERROR 0x0200 /**< Reply with ERROR to sender on ASCONF clash */ 119186543Spiso#define SN_TX_ERROR 0x0300 /**< mask for transmitting error */ 120186543Spiso 121186543Spiso 122186543Spiso#define PKT_ALIAS_RESPOND 0x1000 /**< Signal to libalias that there is a response packet to send */ 123186543Spiso/* 124186543Spiso * Data structures 125186543Spiso */ 126186543Spiso 127186543Spiso/** 128186543Spiso * @brief sctp association information 129186543Spiso * 130186543Spiso * Structure that contains information about a particular sctp association 131186543Spiso * currently under Network Address Translation. 132186543Spiso * Information is stored in network byte order (as is libalias)*** 133186543Spiso */ 134186543Spisostruct sctp_nat_assoc { 135188294Spiso uint32_t l_vtag; /**< local side verification tag */ 136188294Spiso uint16_t l_port; /**< local side port number */ 137188294Spiso uint32_t g_vtag; /**< global side verification tag */ 138188294Spiso uint16_t g_port; /**< global side port number */ 139188294Spiso struct in_addr l_addr; /**< local ip address */ 140188294Spiso struct in_addr a_addr; /**< alias ip address */ 141188294Spiso int state; /**< current state of NAT association */ 142188294Spiso int TableRegister; /**< stores which look up tables association is registered in */ 143188294Spiso int exp; /**< timer expiration in seconds from uptime */ 144188294Spiso int exp_loc; /**< current location in timer_Q */ 145188294Spiso int num_Gaddr; /**< number of global IP addresses in the list */ 146188294Spiso LIST_HEAD(sctpGlobalAddresshead,sctp_GlobalAddress) Gaddr; /**< List of global addresses */ 147188294Spiso LIST_ENTRY (sctp_nat_assoc) list_L; /**< Linked list of pointers for Local table*/ 148188294Spiso LIST_ENTRY (sctp_nat_assoc) list_G; /**< Linked list of pointers for Global table */ 149188294Spiso LIST_ENTRY (sctp_nat_assoc) timer_Q; /**< Linked list of pointers for timer Q */ 150186543Spiso//Using libalias locking 151186543Spiso}; 152186543Spiso 153186543Spisostruct sctp_GlobalAddress { 154188294Spiso struct in_addr g_addr; 155188294Spiso LIST_ENTRY (sctp_GlobalAddress) list_Gaddr; /**< Linked list of pointers for Global table */ 156186543Spiso}; 157186543Spiso 158186543Spiso/** 159186543Spiso * @brief SCTP chunk of interest 160186543Spiso * 161186543Spiso * The only chunks whose contents are of any interest are the INIT and ASCONF_AddIP 162186543Spiso */ 163186543Spisounion sctpChunkOfInt { 164188294Spiso struct sctp_init *Init; /**< Pointer to Init Chunk */ 165188294Spiso struct sctp_init_ack *InitAck; /**< Pointer to Init Chunk */ 166188294Spiso struct sctp_paramhdr *Asconf; /**< Pointer to ASCONF chunk */ 167186543Spiso}; 168186543Spiso 169186543Spiso 170186543Spiso/** 171186543Spiso * @brief SCTP message 172186543Spiso * 173186543Spiso * Structure containing the relevant information from the SCTP message 174186543Spiso */ 175186543Spisostruct sctp_nat_msg { 176188294Spiso uint16_t msg; /**< one of the key messages defined above */ 177186543Spiso#ifdef INET6 178188294Spiso // struct ip6_hdr *ip_hdr; /**< pointer to ip packet header */ /*no inet6 support yet*/ 179186543Spiso#else 180188294Spiso struct ip *ip_hdr; /**< pointer to ip packet header */ 181186543Spiso#endif //#ifdef INET6 182188294Spiso struct sctphdr *sctp_hdr; /**< pointer to sctp common header */ 183188294Spiso union sctpChunkOfInt sctpchnk; /**< union of pointers to the chunk of interest */ 184188294Spiso int chunk_length; /**< length of chunk of interest */ 185186543Spiso}; 186186543Spiso 187186543Spiso 188186543Spiso/** 189186543Spiso * @brief sctp nat timer queue structure 190186543Spiso * 191186543Spiso */ 192186543Spiso 193186543Spisostruct sctp_nat_timer { 194188294Spiso int loc_time; /**< time in seconds for the current location in the queue */ 195188294Spiso int cur_loc; /**< index of the current location in the circular queue */ 196188294Spiso LIST_HEAD(sctpTimerQ,sctp_nat_assoc) *TimerQ; /**< List of associations at this position in the timer Q */ 197186543Spiso}; 198186543Spiso 199186543Spiso 200186543Spiso 201186543Spiso#endif //#ifndef _ALIAS_SCTP_H 202