Skip to content

Commit

Permalink
netlib/route: add length for add/del route-func to reduce caller stac…
Browse files Browse the repository at this point in the history
…k usage

Signed-off-by: meijian <[email protected]>
  • Loading branch information
Meissi-jian committed Aug 21, 2024
1 parent 6071102 commit bcfd865
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
10 changes: 5 additions & 5 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ extern "C"
* netmask - Network mask defining the external network (required)
* router - Router address that on our network that can forward to the
* external network.
* len - The address struct length.
*
* Returned Value:
* OK on success; -1 on failure with the errno variable set appropriately.
*
****************************************************************************/

int addroute(int sockfd, FAR struct sockaddr_storage *target,
FAR struct sockaddr_storage *netmask,
FAR struct sockaddr_storage *router);
int addroute(int sockfd, FAR void *target, FAR void *netmask,
FAR void *router, socklen_t len);

/****************************************************************************
* Name: net_delroute
Expand All @@ -122,14 +122,14 @@ int addroute(int sockfd, FAR struct sockaddr_storage *target,
* sockfd - Any socket descriptor
* target - Target address on the remote network (required)
* netmask - Network mask defining the external network (required)
* len - The address struct length.
*
* Returned Value:
* OK on success; -1 on failure with the errno variable set appropriately.
*
****************************************************************************/

int delroute(int sockfd, FAR struct sockaddr_storage *target,
FAR struct sockaddr_storage *netmask);
int delroute(int sockfd, FAR void *target, FAR void *netmask, socklen_t len);

#undef EXTERN
#ifdef __cplusplus
Expand Down
17 changes: 11 additions & 6 deletions libs/libc/net/lib_addroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,29 @@
* netmask - Network mask defining the external network (required)
* router - Router address that on our network that can forward to the
* external network.
* len - The address struct length.
*
* Returned Value:
* OK on success; -1 on failure with the errno variable set appropriately.
*
****************************************************************************/

int addroute(int sockfd, FAR struct sockaddr_storage *target,
FAR struct sockaddr_storage *netmask,
FAR struct sockaddr_storage *router)
int addroute(int sockfd, FAR void *target, FAR void *netmask,
FAR void *router, socklen_t len)
{
struct rtentry entry;

if (len < sizeof(struct in_addr) || len > sizeof(struct sockaddr_storage))
{
return -EINVAL;
}

/* Set up the rtentry structure */

memset(&entry, 0, sizeof(struct rtentry));
memcpy(&entry.rt_dst, target, sizeof(struct sockaddr_storage));
memcpy(&entry.rt_genmask, netmask, sizeof(struct sockaddr_storage));
memcpy(&entry.rt_gateway, router, sizeof(struct sockaddr_storage));
memcpy(&entry.rt_dst, target, len);
memcpy(&entry.rt_genmask, netmask, len);
memcpy(&entry.rt_gateway, router, len);

/* Then perform the ioctl */

Expand Down
13 changes: 9 additions & 4 deletions libs/libc/net/lib_delroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,27 @@
* sockfd - Any socket descriptor
* target - Target address on the remote network (required)
* netmask - Network mask defining the external network (required)
* len - The address struct length.
*
* Returned Value:
* OK on success; -1 on failure with the errno variable set appropriately.
*
****************************************************************************/

int delroute(int sockfd, FAR struct sockaddr_storage *target,
FAR struct sockaddr_storage *netmask)
int delroute(int sockfd, FAR void *target, FAR void *netmask, socklen_t len)
{
struct rtentry entry;

if (len < sizeof(struct in_addr) || len > sizeof(struct sockaddr_storage))
{
return -EINVAL;
}

/* Set up the rtentry structure */

memset(&entry, 0, sizeof(struct rtentry));
memcpy(&entry.rt_dst, target, sizeof(struct sockaddr_storage));
memcpy(&entry.rt_genmask, netmask, sizeof(struct sockaddr_storage));
memcpy(&entry.rt_dst, target, len);
memcpy(&entry.rt_genmask, netmask, len);

/* Then perform the ioctl */

Expand Down

0 comments on commit bcfd865

Please sign in to comment.