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