2003-09-23 07:42:33 +00:00
|
|
|
/*-
|
|
|
|
* alias_skinny.c
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*/
|
|
|
|
|
2005-05-05 19:27:32 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/param.h>
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#else
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include <errno.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-23 07:42:33 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
|
2005-05-05 19:27:32 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <netinet/libalias/alias_local.h>
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include <netinet/libalias/alias_mod.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#else
|
2003-09-23 07:42:33 +00:00
|
|
|
#include "alias_local.h"
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include "alias_mod.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
AliasHandleSkinny(struct libalias *, struct ip *, struct alias_link *);
|
|
|
|
|
|
|
|
static int
|
|
|
|
fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL)
|
|
|
|
return (-1);
|
|
|
|
if (la->skinnyPort != 0 && (ntohs(*ah->sport) == la->skinnyPort ||
|
|
|
|
ntohs(*ah->dport) == la->skinnyPort))
|
|
|
|
return (0);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah)
|
|
|
|
{
|
|
|
|
|
|
|
|
AliasHandleSkinny(la, pip, ah->lnk);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct proto_handler handlers[] = {
|
|
|
|
{
|
|
|
|
.pri = 110,
|
|
|
|
.dir = IN|OUT,
|
|
|
|
.proto = TCP,
|
|
|
|
.fingerprint = &fingerprint,
|
|
|
|
.protohandler = &protohandler
|
|
|
|
},
|
|
|
|
{ EOH }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
mod_handler(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
error = 0;
|
|
|
|
LibAliasAttachHandlers(handlers);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
error = 0;
|
|
|
|
LibAliasDetachHandlers(handlers);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
static
|
|
|
|
#endif
|
|
|
|
moduledata_t alias_mod = {
|
|
|
|
"alias_skinny", mod_handler, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
DECLARE_MODULE(alias_skinny, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
|
|
|
|
MODULE_VERSION(alias_skinny, 1);
|
|
|
|
MODULE_DEPEND(alias_skinny, libalias, 1, 1, 1);
|
2005-05-05 19:27:32 +00:00
|
|
|
#endif
|
2003-09-23 07:42:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2004-03-16 21:30:41 +00:00
|
|
|
* need translation. Right after the Open Receive Channel Acknowledgement,
|
2003-09-23 07:42:33 +00:00
|
|
|
* the Call Manager sends a Start Media Transmission message indicating the
|
2004-03-16 21:30:41 +00:00
|
|
|
* call is connected. This message contains the IP address and UDP port
|
|
|
|
* number of the remote (called) party. Once this message is translated, the
|
2003-09-23 07:42:33 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-05-06 11:07:49 +00:00
|
|
|
/* #define LIBALIAS_DEBUG 1 */
|
2003-09-23 07:42:33 +00:00
|
|
|
|
|
|
|
/* 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 {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_int32_t len;
|
|
|
|
u_int32_t reserved;
|
|
|
|
u_int32_t msgId;
|
2003-09-23 07:42:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RegisterMessage {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_int32_t msgId;
|
|
|
|
char devName [16];
|
|
|
|
u_int32_t uid;
|
|
|
|
u_int32_t instance;
|
|
|
|
u_int32_t ipAddr;
|
|
|
|
u_char devType;
|
|
|
|
u_int32_t maxStreams;
|
2003-09-23 07:42:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IpPortMessage {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_int32_t msgId;
|
|
|
|
u_int32_t stationIpPort; /* Note: Skinny uses 32-bit port
|
|
|
|
* numbers */
|
2003-09-23 07:42:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OpenReceiveChannelAck {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_int32_t msgId;
|
|
|
|
u_int32_t status;
|
|
|
|
u_int32_t ipAddr;
|
|
|
|
u_int32_t port;
|
|
|
|
u_int32_t passThruPartyID;
|
2003-09-23 07:42:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct StartMediaTransmission {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_int32_t msgId;
|
|
|
|
u_int32_t conferenceID;
|
|
|
|
u_int32_t passThruPartyID;
|
|
|
|
u_int32_t remoteIpAddr;
|
|
|
|
u_int32_t remotePort;
|
|
|
|
u_int32_t MSPacket;
|
|
|
|
u_int32_t payloadCap;
|
|
|
|
u_int32_t precedence;
|
|
|
|
u_int32_t silenceSuppression;
|
|
|
|
u_short maxFramesPerPacket;
|
|
|
|
u_int32_t G723BitRate;
|
2003-09-23 07:42:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
2004-03-16 21:30:41 +00:00
|
|
|
ClientToServer = 0,
|
|
|
|
ServerToClient = 1
|
2003-09-23 07:42:33 +00:00
|
|
|
} ConvDirection;
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
alias_skinny_reg_msg(struct RegisterMessage *reg_msg, struct ip *pip,
|
2004-07-05 11:10:57 +00:00
|
|
|
struct tcphdr *tc, struct alias_link *lnk,
|
2004-03-16 21:30:41 +00:00
|
|
|
ConvDirection direction)
|
2003-09-23 07:42:33 +00:00
|
|
|
{
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)direction;
|
|
|
|
|
|
|
|
reg_msg->ipAddr = (u_int32_t) GetAliasAddress(lnk).s_addr;
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
tc->th_sum = 0;
|
2005-06-27 07:36:02 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
tc->th_x2 = 1;
|
|
|
|
#else
|
2004-03-16 21:30:41 +00:00
|
|
|
tc->th_sum = TcpChecksum(pip);
|
2005-06-27 07:36:02 +00:00
|
|
|
#endif
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-07-05 10:55:23 +00:00
|
|
|
return (0);
|
2003-09-23 07:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
alias_skinny_startmedia(struct StartMediaTransmission *start_media,
|
2004-03-16 21:30:41 +00:00
|
|
|
struct ip *pip, struct tcphdr *tc,
|
2004-07-05 11:10:57 +00:00
|
|
|
struct alias_link *lnk, u_int32_t localIpAddr,
|
2004-03-16 21:30:41 +00:00
|
|
|
ConvDirection direction)
|
2003-09-23 07:42:33 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
struct in_addr dst, src;
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)pip;
|
|
|
|
(void)tc;
|
|
|
|
(void)lnk;
|
|
|
|
(void)direction;
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
dst.s_addr = start_media->remoteIpAddr;
|
|
|
|
src.s_addr = localIpAddr;
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
/*
|
|
|
|
* XXX I should probably handle in bound global translations as
|
|
|
|
* well.
|
|
|
|
*/
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-07-05 10:55:23 +00:00
|
|
|
return (0);
|
2003-09-23 07:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
alias_skinny_port_msg(struct IpPortMessage *port_msg, struct ip *pip,
|
2004-07-05 11:10:57 +00:00
|
|
|
struct tcphdr *tc, struct alias_link *lnk,
|
2004-03-16 21:30:41 +00:00
|
|
|
ConvDirection direction)
|
2003-09-23 07:42:33 +00:00
|
|
|
{
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)direction;
|
|
|
|
|
|
|
|
port_msg->stationIpPort = (u_int32_t) ntohs(GetAliasPort(lnk));
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
tc->th_sum = 0;
|
2005-06-27 07:36:02 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
tc->th_x2 = 1;
|
|
|
|
#else
|
2004-03-16 21:30:41 +00:00
|
|
|
tc->th_sum = TcpChecksum(pip);
|
2005-06-27 07:36:02 +00:00
|
|
|
#endif
|
2004-07-05 10:55:23 +00:00
|
|
|
return (0);
|
2003-09-23 07:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-01-17 10:52:21 +00:00
|
|
|
alias_skinny_opnrcvch_ack(struct libalias *la, struct OpenReceiveChannelAck *opnrcvch_ack,
|
2004-03-16 21:30:41 +00:00
|
|
|
struct ip *pip, struct tcphdr *tc,
|
2004-07-05 11:10:57 +00:00
|
|
|
struct alias_link *lnk, u_int32_t * localIpAddr,
|
2004-03-16 21:30:41 +00:00
|
|
|
ConvDirection direction)
|
2003-09-23 07:42:33 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
struct in_addr null_addr;
|
2004-07-05 11:10:57 +00:00
|
|
|
struct alias_link *opnrcv_lnk;
|
2004-03-16 21:30:41 +00:00
|
|
|
u_int32_t localPort;
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)lnk;
|
|
|
|
(void)direction;
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
*localIpAddr = (u_int32_t) opnrcvch_ack->ipAddr;
|
|
|
|
localPort = opnrcvch_ack->port;
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
null_addr.s_addr = INADDR_ANY;
|
2004-07-05 11:10:57 +00:00
|
|
|
opnrcv_lnk = FindUdpTcpOut(la, pip->ip_src, null_addr,
|
2004-03-16 21:30:41 +00:00
|
|
|
htons((u_short) opnrcvch_ack->port), 0,
|
|
|
|
IPPROTO_UDP, 1);
|
2004-07-05 11:10:57 +00:00
|
|
|
opnrcvch_ack->ipAddr = (u_int32_t) GetAliasAddress(opnrcv_lnk).s_addr;
|
|
|
|
opnrcvch_ack->port = (u_int32_t) ntohs(GetAliasPort(opnrcv_lnk));
|
2003-09-23 07:42:33 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
tc->th_sum = 0;
|
2005-06-27 07:36:02 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
tc->th_x2 = 1;
|
|
|
|
#else
|
2004-03-16 21:30:41 +00:00
|
|
|
tc->th_sum = TcpChecksum(pip);
|
2005-06-27 07:36:02 +00:00
|
|
|
#endif
|
2004-07-05 10:55:23 +00:00
|
|
|
return (0);
|
2003-09-23 07:42:33 +00:00
|
|
|
}
|
|
|
|
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
static void
|
2004-07-05 11:10:57 +00:00
|
|
|
AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *lnk)
|
2003-09-23 07:42:33 +00:00
|
|
|
{
|
2005-03-03 03:06:37 +00:00
|
|
|
size_t hlen, tlen, dlen;
|
2004-03-16 21:30:41 +00:00
|
|
|
struct tcphdr *tc;
|
2005-03-03 03:06:37 +00:00
|
|
|
u_int32_t msgId, t, len, lip;
|
2004-03-16 21:30:41 +00:00
|
|
|
struct skinny_header *sd;
|
2005-03-03 03:06:37 +00:00
|
|
|
size_t orig_len, skinny_hdr_len = sizeof(struct skinny_header);
|
2004-03-16 21:30:41 +00:00
|
|
|
ConvDirection direction;
|
|
|
|
|
2004-07-06 12:13:28 +00:00
|
|
|
tc = (struct tcphdr *)ip_next(pip);
|
2004-03-16 21:30:41 +00:00
|
|
|
hlen = (pip->ip_hl + tc->th_off) << 2;
|
|
|
|
tlen = ntohs(pip->ip_len);
|
|
|
|
dlen = tlen - hlen;
|
|
|
|
|
2004-08-04 15:17:08 +00:00
|
|
|
sd = (struct skinny_header *)tcp_next(tc);
|
2004-03-16 21:30:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (ntohs(tc->th_dport) == la->skinnyPort) {
|
|
|
|
direction = ClientToServer;
|
|
|
|
} else if (ntohs(tc->th_sport) == la->skinnyPort) {
|
|
|
|
direction = ServerToClient;
|
|
|
|
} else {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Invalid port number, not a Skinny packet\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
orig_len = dlen;
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
len = (sd->len);
|
|
|
|
msgId = (sd->msgId);
|
|
|
|
t = len;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
if (t > orig_len || t > dlen) {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Not a skinny packet, invalid length \n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (msgId) {
|
|
|
|
case REG_MSG: {
|
|
|
|
struct RegisterMessage *reg_mesg;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
if (len < (int)sizeof(struct RegisterMessage)) {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Not a skinny packet, bad registration message\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
reg_mesg = (struct RegisterMessage *)&sd->msgId;
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Received a register message");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-07-05 11:10:57 +00:00
|
|
|
alias_skinny_reg_msg(reg_mesg, pip, tc, lnk, direction);
|
2004-03-16 21:30:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IP_PORT_MSG: {
|
|
|
|
struct IpPortMessage *port_mesg;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
if (len < (int)sizeof(struct IpPortMessage)) {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Not a skinny packet, port message\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2005-03-03 03:06:37 +00:00
|
|
|
fprintf(stderr,
|
2004-03-16 21:30:41 +00:00
|
|
|
"PacketAlias/Skinny: Received ipport message\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
port_mesg = (struct IpPortMessage *)&sd->msgId;
|
2004-07-05 11:10:57 +00:00
|
|
|
alias_skinny_port_msg(port_mesg, pip, tc, lnk, direction);
|
2004-03-16 21:30:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPNRCVCH_ACK: {
|
|
|
|
struct OpenReceiveChannelAck *opnrcvchn_ack;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
if (len < (int)sizeof(struct OpenReceiveChannelAck)) {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Not a skinny packet, packet,OpnRcvChnAckMsg\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Received open rcv channel msg\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
opnrcvchn_ack = (struct OpenReceiveChannelAck *)&sd->msgId;
|
2004-07-05 11:10:57 +00:00
|
|
|
alias_skinny_opnrcvch_ack(la, opnrcvchn_ack, pip, tc, lnk, &lip, direction);
|
2004-03-16 21:30:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case START_MEDIATX: {
|
|
|
|
struct StartMediaTransmission *startmedia_tx;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
if (len < (int)sizeof(struct StartMediaTransmission)) {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Not a skinny packet,StartMediaTx Message\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"PacketAlias/Skinny: Received start media trans msg\n");
|
2003-09-23 07:42:33 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
startmedia_tx = (struct StartMediaTransmission *)&sd->msgId;
|
2004-07-05 11:10:57 +00:00
|
|
|
alias_skinny_startmedia(startmedia_tx, pip, tc, lnk, lip, direction);
|
2004-03-16 21:30:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Place the pointer at the next message in the packet. */
|
|
|
|
dlen -= len + (skinny_hdr_len - sizeof(msgId));
|
|
|
|
sd = (struct skinny_header *)(((char *)&sd->msgId) + len);
|
|
|
|
}
|
2003-09-23 07:42:33 +00:00
|
|
|
}
|