Reset path before ping
This commit is contained in:
50
mud.c
50
mud.c
@@ -361,6 +361,8 @@ void mud_set_path (struct path *path, unsigned index,
|
|||||||
MUD_ASSERT(sizeof(index)==sizeof(((struct in_pktinfo *)0)->ipi_ifindex));
|
MUD_ASSERT(sizeof(index)==sizeof(((struct in_pktinfo *)0)->ipi_ifindex));
|
||||||
|
|
||||||
path->index = index;
|
path->index = index;
|
||||||
|
|
||||||
|
if (addr != (struct sockaddr *)&path->addr)
|
||||||
memcpy(&path->addr, addr, sizeof(struct sockaddr_in));
|
memcpy(&path->addr, addr, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
cmsg->cmsg_level = IPPROTO_IP;
|
cmsg->cmsg_level = IPPROTO_IP;
|
||||||
@@ -381,6 +383,8 @@ void mud_set_path (struct path *path, unsigned index,
|
|||||||
MUD_ASSERT(sizeof(index)==sizeof(((struct in6_pktinfo *)0)->ipi6_ifindex));
|
MUD_ASSERT(sizeof(index)==sizeof(((struct in6_pktinfo *)0)->ipi6_ifindex));
|
||||||
|
|
||||||
path->index = index;
|
path->index = index;
|
||||||
|
|
||||||
|
if (addr != (struct sockaddr *)&path->addr)
|
||||||
memcpy(&path->addr, addr, sizeof(struct sockaddr_in6));
|
memcpy(&path->addr, addr, sizeof(struct sockaddr_in6));
|
||||||
|
|
||||||
cmsg->cmsg_level = IPPROTO_IPV6;
|
cmsg->cmsg_level = IPPROTO_IPV6;
|
||||||
@@ -399,29 +403,17 @@ void mud_set_path (struct path *path, unsigned index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
struct path *mud_new_path (struct mud *mud, unsigned index, struct sockaddr *addr)
|
void mud_reset_path (struct path *path, unsigned index, struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
struct path *path = mud_get_path(mud, index, addr);
|
char name[IF_NAMESIZE];
|
||||||
|
|
||||||
if (path)
|
if (if_indextoname(index, name) != name)
|
||||||
return path;
|
return;
|
||||||
|
|
||||||
struct iface *iface = mud_get_iface(mud, index);
|
struct ifaddrs *ifaddrs = NULL;
|
||||||
|
|
||||||
if (!iface)
|
if ((getifaddrs(&ifaddrs) == -1) || !ifaddrs)
|
||||||
return NULL;
|
return;
|
||||||
|
|
||||||
path = calloc(1, sizeof(struct path));
|
|
||||||
|
|
||||||
if (!path)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
struct ifaddrs *ifaddrs;
|
|
||||||
|
|
||||||
if (getifaddrs(&ifaddrs) == -1) {
|
|
||||||
free(path);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (struct ifaddrs *ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
|
for (struct ifaddrs *ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
|
||||||
struct sockaddr *ifa_addr = ifa->ifa_addr;
|
struct sockaddr *ifa_addr = ifa->ifa_addr;
|
||||||
@@ -432,14 +424,31 @@ struct path *mud_new_path (struct mud *mud, unsigned index, struct sockaddr *add
|
|||||||
if (ifa_addr->sa_family != addr->sa_family)
|
if (ifa_addr->sa_family != addr->sa_family)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strncmp(iface->name, ifa->ifa_name, sizeof(iface->name)))
|
if (strncmp(name, ifa->ifa_name, sizeof(name)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mud_set_path(path, index, addr, ifa_addr);
|
mud_set_path(path, index, addr, ifa_addr);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeifaddrs(ifaddrs);
|
freeifaddrs(ifaddrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
struct path *mud_new_path (struct mud *mud, unsigned index, struct sockaddr *addr)
|
||||||
|
{
|
||||||
|
struct path *path = mud_get_path(mud, index, addr);
|
||||||
|
|
||||||
|
if (path)
|
||||||
|
return path;
|
||||||
|
|
||||||
|
path = calloc(1, sizeof(struct path));
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
mud_reset_path(path, index, addr);
|
||||||
|
|
||||||
if (!path->index) {
|
if (!path->index) {
|
||||||
free(path);
|
free(path);
|
||||||
@@ -1123,6 +1132,7 @@ int mud_push (struct mud *mud)
|
|||||||
(now-path->send.time) < mud->send_timeout)
|
(now-path->send.time) < mud->send_timeout)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
mud_reset_path(path, path->index, (struct sockaddr *)&path->addr);
|
||||||
mud_ping_path(mud, path, now);
|
mud_ping_path(mud, path, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user