alias_skinny.c revision ae9ed83297460a052aeae98394d473e83aeafd1f
/*-
*
* Copyright (c) 2002, 2003 MarcusCom, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Author: Joe Marcus Clarke <marcus@FreeBSD.org>
*
* $FreeBSD: src/sys/netinet/libalias/alias_skinny.c,v 1.14.8.1 2009/04/15 03:14:26 kensmith Exp $
*/
#ifdef _KERNEL
#else
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#endif
#include <netinet/in_systm.h>
#ifdef _KERNEL
#else
#include "alias_local.h"
#include "alias_mod.h"
#endif
static void
static int
{
return (-1);
return (0);
return (-1);
}
static int
{
return (0);
}
struct proto_handler handlers[] = {
{
.pri = 110,
.fingerprint = &fingerprint,
},
{ EOH }
};
static int
{
int error;
switch (type) {
case MOD_LOAD:
error = 0;
break;
case MOD_UNLOAD:
error = 0;
break;
default:
}
return (error);
}
#ifdef _KERNEL
static
#endif
};
#ifdef _KERNEL
#endif
/*
* alias_skinny.c handles the translation for the Cisco Skinny Station
* protocol. Skinny typically uses TCP port 2000 to set up calls between
* a Cisco Call Manager and a Cisco IP phone. When a phone comes on line,
* it first needs to register with the Call Manager. To do this it sends
* a registration message. This message contains the IP address of the
* IP phone. This message must then be translated to reflect our global
* IP address. Along with the registration message (and usually in the
* same packet), the phone sends an IP port message. This message indicates
* the TCP port over which it will communicate.
*
* When a call is placed from the phone, the Call Manager will send an
* Open Receive Channel message to the phone to let the caller know someone
* has answered. The phone then sends back an Open Receive Channel
* Acknowledgement. In this packet, the phone sends its IP address again,
* and the UDP port over which the voice traffic should flow. These values
* need translation. Right after the Open Receive Channel Acknowledgement,
* the Call Manager sends a Start Media Transmission message indicating the
* call is connected. This message contains the IP address and UDP port
* number of the remote (called) party. Once this message is translated, the
* call can commence. The called part sends the first UDP packet to the
* calling phone at the pre-arranged UDP port in the Open Receive Channel
* Acknowledgement.
*
* Skinny is a Cisco-proprietary protocol and is a trademark of Cisco Systems,
* Inc. All rights reserved.
*/
/* #define LIBALIAS_DEBUG 1 */
/* Message types that need translating */
#define REG_MSG 0x00000001
#define IP_PORT_MSG 0x00000002
#define OPNRCVCH_ACK 0x00000022
#define START_MEDIATX 0x0000008a
struct skinny_header {
};
struct RegisterMessage {
char devName [16];
};
struct IpPortMessage {
* numbers */
};
struct OpenReceiveChannelAck {
};
struct StartMediaTransmission {
};
typedef enum {
ClientToServer = 0,
ServerToClient = 1
static int
{
(void)direction;
#ifdef _KERNEL
#else
#endif
return (0);
}
static int
{
(void)pip;
(void)tc;
(void)lnk;
(void)direction;
/*
* XXX I should probably handle in bound global translations as
* well.
*/
return (0);
}
static int
{
(void)direction;
#ifdef _KERNEL
#else
#endif
return (0);
}
static int
{
struct alias_link *opnrcv_lnk;
(void)lnk;
(void)direction;
IPPROTO_UDP, 1);
#ifdef _KERNEL
#else
#endif
return (0);
}
static void
{
struct skinny_header *sd;
lip = -1;
/*
* XXX This direction is reserved for future use. I still need to
* handle the scenario where the call manager is on the inside, and
* the calling phone is on the global outside.
*/
} else {
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Invalid port number, not a Skinny packet\n");
#endif
return;
}
/*
* Skinny packets can contain many messages. We need to loop
* through the packet using len to determine message boundaries.
* This comes into play big time with port messages being in the
* same packet as register messages. Also, open receive channel
* acks are usually buried in a pakcet some 400 bytes long.
*/
while (dlen >= skinny_hdr_len) {
t = len;
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Not a skinny packet, invalid length \n");
#endif
return;
}
switch (msgId) {
case REG_MSG: {
struct RegisterMessage *reg_mesg;
if (len < (int)sizeof(struct RegisterMessage)) {
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Not a skinny packet, bad registration message\n");
#endif
return;
}
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Received a register message");
#endif
break;
}
case IP_PORT_MSG: {
struct IpPortMessage *port_mesg;
if (len < (int)sizeof(struct IpPortMessage)) {
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Not a skinny packet, port message\n");
#endif
return;
}
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Received ipport message\n");
#endif
break;
}
case OPNRCVCH_ACK: {
struct OpenReceiveChannelAck *opnrcvchn_ack;
if (len < (int)sizeof(struct OpenReceiveChannelAck)) {
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Not a skinny packet, packet,OpnRcvChnAckMsg\n");
#endif
return;
}
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Received open rcv channel msg\n");
#endif
break;
}
case START_MEDIATX: {
struct StartMediaTransmission *startmedia_tx;
if (len < (int)sizeof(struct StartMediaTransmission)) {
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Not a skinny packet,StartMediaTx Message\n");
#endif
return;
}
if (lip == -1) {
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: received a"
" packet,StartMediaTx Message before"
" packet,OpnRcvChnAckMsg\n"
#endif
return;
}
#ifdef LIBALIAS_DEBUG
"PacketAlias/Skinny: Received start media trans msg\n");
#endif
break;
}
default:
break;
}
/* Place the pointer at the next message in the packet. */
}
}