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