netlib/setroute: fix dhcpd stack-overflow when calls netlib_set_dripv4addr with debug info-level
Signed-off-by: meijian <meijian@xiaomi.com>
This commit is contained in:
parent
05def1befc
commit
c91a1817aa
@ -258,10 +258,9 @@ int main(int argc, FAR char *argv[])
|
||||
FAR char *iobuffer = NULL;
|
||||
struct sockaddr_in6 host;
|
||||
#ifdef CONFIG_NET_ROUTE
|
||||
struct sockaddr_storage target;
|
||||
struct sockaddr_storage router;
|
||||
struct sockaddr_storage netmask;
|
||||
FAR struct sockaddr_in6 *v6_addr;
|
||||
struct sockaddr_in6 target;
|
||||
struct sockaddr_in6 router;
|
||||
struct sockaddr_in6 netmask;
|
||||
#endif
|
||||
struct ipv6_mreq mrec;
|
||||
int nsec;
|
||||
@ -361,21 +360,18 @@ int main(int argc, FAR char *argv[])
|
||||
/* Set up a routing table entry for the address of the multicast group */
|
||||
|
||||
memset(&target, 0, sizeof(target));
|
||||
v6_addr = (FAR struct sockaddr_in6 *)⌖
|
||||
v6_addr->sin6_family = AF_INET6;
|
||||
v6_addr->sin6_port = HTONS(0x4321);
|
||||
target.sin6_family = AF_INET6;
|
||||
target.sin6_port = HTONS(0x4321);
|
||||
memcpy(v6_addr->sin6_addr.s6_addr16, g_grp_addr, sizeof(struct in6_addr));
|
||||
|
||||
memset(&netmask, 0, sizeof(netmask));
|
||||
v6_addr = (FAR struct sockaddr_in6 *)&netmask;
|
||||
v6_addr->sin6_family = AF_INET6;
|
||||
v6_addr->sin6_port = HTONS(0x4321);
|
||||
netmask.sin6_family = AF_INET6;
|
||||
netmask.sin6_port = HTONS(0x4321);
|
||||
memset(v6_addr->sin6_addr.s6_addr16, 0xff, sizeof(struct in6_addr));
|
||||
|
||||
memset(&router, 0, sizeof(router));
|
||||
v6_addr = (FAR struct sockaddr_in6 *)&router;
|
||||
v6_addr->sin6_family = AF_INET6;
|
||||
v6_addr->sin6_port = HTONS(0x4321);
|
||||
router.sin6_family = AF_INET6;
|
||||
router.sin6_port = HTONS(0x4321);
|
||||
|
||||
ret = netlib_get_ipv6addr("eth0", &v6_addr->sin6_addr);
|
||||
if (ret < 0)
|
||||
@ -384,7 +380,7 @@ int main(int argc, FAR char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = addroute(sockfd, &target, &netmask, &router);
|
||||
ret = addroute(sockfd, &target, &netmask, &router, sizeof(router));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: addroute() failed: %d\n", errno);
|
||||
@ -406,7 +402,7 @@ int main(int argc, FAR char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
ret = delroute(sockfd, &target, &netmask);
|
||||
ret = delroute(sockfd, &target, &netmask, sizeof(target));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: delroute() failed: %d\n", errno);
|
||||
|
@ -66,21 +66,19 @@ int netlib_set_dripv4addr(FAR const char *ifname,
|
||||
int ret = ERROR;
|
||||
|
||||
#ifdef CONFIG_NET_ROUTE
|
||||
FAR struct sockaddr_in *v4_addr;
|
||||
struct sockaddr_storage target;
|
||||
struct sockaddr_storage netmask;
|
||||
struct sockaddr_storage router;
|
||||
struct sockaddr_in target;
|
||||
struct sockaddr_in netmask;
|
||||
struct sockaddr_in router;
|
||||
|
||||
memset(&target, 0, sizeof(target));
|
||||
target.ss_family = AF_INET;
|
||||
target.sin_family = AF_INET;
|
||||
|
||||
memset(&netmask, 0, sizeof(netmask));
|
||||
netmask.ss_family = AF_INET;
|
||||
netmask.sin_family = AF_INET;
|
||||
|
||||
memset(&router, 0, sizeof(router));
|
||||
v4_addr = (FAR struct sockaddr_in *)&router;
|
||||
v4_addr->sin_family = AF_INET;
|
||||
v4_addr->sin_addr = *addr;
|
||||
router.sin_family = AF_INET;
|
||||
router.sin_addr = *addr;
|
||||
#endif
|
||||
|
||||
if (ifname && addr)
|
||||
@ -111,11 +109,12 @@ int netlib_set_dripv4addr(FAR const char *ifname,
|
||||
|
||||
/* This call fails if no default route exists, but it's OK */
|
||||
|
||||
delroute(sockfd, &target, &netmask);
|
||||
delroute(sockfd, &target, &netmask, sizeof(target));
|
||||
|
||||
/* Then add the new default route */
|
||||
|
||||
ret = addroute(sockfd, &target, &netmask, &router);
|
||||
ret = addroute(sockfd, &target, &netmask,
|
||||
&router, sizeof(router));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -434,7 +434,8 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
||||
|
||||
/* Then add the route */
|
||||
|
||||
ret = addroute(sockfd, &target.ipx, &netmask.ipx, &router.ipx);
|
||||
ret = addroute(sockfd, &target.ipx, &netmask.ipx,
|
||||
&router.ipx, sizeof(router));
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "addroute", NSH_ERRNO);
|
||||
@ -676,7 +677,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
||||
|
||||
/* Then delete the route */
|
||||
|
||||
ret = delroute(sockfd, &target.ipx, &netmask.ipx);
|
||||
ret = delroute(sockfd, &target.ipx, &netmask.ipx, sizeof(target));
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "delroute", NSH_ERRNO);
|
||||
|
Loading…
Reference in New Issue
Block a user