mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
net/netlink: Move netlink_add_terminator as public
Prepare for other netlink dumps. Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
@@ -398,6 +398,29 @@ void netlink_notifier_teardown(FAR struct netlink_conn_s *conn);
|
|||||||
|
|
||||||
void netlink_notifier_signal(FAR struct netlink_conn_s *conn);
|
void netlink_notifier_signal(FAR struct netlink_conn_s *conn);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlink_add_terminator
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Add one NLMSG_DONE response to handle.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* handle - The handle previously provided to the sendto() implementation
|
||||||
|
* for the protocol. This is an opaque reference to the Netlink
|
||||||
|
* socket state structure.
|
||||||
|
* req - The request message header.
|
||||||
|
* group - The broadcast group index, 0 for normal response.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned if the terminator was successfully added to the
|
||||||
|
* response list.
|
||||||
|
* A negated error value is returned if an unexpected error occurred.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int netlink_add_terminator(NETLINK_HANDLE handle,
|
||||||
|
FAR const struct nlmsghdr *req, int group);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlink_tryget_response
|
* Name: netlink_tryget_response
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -92,6 +92,43 @@ static void netlink_response_available(FAR void *arg)
|
|||||||
nxsem_post(arg);
|
nxsem_post(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlink_get_terminator
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Generate one NLMSG_DONE response.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static FAR struct netlink_response_s *
|
||||||
|
netlink_get_terminator(FAR const struct nlmsghdr *req)
|
||||||
|
{
|
||||||
|
FAR struct netlink_response_s *resp;
|
||||||
|
FAR struct nlmsghdr *hdr;
|
||||||
|
|
||||||
|
/* Allocate the list terminator */
|
||||||
|
|
||||||
|
resp = kmm_zalloc(sizeof(struct netlink_response_s));
|
||||||
|
if (resp == NULL)
|
||||||
|
{
|
||||||
|
nerr("ERROR: Failed to allocate response terminator.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize and send the list terminator */
|
||||||
|
|
||||||
|
hdr = &resp->msg;
|
||||||
|
hdr->nlmsg_len = sizeof(struct nlmsghdr);
|
||||||
|
hdr->nlmsg_type = NLMSG_DONE;
|
||||||
|
hdr->nlmsg_flags = req ? req->nlmsg_flags : 0;
|
||||||
|
hdr->nlmsg_seq = req ? req->nlmsg_seq : 0;
|
||||||
|
hdr->nlmsg_pid = req ? req->nlmsg_pid : 0;
|
||||||
|
|
||||||
|
/* Finally, return the response */
|
||||||
|
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -286,6 +323,49 @@ void netlink_add_response(NETLINK_HANDLE handle,
|
|||||||
net_unlock();
|
net_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlink_add_terminator
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Add one NLMSG_DONE response to handle.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* handle - The handle previously provided to the sendto() implementation
|
||||||
|
* for the protocol. This is an opaque reference to the Netlink
|
||||||
|
* socket state structure.
|
||||||
|
* req - The request message header.
|
||||||
|
* group - The broadcast group index, 0 for normal response.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned if the terminator was successfully added to the
|
||||||
|
* response list.
|
||||||
|
* A negated error value is returned if an unexpected error occurred.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int netlink_add_terminator(NETLINK_HANDLE handle,
|
||||||
|
FAR const struct nlmsghdr *req, int group)
|
||||||
|
{
|
||||||
|
FAR struct netlink_response_s *resp;
|
||||||
|
|
||||||
|
resp = netlink_get_terminator(req);
|
||||||
|
if (resp == NULL)
|
||||||
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group > 0)
|
||||||
|
{
|
||||||
|
netlink_add_broadcast(group, resp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
netlink_add_response(handle, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlink_add_broadcast
|
* Name: netlink_add_broadcast
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -440,66 +440,6 @@ netlink_get_ifaddr(FAR struct net_driver_s *dev, int domain, int type,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: netlink_get_terminator
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Generate one NLMSG_DONE response.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static FAR struct netlink_response_s *
|
|
||||||
netlink_get_terminator(FAR const struct nlroute_sendto_request_s *req)
|
|
||||||
{
|
|
||||||
FAR struct netlink_response_s *resp;
|
|
||||||
FAR struct nlmsghdr *hdr;
|
|
||||||
|
|
||||||
/* Allocate the list terminator */
|
|
||||||
|
|
||||||
resp = kmm_zalloc(sizeof(struct netlink_response_s));
|
|
||||||
if (resp == NULL)
|
|
||||||
{
|
|
||||||
nerr("ERROR: Failed to allocate response terminator.\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize and send the list terminator */
|
|
||||||
|
|
||||||
hdr = &resp->msg;
|
|
||||||
hdr->nlmsg_len = sizeof(struct nlmsghdr);
|
|
||||||
hdr->nlmsg_type = NLMSG_DONE;
|
|
||||||
hdr->nlmsg_flags = req ? req->hdr.nlmsg_flags : 0;
|
|
||||||
hdr->nlmsg_seq = req ? req->hdr.nlmsg_seq : 0;
|
|
||||||
hdr->nlmsg_pid = req ? req->hdr.nlmsg_pid : 0;
|
|
||||||
|
|
||||||
/* Finally, return the response */
|
|
||||||
|
|
||||||
return resp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: netlink_add_terminator
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Add one NLMSG_DONE response to handle.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int netlink_add_terminator(NETLINK_HANDLE handle,
|
|
||||||
FAR const struct nlroute_sendto_request_s *req)
|
|
||||||
{
|
|
||||||
FAR struct netlink_response_s * resp;
|
|
||||||
|
|
||||||
resp = netlink_get_terminator(req);
|
|
||||||
if (resp == NULL)
|
|
||||||
{
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
netlink_add_response(handle, resp);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlink_get_devlist
|
* Name: netlink_get_devlist
|
||||||
*
|
*
|
||||||
@@ -544,7 +484,7 @@ static int netlink_get_devlist(NETLINK_HANDLE handle,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return netlink_add_terminator(handle, req);
|
return netlink_add_terminator(handle, &req->hdr, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -803,7 +743,7 @@ static int netlink_get_ipv4route(NETLINK_HANDLE handle,
|
|||||||
|
|
||||||
/* Terminate the routing table */
|
/* Terminate the routing table */
|
||||||
|
|
||||||
return netlink_add_terminator(handle, req);
|
return netlink_add_terminator(handle, &req->hdr, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -869,7 +809,7 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlink_get_ip6vroute
|
* Name: netlink_get_ipv6route
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Dump a list of all network devices of the specified type.
|
* Dump a list of all network devices of the specified type.
|
||||||
@@ -877,7 +817,7 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
|
#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
|
||||||
static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
|
static int netlink_get_ipv6route(NETLINK_HANDLE handle,
|
||||||
FAR const struct nlroute_sendto_request_s *req)
|
FAR const struct nlroute_sendto_request_s *req)
|
||||||
{
|
{
|
||||||
struct nlroute_info_s info;
|
struct nlroute_info_s info;
|
||||||
@@ -896,7 +836,7 @@ static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
|
|||||||
|
|
||||||
/* Terminate the routing table */
|
/* Terminate the routing table */
|
||||||
|
|
||||||
return netlink_add_terminator(handle, req);
|
return netlink_add_terminator(handle, &req->hdr, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1188,7 +1128,7 @@ static int netlink_get_addr(NETLINK_HANDLE handle,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return netlink_add_terminator(handle, req);
|
return netlink_add_terminator(handle, &req->hdr, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1278,7 +1218,7 @@ ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
|
|||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (req->gen.rtgen_family == AF_INET6)
|
if (req->gen.rtgen_family == AF_INET6)
|
||||||
{
|
{
|
||||||
ret = netlink_get_ip6vroute(handle, req);
|
ret = netlink_get_ipv6route(handle, req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@@ -1394,12 +1334,7 @@ void netlink_device_notify(FAR struct net_driver_s *dev)
|
|||||||
if (resp != NULL)
|
if (resp != NULL)
|
||||||
{
|
{
|
||||||
netlink_add_broadcast(RTNLGRP_LINK, resp);
|
netlink_add_broadcast(RTNLGRP_LINK, resp);
|
||||||
|
netlink_add_terminator(NULL, NULL, RTNLGRP_LINK);
|
||||||
resp = netlink_get_terminator(NULL);
|
|
||||||
if (resp != NULL)
|
|
||||||
{
|
|
||||||
netlink_add_broadcast(RTNLGRP_LINK, resp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1448,12 +1383,7 @@ void netlink_device_notify_ipaddr(FAR struct net_driver_s *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
netlink_add_broadcast(group, resp);
|
netlink_add_broadcast(group, resp);
|
||||||
|
netlink_add_terminator(NULL, NULL, group);
|
||||||
resp = netlink_get_terminator(NULL);
|
|
||||||
if (resp != NULL)
|
|
||||||
{
|
|
||||||
netlink_add_broadcast(group, resp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user