2018-08-03 21:22:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/netlink/netlink.h
|
|
|
|
*
|
2019-11-19 04:12:50 +01:00
|
|
|
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
2018-08-03 21:22:36 +02:00
|
|
|
* 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 __NET_NETLINK_NETLINK_H
|
|
|
|
#define __NET_NETLINK_NETLINK_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <queue.h>
|
2019-11-28 04:30:01 +01:00
|
|
|
#include <poll.h>
|
2018-08-03 21:22:36 +02:00
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
#include <netpacket/netlink.h>
|
2019-11-19 04:12:50 +01:00
|
|
|
#include <nuttx/net/netlink.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2018-08-03 21:22:36 +02:00
|
|
|
#include "devif/devif.h"
|
|
|
|
#include "socket/socket.h"
|
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NETLINK_ROUTE
|
|
|
|
#define netlink_device_notify(dev)
|
|
|
|
#endif
|
|
|
|
|
2018-08-03 21:22:36 +02:00
|
|
|
#ifdef CONFIG_NET_NETLINK
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
/* This connection structure describes the underlying state of the socket. */
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2018-08-03 21:22:36 +02:00
|
|
|
struct netlink_conn_s
|
|
|
|
{
|
2019-09-01 16:47:01 +02:00
|
|
|
/* Common prologue of all connection structures. */
|
|
|
|
|
2018-08-03 21:22:36 +02:00
|
|
|
dq_entry_t node; /* Supports a doubly linked list */
|
|
|
|
|
2019-11-04 21:06:07 +01:00
|
|
|
/* NetLink-specific content follows */
|
2018-08-03 21:22:36 +02:00
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
uint32_t pid; /* Port ID (if bound) */
|
|
|
|
uint32_t groups; /* Multicast groups mask (if bound) */
|
2020-04-07 20:31:57 +02:00
|
|
|
uint32_t dst_pid; /* Destination port ID */
|
|
|
|
uint32_t dst_groups; /* Destination multicast groups mask */
|
2019-09-01 16:47:01 +02:00
|
|
|
uint8_t crefs; /* Reference counts on this instance */
|
2019-11-03 20:59:42 +01:00
|
|
|
uint8_t protocol; /* See NETLINK_* definitions */
|
|
|
|
|
2019-11-28 04:30:01 +01:00
|
|
|
/* poll() support */
|
|
|
|
|
2019-11-28 21:20:40 +01:00
|
|
|
int key; /* used to cancel notifications */
|
2019-11-28 04:30:01 +01:00
|
|
|
FAR sem_t *pollsem; /* Used to wakeup poll() */
|
|
|
|
FAR pollevent_t *pollevent; /* poll() wakeup event */
|
2019-11-18 16:48:14 +01:00
|
|
|
|
|
|
|
/* Queued response data */
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2020-04-07 19:44:23 +02:00
|
|
|
sq_queue_t resplist; /* Singly linked list of responses */
|
2018-08-03 21:22:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
# define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
# define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXTERN const struct sock_intf_s g_netlink_sockif;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_initialize()
|
|
|
|
*
|
|
|
|
* Description:
|
2018-10-31 21:10:19 +01:00
|
|
|
* Initialize the NetLink connection structures. Called once and only
|
2018-08-03 21:22:36 +02:00
|
|
|
* from the networking layer.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void netlink_initialize(void);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_alloc()
|
|
|
|
*
|
|
|
|
* Description:
|
2019-11-04 21:06:07 +01:00
|
|
|
* Allocate a new, uninitialized NetLink connection structure. This is
|
2018-08-03 21:22:36 +02:00
|
|
|
* normally something done by the implementation of the socket() API
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct netlink_conn_s *netlink_alloc(void);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_free()
|
|
|
|
*
|
|
|
|
* Description:
|
2020-04-10 15:03:34 +02:00
|
|
|
* Free a NetLink connection structure that is no longer in use. This
|
|
|
|
* should be done by the implementation of close().
|
2018-08-03 21:22:36 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void netlink_free(FAR struct netlink_conn_s *conn);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_nextconn()
|
|
|
|
*
|
|
|
|
* Description:
|
2019-11-04 21:06:07 +01:00
|
|
|
* Traverse the list of allocated NetLink connections
|
2018-08-03 21:22:36 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2019-11-04 21:06:07 +01:00
|
|
|
* This function is called from NetLink device logic.
|
2018-08-03 21:22:36 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct netlink_conn_s *netlink_nextconn(FAR struct netlink_conn_s *conn);
|
|
|
|
|
2019-11-28 21:20:40 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_notifier_setup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set up to perform a callback to the worker function the Netlink
|
|
|
|
* response data is received. The worker function will execute on the low
|
|
|
|
* priority worker thread.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* worker - The worker function to execute on the low priority work
|
|
|
|
* queue when Netlink response data is available.
|
|
|
|
* conn - The Netlink connection where the response is expected.
|
|
|
|
* arg - A user-defined argument that will be available to the worker
|
|
|
|
* function when it runs.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned if the notification was successfully set up.
|
|
|
|
* A negated error value is returned if an unexpected error occurred
|
|
|
|
* and no notification will occur.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int netlink_notifier_setup(worker_t worker, FAR struct netlink_conn_s *conn,
|
|
|
|
FAR void *arg);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_notifier_teardown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Eliminate a Netlink response notification previously setup by
|
|
|
|
* netlink_notifier_setup(). This function should only be called if the
|
|
|
|
* notification should be aborted prior to the notification. The
|
|
|
|
* notification will automatically be torn down after the notification.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - Teardown the notification for this Netlink connection.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int netlink_notifier_teardown(FAR struct netlink_conn_s *conn);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_notifier_signal
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* New Netlink response data is available. Execute worker thread
|
|
|
|
* functions for all threads that wait for response data.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - The Netlink connection where the response was just buffered.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void netlink_notifier_signal(FAR struct netlink_conn_s *conn);
|
|
|
|
|
2019-11-18 16:48:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_tryget_response
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the next response from the head of the pending response list.
|
|
|
|
* Responses are returned one-at-a-time in FIFO order.
|
|
|
|
*
|
|
|
|
* Note: The network will be momentarily locked to support exclusive
|
|
|
|
* access to the pending response list.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The next response from the head of the pending response list is
|
|
|
|
* returned. NULL will be returned if the pending response list is
|
|
|
|
* empty
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct netlink_response_s *
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_tryget_response(FAR struct netlink_conn_s *conn);
|
2019-11-18 16:48:14 +01:00
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_get_response
|
|
|
|
*
|
|
|
|
* Description:
|
2019-11-04 16:02:14 +01:00
|
|
|
* Return the next response from the head of the pending response list.
|
|
|
|
* Responses are returned one-at-a-time in FIFO order.
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
2019-11-18 16:48:14 +01:00
|
|
|
* Note: The network will be momentarily locked to support exclusive
|
|
|
|
* access to the pending response list.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The next response from the head of the pending response list is
|
2019-11-28 21:20:40 +01:00
|
|
|
* returned. This function will block until a response is received if
|
|
|
|
* the pending response list is empty. NULL will be returned only in the
|
|
|
|
* event of a failure.
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-18 16:48:14 +01:00
|
|
|
FAR struct netlink_response_s *
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_get_response(FAR struct netlink_conn_s *conn);
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-27 01:52:22 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_check_response
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true is a response is pending now.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True: A response is available; False; No response is available.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
bool netlink_check_response(FAR struct netlink_conn_s *conn);
|
2019-11-27 01:52:22 +01:00
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_route_sendto()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform the sendto() operation for the NETLINK_ROUTE protocol.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
2020-04-13 14:49:52 +02:00
|
|
|
ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
|
2019-11-03 20:59:42 +01:00
|
|
|
FAR const struct nlmsghdr *nlmsg,
|
|
|
|
size_t len, int flags,
|
|
|
|
FAR const struct sockaddr_nl *to,
|
|
|
|
socklen_t tolen);
|
2020-04-13 10:10:30 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_device_notify()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform the route broadcast for the NETLINK_ROUTE protocol.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void netlink_device_notify(FAR struct net_driver_s *dev);
|
2019-11-03 20:59:42 +01:00
|
|
|
#endif
|
|
|
|
|
2018-08-03 21:22:36 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_NETLINK */
|
|
|
|
#endif /* __NET_NETLINK_NETLINK_H */
|