From eda778488115a93cd3b51293ad863ed5ad10f571 Mon Sep 17 00:00:00 2001 From: paulc Date: Thu, 21 Oct 2010 11:59:43 +0000 Subject: [PATCH] Added capability of configuring explicit routes per MTP3 linkset. git-svn-id: http://yate.null.ro/svn/yate/trunk@3741 acf43c95-373e-0410-b603-e72c3f656dc1 --- conf.d/ysigchan.conf.sample | 5 +++++ libs/ysig/layer3.cpp | 38 +++++++++++++++++++++++++++++++++++++ libs/ysig/router.cpp | 13 ++++++++++++- libs/ysig/yatesig.h | 19 +++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/conf.d/ysigchan.conf.sample b/conf.d/ysigchan.conf.sample index 4c062b92..4438e231 100644 --- a/conf.d/ysigchan.conf.sample +++ b/conf.d/ysigchan.conf.sample @@ -466,6 +466,11 @@ ; Example: local=ITU,2-2-4 ;local= +; allowed: string: List of point codes explicitely allowed from this SS7 network +; An empty or missing list will allow access to all known routes +; Example: allowed=ITU,2-2-2,2-2-3,1001,2001,2002 +;allowed= + ; router: string: Name of the SS7 Router to attach to ; A boolean false value disables attaching a router (unlikely) ; If no router is attached only a single User Part can be connected diff --git a/libs/ysig/layer3.cpp b/libs/ysig/layer3.cpp index 76b844ab..f0121977 100644 --- a/libs/ysig/layer3.cpp +++ b/libs/ysig/layer3.cpp @@ -469,6 +469,8 @@ SS7MTP3::SS7MTP3(const NamedList& params) ¶ms,this,tmp.c_str()); } #endif + for (unsigned int i = 0; i < YSS7_PCTYPE_COUNT; i++) + m_allowed[i] = 0; // Set point code type for each network indicator static const unsigned char ni[4] = { SS7MSU::International, SS7MSU::SpareInternational, SS7MSU::National, SS7MSU::ReservedNational }; @@ -519,12 +521,35 @@ SS7MTP3::SS7MTP3(const NamedList& params) m_checkT2 = 1000 * check; } buildRoutes(params); + unsigned int n = params.length(); + for (unsigned int p = 0; p < n; p++) { + NamedString* ns = params.getParam(p); + if (!ns || (ns->name() != "allowed")) + continue; + ObjList* l = ns->split(',',false); + ObjList* o = l->skipNull(); + if (o) { + SS7PointCode::Type type = SS7PointCode::lookup(o->get()->toString()); + o = o->skipNext(); + if (o && (SS7PointCode::Other != type)) { + unsigned int a = o->count(); + delete[] m_allowed[type-1]; + m_allowed[type-1] = new unsigned int[a+1]; + for (a = 0; o; o = o->skipNext()) + m_allowed[type-1][a++] = o->get()->toString().toInteger(-1); + m_allowed[type-1][a] = 0; + } + } + TelEngine::destruct(l); + } setDumper(params.getValue("layer3dump")); } SS7MTP3::~SS7MTP3() { setDumper(); + for (unsigned int i = 0; i < YSS7_PCTYPE_COUNT; i++) + delete[] m_allowed[i]; } unsigned int SS7MTP3::countLinks() @@ -728,6 +753,19 @@ void SS7MTP3::detach(SS7Layer2* link) } } +bool SS7MTP3::allowedTo(SS7PointCode::Type type, unsigned int packedPC) const +{ + if (type >= SS7PointCode::DefinedTypes) + return false; + if (!m_allowed[type-1]) + return true; + for (int i = 0; m_allowed[type-1][i]; i++) { + if (packedPC == m_allowed[type-1][i]) + return true; + } + return false; +} + bool SS7MTP3::control(Operation oper, NamedList* params) { bool ok = operational(); diff --git a/libs/ysig/router.cpp b/libs/ysig/router.cpp index fe5f0998..37e23915 100644 --- a/libs/ysig/router.cpp +++ b/libs/ysig/router.cpp @@ -1039,13 +1039,24 @@ SS7Route::State SS7Router::getRouteView(SS7PointCode::Type type, unsigned int pa { if (type == SS7PointCode::Other || (unsigned int)type > YSS7_PCTYPE_COUNT || !packedPC) return SS7Route::Unknown; + if (network && !network->allowedTo(type,packedPC)) { + DDebug(this,DebugInfo,"View of %u from %u on %s is Prohibited", + packedPC,remotePC,network->toString().c_str()); + return SS7Route::Prohibited; + } SS7Route::State best = SS7Route::Unknown; for (ObjList* o = m_layer3.skipNull(); o; o = o->skipNext()) { SS7Layer3* l3 = *static_cast(o->get()); if (!l3 || (l3 == network)) continue; - if (!l3->getRoutePriority(type,remotePC)) + if (!l3->getRoutePriority(type,remotePC)) { + if (!l3->allowedTo(type,packedPC)) { + DDebug(this,DebugInfo,"View of %u from %u on %s is Prohibited", + packedPC,remotePC,l3->toString().c_str()); + return SS7Route::Prohibited; + } continue; + } SS7Route::State state; if (l3->operational()) { state = l3->getRouteState(type,packedPC); diff --git a/libs/ysig/yatesig.h b/libs/ysig/yatesig.h index 13adb0cc..ea8d641c 100644 --- a/libs/ysig/yatesig.h +++ b/libs/ysig/yatesig.h @@ -5675,6 +5675,15 @@ public: inline SS7Route::State getRouteState(SS7PointCode::Type type, const SS7PointCode& dest) { return getRouteState(type,dest.pack(type)); } + /** + * Check if access to a specific Point Code is allowed from this network + * @param type Destination point code type + * @param packedPC The destination point code + * @return True if access to the specified Point Code is allowed + */ + virtual bool allowedTo(SS7PointCode::Type type, unsigned int packedPC) const + { return true; } + /** * Print the destinations or routing table to output */ @@ -6988,6 +6997,14 @@ public: */ virtual bool control(NamedList& params); + /** + * Check if access to a specific Point Code is allowed from this network + * @param type Destination point code type + * @param packedPC The destination point code + * @return True if access to the specified Point Code is allowed + */ + virtual bool allowedTo(SS7PointCode::Type type, unsigned int packedPC) const; + /** * Get the total number of links attached * @return Number of attached data links @@ -7085,6 +7102,8 @@ private: // maintenance check intervals (Q.707) u_int64_t m_checkT1; u_int64_t m_checkT2; + // list of allowed point codes seen from this network + unsigned int* m_allowed[YSS7_PCTYPE_COUNT]; }; /**