Add some checks in mud_set_path()
They are useless in theory but as we do not define the macros CMSG_FIRSTHDR and CMSG_NXTHDR.. Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
27
mud.c
27
mud.c
@@ -411,7 +411,7 @@ mud_cmp_addr(struct sockaddr *a, struct sockaddr *b)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
mud_set_path(struct mud_path *path, struct mud_ipaddr *local_addr,
|
mud_set_path(struct mud_path *path, struct mud_ipaddr *local_addr,
|
||||||
struct sockaddr *addr)
|
struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
@@ -422,6 +422,9 @@ mud_set_path(struct mud_path *path, struct mud_ipaddr *local_addr,
|
|||||||
|
|
||||||
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
|
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
|
|
||||||
|
if (!cmsg)
|
||||||
|
return -1;
|
||||||
|
|
||||||
memset(path->ctrl.data, 0, sizeof(path->ctrl.data));
|
memset(path->ctrl.data, 0, sizeof(path->ctrl.data));
|
||||||
memmove(&path->local_addr, local_addr, sizeof(struct mud_ipaddr));
|
memmove(&path->local_addr, local_addr, sizeof(struct mud_ipaddr));
|
||||||
|
|
||||||
@@ -438,6 +441,9 @@ mud_set_path(struct mud_path *path, struct mud_ipaddr *local_addr,
|
|||||||
|
|
||||||
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
||||||
|
|
||||||
|
if (!cmsg)
|
||||||
|
return -1;
|
||||||
|
|
||||||
cmsg->cmsg_level = IPPROTO_IP;
|
cmsg->cmsg_level = IPPROTO_IP;
|
||||||
cmsg->cmsg_type = IP_TOS;
|
cmsg->cmsg_type = IP_TOS;
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
@@ -460,6 +466,9 @@ mud_set_path(struct mud_path *path, struct mud_ipaddr *local_addr,
|
|||||||
|
|
||||||
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
||||||
|
|
||||||
|
if (!cmsg)
|
||||||
|
return -1;
|
||||||
|
|
||||||
cmsg->cmsg_level = IPPROTO_IPV6;
|
cmsg->cmsg_level = IPPROTO_IPV6;
|
||||||
cmsg->cmsg_type = IPV6_TCLASS;
|
cmsg->cmsg_type = IPV6_TCLASS;
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
@@ -468,14 +477,18 @@ mud_set_path(struct mud_path *path, struct mud_ipaddr *local_addr,
|
|||||||
path->ctrl.size = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
path->ctrl.size = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
||||||
CMSG_SPACE(sizeof(int));
|
CMSG_SPACE(sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct mud_path *
|
static struct mud_path *
|
||||||
mud_path(struct mud *mud, struct mud_ipaddr *local_addr,
|
mud_path(struct mud *mud, struct mud_ipaddr *local_addr,
|
||||||
struct sockaddr *addr, int create)
|
struct sockaddr *addr, int create)
|
||||||
{
|
{
|
||||||
if (local_addr->family != addr->sa_family)
|
if (local_addr->family != addr->sa_family) {
|
||||||
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct mud_path *path;
|
struct mud_path *path;
|
||||||
|
|
||||||
@@ -497,7 +510,11 @@ mud_path(struct mud *mud, struct mud_ipaddr *local_addr,
|
|||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
mud_set_path(path, local_addr, addr);
|
if (mud_set_path(path, local_addr, addr)) {
|
||||||
|
free(path);
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
path->conf.mtu.local = mud->mtu; // XXX
|
path->conf.mtu.local = mud->mtu; // XXX
|
||||||
|
|
||||||
@@ -538,10 +555,8 @@ mud_peer(struct mud *mud, const char *name, const char *host, int port,
|
|||||||
|
|
||||||
struct mud_path *path = mud_path(mud, &local_addr, (struct sockaddr *)&addr, 1);
|
struct mud_path *path = mud_path(mud, &local_addr, (struct sockaddr *)&addr, 1);
|
||||||
|
|
||||||
if (!path) {
|
if (!path)
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
path->state.active = 1;
|
path->state.active = 1;
|
||||||
path->state.backup = !!backup;
|
path->state.backup = !!backup;
|
||||||
|
|||||||
Reference in New Issue
Block a user