removed ICMP watcher.

icmpwatcher has not been used for some time, as it is a 
quite dangerous method of checking for the remote party
(in the beginning of a call due to delays in signalling,
the port on the remote end could for example still be not 
open for some time) 


git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1652 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 17 years ago
parent 3ec30d9ce9
commit 609995aa79

@ -1,173 +0,0 @@
#include "AmIcmpWatcher.h"
#include "AmRtpStream.h"
#include "log.h"
#include <string>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
#define __FAVOR_BSD /* only for linux */
#include <netinet/udp.h>
AmIcmpWatcher* AmIcmpWatcher::_instance=0;
AmIcmpWatcher* AmIcmpWatcher::instance()
{
if(!_instance)
_instance = new AmIcmpWatcher();
return _instance;
}
AmIcmpWatcher::AmIcmpWatcher()
: raw_sd(-1)
{
}
AmIcmpWatcher::~AmIcmpWatcher()
{
if(raw_sd != -1)
close(raw_sd);
}
void AmIcmpWatcher::run()
{
raw_sd = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
if(raw_sd == -1){
ERROR("ICMP Watcher: could not create RAW socket: %s\n",strerror(errno));
ERROR("ICMP Watcher: try to run SEMS as root or suid.\n");
return;
}
int raw_sz;
char msg_buf[ICMP_BUF_SIZE];
struct sockaddr_in from;
socklen_t from_len;
char from_str[INET_ADDRSTRLEN];
struct ip *ip_hdr1,*ip_hdr2;
size_t hlen_ip1,hlen_ip2;
struct icmp* icmp_hdr;
size_t icmp_len;
std::string icmp_type_str;
char src_str[INET_ADDRSTRLEN];
char dst_str[INET_ADDRSTRLEN];
while(true){
from_len = sizeof(from);
raw_sz = recvfrom(raw_sd, msg_buf, ICMP_BUF_SIZE, 0,
(struct sockaddr*)&from, &from_len);
inet_ntop(AF_INET,&from.sin_addr,from_str,INET_ADDRSTRLEN);
ip_hdr1 = (struct ip*)msg_buf;
hlen_ip1 = ip_hdr1->ip_hl << 2; /* convert to bytes */
icmp_hdr = (struct icmp*)(msg_buf + hlen_ip1);
icmp_len = raw_sz - hlen_ip1;
/* if ICMP smaller than minimal length */
if(icmp_len < 8){
ERROR("icmp_len < 8\n");
continue;
}
// DBG("%d bytes ICMP from %s: type = %d code = %d\n",
// raw_sz,from_str,icmp_hdr->icmp_type,icmp_hdr->icmp_code);
switch(icmp_hdr->icmp_type){
case ICMP_UNREACH:
icmp_type_str = "Destination Unreachable";
break;
case ICMP_SOURCEQUENCH:
icmp_type_str = "Source Quench";
break;
case ICMP_TIMXCEED:
icmp_type_str = "Time Exceeded";
break;
default:
continue;
}
/* if ICMP smaller than expected length */
if(icmp_len < 8 + 20 + 8){
ERROR("icmp_len < 8 + 20 + 8\n");
continue;
}
ip_hdr2 = (struct ip*)(msg_buf + hlen_ip1 + 8);
hlen_ip2 = ip_hdr2->ip_hl << 2;
inet_ntop(AF_INET,&ip_hdr2->ip_src,src_str,INET_ADDRSTRLEN);
inet_ntop(AF_INET,&ip_hdr2->ip_dst,dst_str,INET_ADDRSTRLEN);
if(ip_hdr2->ip_p == IPPROTO_UDP){
struct udphdr* udp_hdr =
(struct udphdr*)(msg_buf + hlen_ip1 + 8 + hlen_ip2);
int srcport = ntohs(udp_hdr->uh_sport);
int dstport = ntohs(udp_hdr->uh_dport);
stream_map_m.lock();
std::map<int,AmRtpStream*>::iterator str_it = stream_map.find(srcport);
if(str_it != stream_map.end()){
DBG("ICMP from %s: type='%s' src=%s:%d dst=%s:%d\n",
from_str,icmp_type_str.c_str(),
src_str,srcport,dst_str,dstport);
IcmpReporter* rep = new IcmpReporter(str_it->second);
rep->start();
AmThreadWatcher::instance()->add(rep);
}
stream_map_m.unlock();
}
}
}
void AmIcmpWatcher::on_stop()
{
}
void AmIcmpWatcher::addStream(int localport, AmRtpStream* str)
{
stream_map_m.lock();
stream_map[localport] = str;
stream_map_m.unlock();
}
void AmIcmpWatcher::removeStream(int localport)
{
stream_map_m.lock();
stream_map.erase(localport);
stream_map_m.unlock();
}
void IcmpReporter::run()
{
rtp_str->icmpError();
}
void IcmpReporter::on_stop()
{
}
IcmpReporter::IcmpReporter(AmRtpStream* str)
: rtp_str(str)
{
}

@ -1,76 +0,0 @@
/*
* $Id$
*
* Copyright (C) 2002-2003 Fhg Fokus
*
* This file is part of sems, a free SIP media server.
*
* sems 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
*
* For a license to use the ser software under conditions
* other than those described here, or to purchase support for this
* software, please contact iptel.org by e-mail at the following addresses:
* info@iptel.org
*
* sems is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @file AmIcmpWatcher.h */
#ifndef _AmIcmpWatcher_h_
#define _AmIcmpWatcher_h_
#include "AmThread.h"
#include <map>
#define ICMP_BUF_SIZE 512
class AmRtpStream;
/** \brief thread that watches ICMP reports */
class AmIcmpWatcher: public AmThread
{
static AmIcmpWatcher* _instance;
/* RAW socket descriptor */
int raw_sd;
/* RTP Stream map */
std::map<int,AmRtpStream*> stream_map;
AmMutex stream_map_m;
/* constructor & destructor are
* private as we want a singleton.
*/
AmIcmpWatcher();
~AmIcmpWatcher();
void run();
void on_stop();
public:
static AmIcmpWatcher* instance();
void addStream(int localport, AmRtpStream* str);
void removeStream(int localport);
};
/** \brief one-shot thread: report an ICMP error to the rtp stream */
class IcmpReporter: public AmThread
{
AmRtpStream* rtp_str;
void run();
void on_stop();
public:
IcmpReporter(AmRtpStream* str);
};
#endif

@ -27,7 +27,6 @@
#include "AmRtpStream.h"
#include "AmRtpPacket.h"
#include "AmIcmpWatcher.h"
#include "AmRtpReceiver.h"
#include "AmConfig.h"
#include "AmPlugIn.h"
@ -161,7 +160,6 @@ void AmRtpStream::setLocalPort()
l_sd = sd;
l_port = port;
//AmIcmpWatcher::instance()->addStream(l_port,this);
AmRtpReceiver::instance()->addStream(l_sd,this);
DBG("local rtp port set to %i\n",l_port);
}
@ -489,15 +487,6 @@ bool AmRtpStream::getOnHold() {
return hold;
}
void AmRtpStream::icmpError()
{
if(!passive){
// AmIcmpWatcher::instance()->removeStream(l_port);
if(session)
session->stop();
}
}
AmRtpPacket* AmRtpStream::newPacket() {
return mem.newPacket();
}

@ -256,11 +256,6 @@ public:
/** getter for monitor_rtp_timeout */
bool getMonitorRTPTimeout() { return monitor_rtp_timeout; }
/**
* Report an ICMP error.
*/
void icmpError();
/**
* Insert an RTP packet to the buffer.
* Note: memory is owned by this instance.

@ -18,7 +18,6 @@ SET (sems_SRCS
AmEvent.cpp
AmEventDispatcher.cpp
AmEventQueue.cpp
AmIcmpWatcher.cpp
AmJitterBuffer.cpp
AmMediaProcessor.cpp
AmMultiPartyMixer.cpp

@ -32,7 +32,6 @@
#include "AmSessionContainer.h"
#include "AmServer.h"
#include "AmMediaProcessor.h"
#include "AmIcmpWatcher.h"
#include "AmRtpReceiver.h"
#include "AmEventDispatcher.h"

Loading…
Cancel
Save