- plugin_fix_bogus_via: fixes broken VIA headers on
incoming SIP messages (inspired by Ralph Babel, see http://babel.de/art20080317a.html for more info)
This commit is contained in:
+5
-1
@@ -41,7 +41,8 @@ siproxd_SOURCES = siproxd.c proxy.c register.c sock.c utils.c \
|
||||
pkglib_LTLIBRARIES = plugin_demo.la \
|
||||
plugin_shortdial.la \
|
||||
plugin_logcall.la \
|
||||
plugin_defaulttarget.la
|
||||
plugin_defaulttarget.la \
|
||||
plugin_fix_bogus_via.la
|
||||
#
|
||||
plugin_demo_la_SOURCES = plugin_demo.c
|
||||
plugin_demo_la_LDFLAGS = -module
|
||||
@@ -54,6 +55,9 @@ plugin_logcall_la_LDFLAGS = -module
|
||||
#
|
||||
plugin_defaulttarget_la_SOURCES = plugin_defaulttarget.c
|
||||
plugin_defaulttarget_la_LDFLAGS = -module
|
||||
#
|
||||
plugin_fix_bogus_via_la_SOURCES = plugin_fix_bogus_via.c
|
||||
plugin_fix_bogus_via_la_LDFLAGS = -module
|
||||
|
||||
|
||||
#
|
||||
|
||||
@@ -36,9 +36,6 @@ static char const ident[]="$Id$";
|
||||
/* configuration storage */
|
||||
struct siproxd_config configuration;
|
||||
|
||||
/* prototypes used locally only */
|
||||
int process_aclist (char *aclist, struct sockaddr_in from);
|
||||
|
||||
|
||||
/*
|
||||
* verifies the from address agains the access lists
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
Copyright (C) 2008 Thomas Ries <tries@gmx.net>
|
||||
|
||||
This file is part of Siproxd.
|
||||
|
||||
Siproxd is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Siproxd is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warrantry of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Siproxd; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <osipparser2/osip_parser.h>
|
||||
|
||||
#include "siproxd.h"
|
||||
#include "plugins.h"
|
||||
#include "log.h"
|
||||
|
||||
static char const ident[]="$Id$";
|
||||
|
||||
/* Plug-in identification */
|
||||
static char name[]="plugin_fix_bogus_via";
|
||||
static char desc[]="Fixes broken VIA headers on incoming calls";
|
||||
|
||||
/* global configuration storage - required for config file location */
|
||||
extern struct siproxd_config configuration;
|
||||
|
||||
/* plugin configuration storage */
|
||||
static struct plugin_config {
|
||||
char *networks;
|
||||
} plugin_cfg;
|
||||
|
||||
/* Instructions for config parser */
|
||||
static cfgopts_t plugin_cfg_opts[] = {
|
||||
{ "plugin_fix_bogus_via_networks", TYP_STRING, &plugin_cfg.networks },
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
/* Prototypes */
|
||||
static int sip_patch_topvia(sip_ticket_t *ticket);
|
||||
|
||||
|
||||
/*
|
||||
* Initialization.
|
||||
* Called once suring siproxd startup.
|
||||
*/
|
||||
int plugin_init(plugin_def_t *plugin_def) {
|
||||
/* API version number of siproxd that this plugin is built against.
|
||||
* This constant will change whenever changes to the API are made
|
||||
* that require adaptions in the plugin. */
|
||||
plugin_def->api_version=SIPROXD_API_VERSION;
|
||||
|
||||
/* Name and descriptive text of the plugin */
|
||||
plugin_def->name=name;
|
||||
plugin_def->desc=desc;
|
||||
|
||||
/* Execution mask - during what stages of SIP processing shall
|
||||
* the plugin be called. */
|
||||
plugin_def->exe_mask=PLUGIN_PRE_PROXY;
|
||||
|
||||
/* read the config file */
|
||||
if (read_config(configuration.configfile,
|
||||
configuration.config_search,
|
||||
plugin_cfg_opts, name) == STS_FAILURE) {
|
||||
ERROR("Plugin '%s': could not load config file", name);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
INFO("plugin_fix_bogus_via is initialized");
|
||||
return STS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Processing.
|
||||
*
|
||||
*/
|
||||
int plugin_process(int stage, sip_ticket_t *ticket){
|
||||
/* stage contains the PLUGIN_* value - the stage of SIP processing. */
|
||||
int type;
|
||||
osip_via_t *via;
|
||||
struct sockaddr_in from;
|
||||
|
||||
type = ticket->direction;
|
||||
|
||||
/* Incoming SIP message? */
|
||||
DEBUGC(DBCLASS_PLUGIN, "plugin_fix_bogus_via: type=%i", type);
|
||||
if (type == REQTYP_INCOMING) {
|
||||
|
||||
if((via = osip_list_get(&(ticket->sipmsg->vias), 0)) == NULL) {
|
||||
WARN("no Via header found in incoming SIP message");
|
||||
return STS_SUCCESS;
|
||||
}
|
||||
|
||||
get_ip_by_host(via->host, &(from.sin_addr));
|
||||
|
||||
/* check for Via IP in configured range */
|
||||
if ((plugin_cfg.networks != NULL) &&
|
||||
(strcmp(plugin_cfg.networks, "") !=0) &&
|
||||
(process_aclist(plugin_cfg.networks, from) == STS_SUCCESS)) {
|
||||
/* is in list, patch Via header with received from IP */
|
||||
DEBUGC(DBCLASS_PLUGIN, "plugin_fix_bogus_via: replacing a bogus via");
|
||||
if (sip_patch_topvia(ticket) == STS_FAILURE) {
|
||||
ERROR("patching inbound Via failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return STS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* De-Initialization.
|
||||
* Called during shutdown of siproxd. Gives the plugin the chance
|
||||
* to clean up its mess (e.g. dynamic memory allocation, database
|
||||
* connections, whatever the plugin messes around with)
|
||||
*/
|
||||
int plugin_end(plugin_def_t *plugin_def){
|
||||
INFO("plugin_fix_bogus_via ends here");
|
||||
return STS_SUCCESS;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int sip_patch_topvia(sip_ticket_t *ticket) {
|
||||
osip_via_t *via;
|
||||
|
||||
if((via = osip_list_get(&(ticket->sipmsg->vias), 0)) != NULL) {
|
||||
/* clone Via header */
|
||||
|
||||
/* set new IP (from IP) */
|
||||
osip_free(via->host);
|
||||
via->host=osip_malloc(IPSTRING_SIZE);
|
||||
snprintf(via->host, IPSTRING_SIZE, "%s",
|
||||
utils_inet_ntoa(ticket->from.sin_addr));
|
||||
via->host[IPSTRING_SIZE-1] ='\0';
|
||||
|
||||
/* set new port number */
|
||||
osip_free(via->port);
|
||||
via->port=osip_malloc(6); /* 5 digits + \0 */
|
||||
snprintf(via->port, 5, "%u", ntohs(ticket->from.sin_port));
|
||||
via->port[5-1] ='\0';
|
||||
|
||||
DEBUGC(DBCLASS_PLUGIN, "plugin_fix_bogus_via: -> %s:%s",
|
||||
via->host, via->port);
|
||||
|
||||
}
|
||||
|
||||
return STS_SUCCESS;
|
||||
}
|
||||
|
||||
+4
-2
@@ -210,8 +210,8 @@ int sip_fixup_asterisk(char *buff, int *buflen); /*X*/
|
||||
int sip_obscure_callid(sip_ticket_t *ticket); /*X*/
|
||||
|
||||
/* readconf.c */
|
||||
int read_config(char *name, int search, cfgopts_t cfgopts[], char *filter); /*X*/
|
||||
int make_default_config(void); /*X*/
|
||||
int read_config(char *name, int search, cfgopts_t cfgopts[], char *filter); /*X*/
|
||||
int make_default_config(void); /*X*/
|
||||
|
||||
/* rtpproxy.c */
|
||||
int rtpproxy_init( void ); /*X*/
|
||||
@@ -224,6 +224,7 @@ int rtp_stop_fwd (osip_call_id_t *callid, int direction); /*X*/
|
||||
|
||||
/* accessctl.c */
|
||||
int accesslist_check(struct sockaddr_in from);
|
||||
int process_aclist (char *aclist, struct sockaddr_in from);
|
||||
|
||||
/* security.c */
|
||||
int security_check_raw(char *sip_buffer, size_t size); /*X*/
|
||||
@@ -288,6 +289,7 @@ int unload_plugins(void);
|
||||
#define HOSTNAME_SIZE 128 /* max string length of a hostname */
|
||||
#define USERNAME_SIZE 128 /* max string length of a username (auth) */
|
||||
#define PASSWORD_SIZE 128 /* max string length of a password (auth) */
|
||||
#define IPSTRING_SIZE 16 /* stringsize of IP address xxx.xxx.xxx.xxx */
|
||||
#define VIA_BRANCH_SIZE 128 /* max string length for via branch param */
|
||||
/* scratch buffer for gethostbyname_r() */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user