NSIS-ka
A free C++ implementation of NSIS protocols

Changeset 4200


Ignore:
Timestamp:
Aug 4, 2009, 3:33:03 PM (8 years ago)
Author:
stud-lenk
Message:

Extend gist_conf and ntlp_starter to read configured multicast interfaces and join multicast groups on all the configured interfaces

Location:
ntlp/branches/20090723-multicast
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ntlp/branches/20090723-multicast/include/gist_conf.h

    r4165 r4200  
    7474    gistconf_tls_cacert,
    7575    gistconf_multicast_groups,
     76    gistconf_multicast_interfaces,
    7677    gistconf_maxparno
    7778  };
  • ntlp/branches/20090723-multicast/src/gist_conf.cpp

    r4165 r4200  
    3030
    3131#include <gist_conf.h>
     32#include "networkinterface.h"
    3233
    3334#include <sstream>
     
    8182  registerPar( new configpar<string>(gist_realm, gistconf_tls_cacert, "tls-cacert",  "filename pointing to the SSL/TLS CA cert file (may contain absolute path)", false, "root_cert.pem") );
    8283  registerPar( new configpar< hostaddresslist_t >(gist_realm, gistconf_multicast_groups, "gist-multicast-groups", "IP multicast groups for GIST multicast messages", false, list<hostaddress>() ) );
     84  registerPar( new configpar< networkinterfacelist_t >(gist_realm, gistconf_multicast_interfaces, "gist-multicast-interfaces", "Interfaces on which GIST should join IP multicast groups (see gist-multicast-groups)", false, list<networkinterface>() ) );
    8385
    8486  DLog("gistconf::registerAllPars", "finished registering gist parameters.");
  • ntlp/branches/20090723-multicast/src/ntlp_starter.cpp

    r4165 r4200  
    501501  // =====================================================================
    502502  DLog(param.name, "Startup phase 9: Join GIST multicast groups");
     503  networkinterfacelist_t& mcastifs = gconf.getparref< networkinterfacelist_t >(gistconf_multicast_interfaces);
    503504  hostaddresslist_t& mcastgroups= gconf.getparref< hostaddresslist_t >(gistconf_multicast_groups);
     505  if (mcastifs.empty() && (mcastgroups.empty() == false)) {
     506    set<unsigned int> configured_interfaces;
     507    DLog(param.name, "No multicast interfaces specified. Deriving interfaces from configured addresses");
     508    // iterate through all configured IPv4 addresses and insert corresponding network interface indices
     509    hostaddresslist_t::iterator it = localaddrv4.begin();
     510    while (it != localaddrv4.end()) {
     511      try {
     512        networkinterface a_netif(*it);
     513        // DLog(param.name, "Got network interface " << a_netif << " for configured IP address " << *it);
     514        configured_interfaces.insert(a_netif.get_index());
     515      } catch (std::invalid_argument e) {
     516        DLog(param.name, "No network interface found for configured address " << *it);
     517      }
     518      it++;
     519    }
     520    // iterate through all configured IPv6 addresses and insert corresponding network interface indices
     521    it = localaddrv6.begin();
     522    while (it != localaddrv6.end()) {
     523      try {
     524        networkinterface a_netif(*it);
     525        // DLog(param.name, "Got network interface " << a_netif << " for configured IP address " << *it);
     526        configured_interfaces.insert(a_netif.get_index());
     527      } catch (std::invalid_argument e) {
     528        DLog(param.name, "No network interface found for configured address " << *it);
     529      }
     530      it++;
     531    }
     532    // iterate through all interface indices and fill networkinterfacelist_t
     533    for( set<unsigned int>::const_iterator ifiter = configured_interfaces.begin();
     534         ifiter != configured_interfaces.end(); ++ifiter ) {
     535      try {
     536        networkinterface a_mcast_if(*ifiter);
     537        // DLog(param.name, "Adding network interface " << a_mcast_if << " to list of multicast interfaces");
     538        mcastifs.push_back(a_mcast_if);
     539      } catch (std::invalid_argument ia)
     540      {
     541        ERRLog(param.name, "Adding network interface " << *ifiter << " to list of multicast interfaces failed");
     542      }
     543    }
     544  }
     545  // Now, join all multicast groups
    504546  if (mcastgroups.empty() == false) {
    505547    hostaddresslist_t::iterator it = mcastgroups.begin();
     
    507549    {
    508550      if ((*it).is_multicast()) {
    509         int status = (*udpproto).join_multicast_group(*it);
    510         if (status == 0)
    511           ILog(param.name, "Successfully joined IP multicast group " << *it);
    512         else
    513           ERRLog(param.name, "Joining IP multicast group " << *it
     551        networkinterfacelist_t::iterator mcast_if_it = mcastifs.begin();
     552        while (mcast_if_it != mcastifs.end())
     553        {
     554          networkinterface mcast_interface = (networkinterface)(*mcast_if_it);
     555          int status = (*udpproto).join_multicast_group(*it, &mcast_interface);
     556          if (status == 0) {
     557            ILog(param.name, "Successfully joined IP multicast group " << *it << " on interface " << mcast_interface);
     558          } else {
     559            ERRLog(param.name, "Joining IP multicast group " << *it << " on interface " << mcast_interface
    514560                             << " failed: " << strerror(errno));
     561          }
     562          mcast_if_it++;
     563        }
    515564      } else {
    516565        ERRLog(param.name, "Skipping join to IP multicast group " << *it
Note: See TracChangeset for help on using the changeset viewer.