From 64c663c0d1341d208891e68a7e2c857485754f99 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 10 Jan 2017 08:04:58 +0100 Subject: ARP(8): Port to RTEMS --- freebsd/usr.sbin/arp/arp.c | 57 +++++++++++++++++++++- freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h | 14 ++++++ freebsd/usr.sbin/arp/rtems-bsd-arp-data.h | 3 ++ freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h | 2 + libbsd.py | 2 + libbsd_waf.py | 4 +- rtemsbsd/include/machine/rtems-bsd-commands.h | 2 + rtemsbsd/include/rtems/netcmds-config.h | 2 + rtemsbsd/rtems/rtems-bsd-shell-arp.c | 40 +++++++++++++++ .../include/rtems/bsd/test/default-network-init.h | 1 + testsuite/media01/test_main.c | 1 + testsuite/netshell01/shellconfig.c | 1 + 12 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h create mode 100644 freebsd/usr.sbin/arp/rtems-bsd-arp-data.h create mode 100644 freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h create mode 100644 rtemsbsd/rtems/rtems-bsd-shell-arp.c diff --git a/freebsd/usr.sbin/arp/arp.c b/freebsd/usr.sbin/arp/arp.c index 951d6f5c..5a85f252 100644 --- a/freebsd/usr.sbin/arp/arp.c +++ b/freebsd/usr.sbin/arp/arp.c @@ -1,5 +1,9 @@ #include +#ifdef __rtems__ +#include "rtems-bsd-arp-namespace.h" +#endif /* __rtems__ */ + /* * Copyright (c) 1984, 1993 * The Regents of the University of California. All rights reserved. @@ -51,6 +55,12 @@ __FBSDID("$FreeBSD$"); */ +#ifdef __rtems__ +#define __need_getopt_newlib +#include +#include +#include +#endif /* __rtems__ */ #include #include #include @@ -81,6 +91,13 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef __rtems__ +#include "rtems-bsd-arp-arp-data.h" +static struct timespec tp; +static int seq; +static int s = -1; +static pid_t pid; +#endif /* __rtems__ */ typedef void (action_fn)(struct sockaddr_dl *sdl, struct sockaddr_in *s_in, struct rt_msghdr *rtm); @@ -106,7 +123,7 @@ static char *rifname; static time_t expire_time; static int flags, doing_proxy; -struct if_nameindex *ifnameindex; +static struct if_nameindex *ifnameindex; /* which function we're supposed to do */ #define F_GET 1 @@ -117,12 +134,44 @@ struct if_nameindex *ifnameindex; #define SETFUNC(f) { if (func) usage(); func = (f); } +#ifdef __rtems__ +static int main(int argc, char *argv[]); + +RTEMS_LINKER_RWSET(bsd_prog_arp, char); + +int +rtems_bsd_command_arp(int argc, char *argv[]) +{ + int exit_code; + void *data_begin; + size_t data_size; + + data_begin = RTEMS_LINKER_SET_BEGIN(bsd_prog_arp); + data_size = RTEMS_LINKER_SET_SIZE(bsd_prog_arp); + + rtems_bsd_program_lock(); + exit_code = rtems_bsd_program_call_main_with_data_restore("arp", + main, argc, argv, data_begin, data_size); + rtems_bsd_program_unlock(); + + return exit_code; +} +#endif /* __rtems__ */ int main(int argc, char *argv[]) { int ch, func = 0; int rtn = 0; int aflag = 0; /* do it for all entries */ +#ifdef __rtems__ + struct getopt_data getopt_data; + memset(&getopt_data, 0, sizeof(getopt_data)); +#define optind getopt_data.optind +#define optarg getopt_data.optarg +#define opterr getopt_data.opterr +#define optopt getopt_data.optopt +#define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data) +#endif /* __rtems__ */ while ((ch = getopt(argc, argv, "andfsSi:")) != -1) switch(ch) { @@ -619,7 +668,9 @@ print_entry(struct sockaddr_dl *sdl, if (rtm->rtm_rmx.rmx_expire == 0) printf(" permanent"); else { +#ifndef __rtems__ static struct timespec tp; +#endif /* __rtems__ */ if (tp.tv_sec == 0) clock_gettime(CLOCK_MONOTONIC, &tp); if ((expire_time = rtm->rtm_rmx.rmx_expire - tp.tv_sec) > 0) @@ -703,12 +754,16 @@ usage(void) static struct rt_msghdr * rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl *sdl) { +#ifndef __rtems__ static int seq; +#endif /* __rtems__ */ int rlen; int l; struct sockaddr_in so_mask, *som = &so_mask; +#ifndef __rtems__ static int s = -1; static pid_t pid; +#endif /* __rtems__ */ static struct { struct rt_msghdr m_rtm; diff --git a/freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h b/freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h new file mode 100644 index 00000000..b50ea220 --- /dev/null +++ b/freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h @@ -0,0 +1,14 @@ +/* generated by userspace-header-gen.py */ +#include +#include "rtems-bsd-arp-data.h" +/* arp.c */ +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int nflag); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static char *rifname); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static time_t expire_time); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int flags); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int doing_proxy); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static struct if_nameindex *ifnameindex); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static struct timespec tp); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int seq); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int s); +RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static pid_t pid); diff --git a/freebsd/usr.sbin/arp/rtems-bsd-arp-data.h b/freebsd/usr.sbin/arp/rtems-bsd-arp-data.h new file mode 100644 index 00000000..cd210b1d --- /dev/null +++ b/freebsd/usr.sbin/arp/rtems-bsd-arp-data.h @@ -0,0 +1,3 @@ +/* generated by userspace-header-gen.py */ +#include +/* arp.c */ diff --git a/freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h b/freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h new file mode 100644 index 00000000..71a22796 --- /dev/null +++ b/freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h @@ -0,0 +1,2 @@ +/* generated by userspace-header-gen.py */ +/* arp.c */ diff --git a/libbsd.py b/libbsd.py index 4033a26e..dba932ab 100755 --- a/libbsd.py +++ b/libbsd.py @@ -70,6 +70,7 @@ def rtems(mm): 'rtems/rtems-bsd-rc-conf-pf.c', 'rtems/rtems-bsd-rc-conf.c', 'rtems/rtems-bsd-shell.c', + 'rtems/rtems-bsd-shell-arp.c', 'rtems/rtems-bsd-shell-ifconfig.c', 'rtems/rtems-bsd-shell-netstat.c', 'rtems/rtems-bsd-shell-pfctl.c', @@ -2219,6 +2220,7 @@ def user_space(mm): 'usr.bin/netstat/sctp.c', 'usr.bin/netstat/unix.c', 'usr.bin/vmstat/vmstat.c', + 'usr.sbin/arp/arp.c', ], mm.generator['source'](['-DINET6', '-DINET']) ) diff --git a/libbsd_waf.py b/libbsd_waf.py index ff34ad9a..0d7f8636 100644 --- a/libbsd_waf.py +++ b/libbsd_waf.py @@ -447,7 +447,8 @@ def build(bld): 'freebsd/usr.bin/netstat/route.c', 'freebsd/usr.bin/netstat/sctp.c', 'freebsd/usr.bin/netstat/unix.c', - 'freebsd/usr.bin/vmstat/vmstat.c'] + 'freebsd/usr.bin/vmstat/vmstat.c', + 'freebsd/usr.sbin/arp/arp.c'] bld.objects(target = "objs01", features = "c", cflags = cflags, @@ -1099,6 +1100,7 @@ def build(bld): 'rtemsbsd/rtems/rtems-bsd-rc-conf-net.c', 'rtemsbsd/rtems/rtems-bsd-rc-conf-pf.c', 'rtemsbsd/rtems/rtems-bsd-rc-conf.c', + 'rtemsbsd/rtems/rtems-bsd-shell-arp.c', 'rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c', 'rtemsbsd/rtems/rtems-bsd-shell-ifconfig.c', 'rtemsbsd/rtems/rtems-bsd-shell-netstat.c', diff --git a/rtemsbsd/include/machine/rtems-bsd-commands.h b/rtemsbsd/include/machine/rtems-bsd-commands.h index a6b03391..52137b02 100644 --- a/rtemsbsd/include/machine/rtems-bsd-commands.h +++ b/rtemsbsd/include/machine/rtems-bsd-commands.h @@ -46,6 +46,8 @@ __BEGIN_DECLS +int rtems_bsd_command_arp(int argc, char **argv); + int rtems_bsd_command_ifconfig(int argc, char **argv); int rtems_bsd_command_netstat(int argc, char **argv); diff --git a/rtemsbsd/include/rtems/netcmds-config.h b/rtemsbsd/include/rtems/netcmds-config.h index 818fd351..53ba255e 100644 --- a/rtemsbsd/include/rtems/netcmds-config.h +++ b/rtemsbsd/include/rtems/netcmds-config.h @@ -22,6 +22,8 @@ extern "C" { #endif /* __cplusplus */ +extern rtems_shell_cmd_t rtems_shell_ARP_Command; + extern rtems_shell_cmd_t rtems_shell_BSD_Command; extern rtems_shell_cmd_t rtems_shell_PFCTL_Command; diff --git a/rtemsbsd/rtems/rtems-bsd-shell-arp.c b/rtemsbsd/rtems/rtems-bsd-shell-arp.c new file mode 100644 index 00000000..2e3eed42 --- /dev/null +++ b/rtemsbsd/rtems/rtems-bsd-shell-arp.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +#include + +rtems_shell_cmd_t rtems_shell_ARP_Command = { + .name = "arp", + .usage = "arp [args]", + .topic = "net", + .command = rtems_bsd_command_arp +}; diff --git a/testsuite/include/rtems/bsd/test/default-network-init.h b/testsuite/include/rtems/bsd/test/default-network-init.h index 707347c6..db07d2aa 100644 --- a/testsuite/include/rtems/bsd/test/default-network-init.h +++ b/testsuite/include/rtems/bsd/test/default-network-init.h @@ -357,6 +357,7 @@ Init(rtems_task_argument arg) #define CONFIGURE_SHELL_USER_COMMANDS \ &bsp_interrupt_shell_command, \ + &rtems_shell_ARP_Command, \ &rtems_shell_BSD_Command, \ &rtems_shell_HOSTNAME_Command, \ &rtems_shell_PING_Command, \ diff --git a/testsuite/media01/test_main.c b/testsuite/media01/test_main.c index f7847130..4dd4a98c 100644 --- a/testsuite/media01/test_main.c +++ b/testsuite/media01/test_main.c @@ -199,6 +199,7 @@ early_initialization(void) #define CONFIGURE_SHELL_USER_COMMANDS \ &bsp_interrupt_shell_command, \ + &rtems_shell_ARP_Command, \ &rtems_shell_BSD_Command, \ &rtems_shell_HOSTNAME_Command, \ &rtems_shell_PING_Command, \ diff --git a/testsuite/netshell01/shellconfig.c b/testsuite/netshell01/shellconfig.c index 5b59acff..a5c1fba2 100644 --- a/testsuite/netshell01/shellconfig.c +++ b/testsuite/netshell01/shellconfig.c @@ -10,6 +10,7 @@ #define CONFIGURE_SHELL_COMMANDS_ALL #define CONFIGURE_SHELL_USER_COMMANDS \ + &rtems_shell_ARP_Command, \ &rtems_shell_SYSCTL_Command, \ &rtems_shell_HOSTNAME_Command, \ &rtems_shell_PING_Command, \ -- cgit v1.2.3