2007-09-16 19:46:25 +02:00
|
|
|
/****************************************************************************
|
2014-06-27 17:56:45 +02:00
|
|
|
* net/netdev/netdev_ioctl.c
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-09-16 19:46:25 +02: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.
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2007-09-17 00:12:04 +02:00
|
|
|
#include <sys/ioctl.h>
|
2007-11-04 23:59:30 +01:00
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
#include <assert.h>
|
2007-11-04 23:59:30 +01:00
|
|
|
#include <debug.h>
|
2023-08-07 10:02:57 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-11-04 23:59:30 +01:00
|
|
|
|
2012-03-04 00:18:34 +01:00
|
|
|
#include <nuttx/net/net.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
2007-09-16 19:46:25 +02:00
|
|
|
|
2007-11-30 21:46:29 +01:00
|
|
|
#include <net/if.h>
|
2013-10-02 18:51:48 +02:00
|
|
|
#include <net/route.h>
|
2007-12-11 15:28:16 +01:00
|
|
|
#include <net/ethernet.h>
|
2013-10-02 18:51:48 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2017-08-20 15:10:48 +02:00
|
|
|
#include <nuttx/net/radiodev.h>
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-04-06 23:58:00 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
# include <nuttx/net/sixlowpan.h>
|
|
|
|
#endif
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <nuttx/net/igmp.h>
|
2017-03-13 16:51:31 +01:00
|
|
|
|
2017-03-13 17:14:38 +01:00
|
|
|
#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
|
2017-03-13 16:51:31 +01:00
|
|
|
# include <nuttx/wireless/wireless.h>
|
2017-04-15 18:23:29 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH
|
2018-04-29 20:43:09 +02:00
|
|
|
# include <nuttx/wireless/bluetooth/bt_ioctl.h>
|
2018-04-06 17:42:41 +02:00
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_IEEE802154
|
|
|
|
# include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
#endif
|
2017-08-02 19:52:44 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_PKTRADIO
|
|
|
|
# include <nuttx/wireless/pktradio.h>
|
2017-04-15 17:11:52 +02:00
|
|
|
#endif
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2022-12-07 10:38:11 +01:00
|
|
|
#ifdef CONFIG_NET_CELLULAR
|
|
|
|
# include <nuttx/wireless/cellular/cellular.h>
|
|
|
|
#endif
|
|
|
|
|
2023-06-08 03:17:27 +02:00
|
|
|
#ifdef CONFIG_NETDEV_MODEM_LTE_IOCTL
|
|
|
|
# include <nuttx/wireless/lte/lte_ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
2016-02-08 18:17:22 +01:00
|
|
|
#include "arp/arp.h"
|
2014-06-29 01:25:18 +02:00
|
|
|
#include "socket/socket.h"
|
2014-06-27 17:56:45 +02:00
|
|
|
#include "netdev/netdev.h"
|
2015-05-27 17:26:00 +02:00
|
|
|
#include "devif/devif.h"
|
2014-07-05 23:15:40 +02:00
|
|
|
#include "igmp/igmp.h"
|
2015-02-03 15:54:42 +01:00
|
|
|
#include "icmpv6/icmpv6.h"
|
2014-06-26 21:02:08 +02:00
|
|
|
#include "route/route.h"
|
2020-04-13 15:36:14 +02:00
|
|
|
#include "netlink/netlink.h"
|
2023-10-19 09:04:23 +02:00
|
|
|
#include "utils/utils.h"
|
2007-09-16 19:46:25 +02:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
2009-12-15 16:57:25 +01:00
|
|
|
* Pre-processor Definitions
|
2007-09-17 00:12:04 +02:00
|
|
|
****************************************************************************/
|
2018-10-29 23:25:57 +01:00
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
/* Configuration */
|
|
|
|
|
|
|
|
#undef HAVE_WRITABLE_IPv4ROUTE
|
|
|
|
#undef HAVE_WRITABLE_IPv6ROUTE
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ROUTE
|
|
|
|
# if defined(CONFIG_NET_IPv4) && !defined(CONFIG_ROUTE_IPv4_ROMROUTE)
|
|
|
|
# define HAVE_WRITABLE_IPv4ROUTE 1
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(CONFIG_NET_IPv6) && !defined(CONFIG_ROUTE_IPv6_ROMROUTE)
|
|
|
|
# define HAVE_WRITABLE_IPv6ROUTE 1
|
|
|
|
# endif
|
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#undef HAVE_IEEE802154_IOCTL
|
|
|
|
#undef HAVE_PKTRADIO_IOCTL
|
|
|
|
#undef HAVE_BLUETOOTH_IOCTL
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
/* IEEE 802.15.4 6LoWPAN or raw packet support */
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IEEE802154) || (defined(CONFIG_NET_6LOWPAN) && \
|
|
|
|
defined(CONFIG_WIRELESS_IEEE802154))
|
|
|
|
# define HAVE_IEEE802154_IOCTL 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* pktradio raw packet support not implemented */
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_WIRELESS_PKTRADIO)
|
|
|
|
# define HAVE_PKTRADIO_IOCTL 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Bluetooth 6LoWPAN support not implemented */
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_BLUETOOTH)
|
|
|
|
# define HAVE_BLUETOOTH_IOCTL 1
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_NETDEV_IOCTL */
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-16 19:30:18 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_add_ipv4route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add an IPv4 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be added
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_add_ipv4route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr;
|
|
|
|
in_addr_t target;
|
|
|
|
in_addr_t netmask;
|
|
|
|
in_addr_t router;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_dst;
|
2015-01-16 19:30:18 +01:00
|
|
|
target = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_gateway;
|
|
|
|
router = (in_addr_t)addr->sin_addr.s_addr;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2017-08-10 17:14:31 +02:00
|
|
|
return net_addroute_ipv4(target, netmask, router);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv4ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-07-08 19:58:19 +02:00
|
|
|
* Name: ioctl_add_ipv6route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add an IPv6 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be added
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-07-08 19:58:19 +02:00
|
|
|
static int ioctl_add_ipv6route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2015-05-13 15:22:02 +02:00
|
|
|
FAR struct sockaddr_in6 *target;
|
|
|
|
FAR struct sockaddr_in6 *netmask;
|
2019-11-10 19:35:15 +01:00
|
|
|
FAR struct sockaddr_in6 *gateway;
|
2015-01-16 19:30:18 +01:00
|
|
|
net_ipv6addr_t router;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
target = (FAR struct sockaddr_in6 *)&rtentry->rt_dst;
|
|
|
|
netmask = (FAR struct sockaddr_in6 *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/* The router is an optional argument */
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
gateway = (FAR struct sockaddr_in6 *)&rtentry->rt_gateway;
|
|
|
|
net_ipv6addr_copy(router, gateway->sin6_addr.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2019-10-25 19:31:42 +02:00
|
|
|
return net_addroute_ipv6(target->sin6_addr.s6_addr16,
|
|
|
|
netmask->sin6_addr.s6_addr16, router);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv6ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_del_ipv4route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Delete an IPv4 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be deleted
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_del_ipv4route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr;
|
|
|
|
in_addr_t target;
|
|
|
|
in_addr_t netmask;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_dst;
|
2015-01-16 19:30:18 +01:00
|
|
|
target = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2017-08-10 17:14:31 +02:00
|
|
|
return net_delroute_ipv4(target, netmask);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv4ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_del_ipv6route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Delete an IPv6 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be deleted
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_del_ipv6route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2015-05-13 15:22:02 +02:00
|
|
|
FAR struct sockaddr_in6 *target;
|
|
|
|
FAR struct sockaddr_in6 *netmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
target = (FAR struct sockaddr_in6 *)&rtentry->rt_dst;
|
|
|
|
netmask = (FAR struct sockaddr_in6 *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
return net_delroute_ipv6(target->sin6_addr.s6_addr16,
|
|
|
|
netmask->sin6_addr.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv6ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_get_ipv4addr
|
2007-09-17 00:12:04 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-06-08 03:53:26 +02:00
|
|
|
* Copy IP addresses from device structure to user memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the user-provided memory to receive the address.
|
2015-01-16 19:30:18 +01:00
|
|
|
* inaddr - The source IP address in the device structure.
|
2007-09-17 00:12:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_get_ipv4addr(FAR struct sockaddr *outaddr,
|
|
|
|
in_addr_t inaddr)
|
2007-09-17 00:12:04 +02:00
|
|
|
{
|
2012-06-08 03:53:26 +02:00
|
|
|
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
|
|
|
dest->sin_family = AF_INET;
|
|
|
|
dest->sin_port = 0;
|
2015-01-15 20:08:28 +01:00
|
|
|
dest->sin_addr.s_addr = inaddr;
|
2020-02-25 15:53:39 +01:00
|
|
|
memset(dest->sin_zero, 0, sizeof(dest->sin_zero));
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
#endif
|
2015-01-14 20:03:12 +01:00
|
|
|
|
2017-11-22 23:46:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ioctl_get_ipv4broadcast
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the sub-net broadcast address to user memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the user-provided memory to receive the address.
|
|
|
|
* inaddr - The source IP address in the device structure.
|
|
|
|
* netmask - The netmask address mask in the device structure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
2020-04-16 16:02:11 +02:00
|
|
|
static void ioctl_get_ipv4broadcast(FAR struct sockaddr *outaddr,
|
|
|
|
in_addr_t inaddr, in_addr_t netmask)
|
2017-11-22 23:46:46 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
|
|
|
dest->sin_family = AF_INET;
|
|
|
|
dest->sin_port = 0;
|
|
|
|
dest->sin_addr.s_addr = net_ipv4addr_broadcast(inaddr, netmask);
|
2020-02-25 15:53:39 +01:00
|
|
|
memset(dest->sin_zero, 0, sizeof(dest->sin_zero));
|
2017-11-22 23:46:46 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_get_ipv6addr
|
2015-01-14 20:03:12 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy IP addresses from device structure to user memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the user-provided memory to receive the address.
|
2020-02-22 19:31:14 +01:00
|
|
|
* inaddr - The source IP address in the device structure.
|
2015-01-14 20:03:12 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_get_ipv6addr(FAR struct sockaddr_storage *outaddr,
|
|
|
|
FAR const net_ipv6addr_t inaddr)
|
2015-01-14 20:03:12 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in6 *dest = (FAR struct sockaddr_in6 *)outaddr;
|
2015-01-21 01:14:09 +01:00
|
|
|
dest->sin6_family = AF_INET6;
|
|
|
|
dest->sin6_port = 0;
|
2015-01-14 20:03:12 +01:00
|
|
|
memcpy(dest->sin6_addr.in6_u.u6_addr8, inaddr, 16);
|
2007-09-17 00:12:04 +02:00
|
|
|
}
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2012-06-08 03:53:26 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_set_ipv4addr
|
2012-06-08 03:53:26 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy IP addresses from user memory into the device structure
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the source IP address in the device structure.
|
|
|
|
* inaddr - Pointer to the user-provided memory to containing the new IP
|
2015-01-14 20:03:12 +01:00
|
|
|
* address.
|
2012-06-08 03:53:26 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_set_ipv4addr(FAR in_addr_t *outaddr,
|
|
|
|
FAR const struct sockaddr *inaddr)
|
2007-09-17 00:12:04 +02:00
|
|
|
{
|
2012-06-08 03:53:26 +02:00
|
|
|
FAR const struct sockaddr_in *src = (FAR const struct sockaddr_in *)inaddr;
|
2007-09-17 00:12:04 +02:00
|
|
|
*outaddr = src->sin_addr.s_addr;
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
#endif
|
2015-01-14 20:03:12 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_set_ipv6addr
|
2015-01-14 20:03:12 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy IP addresses from user memory into the device structure
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the source IP address in the device structure.
|
2018-03-30 20:27:04 +02:00
|
|
|
* inaddr - Pointer to the user-provided memory to containing the new IP
|
2015-01-14 20:03:12 +01:00
|
|
|
* address.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_set_ipv6addr(FAR net_ipv6addr_t outaddr,
|
|
|
|
FAR const struct sockaddr_storage *inaddr)
|
2015-01-14 20:03:12 +01:00
|
|
|
{
|
2020-04-16 16:02:11 +02:00
|
|
|
FAR const struct sockaddr_in6 *src =
|
|
|
|
(FAR const struct sockaddr_in6 *)inaddr;
|
2015-01-14 20:03:12 +01:00
|
|
|
memcpy(outaddr, src->sin6_addr.in6_u.u6_addr8, 16);
|
2007-09-17 00:12:04 +02:00
|
|
|
}
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/****************************************************************************
|
2018-04-06 17:42:41 +02:00
|
|
|
* Name: netdev_bluetooth_ioctl
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform Bluetooth network device specific operations.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock - Socket structure
|
|
|
|
* dev - Ethernet driver device structure
|
|
|
|
* cmd - The ioctl command
|
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_BLUETOOTH_IOCTL
|
|
|
|
static int netdev_bluetooth_ioctl(FAR struct socket *psock, int cmd,
|
2018-03-31 22:55:03 +02:00
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *ifname;
|
2018-04-06 17:42:41 +02:00
|
|
|
int ret = -EINVAL;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
if (arg != 0ul)
|
|
|
|
{
|
2022-09-19 13:38:40 +02:00
|
|
|
if (_BLUETOOTHIOCVALID(cmd))
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
/* Get the name of the Bluetooth device to receive the IOCTL
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
FAR struct btreq_s *btreq =
|
|
|
|
(FAR struct btreq_s *)((uintptr_t)arg);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
ifname = btreq->btr_name;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not a Bluetooth IOCTL command */
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
2018-04-06 17:42:41 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
if (dev != NULL && dev->d_lltype == NET_LL_BLUETOOTH)
|
|
|
|
{
|
|
|
|
/* Perform the device IOCTL */
|
|
|
|
|
|
|
|
ret = dev->d_ioctl(dev, cmd, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-04-15 17:11:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_iee802154_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform IEEE802.15.4 network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-03-30 20:27:04 +02:00
|
|
|
* psock - Socket structure
|
|
|
|
* dev - Ethernet driver device structure
|
|
|
|
* cmd - The ioctl command
|
|
|
|
* req - The argument of the ioctl cmd
|
2017-04-15 17:11:52 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-04-15 17:11:52 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_IEEE802154_IOCTL
|
2017-04-15 17:11:52 +02:00
|
|
|
static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *ifname;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
if (arg != 0ul)
|
2017-04-15 17:11:52 +02:00
|
|
|
{
|
2017-05-05 17:15:28 +02:00
|
|
|
if (_MAC802154IOCVALID(cmd))
|
2017-04-15 17:11:52 +02:00
|
|
|
{
|
|
|
|
/* Get the IEEE802.15.4 MAC device to receive the radio IOCTL
|
2017-08-02 19:52:44 +02:00
|
|
|
* command
|
2017-04-15 17:11:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
FAR struct ieee802154_netmac_s *netmac =
|
|
|
|
(FAR struct ieee802154_netmac_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
ifname = netmac->ifr_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-02 19:52:44 +02:00
|
|
|
/* Not an EEE802.15.4 MAC IOCTL command */
|
2017-04-15 17:11:52 +02:00
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
2017-08-02 19:52:44 +02:00
|
|
|
if (dev != NULL && dev->d_lltype == NET_LL_IEEE802154)
|
|
|
|
{
|
|
|
|
/* Perform the device IOCTL */
|
|
|
|
|
|
|
|
ret = dev->d_ioctl(dev, cmd, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2018-04-06 17:42:41 +02:00
|
|
|
#endif /* HAVE_IEEE802154_IOCTL */
|
2017-08-02 19:52:44 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_pktradio_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
2020-04-16 16:02:11 +02:00
|
|
|
* Perform non-IEEE802.15.4 packet radio network device specific operation.
|
2017-08-02 19:52:44 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-03-30 20:27:04 +02:00
|
|
|
* psock - Socket structure
|
|
|
|
* dev - Ethernet driver device structure
|
|
|
|
* cmd - The ioctl command
|
|
|
|
* req - The argument of the ioctl cmd
|
2017-08-02 19:52:44 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-08-02 19:52:44 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_PKTRADIO_IOCTL
|
2017-08-02 19:52:44 +02:00
|
|
|
static int netdev_pktradio_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *ifname;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
if (arg != 0ul)
|
|
|
|
{
|
2022-09-19 13:38:40 +02:00
|
|
|
if (_PKRADIOIOCVALID(cmd))
|
2017-08-02 19:52:44 +02:00
|
|
|
{
|
|
|
|
/* Get the packet radio device to receive the radio IOCTL
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
|
|
|
|
FAR struct pktradio_ifreq_s *cmddata =
|
|
|
|
(FAR struct pktradio_ifreq_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
ifname = cmddata->pifr_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not a packet radio IOCTL command */
|
|
|
|
|
2017-08-02 22:28:17 +02:00
|
|
|
nwarn("WARNING: Not a packet radio IOCTL command: %d\n", cmd);
|
2017-08-02 19:52:44 +02:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
|
|
|
if (dev != NULL && dev->d_lltype == NET_LL_PKTRADIO)
|
2017-04-15 18:23:29 +02:00
|
|
|
{
|
|
|
|
/* Perform the device IOCTL */
|
2017-04-15 17:11:52 +02:00
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
ret = dev->d_ioctl(dev, cmd, arg);
|
|
|
|
}
|
2017-04-15 17:11:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2018-04-06 17:42:41 +02:00
|
|
|
#endif /* HAVE_PKTRADIO_IOCTL */
|
2017-04-15 17:11:52 +02:00
|
|
|
|
2022-12-07 10:38:11 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_cell_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform cell ioctl operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* arg The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_CELLULAR)
|
|
|
|
static int netdev_cell_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct icellreq *req)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev = NULL;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
ninfo("cmd: %d\n", cmd);
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
if (_CELLIOCVALID(cmd))
|
|
|
|
{
|
|
|
|
dev = netdev_findbyname(req->ifr_name);
|
|
|
|
if (dev && dev->d_ioctl)
|
|
|
|
{
|
|
|
|
ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_wifr_ioctl
|
2017-03-13 16:51:31 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform wireless network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-03-13 16:51:31 +01:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-03-13 16:51:31 +01:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-13 17:14:38 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL)
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_wifr_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct iwreq *req)
|
2017-03-13 16:51:31 +01:00
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
/* Verify that this is a valid wireless network IOCTL command */
|
|
|
|
|
2022-09-19 13:38:40 +02:00
|
|
|
if (_WLIOCVALID(cmd))
|
2017-03-13 16:51:31 +01:00
|
|
|
{
|
|
|
|
/* Get the wireless device associated with the IOCTL command */
|
|
|
|
|
2017-04-26 20:31:13 +02:00
|
|
|
dev = netdev_findbyname(req->ifr_name);
|
2023-11-01 16:09:37 +01:00
|
|
|
if (cmd == SIOCGIWNAME)
|
|
|
|
{
|
|
|
|
if (dev == NULL)
|
|
|
|
{
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy((FAR char *)&req->u, "IEEE 802.11");
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev != NULL && ret == -ENOTTY)
|
2017-03-13 16:51:31 +01:00
|
|
|
{
|
2017-03-13 17:14:38 +01:00
|
|
|
/* Just forward the IOCTL to the wireless driver */
|
2017-03-13 16:51:31 +01:00
|
|
|
|
2020-04-16 16:02:11 +02:00
|
|
|
ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)req);
|
2017-03-13 16:51:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-16 19:46:25 +02:00
|
|
|
/****************************************************************************
|
2023-10-20 11:08:10 +02:00
|
|
|
* Name: netdev_ifr_split_idx
|
2013-10-06 00:43:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2023-10-20 11:08:10 +02:00
|
|
|
* Split the address index from device name like 'eth0:0'.
|
2013-10-06 00:43:10 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-06 00:43:10 +02:00
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2023-10-20 11:08:10 +02:00
|
|
|
* The address index from device name.
|
2013-10-06 00:43:10 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
static unsigned int netdev_ifr_split_idx(FAR struct ifreq *req)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
2023-10-20 11:08:10 +02:00
|
|
|
FAR char *colon = strchr(req->ifr_name, ':');
|
|
|
|
int idx;
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
if (colon)
|
|
|
|
{
|
|
|
|
*colon++ = '\0'; /* Remove suffix from device name */
|
|
|
|
idx = atoi(colon);
|
|
|
|
return idx >= 0 ? idx + 1 : 0; /* eth0:0 represents the second addr */
|
2017-03-13 16:51:31 +01:00
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
return 0;
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: net_ioctl_ifreq_arglen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Calculate the ioctl argument buffer length of ifreq.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2023-10-20 11:08:10 +02:00
|
|
|
* domain The socket domain
|
2022-09-07 04:56:09 +02:00
|
|
|
* cmd The ioctl command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The argument buffer length, or error code.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
static ssize_t net_ioctl_ifreq_arglen(uint8_t domain, int cmd)
|
2022-09-07 04:56:09 +02:00
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
case SIOCGIFDSTADDR:
|
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
case SIOCSIFBRDADDR:
|
|
|
|
case SIOCGIFNETMASK:
|
|
|
|
case SIOCSIFNETMASK:
|
2022-12-07 10:22:02 +01:00
|
|
|
case SIOCSIFMTU:
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGIFMTU:
|
|
|
|
case SIOCGIFHWADDR:
|
|
|
|
case SIOCSIFHWADDR:
|
|
|
|
case SIOCGIFCOUNT:
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
case SIOCGIFFLAGS:
|
|
|
|
case SIOCMIINOTIFY:
|
|
|
|
case SIOCGMIIPHY:
|
|
|
|
case SIOCGMIIREG:
|
|
|
|
case SIOCSMIIREG:
|
|
|
|
case SIOCGCANBITRATE:
|
|
|
|
case SIOCSCANBITRATE:
|
|
|
|
case SIOCACANEXTFILTER:
|
|
|
|
case SIOCDCANEXTFILTER:
|
|
|
|
case SIOCACANSTDFILTER:
|
|
|
|
case SIOCDCANSTDFILTER:
|
2023-08-11 05:14:13 +02:00
|
|
|
case SIOCCANRECOVERY:
|
2022-12-07 10:22:02 +01:00
|
|
|
case SIOCSIFNAME:
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGIFNAME:
|
|
|
|
case SIOCGIFINDEX:
|
|
|
|
return sizeof(struct ifreq);
|
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCDIFADDR:
|
|
|
|
return domain == PF_INET6 ?
|
|
|
|
sizeof(struct in6_ifreq) : sizeof(struct ifreq);
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGLIFADDR:
|
|
|
|
case SIOCSLIFADDR:
|
|
|
|
case SIOCGLIFDSTADDR:
|
|
|
|
case SIOCSLIFDSTADDR:
|
|
|
|
case SIOCGLIFBRDADDR:
|
|
|
|
case SIOCSLIFBRDADDR:
|
|
|
|
case SIOCGLIFNETMASK:
|
|
|
|
case SIOCSLIFNETMASK:
|
|
|
|
case SIOCGLIFMTU:
|
|
|
|
case SIOCIFAUTOCONF:
|
|
|
|
return sizeof(struct lifreq);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
2013-10-06 00:43:10 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_ifr_ioctl
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2010-07-11 20:10:22 +02:00
|
|
|
* psock Socket structure
|
2007-09-16 19:46:25 +02:00
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-09-16 19:46:25 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
2010-07-11 20:10:22 +02:00
|
|
|
* Negated errno returned on failure.
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct ifreq *req)
|
2007-09-16 19:46:25 +02:00
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct net_driver_s *dev = NULL;
|
2023-10-20 11:08:10 +02:00
|
|
|
unsigned int idx = 0;
|
2022-09-07 04:56:09 +02:00
|
|
|
int ret = OK;
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("cmd: %d\n", cmd);
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2022-08-25 01:00:26 +02:00
|
|
|
net_lock();
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
/* Execute commands that do not need ifr_name or lifr_name */
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGIFCOUNT: /* Get number of devices */
|
|
|
|
req->ifr_count = netdev_count();
|
|
|
|
break;
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGIFCONF: /* Return an interface list (IPv4) */
|
|
|
|
ret = netdev_ipv4_ifconf((FAR struct ifconf *)req);
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCGLIFCONF: /* Return an interface list (IPv6) */
|
|
|
|
ret = netdev_ipv6_ifconf((FAR struct lifconf *)req);
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
#ifdef CONFIG_NETDEV_IFINDEX
|
2022-12-07 10:22:02 +01:00
|
|
|
case SIOCSIFNAME: /* Set interface name */
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *tmpdev;
|
|
|
|
tmpdev = netdev_findbyindex(req->ifr_ifindex);
|
|
|
|
if (tmpdev != NULL)
|
|
|
|
{
|
|
|
|
strlcpy(tmpdev->d_ifname, req->ifr_name, IFNAMSIZ);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGIFNAME: /* Get interface name */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct net_driver_s *tmpdev;
|
|
|
|
tmpdev = netdev_findbyindex(req->ifr_ifindex);
|
|
|
|
if (tmpdev != NULL)
|
|
|
|
{
|
|
|
|
strlcpy(req->ifr_name, tmpdev->d_ifname, IFNAMSIZ);
|
|
|
|
}
|
|
|
|
else
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = -ENODEV;
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2022-09-07 04:56:09 +02:00
|
|
|
default:
|
2023-10-20 11:08:10 +02:00
|
|
|
if (req == NULL)
|
2022-09-07 04:56:09 +02:00
|
|
|
{
|
2023-10-20 11:08:10 +02:00
|
|
|
net_unlock();
|
|
|
|
return -ENOTTY;
|
2022-09-07 04:56:09 +02:00
|
|
|
}
|
2023-10-20 11:08:10 +02:00
|
|
|
|
|
|
|
if (net_ioctl_ifreq_arglen(psock->s_domain, cmd)
|
|
|
|
>= (ssize_t)sizeof(struct ifreq))
|
|
|
|
{
|
|
|
|
idx = netdev_ifr_split_idx(req);
|
|
|
|
UNUSED(idx);
|
|
|
|
dev = netdev_findbyname(req->ifr_name);
|
|
|
|
}
|
|
|
|
else if (net_ioctl_ifreq_arglen(psock->s_domain, cmd)
|
|
|
|
== (ssize_t)sizeof(struct in6_ifreq))
|
|
|
|
{
|
|
|
|
FAR struct in6_ifreq *ifr6 = (FAR struct in6_ifreq *)req;
|
|
|
|
dev = netdev_findbyindex(ifr6->ifr6_ifindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev == NULL)
|
2022-09-07 04:56:09 +02:00
|
|
|
{
|
|
|
|
ret = -ENOTTY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev == NULL)
|
|
|
|
{
|
2022-09-08 07:39:36 +02:00
|
|
|
net_unlock();
|
2022-09-07 04:56:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute commands that need ifr_name or lifr_name */
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2022-09-07 04:56:09 +02:00
|
|
|
case SIOCGIFADDR: /* Get IP address */
|
|
|
|
ioctl_get_ipv4addr(&req->ifr_addr, dev->d_ipaddr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFDSTADDR: /* Get P-to-P address */
|
|
|
|
ioctl_get_ipv4addr(&req->ifr_dstaddr, dev->d_draddr);
|
|
|
|
break;
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCSIFDSTADDR: /* Set P-to-P address */
|
2022-09-07 04:56:09 +02:00
|
|
|
ioctl_set_ipv4addr(&dev->d_draddr, &req->ifr_dstaddr);
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
|
|
|
|
case SIOCGIFBRDADDR: /* Get broadcast IP address */
|
2022-09-07 04:56:09 +02:00
|
|
|
ioctl_get_ipv4broadcast(&req->ifr_broadaddr, dev->d_ipaddr,
|
|
|
|
dev->d_netmask);
|
2017-11-22 23:46:46 +01:00
|
|
|
break;
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
case SIOCSIFBRDADDR: /* Set broadcast IP address */
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = -ENOSYS;
|
2015-01-14 20:03:12 +01:00
|
|
|
break;
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
case SIOCGIFNETMASK: /* Get network mask */
|
2022-09-07 04:56:09 +02:00
|
|
|
ioctl_get_ipv4addr(&req->ifr_addr, dev->d_netmask);
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFNETMASK: /* Set network mask */
|
2022-09-07 04:56:09 +02:00
|
|
|
ioctl_set_ipv4addr(&dev->d_netmask, &req->ifr_addr);
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCGLIFADDR: /* Get IP address */
|
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
2023-10-20 11:08:10 +02:00
|
|
|
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
|
|
|
ioctl_get_ipv6addr(&lreq->lifr_addr, dev->d_ipv6[idx].addr);
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSLIFADDR: /* Set IP address */
|
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
2023-10-20 11:08:10 +02:00
|
|
|
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
2023-12-13 05:39:43 +01:00
|
|
|
|
|
|
|
netdev_ipv6_removemcastmac(dev, dev->d_ipv6[idx].addr);
|
2023-10-20 11:08:10 +02:00
|
|
|
ioctl_set_ipv6addr(dev->d_ipv6[idx].addr, &lreq->lifr_addr);
|
2023-12-13 05:39:43 +01:00
|
|
|
netdev_ipv6_addmcastmac(dev, dev->d_ipv6[idx].addr);
|
|
|
|
|
2023-10-19 09:04:23 +02:00
|
|
|
netlink_device_notify_ipaddr(dev, RTM_NEWADDR, AF_INET6,
|
2023-10-20 11:08:10 +02:00
|
|
|
dev->d_ipv6[idx].addr, net_ipv6_mask2pref(dev->d_ipv6[idx].mask));
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGLIFDSTADDR: /* Get P-to-P address */
|
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
ioctl_get_ipv6addr(&lreq->lifr_dstaddr, dev->d_ipv6draddr);
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSLIFDSTADDR: /* Set P-to-P address */
|
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
ioctl_set_ipv6addr(dev->d_ipv6draddr, &lreq->lifr_dstaddr);
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGLIFBRDADDR: /* Get broadcast IP address */
|
|
|
|
case SIOCSLIFBRDADDR: /* Set broadcast IP address */
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = -ENOSYS;
|
2015-01-14 20:03:12 +01:00
|
|
|
break;
|
|
|
|
|
2015-01-18 16:23:22 +01:00
|
|
|
case SIOCGLIFNETMASK: /* Get network mask */
|
2015-01-14 20:03:12 +01:00
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
2023-10-20 11:08:10 +02:00
|
|
|
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
|
|
|
ioctl_get_ipv6addr(&lreq->lifr_addr, dev->d_ipv6[idx].mask);
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSLIFNETMASK: /* Set network mask */
|
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
2023-10-20 11:08:10 +02:00
|
|
|
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
|
|
|
ioctl_set_ipv6addr(dev->d_ipv6[idx].mask, &lreq->lifr_addr);
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case SIOCGLIFMTU: /* Get MTU size */
|
|
|
|
case SIOCGIFMTU: /* Get MTU size */
|
2023-04-27 04:17:53 +02:00
|
|
|
req->ifr_mtu = NETDEV_PKTSIZE(dev) - dev->d_llhdrlen;
|
2012-11-04 19:54:04 +01:00
|
|
|
break;
|
2022-12-07 10:22:02 +01:00
|
|
|
case SIOCSIFMTU: /* Set MTU size */
|
2023-08-07 04:07:53 +02:00
|
|
|
NETDEV_PKTSIZE(dev) = req->ifr_mtu + dev->d_llhdrlen;
|
2022-12-07 10:22:02 +01:00
|
|
|
break;
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2015-02-03 15:54:42 +01:00
|
|
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
|
|
|
case SIOCIFAUTOCONF: /* Perform ICMPv6 auto-configuration */
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = icmpv6_autoconfig(dev);
|
2015-02-03 15:54:42 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-11-04 19:54:04 +01:00
|
|
|
case SIOCSIFFLAGS: /* Sets the interface flags */
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
/* Is this a request to bring the interface up? */
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
if ((req->ifr_flags & IFF_UP) != 0)
|
|
|
|
{
|
|
|
|
/* Yes.. bring the interface up */
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = netdev_ifup(dev);
|
2024-01-22 03:20:46 +01:00
|
|
|
#ifdef CONFIG_NET_ARP_ACD
|
|
|
|
/* having address then start acd */
|
|
|
|
|
|
|
|
arp_acd_setup(dev);
|
|
|
|
#endif /* CONFIG_NET_ARP_ACD */
|
2022-09-07 04:56:09 +02:00
|
|
|
}
|
2024-10-06 09:15:56 +02:00
|
|
|
else
|
2022-09-07 04:56:09 +02:00
|
|
|
{
|
|
|
|
/* Yes.. take the interface down */
|
|
|
|
|
|
|
|
ret = netdev_ifdown(dev);
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFFLAGS: /* Gets the interface flags */
|
2022-09-07 04:56:09 +02:00
|
|
|
req->ifr_flags = dev->d_flags;
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
|
|
|
|
2017-06-19 00:00:08 +02:00
|
|
|
/* MAC address operations only make sense if Ethernet or 6LoWPAN are
|
2017-04-22 02:31:05 +02:00
|
|
|
* supported.
|
|
|
|
*/
|
2011-03-12 16:36:28 +01:00
|
|
|
|
2017-04-06 23:58:00 +02:00
|
|
|
#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN)
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCGIFHWADDR: /* Get hardware address */
|
2017-04-06 23:58:00 +02:00
|
|
|
#ifdef CONFIG_NET_ETHERNET
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_lltype == NET_LL_ETHERNET ||
|
|
|
|
dev->d_lltype == NET_LL_IEEE80211)
|
|
|
|
{
|
2022-09-15 16:36:47 +02:00
|
|
|
req->ifr_hwaddr.sa_family = ARPHRD_ETHER;
|
2022-09-07 04:56:09 +02:00
|
|
|
memcpy(req->ifr_hwaddr.sa_data,
|
|
|
|
dev->d_mac.ether.ether_addr_octet, IFHWADDRLEN);
|
|
|
|
}
|
|
|
|
else
|
2017-04-06 23:58:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
|
|
|
dev->d_lltype == NET_LL_PKTRADIO)
|
|
|
|
{
|
2022-09-15 16:36:47 +02:00
|
|
|
req->ifr_hwaddr.sa_family = ARPHRD_IEEE802154;
|
2022-09-07 04:56:09 +02:00
|
|
|
memcpy(req->ifr_hwaddr.sa_data,
|
|
|
|
dev->d_mac.radio.nv_addr,
|
|
|
|
dev->d_mac.radio.nv_addrlen);
|
|
|
|
}
|
|
|
|
else
|
2017-04-06 23:58:00 +02:00
|
|
|
#endif
|
2022-09-07 04:56:09 +02:00
|
|
|
{
|
2024-03-28 04:57:06 +01:00
|
|
|
nwarn("WARNING: Unsupported link layer\n");
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = -EAFNOSUPPORT;
|
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-12 03:18:34 +01:00
|
|
|
case SIOCSIFHWADDR: /* Set hardware address -- will not take effect until ifup */
|
2017-04-06 23:58:00 +02:00
|
|
|
#ifdef CONFIG_NET_ETHERNET
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_lltype == NET_LL_ETHERNET ||
|
|
|
|
dev->d_lltype == NET_LL_IEEE80211)
|
|
|
|
{
|
|
|
|
memcpy(dev->d_mac.ether.ether_addr_octet,
|
|
|
|
req->ifr_hwaddr.sa_data, IFHWADDRLEN);
|
|
|
|
}
|
|
|
|
else
|
2017-04-06 23:58:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
|
|
|
dev->d_lltype == NET_LL_PKTRADIO)
|
|
|
|
{
|
|
|
|
FAR struct radio_driver_s *radio;
|
|
|
|
struct radiodev_properties_s properties;
|
|
|
|
|
|
|
|
/* Get the radio properties */
|
|
|
|
|
|
|
|
radio = (FAR struct radio_driver_s *)dev;
|
|
|
|
DEBUGASSERT(radio->r_properties != NULL);
|
|
|
|
|
|
|
|
ret = radio->r_properties(radio, &properties);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
dev->d_mac.radio.nv_addrlen = properties.sp_addrlen;
|
2022-09-15 16:57:51 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(dev->d_mac.radio.nv_addrlen <=
|
|
|
|
sizeof(dev->d_mac.radio.nv_addr));
|
|
|
|
DEBUGASSERT(dev->d_mac.radio.nv_addrlen <=
|
|
|
|
sizeof(req->ifr_hwaddr.sa_data));
|
|
|
|
|
2022-09-07 04:56:09 +02:00
|
|
|
memcpy(dev->d_mac.radio.nv_addr,
|
2022-09-15 16:57:51 +02:00
|
|
|
req->ifr_hwaddr.sa_data, dev->d_mac.radio.nv_addrlen);
|
2022-09-07 04:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-04-06 23:58:00 +02:00
|
|
|
#endif
|
2022-09-07 04:56:09 +02:00
|
|
|
{
|
|
|
|
nerr("Unsupported link layer\n");
|
|
|
|
ret = -EAFNOSUPPORT;
|
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2011-03-12 16:36:28 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
case SIOCSIFADDR: /* Set IP address */
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
if (psock->s_domain != PF_INET6)
|
|
|
|
{
|
2024-01-22 03:20:46 +01:00
|
|
|
if (net_ipv4addr_cmp(dev->d_ipaddr,
|
|
|
|
((FAR struct sockaddr_in *)&req->ifr_addr)->sin_addr.s_addr))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
ioctl_set_ipv4addr(&dev->d_ipaddr, &req->ifr_addr);
|
|
|
|
netlink_device_notify_ipaddr(dev, RTM_NEWADDR, AF_INET,
|
|
|
|
&dev->d_ipaddr, net_ipv4_mask2pref(dev->d_netmask));
|
2024-01-22 03:20:46 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ARP_ACD
|
|
|
|
arp_acd_set_addr(dev);
|
|
|
|
#endif /* CONFIG_NET_ARP_ACD */
|
2023-10-20 11:08:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (psock->s_domain == PF_INET6)
|
|
|
|
{
|
|
|
|
FAR struct in6_ifreq *ifr6 = (FAR struct in6_ifreq *)req;
|
|
|
|
ret = netdev_ipv6_add(dev, ifr6->ifr6_addr.in6_u.u6_addr16,
|
|
|
|
ifr6->ifr6_prefixlen);
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
netlink_device_notify_ipaddr(dev, RTM_NEWADDR, AF_INET6,
|
|
|
|
ifr6->ifr6_addr.in6_u.u6_addr16, ifr6->ifr6_prefixlen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCDIFADDR: /* Delete IP address */
|
2015-01-15 20:08:28 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2023-10-20 11:08:10 +02:00
|
|
|
if (psock->s_domain != PF_INET6)
|
|
|
|
{
|
|
|
|
netlink_device_notify_ipaddr(dev, RTM_DELADDR, AF_INET,
|
2023-10-19 09:04:23 +02:00
|
|
|
&dev->d_ipaddr, net_ipv4_mask2pref(dev->d_netmask));
|
2023-10-20 11:08:10 +02:00
|
|
|
dev->d_ipaddr = 0;
|
|
|
|
}
|
2015-01-15 20:08:28 +01:00
|
|
|
#endif
|
2023-10-20 11:08:10 +02:00
|
|
|
|
2015-01-15 20:08:28 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2023-10-20 11:08:10 +02:00
|
|
|
if (psock->s_domain == PF_INET6)
|
|
|
|
{
|
|
|
|
FAR struct in6_ifreq *ifr6 = (FAR struct in6_ifreq *)req;
|
|
|
|
ret = netdev_ipv6_del(dev, ifr6->ifr6_addr.in6_u.u6_addr16,
|
|
|
|
ifr6->ifr6_prefixlen);
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
netlink_device_notify_ipaddr(dev, RTM_DELADDR, AF_INET6,
|
|
|
|
ifr6->ifr6_addr.in6_u.u6_addr16, ifr6->ifr6_prefixlen);
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 20:08:28 +01:00
|
|
|
#endif
|
2010-07-11 20:10:22 +02:00
|
|
|
break;
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_PHY_IOCTL)
|
2014-08-16 23:04:09 +02:00
|
|
|
#ifdef CONFIG_ARCH_PHY_INTERRUPT
|
|
|
|
case SIOCMIINOTIFY: /* Set up for PHY event notifications */
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_ioctl)
|
|
|
|
{
|
2022-07-28 09:46:49 +02:00
|
|
|
FAR struct mii_ioctl_notify_s *notify =
|
2022-09-07 04:56:09 +02:00
|
|
|
&req->ifr_ifru.ifru_mii_notify;
|
|
|
|
ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)notify);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
2014-08-16 23:04:09 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2014-06-27 17:30:41 +02:00
|
|
|
case SIOCGMIIPHY: /* Get address of MII PHY in use */
|
|
|
|
case SIOCGMIIREG: /* Get MII register via MDIO */
|
|
|
|
case SIOCSMIIREG: /* Set MII register via MDIO */
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_ioctl)
|
|
|
|
{
|
2022-07-28 09:46:49 +02:00
|
|
|
FAR struct mii_ioctl_data_s *mii_data =
|
2022-09-07 04:56:09 +02:00
|
|
|
&req->ifr_ifru.ifru_mii_data;
|
|
|
|
ret = dev->d_ioctl(dev, cmd,
|
|
|
|
(unsigned long)(uintptr_t)mii_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
2014-06-27 17:30:41 +02:00
|
|
|
break;
|
2020-10-24 03:40:33 +02:00
|
|
|
#endif
|
2020-06-15 10:23:25 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_CAN_BITRATE_IOCTL)
|
|
|
|
case SIOCGCANBITRATE: /* Get bitrate from a CAN controller */
|
|
|
|
case SIOCSCANBITRATE: /* Set bitrate of a CAN controller */
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_ioctl)
|
|
|
|
{
|
2022-07-28 09:46:49 +02:00
|
|
|
FAR struct can_ioctl_data_s *can_bitrate_data =
|
2022-09-07 04:56:09 +02:00
|
|
|
&req->ifr_ifru.ifru_can_data;
|
|
|
|
ret = dev->d_ioctl(dev, cmd,
|
|
|
|
(unsigned long)(uintptr_t)can_bitrate_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
2020-06-15 10:23:25 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2022-04-15 23:40:00 +02:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_CAN_FILTER_IOCTL)
|
|
|
|
case SIOCACANEXTFILTER: /* Add an extended-ID filter */
|
|
|
|
case SIOCDCANEXTFILTER: /* Delete an extended-ID filter */
|
|
|
|
case SIOCACANSTDFILTER: /* Add a standard-ID filter */
|
|
|
|
case SIOCDCANSTDFILTER: /* Delete a standard-ID filter */
|
2023-08-11 05:14:13 +02:00
|
|
|
case SIOCCANRECOVERY: /* Recovery can controller when bus-off */
|
2022-09-07 04:56:09 +02:00
|
|
|
if (dev->d_ioctl)
|
|
|
|
{
|
2022-07-28 09:46:49 +02:00
|
|
|
FAR struct can_ioctl_filter_s *can_filter =
|
2022-09-07 04:56:09 +02:00
|
|
|
&req->ifr_ifru.ifru_can_filter;
|
|
|
|
ret = dev->d_ioctl(dev, cmd,
|
|
|
|
(unsigned long)(uintptr_t)can_filter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
2022-04-15 23:40:00 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2020-06-15 10:23:25 +02:00
|
|
|
#ifdef CONFIG_NETDEV_IFINDEX
|
|
|
|
case SIOCGIFINDEX: /* Index to name mapping */
|
2022-09-07 04:56:09 +02:00
|
|
|
req->ifr_ifindex = dev->d_ifindex;
|
2020-06-15 10:23:25 +02:00
|
|
|
break;
|
2014-06-27 17:30:41 +02:00
|
|
|
#endif
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
default:
|
2022-09-07 04:56:09 +02:00
|
|
|
ret = -ENOTTY;
|
2015-10-08 23:10:04 +02:00
|
|
|
break;
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:00:26 +02:00
|
|
|
net_unlock();
|
2010-07-11 20:10:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-06 00:43:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_imsfdev
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Verify the struct ip_msfilter and get the Ethernet device.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-06 00:43:10 +02:00
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-10-06 00:43:10 +02:00
|
|
|
* A pointer to the driver structure on success; NULL on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2014-06-28 00:48:12 +02:00
|
|
|
static FAR struct net_driver_s *netdev_imsfdev(FAR struct ip_msfilter *imsf)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
2018-10-29 13:50:47 +01:00
|
|
|
if (imsf == NULL)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-29 13:50:47 +01:00
|
|
|
/* Find the network device associated with the address of the IP address
|
|
|
|
* of the local device.
|
2013-10-06 00:43:10 +02:00
|
|
|
*/
|
|
|
|
|
2018-10-29 19:20:44 +01:00
|
|
|
return netdev_findby_lipv4addr(imsf->imsf_interface.s_addr);
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_imsf_ioctl
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2010-07-11 20:10:22 +02:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
2014-03-24 16:34:17 +01:00
|
|
|
* imsf The argument of the ioctl cmd
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2010-07-11 20:10:22 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct ip_msfilter *imsf)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2014-06-28 00:48:12 +02:00
|
|
|
FAR struct net_driver_s *dev;
|
2013-10-06 00:43:10 +02:00
|
|
|
int ret = -EINVAL;
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("cmd: %d\n", cmd);
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2023-11-01 12:57:27 +01:00
|
|
|
net_lock();
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCSIPMSFILTER: /* Set source filter content */
|
|
|
|
{
|
2014-03-24 16:34:17 +01:00
|
|
|
dev = netdev_imsfdev(imsf);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2013-10-06 00:43:10 +02:00
|
|
|
if (imsf->imsf_fmode == MCAST_INCLUDE)
|
|
|
|
{
|
|
|
|
ret = igmp_joingroup(dev, &imsf->imsf_multiaddr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUGASSERT(imsf->imsf_fmode == MCAST_EXCLUDE);
|
|
|
|
ret = igmp_leavegroup(dev, &imsf->imsf_multiaddr);
|
|
|
|
}
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIPMSFILTER: /* Retrieve source filter addresses */
|
|
|
|
default:
|
2013-10-02 18:51:48 +02:00
|
|
|
ret = -ENOTTY;
|
2010-07-11 20:10:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-11-01 12:57:27 +01:00
|
|
|
net_unlock();
|
2010-07-11 20:10:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-03-06 10:30:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ioctl_arpreq_parse
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Parse arpreq into netdev and sockaddr.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
* dev The pointer to get ethernet driver device structure
|
|
|
|
* addr The pointer to get address in the request
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* true on success and false on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
static bool ioctl_arpreq_parse(FAR struct arpreq *req,
|
|
|
|
FAR struct net_driver_s **dev,
|
|
|
|
FAR struct sockaddr_in **addr)
|
|
|
|
{
|
|
|
|
if (req != NULL)
|
|
|
|
{
|
|
|
|
*addr = (FAR struct sockaddr_in *)&req->arp_pa;
|
|
|
|
*dev = req->arp_dev[0] != '\0' ?
|
|
|
|
netdev_findbyname((FAR const char *)req->arp_dev) :
|
|
|
|
netdev_findby_ripv4addr(INADDR_ANY, (*addr)->sin_addr.s_addr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-08 18:17:22 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_arp_ioctl
|
2016-02-08 18:17:22 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform ARP table specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-02-08 18:17:22 +01:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2016-02-08 18:17:22 +01:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ARP
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct arpreq *req)
|
2016-02-08 18:17:22 +01:00
|
|
|
{
|
2023-03-06 10:30:25 +01:00
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR struct sockaddr_in *addr;
|
2016-02-08 18:17:22 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCSARP: /* Set an ARP mapping */
|
|
|
|
{
|
2023-03-06 10:30:25 +01:00
|
|
|
if (ioctl_arpreq_parse(req, &dev, &addr) && dev != NULL &&
|
2017-05-04 16:20:59 +02:00
|
|
|
req->arp_pa.sa_family == AF_INET &&
|
2016-02-08 18:17:22 +01:00
|
|
|
req->arp_ha.sa_family == ARPHRD_ETHER)
|
|
|
|
{
|
|
|
|
/* Update any existing ARP table entry for this protocol
|
|
|
|
* address -OR- add a new ARP table entry if there is not.
|
|
|
|
*/
|
|
|
|
|
2022-12-06 03:40:18 +01:00
|
|
|
ret = arp_update(dev, addr->sin_addr.s_addr,
|
|
|
|
(FAR const uint8_t *)req->arp_ha.sa_data);
|
2016-02-08 18:17:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCDARP: /* Delete an ARP mapping */
|
|
|
|
{
|
2023-03-06 10:30:25 +01:00
|
|
|
if (ioctl_arpreq_parse(req, &dev, &addr) && dev != NULL &&
|
|
|
|
req->arp_pa.sa_family == AF_INET)
|
2016-02-08 18:17:22 +01:00
|
|
|
{
|
2022-12-06 03:40:18 +01:00
|
|
|
/* Delete the ARP entry for this protocol address. */
|
2016-02-08 18:17:22 +01:00
|
|
|
|
2022-12-06 03:40:18 +01:00
|
|
|
ret = arp_delete(addr->sin_addr.s_addr, dev);
|
2016-02-08 18:17:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGARP: /* Get an ARP mapping */
|
|
|
|
{
|
2023-03-06 10:30:25 +01:00
|
|
|
if (ioctl_arpreq_parse(req, &dev, &addr) &&
|
|
|
|
req->arp_pa.sa_family == AF_INET)
|
2016-02-08 18:17:22 +01:00
|
|
|
{
|
2018-08-25 14:47:10 +02:00
|
|
|
ret = arp_find(addr->sin_addr.s_addr,
|
2022-12-06 03:40:18 +01:00
|
|
|
(FAR uint8_t *)req->arp_ha.sa_data, dev);
|
2018-08-25 01:36:08 +02:00
|
|
|
if (ret >= 0)
|
2016-02-08 18:17:22 +01:00
|
|
|
{
|
|
|
|
/* Return the mapped hardware address. */
|
|
|
|
|
|
|
|
req->arp_ha.sa_family = ARPHRD_ETHER;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_rt_ioctl
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform routing table specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-02 18:51:48 +02:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* rtentry The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-10-02 18:51:48 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_rt_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct rtentry *rtentry)
|
2013-10-02 18:51:48 +02:00
|
|
|
{
|
2015-01-18 17:33:27 +01:00
|
|
|
int ret = -EAFNOSUPPORT;
|
2013-10-02 18:51:48 +02:00
|
|
|
|
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCADDRT: /* Add an entry to the routing table */
|
|
|
|
{
|
2015-01-16 19:30:18 +01:00
|
|
|
/* The target address and the netmask are required values */
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry == NULL)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2015-01-18 17:33:27 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry->rt_dst.ss_family == AF_INET)
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_add_ipv4route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-02-06 20:34:19 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-16 19:30:18 +01:00
|
|
|
else
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-07-08 19:58:19 +02:00
|
|
|
ret = ioctl_add_ipv6route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-02-06 20:34:19 +01:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2013-10-02 18:51:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCDELRT: /* Delete an entry from the routing table */
|
|
|
|
{
|
2015-01-16 19:30:18 +01:00
|
|
|
/* The target address and the netmask are required values */
|
2013-10-02 18:51:48 +02:00
|
|
|
|
2023-05-30 07:28:05 +02:00
|
|
|
if (rtentry == NULL)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-10-02 18:51:48 +02:00
|
|
|
|
2015-01-18 17:33:27 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry->rt_dst.ss_family == AF_INET)
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_del_ipv4route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-02-06 20:34:19 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-16 19:30:18 +01:00
|
|
|
else
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_del_ipv6route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-02-06 20:34:19 +01:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2013-10-02 18:51:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-03-04 09:13:17 +01:00
|
|
|
/****************************************************************************
|
2023-03-06 21:22:31 +01:00
|
|
|
* Name: netdev_ioctl
|
2022-03-04 09:13:17 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2023-03-06 21:22:31 +01:00
|
|
|
* Perform user private ioctl operations.
|
2022-03-04 09:13:17 +01:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* arg The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-03-06 21:22:31 +01:00
|
|
|
static int netdev_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
unsigned long arg)
|
2022-03-04 09:13:17 +01:00
|
|
|
{
|
2023-03-06 21:22:31 +01:00
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
if (psock->s_sockif && psock->s_sockif->si_ioctl)
|
|
|
|
{
|
|
|
|
ret = psock->s_sockif->si_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != OK && ret != -ENOTTY)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2022-03-04 09:13:17 +01:00
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case FIONBIO:
|
|
|
|
{
|
|
|
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
|
|
|
FAR int *nonblock = (FAR int *)(uintptr_t)arg;
|
|
|
|
sockcaps_t sockcaps;
|
|
|
|
|
2023-03-06 21:22:31 +01:00
|
|
|
/* Non-blocking is the only configurable option. And it applies
|
|
|
|
* only Unix domain sockets and to read operations on TCP/IP
|
|
|
|
* and UDP/IP sockets when read-ahead is enabled.
|
|
|
|
*/
|
2022-03-04 09:13:17 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(psock->s_sockif != NULL &&
|
|
|
|
psock->s_sockif->si_sockcaps != NULL);
|
|
|
|
sockcaps = psock->s_sockif->si_sockcaps(psock);
|
|
|
|
|
|
|
|
if ((sockcaps & SOCKCAP_NONBLOCKING) != 0)
|
|
|
|
{
|
2023-03-06 21:22:31 +01:00
|
|
|
if (nonblock && *nonblock)
|
|
|
|
{
|
|
|
|
conn->s_flags |= _SF_NONBLOCK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
conn->s_flags &= ~_SF_NONBLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = OK;
|
2022-03-04 09:13:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nerr("ERROR: Non-blocking not supported for this socket\n");
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 21:22:31 +01:00
|
|
|
|
2022-03-19 07:47:37 +01:00
|
|
|
break;
|
2022-03-04 09:13:17 +01:00
|
|
|
|
2023-08-07 10:02:57 +02:00
|
|
|
case FIOC_FILEPATH:
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
snprintf((FAR char *)(uintptr_t)arg, PATH_MAX, "socket:["
|
|
|
|
"domain %" PRIu8 ", type %" PRIu8 ", proto %" PRIu8 "]",
|
|
|
|
psock->s_domain, psock->s_type, psock->s_proto);
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-03-04 09:13:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/****************************************************************************
|
2015-01-19 23:02:56 +01:00
|
|
|
* Public Functions
|
2010-07-11 20:10:22 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: net_ioctl_arglen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Calculate the ioctl argument buffer length.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2023-10-20 11:08:10 +02:00
|
|
|
* domain The socket domain
|
2018-08-26 22:54:26 +02:00
|
|
|
* cmd The ioctl command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The argument buffer length, or error code.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
ssize_t net_ioctl_arglen(uint8_t domain, int cmd)
|
2018-08-26 22:54:26 +02:00
|
|
|
{
|
2022-09-07 04:56:09 +02:00
|
|
|
ssize_t arglen;
|
|
|
|
|
2023-10-20 11:08:10 +02:00
|
|
|
arglen = net_ioctl_ifreq_arglen(domain, cmd);
|
2022-09-07 04:56:09 +02:00
|
|
|
if (arglen > 0)
|
|
|
|
{
|
|
|
|
return arglen;
|
|
|
|
}
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
2022-03-25 17:33:40 +01:00
|
|
|
case FIONBIO:
|
2021-12-09 10:24:44 +01:00
|
|
|
case FIONSPACE:
|
2021-06-07 12:06:44 +02:00
|
|
|
case FIONREAD:
|
|
|
|
return sizeof(int);
|
|
|
|
|
2023-08-02 10:58:46 +02:00
|
|
|
case FIOC_FILEPATH:
|
|
|
|
return PATH_MAX;
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGIFCONF:
|
|
|
|
return sizeof(struct ifconf);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGLIFCONF:
|
|
|
|
return sizeof(struct lifconf);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGIPMSFILTER:
|
|
|
|
case SIOCSIPMSFILTER:
|
|
|
|
return sizeof(struct ip_msfilter);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCSARP:
|
|
|
|
case SIOCDARP:
|
|
|
|
case SIOCGARP:
|
|
|
|
return sizeof(struct arpreq);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCADDRT:
|
|
|
|
case SIOCDELRT:
|
|
|
|
return sizeof(struct rtentry);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2023-06-08 03:17:27 +02:00
|
|
|
case SIOCDENYINETSOCK:
|
|
|
|
return sizeof(uint8_t);
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
default:
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
# ifdef CONFIG_NETDEV_WIRELESS_IOCTL
|
2022-09-19 13:38:40 +02:00
|
|
|
if (_WLIOCVALID(cmd))
|
2018-08-26 22:54:26 +02:00
|
|
|
{
|
|
|
|
return sizeof(struct iwreq);
|
|
|
|
}
|
|
|
|
# endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
# ifdef CONFIG_WIRELESS_IEEE802154
|
|
|
|
if (_MAC802154IOCVALID(cmd))
|
|
|
|
{
|
|
|
|
return sizeof(struct ieee802154_netmac_s);
|
|
|
|
}
|
|
|
|
# endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
# ifdef CONFIG_WIRELESS_PKTRADIO
|
2022-09-19 13:38:40 +02:00
|
|
|
if (_PKRADIOIOCVALID(cmd))
|
2018-08-26 22:54:26 +02:00
|
|
|
{
|
|
|
|
return sizeof(struct pktradio_ifreq_s);
|
|
|
|
}
|
|
|
|
# endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
# ifdef CONFIG_WIRELESS_BLUETOOTH
|
2022-09-19 13:38:40 +02:00
|
|
|
if (_BLUETOOTHIOCVALID(cmd))
|
2018-08-26 22:54:26 +02:00
|
|
|
{
|
|
|
|
return sizeof(struct btreq_s);
|
|
|
|
}
|
|
|
|
# endif
|
2023-06-08 03:17:27 +02:00
|
|
|
|
|
|
|
# ifdef CONFIG_NETDEV_MODEM_LTE_IOCTL
|
|
|
|
if (_LTEIOCVALID(cmd))
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCLTECMD:
|
|
|
|
return sizeof(struct lte_ioctl_data_s);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return sizeof(struct lte_smsreq_s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
2018-08-26 22:54:26 +02:00
|
|
|
#endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/****************************************************************************
|
2020-05-04 11:00:51 +02:00
|
|
|
* Name: psock_ioctl and psock_vioctl
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-07-06 15:30:09 +02:00
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
2010-07-11 20:10:22 +02:00
|
|
|
* cmd The ioctl command
|
2013-10-02 18:51:48 +02:00
|
|
|
* arg The argument of the ioctl cmd
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-09-30 18:41:21 +02:00
|
|
|
* A non-negative value is returned on success; a negated errno value is
|
|
|
|
* returned on any failure to indicate the nature of the failure:
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* EBADF
|
2016-07-06 15:30:09 +02:00
|
|
|
* 'psock' is not a valid, connected socket structure.
|
2010-07-11 20:10:22 +02:00
|
|
|
* EFAULT
|
2013-10-02 18:51:48 +02:00
|
|
|
* 'arg' references an inaccessible memory area.
|
|
|
|
* ENOTTY
|
|
|
|
* 'cmd' not valid.
|
2010-07-11 20:10:22 +02:00
|
|
|
* EINVAL
|
2013-10-02 18:51:48 +02:00
|
|
|
* 'arg' is not valid.
|
2010-07-11 20:10:22 +02:00
|
|
|
* ENOTTY
|
|
|
|
* 'sockfd' is not associated with a network device.
|
|
|
|
* ENOTTY
|
|
|
|
* The specified request does not apply to the kind of object that the
|
|
|
|
* descriptor 'sockfd' references.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2020-05-04 11:00:51 +02:00
|
|
|
unsigned long arg;
|
2010-07-11 20:10:22 +02:00
|
|
|
int ret;
|
|
|
|
|
2016-07-06 15:30:09 +02:00
|
|
|
/* Verify that the psock corresponds to valid, allocated socket */
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2021-02-23 11:04:13 +01:00
|
|
|
if (psock == NULL || psock->s_conn == NULL)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2017-09-30 18:41:21 +02:00
|
|
|
return -EBADF;
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
arg = va_arg(ap, unsigned long);
|
|
|
|
|
2022-03-04 09:13:17 +01:00
|
|
|
/* Check for socket specific ioctl command */
|
2018-08-26 22:54:26 +02:00
|
|
|
|
2021-06-07 12:06:44 +02:00
|
|
|
ret = netdev_ioctl(psock, cmd, arg);
|
2022-03-04 09:13:17 +01:00
|
|
|
|
|
|
|
/* Check for a standard network IOCTL command. */
|
2018-08-26 22:54:26 +02:00
|
|
|
|
2022-03-04 09:13:17 +01:00
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2020-04-16 16:02:11 +02:00
|
|
|
ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)(uintptr_t)arg);
|
2018-08-26 22:54:26 +02:00
|
|
|
}
|
2016-02-25 02:02:51 +01:00
|
|
|
|
2017-03-13 17:14:38 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL)
|
2017-04-15 18:23:29 +02:00
|
|
|
/* Check for a wireless network command */
|
2017-03-13 16:51:31 +01:00
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2017-04-20 02:06:43 +02:00
|
|
|
FAR struct iwreq *wifrreq;
|
|
|
|
|
2017-04-22 02:42:13 +02:00
|
|
|
wifrreq = (FAR struct iwreq *)((uintptr_t)arg);
|
2017-04-20 02:06:43 +02:00
|
|
|
ret = netdev_wifr_ioctl(psock, cmd, wifrreq);
|
2017-03-13 16:51:31 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-07 10:38:11 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_CELLULAR)
|
|
|
|
/* Check for a cellular network command */
|
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_cell_ioctl(psock, cmd,
|
|
|
|
(FAR struct icellreq *)(uintptr_t)arg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_IEEE802154_IOCTL
|
|
|
|
/* Check for a IEEE802.15.4 network device IOCTL command */
|
2017-04-15 18:23:29 +02:00
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_iee802154_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-06 17:42:41 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_PKTRADIO_IOCTL
|
|
|
|
/* Check for a non-IEEE802.15.4 packet radio network device IOCTL command */
|
2017-08-02 19:52:44 +02:00
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_pktradio_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-06 17:42:41 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_BLUETOOTH_IOCTL
|
|
|
|
/* Check for Bluetooth network device IOCTL command */
|
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_bluetooth_ioctl(psock, cmd, arg);
|
|
|
|
}
|
2017-08-02 19:52:44 +02:00
|
|
|
#endif
|
2017-04-15 18:23:29 +02:00
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2016-02-25 02:02:51 +01:00
|
|
|
/* Check for address filtering commands */
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_imsf_ioctl(psock, cmd,
|
2020-04-16 16:02:11 +02:00
|
|
|
(FAR struct ip_msfilter *)(uintptr_t)arg);
|
2013-10-02 18:51:48 +02:00
|
|
|
}
|
|
|
|
#endif
|
2016-02-08 18:17:22 +01:00
|
|
|
|
2016-02-25 02:02:51 +01:00
|
|
|
#ifdef CONFIG_NET_ARP
|
2016-02-08 18:17:22 +01:00
|
|
|
/* Check for ARP table IOCTL commands */
|
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_arp_ioctl(psock, cmd,
|
2020-04-16 16:02:11 +02:00
|
|
|
(FAR struct arpreq *)(uintptr_t)arg);
|
2016-02-08 18:17:22 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-25 02:02:51 +01:00
|
|
|
#ifdef CONFIG_NET_ROUTE
|
2016-02-08 18:17:22 +01:00
|
|
|
/* Check for Routing table IOCTL commands */
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
if (ret == -ENOTTY)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_rt_ioctl(psock, cmd,
|
2020-04-16 16:02:11 +02:00
|
|
|
(FAR struct rtentry *)(uintptr_t)arg);
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-09-30 18:41:21 +02:00
|
|
|
return ret;
|
2007-09-16 19:46:25 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
int psock_ioctl(FAR struct socket *psock, int cmd, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Setup to access the variable argument list */
|
|
|
|
|
|
|
|
va_start(ap, cmd);
|
|
|
|
|
|
|
|
/* Let psock_vfcntl() do the real work. The errno is not set on
|
|
|
|
* failures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = psock_vioctl(psock, cmd, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-03 22:40:56 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_ifup / netdev_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Bring the interface up/down
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-19 05:41:44 +02:00
|
|
|
int netdev_ifup(FAR struct net_driver_s *dev)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
2022-07-19 05:41:44 +02:00
|
|
|
int ret = -ENOSYS;
|
|
|
|
|
2015-02-03 22:40:56 +01:00
|
|
|
/* Make sure that the device supports the d_ifup() method */
|
|
|
|
|
2017-03-14 00:59:36 +01:00
|
|
|
if (dev->d_ifup != NULL)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
|
|
|
/* Is the interface already up? */
|
|
|
|
|
|
|
|
if ((dev->d_flags & IFF_UP) == 0)
|
|
|
|
{
|
|
|
|
/* No, bring the interface up now */
|
|
|
|
|
2022-07-19 05:41:44 +02:00
|
|
|
if ((ret = dev->d_ifup(dev)) == OK)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
|
|
|
/* Mark the interface as up */
|
|
|
|
|
|
|
|
dev->d_flags |= IFF_UP;
|
2020-04-13 15:36:14 +02:00
|
|
|
|
|
|
|
/* Update the driver status */
|
|
|
|
|
|
|
|
netlink_device_notify(dev);
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-19 05:41:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = OK;
|
|
|
|
}
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
2022-07-19 05:41:44 +02:00
|
|
|
|
|
|
|
return ret;
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
|
|
|
|
2022-07-19 05:41:44 +02:00
|
|
|
int netdev_ifdown(FAR struct net_driver_s *dev)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
2022-07-19 05:41:44 +02:00
|
|
|
int ret = -ENOSYS;
|
|
|
|
|
2015-05-27 17:26:00 +02:00
|
|
|
/* Check sure that the device supports the d_ifdown() method */
|
2015-02-03 22:40:56 +01:00
|
|
|
|
2017-03-14 00:59:36 +01:00
|
|
|
if (dev->d_ifdown != NULL)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
|
|
|
/* Is the interface already down? */
|
|
|
|
|
|
|
|
if ((dev->d_flags & IFF_UP) != 0)
|
|
|
|
{
|
|
|
|
/* No, take the interface down now */
|
|
|
|
|
2022-07-19 05:41:44 +02:00
|
|
|
if ((ret = dev->d_ifdown(dev)) == OK)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
|
|
|
/* Mark the interface as down */
|
|
|
|
|
2022-07-04 10:20:15 +02:00
|
|
|
dev->d_flags &= ~(IFF_UP | IFF_RUNNING);
|
2020-04-13 15:36:14 +02:00
|
|
|
|
|
|
|
/* Update the driver status */
|
|
|
|
|
|
|
|
netlink_device_notify(dev);
|
2015-05-27 17:26:00 +02:00
|
|
|
|
2022-07-19 05:41:44 +02:00
|
|
|
/* Notify clients that the network has been taken down */
|
2015-05-27 17:26:00 +02:00
|
|
|
|
2022-08-25 15:17:57 +02:00
|
|
|
devif_dev_event(dev, NETDEV_DOWN);
|
2018-09-09 18:39:25 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NETDOWN_NOTIFIER
|
2022-07-19 05:41:44 +02:00
|
|
|
/* Provide signal notifications to threads that want to be
|
|
|
|
* notified of the network down state via signal.
|
|
|
|
*/
|
2018-09-09 18:39:25 +02:00
|
|
|
|
2022-07-19 05:41:44 +02:00
|
|
|
netdown_notifier_signal(dev);
|
2018-09-09 18:39:25 +02:00
|
|
|
#endif
|
2022-07-19 05:41:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = OK;
|
|
|
|
}
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
2022-07-19 05:41:44 +02:00
|
|
|
|
|
|
|
return ret;
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|