From c65e1aa3df9f2f602035d2b18bf97e58f156679d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jun 2018 12:41:28 -0600 Subject: [PATCH] Squashed commit of the following: syscalls/: Add syscall support for if_nametoindex() and if_indextoname() net/: Update some comments. --- arch/sim/src/nuttx-names.dat | 2 + include/net/if.h | 2 +- include/netinet/udp.h | 53 ++++ include/sys/syscall.h | 416 ++++++++++++++++---------------- net/netdev/netdev_count.c | 3 - net/netdev/netdev_default.c | 3 - net/netdev/netdev_findbyaddr.c | 12 - net/netdev/netdev_findbyname.c | 3 - net/netdev/netdev_indextoname.c | 134 ++++++++++ net/netdev/netdev_nametoindex.c | 124 ++++++++++ net/netdev/netdev_register.c | 3 +- net/netdev/netdev_txnotify.c | 9 - net/socket/setsockopt.c | 8 +- net/tcp/tcp.h | 2 +- net/tcp/tcp_conn.c | 2 +- net/udp/Kconfig | 9 + net/udp/Make.defs | 4 + net/udp/udp.h | 29 +++ net/udp/udp_setsockopt.c | 141 +++++++++++ syscall/syscall.csv | 2 + syscall/syscall_lookup.h | 4 + syscall/syscall_stublookup.c | 9 + 22 files changed, 735 insertions(+), 239 deletions(-) create mode 100644 include/netinet/udp.h create mode 100644 net/netdev/netdev_indextoname.c create mode 100644 net/netdev/netdev_nametoindex.c create mode 100644 net/udp/udp_setsockopt.c diff --git a/arch/sim/src/nuttx-names.dat b/arch/sim/src/nuttx-names.dat index bb98a0ebd7..d7e76bb904 100644 --- a/arch/sim/src/nuttx-names.dat +++ b/arch/sim/src/nuttx-names.dat @@ -34,6 +34,8 @@ getpid NXgetpid gettimeofday NXgettimeofday htons NXhtons ntohs NXhntohs +if_indextoname NXif_indextoname +if_nametoindex NXif_nametoindex ioctl NXioctl isatty NXisatty kill NXkill diff --git a/include/net/if.h b/include/net/if.h index f7f0441150..1909a72951 100644 --- a/include/net/if.h +++ b/include/net/if.h @@ -276,7 +276,7 @@ unsigned int if_nametoindex(FAR const char *ifname); * Returned Value: * If ifindex is an interface index, then the function will return the value supplied by * ifname. Otherwise, the function returns a NULL pointer and sets errno to indicate the -* error. + * error. * *******************************************************************************************/ diff --git a/include/netinet/udp.h b/include/netinet/udp.h new file mode 100644 index 0000000000..9481624dcd --- /dev/null +++ b/include/netinet/udp.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * include/netinet/udp.h + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NETINET_UDP_H +#define __INCLUDE_NETINET_UDP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define UDP_BINDTODEVICE (__SO_PROTOCOL + 0) /* Bind this UDP socket to a + * specific network device. + */ + +#endif /* __INCLUDE_NETINET_UDP_H */ diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 8e2283f337..3a0070bd3c 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -67,44 +67,44 @@ * configuration */ -#define SYS__exit (CONFIG_SYS_RESERVED+0) -#define SYS_exit (CONFIG_SYS_RESERVED+1) -#define SYS_get_errno (CONFIG_SYS_RESERVED+2) -#define SYS_getpid (CONFIG_SYS_RESERVED+3) -#define SYS_sched_getparam (CONFIG_SYS_RESERVED+4) -#define SYS_sched_getscheduler (CONFIG_SYS_RESERVED+5) -#define SYS_sched_lock (CONFIG_SYS_RESERVED+6) -#define SYS_sched_lockcount (CONFIG_SYS_RESERVED+7) -#define SYS_sched_rr_get_interval (CONFIG_SYS_RESERVED+8) -#define SYS_sched_setparam (CONFIG_SYS_RESERVED+9) -#define SYS_sched_setscheduler (CONFIG_SYS_RESERVED+10) -#define SYS_sched_unlock (CONFIG_SYS_RESERVED+11) -#define SYS_sched_yield (CONFIG_SYS_RESERVED+12) -#define SYS_set_errno (CONFIG_SYS_RESERVED+13) -#define SYS_uname (CONFIG_SYS_RESERVED+14) +#define SYS__exit (CONFIG_SYS_RESERVED + 0) +#define SYS_exit (CONFIG_SYS_RESERVED + 1) +#define SYS_get_errno (CONFIG_SYS_RESERVED + 2) +#define SYS_getpid (CONFIG_SYS_RESERVED + 3) +#define SYS_sched_getparam (CONFIG_SYS_RESERVED + 4) +#define SYS_sched_getscheduler (CONFIG_SYS_RESERVED + 5) +#define SYS_sched_lock (CONFIG_SYS_RESERVED + 6) +#define SYS_sched_lockcount (CONFIG_SYS_RESERVED + 7) +#define SYS_sched_rr_get_interval (CONFIG_SYS_RESERVED + 8) +#define SYS_sched_setparam (CONFIG_SYS_RESERVED + 9) +#define SYS_sched_setscheduler (CONFIG_SYS_RESERVED + 10) +#define SYS_sched_unlock (CONFIG_SYS_RESERVED + 11) +#define SYS_sched_yield (CONFIG_SYS_RESERVED + 12) +#define SYS_set_errno (CONFIG_SYS_RESERVED + 13) +#define SYS_uname (CONFIG_SYS_RESERVED + 14) /* Semaphores */ -#define SYS_sem_destroy (CONFIG_SYS_RESERVED+15) -#define SYS_sem_post (CONFIG_SYS_RESERVED+16) -#define SYS_sem_timedwait (CONFIG_SYS_RESERVED+17) -#define SYS_sem_trywait (CONFIG_SYS_RESERVED+18) -#define SYS_sem_wait (CONFIG_SYS_RESERVED+19) +#define SYS_sem_destroy (CONFIG_SYS_RESERVED + 15) +#define SYS_sem_post (CONFIG_SYS_RESERVED + 16) +#define SYS_sem_timedwait (CONFIG_SYS_RESERVED + 17) +#define SYS_sem_trywait (CONFIG_SYS_RESERVED + 18) +#define SYS_sem_wait (CONFIG_SYS_RESERVED + 19) #ifdef CONFIG_PRIORITY_INHERITANCE -# define SYS_sem_setprotocol (CONFIG_SYS_RESERVED+20) -# define __SYS_named_sem (CONFIG_SYS_RESERVED+21) +# define SYS_sem_setprotocol (CONFIG_SYS_RESERVED + 20) +# define __SYS_named_sem (CONFIG_SYS_RESERVED + 21) #else -# define __SYS_named_sem (CONFIG_SYS_RESERVED+20) +# define __SYS_named_sem (CONFIG_SYS_RESERVED + 20) #endif /* Named semaphores */ #ifdef CONFIG_FS_NAMED_SEMAPHORES # define SYS_sem_open __SYS_named_sem -# define SYS_sem_close (__SYS_named_sem+1) -# define SYS_sem_unlink (__SYS_named_sem+2) -# define __SYS_task_create (__SYS_named_sem+3) +# define SYS_sem_close (__SYS_named_sem + 1) +# define SYS_sem_unlink (__SYS_named_sem + 2) +# define __SYS_task_create (__SYS_named_sem + 3) #else # define __SYS_task_create __SYS_named_sem #endif @@ -115,7 +115,7 @@ #ifndef CONFIG_BUILD_KERNEL # define SYS_task_create __SYS_task_create -# define __SYS_task_delete (__SYS_task_create+1) +# define __SYS_task_delete (__SYS_task_create + 1) /* pgalloc() is only available with address environments with the page * allocator selected. MMU support from the CPU is also required. @@ -123,41 +123,41 @@ #else # define SYS_pgalloc __SYS_task_create -# define __SYS_task_delete (__SYS_task_create+1) +# define __SYS_task_delete (__SYS_task_create + 1) #endif # define SYS_task_delete __SYS_task_delete -# define SYS_task_restart (__SYS_task_delete+1) -# define SYS_task_setcancelstate (__SYS_task_delete+2) -# define SYS_up_assert (__SYS_task_delete+3) +# define SYS_task_restart (__SYS_task_delete + 1) +# define SYS_task_setcancelstate (__SYS_task_delete + 2) +# define SYS_up_assert (__SYS_task_delete + 3) # ifdef CONFIG_CANCELLATION_POINTS -# define SYS_task_setcanceltype (__SYS_task_delete+4) -# define SYS_task_testcancel (__SYS_task_delete+5) -# define __SYS_vfork (__SYS_task_delete+6) +# define SYS_task_setcanceltype (__SYS_task_delete + 4) +# define SYS_task_testcancel (__SYS_task_delete + 5) +# define __SYS_vfork (__SYS_task_delete + 6) # else -# define __SYS_vfork (__SYS_task_delete+4) +# define __SYS_vfork (__SYS_task_delete + 4) # endif /* The following can be individually enabled */ #ifdef CONFIG_ARCH_HAVE_VFORK # define SYS_vfork __SYS_vfork -# define __SYS_atexit (__SYS_vfork+1) +# define __SYS_atexit (__SYS_vfork + 1) #else # define __SYS_atexit __SYS_vfork #endif #ifdef CONFIG_SCHED_ATEXIT # define SYS_atexit __SYS_atexit -# define __SYS_on_exit (__SYS_atexit+1) +# define __SYS_on_exit (__SYS_atexit + 1) #else # define __SYS_on_exit __SYS_atexit #endif #ifdef CONFIG_SCHED_ONEXIT # define SYS_on_exit __SYS_on_exit -# define __SYS_waitpid (__SYS_on_exit+1) +# define __SYS_waitpid (__SYS_on_exit + 1) #else # define __SYS_waitpid __SYS_on_exit #endif @@ -165,11 +165,11 @@ #ifdef CONFIG_SCHED_WAITPID # define SYS_waitpid __SYS_waitpid # ifdef CONFIG_SCHED_HAVE_PARENT -# define SYS_wait (__SYS_waitpid+1) -# define SYS_waitid (__SYS_waitpid+2) -# define __SYS_insmod (__SYS_waitpid+3) +# define SYS_wait (__SYS_waitpid + 1) +# define SYS_waitid (__SYS_waitpid + 2) +# define __SYS_insmod (__SYS_waitpid + 3) # else -# define __SYS_insmod (__SYS_waitpid+1) +# define __SYS_insmod (__SYS_waitpid + 1) #endif #else # define __SYS_insmod __SYS_waitpid @@ -181,9 +181,9 @@ #ifdef CONFIG_MODULE # define SYS_insmod __SYS_insmod -# define SYS_rmmod (__SYS_insmod+1) -# define SYS_modhandle (__SYS_insmod+2) -# define __SYS_exec (__SYS_insmod+3) +# define SYS_rmmod (__SYS_insmod + 1) +# define SYS_modhandle (__SYS_insmod + 2) +# define __SYS_exec (__SYS_insmod + 3) #else # define __SYS_exec __SYS_insmod #endif @@ -195,7 +195,7 @@ #ifndef CONFIG_BINFMT_DISABLE # ifndef CONFIG_BUILD_KERNEL # define SYS_exec __SYS_exec -# define __SYS_posix_spawn (__SYS_exec+1) +# define __SYS_posix_spawn (__SYS_exec + 1) # else # define __SYS_posix_spawn __SYS_exec # endif @@ -205,8 +205,8 @@ # else # define SYS_posix_spawn __SYS_posix_spawn # endif -# define SYS_execv (__SYS_posix_spawn+1) -# define __SYS_signals (__SYS_posix_spawn+2) +# define SYS_execv (__SYS_posix_spawn + 1) +# define __SYS_signals (__SYS_posix_spawn + 2) # else # define __SYS_signals __SYS_posix_spawn # endif @@ -219,16 +219,16 @@ */ #ifndef CONFIG_DISABLE_SIGNALS -# define SYS_kill (__SYS_signals+0) -# define SYS_sigaction (__SYS_signals+1) -# define SYS_sigpending (__SYS_signals+2) -# define SYS_sigprocmask (__SYS_signals+3) -# define SYS_sigqueue (__SYS_signals+4) -# define SYS_sigsuspend (__SYS_signals+5) -# define SYS_sigtimedwait (__SYS_signals+6) -# define SYS_sigwaitinfo (__SYS_signals+7) -# define SYS_clock_nanosleep (__SYS_signals+8) -# define __SYS_clock (__SYS_signals+9) +# define SYS_kill (__SYS_signals + 0) +# define SYS_sigaction (__SYS_signals + 1) +# define SYS_sigpending (__SYS_signals + 2) +# define SYS_sigprocmask (__SYS_signals + 3) +# define SYS_sigqueue (__SYS_signals + 4) +# define SYS_sigsuspend (__SYS_signals + 5) +# define SYS_sigtimedwait (__SYS_signals + 6) +# define SYS_sigwaitinfo (__SYS_signals + 7) +# define SYS_clock_nanosleep (__SYS_signals + 8) +# define __SYS_clock (__SYS_signals + 9) #else # define __SYS_clock __SYS_signals #endif @@ -237,34 +237,34 @@ * NuttX configuration. */ -#define SYS_clock (__SYS_clock+0) -#define SYS_clock_getres (__SYS_clock+1) -#define SYS_clock_gettime (__SYS_clock+2) -#define SYS_clock_settime (__SYS_clock+3) +#define SYS_clock (__SYS_clock + 0) +#define SYS_clock_getres (__SYS_clock + 1) +#define SYS_clock_gettime (__SYS_clock + 2) +#define SYS_clock_settime (__SYS_clock + 3) #ifdef CONFIG_CLOCK_TIMEKEEPING -# define SYS_adjtime (__SYS_clock+4) -# define __SYS_timers (__SYS_clock+5) +# define SYS_adjtime (__SYS_clock + 4) +# define __SYS_timers (__SYS_clock + 5) #else -# define __SYS_timers (__SYS_clock+4) +# define __SYS_timers (__SYS_clock + 4) #endif /* The following are defined only if POSIX timers are supported */ #ifndef CONFIG_DISABLE_POSIX_TIMERS -# define SYS_timer_create (__SYS_timers+0) -# define SYS_timer_delete (__SYS_timers+1) -# define SYS_timer_getoverrun (__SYS_timers+2) -# define SYS_timer_gettime (__SYS_timers+3) -# define SYS_timer_settime (__SYS_timers+4) -# define __SYS_syslog (__SYS_timers+5) +# define SYS_timer_create (__SYS_timers + 0) +# define SYS_timer_delete (__SYS_timers + 1) +# define SYS_timer_getoverrun (__SYS_timers + 2) +# define SYS_timer_gettime (__SYS_timers + 3) +# define SYS_timer_settime (__SYS_timers + 4) +# define __SYS_syslog (__SYS_timers + 5) #else # define __SYS_syslog __SYS_timers #endif /* Unconditional system logging */ -#define SYS_nx_vsyslog (__SYS_syslog+0) -#define __SYS_descriptors (__SYS_syslog+1) +#define SYS_nx_vsyslog (__SYS_syslog + 0) +#define __SYS_descriptors (__SYS_syslog + 1) /* The following are defined if either file or socket descriptor are * enabled. @@ -276,35 +276,43 @@ #endif #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -# define SYS_close (__SYS_descriptors+0) +# define SYS_close (__SYS_descriptors + 0) # ifdef CONFIG_LIBC_IOCTL_VARIADIC -# define SYS_fs_ioctl (__SYS_descriptors+1) +# define SYS_fs_ioctl (__SYS_descriptors + 1) # else -# define SYS_ioctl (__SYS_descriptors+1) +# define SYS_ioctl (__SYS_descriptors + 1) # endif -# define SYS_read (__SYS_descriptors+2) -# define SYS_write (__SYS_descriptors+3) -# define SYS_pread (__SYS_descriptors+4) -# define SYS_pwrite (__SYS_descriptors+5) +# define SYS_read (__SYS_descriptors + 2) +# define SYS_write (__SYS_descriptors + 3) +# define SYS_pread (__SYS_descriptors + 4) +# define SYS_pwrite (__SYS_descriptors + 5) # ifdef CONFIG_FS_AIO -# define SYS_aio_read (__SYS_descriptors+6) -# define SYS_aio_write (__SYS_descriptors+7) -# define SYS_aio_fsync (__SYS_descriptors+8) -# define SYS_aio_cancel (__SYS_descriptors+9) -# define __SYS_poll (__SYS_descriptors+10) +# define SYS_aio_read (__SYS_descriptors + 6) +# define SYS_aio_write (__SYS_descriptors + 7) +# define SYS_aio_fsync (__SYS_descriptors + 8) +# define SYS_aio_cancel (__SYS_descriptors + 9) +# define __SYS_poll (__SYS_descriptors + 10) # else -# define __SYS_poll (__SYS_descriptors+6) +# define __SYS_poll (__SYS_descriptors + 6) # endif # ifndef CONFIG_DISABLE_POLL # define SYS_poll __SYS_poll -# define SYS_select (__SYS_poll+1) -# define __SYS_termios (__SYS_poll+2) +# define SYS_select (__SYS_poll + 1) +# define __SYS_ifindex (__SYS_poll + 2) # else -# define __SYS_termios __SYS_poll +# define __SYS_ifindex __SYS_poll +# endif +# ifdef CONFIG_NETDEV_IFINDEX +# define SYS_if_indextoname __SYS_ifindex +# define SYS_if_nametoindex (__SYS_ifindex + 1) +# define __SYS_termios (__SYS_ifindex + 2) +# else +# define __SYS_termios __SYS_ifindex +# endif # endif # ifdef CONFIG_SERIAL_TERMIOS # define SYS_tcdrain __SYS_termios -# define __SYS_boardctl (__SYS_termios+1) +# define __SYS_boardctl (__SYS_termios + 1) # else # define __SYS_boardctl __SYS_termios # endif @@ -316,7 +324,7 @@ #ifdef CONFIG_LIB_BOARDCTL # define SYS_boardctl __SYS_boardctl -# define __SYS_filedesc (__SYS_boardctl+1) +# define __SYS_filedesc (__SYS_boardctl + 1) #else # define __SYS_filedesc __SYS_boardctl #endif @@ -324,72 +332,72 @@ /* The following are defined if file descriptors are enabled */ #if CONFIG_NFILE_DESCRIPTORS > 0 -# define SYS_closedir (__SYS_filedesc+0) -# define SYS_dup (__SYS_filedesc+1) -# define SYS_dup2 (__SYS_filedesc+2) -# define SYS_fcntl (__SYS_filedesc+3) -# define SYS_lseek (__SYS_filedesc+4) -# define SYS_mmap (__SYS_filedesc+5) -# define SYS_open (__SYS_filedesc+6) -# define SYS_opendir (__SYS_filedesc+7) -# define SYS_readdir (__SYS_filedesc+8) -# define SYS_rewinddir (__SYS_filedesc+9) -# define SYS_seekdir (__SYS_filedesc+10) -# define SYS_stat (__SYS_filedesc+11) -# define SYS_fstat (__SYS_filedesc+12) -# define SYS_statfs (__SYS_filedesc+13) -# define SYS_fstatfs (__SYS_filedesc+14) -# define SYS_telldir (__SYS_filedesc+15) +# define SYS_closedir (__SYS_filedesc + 0) +# define SYS_dup (__SYS_filedesc + 1) +# define SYS_dup2 (__SYS_filedesc + 2) +# define SYS_fcntl (__SYS_filedesc + 3) +# define SYS_lseek (__SYS_filedesc + 4) +# define SYS_mmap (__SYS_filedesc + 5) +# define SYS_open (__SYS_filedesc + 6) +# define SYS_opendir (__SYS_filedesc + 7) +# define SYS_readdir (__SYS_filedesc + 8) +# define SYS_rewinddir (__SYS_filedesc + 9) +# define SYS_seekdir (__SYS_filedesc + 10) +# define SYS_stat (__SYS_filedesc + 11) +# define SYS_fstat (__SYS_filedesc + 12) +# define SYS_statfs (__SYS_filedesc + 13) +# define SYS_fstatfs (__SYS_filedesc + 14) +# define SYS_telldir (__SYS_filedesc + 15) # if defined(CONFIG_PSEUDOFS_SOFTLINKS) -# define SYS_link (__SYS_filedesc+16) -# define SYS_readlink (__SYS_filedesc+17) -# define __SYS_pipes (__SYS_filedesc+18) +# define SYS_link (__SYS_filedesc + 16) +# define SYS_readlink (__SYS_filedesc + 17) +# define __SYS_pipes (__SYS_filedesc + 18) # else -# define __SYS_pipes (__SYS_filedesc+16) +# define __SYS_pipes (__SYS_filedesc + 16) # endif # if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 -# define SYS_pipe2 (__SYS_pipes+0) -# define __SYS_mkfifo2 (__SYS_pipes+1) +# define SYS_pipe2 (__SYS_pipes + 0) +# define __SYS_mkfifo2 (__SYS_pipes + 1) # else -# define __SYS_mkfifo2 (__SYS_pipes+0) +# define __SYS_mkfifo2 (__SYS_pipes + 0) # endif # if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 -# define SYS_mkfifo2 (__SYS_mkfifo2+0) -# define __SYS_fs_fdopen (__SYS_mkfifo2+1) +# define SYS_mkfifo2 (__SYS_mkfifo2 + 0) +# define __SYS_fs_fdopen (__SYS_mkfifo2 + 1) # else -# define __SYS_fs_fdopen (__SYS_mkfifo2+0) +# define __SYS_fs_fdopen (__SYS_mkfifo2 + 0) # endif # if CONFIG_NFILE_STREAMS > 0 -# define SYS_fs_fdopen (__SYS_fs_fdopen+0) -# define SYS_sched_getstreams (__SYS_fs_fdopen+1) -# define __SYS_sendfile (__SYS_fs_fdopen+2) +# define SYS_fs_fdopen (__SYS_fs_fdopen + 0) +# define SYS_sched_getstreams (__SYS_fs_fdopen + 1) +# define __SYS_sendfile (__SYS_fs_fdopen + 2) # else -# define __SYS_sendfile (__SYS_fs_fdopen+0) +# define __SYS_sendfile (__SYS_fs_fdopen + 0) # endif # if defined(CONFIG_NET_SENDFILE) # define SYS_sendfile, __SYS_sendfile -# define __SYS_mountpoint (__SYS_sendfile+1) +# define __SYS_mountpoint (__SYS_sendfile + 1) # else # define __SYS_mountpoint __SYS_sendfile # endif # if !defined(CONFIG_DISABLE_MOUNTPOINT) # if defined(CONFIG_FS_READABLE) -# define SYS_mount (__SYS_mountpoint+0) +# define SYS_mount (__SYS_mountpoint + 0) # endif -# define SYS_fsync (__SYS_mountpoint+1) -# define SYS_ftruncate (__SYS_mountpoint+2) -# define SYS_mkdir (__SYS_mountpoint+3) -# define SYS_rename (__SYS_mountpoint+4) -# define SYS_rmdir (__SYS_mountpoint+5) -# define SYS_umount2 (__SYS_mountpoint+6) -# define SYS_unlink (__SYS_mountpoint+7) -# define __SYS_shm (__SYS_mountpoint+8) +# define SYS_fsync (__SYS_mountpoint + 1) +# define SYS_ftruncate (__SYS_mountpoint + 2) +# define SYS_mkdir (__SYS_mountpoint + 3) +# define SYS_rename (__SYS_mountpoint + 4) +# define SYS_rmdir (__SYS_mountpoint + 5) +# define SYS_umount2 (__SYS_mountpoint + 6) +# define SYS_unlink (__SYS_mountpoint + 7) +# define __SYS_shm (__SYS_mountpoint + 8) # else # define __SYS_shm __SYS_mountpoint # endif @@ -401,11 +409,11 @@ /* Shared memory interfaces */ #ifdef CONFIG_MM_SHM -# define SYS_shmget (__SYS_shm+0) -# define SYS_shmat (__SYS_shm+1) -# define SYS_shmctl (__SYS_shm+2) -# define SYS_shmdt (__SYS_shm+3) -# define __SYS_pthread (__SYS_shm+4) +# define SYS_shmget (__SYS_shm + 0) +# define SYS_shmat (__SYS_shm + 1) +# define SYS_shmctl (__SYS_shm + 2) +# define SYS_shmdt (__SYS_shm + 3) +# define __SYS_pthread (__SYS_shm + 4) #else # define __SYS_pthread __SYS_shm #endif @@ -413,57 +421,57 @@ /* The following are defined if pthreads are enabled */ #ifndef CONFIG_DISABLE_PTHREAD -# define SYS_pthread_cancel (__SYS_pthread+0) -# define SYS_pthread_cond_broadcast (__SYS_pthread+1) -# define SYS_pthread_cond_signal (__SYS_pthread+2) -# define SYS_pthread_cond_wait (__SYS_pthread+3) -# define SYS_pthread_create (__SYS_pthread+4) -# define SYS_pthread_detach (__SYS_pthread+5) -# define SYS_pthread_exit (__SYS_pthread+6) -# define SYS_pthread_getschedparam (__SYS_pthread+7) -# define SYS_pthread_getspecific (__SYS_pthread+8) -# define SYS_pthread_join (__SYS_pthread+9) -# define SYS_pthread_key_create (__SYS_pthread+10) -# define SYS_pthread_key_delete (__SYS_pthread+11) -# define SYS_pthread_mutex_destroy (__SYS_pthread+12) -# define SYS_pthread_mutex_init (__SYS_pthread+13) -# define SYS_pthread_mutex_lock (__SYS_pthread+14) -# define SYS_pthread_mutex_trylock (__SYS_pthread+15) -# define SYS_pthread_mutex_unlock (__SYS_pthread+16) +# define SYS_pthread_cancel (__SYS_pthread + 0) +# define SYS_pthread_cond_broadcast (__SYS_pthread + 1) +# define SYS_pthread_cond_signal (__SYS_pthread + 2) +# define SYS_pthread_cond_wait (__SYS_pthread + 3) +# define SYS_pthread_create (__SYS_pthread + 4) +# define SYS_pthread_detach (__SYS_pthread + 5) +# define SYS_pthread_exit (__SYS_pthread + 6) +# define SYS_pthread_getschedparam (__SYS_pthread + 7) +# define SYS_pthread_getspecific (__SYS_pthread + 8) +# define SYS_pthread_join (__SYS_pthread + 9) +# define SYS_pthread_key_create (__SYS_pthread + 10) +# define SYS_pthread_key_delete (__SYS_pthread + 11) +# define SYS_pthread_mutex_destroy (__SYS_pthread + 12) +# define SYS_pthread_mutex_init (__SYS_pthread + 13) +# define SYS_pthread_mutex_lock (__SYS_pthread + 14) +# define SYS_pthread_mutex_trylock (__SYS_pthread + 15) +# define SYS_pthread_mutex_unlock (__SYS_pthread + 16) #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE -# define SYS_pthread_mutex_consistent (__SYS_pthread+17) -# define __SYS_pthread_setschedparam (__SYS_pthread+18) +# define SYS_pthread_mutex_consistent (__SYS_pthread + 17) +# define __SYS_pthread_setschedparam (__SYS_pthread + 18) #else -# define __SYS_pthread_setschedparam (__SYS_pthread+17) +# define __SYS_pthread_setschedparam (__SYS_pthread + 17) #endif -# define SYS_pthread_setschedparam (__SYS_pthread_setschedparam+0) -# define SYS_pthread_setschedprio (__SYS_pthread_setschedparam+1) -# define SYS_pthread_setspecific (__SYS_pthread_setschedparam+2) -# define __SYS_pthread_smp (__SYS_pthread_setschedparam+3) +# define SYS_pthread_setschedparam (__SYS_pthread_setschedparam + 0) +# define SYS_pthread_setschedprio (__SYS_pthread_setschedparam + 1) +# define SYS_pthread_setspecific (__SYS_pthread_setschedparam + 2) +# define __SYS_pthread_smp (__SYS_pthread_setschedparam + 3) # ifdef CONFIG_SMP -# define SYS_pthread_setaffinity_np (__SYS_pthread_smp+0) -# define SYS_pthread_getaffinity_np (__SYS_pthread_smp+1) -# define __SYS_pthread_signals (__SYS_pthread_smp+2) +# define SYS_pthread_setaffinity_np (__SYS_pthread_smp + 0) +# define SYS_pthread_getaffinity_np (__SYS_pthread_smp + 1) +# define __SYS_pthread_signals (__SYS_pthread_smp + 2) # else # define __SYS_pthread_signals __SYS_pthread_smp # endif # ifndef CONFIG_DISABLE_SIGNALS -# define SYS_pthread_cond_timedwait (__SYS_pthread_signals+0) -# define SYS_pthread_kill (__SYS_pthread_signals+1) -# define SYS_pthread_sigmask (__SYS_pthread_signals+2) -# define __SYS_pthread_cleanup (__SYS_pthread_signals+3) +# define SYS_pthread_cond_timedwait (__SYS_pthread_signals + 0) +# define SYS_pthread_kill (__SYS_pthread_signals + 1) +# define SYS_pthread_sigmask (__SYS_pthread_signals + 2) +# define __SYS_pthread_cleanup (__SYS_pthread_signals + 3) # else # define __SYS_pthread_cleanup __SYS_pthread_signals # endif # ifdef CONFIG_PTHREAD_CLEANUP -# define __SYS_pthread_cleanup_push (__SYS_pthread_cleanup+0) -# define __SYS_pthread_cleanup_pop (__SYS_pthread_cleanup+1) -# define __SYS_mqueue (__SYS_pthread_cleanup+2) +# define __SYS_pthread_cleanup_push (__SYS_pthread_cleanup + 0) +# define __SYS_pthread_cleanup_pop (__SYS_pthread_cleanup + 1) +# define __SYS_mqueue (__SYS_pthread_cleanup + 2) # else # define __SYS_mqueue __SYS_pthread_cleanup # endif @@ -475,17 +483,17 @@ /* The following are defined only if message queues are enabled */ #ifndef CONFIG_DISABLE_MQUEUE -# define SYS_mq_close (__SYS_mqueue+0) -# define SYS_mq_getattr (__SYS_mqueue+1) -# define SYS_mq_notify (__SYS_mqueue+2) -# define SYS_mq_open (__SYS_mqueue+3) -# define SYS_mq_receive (__SYS_mqueue+4) -# define SYS_mq_send (__SYS_mqueue+5) -# define SYS_mq_setattr (__SYS_mqueue+6) -# define SYS_mq_timedreceive (__SYS_mqueue+7) -# define SYS_mq_timedsend (__SYS_mqueue+8) -# define SYS_mq_unlink (__SYS_mqueue+9) -# define __SYS_environ (__SYS_mqueue+10) +# define SYS_mq_close (__SYS_mqueue + 0) +# define SYS_mq_getattr (__SYS_mqueue + 1) +# define SYS_mq_notify (__SYS_mqueue + 2) +# define SYS_mq_open (__SYS_mqueue + 3) +# define SYS_mq_receive (__SYS_mqueue + 4) +# define SYS_mq_send (__SYS_mqueue + 5) +# define SYS_mq_setattr (__SYS_mqueue + 6) +# define SYS_mq_timedreceive (__SYS_mqueue + 7) +# define SYS_mq_timedsend (__SYS_mqueue + 8) +# define SYS_mq_unlink (__SYS_mqueue + 9) +# define __SYS_environ (__SYS_mqueue + 10) #else # define __SYS_environ __SYS_mqueue #endif @@ -493,12 +501,12 @@ /* The following are defined only if environment variables are supported */ #ifndef CONFIG_DISABLE_ENVIRON -# define SYS_clearenv (__SYS_environ+0) -# define SYS_getenv (__SYS_environ+1) -# define SYS_putenv (__SYS_environ+2) -# define SYS_setenv (__SYS_environ+3) -# define SYS_unsetenv (__SYS_environ+4) -# define __SYS_netdb (__SYS_environ+5) +# define SYS_clearenv (__SYS_environ + 0) +# define SYS_getenv (__SYS_environ + 1) +# define SYS_putenv (__SYS_environ + 2) +# define SYS_setenv (__SYS_environ + 3) +# define SYS_unsetenv (__SYS_environ + 4) +# define __SYS_netdb (__SYS_environ + 5) #else # define __SYS_netdb __SYS_environ #endif @@ -506,8 +514,8 @@ /* The following are defined if netdb is supported */ #ifdef CONFIG_LIBC_NETDB -# define SYS_sethostname (__SYS_netdb+0) -# define __SYS_network (__SYS_netdb+1) +# define SYS_sethostname (__SYS_netdb + 0) +# define __SYS_network (__SYS_netdb + 1) #else # define __SYS_network __SYS_netdb #endif @@ -515,18 +523,18 @@ /* The following are defined only if networking AND sockets are supported */ #if CONFIG_NSOCKET_DESCRIPTORS > 0 -# define SYS_accept (__SYS_network+0) -# define SYS_bind (__SYS_network+1) -# define SYS_connect (__SYS_network+2) -# define SYS_getsockopt (__SYS_network+3) -# define SYS_listen (__SYS_network+4) -# define SYS_recv (__SYS_network+5) -# define SYS_recvfrom (__SYS_network+6) -# define SYS_send (__SYS_network+7) -# define SYS_sendto (__SYS_network+8) -# define SYS_setsockopt (__SYS_network+9) -# define SYS_socket (__SYS_network+10) -# define SYS_nnetsocket (__SYS_network+11) +# define SYS_accept (__SYS_network + 0) +# define SYS_bind (__SYS_network + 1) +# define SYS_connect (__SYS_network + 2) +# define SYS_getsockopt (__SYS_network + 3) +# define SYS_listen (__SYS_network + 4) +# define SYS_recv (__SYS_network + 5) +# define SYS_recvfrom (__SYS_network + 6) +# define SYS_send (__SYS_network + 7) +# define SYS_sendto (__SYS_network + 8) +# define SYS_setsockopt (__SYS_network + 9) +# define SYS_socket (__SYS_network + 10) +# define SYS_nnetsocket (__SYS_network + 11) #else # define SYS_nnetsocket __SYS_network #endif @@ -534,7 +542,7 @@ /* The following is defined only if CONFIG_TASK_NAME_SIZE > 0 */ #if CONFIG_TASK_NAME_SIZE > 0 -# define SYS_prctl (SYS_nnetsocket+1) +# define SYS_prctl (SYS_nnetsocket + 1) #else # define SYS_prctl SYS_nnetsocket #endif @@ -543,8 +551,8 @@ * is enabled. */ #ifdef CONFIG_CRYPTO_RANDOM_POOL -# define SYS_getrandom (SYS_prctl+1) -# define SYS_maxsyscall (SYS_prctl+2) +# define SYS_getrandom (SYS_prctl + 1) +# define SYS_maxsyscall (SYS_prctl + 2) #else # define SYS_maxsyscall SYS_prctl #endif diff --git a/net/netdev/netdev_count.c b/net/netdev/netdev_count.c index 8f3b5ac793..6635cfc425 100644 --- a/net/netdev/netdev_count.c +++ b/net/netdev/netdev_count.c @@ -64,9 +64,6 @@ * Returned Value: * The number of network devices * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ int netdev_count(void) diff --git a/net/netdev/netdev_default.c b/net/netdev/netdev_default.c index c3da8dbe3a..f177d0dfb8 100644 --- a/net/netdev/netdev_default.c +++ b/net/netdev/netdev_default.c @@ -68,9 +68,6 @@ * Returned Value: * Pointer to default network driver on success; null on failure * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ FAR struct net_driver_s *netdev_default(void) diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index 5328d04db7..4851e2f985 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -74,9 +74,6 @@ * Returned Value: * Pointer to driver on success; null on failure * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ #ifdef CONFIG_NET_IPv4 @@ -127,9 +124,6 @@ static FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr) * Returned Value: * Pointer to driver on success; null on failure * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ #ifdef CONFIG_NET_IPv6 @@ -185,9 +179,6 @@ netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr) * Returned Value: * Pointer to driver on success; null on failure * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ #ifdef CONFIG_NET_IPv4 @@ -285,9 +276,6 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, * Returned Value: * Pointer to driver on success; null on failure * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ #ifdef CONFIG_NET_IPv6 diff --git a/net/netdev/netdev_findbyname.c b/net/netdev/netdev_findbyname.c index 4c4f3b8e34..2ab2a1a97f 100644 --- a/net/netdev/netdev_findbyname.c +++ b/net/netdev/netdev_findbyname.c @@ -65,9 +65,6 @@ * Returned Value: * Pointer to driver on success; null on failure * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ FAR struct net_driver_s *netdev_findbyname(FAR const char *ifname) diff --git a/net/netdev/netdev_indextoname.c b/net/netdev/netdev_indextoname.c new file mode 100644 index 0000000000..7d05a95814 --- /dev/null +++ b/net/netdev/netdev_indextoname.c @@ -0,0 +1,134 @@ +/**************************************************************************** + * net/netdev/netdev_indextoname.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "nuttx/net/net.h" +#include "nuttx/net/netdev.h" + +#include "netdev/netdev.h" + +#ifdef CONFIG_NETDEV_IFINDEX + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netdev_indextoname + * + * Description: + * The if_indextoname() function maps an interface index to its + * corresponding name. + * + * Input Parameters: + * ifname - Points to a buffer of at least IF_NAMESIZE bytes. + * if_indextoname() will place in this buffer the name of the + * interface with index ifindex. + * + * Returned Value: + * If ifindex is an interface index, then the function will return zero + * (OK). Otherwise, the function returns a negated errno value; + * + ****************************************************************************/ + +int netdev_indextoname(unsigned int ifindex, FAR char *ifname) +{ + FAR struct net_driver_s *dev; + int ret = -ENODEV; + + DEBUGASSERT(ifindex > 0 && ifindex <= MAX_IFINDEX); + DEBUGASSERT(ifname != NULL); + + /* Find the driver with this name */ + + net_lock(); + dev = netdev_findbyindex(ifindex); + if (dev != NULL) + { + memcpy(ifname, dev->d_ifname, IF_NAMESIZE); + ret = OK; + } + + net_unlock(); + return ret; +} + +/**************************************************************************** + * Name: if_indextoname + * + * Description: + * The if_indextoname() function maps an interface index to its + * corresponding name. + * + * Input Parameters: + * ifname - Points to a buffer of at least IF_NAMESIZE bytes. + * if_indextoname() will place in this buffer the name of the + * interface with index ifindex. + * + * Returned Value: + * If ifindex is an interface index, then the function will return the + * value supplied by ifname. Otherwise, the function returns a NULL pointer + * and sets errno to indicate the error. + * + ****************************************************************************/ + +FAR char *if_indextoname(unsigned int ifindex, FAR char *ifname) +{ + int ret; + + /* Let netdev_indextoname to the work */ + + ret = netdev_indextoname(ifindex, ifname); + if (ret < 0) + { + set_errno(-ret); + return NULL; + } + + return ifname; +} + +#endif /* CONFIG_NETDEV_IFINDEX */ diff --git a/net/netdev/netdev_nametoindex.c b/net/netdev/netdev_nametoindex.c new file mode 100644 index 0000000000..e5bb3d3409 --- /dev/null +++ b/net/netdev/netdev_nametoindex.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * net/netdev/netdev_nametoindex.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "nuttx/net/net.h" +#include "nuttx/net/netdev.h" + +#include "netdev/netdev.h" + +#ifdef CONFIG_NETDEV_IFINDEX + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netdev_nametoindex + * + * Description: + * The if_nametoindex() function returns the interface index corresponding + * to name ifname. + * + * Input Parameters: + * ifname - The interface name + * + * Returned Value: + * The corresponding index if ifname is the name of an interface; + * otherwise, a negated errno value is returned. + * + ****************************************************************************/ + +unsigned int netdev_nametoindex(FAR const char *ifname) +{ + FAR struct net_driver_s *dev; + unsigned int ifindex = -ENODEV; + + /* Find the driver with this name */ + + net_lock(); + dev = netdev_findbyname(ifname); + if (dev != NULL) + { + ifindex = dev->d_ifindex; + } + + net_unlock(); + return ifindex; +} + +/**************************************************************************** + * Name: if_nametoindex + * + * Description: + * The if_nametoindex() function returns the interface index corresponding + * to name ifname. + * + * Input Parameters: + * ifname - The interface name + * + * Returned Value: + * The corresponding index if ifname is the name of an interface; + * otherwise, zero. Although not specified, the errno value will be set. + * + ****************************************************************************/ + +unsigned int if_nametoindex(FAR const char *ifname) +{ + int ret; + + /* Let netdev_nametoindex to the work */ + + ret = netdev_nametoindex(ifname); + if (ret < 0) + { + set_errno(-ret); + return 0; + } + + return ret; +} + +#endif /* CONFIG_NETDEV_IFINDEX */ diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 9a7e63edd0..fb9b149a48 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -221,7 +221,8 @@ static int get_ifindex(void) * 0:Success; negated errno on failure * * Assumptions: - * Called during system initialization from normal user mode + * Called during system bring-up, but also when a removable network + * device is installed. * ****************************************************************************/ diff --git a/net/netdev/netdev_txnotify.c b/net/netdev/netdev_txnotify.c index 1d91f6737d..d2b2e5e570 100644 --- a/net/netdev/netdev_txnotify.c +++ b/net/netdev/netdev_txnotify.c @@ -68,9 +68,6 @@ * Returned Value: * None * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ #ifdef CONFIG_NET_IPv4 @@ -105,9 +102,6 @@ void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr) * Returned Value: * None * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ #ifdef CONFIG_NET_IPv6 @@ -142,9 +136,6 @@ void netdev_ipv6_txnotify(FAR const net_ipv6addr_t lipaddr, * Returned Value: * None * - * Assumptions: - * Called from normal user mode - * ****************************************************************************/ void netdev_txnotify_dev(FAR struct net_driver_s *dev) diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index 6b86f303b7..610ba83729 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -53,6 +53,7 @@ #include "socket/socket.h" #include "tcp/tcp.h" +#include "udp/udp.h" #include "usrsock/usrsock.h" #include "utils/utils.h" @@ -369,13 +370,18 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option, break; #endif + case SOL_UDP: /* UDP protocol socket options (see include/netinet/udp.h) */ +#ifdef CONFIG_NET_UDPPROTO_OPTIONS + ret = udp_setsockopt(psock, option, value, value_len); + break; +#endif + /* These levels are defined in sys/socket.h, but are not yet * implemented. */ case SOL_IP: /* TCP protocol socket options (see include/netinet/ip.h) */ case SOL_IPV6: /* TCP protocol socket options (see include/netinet/ip6.h) */ - case SOL_UDP: /* TCP protocol socket options (see include/netinit/udp.h) */ ret = -ENOSYS; break; diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index e183277ec2..3be1135439 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -331,7 +331,7 @@ struct pollfd; /* Forward reference */ * * Description: * Initialize the TCP/IP connection structures. Called only once and only - * from the UIP layer at start-up in normal user mode. + * from the network layer at start-up. * ****************************************************************************/ diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 94b3681306..4047fbfda9 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -581,7 +581,7 @@ static inline int tcp_ipv6_bind(FAR struct tcp_conn_s *conn, * * Description: * Initialize the TCP/IP connection structures. Called only once and only - * from the UIP layer at start-up in normal user mode. + * from the network layer at start-up. * ****************************************************************************/ diff --git a/net/udp/Kconfig b/net/udp/Kconfig index 7deccfc4ca..757ec9078f 100644 --- a/net/udp/Kconfig +++ b/net/udp/Kconfig @@ -21,6 +21,15 @@ config NET_UDP_NO_STACK if NET_UDP && !NET_UDP_NO_STACK +config NET_UDP_BINDTODEVICE + bool "UDP Bind-to-device support" + default n + select NET_UDPPROTO_OPTIONS + ---help--- + Enable support for the UDP_BINDTODEVICE socket option. + Linux has SO_BINDTODEVICE but in NuttX this option is instead + specific to the UDP protocol. + config NET_UDP_CHECKSUMS bool "UDP checksums" default y if NET_IPv6 diff --git a/net/udp/Make.defs b/net/udp/Make.defs index 7cb743bfac..8b5650c3f4 100644 --- a/net/udp/Make.defs +++ b/net/udp/Make.defs @@ -42,6 +42,10 @@ ifneq ($(CONFIG_NET_UDP_NO_STACK),y) SOCK_CSRCS += udp_psock_send.c +ifeq ($(CONFIG_NET_UDPPROTO_OPTIONS),y) +SOCK_CSRCS += udp_setsockopt.c +endif + ifeq ($(CONFIG_NET_UDP_WRITE_BUFFERS),y) SOCK_CSRCS += udp_psock_sendto_buffered.c else diff --git a/net/udp/udp.h b/net/udp/udp.h index 35e29e788d..64ff97ea57 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -345,6 +345,35 @@ void udp_poll(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn); void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn); +/**************************************************************************** + * Name: udp_setsockopt + * + * Description: + * udp_setsockopt() sets the UDP-protocol option specified by the + * 'option' argument to the value pointed to by the 'value' argument for + * the socket specified by the 'psock' argument. + * + * See for the a complete list of values of UDP protocol + * options. + * + * Input Parameters: + * psock Socket structure of socket to operate on + * option identifies the option to set + * value Points to the argument value + * value_len The length of the argument value + * + * Returned Value: + * Returns zero (OK) on success. On failure, it returns a negated errno + * value to indicate the nature of the error. See psock_setcockopt() for + * the list of possible error values. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_UDPPROTO_OPTIONS +int udp_setsockopt(FAR struct socket *psock, int option, + FAR const void *value, socklen_t value_len); +#endif + /**************************************************************************** * Name: udp_wrbuffer_initialize * diff --git a/net/udp/udp_setsockopt.c b/net/udp/udp_setsockopt.c new file mode 100644 index 0000000000..7380638faf --- /dev/null +++ b/net/udp/udp_setsockopt.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * net/udp/udp_setsockopt.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "socket/socket.h" +#include "utils/utils.h" +#include "udp/udp.h" + +#ifdef CONFIG_NET_UDPPROTO_OPTIONS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: udp_setsockopt + * + * Description: + * udp_setsockopt() sets the UDP-protocol option specified by the + * 'option' argument to the value pointed to by the 'value' argument for + * the socket specified by the 'psock' argument. + * + * See for the a complete list of values of UDP protocol + * options. + * + * Input Parameters: + * psock Socket structure of socket to operate on + * option identifies the option to set + * value Points to the argument value + * value_len The length of the argument value + * + * Returned Value: + * Returns zero (OK) on success. On failure, it returns a negated errno + * value to indicate the nature of the error. See psock_setcockopt() for + * the list of possible error values. + * + ****************************************************************************/ + +int udp_setsockopt(FAR struct socket *psock, int option, + FAR const void *value, socklen_t value_len) +{ +#ifdef CONFIG_NET_UDP_BINDTODEVICE + /* Keep alive options are the only UDP protocol socket option currently + * supported. + */ + + FAR struct udp_conn_s *conn; + int ret; + + DEBUGASSERT(psock != NULL && value != NULL && psock->s_conn != NULL); + conn = (FAR struct udp_conn_s *)psock->s_conn; + + /* All of the UDP protocol options apply only UDP sockets. The sockets + * do not have to be connected.. that might occur later with the KeepAlive + * already configured. + */ + + if (psock->s_type != SOCK_STREAM) + { + nerr("ERROR: Not a UDP socket\n"); + return -ENOTCONN; + } + + /* Handle the Keep-Alive option */ + + switch (option) + { + /* Handle the SO_KEEPALIVE socket-level option. + * + * NOTE: SO_KEEPALIVE is not really a socket-level option; it is a + * protocol-level option. A given UDP connection may service multiple + * sockets (via dup'ing of the socket). There is, however, still only + * one connection to be monitored and that is a global attribute across + * all of the clones that may use the underlying connection. + */ + + case UDP_BINDTODEVICE: /* Bind socket to a specific network device */ + break; + + default: + nerr("ERROR: Unrecognized UDP option: %d\n", option); + ret = -ENOPROTOOPT; + break; + } + + return ret; +#else + return -ENOPROTOOPT; +#endif /* CONFIG_NET_UDP_BINDTODEVICE */ +} + +#endif /* CONFIG_NET_UDPPROTO_OPTIONS */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 529b891121..47ca079e42 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -35,6 +35,8 @@ "getpid","unistd.h","","pid_t" "getrandom","sys/random.h","defined(CONFIG_CRYPTO_RANDOM_POOL)","void","FAR void*","size_t" "getsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR void*","FAR socklen_t*" +"if_indextoname","net/if.h","CONFIG_NETDEV_IFINDEX","FAR char *","unsigned int","FAR char *" +"if_nametoindex","net/if.h","CONFIG_NETDEV_IFINDEX","unsigned int","FAR const char *" "insmod","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *","FAR const char *" "ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "kill","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","pid_t","int" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index e0b91642b0..ee3349d90d 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -211,6 +211,10 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) SYSCALL_LOOKUP(poll, 3, STUB_poll) SYSCALL_LOOKUP(select, 5, STUB_select) # endif +# ifdef CONFIG_NETDEV_IFINDEX + SYSCALL_LOOKUP(if_indextoname, 2, STUB_if_indextoname) + SYSCALL_LOOKUP(if_nametoindex, 1, STUB_if_nametoindex) +# endif # ifdef CONFIG_SERIAL_TERMIOS SYSCALL_LOOKUP(tcdrain, 1, STUB_tcdrain) # endif diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 26690f6a95..93afec5c9a 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -206,11 +206,20 @@ uintptr_t STUB_poll(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t STUB_select(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5); +/* Asynchronous I/O */ + uintptr_t STUB_aio_read(int nbr, uintptr_t parm1); uintptr_t STUB_aio_write(int nbr, uintptr_t parm1); uintptr_t STUB_aio_fsync(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_aio_cancel(int nbr, uintptr_t parm1, uintptr_t parm2); +/* Network interface indices */ + +uintptr_t STUB_if_indextoname(int nbr, uintptr_t parm1, uintptr_t parm2); +uintptr_t STUB_if_nametoindex(int nbr, uintptr_t parm1); + +/* Termios */ + uintptr_t STUB_tcdrain(int nbr, uintptr_t parm1); /* Board support */