From 609995aa79218e5041b12ecb3d24fb73cdf3ddc9 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Fri, 5 Mar 2010 12:27:58 +0000 Subject: [PATCH] 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 --- core/AmIcmpWatcher.cpp | 173 ----------------------------------------- core/AmIcmpWatcher.h | 76 ------------------ core/AmRtpStream.cpp | 11 --- core/AmRtpStream.h | 5 -- core/CMakeLists.txt | 1 - core/sems.cpp | 1 - 6 files changed, 267 deletions(-) delete mode 100644 core/AmIcmpWatcher.cpp delete mode 100644 core/AmIcmpWatcher.h diff --git a/core/AmIcmpWatcher.cpp b/core/AmIcmpWatcher.cpp deleted file mode 100644 index 8d2fd66b..00000000 --- a/core/AmIcmpWatcher.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include "AmIcmpWatcher.h" -#include "AmRtpStream.h" -#include "log.h" - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define __FAVOR_BSD /* only for linux */ -#include - -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::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) -{ -} diff --git a/core/AmIcmpWatcher.h b/core/AmIcmpWatcher.h deleted file mode 100644 index 6823a170..00000000 --- a/core/AmIcmpWatcher.h +++ /dev/null @@ -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 - -#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 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 diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index 5d87a280..69518437 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -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(); } diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index 648d1bdf..685ca749 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -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. diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 83007028..785f9faf 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,7 +18,6 @@ SET (sems_SRCS AmEvent.cpp AmEventDispatcher.cpp AmEventQueue.cpp - AmIcmpWatcher.cpp AmJitterBuffer.cpp AmMediaProcessor.cpp AmMultiPartyMixer.cpp diff --git a/core/sems.cpp b/core/sems.cpp index ca1e8ae7..612b842a 100644 --- a/core/sems.cpp +++ b/core/sems.cpp @@ -32,7 +32,6 @@ #include "AmSessionContainer.h" #include "AmServer.h" #include "AmMediaProcessor.h" -#include "AmIcmpWatcher.h" #include "AmRtpReceiver.h" #include "AmEventDispatcher.h"