2011-05-09 22:21:10 +00:00
|
|
|
/****************************************************************************
|
2021-08-12 17:01:12 +09:00
|
|
|
* apps/include/netutils/netlib.h
|
2011-05-09 22:21:10 +00:00
|
|
|
*
|
2024-12-19 04:54:28 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
* SPDX-FileCopyrightText: 2007, 2009, 2011, 2015, 2017 Gregory Nutt.
|
|
|
|
|
* SPDX-FileCopyrightText: 2002 Adam Dunkels.
|
|
|
|
|
* SPDX-FileContributor: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
|
* SPDX-FileContributor: Adam Dunkels <adam@sics.se>
|
2011-05-09 22:21:10 +00:00
|
|
|
*
|
|
|
|
|
* 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. The name of the author may not be used to endorse or promote
|
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
|
* written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-07-02 16:04:25 -06:00
|
|
|
#ifndef __APPS_INCLUDE_NETUTILS_NETLIB_H
|
|
|
|
|
#define __APPS_INCLUDE_NETUTILS_NETLIB_H
|
2011-05-09 22:21:10 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
2018-08-03 10:50:24 -06:00
|
|
|
#include <sys/socket.h>
|
2011-05-09 22:21:10 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
2017-09-20 10:35:56 -06:00
|
|
|
#include <stdio.h>
|
2011-05-09 22:21:10 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
2019-11-09 17:38:02 -06:00
|
|
|
#include <net/if.h>
|
2011-05-09 22:21:10 +00:00
|
|
|
#include <netinet/in.h>
|
2024-10-09 17:34:00 +08:00
|
|
|
#include <nuttx/mm/iob.h>
|
2024-09-06 15:22:35 +08:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-06-24 08:53:28 -06:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2011-05-09 22:21:10 +00:00
|
|
|
|
2025-09-17 11:18:17 +08:00
|
|
|
#ifdef CONFIG_NET_IPTABLES
|
|
|
|
|
# include <nuttx/net/netfilter/ip_tables.h>
|
|
|
|
|
# include <nuttx/net/netfilter/ip6_tables.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-05-09 22:21:10 +00:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Pre-processor Definitions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-09-20 10:35:56 -06:00
|
|
|
#undef HAVE_ROUTE_PROCFS
|
|
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_NET_ROUTE) && \
|
|
|
|
|
defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ROUTE)
|
|
|
|
|
# define HAVE_ROUTE_PROCFS
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ROUTE_PROCFS
|
|
|
|
|
# ifndef CONFIG_NETLIB_PROCFS_MOUNTPT
|
|
|
|
|
# define CONFIG_NETLIB_PROCFS_MOUNTPT "/proc"
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
# define IPv4_ROUTE_PATH CONFIG_NETLIB_PROCFS_MOUNTPT "/net/route/ipv4"
|
|
|
|
|
# define IPv6_ROUTE_PATH CONFIG_NETLIB_PROCFS_MOUNTPT "/net/route/ipv6"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Types
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ROUTE_PROCFS
|
2019-11-10 12:36:34 -06:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2017-09-20 10:35:56 -06:00
|
|
|
/* Describes one entry from the IPv4 routing table. All addresses are in
|
|
|
|
|
* host byte order!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct netlib_ipv4_route_s
|
|
|
|
|
{
|
|
|
|
|
in_addr_t prefix; /* Routing prefix */
|
|
|
|
|
in_addr_t netmask; /* Routing netmask */
|
|
|
|
|
in_addr_t router; /* Router IPv4 address */
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-11-10 12:36:34 -06:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-09-20 10:35:56 -06:00
|
|
|
/* Describes one entry from the IPv6 routing table. All addresses are in
|
|
|
|
|
* host byte order!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct netlib_ipv6_route_s
|
|
|
|
|
{
|
|
|
|
|
uint16_t prefix[8]; /* Routing prefix */
|
|
|
|
|
uint16_t netmask[8]; /* Routing netmask */
|
|
|
|
|
uint16_t router[8]; /* Router IPv6 address */
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* HAVE_ROUTE_PROCFS */
|
|
|
|
|
|
2019-11-09 17:38:02 -06:00
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
|
|
|
|
/* Describes one device returned by netlib_get_devices() */
|
|
|
|
|
|
|
|
|
|
struct netlib_device_s
|
|
|
|
|
{
|
|
|
|
|
#ifdef CONFIG_NETDEV_IFINDEX
|
|
|
|
|
uint8_t ifindex; /* Interface index */
|
|
|
|
|
#endif
|
|
|
|
|
char ifname[IFNAMSIZ]; /* Interface name */
|
|
|
|
|
};
|
2019-11-10 12:36:34 -06:00
|
|
|
#endif /* CONFIG_NETLINK_ROUTE*/
|
2019-11-09 17:38:02 -06:00
|
|
|
|
2024-03-25 16:36:30 +08:00
|
|
|
#ifdef CONFIG_NETLINK_NETFILTER
|
|
|
|
|
/* Describes one connection returned by netlib_get_conntrack() */
|
|
|
|
|
|
|
|
|
|
union netlib_conntrack_addr_u
|
|
|
|
|
{
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
|
struct in_addr ipv4;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
|
struct in6_addr ipv6;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct netlib_conntrack_tuple_s
|
|
|
|
|
{
|
|
|
|
|
union netlib_conntrack_addr_u src;
|
|
|
|
|
union netlib_conntrack_addr_u dst;
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
uint16_t sport;
|
|
|
|
|
uint16_t dport;
|
|
|
|
|
} tcp; /* and udp */
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
uint16_t id;
|
|
|
|
|
uint8_t type;
|
|
|
|
|
uint8_t code;
|
|
|
|
|
} icmp; /* and icmp6 */
|
|
|
|
|
} l4;
|
|
|
|
|
|
|
|
|
|
uint8_t l4proto;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct netlib_conntrack_s
|
|
|
|
|
{
|
|
|
|
|
struct netlib_conntrack_tuple_s orig;
|
|
|
|
|
struct netlib_conntrack_tuple_s reply;
|
|
|
|
|
|
|
|
|
|
sa_family_t family; /* AF_INET or AF_INET6 */
|
|
|
|
|
uint8_t type; /* IPCTNL_MSG_CT_* */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* There might be many conntrack entries, so we don't use array of data, but
|
|
|
|
|
* use callback instead.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef CODE int (*netlib_conntrack_cb_t)(FAR struct netlib_conntrack_s *ct);
|
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_NETLINK_NETFILTER */
|
|
|
|
|
|
2019-04-26 13:08:38 -06:00
|
|
|
#ifdef CONFIG_NETUTILS_NETLIB_GENERICURLPARSER
|
|
|
|
|
struct url_s
|
|
|
|
|
{
|
|
|
|
|
FAR char *scheme;
|
|
|
|
|
int schemelen;
|
2020-05-27 14:10:04 +09:00
|
|
|
#if 0 /* not yet */
|
2019-04-26 13:08:38 -06:00
|
|
|
FAR char *user;
|
|
|
|
|
int userlen;
|
|
|
|
|
FAR char *password;
|
|
|
|
|
int passwordlen;
|
2020-05-27 14:10:04 +09:00
|
|
|
#endif
|
2019-04-26 13:08:38 -06:00
|
|
|
FAR char *host;
|
|
|
|
|
int hostlen;
|
2021-08-12 16:51:52 +09:00
|
|
|
uint16_t port;
|
2019-04-26 13:08:38 -06:00
|
|
|
FAR char *path;
|
|
|
|
|
int pathlen;
|
2020-05-27 14:10:04 +09:00
|
|
|
#if 0 /* not yet */
|
2019-04-26 13:08:38 -06:00
|
|
|
FAR char *parameters;
|
|
|
|
|
int parameterslen;
|
|
|
|
|
FAR char *bookmark;
|
|
|
|
|
int bookmarklen;
|
2020-05-27 14:10:04 +09:00
|
|
|
#endif
|
2019-04-26 13:08:38 -06:00
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-04-11 18:41:05 +08:00
|
|
|
#ifdef CONFIG_NETUTILS_DHCPC
|
|
|
|
|
typedef CODE void (*netlib_dhcp_ntp_callback_t)
|
|
|
|
|
(FAR const char *ntp_server_list, FAR void *arg);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-05-09 22:21:10 +00:00
|
|
|
/****************************************************************************
|
2015-07-12 11:53:23 -06:00
|
|
|
* Public Data
|
2011-05-09 22:21:10 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-07-17 03:58:11 +00:00
|
|
|
#undef EXTERN
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
#define EXTERN extern "C"
|
2014-01-21 10:21:45 -06:00
|
|
|
extern "C"
|
|
|
|
|
{
|
2012-07-17 03:58:11 +00:00
|
|
|
#else
|
|
|
|
|
#define EXTERN extern
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-12 11:53:23 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Function Prototypes
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2019-11-09 17:38:02 -06:00
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
|
|
|
|
/* Return a list of all devices */
|
|
|
|
|
|
|
|
|
|
ssize_t netlib_get_devices(FAR struct netlib_device_s *devlist,
|
|
|
|
|
unsigned int nentries, sa_family_t family);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-05-27 14:19:26 +09:00
|
|
|
/* Convert a textual representation of an IP address to a numerical
|
|
|
|
|
* representation.
|
2011-05-09 22:21:10 +00:00
|
|
|
*
|
|
|
|
|
* This function takes a textual representation of an IP address in
|
|
|
|
|
* the form a.b.c.d and converts it into a 4-byte array that can be
|
|
|
|
|
* used by other uIP functions.
|
|
|
|
|
*
|
|
|
|
|
* addrstr A pointer to a string containing the IP address in
|
|
|
|
|
* textual form.
|
|
|
|
|
*
|
|
|
|
|
* addr A pointer to a 4-byte array that will be filled in with
|
|
|
|
|
* the numerical representation of the address.
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 If the IP address could not be parsed.
|
|
|
|
|
* Return: Non-zero If the IP address was parsed.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-08 16:09:24 -06:00
|
|
|
bool netlib_ipv4addrconv(FAR const char *addrstr, FAR uint8_t *addr);
|
|
|
|
|
bool netlib_ethaddrconv(FAR const char *hwstr, FAR uint8_t *hw);
|
2011-05-09 22:21:10 +00:00
|
|
|
|
2026-04-11 18:41:05 +08:00
|
|
|
#ifdef CONFIG_NETUTILS_DHCPC
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: netlib_set_ntp_servers_from_dhcp
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Update the currently active DHCP option 42 NTP server list. The list
|
|
|
|
|
* contains semicolon-separated hostnames or addresses. Passing NULL or
|
|
|
|
|
* an empty string clears the DHCP-provided list.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int netlib_set_ntp_servers_from_dhcp(FAR const char *ntp_server_list);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: netlib_register_dhcp_ntp_callback
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Register a callback to receive DHCP option 42 NTP server list updates.
|
|
|
|
|
* The current list, if any, is replayed immediately after registration.
|
|
|
|
|
* Only one callback may be registered at a time.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int netlib_register_dhcp_ntp_callback(netlib_dhcp_ntp_callback_t callback,
|
|
|
|
|
FAR void *arg);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: netlib_unregister_dhcp_ntp_callback
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Unregister a previously registered DHCP option 42 NTP update callback.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int netlib_unregister_dhcp_ntp_callback(netlib_dhcp_ntp_callback_t callback,
|
|
|
|
|
FAR void *arg);
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-12 11:53:23 -06:00
|
|
|
#ifdef CONFIG_NET_ETHERNET
|
2011-05-09 22:21:10 +00:00
|
|
|
/* Get and set IP/MAC addresses (Ethernet L2 only) */
|
|
|
|
|
|
2016-02-08 16:09:24 -06:00
|
|
|
int netlib_setmacaddr(FAR const char *ifname, FAR const uint8_t *macaddr);
|
|
|
|
|
int netlib_getmacaddr(FAR const char *ifname, FAR uint8_t *macaddr);
|
2011-05-09 22:21:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
2017-08-02 12:40:50 -06:00
|
|
|
#ifdef CONFIG_WIRELESS_IEEE802154
|
|
|
|
|
/* IEEE 802.15.4 MAC IOCTL commands. */
|
2017-04-06 16:00:41 -06:00
|
|
|
|
2017-06-17 10:04:18 -06:00
|
|
|
int netlib_seteaddr(FAR const char *ifname, FAR const uint8_t *eaddr);
|
2017-06-19 05:56:52 -04:00
|
|
|
int netlib_getpanid(FAR const char *ifname, FAR uint8_t *panid);
|
2017-08-18 12:07:41 -06:00
|
|
|
bool netlib_saddrconv(FAR const char *hwstr, FAR uint8_t *hw);
|
2017-06-17 10:04:18 -06:00
|
|
|
bool netlib_eaddrconv(FAR const char *hwstr, FAR uint8_t *hw);
|
2017-04-06 16:00:41 -06:00
|
|
|
#endif
|
|
|
|
|
|
2017-08-02 12:40:50 -06:00
|
|
|
#ifdef CONFIG_WIRELESS_PKTRADIO
|
|
|
|
|
/* IEEE 802.15.4 MAC IOCTL commands. */
|
|
|
|
|
|
|
|
|
|
struct pktradio_properties_s; /* Forward reference */
|
|
|
|
|
struct pktradio_addr_s; /* Forward reference */
|
|
|
|
|
|
|
|
|
|
int netlib_getproperties(FAR const char *ifname,
|
|
|
|
|
FAR struct pktradio_properties_s *properties);
|
|
|
|
|
int netlib_setnodeaddr(FAR const char *ifname,
|
|
|
|
|
FAR const struct pktradio_addr_s *nodeaddr);
|
|
|
|
|
int netlib_getnodnodeaddr(FAR const char *ifname,
|
|
|
|
|
FAR struct pktradio_addr_s *nodeaddr);
|
2017-08-02 14:30:34 -06:00
|
|
|
bool netlib_nodeaddrconv(FAR const char *addrstr,
|
|
|
|
|
FAR struct pktradio_addr_s *nodeaddr);
|
2017-08-02 12:40:50 -06:00
|
|
|
#endif
|
|
|
|
|
|
2011-05-09 22:21:10 +00:00
|
|
|
/* IP address support */
|
|
|
|
|
|
2015-01-18 14:17:00 -06:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
|
int netlib_get_ipv4addr(FAR const char *ifname, FAR struct in_addr *addr);
|
2020-05-27 14:19:26 +09:00
|
|
|
int netlib_set_ipv4addr(FAR const char *ifname,
|
|
|
|
|
FAR const struct in_addr *addr);
|
|
|
|
|
int netlib_set_dripv4addr(FAR const char *ifname,
|
|
|
|
|
FAR const struct in_addr *addr);
|
2016-01-14 07:24:36 -06:00
|
|
|
int netlib_get_dripv4addr(FAR const char *ifname, FAR struct in_addr *addr);
|
2020-05-27 14:19:26 +09:00
|
|
|
int netlib_set_ipv4netmask(FAR const char *ifname,
|
|
|
|
|
FAR const struct in_addr *addr);
|
2016-01-14 07:24:36 -06:00
|
|
|
int netlib_get_ipv4netmask(FAR const char *ifname, FAR struct in_addr *addr);
|
2017-09-19 15:21:13 -06:00
|
|
|
int netlib_ipv4adaptor(in_addr_t destipaddr, FAR in_addr_t *srcipaddr);
|
2015-01-18 14:17:00 -06:00
|
|
|
#endif
|
|
|
|
|
|
2023-10-19 15:35:32 +08:00
|
|
|
/* We support multiple IPv6 addresses on a single interface.
|
|
|
|
|
* Recommend to use netlib_add/del_ipv6addr to manage them, by which you
|
|
|
|
|
* don't need to care about the slot it stored.
|
|
|
|
|
*
|
|
|
|
|
* Previous interfaces can still work, the ifname can be <eth>:<num>,
|
|
|
|
|
* e.g. eth0:0 stands for managing the secondary address on eth0
|
|
|
|
|
*/
|
|
|
|
|
|
2011-05-09 22:21:10 +00:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2023-10-19 15:35:32 +08:00
|
|
|
# ifdef CONFIG_NETDEV_MULTIPLE_IPv6
|
|
|
|
|
int netlib_add_ipv6addr(FAR const char *ifname,
|
|
|
|
|
FAR const struct in6_addr *addr, uint8_t preflen);
|
|
|
|
|
int netlib_del_ipv6addr(FAR const char *ifname,
|
|
|
|
|
FAR const struct in6_addr *addr, uint8_t preflen);
|
|
|
|
|
# endif
|
2015-01-18 14:17:00 -06:00
|
|
|
int netlib_get_ipv6addr(FAR const char *ifname, FAR struct in6_addr *addr);
|
2020-05-27 14:19:26 +09:00
|
|
|
int netlib_set_ipv6addr(FAR const char *ifname,
|
|
|
|
|
FAR const struct in6_addr *addr);
|
|
|
|
|
int netlib_set_dripv6addr(FAR const char *ifname,
|
|
|
|
|
FAR const struct in6_addr *addr);
|
|
|
|
|
int netlib_set_ipv6netmask(FAR const char *ifname,
|
|
|
|
|
FAR const struct in6_addr *addr);
|
2017-09-20 06:52:05 -06:00
|
|
|
int netlib_ipv6adaptor(FAR const struct in6_addr *destipaddr,
|
|
|
|
|
FAR struct in6_addr *srcipaddr);
|
2015-02-06 10:23:15 -06:00
|
|
|
|
|
|
|
|
uint8_t netlib_ipv6netmask2prefix(FAR const uint16_t *mask);
|
2020-05-27 14:19:26 +09:00
|
|
|
void netlib_prefix2ipv6netmask(uint8_t preflen,
|
|
|
|
|
FAR struct in6_addr *netmask);
|
2019-11-08 11:30:32 -06:00
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
|
|
|
|
struct neighbor_entry_s;
|
|
|
|
|
ssize_t netlib_get_nbtable(FAR struct neighbor_entry_s *nbtab,
|
|
|
|
|
unsigned int nentries);
|
|
|
|
|
#endif
|
2019-11-11 13:40:57 -06:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2011-05-09 22:21:10 +00:00
|
|
|
|
2017-03-13 10:16:20 -06:00
|
|
|
#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
|
2017-03-13 14:16:26 -06:00
|
|
|
int netlib_getessid(FAR const char *ifname, FAR char *essid, size_t idlen);
|
2017-03-13 10:16:20 -06:00
|
|
|
int netlib_setessid(FAR const char *ifname, FAR const char *essid);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-01-07 18:10:13 +08:00
|
|
|
#ifdef CONFIG_NET_VLAN
|
2025-02-07 14:46:46 +08:00
|
|
|
int netlib_add_vlan(FAR const char *ifname, int vlanid, int prio);
|
2025-01-07 18:10:13 +08:00
|
|
|
int netlib_del_vlan(FAR const char *vlanif);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-08 11:44:59 -06:00
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
|
/* ARP Table Support */
|
|
|
|
|
|
2022-12-06 13:42:15 +08:00
|
|
|
int netlib_del_arpmapping(FAR const struct sockaddr_in *inaddr,
|
|
|
|
|
FAR const char *ifname);
|
2016-02-08 11:44:59 -06:00
|
|
|
int netlib_get_arpmapping(FAR const struct sockaddr_in *inaddr,
|
2022-12-06 13:42:15 +08:00
|
|
|
FAR uint8_t *macaddr, FAR const char *ifname);
|
2016-02-08 11:44:59 -06:00
|
|
|
int netlib_set_arpmapping(FAR const struct sockaddr_in *inaddr,
|
2022-12-06 13:42:15 +08:00
|
|
|
FAR const uint8_t *macaddr,
|
|
|
|
|
FAR const char *ifname);
|
2019-11-03 15:13:47 -06:00
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
2022-12-11 21:36:23 +08:00
|
|
|
struct arpreq;
|
|
|
|
|
ssize_t netlib_get_arptable(FAR struct arpreq *arptab,
|
2019-11-03 16:19:14 -06:00
|
|
|
unsigned int nentries);
|
2019-11-03 15:13:47 -06:00
|
|
|
#endif
|
2016-02-08 11:44:59 -06:00
|
|
|
#endif
|
|
|
|
|
|
2017-09-20 10:35:56 -06:00
|
|
|
#ifdef HAVE_ROUTE_PROCFS
|
|
|
|
|
# ifdef CONFIG_NET_IPv4
|
|
|
|
|
# define netlib_open_ipv4route() fopen(IPv4_ROUTE_PATH, "r")
|
|
|
|
|
# define netlib_close_ipv4route(stream) fclose(stream)
|
|
|
|
|
ssize_t netlib_read_ipv4route(FILE *stream,
|
|
|
|
|
FAR struct netlib_ipv4_route_s *route);
|
|
|
|
|
int netlib_ipv4router(FAR const struct in_addr *destipaddr,
|
|
|
|
|
FAR struct in_addr *router);
|
|
|
|
|
# endif
|
|
|
|
|
# ifdef CONFIG_NET_IPv6
|
|
|
|
|
# define netlib_open_ipv6route() fopen(IPv6_ROUTE_PATH, "r")
|
|
|
|
|
# define netlib_close_ipv6route(stream) fclose(stream)
|
|
|
|
|
ssize_t netlib_read_ipv6route(FILE *stream,
|
|
|
|
|
FAR struct netlib_ipv6_route_s *route);
|
|
|
|
|
int netlib_ipv6router(FAR const struct in6_addr *destipaddr,
|
|
|
|
|
FAR struct in6_addr *router);
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
2019-11-10 12:36:34 -06:00
|
|
|
|
|
|
|
|
#if defined(CONFIG_NETLINK_ROUTE) && defined(CONFIG_NET_ROUTE)
|
|
|
|
|
struct rtentry; /* Forward reference */
|
|
|
|
|
ssize_t netlib_get_route(FAR struct rtentry *rtelist,
|
|
|
|
|
unsigned int nentries, sa_family_t family);
|
|
|
|
|
#endif
|
2017-09-20 10:35:56 -06:00
|
|
|
|
2024-08-19 10:15:10 +08:00
|
|
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETUTILS_DHCPC)
|
|
|
|
|
/* DHCP */
|
|
|
|
|
|
|
|
|
|
int netlib_obtain_ipv4addr(FAR const char *ifname);
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-12 11:53:23 -06:00
|
|
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
2015-02-03 08:01:55 -06:00
|
|
|
/* ICMPv6 Autoconfiguration */
|
|
|
|
|
|
|
|
|
|
int netlib_icmpv6_autoconfiguration(FAR const char *ifname);
|
2023-11-23 19:14:19 +08:00
|
|
|
|
|
|
|
|
/* DHCPv6 */
|
|
|
|
|
|
|
|
|
|
int netlib_obtain_ipv6addr(FAR const char *ifname);
|
2015-02-03 08:01:55 -06:00
|
|
|
#endif
|
2022-12-13 18:08:12 +08:00
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPTABLES
|
|
|
|
|
/* iptables interface support */
|
|
|
|
|
|
|
|
|
|
struct ipt_replace; /* Forward reference */
|
|
|
|
|
struct ipt_entry; /* Forward reference */
|
2024-05-07 14:46:45 +08:00
|
|
|
struct ip6t_replace; /* Forward reference */
|
|
|
|
|
struct ip6t_entry; /* Forward reference */
|
2022-12-13 18:08:12 +08:00
|
|
|
enum nf_inet_hooks; /* Forward reference */
|
|
|
|
|
|
2024-05-07 14:46:45 +08:00
|
|
|
# ifdef CONFIG_NET_IPv4
|
2022-12-13 18:08:12 +08:00
|
|
|
FAR struct ipt_replace *netlib_ipt_prepare(FAR const char *table);
|
|
|
|
|
int netlib_ipt_commit(FAR const struct ipt_replace *repl);
|
|
|
|
|
int netlib_ipt_flush(FAR const char *table, enum nf_inet_hooks hook);
|
2024-04-16 16:06:22 +08:00
|
|
|
int netlib_ipt_policy(FAR const char *table, enum nf_inet_hooks hook,
|
|
|
|
|
int verdict);
|
2022-12-13 18:08:12 +08:00
|
|
|
int netlib_ipt_append(FAR struct ipt_replace **repl,
|
|
|
|
|
FAR const struct ipt_entry *entry,
|
|
|
|
|
enum nf_inet_hooks hook);
|
|
|
|
|
int netlib_ipt_insert(FAR struct ipt_replace **repl,
|
|
|
|
|
FAR const struct ipt_entry *entry,
|
|
|
|
|
enum nf_inet_hooks hook, int rulenum);
|
|
|
|
|
int netlib_ipt_delete(FAR struct ipt_replace *repl,
|
|
|
|
|
FAR const struct ipt_entry *entry,
|
|
|
|
|
enum nf_inet_hooks hook, int rulenum);
|
2024-04-16 16:06:22 +08:00
|
|
|
int netlib_ipt_fillifname(FAR struct ipt_entry *entry,
|
|
|
|
|
FAR const char *inifname,
|
|
|
|
|
FAR const char *outifname);
|
2024-05-07 14:46:45 +08:00
|
|
|
# ifdef CONFIG_NET_NAT
|
2022-12-13 18:08:12 +08:00
|
|
|
FAR struct ipt_entry *netlib_ipt_masquerade_entry(FAR const char *ifname);
|
2024-05-07 14:46:45 +08:00
|
|
|
# endif
|
|
|
|
|
# ifdef CONFIG_NET_IPFILTER
|
2024-04-16 16:06:22 +08:00
|
|
|
FAR struct ipt_entry *netlib_ipt_filter_entry(FAR const char *target,
|
|
|
|
|
int verdict,
|
|
|
|
|
uint8_t match_proto);
|
2024-05-07 14:46:45 +08:00
|
|
|
# endif
|
|
|
|
|
# endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
# ifdef CONFIG_NET_IPv6
|
|
|
|
|
FAR struct ip6t_replace *netlib_ip6t_prepare(FAR const char *table);
|
|
|
|
|
int netlib_ip6t_commit(FAR const struct ip6t_replace *repl);
|
|
|
|
|
int netlib_ip6t_flush(FAR const char *table, enum nf_inet_hooks hook);
|
|
|
|
|
int netlib_ip6t_policy(FAR const char *table, enum nf_inet_hooks hook,
|
|
|
|
|
int verdict);
|
|
|
|
|
int netlib_ip6t_append(FAR struct ip6t_replace **repl,
|
|
|
|
|
FAR const struct ip6t_entry *entry,
|
|
|
|
|
enum nf_inet_hooks hook);
|
|
|
|
|
int netlib_ip6t_insert(FAR struct ip6t_replace **repl,
|
|
|
|
|
FAR const struct ip6t_entry *entry,
|
|
|
|
|
enum nf_inet_hooks hook, int rulenum);
|
|
|
|
|
int netlib_ip6t_delete(FAR struct ip6t_replace *repl,
|
|
|
|
|
FAR const struct ip6t_entry *entry,
|
|
|
|
|
enum nf_inet_hooks hook, int rulenum);
|
|
|
|
|
int netlib_ip6t_fillifname(FAR struct ip6t_entry *entry,
|
|
|
|
|
FAR const char *inifname,
|
|
|
|
|
FAR const char *outifname);
|
|
|
|
|
# ifdef CONFIG_NET_IPFILTER
|
|
|
|
|
FAR struct ip6t_entry *netlib_ip6t_filter_entry(FAR const char *target,
|
|
|
|
|
int verdict,
|
|
|
|
|
uint8_t match_proto);
|
|
|
|
|
# endif
|
|
|
|
|
# endif /* CONFIG_NET_IPv6 */
|
|
|
|
|
#endif /* CONFIG_NET_IPTABLES */
|
2015-02-03 08:01:55 -06:00
|
|
|
|
2024-03-25 16:36:30 +08:00
|
|
|
#ifdef CONFIG_NETLINK_NETFILTER
|
|
|
|
|
/* Netfilter connection tracking support */
|
|
|
|
|
|
|
|
|
|
struct nlmsghdr; /* Forward reference */
|
|
|
|
|
|
|
|
|
|
int netlib_parse_conntrack(FAR const struct nlmsghdr *nlh, size_t len,
|
|
|
|
|
FAR struct netlib_conntrack_s *ct);
|
|
|
|
|
int netlib_get_conntrack(sa_family_t family, netlib_conntrack_cb_t cb);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-05-09 22:21:10 +00:00
|
|
|
/* HTTP support */
|
|
|
|
|
|
2023-04-14 21:49:48 +03:00
|
|
|
int netlib_parsehttpurl(FAR const char *url, uint16_t *port,
|
|
|
|
|
FAR char *hostname, int hostlen,
|
|
|
|
|
FAR char *filename, int namelen);
|
2011-05-09 22:21:10 +00:00
|
|
|
|
2019-04-26 13:08:38 -06:00
|
|
|
#ifdef CONFIG_NETUTILS_NETLIB_GENERICURLPARSER
|
|
|
|
|
int netlib_parseurl(FAR const char *str, FAR struct url_s *url);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-05-09 22:21:10 +00:00
|
|
|
/* Generic server logic */
|
|
|
|
|
|
2014-07-02 16:52:02 -06:00
|
|
|
int netlib_listenon(uint16_t portno);
|
|
|
|
|
void netlib_server(uint16_t portno, pthread_startroutine_t handler,
|
2023-04-14 21:49:48 +03:00
|
|
|
int stacksize);
|
2012-07-17 03:58:11 +00:00
|
|
|
|
2014-07-02 16:52:02 -06:00
|
|
|
int netlib_getifstatus(FAR const char *ifname, FAR uint8_t *flags);
|
|
|
|
|
int netlib_ifup(FAR const char *ifname);
|
|
|
|
|
int netlib_ifdown(FAR const char *ifname);
|
2025-05-20 00:44:52 +08:00
|
|
|
int netlib_ifarp(const char *ifname);
|
|
|
|
|
int netlib_ifnoarp(const char *ifname);
|
2012-11-04 18:54:04 +00:00
|
|
|
|
2015-07-12 11:53:23 -06:00
|
|
|
/* DNS server addressing */
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT)
|
|
|
|
|
int netlib_set_ipv4dnsaddr(FAR const struct in_addr *inaddr);
|
2025-11-06 11:11:15 +08:00
|
|
|
int netlib_del_ipv4dnsaddr(FAR const struct in_addr *inaddr);
|
|
|
|
|
int netlib_del_ipv4dnsaddr_by_index(int index);
|
2015-07-12 11:53:23 -06:00
|
|
|
#endif
|
|
|
|
|
|
2022-08-03 17:34:31 +08:00
|
|
|
#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NETDB_DNSCLIENT)
|
|
|
|
|
int netlib_set_ipv6dnsaddr(FAR const struct in6_addr *inaddr);
|
2025-11-06 11:11:15 +08:00
|
|
|
int netlib_del_ipv6dnsaddr(FAR const struct in6_addr *inaddr);
|
|
|
|
|
int netlib_del_ipv6dnsaddr_by_index(int index);
|
2022-08-03 17:34:31 +08:00
|
|
|
#endif
|
|
|
|
|
|
2023-04-27 10:58:11 +08:00
|
|
|
int netlib_set_mtu(FAR const char *ifname, int mtu);
|
|
|
|
|
|
2024-09-06 15:22:35 +08:00
|
|
|
#if defined(CONFIG_NETDEV_STATISTICS)
|
|
|
|
|
int netlib_getifstatistics(FAR const char *ifname,
|
|
|
|
|
FAR struct netdev_statistics_s *stat);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-09-29 16:26:14 +08:00
|
|
|
/* Network check support */
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ARP_ACD
|
|
|
|
|
int netlib_check_ifconflict(FAR const char *ifname);
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-04-23 11:50:53 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: netlib_check_ipconnectivity
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Check network connectivity by pinging a remote IP address.
|
|
|
|
|
* If ip is NULL, ping the gateway of each network interface,
|
|
|
|
|
* and optionally the routers from the routing table. If ping
|
|
|
|
|
* is disabled, just check the status of the IP network card.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* ip The ipv4 address to check, or NULL to ping gateways
|
|
|
|
|
* timeout The max timeout of each ping
|
|
|
|
|
* retry The retry times of ping
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* nums of remote reply of ping; a negative or ZERO on failure
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2024-10-12 16:54:05 +08:00
|
|
|
int netlib_check_ipconnectivity(FAR const char *ip, int timeout, int retry);
|
2026-04-23 11:50:53 +08:00
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETUTILS_PING
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: netlib_check_ifconnectivity
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Check network connectivity by pinging the default gateway
|
|
|
|
|
* of the specified network interface.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* ifname The name of the interface to use
|
|
|
|
|
* timeout The timeout of ping
|
|
|
|
|
* retry The retry times of ping
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* nums of gateway reply of ping; a negative on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2024-10-10 16:34:10 +08:00
|
|
|
int netlib_check_ifconnectivity(FAR const char *ifname,
|
|
|
|
|
int timeout, int retry);
|
2025-08-06 20:48:43 +08:00
|
|
|
#else
|
|
|
|
|
#define netlib_check_ifconnectivity(i, t, r) 1
|
2024-10-12 16:54:05 +08:00
|
|
|
#endif
|
|
|
|
|
|
2024-10-09 17:34:00 +08:00
|
|
|
#ifdef CONFIG_MM_IOB
|
|
|
|
|
int netlib_get_iobinfo(FAR struct iob_stats_s *iob);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-10-14 20:36:13 +08:00
|
|
|
int netlib_check_httpconnectivity(FAR const char *host,
|
|
|
|
|
FAR const char *getmsg,
|
|
|
|
|
int port, int expect_code);
|
|
|
|
|
|
2012-07-17 03:58:11 +00:00
|
|
|
#undef EXTERN
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2011-05-09 22:21:10 +00:00
|
|
|
|
2014-07-02 16:04:25 -06:00
|
|
|
#endif /* __APPS_INCLUDE_NETUTILS_NETLIB_H */
|