Go back to using own implementation of smart pointers
This commit is contained in:
parent
ffb4e6d398
commit
ab0ebe09ff
6
Makefile
6
Makefile
@ -1,9 +1,9 @@
|
||||
DEBUG=1
|
||||
|
||||
ifdef DEBUG
|
||||
CXXFLAGS ?= -g -std=c++0x -DDEBUG
|
||||
CXXFLAGS ?= -g -DDEBUG
|
||||
else
|
||||
CXXFLAGS ?= -O3 -std=c++0x
|
||||
CXXFLAGS ?= -O3
|
||||
endif
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
@ -12,7 +12,7 @@ GZIP ?= /bin/gzip
|
||||
MANDIR ?= ${DESTDIR}${PREFIX}/share/man
|
||||
SBINDIR ?= ${DESTDIR}${PREFIX}/sbin
|
||||
|
||||
LIBS = -lconfuse
|
||||
LIBS =
|
||||
|
||||
OBJS = src/logger.o src/ndppd.o src/iface.o src/proxy.o src/address.o \
|
||||
src/rule.o src/session.o src/conf.o
|
||||
|
35
src/conf.cc
35
src/conf.cc
@ -17,7 +17,9 @@
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <netinet/ip6.h>
|
||||
@ -55,18 +57,17 @@ void conf::value(const std::string &value)
|
||||
_value = value;
|
||||
}
|
||||
|
||||
std::shared_ptr<conf> conf::load(const std::string &path)
|
||||
ptr<conf> conf::load(const std::string &path)
|
||||
{
|
||||
std::ifstream ifs;
|
||||
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
|
||||
try {
|
||||
ifs.open(path, std::ios::in);
|
||||
std::ifstream ifs;
|
||||
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
ifs.open(path.c_str(), std::ios::in);
|
||||
std::string buf((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
ifs.close();
|
||||
|
||||
const char *c_buf = buf.c_str();
|
||||
|
||||
std::shared_ptr<conf> cf(new conf);
|
||||
ptr<conf> cf(new conf);
|
||||
|
||||
if (cf->parse_block(&c_buf)) {
|
||||
logger l(LOG_DEBUG);
|
||||
@ -79,7 +80,7 @@ std::shared_ptr<conf> conf::load(const std::string &path)
|
||||
logger::error() << "Failed to load configuration file '" << path << "'";
|
||||
}
|
||||
|
||||
return std::shared_ptr<conf>();
|
||||
return ptr<conf>();
|
||||
}
|
||||
|
||||
bool conf::is_block() const
|
||||
@ -152,10 +153,10 @@ bool conf::parse_block(const char **str)
|
||||
p++;
|
||||
}
|
||||
|
||||
std::shared_ptr<conf> cf(new conf);
|
||||
ptr<conf> cf(new conf);
|
||||
|
||||
if (cf->parse(&p)) {
|
||||
_map.insert(std::pair<std::string, std::shared_ptr<conf> >(ss.str(), cf));
|
||||
_map.insert(std::pair<std::string, ptr<conf> >(ss.str(), cf));
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,7 +225,7 @@ void conf::dump(logger &l, int level) const
|
||||
if (_is_block) {
|
||||
l << "{" << logger::endl;
|
||||
|
||||
std::multimap<std::string, std::shared_ptr<conf> >::const_iterator it;
|
||||
std::multimap<std::string, ptr<conf> >::const_iterator it;
|
||||
|
||||
for (it = _map.begin(); it != _map.end(); it++) {
|
||||
l << pfx << " " << it->first << " ";
|
||||
@ -237,20 +238,20 @@ void conf::dump(logger &l, int level) const
|
||||
l << logger::endl;
|
||||
}
|
||||
|
||||
std::shared_ptr<conf> conf::operator[](const std::string& name) const
|
||||
ptr<conf> conf::operator[](const std::string& name) const
|
||||
{
|
||||
std::multimap<std::string, std::shared_ptr<conf> >::const_iterator it;
|
||||
std::multimap<std::string, ptr<conf> >::const_iterator it;
|
||||
|
||||
if ((it = _map.find(name)) == _map.end())
|
||||
return std::shared_ptr<conf>();
|
||||
return ptr<conf>();
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<conf> > conf::find(const std::string& name) const
|
||||
std::vector<ptr<conf> > conf::find(const std::string& name) const
|
||||
{
|
||||
std::vector<std::shared_ptr<conf> > vec;
|
||||
std::multimap<std::string, std::shared_ptr<conf> >::const_iterator it;
|
||||
std::vector<ptr<conf> > vec;
|
||||
std::multimap<std::string, ptr<conf> >::const_iterator it;
|
||||
for (it = _map.find(name); it != _map.end(); it++) {
|
||||
vec.push_back(it->second);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ private:
|
||||
|
||||
bool _is_block;
|
||||
|
||||
std::multimap<std::string, std::shared_ptr<conf> > _map;
|
||||
std::multimap<std::string, ptr<conf> > _map;
|
||||
|
||||
void dump(logger &l, int level) const;
|
||||
|
||||
@ -55,12 +55,12 @@ public:
|
||||
|
||||
void value(const std::string &value);
|
||||
|
||||
static std::shared_ptr<conf> load(const std::string &path);
|
||||
static ptr<conf> load(const std::string &path);
|
||||
|
||||
bool is_block() const;
|
||||
|
||||
std::shared_ptr<conf> operator[](const std::string &name) const;
|
||||
std::vector<std::shared_ptr<conf> > find(const std::string &name) const;
|
||||
ptr<conf> operator[](const std::string &name) const;
|
||||
std::vector<ptr<conf> > find(const std::string &name) const;
|
||||
|
||||
void dump() const;
|
||||
|
||||
|
64
src/iface.cc
64
src/iface.cc
@ -42,7 +42,7 @@
|
||||
|
||||
NDPPD_NS_BEGIN
|
||||
|
||||
std::map<std::string, std::shared_ptr<iface> > iface::_map;
|
||||
std::map<std::string, ptr<iface> > iface::_map;
|
||||
|
||||
std::vector<struct pollfd> iface::_pollfds;
|
||||
|
||||
@ -64,13 +64,13 @@ iface::~iface()
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<iface> iface::open_pfd(const std::string& name)
|
||||
ptr<iface> iface::open_pfd(const std::string& name)
|
||||
{
|
||||
int fd;
|
||||
|
||||
std::map<std::string, std::shared_ptr<iface> >::iterator it = _map.find(name);
|
||||
std::map<std::string, ptr<iface> >::iterator it = _map.find(name);
|
||||
|
||||
std::shared_ptr<iface> ifa;
|
||||
ptr<iface> ifa;
|
||||
|
||||
if (it != _map.end()) {
|
||||
if (it->second->_pfd >= 0)
|
||||
@ -83,13 +83,13 @@ std::shared_ptr<iface> iface::open_pfd(const std::string& name)
|
||||
}
|
||||
|
||||
if (!ifa)
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
|
||||
// Create a socket.
|
||||
|
||||
if ((fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IPV6))) < 0) {
|
||||
logger::error() << "Unable to create socket";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Bind to the specified interface.
|
||||
@ -103,13 +103,13 @@ std::shared_ptr<iface> iface::open_pfd(const std::string& name)
|
||||
if (!(lladdr.sll_ifindex = if_nametoindex(name.c_str()))) {
|
||||
close(fd);
|
||||
logger::error() << "Failed to bind to interface '" << name << "'";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&lladdr, sizeof(struct sockaddr_ll)) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "Failed to bind to interface '" << name << "'";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Switch to non-blocking mode.
|
||||
@ -119,7 +119,7 @@ std::shared_ptr<iface> iface::open_pfd(const std::string& name)
|
||||
if (ioctl(fd, FIONBIO, (char *)&on) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "Failed to switch to non-blocking on interface '" << name << "'";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Set up filter.
|
||||
@ -154,7 +154,7 @@ std::shared_ptr<iface> iface::open_pfd(const std::string& name)
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog)) < 0) {
|
||||
logger::error() << "Failed to set filter";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Set up an instance of 'iface'.
|
||||
@ -166,11 +166,11 @@ std::shared_ptr<iface> iface::open_pfd(const std::string& name)
|
||||
return ifa;
|
||||
}
|
||||
|
||||
std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
ptr<iface> iface::open_ifd(const std::string& name)
|
||||
{
|
||||
int fd;
|
||||
|
||||
std::map<std::string, std::shared_ptr<iface> >::iterator it = _map.find(name);
|
||||
std::map<std::string, ptr<iface> >::iterator it = _map.find(name);
|
||||
|
||||
if ((it != _map.end()) && it->second->_ifd)
|
||||
return it->second;
|
||||
@ -179,7 +179,7 @@ std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
|
||||
if ((fd = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
|
||||
logger::error() << "Unable to create socket";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Bind to the specified interface.
|
||||
@ -193,7 +193,7 @@ std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "Failed to bind to interface '" << name << "'";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Detect the link-layer address.
|
||||
@ -205,7 +205,7 @@ std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "Failed to detect link-layer address for interface '" << name << "'";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
logger::debug() << "fd=" << fd << ", hwaddr=" << ether_ntoa((const struct ether_addr *)&ifr.ifr_hwaddr.sa_data);;
|
||||
@ -217,13 +217,13 @@ std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops, sizeof(hops)) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "iface::open_ifd() failed IPV6_MULTICAST_HOPS";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hops, sizeof(hops)) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "iface::open_ifd() failed IPV6_UNICAST_HOPS";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Switch to non-blocking mode.
|
||||
@ -233,7 +233,7 @@ std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
if (ioctl(fd, FIONBIO, (char *)&on) < 0) {
|
||||
close(fd);
|
||||
logger::error() << "Failed to switch to non-blocking on interface '" << name << "'";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Set up filter.
|
||||
@ -244,15 +244,15 @@ std::shared_ptr<iface> iface::open_ifd(const std::string& name)
|
||||
|
||||
if (setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter)) < 0) {
|
||||
logger::error() << "Failed to set filter";
|
||||
return std::shared_ptr<iface>();
|
||||
return ptr<iface>();
|
||||
}
|
||||
|
||||
// Set up an instance of 'iface'.
|
||||
|
||||
std::shared_ptr<iface> ifa;
|
||||
ptr<iface> ifa;
|
||||
|
||||
if (it == _map.end()) {
|
||||
ifa.reset(new iface());
|
||||
ifa = new iface();
|
||||
ifa->_name = name;
|
||||
ifa->_ptr = ifa;
|
||||
|
||||
@ -451,7 +451,7 @@ void iface::fixup_pollfds()
|
||||
|
||||
logger::debug() << "iface::fixup_pollfds() _map.size()=" << _map.size();
|
||||
|
||||
for (std::map<std::string, std::shared_ptr<iface> >::iterator it = _map.begin();
|
||||
for (std::map<std::string, ptr<iface> >::iterator it = _map.begin();
|
||||
it != _map.end(); it++) {
|
||||
_pollfds[i].fd = it->second->_ifd;
|
||||
_pollfds[i].events = POLLIN;
|
||||
@ -465,18 +465,18 @@ void iface::fixup_pollfds()
|
||||
}
|
||||
}
|
||||
|
||||
void iface::remove_session(const std::shared_ptr<session>& se)
|
||||
void iface::remove_session(const ptr<session>& se)
|
||||
{
|
||||
for (std::list<std::weak_ptr<session> >::iterator it = _sessions.begin();
|
||||
for (std::list<weak_ptr<session> >::iterator it = _sessions.begin();
|
||||
it != _sessions.end(); it++) {
|
||||
if (it->lock() == se) {
|
||||
if (*it == se) {
|
||||
_sessions.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void iface::add_session(const std::shared_ptr<session>& se)
|
||||
void iface::add_session(const ptr<session>& se)
|
||||
{
|
||||
_sessions.push_back(se);
|
||||
}
|
||||
@ -498,7 +498,7 @@ int iface::poll_all()
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
std::map<std::string, std::shared_ptr<iface> >::iterator i_it = _map.begin();
|
||||
std::map<std::string, ptr<iface> >::iterator i_it = _map.begin();
|
||||
|
||||
int i = 0;
|
||||
|
||||
@ -514,7 +514,7 @@ int iface::poll_all()
|
||||
if (!(f_it->revents & POLLIN))
|
||||
continue;
|
||||
|
||||
std::shared_ptr<iface> ifa = i_it->second;
|
||||
ptr<iface> ifa = i_it->second;
|
||||
|
||||
address saddr, daddr, taddr;
|
||||
|
||||
@ -534,9 +534,9 @@ int iface::poll_all()
|
||||
continue;
|
||||
}
|
||||
|
||||
for (std::list<std::weak_ptr<session> >::iterator s_it = ifa->_sessions.begin();
|
||||
for (std::list<weak_ptr<session> >::iterator s_it = ifa->_sessions.begin();
|
||||
s_it != ifa->_sessions.end(); s_it++) {
|
||||
const std::shared_ptr<session> sess = s_it->lock();
|
||||
const ptr<session> sess = *s_it;
|
||||
if ((sess->taddr() == taddr) && (sess->status() == session::WAITING)) {
|
||||
sess->handle_advert();
|
||||
break;
|
||||
@ -582,12 +582,12 @@ const std::string& iface::name() const
|
||||
return _name;
|
||||
}
|
||||
|
||||
void iface::pr(const std::shared_ptr<proxy>& pr)
|
||||
void iface::pr(const ptr<proxy>& pr)
|
||||
{
|
||||
_pr = pr;
|
||||
}
|
||||
|
||||
const std::shared_ptr<proxy>& iface::pr() const
|
||||
const ptr<proxy>& iface::pr() const
|
||||
{
|
||||
return _pr;
|
||||
}
|
||||
|
20
src/iface.h
20
src/iface.h
@ -34,9 +34,9 @@ class iface
|
||||
{
|
||||
private:
|
||||
// Weak pointer so this object can reference itself.
|
||||
std::weak_ptr<iface> _ptr;
|
||||
weak_ptr<iface> _ptr;
|
||||
|
||||
static std::map<std::string, std::shared_ptr<iface> > _map;
|
||||
static std::map<std::string, ptr<iface> > _map;
|
||||
|
||||
// An array of objects used with ::poll.
|
||||
static std::vector<struct pollfd> _pollfds;
|
||||
@ -60,9 +60,9 @@ private:
|
||||
|
||||
// An array of sessions that are monitoring this interface for
|
||||
// ND_NEIGHBOR_ADVERT messages.
|
||||
std::list<std::weak_ptr<session> > _sessions;
|
||||
std::list<weak_ptr<session> > _sessions;
|
||||
|
||||
std::shared_ptr<proxy> _pr;
|
||||
ptr<proxy> _pr;
|
||||
|
||||
// The link-layer address of this interface.
|
||||
struct ether_addr hwaddr;
|
||||
@ -79,9 +79,9 @@ public:
|
||||
// Destructor.
|
||||
~iface();
|
||||
|
||||
static std::shared_ptr<iface> open_ifd(const std::string& name);
|
||||
static ptr<iface> open_ifd(const std::string& name);
|
||||
|
||||
static std::shared_ptr<iface> open_pfd(const std::string& name);
|
||||
static ptr<iface> open_pfd(const std::string& name);
|
||||
|
||||
static int poll_all();
|
||||
|
||||
@ -105,13 +105,13 @@ public:
|
||||
const std::string& name() const;
|
||||
|
||||
// Adds a session to be monitored for ND_NEIGHBOR_ADVERT messages.
|
||||
void add_session(const std::shared_ptr<session>& se);
|
||||
void add_session(const ptr<session>& se);
|
||||
|
||||
void remove_session(const std::shared_ptr<session>& se);
|
||||
void remove_session(const ptr<session>& se);
|
||||
|
||||
void pr(const std::shared_ptr<proxy>& pr);
|
||||
void pr(const ptr<proxy>& pr);
|
||||
|
||||
const std::shared_ptr<proxy>& pr() const;
|
||||
const ptr<proxy>& pr() const;
|
||||
};
|
||||
|
||||
NDPPD_NS_END
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
18
src/ndppd.cc
18
src/ndppd.cc
@ -13,6 +13,8 @@
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <cstdlib>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@ -52,24 +54,24 @@ int daemonize()
|
||||
|
||||
bool configure(const std::string &path)
|
||||
{
|
||||
std::shared_ptr<conf> cf;
|
||||
ptr<conf> cf;
|
||||
|
||||
if (!(cf = conf::load(path)))
|
||||
return false;
|
||||
|
||||
std::vector<std::shared_ptr<conf> >::const_iterator p_it;
|
||||
std::vector<ptr<conf> >::const_iterator p_it;
|
||||
|
||||
std::vector<std::shared_ptr<conf> > proxies(cf->find("proxy"));
|
||||
std::vector<ptr<conf> > proxies(cf->find("proxy"));
|
||||
|
||||
for (p_it = proxies.begin(); p_it != proxies.end(); p_it++) {
|
||||
std::shared_ptr<conf> pr_cf = *p_it, x_cf;
|
||||
ptr<conf> pr_cf = *p_it, x_cf;
|
||||
|
||||
if (pr_cf->value() == "") {
|
||||
logger::error() << "'proxy' section is missing interface name";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<proxy> pr = proxy::open(pr_cf->value());
|
||||
ptr<proxy> pr = proxy::open(pr_cf->value());
|
||||
|
||||
if (!pr) {
|
||||
logger::error() << "Configuration failed for proxy '" << pr_cf->value() << "'";
|
||||
@ -91,12 +93,12 @@ bool configure(const std::string &path)
|
||||
else
|
||||
pr->timeout(x_cf->int_value());
|
||||
|
||||
std::vector<std::shared_ptr<conf> >::const_iterator r_it;
|
||||
std::vector<ptr<conf> >::const_iterator r_it;
|
||||
|
||||
std::vector<std::shared_ptr<conf> > rules(pr_cf->find("rule"));
|
||||
std::vector<ptr<conf> > rules(pr_cf->find("rule"));
|
||||
|
||||
for (r_it = rules.begin(); r_it != rules.end(); r_it++) {
|
||||
std::shared_ptr<conf> ru_cf = *r_it;
|
||||
ptr<conf> ru_cf = *r_it;
|
||||
|
||||
if (ru_cf->value() == "") {
|
||||
logger::error() << "'rule' is missing an IPv6 address/net";
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "ptr.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "conf.h"
|
||||
#include "address.h"
|
||||
|
32
src/proxy.cc
32
src/proxy.cc
@ -31,9 +31,9 @@ proxy::proxy() :
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<proxy> proxy::create(const std::shared_ptr<iface>& ifa)
|
||||
ptr<proxy> proxy::create(const ptr<iface>& ifa)
|
||||
{
|
||||
std::shared_ptr<proxy> pr(new proxy());
|
||||
ptr<proxy> pr(new proxy());
|
||||
pr->_ptr = pr;
|
||||
pr->_ifa = ifa;
|
||||
|
||||
@ -44,12 +44,12 @@ std::shared_ptr<proxy> proxy::create(const std::shared_ptr<iface>& ifa)
|
||||
return pr;
|
||||
}
|
||||
|
||||
std::shared_ptr<proxy> proxy::open(const std::string& ifname)
|
||||
ptr<proxy> proxy::open(const std::string& ifname)
|
||||
{
|
||||
std::shared_ptr<iface> ifa = iface::open_pfd(ifname);
|
||||
ptr<iface> ifa = iface::open_pfd(ifname);
|
||||
|
||||
if (!ifa)
|
||||
return std::shared_ptr<proxy>();
|
||||
return ptr<proxy>();
|
||||
|
||||
return create(ifa);
|
||||
}
|
||||
@ -63,7 +63,7 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
|
||||
// Let's check this proxy's list of sessions to see if we can
|
||||
// find one with the same target address.
|
||||
|
||||
for (std::list<std::shared_ptr<session> >::iterator sit = _sessions.begin();
|
||||
for (std::list<ptr<session> >::iterator sit = _sessions.begin();
|
||||
sit != _sessions.end(); sit++) {
|
||||
|
||||
if ((*sit)->taddr() == taddr) {
|
||||
@ -83,17 +83,17 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
|
||||
// Since we couldn't find a session that matched, we'll try to find
|
||||
// a matching rule instead, and then set up a new session.
|
||||
|
||||
std::shared_ptr<session> se;
|
||||
ptr<session> se;
|
||||
|
||||
for (std::list<std::shared_ptr<rule> >::iterator it = _rules.begin();
|
||||
for (std::list<ptr<rule> >::iterator it = _rules.begin();
|
||||
it != _rules.end(); it++) {
|
||||
std::shared_ptr<rule> ru = *it;
|
||||
ptr<rule> ru = *it;
|
||||
|
||||
logger::debug() << "checking " << ru->addr().to_string() << " against " << taddr;
|
||||
|
||||
if (ru->addr() == taddr) {
|
||||
if (!se)
|
||||
se = session::create(_ptr.lock(), saddr, daddr, taddr);
|
||||
se = session::create(_ptr, saddr, daddr, taddr);
|
||||
|
||||
if (!ru->ifa()) {
|
||||
// This rule doesn't have an interface, and thus we'll consider
|
||||
@ -113,26 +113,26 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<rule> proxy::add_rule(const address& addr, const std::shared_ptr<iface>& ifa)
|
||||
ptr<rule> proxy::add_rule(const address& addr, const ptr<iface>& ifa)
|
||||
{
|
||||
std::shared_ptr<rule> ru(rule::create(_ptr.lock(), addr, ifa));
|
||||
ptr<rule> ru(rule::create(_ptr, addr, ifa));
|
||||
_rules.push_back(ru);
|
||||
return ru;
|
||||
}
|
||||
|
||||
std::shared_ptr<rule> proxy::add_rule(const address& addr)
|
||||
ptr<rule> proxy::add_rule(const address& addr)
|
||||
{
|
||||
std::shared_ptr<rule> ru(rule::create(_ptr.lock(), addr));
|
||||
ptr<rule> ru(rule::create(_ptr, addr));
|
||||
_rules.push_back(ru);
|
||||
return ru;
|
||||
}
|
||||
|
||||
void proxy::remove_session(const std::shared_ptr<session>& se)
|
||||
void proxy::remove_session(const ptr<session>& se)
|
||||
{
|
||||
_sessions.remove(se);
|
||||
}
|
||||
|
||||
const std::shared_ptr<iface>& proxy::ifa() const
|
||||
const ptr<iface>& proxy::ifa() const
|
||||
{
|
||||
return _ifa;
|
||||
}
|
||||
|
20
src/proxy.h
20
src/proxy.h
@ -31,13 +31,13 @@ class rule;
|
||||
class proxy
|
||||
{
|
||||
private:
|
||||
std::weak_ptr<proxy> _ptr;
|
||||
weak_ptr<proxy> _ptr;
|
||||
|
||||
std::shared_ptr<iface> _ifa;
|
||||
ptr<iface> _ifa;
|
||||
|
||||
std::list<std::shared_ptr<rule> > _rules;
|
||||
std::list<ptr<rule> > _rules;
|
||||
|
||||
std::list<std::shared_ptr<session> > _sessions;
|
||||
std::list<ptr<session> > _sessions;
|
||||
|
||||
bool _router;
|
||||
|
||||
@ -46,20 +46,20 @@ private:
|
||||
proxy();
|
||||
|
||||
public:
|
||||
static std::shared_ptr<proxy> create(const std::shared_ptr<iface>& ifa);
|
||||
static ptr<proxy> create(const ptr<iface>& ifa);
|
||||
|
||||
static std::shared_ptr<proxy> open(const std::string& ifn);
|
||||
static ptr<proxy> open(const std::string& ifn);
|
||||
|
||||
void handle_solicit(const address& saddr, const address& daddr,
|
||||
const address& taddr);
|
||||
|
||||
void remove_session(const std::shared_ptr<session>& se);
|
||||
void remove_session(const ptr<session>& se);
|
||||
|
||||
std::shared_ptr<rule> add_rule(const address& addr, const std::shared_ptr<iface>& ifa);
|
||||
ptr<rule> add_rule(const address& addr, const ptr<iface>& ifa);
|
||||
|
||||
std::shared_ptr<rule> add_rule(const address& addr);
|
||||
ptr<rule> add_rule(const address& addr);
|
||||
|
||||
const std::shared_ptr<iface>& ifa() const;
|
||||
const ptr<iface>& ifa() const;
|
||||
|
||||
bool router() const;
|
||||
|
||||
|
10
src/rule.cc
10
src/rule.cc
@ -28,9 +28,9 @@ rule::rule()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<rule> rule::create(const std::shared_ptr<proxy>& pr, const address& addr, const std::shared_ptr<iface>& ifa)
|
||||
ptr<rule> rule::create(const ptr<proxy>& pr, const address& addr, const ptr<iface>& ifa)
|
||||
{
|
||||
std::shared_ptr<rule> ru(new rule());
|
||||
ptr<rule> ru(new rule());
|
||||
ru->_ptr = ru;
|
||||
ru->_pr = pr;
|
||||
ru->_ifa = ifa;
|
||||
@ -41,9 +41,9 @@ std::shared_ptr<rule> rule::create(const std::shared_ptr<proxy>& pr, const addre
|
||||
return ru;
|
||||
}
|
||||
|
||||
std::shared_ptr<rule> rule::create(const std::shared_ptr<proxy>& pr, const address& addr)
|
||||
ptr<rule> rule::create(const ptr<proxy>& pr, const address& addr)
|
||||
{
|
||||
std::shared_ptr<rule> ru(new rule());
|
||||
ptr<rule> ru(new rule());
|
||||
ru->_ptr = ru;
|
||||
ru->_pr = pr;
|
||||
ru->_addr = addr;
|
||||
@ -58,7 +58,7 @@ const address& rule::addr() const
|
||||
return _addr;
|
||||
}
|
||||
|
||||
std::shared_ptr<iface> rule::ifa() const
|
||||
ptr<iface> rule::ifa() const
|
||||
{
|
||||
return _ifa;
|
||||
}
|
||||
|
12
src/rule.h
12
src/rule.h
@ -31,24 +31,24 @@ class proxy;
|
||||
class rule
|
||||
{
|
||||
private:
|
||||
std::weak_ptr<rule> _ptr;
|
||||
weak_ptr<rule> _ptr;
|
||||
|
||||
std::shared_ptr<proxy> _pr;
|
||||
ptr<proxy> _pr;
|
||||
|
||||
std::shared_ptr<iface> _ifa;
|
||||
ptr<iface> _ifa;
|
||||
|
||||
address _addr;
|
||||
|
||||
rule();
|
||||
|
||||
public:
|
||||
static std::shared_ptr<rule> create(const std::shared_ptr<proxy>& pr, const address& addr, const std::shared_ptr<iface>& ifa);
|
||||
static ptr<rule> create(const ptr<proxy>& pr, const address& addr, const ptr<iface>& ifa);
|
||||
|
||||
static std::shared_ptr<rule> create(const std::shared_ptr<proxy>& pr, const address& addr);
|
||||
static ptr<rule> create(const ptr<proxy>& pr, const address& addr);
|
||||
|
||||
const address& addr() const;
|
||||
|
||||
std::shared_ptr<iface> ifa() const;
|
||||
ptr<iface> ifa() const;
|
||||
|
||||
bool is_static() const;
|
||||
|
||||
|
@ -22,13 +22,13 @@
|
||||
|
||||
NDPPD_NS_BEGIN
|
||||
|
||||
std::list<std::weak_ptr<session> > session::_sessions;
|
||||
std::list<weak_ptr<session> > session::_sessions;
|
||||
|
||||
void session::update_all(int elapsed_time)
|
||||
{
|
||||
for (std::list<std::weak_ptr<session> >::iterator it = _sessions.begin();
|
||||
for (std::list<weak_ptr<session> >::iterator it = _sessions.begin();
|
||||
it != _sessions.end(); ) {
|
||||
std::shared_ptr<session> se = (*it++).lock();
|
||||
ptr<session> se = (*it++);
|
||||
|
||||
if ((se->_ttl -= elapsed_time) >= 0)
|
||||
continue;
|
||||
@ -50,24 +50,24 @@ session::~session()
|
||||
{
|
||||
logger::debug() << "session::~session() this=" << logger::format("%x", this);
|
||||
|
||||
for (std::list<std::weak_ptr<session> >::iterator it = _sessions.begin();
|
||||
for (std::list<weak_ptr<session> >::iterator it = _sessions.begin();
|
||||
it != _sessions.end(); it++) {
|
||||
if (it->lock() == _ptr.lock()) {
|
||||
if (*it == _ptr) {
|
||||
_sessions.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::list<std::shared_ptr<iface> >::iterator it = _ifaces.begin();
|
||||
for (std::list<ptr<iface> >::iterator it = _ifaces.begin();
|
||||
it != _ifaces.end(); it++) {
|
||||
(*it)->remove_session(_ptr.lock());
|
||||
(*it)->remove_session(_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<session> session::create(const std::shared_ptr<proxy>& pr, const address& saddr,
|
||||
ptr<session> session::create(const ptr<proxy>& pr, const address& saddr,
|
||||
const address& daddr, const address& taddr)
|
||||
{
|
||||
std::shared_ptr<session> se(new session());
|
||||
ptr<session> se(new session());
|
||||
|
||||
se->_ptr = se;
|
||||
se->_pr = pr;
|
||||
@ -78,18 +78,19 @@ std::shared_ptr<session> session::create(const std::shared_ptr<proxy>& pr, const
|
||||
|
||||
_sessions.push_back(se);
|
||||
|
||||
logger::debug() << "session::create() pr=" << logger::format("%x", pr.get()) << ", saddr=" << saddr
|
||||
<< ", daddr=" << daddr << ", taddr=" << taddr << " =" << logger::format("%x", se.get());
|
||||
logger::debug()
|
||||
<< "session::create() pr=" << logger::format("%x", (proxy *)pr) << ", saddr=" << saddr
|
||||
<< ", daddr=" << daddr << ", taddr=" << taddr << " =" << logger::format("%x", (session *)se);
|
||||
|
||||
return se;
|
||||
}
|
||||
|
||||
void session::add_iface(const std::shared_ptr<iface>& ifa)
|
||||
void session::add_iface(const ptr<iface>& ifa)
|
||||
{
|
||||
if (std::find(_ifaces.begin(), _ifaces.end(), ifa) != _ifaces.end())
|
||||
return;
|
||||
|
||||
ifa->add_session(_ptr.lock());
|
||||
ifa->add_session(_ptr);
|
||||
_ifaces.push_back(ifa);
|
||||
}
|
||||
|
||||
@ -97,7 +98,7 @@ void session::send_solicit()
|
||||
{
|
||||
logger::debug() << "session::send_solicit() (" << _ifaces.size() << ")";
|
||||
|
||||
for (std::list<std::shared_ptr<iface> >::iterator it = _ifaces.begin();
|
||||
for (std::list<ptr<iface> >::iterator it = _ifaces.begin();
|
||||
it != _ifaces.end(); it++) {
|
||||
logger::debug() << " - %s" << (*it)->name();
|
||||
(*it)->write_solicit(_taddr);
|
||||
|
@ -27,15 +27,15 @@ class iface;
|
||||
class session
|
||||
{
|
||||
private:
|
||||
std::weak_ptr<session> _ptr;
|
||||
weak_ptr<session> _ptr;
|
||||
|
||||
std::shared_ptr<proxy> _pr;
|
||||
ptr<proxy> _pr;
|
||||
|
||||
address _saddr, _daddr, _taddr;
|
||||
|
||||
// An array of interfaces this session is monitoring for
|
||||
// ND_NEIGHBOR_ADVERT on.
|
||||
std::list<std::shared_ptr<iface> > _ifaces;
|
||||
std::list<ptr<iface> > _ifaces;
|
||||
|
||||
// The remaining time in miliseconds the object will stay in the
|
||||
// interface's session array or cache.
|
||||
@ -43,7 +43,7 @@ private:
|
||||
|
||||
int _status;
|
||||
|
||||
static std::list<std::weak_ptr<session> > _sessions;
|
||||
static std::list<weak_ptr<session> > _sessions;
|
||||
|
||||
public:
|
||||
enum
|
||||
@ -58,10 +58,10 @@ public:
|
||||
// Destructor.
|
||||
~session();
|
||||
|
||||
static std::shared_ptr<session> create(const std::shared_ptr<proxy>& pr, const address& saddr,
|
||||
static ptr<session> create(const ptr<proxy>& pr, const address& saddr,
|
||||
const address& daddr, const address& taddr);
|
||||
|
||||
void add_iface(const std::shared_ptr<iface>& ifa);
|
||||
void add_iface(const ptr<iface>& ifa);
|
||||
|
||||
const address& taddr() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user