Public Member Functions
KernelRoute Class Reference

Brief description of class still missing. More...

#include <KernelRoute.h>

List of all members.

Public Member Functions

void add (const Address &dest, const Address &gw)
void clear ()
int count () const
Address destination (const Address &gateway) const
 KernelRoute (const char *interface)
void remove (const Address &dest, const Address &gw)
void removeDestination (const Address &destination)
Routeroutes () const
 ~KernelRoute ()

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

KernelRoute::KernelRoute ( const char *  interface)
{
  _interface=interface;
  _fd=socket(AF_INET, SOCK_DGRAM, 0);
  if(_fd<0) {
    Log::write(1, "kernel route: %s\n", strerror(errno));
    CoreApplication::exit(2);
  }
  // Set ip_forward bit to one to allow packet forward on all nodes
  int fdf=open("/proc/sys/net/ipv4/ip_forward", O_WRONLY);
  if(fdf>0) {
    write(fdf, "1", 1);
    close(fdf);
  }
}

References clear().

{
  clear();
  close(_fd);
}

Member Function Documentation

void KernelRoute::add ( const Address dest,
const Address gw 
)

Referenced by PeerTracker::addFromMasterRoute().

{
  std::list<Route>::iterator it=find(destination, gateway);
  if(it==_routes.end()) {
    Route rt(destination, gateway);
    if(add(rt)) {
      _routes.push_back(rt);
    }
  } else {
    Log::write(1, "Route to %s already exists", Route(destination, gateway).toString().data());
  }
}

Referenced by ~KernelRoute().

{
  for(std::list<Route>::iterator it=_routes.begin(); it!=_routes.end(); it++) {
    Route& rt=*it;
    remove(rt);
  }
  _routes.clear();
}
int KernelRoute::count ( ) const [inline]
{return _routes.size();}
Address KernelRoute::destination ( const Address gateway) const

Returns destination address of first entry with gateway.

References Route::destination(), and Route::gateway().

Referenced by PeerTracker::stop().

{
  std::list<Route>::const_iterator it;
  for(it=_routes.begin(); it!=_routes.end(); it++) {
    Route rt=*it;
    if(rt.gateway()==gateway) {
      return rt.destination();
    }
  }
  return Address();
}
void KernelRoute::remove ( const Address dest,
const Address gw 
)
{
  std::list<Route>::iterator it=find(destination, gateway);
  if(it!=_routes.end()) {
    if(remove(*it)) {
      _routes.erase(it);
    }
  }
}
void KernelRoute::removeDestination ( const Address destination)

Referenced by PeerTracker::removeFromMasterRoute().

{
  std::list<Route>::iterator it=find(destination);
  if(it!=_routes.end()) {
    if(remove(*it)) {
      _routes.erase(it);
    }
  }
}
{
  Route * rts=new Route[_routes.size()];
  std::list<Route>::const_iterator it;
  int i=0;
  for(it=_routes.begin(); it!=_routes.end(); it++, i++) {
    Route rt=*it;
    rts[i]=rt;
  }
  return rts;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines