net/netlink and include/nuttx/net/netlink.h: Make netlink_add_response() a globally access part of the network interface. This is necesssary to support netlink components that reside outside of the net/ sandbox.

This commit is contained in:
Gregory Nutt 2019-11-18 21:12:50 -06:00
parent bb6a3341aa
commit 936d69da1f
4 changed files with 120 additions and 35 deletions

113
include/nuttx/net/netlink.h Normal file
View File

@ -0,0 +1,113 @@
/****************************************************************************
* include/nuttx/net/netlink.h
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_NET_NETLINK_H
#define __INCLUDE_NUTTX_NET_NETLINK_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <queue.h>
#include <netpacket/netlink.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/* This is the form of the obfuscated state structure passed to modules outside of the
* networking layer.
*/
typedef FAR void *NETLINK_HANDLE;
/* Netlink uses a two step, request-get, referenced by a user managed
* sequence number. This means that the requested data must be buffered
* until it is gotten by the client. This structure holds that buffered
* data.
*
* REVISIT: There really should be a time stamp on this so that we can
* someday weed out un-claimed responses.
*/
struct netlink_response_s
{
sq_entry_t flink;
FAR struct nlmsghdr msg;
/* Message-specific data may follow */
};
#define SIZEOF_NETLINK_RESPONSE_S(n) (sizeof(struct netlink_response_s) + (n) - 1)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: netlink_add_response
*
* Description:
* Add response data at the tail of the pending response list.
*
* Note: The network will be momentarily locked to support exclusive
* access to the pending response list.
*
****************************************************************************/
void netlink_add_response(NETLINK_HANDLE handle,
FAR struct netlink_response_s *resp);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_NET_NETLINK_H */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/netlink/netlink.h
*
* Copyright (C) 2018-2019 Gregory Nutt. All rights reserved.
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -47,6 +47,7 @@
#include <semaphore.h>
#include <netpacket/netlink.h>
#include <nuttx/net/netlink.h>
#include "devif/devif.h"
#include "socket/socket.h"
@ -63,25 +64,6 @@
* Public Type Definitions
****************************************************************************/
/* Netlink uses a two step, request-get, referenced by a user managed
* sequence number. This means that the requested data must be buffered
* until it is gotten by the client. This structure holds that buffered
* data.
*
* REVISIT: There really should be a time stamp on this so that we can
* someday weed out un-claimed responses.
*/
struct netlink_response_s
{
sq_entry_t flink;
FAR struct nlmsghdr msg;
/* Message-specific data may follow */
};
#define SIZEOF_NETLINK_RESPONSE_S(n) (sizeof(struct netlink_response_s) + (n) - 1)
/* This "connection" structure describes the underlying state of the socket. */
struct netlink_conn_s
@ -190,20 +172,6 @@ FAR struct netlink_conn_s *netlink_nextconn(FAR struct netlink_conn_s *conn);
FAR struct netlink_conn_s *netlink_active(FAR struct sockaddr_nl *addr);
/****************************************************************************
* Name: netlink_add_response
*
* Description:
* Add response data at the tail of the pending response list.
*
* Note: The network will be momentarily locked to support exclusive
* access to the pending response list.
*
****************************************************************************/
void netlink_add_response(FAR struct socket *psock,
FAR struct netlink_response_s *resp);
/****************************************************************************
* Name: netlink_tryget_response
*

View File

@ -53,6 +53,7 @@
#include <nuttx/signal.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netlink.h>
#include "utils/utils.h"
#include "netlink/netlink.h"
@ -346,11 +347,13 @@ FAR struct netlink_conn_s *netlink_active(FAR struct sockaddr_nl *addr)
*
****************************************************************************/
void netlink_add_response(FAR struct socket *psock,
void netlink_add_response(NETLINK_HANDLE handle,
FAR struct netlink_response_s *resp)
{
FAR struct socket *psock;
FAR struct netlink_conn_s *conn;
psock = (FAR struct socket *)handle;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && resp != NULL);
conn = (FAR struct netlink_conn_s *)psock->s_conn;

View File

@ -52,6 +52,7 @@
#include <nuttx/net/arp.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/neighbor.h>
#include <nuttx/net/netlink.h>
#include "netdev/netdev.h"
#include "arp/arp.h"