2019-11-03 20:59:42 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/netlink/netlink_route.c
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2021-07-01 12:49:03 +02:00
|
|
|
#include <debug.h>
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 21:11:44 +01:00
|
|
|
#include <net/route.h>
|
2019-11-03 20:59:42 +01:00
|
|
|
#include <netpacket/netlink.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/arp.h>
|
2019-11-10 21:11:44 +01:00
|
|
|
#include <nuttx/net/ip.h>
|
2019-11-08 18:15:16 +01:00
|
|
|
#include <nuttx/net/neighbor.h>
|
2019-11-19 04:12:50 +01:00
|
|
|
#include <nuttx/net/netlink.h>
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
#include "netdev/netdev.h"
|
2019-11-03 20:59:42 +01:00
|
|
|
#include "arp/arp.h"
|
2019-11-08 18:15:16 +01:00
|
|
|
#include "neighbor/neighbor.h"
|
2019-11-10 21:11:44 +01:00
|
|
|
#include "route/route.h"
|
2019-11-03 20:59:42 +01:00
|
|
|
#include "netlink/netlink.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-11-12 17:19:42 +01:00
|
|
|
* Pre-processor Definitions
|
2019-11-03 20:59:42 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_NET_ARP) && !defined(CONFIG_NET_IPv6)
|
|
|
|
# undef CONFIG_NETLINK_DISABLE_GETNEIGH
|
|
|
|
# define CONFIG_NETLINK_DISABLE_GETNEIGH 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_NET_ROUTE) || (!defined(CONFIG_NET_IPv4) && \
|
|
|
|
!defined(CONFIG_NET_IPv6))
|
|
|
|
# undef CONFIG_NETLINK_DISABLE_GETROUTE
|
|
|
|
# define CONFIG_NETLINK_DISABLE_GETROUTE 1
|
|
|
|
#endif
|
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
/* RTM_GETLINK: Enumerate network devices */
|
2019-11-10 00:36:30 +01:00
|
|
|
|
|
|
|
struct getlink_recvfrom_response_s
|
|
|
|
{
|
|
|
|
struct nlmsghdr hdr;
|
|
|
|
struct ifinfomsg iface;
|
|
|
|
struct rtattr attr;
|
|
|
|
uint8_t data[IFNAMSIZ]; /* IFLA_IFNAME is the only attribute supported */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct getlink_recvfrom_rsplist_s
|
|
|
|
{
|
|
|
|
sq_entry_t flink;
|
|
|
|
struct getlink_recvfrom_response_s payload;
|
|
|
|
};
|
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
/* RTM_GETNEIGH: Get neighbor table entry */
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
struct getneigh_recvfrom_response_s
|
2019-11-03 20:59:42 +01:00
|
|
|
{
|
|
|
|
struct nlmsghdr hdr;
|
2019-11-10 00:36:30 +01:00
|
|
|
struct ndmsg msg;
|
|
|
|
struct rtattr attr;
|
|
|
|
uint8_t data[1];
|
2019-11-03 20:59:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(n) \
|
2019-11-10 00:36:30 +01:00
|
|
|
(sizeof(struct getneigh_recvfrom_response_s) + (n) - 1)
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
struct getneigh_recvfrom_rsplist_s
|
2019-11-04 02:27:58 +01:00
|
|
|
{
|
2019-11-04 16:02:14 +01:00
|
|
|
sq_entry_t flink;
|
2019-11-10 00:36:30 +01:00
|
|
|
struct getneigh_recvfrom_response_s payload;
|
2019-11-04 02:27:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(n) \
|
2019-11-10 00:36:30 +01:00
|
|
|
(sizeof(struct getneigh_recvfrom_rsplist_s) + (n) - 1)
|
|
|
|
|
2019-11-10 21:11:44 +01:00
|
|
|
/* RTM_GETROUTE. Get routing tables */
|
|
|
|
|
|
|
|
struct getroute_recvfrom_ipv4addr_s
|
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct rtattr attr;
|
|
|
|
in_addr_t addr;
|
2019-11-10 21:11:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct getroute_recvfrom_ipv4response_s
|
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlmsghdr hdr;
|
|
|
|
struct rtmsg rte;
|
2019-11-10 21:11:44 +01:00
|
|
|
struct getroute_recvfrom_ipv4addr_s dst;
|
|
|
|
struct getroute_recvfrom_ipv4addr_s genmask;
|
|
|
|
struct getroute_recvfrom_ipv4addr_s gateway;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct getroute_recvfrom_ipv4resplist_s
|
|
|
|
{
|
|
|
|
sq_entry_t flink;
|
|
|
|
struct getroute_recvfrom_ipv4response_s payload;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct getroute_recvfrom_ipv6addr_s
|
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct rtattr attr;
|
|
|
|
net_ipv6addr_t addr;
|
2019-11-10 21:11:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct getroute_recvfrom_ipv6response_s
|
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlmsghdr hdr;
|
|
|
|
struct rtmsg rte;
|
2019-11-10 21:11:44 +01:00
|
|
|
struct getroute_recvfrom_ipv6addr_s dst;
|
|
|
|
struct getroute_recvfrom_ipv6addr_s genmask;
|
|
|
|
struct getroute_recvfrom_ipv6addr_s gateway;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct getroute_recvfrom_ipv6resplist_s
|
|
|
|
{
|
|
|
|
sq_entry_t flink;
|
|
|
|
struct getroute_recvfrom_ipv6response_s payload;
|
|
|
|
};
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* netdev_foreach() callback */
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlroute_sendto_request_s
|
2019-11-10 00:36:30 +01:00
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlmsghdr hdr;
|
|
|
|
struct rtgenmsg gen;
|
2019-11-10 00:36:30 +01:00
|
|
|
};
|
2019-11-04 02:27:58 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlroute_info_s
|
2019-11-10 21:11:44 +01:00
|
|
|
{
|
2020-04-13 14:49:52 +02:00
|
|
|
NETLINK_HANDLE handle;
|
2020-04-10 07:54:18 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req;
|
2019-11-10 21:11:44 +01:00
|
|
|
};
|
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
/****************************************************************************
|
2019-11-10 00:36:30 +01:00
|
|
|
* Private Functions
|
2019-11-03 20:59:42 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-04-13 10:10:30 +02:00
|
|
|
* Name: netlink_get_device
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-04-13 10:10:30 +02:00
|
|
|
* Generate one device response.
|
2019-11-03 20:59:42 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#ifndef CONFIG_NETLINK_DISABLE_GETLINK
|
2020-04-13 10:10:30 +02:00
|
|
|
static FAR struct netlink_response_s *
|
|
|
|
netlink_get_device(FAR struct net_driver_s *dev,
|
|
|
|
FAR const struct nlroute_sendto_request_s *req)
|
2019-11-03 20:59:42 +01:00
|
|
|
{
|
2019-11-10 00:36:30 +01:00
|
|
|
FAR struct getlink_recvfrom_rsplist_s *alloc;
|
|
|
|
FAR struct getlink_recvfrom_response_s *resp;
|
2020-04-13 10:10:30 +02:00
|
|
|
int up = IFF_IS_UP(dev->d_flags);
|
2019-11-10 00:36:30 +01:00
|
|
|
|
|
|
|
/* Allocate the response buffer */
|
|
|
|
|
|
|
|
alloc = (FAR struct getlink_recvfrom_rsplist_s *)
|
2020-04-10 07:54:18 +02:00
|
|
|
kmm_zalloc(sizeof(struct getlink_recvfrom_rsplist_s));
|
2019-11-10 00:36:30 +01:00
|
|
|
if (alloc == NULL)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate response buffer.\n");
|
2020-04-13 10:10:30 +02:00
|
|
|
return NULL;
|
2019-11-10 00:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the response buffer */
|
|
|
|
|
|
|
|
resp = &alloc->payload;
|
|
|
|
|
|
|
|
resp->hdr.nlmsg_len = sizeof(struct getlink_recvfrom_response_s);
|
2020-04-13 10:10:30 +02:00
|
|
|
resp->hdr.nlmsg_type = up ? RTM_NEWLINK : RTM_DELLINK;
|
|
|
|
resp->hdr.nlmsg_flags = req ? req->hdr.nlmsg_flags : 0;
|
|
|
|
resp->hdr.nlmsg_seq = req ? req->hdr.nlmsg_seq : 0;
|
|
|
|
resp->hdr.nlmsg_pid = req ? req->hdr.nlmsg_pid : 0;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
resp->iface.ifi_family = req ? req->gen.rtgen_family : AF_PACKET;
|
2020-04-10 07:54:18 +02:00
|
|
|
resp->iface.ifi_type = dev->d_lltype;
|
2019-11-10 00:36:30 +01:00
|
|
|
#ifdef CONFIG_NETDEV_IFINDEX
|
2020-02-13 18:44:35 +01:00
|
|
|
resp->iface.ifi_index = dev->d_ifindex;
|
2019-11-10 00:36:30 +01:00
|
|
|
#endif
|
2020-02-25 09:32:37 +01:00
|
|
|
resp->iface.ifi_flags = dev->d_flags;
|
2019-11-10 00:36:30 +01:00
|
|
|
resp->iface.ifi_change = 0xffffffff;
|
|
|
|
|
2019-11-11 20:38:11 +01:00
|
|
|
resp->attr.rta_len = RTA_LENGTH(strnlen(dev->d_ifname, IFNAMSIZ));
|
2019-11-10 00:36:30 +01:00
|
|
|
resp->attr.rta_type = IFLA_IFNAME;
|
|
|
|
|
2022-04-01 09:03:47 +02:00
|
|
|
strlcpy((FAR char *)resp->data, dev->d_ifname, IFNAMSIZ);
|
2019-11-10 00:36:30 +01:00
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
/* Finally, return the response */
|
2019-11-10 00:36:30 +01:00
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
return (FAR struct netlink_response_s *)alloc;
|
2019-11-10 00:36:30 +01:00
|
|
|
}
|
2019-11-12 17:19:42 +01:00
|
|
|
#endif
|
2019-11-10 00:36:30 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2020-04-13 10:10:30 +02:00
|
|
|
* Name: netlink_get_terminator
|
2019-11-10 00:36:30 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-04-13 10:10:30 +02:00
|
|
|
* Generate one NLMSG_DONE response.
|
2019-11-10 00:36:30 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
static FAR struct netlink_response_s *
|
|
|
|
netlink_get_terminator(FAR const struct nlroute_sendto_request_s *req)
|
2019-11-10 00:36:30 +01:00
|
|
|
{
|
2020-04-13 09:40:01 +02:00
|
|
|
FAR struct netlink_response_s *resp;
|
|
|
|
FAR struct nlmsghdr *hdr;
|
2019-11-10 00:36:30 +01:00
|
|
|
|
2020-04-13 09:40:01 +02:00
|
|
|
/* Allocate the list terminator */
|
2019-11-10 00:36:30 +01:00
|
|
|
|
2020-04-13 09:40:01 +02:00
|
|
|
resp = kmm_zalloc(sizeof(struct netlink_response_s));
|
|
|
|
if (resp == NULL)
|
2019-11-10 00:36:30 +01:00
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate response terminator.\n");
|
2020-04-13 10:10:30 +02:00
|
|
|
return NULL;
|
2019-11-10 00:36:30 +01:00
|
|
|
}
|
|
|
|
|
2020-04-13 09:40:01 +02:00
|
|
|
/* Initialize and send the list terminator */
|
|
|
|
|
|
|
|
hdr = &resp->msg;
|
|
|
|
hdr->nlmsg_len = sizeof(struct nlmsghdr);
|
|
|
|
hdr->nlmsg_type = NLMSG_DONE;
|
2020-04-13 10:10:30 +02:00
|
|
|
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;
|
2020-04-13 09:40:01 +02:00
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
/* 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;
|
|
|
|
}
|
2020-04-13 09:40:01 +02:00
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_add_response(handle, resp);
|
2020-04-13 09:40:01 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_get_devlist
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump a list of all network devices of the specified type.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NETLINK_DISABLE_GETLINK
|
2020-04-13 10:10:30 +02:00
|
|
|
static int netlink_device_callback(FAR struct net_driver_s *dev,
|
|
|
|
FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct nlroute_info_s *info = arg;
|
|
|
|
FAR struct netlink_response_s * resp;
|
|
|
|
|
|
|
|
resp = netlink_get_device(dev, info->req);
|
|
|
|
if (resp == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
netlink_add_response(info->handle, resp);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
static int netlink_get_devlist(NETLINK_HANDLE handle,
|
2020-04-13 09:40:01 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req)
|
|
|
|
{
|
|
|
|
struct nlroute_info_s info;
|
|
|
|
int ret;
|
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/* Visit each device */
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
info.handle = handle;
|
|
|
|
info.req = req;
|
2019-11-10 00:36:30 +01:00
|
|
|
|
|
|
|
net_lock();
|
2020-04-10 07:54:18 +02:00
|
|
|
ret = netdev_foreach(netlink_device_callback, &info);
|
|
|
|
net_unlock();
|
2019-11-10 00:36:30 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
return netlink_add_terminator(handle, req);
|
2019-11-10 00:36:30 +01:00
|
|
|
}
|
2019-11-12 17:19:42 +01:00
|
|
|
#endif
|
2019-11-10 00:36:30 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_get_arptable()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the entire ARP table.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#if defined(CONFIG_NET_ARP) && !defined(CONFIG_NETLINK_DISABLE_GETNEIGH)
|
2020-04-13 14:49:52 +02:00
|
|
|
static int netlink_get_arptable(NETLINK_HANDLE handle,
|
2020-04-10 15:03:34 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req)
|
2019-11-10 00:36:30 +01:00
|
|
|
{
|
|
|
|
FAR struct getneigh_recvfrom_rsplist_s *entry;
|
|
|
|
unsigned int ncopied;
|
2020-04-13 14:49:52 +02:00
|
|
|
size_t allocsize;
|
2019-11-10 00:36:30 +01:00
|
|
|
size_t tabsize;
|
|
|
|
size_t rspsize;
|
|
|
|
|
|
|
|
/* Preallocate memory to hold the maximum sized ARP table
|
|
|
|
* REVISIT: This is probably excessively large and could cause false
|
|
|
|
* memory out conditions. A better approach would be to actually count
|
|
|
|
* the number of valid entries in the ARP table.
|
2019-11-03 20:59:42 +01:00
|
|
|
*/
|
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
tabsize = CONFIG_NET_ARPTAB_SIZE * sizeof(struct arp_entry_s);
|
|
|
|
rspsize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
|
|
|
allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
|
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
entry = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
|
2019-11-10 00:36:30 +01:00
|
|
|
if (entry == NULL)
|
2019-11-03 20:59:42 +01:00
|
|
|
{
|
2019-11-10 00:36:30 +01:00
|
|
|
nerr("ERROR: Failed to allocate response buffer.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/* Populate the entry */
|
|
|
|
|
|
|
|
memcpy(&entry->payload.hdr, &req->hdr, sizeof(struct nlmsghdr));
|
2020-04-10 07:54:18 +02:00
|
|
|
entry->payload.hdr.nlmsg_len = rspsize;
|
|
|
|
entry->payload.msg.ndm_family = req->gen.rtgen_family;
|
|
|
|
entry->payload.attr.rta_len = RTA_LENGTH(tabsize);
|
2019-11-10 00:36:30 +01:00
|
|
|
|
|
|
|
/* Lock the network so that the ARP table will be stable, then copy
|
|
|
|
* the ARP table into the allocated memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
ncopied = arp_snapshot((FAR struct arp_entry_s *)entry->payload.data,
|
|
|
|
CONFIG_NET_ARPTAB_SIZE);
|
|
|
|
net_unlock();
|
|
|
|
|
|
|
|
/* Now we have the real number of valid entries in the ARP table and
|
|
|
|
* we can trim the allocation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ncopied < CONFIG_NET_ARPTAB_SIZE)
|
|
|
|
{
|
|
|
|
FAR struct getneigh_recvfrom_rsplist_s *newentry;
|
|
|
|
|
|
|
|
tabsize = ncopied * sizeof(struct arp_entry_s);
|
|
|
|
rspsize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
2019-11-04 02:27:58 +01:00
|
|
|
allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
newentry = (FAR struct getneigh_recvfrom_rsplist_s *)
|
|
|
|
kmm_realloc(entry, allocsize);
|
|
|
|
|
|
|
|
if (newentry != NULL)
|
2019-11-03 20:59:42 +01:00
|
|
|
{
|
2019-11-10 00:36:30 +01:00
|
|
|
entry = newentry;
|
2019-11-03 20:59:42 +01:00
|
|
|
}
|
|
|
|
|
2019-11-04 02:27:58 +01:00
|
|
|
entry->payload.hdr.nlmsg_len = rspsize;
|
2019-11-11 20:38:11 +01:00
|
|
|
entry->payload.attr.rta_len = RTA_LENGTH(tabsize);
|
2019-11-10 00:36:30 +01:00
|
|
|
}
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/* Finally, add the data to the list of pending responses */
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_add_response(handle, (FAR struct netlink_response_s *)entry);
|
2019-11-10 00:36:30 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_get_nbtable()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the entire IPv6 neighbor table.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETNEIGH)
|
2020-04-13 14:49:52 +02:00
|
|
|
static int netlink_get_nbtable(NETLINK_HANDLE handle,
|
2020-04-10 15:03:34 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req)
|
2019-11-10 00:36:30 +01:00
|
|
|
{
|
|
|
|
FAR struct getneigh_recvfrom_rsplist_s *entry;
|
|
|
|
unsigned int ncopied;
|
2020-04-13 14:49:52 +02:00
|
|
|
size_t allocsize;
|
2019-11-10 00:36:30 +01:00
|
|
|
size_t tabsize;
|
|
|
|
size_t rspsize;
|
|
|
|
|
|
|
|
/* Preallocate memory to hold the maximum sized Neighbor table
|
|
|
|
* REVISIT: This is probably excessively large and could cause false
|
|
|
|
* memory out conditions. A better approach would be to actually count
|
|
|
|
* the number of valid entries in the Neighbor table.
|
|
|
|
*/
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
tabsize = CONFIG_NET_IPv6_NCONF_ENTRIES *
|
|
|
|
sizeof(struct neighbor_entry_s);
|
|
|
|
rspsize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
|
|
|
allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
entry = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
|
2019-11-10 00:36:30 +01:00
|
|
|
if (entry == NULL)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate response buffer.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/* Populate the entry */
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
memcpy(&entry->payload.hdr, &req->hdr, sizeof(struct nlmsghdr));
|
2020-04-10 07:54:18 +02:00
|
|
|
entry->payload.hdr.nlmsg_len = rspsize;
|
|
|
|
entry->payload.msg.ndm_family = req->gen.rtgen_family;
|
|
|
|
entry->payload.attr.rta_len = RTA_LENGTH(tabsize);
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/* Lock the network so that the Neighbor table will be stable, then
|
|
|
|
* copy the Neighbor table into the allocated memory.
|
|
|
|
*/
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
net_lock();
|
2020-04-10 15:03:34 +02:00
|
|
|
ncopied = neighbor_snapshot(
|
|
|
|
(FAR struct neighbor_entry_s *)entry->payload.data,
|
|
|
|
CONFIG_NET_IPv6_NCONF_ENTRIES);
|
2019-11-10 00:36:30 +01:00
|
|
|
net_unlock();
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/* Now we have the real number of valid entries in the Neighbor table
|
|
|
|
* and we can trim the allocation.
|
2019-11-08 18:15:16 +01:00
|
|
|
*/
|
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
if (ncopied < CONFIG_NET_IPv6_NCONF_ENTRIES)
|
2019-11-08 18:15:16 +01:00
|
|
|
{
|
2019-11-10 00:36:30 +01:00
|
|
|
FAR struct getneigh_recvfrom_rsplist_s *newentry;
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
tabsize = ncopied * sizeof(struct neighbor_entry_s);
|
2019-11-08 18:15:16 +01:00
|
|
|
rspsize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
|
|
|
allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
|
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
newentry = (FAR struct getneigh_recvfrom_rsplist_s *)
|
|
|
|
kmm_realloc(entry, allocsize);
|
|
|
|
|
|
|
|
if (newentry != NULL)
|
2019-11-08 18:15:16 +01:00
|
|
|
{
|
2019-11-10 00:36:30 +01:00
|
|
|
entry = newentry;
|
2019-11-08 18:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
entry->payload.hdr.nlmsg_len = rspsize;
|
2019-11-11 20:38:11 +01:00
|
|
|
entry->payload.attr.rta_len = RTA_LENGTH(tabsize);
|
2019-11-10 00:36:30 +01:00
|
|
|
}
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-10 21:11:44 +01:00
|
|
|
/* Finally, add the response to the list of pending responses */
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_add_response(handle, (FAR struct netlink_response_s *)entry);
|
2019-11-10 00:36:30 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-10 21:11:44 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_ipv4_route
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump a list of all network devices of the specified type.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#if defined(CONFIG_NET_IPv4) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
|
2019-11-10 21:11:44 +01:00
|
|
|
static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
|
|
|
|
FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct getroute_recvfrom_ipv4resplist_s *alloc;
|
|
|
|
FAR struct getroute_recvfrom_ipv4response_s *resp;
|
2020-04-13 14:49:52 +02:00
|
|
|
FAR struct nlroute_info_s *info;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(route != NULL && arg != NULL);
|
2020-04-10 07:54:18 +02:00
|
|
|
info = (FAR struct nlroute_info_s *)arg;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
|
|
|
/* Allocate the response */
|
|
|
|
|
|
|
|
alloc = (FAR struct getroute_recvfrom_ipv4resplist_s *)
|
2020-04-10 07:54:18 +02:00
|
|
|
kmm_zalloc(sizeof(struct getroute_recvfrom_ipv4resplist_s));
|
2019-11-10 21:11:44 +01:00
|
|
|
if (alloc == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the response */
|
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
resp = &alloc->payload;
|
|
|
|
resp->hdr.nlmsg_len = sizeof(struct getroute_recvfrom_ipv4response_s);
|
|
|
|
resp->hdr.nlmsg_type = RTM_NEWROUTE;
|
|
|
|
resp->hdr.nlmsg_flags = info->req->hdr.nlmsg_flags;
|
|
|
|
resp->hdr.nlmsg_seq = info->req->hdr.nlmsg_seq;
|
|
|
|
resp->hdr.nlmsg_pid = info->req->hdr.nlmsg_pid;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
resp->rte.rtm_family = info->req->gen.rtgen_family;
|
|
|
|
resp->rte.rtm_table = RT_TABLE_MAIN;
|
|
|
|
resp->rte.rtm_protocol = RTPROT_STATIC;
|
|
|
|
resp->rte.rtm_scope = RT_SCOPE_SITE;
|
2019-11-18 17:47:35 +01:00
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
resp->dst.attr.rta_len = RTA_LENGTH(sizeof(in_addr_t));
|
|
|
|
resp->dst.attr.rta_type = RTA_DST;
|
|
|
|
resp->dst.addr = route->target;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2019-11-11 20:38:11 +01:00
|
|
|
resp->genmask.attr.rta_len = RTA_LENGTH(sizeof(in_addr_t));
|
2019-11-10 21:11:44 +01:00
|
|
|
resp->genmask.attr.rta_type = RTA_GENMASK;
|
|
|
|
resp->genmask.addr = route->netmask;
|
|
|
|
|
2019-11-11 20:38:11 +01:00
|
|
|
resp->gateway.attr.rta_len = RTA_LENGTH(sizeof(in_addr_t));
|
2019-11-10 21:11:44 +01:00
|
|
|
resp->gateway.attr.rta_type = RTA_GATEWAY;
|
|
|
|
resp->gateway.addr = route->router;
|
|
|
|
|
|
|
|
/* Finally, add the response to the list of pending responses */
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_add_response(info->handle, (FAR struct netlink_response_s *)alloc);
|
2019-11-10 21:11:44 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_get_ipv4route
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump a list of all network devices of the specified type.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#if defined(CONFIG_NET_IPv4) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
|
2020-04-13 14:49:52 +02:00
|
|
|
static int netlink_get_ipv4route(NETLINK_HANDLE handle,
|
2020-04-10 15:03:34 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req)
|
2019-11-10 21:11:44 +01:00
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlroute_info_s info;
|
2019-11-10 21:11:44 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Visit each routing table entry */
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
info.handle = handle;
|
|
|
|
info.req = req;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
ret = net_foreachroute_ipv4(netlink_ipv4_route, &info);
|
2019-11-10 21:11:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-10 22:00:05 +01:00
|
|
|
/* Terminate the routing table */
|
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
return netlink_add_terminator(handle, req);
|
2019-11-10 21:11:44 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_ipv6_route
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump a list of all network devices of the specified type.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
|
2019-11-10 21:11:44 +01:00
|
|
|
static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
|
|
|
|
FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct getroute_recvfrom_ipv6resplist_s *alloc;
|
|
|
|
FAR struct getroute_recvfrom_ipv6response_s *resp;
|
2020-04-13 14:49:52 +02:00
|
|
|
FAR struct nlroute_info_s *info;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(route != NULL && arg != NULL);
|
2020-04-10 07:54:18 +02:00
|
|
|
info = (FAR struct nlroute_info_s *)arg;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
|
|
|
/* Allocate the response */
|
|
|
|
|
|
|
|
alloc = (FAR struct getroute_recvfrom_ipv6resplist_s *)
|
2020-04-10 07:54:18 +02:00
|
|
|
kmm_zalloc(sizeof(struct getroute_recvfrom_ipv6resplist_s));
|
2019-11-10 21:11:44 +01:00
|
|
|
if (alloc == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the response */
|
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
resp = &alloc->payload;
|
|
|
|
resp->hdr.nlmsg_len = sizeof(struct getroute_recvfrom_ipv6response_s);
|
|
|
|
resp->hdr.nlmsg_type = RTM_NEWROUTE;
|
|
|
|
resp->hdr.nlmsg_flags = info->req->hdr.nlmsg_flags;
|
|
|
|
resp->hdr.nlmsg_seq = info->req->hdr.nlmsg_seq;
|
|
|
|
resp->hdr.nlmsg_pid = info->req->hdr.nlmsg_pid;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
resp->rte.rtm_family = info->req->gen.rtgen_family;
|
|
|
|
resp->rte.rtm_table = RT_TABLE_MAIN;
|
|
|
|
resp->rte.rtm_protocol = RTPROT_STATIC;
|
|
|
|
resp->rte.rtm_scope = RT_SCOPE_SITE;
|
2019-11-18 17:47:35 +01:00
|
|
|
|
2020-04-10 15:03:34 +02:00
|
|
|
resp->dst.attr.rta_len = RTA_LENGTH(sizeof(net_ipv6addr_t));
|
|
|
|
resp->dst.attr.rta_type = RTA_DST;
|
2019-11-10 21:11:44 +01:00
|
|
|
net_ipv6addr_copy(resp->dst.addr, route->target);
|
|
|
|
|
2019-11-11 20:38:11 +01:00
|
|
|
resp->genmask.attr.rta_len = RTA_LENGTH(sizeof(net_ipv6addr_t));
|
2019-11-10 21:11:44 +01:00
|
|
|
resp->genmask.attr.rta_type = RTA_GENMASK;
|
|
|
|
net_ipv6addr_copy(resp->genmask.addr, route->netmask);
|
|
|
|
|
2019-11-11 20:38:11 +01:00
|
|
|
resp->gateway.attr.rta_len = RTA_LENGTH(sizeof(net_ipv6addr_t));
|
2019-11-10 21:11:44 +01:00
|
|
|
resp->gateway.attr.rta_type = RTA_GATEWAY;
|
|
|
|
net_ipv6addr_copy(resp->gateway.addr, route->router);
|
|
|
|
|
|
|
|
/* Finally, add the response to the list of pending responses */
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
netlink_add_response(info->handle, (FAR struct netlink_response_s *)alloc);
|
2019-11-10 21:11:44 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_get_ip6vroute
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump a list of all network devices of the specified type.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
|
2020-04-13 14:49:52 +02:00
|
|
|
static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
|
2020-04-10 15:03:34 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req)
|
2019-11-10 21:11:44 +01:00
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
struct nlroute_info_s info;
|
2019-11-10 21:11:44 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Visit each routing table entry */
|
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
info.handle = handle;
|
|
|
|
info.req = req;
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
ret = net_foreachroute_ipv6(netlink_ipv6_route, &info);
|
2019-11-10 21:11:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-10 22:00:05 +01:00
|
|
|
/* Terminate the routing table */
|
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
return netlink_add_terminator(handle, req);
|
2019-11-10 21:11:44 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_route_sendto()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform the sendto() operation for the NETLINK_ROUTE protocol.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
|
2019-11-10 00:36:30 +01:00
|
|
|
FAR const struct nlmsghdr *nlmsg,
|
|
|
|
size_t len, int flags,
|
|
|
|
FAR const struct sockaddr_nl *to,
|
|
|
|
socklen_t tolen)
|
|
|
|
{
|
2020-04-10 07:54:18 +02:00
|
|
|
FAR const struct nlroute_sendto_request_s *req =
|
|
|
|
(FAR const struct nlroute_sendto_request_s *)nlmsg;
|
2019-11-12 17:19:42 +01:00
|
|
|
int ret;
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
DEBUGASSERT(handle != NULL && nlmsg != NULL &&
|
2019-11-10 00:36:30 +01:00
|
|
|
nlmsg->nlmsg_len >= sizeof(struct nlmsghdr) &&
|
|
|
|
len >= sizeof(struct nlmsghdr) &&
|
|
|
|
len >= nlmsg->nlmsg_len && to != NULL &&
|
|
|
|
tolen >= sizeof(struct sockaddr_nl));
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
/* Handle according to the message type */
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
switch (nlmsg->nlmsg_type)
|
2019-11-10 00:36:30 +01:00
|
|
|
{
|
2019-11-12 17:19:42 +01:00
|
|
|
#ifndef CONFIG_NETLINK_DISABLE_GETLINK
|
|
|
|
/* Dump a list of all devices */
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
case RTM_GETLINK:
|
2020-04-10 15:03:34 +02:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
/* Generate the response */
|
2019-11-12 17:19:42 +01:00
|
|
|
|
2020-04-13 14:49:52 +02:00
|
|
|
ret = netlink_get_devlist(handle, req);
|
2019-11-12 17:19:42 +01:00
|
|
|
break;
|
|
|
|
#endif
|
2019-11-08 18:15:16 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#ifndef CONFIG_NETLINK_DISABLE_GETNEIGH
|
|
|
|
/* Retrieve ARP/Neighbor Tables */
|
|
|
|
|
|
|
|
case RTM_GETNEIGH:
|
2019-11-10 00:36:30 +01:00
|
|
|
#ifdef CONFIG_NET_ARP
|
2020-04-10 07:54:18 +02:00
|
|
|
/* Retrieve the ARP table in its entirety. */
|
2019-11-10 00:36:30 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
if (req->gen.rtgen_family == AF_INET)
|
|
|
|
{
|
2020-04-13 14:49:52 +02:00
|
|
|
ret = netlink_get_arptable(handle, req);
|
2020-04-10 07:54:18 +02:00
|
|
|
}
|
|
|
|
else
|
2019-11-08 18:15:16 +01:00
|
|
|
#endif
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-10 00:36:30 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2020-04-10 07:54:18 +02:00
|
|
|
/* Retrieve the IPv6 neighbor table in its entirety. */
|
2019-11-10 00:36:30 +01:00
|
|
|
|
2020-04-10 07:54:18 +02:00
|
|
|
if (req->gen.rtgen_family == AF_INET6)
|
|
|
|
{
|
2020-04-13 14:49:52 +02:00
|
|
|
ret = netlink_get_nbtable(handle, req);
|
2020-04-10 07:54:18 +02:00
|
|
|
}
|
|
|
|
else
|
2019-11-03 20:59:42 +01:00
|
|
|
#endif
|
2020-04-10 07:54:18 +02:00
|
|
|
{
|
|
|
|
ret = -EAFNOSUPPORT;
|
|
|
|
}
|
2019-11-12 17:19:42 +01:00
|
|
|
break;
|
|
|
|
#endif /* !CONFIG_NETLINK_DISABLE_GETNEIGH */
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
#ifndef CONFIG_NETLINK_DISABLE_GETROUTE
|
|
|
|
/* Retrieve the IPv4 or IPv6 routing table */
|
2019-11-10 21:11:44 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
case RTM_GETROUTE:
|
2019-11-10 21:11:44 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2020-04-10 07:54:18 +02:00
|
|
|
if (req->gen.rtgen_family == AF_INET)
|
|
|
|
{
|
2020-04-13 14:49:52 +02:00
|
|
|
ret = netlink_get_ipv4route(handle, req);
|
2020-04-10 07:54:18 +02:00
|
|
|
}
|
|
|
|
else
|
2019-11-10 21:11:44 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2020-04-10 07:54:18 +02:00
|
|
|
if (req->gen.rtgen_family == AF_INET6)
|
|
|
|
{
|
2020-04-13 14:49:52 +02:00
|
|
|
ret = netlink_get_ip6vroute(handle, req);
|
2020-04-10 07:54:18 +02:00
|
|
|
}
|
|
|
|
else
|
2019-11-10 21:11:44 +01:00
|
|
|
#endif
|
2020-04-10 07:54:18 +02:00
|
|
|
{
|
|
|
|
ret = -EAFNOSUPPORT;
|
|
|
|
}
|
2019-11-12 17:19:42 +01:00
|
|
|
break;
|
2019-11-10 21:11:44 +01:00
|
|
|
#endif
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
2019-11-10 21:11:44 +01:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
/* On success, return the size of the request that was processed */
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
ret = len;
|
|
|
|
}
|
2019-11-03 20:59:42 +01:00
|
|
|
|
2019-11-12 17:19:42 +01:00
|
|
|
return ret;
|
2019-11-03 20:59:42 +01:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:10:30 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlink_device_notify()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform the route broadcast for the NETLINK_ROUTE protocol.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NETLINK_DISABLE_GETLINK
|
|
|
|
void netlink_device_notify(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct netlink_response_s *resp;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev != NULL);
|
|
|
|
|
|
|
|
resp = netlink_get_device(dev, NULL);
|
|
|
|
if (resp != NULL)
|
|
|
|
{
|
|
|
|
netlink_add_broadcast(RTNLGRP_LINK, resp);
|
|
|
|
|
|
|
|
resp = netlink_get_terminator(NULL);
|
|
|
|
if (resp != NULL)
|
|
|
|
{
|
|
|
|
netlink_add_broadcast(RTNLGRP_LINK, resp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-03 20:59:42 +01:00
|
|
|
#endif /* CONFIG_NETLINK_ROUTE */
|