Major changes
This commit is contained in:
parent
456813fb9e
commit
e37df74b8e
64
src/iface.cc
64
src/iface.cc
@ -211,8 +211,6 @@ ssize_t iface::read(address& saddr, address& daddr, uint8_t *msg, size_t size)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ssize_t iface::write(address& saddr, address& daddr, uint8_t *msg, size_t size)
|
|
||||||
|
|
||||||
ssize_t iface::write(const address& daddr, const uint8_t *msg, size_t size)
|
ssize_t iface::write(const address& daddr, const uint8_t *msg, size_t size)
|
||||||
{
|
{
|
||||||
struct sockaddr_in6 daddr_tmp;
|
struct sockaddr_in6 daddr_tmp;
|
||||||
@ -220,7 +218,6 @@ ssize_t iface::write(const address& daddr, const uint8_t *msg, size_t size)
|
|||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
|
|
||||||
memset(&daddr_tmp, 0, sizeof(struct sockaddr_in6));
|
memset(&daddr_tmp, 0, sizeof(struct sockaddr_in6));
|
||||||
//daddr_tmp.sin6_len = sizeof(struct sockaddr_in6);
|
|
||||||
daddr_tmp.sin6_family = AF_INET6;
|
daddr_tmp.sin6_family = AF_INET6;
|
||||||
daddr_tmp.sin6_port = htons(IPPROTO_ICMPV6); // Needed?
|
daddr_tmp.sin6_port = htons(IPPROTO_ICMPV6); // Needed?
|
||||||
memcpy(&daddr_tmp.sin6_addr, &daddr.const_addr(), sizeof(struct in6_addr));
|
memcpy(&daddr_tmp.sin6_addr, &daddr.const_addr(), sizeof(struct in6_addr));
|
||||||
@ -234,9 +231,6 @@ ssize_t iface::write(const address& daddr, const uint8_t *msg, size_t size)
|
|||||||
mhdr.msg_iov = &iov;
|
mhdr.msg_iov = &iov;
|
||||||
mhdr.msg_iovlen = 1;
|
mhdr.msg_iovlen = 1;
|
||||||
|
|
||||||
/*mhdr.msg_control = (void *)cmsg;
|
|
||||||
mhdr.msg_controllen = sizeof(chdr);*/
|
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if((len = sendmsg(_fd, &mhdr, 0)) < 0)
|
if((len = sendmsg(_fd, &mhdr, 0)) < 0)
|
||||||
@ -247,18 +241,18 @@ ssize_t iface::write(const address& daddr, const uint8_t *msg, size_t size)
|
|||||||
|
|
||||||
ssize_t iface::write_solicit(const address& taddr)
|
ssize_t iface::write_solicit(const address& taddr)
|
||||||
{
|
{
|
||||||
struct nd_neighbor_solicit msg;
|
struct nd_neighbor_solicit ns;
|
||||||
|
|
||||||
// FIXME: Alright, I'm lazy.
|
// FIXME: Alright, I'm lazy.
|
||||||
static address multicast("ff02::1:ff00:0000");
|
static address multicast("ff02::1:ff00:0000");
|
||||||
|
|
||||||
address daddr;
|
address daddr;
|
||||||
|
|
||||||
memset(&msg, 0, sizeof(struct nd_neighbor_solicit));
|
memset(&ns, 0, sizeof(struct nd_neighbor_solicit));
|
||||||
|
|
||||||
msg.nd_ns_hdr.icmp6_type = ND_NEIGHBOR_SOLICIT;
|
ns.nd_ns_type = ND_NEIGHBOR_SOLICIT;
|
||||||
|
|
||||||
memcpy(&msg.nd_ns_target, &taddr.const_addr(), sizeof(struct in6_addr));
|
memcpy(&ns.nd_ns_target, &taddr.const_addr(), sizeof(struct in6_addr));
|
||||||
|
|
||||||
daddr = multicast;
|
daddr = multicast;
|
||||||
|
|
||||||
@ -269,14 +263,33 @@ ssize_t iface::write_solicit(const address& taddr)
|
|||||||
DBG("iface::write_solicit() taddr=%s, daddr=%s",
|
DBG("iface::write_solicit() taddr=%s, daddr=%s",
|
||||||
taddr.to_string().c_str(), daddr.to_string().c_str());
|
taddr.to_string().c_str(), daddr.to_string().c_str());
|
||||||
|
|
||||||
return write(daddr, (uint8_t *)&msg, sizeof(struct nd_neighbor_solicit));
|
return write(daddr, (uint8_t *)&ns, sizeof(struct nd_neighbor_solicit));
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t iface::write_advert(const address& daddr, const address& taddr)
|
ssize_t iface::write_advert(const address& daddr, const address& taddr)
|
||||||
{
|
{
|
||||||
struct nd_neighbor_advert msg;
|
char buf[256];
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
|
struct nd_neighbor_advert *na =
|
||||||
|
(struct nd_neighbor_advert *)&buf[0];
|
||||||
|
|
||||||
|
struct nd_opt_hdr *opt =
|
||||||
|
(struct nd_opt_hdr *)&buf[sizeof(struct nd_neighbor_advert)];
|
||||||
|
|
||||||
|
opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
|
||||||
|
opt->nd_opt_len = 1;
|
||||||
|
|
||||||
|
na->nd_na_type = ND_NEIGHBOR_ADVERT;
|
||||||
|
na->nd_na_flags_reserved = ND_NA_FLAG_SOLICITED | ND_NA_FLAG_ROUTER;
|
||||||
|
|
||||||
|
memcpy(&na->nd_na_target, &taddr.const_addr(), sizeof(struct in6_addr));
|
||||||
|
|
||||||
|
memcpy(buf + sizeof(struct nd_neighbor_advert) + sizeof(struct nd_opt_hdr), &hwaddr, 6);
|
||||||
|
|
||||||
|
return write(daddr, (uint8_t *)buf, sizeof(struct nd_neighbor_advert) +
|
||||||
|
sizeof(struct nd_opt_hdr) + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
int iface::read_nd(address& saddr, address& daddr, address& taddr)
|
int iface::read_nd(address& saddr, address& daddr, address& taddr)
|
||||||
@ -312,7 +325,7 @@ void iface::fixup_pollfds()
|
|||||||
DBG("iface::fixup_pollfds() _map.size()=%d", _map.size());
|
DBG("iface::fixup_pollfds() _map.size()=%d", _map.size());
|
||||||
|
|
||||||
for(std::map<std::string, ptr<iface> >::iterator it = _map.begin();
|
for(std::map<std::string, ptr<iface> >::iterator it = _map.begin();
|
||||||
it != _map.end(); it++)
|
it != _map.end(); it++)
|
||||||
{
|
{
|
||||||
_pollfds[i].fd = it->second->_fd;
|
_pollfds[i].fd = it->second->_fd;
|
||||||
_pollfds[i].events = POLLIN;
|
_pollfds[i].events = POLLIN;
|
||||||
@ -364,19 +377,17 @@ int iface::poll_all()
|
|||||||
if(len == 0)
|
if(len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
std::vector<struct pollfd>::iterator fit;
|
std::vector<struct pollfd>::iterator f_it;
|
||||||
std::map<std::string, ptr<iface> >::iterator iit;
|
std::map<std::string, ptr<iface> >::iterator i_it;
|
||||||
|
|
||||||
for(fit = _pollfds.begin(), iit = _map.begin(); fit != _pollfds.end(); fit++, iit++)
|
for(f_it = _pollfds.begin(), i_it = _map.begin(); f_it != _pollfds.end(); f_it++, i_it++)
|
||||||
{
|
{
|
||||||
if(!(fit->revents & POLLIN))
|
if(!(f_it->revents & POLLIN))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// We assume here that _pollfds is perfectly aligned with _map.
|
// We assume here that _pollfds is perfectly aligned with _map.
|
||||||
|
|
||||||
ptr<iface> ifa = iit->second;
|
ptr<iface> ifa = i_it->second;
|
||||||
|
|
||||||
//DBG("POLLIN on %s", ifa->_name.c_str());
|
|
||||||
|
|
||||||
int icmp6_type;
|
int icmp6_type;
|
||||||
address saddr, daddr, taddr;
|
address saddr, daddr, taddr;
|
||||||
@ -391,8 +402,6 @@ int iface::poll_all()
|
|||||||
{
|
{
|
||||||
DBG("ND_NEIGHBOR_SOLICIT");
|
DBG("ND_NEIGHBOR_SOLICIT");
|
||||||
|
|
||||||
// TODO: Check the cache for recent sessions.
|
|
||||||
|
|
||||||
ifa->_proxy->handle_solicit(saddr, daddr, taddr);
|
ifa->_proxy->handle_solicit(saddr, daddr, taddr);
|
||||||
}
|
}
|
||||||
else if(icmp6_type == ND_NEIGHBOR_ADVERT)
|
else if(icmp6_type == ND_NEIGHBOR_ADVERT)
|
||||||
@ -402,10 +411,12 @@ int iface::poll_all()
|
|||||||
for(std::list<ptr<session> >::iterator s_it = ifa->_sessions.begin();
|
for(std::list<ptr<session> >::iterator s_it = ifa->_sessions.begin();
|
||||||
s_it != ifa->_sessions.end(); s_it++)
|
s_it != ifa->_sessions.end(); s_it++)
|
||||||
{
|
{
|
||||||
/*if((*s_it)->addr() == taddr)
|
ptr<session> se = *s_it;
|
||||||
{
|
|
||||||
(*s_it)->handle_advert();
|
//if((se->daddr() =
|
||||||
}*/
|
|
||||||
|
|
||||||
|
//(*s_it)->handle_advert();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -420,4 +431,3 @@ const std::string& iface::name() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
__NDPPD_NS_END
|
__NDPPD_NS_END
|
||||||
|
|
||||||
|
@ -101,5 +101,3 @@ public:
|
|||||||
__NDPPD_NS_END
|
__NDPPD_NS_END
|
||||||
|
|
||||||
#endif // __NDPPD_IFACE_H
|
#endif // __NDPPD_IFACE_H
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
__NDPPD_NS_BEGIN
|
__NDPPD_NS_BEGIN
|
||||||
|
|
||||||
// This template class simplifies the usage of pointers. It's basically
|
// This template class simplifies the usage of pointers. It's basically
|
||||||
// a reference-counting smart-pointer that supports both weak and
|
// a reference-counting smart pointer that supports both weak and
|
||||||
// strong references.
|
// strong references.
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -204,5 +204,3 @@ public:
|
|||||||
__NDPPD_NS_END
|
__NDPPD_NS_END
|
||||||
|
|
||||||
#endif // __NDPPD_PTR_H
|
#endif // __NDPPD_PTR_H
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ session::~session()
|
|||||||
{
|
{
|
||||||
(*it)->remove_session(_weak_ptr);
|
(*it)->remove_session(_weak_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr<session> session::create(const ptr<proxy>& pr, const address& saddr,
|
ptr<session> session::create(const ptr<proxy>& pr, const address& saddr,
|
||||||
@ -99,7 +98,6 @@ void session::send_solicit()
|
|||||||
{
|
{
|
||||||
DBG(" on %s", (*it)->name().c_str());
|
DBG(" on %s", (*it)->name().c_str());
|
||||||
(*it)->write_solicit(_taddr);
|
(*it)->write_solicit(_taddr);
|
||||||
// huhh hahh.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,12 +131,4 @@ int session::status() const
|
|||||||
return _status;
|
return _status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__NDPPD_NS_END
|
__NDPPD_NS_END
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user