A couple of bugfixes
* Fix a bug where pollfds would be changed while in the poll_all loop. This issue didn't exist before 'auto' was implemented. * Fix so 'auto' rules won't try to forward Neighbor Solicitation Packages through proxy's interface. * Some code cleanup.
This commit is contained in:
parent
13b81fdd97
commit
0dbc3e288a
@ -245,18 +245,21 @@ bool address::parse_string(const std::string& str)
|
||||
if (*p++ != '/')
|
||||
return false;
|
||||
|
||||
while (*p && isspace(*p))
|
||||
while (*p && isspace(*p)) {
|
||||
p++;
|
||||
}
|
||||
|
||||
sz = 0;
|
||||
b = buf;
|
||||
|
||||
while (*p) {
|
||||
if (!isdigit(*p))
|
||||
if (!isdigit(*p)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sz > 3)
|
||||
if (sz > 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*b++ =* p++;
|
||||
sz++;
|
||||
|
14
src/iface.cc
14
src/iface.cc
@ -169,7 +169,7 @@ ptr<iface> iface::open_pfd(const std::string& name)
|
||||
|
||||
ifa->_pfd = fd;
|
||||
|
||||
fixup_pollfds();
|
||||
_map_dirty = true;
|
||||
|
||||
return ifa;
|
||||
}
|
||||
@ -273,7 +273,7 @@ ptr<iface> iface::open_ifd(const std::string& name)
|
||||
|
||||
memcpy(&ifa->hwaddr, ifr.ifr_hwaddr.sa_data, sizeof(struct ether_addr));
|
||||
|
||||
fixup_pollfds();
|
||||
_map_dirty = true;
|
||||
|
||||
return ifa;
|
||||
}
|
||||
@ -453,10 +453,6 @@ ssize_t iface::read_advert(address& saddr, address& taddr)
|
||||
|
||||
void iface::fixup_pollfds()
|
||||
{
|
||||
if (_map_dirty) {
|
||||
clean();
|
||||
}
|
||||
|
||||
_pollfds.resize(_map.size()* 2);
|
||||
|
||||
int i = 0;
|
||||
@ -493,7 +489,7 @@ void iface::add_session(const ptr<session>& se)
|
||||
_sessions.push_back(se);
|
||||
}
|
||||
|
||||
void iface::clean()
|
||||
void iface::cleanup()
|
||||
{
|
||||
for (std::map<std::string, weak_ptr<iface> >::iterator it = _map.begin();
|
||||
it != _map.end(); it++) {
|
||||
@ -501,14 +497,14 @@ void iface::clean()
|
||||
_map.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
_map_dirty = false;
|
||||
}
|
||||
|
||||
int iface::poll_all()
|
||||
{
|
||||
if (_map_dirty) {
|
||||
cleanup();
|
||||
fixup_pollfds();
|
||||
_map_dirty = false;
|
||||
}
|
||||
|
||||
if (_pollfds.size() == 0) {
|
||||
|
@ -81,7 +81,7 @@ private:
|
||||
// Updates the array above.
|
||||
static void fixup_pollfds();
|
||||
|
||||
static void clean();
|
||||
static void cleanup();
|
||||
|
||||
// Weak pointer so this object can reference itself.
|
||||
weak_ptr<iface> _ptr;
|
||||
|
11
src/proxy.cc
11
src/proxy.cc
@ -104,13 +104,16 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
|
||||
}
|
||||
|
||||
if (ru->is_auto()) {
|
||||
ptr<iface> ifa = route::find_and_open(taddr);
|
||||
ptr<route> rt = route::find(taddr);
|
||||
|
||||
if (rt->ifname() == _ifa->name()) {
|
||||
logger::debug() << "skipping route since it's using interface " << rt->ifname();
|
||||
} else {
|
||||
ptr<iface> ifa = rt->ifa();
|
||||
|
||||
// If we could find a route matching our rule in /proc/net/ipv6_route,
|
||||
// and it's not the same interface as the one pr (proxy) is using.
|
||||
if (ifa && (ifa != ru->ifa())) {
|
||||
se->add_iface(ifa);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (!ru->ifa()) {
|
||||
// This rule doesn't have an interface, and thus we'll consider
|
||||
|
21
src/route.cc
21
src/route.cc
@ -36,25 +36,29 @@ route::route(const address& addr, const std::string& ifname) :
|
||||
size_t route::hexdec(const char* str, unsigned char* buf, size_t size)
|
||||
{
|
||||
for (size_t i = 0; ; i++) {
|
||||
if (i >= size)
|
||||
if (i >= size) {
|
||||
return i;
|
||||
}
|
||||
|
||||
char c1 = tolower(str[i* 2]), c2 = tolower(str[i* 2 + 1]);
|
||||
|
||||
if (!isxdigit(c1) || !isxdigit(c2))
|
||||
if (!isxdigit(c1) || !isxdigit(c2)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
if ((c1 >= '0') && (c1 <= '9'))
|
||||
if ((c1 >= '0') && (c1 <= '9')) {
|
||||
buf[i] = (c1 - '0') << 4;
|
||||
else
|
||||
} else {
|
||||
buf[i] = ((c1 - 'a') + 10) << 4;
|
||||
}
|
||||
|
||||
if ((c2 >= '0') && (c2 <= '9'))
|
||||
if ((c2 >= '0') && (c2 <= '9')) {
|
||||
buf[i] |= c2 - '0';
|
||||
else
|
||||
} else {
|
||||
buf[i] |= (c2 - 'a') + 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string route::token(const char* str)
|
||||
{
|
||||
@ -89,8 +93,9 @@ void route::load(const std::string& path)
|
||||
char buf[1024];
|
||||
ifs.getline(buf, sizeof(buf));
|
||||
|
||||
if (ifs.gcount() < 149)
|
||||
if (ifs.gcount() < 149) {
|
||||
continue;
|
||||
}
|
||||
|
||||
address addr;
|
||||
|
||||
@ -127,7 +132,7 @@ void route::update(int elapsed_time)
|
||||
ptr<route> route::create(const address& addr, const std::string& ifname)
|
||||
{
|
||||
ptr<route> rt(new route(addr, ifname));
|
||||
logger::debug() << "route::create() addr=" << addr << ", ifname=" << ifname;
|
||||
// logger::debug() << "route::create() addr=" << addr << ", ifname=" << ifname;
|
||||
_routes.push_back(rt);
|
||||
return rt;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user