[PATCH 2/3] ifmcstat: Port to RTEMS
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Sep 10 07:51:43 UTC 2020
---
Makefile.todo | 1 +
freebsd/usr.sbin/ifmcstat/ifmcstat.c | 49 ++++++++++++++++++-
freebsd/usr.sbin/ifmcstat/printb.c | 5 ++
.../ifmcstat/rtems-bsd-ifmcstat-data.h | 4 ++
.../rtems-bsd-ifmcstat-ifmcstat-data.h | 7 +++
.../ifmcstat/rtems-bsd-ifmcstat-namespace.h | 5 ++
.../ifmcstat/rtems-bsd-ifmcstat-printb-data.h | 4 ++
libbsd.py | 3 ++
rtemsbsd/include/machine/rtems-bsd-commands.h | 2 +
rtemsbsd/include/rtems/netcmds-config.h | 4 ++
rtemsbsd/rtems/rtems-bsd-shell-ifmcstat.c | 36 ++++++++++++++
testsuite/media01/test_main.c | 1 +
12 files changed, 119 insertions(+), 2 deletions(-)
create mode 100644 freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-data.h
create mode 100644 freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-ifmcstat-data.h
create mode 100644 freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-namespace.h
create mode 100644 freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-printb-data.h
create mode 100644 rtemsbsd/rtems/rtems-bsd-shell-ifmcstat.c
diff --git a/Makefile.todo b/Makefile.todo
index a05716ef..36951c55 100644
--- a/Makefile.todo
+++ b/Makefile.todo
@@ -86,6 +86,7 @@ program-header:
cd freebsd/tools/tools/net80211/wlanstats && $(BASE)/userspace-header-gen.py $(BUILD_BSP)/freebsd/tools/tools/net80211/wlanstats/*.o -p wlanstats
cd freebsd/usr.bin/netstat && $(BASE)/userspace-header-gen.py $(BUILD_BSP)/freebsd/usr.bin/netstat/*.o -p netstat
cd freebsd/usr.sbin/arp && $(BASE)/userspace-header-gen.py $(BUILD_BSP)/freebsd/usr.sbin/arp/*.o -p arp
+ cd freebsd/usr.sbin/ifmcstat && $(BASE)/userspace-header-gen.py $(BUILD_BSP)/freebsd/usr.sbin/ifmcstat/*.o -p ifmcstat
cd ipsec-tools/src/racoon && $(BASE)/userspace-header-gen.py $(BUILD_BSP)/ipsec-tools/src/racoon/*.o -p racoon
cd ipsec-tools/src/setkey && $(BASE)/userspace-header-gen.py $(BUILD_BSP)/ipsec-tools/src/setkey/*.o -p setkey
diff --git a/freebsd/usr.sbin/ifmcstat/ifmcstat.c b/freebsd/usr.sbin/ifmcstat/ifmcstat.c
index d28e54bc..19acaf62 100644
--- a/freebsd/usr.sbin/ifmcstat/ifmcstat.c
+++ b/freebsd/usr.sbin/ifmcstat/ifmcstat.c
@@ -1,5 +1,10 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifmcstat-namespace.h"
+#include "rtems-bsd-ifmcstat-ifmcstat-data.h"
+#endif /* __rtems__ */
+
/* $KAME: ifmcstat.c,v 1.48 2006/11/15 05:13:59 itojun Exp $ */
/*-
@@ -34,6 +39,13 @@
* SUCH DAMAGE.
*/
+#ifdef __rtems__
+#define __need_getopt_newlib
+#include <getopt.h>
+#include <machine/rtems-bsd-program.h>
+#include <machine/rtems-bsd-commands.h>
+#include <rtems/libio_.h>
+#endif /* __rtems__ */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -112,11 +124,20 @@ union sockunion {
};
typedef union sockunion sockunion_t;
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
uint32_t ifindex = 0;
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
int af = AF_UNSPEC;
#ifdef WITH_KVM
int Kflag = 0;
#endif
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
int vflag = 0;
#define sa_dl_equal(a1, a2) \
@@ -170,7 +191,31 @@ static const char * inm_mode(u_int mode);
static void in6_ifinfo(struct mld_ifinfo *);
static const char * inet6_n2a(struct in6_addr *, uint32_t);
#endif
+#ifdef __rtems__
+static int main(int argc, char *argv[]);
+
+RTEMS_LINKER_RWSET(bsd_prog_ifmcstat, char);
+
+int
+rtems_bsd_command_ifmcstat(int argc, char *argv[])
+{
+ int exit_code;
+ void *data_begin;
+ size_t data_size;
+
+ data_begin = RTEMS_LINKER_SET_BEGIN(bsd_prog_ifmcstat);
+ data_size = RTEMS_LINKER_SET_SIZE(bsd_prog_ifmcstat);
+
+ rtems_bsd_program_lock();
+ exit_code = rtems_bsd_program_call_main_with_data_restore("ifmcstat",
+ main, argc, argv, data_begin, data_size);
+ rtems_bsd_program_unlock();
+
+ return exit_code;
+}
+#else /* __rtems__ */
int main(int, char **);
+#endif /* __rtems__ */
static void
usage()
@@ -186,7 +231,7 @@ usage()
exit(EX_USAGE);
}
-static const char *options = "i:f:vM:N:"
+static const char * const options = "i:f:vM:N:"
#ifdef WITH_KVM
"K"
#endif
@@ -310,7 +355,7 @@ in_ifinfo(struct igmp_ifinfo *igi)
printf("\n");
}
-static const char *inm_modes[] = {
+static const char * const inm_modes[] = {
"undefined",
"include",
"exclude",
diff --git a/freebsd/usr.sbin/ifmcstat/printb.c b/freebsd/usr.sbin/ifmcstat/printb.c
index d94923fe..2c979951 100644
--- a/freebsd/usr.sbin/ifmcstat/printb.c
+++ b/freebsd/usr.sbin/ifmcstat/printb.c
@@ -1,5 +1,10 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifmcstat-namespace.h"
+#include "rtems-bsd-ifmcstat-printb-data.h"
+#endif /* __rtems__ */
+
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
diff --git a/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-data.h b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-data.h
new file mode 100644
index 00000000..e94df9c0
--- /dev/null
+++ b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-data.h
@@ -0,0 +1,4 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+/* ifmcstat.c */
+/* printb.c */
diff --git a/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-ifmcstat-data.h b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-ifmcstat-data.h
new file mode 100644
index 00000000..39287947
--- /dev/null
+++ b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-ifmcstat-data.h
@@ -0,0 +1,7 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifmcstat-data.h"
+/* ifmcstat.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifmcstat, static int af);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifmcstat, static int vflag);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifmcstat, static uint32_t ifindex);
diff --git a/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-namespace.h b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-namespace.h
new file mode 100644
index 00000000..78414818
--- /dev/null
+++ b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-namespace.h
@@ -0,0 +1,5 @@
+/* generated by userspace-header-gen.py */
+/* ifmcstat.c */
+#define main _bsd_ifmcstat_main
+/* printb.c */
+#define printb _bsd_ifmcstat_printb
diff --git a/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-printb-data.h b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-printb-data.h
new file mode 100644
index 00000000..3f74bd60
--- /dev/null
+++ b/freebsd/usr.sbin/ifmcstat/rtems-bsd-ifmcstat-printb-data.h
@@ -0,0 +1,4 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifmcstat-data.h"
+/* printb.c */
diff --git a/libbsd.py b/libbsd.py
index 20086568..6a471873 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -186,6 +186,7 @@ class rtems(builder.Module):
'rtems/rtems-bsd-set-if-input.c',
'rtems/rtems-bsd-shell-arp.c',
'rtems/rtems-bsd-shell-ifconfig.c',
+ 'rtems/rtems-bsd-shell-ifmcstat.c',
'rtems/rtems-bsd-shell-netstat.c',
'rtems/rtems-bsd-shell-nvmecontrol.c',
'rtems/rtems-bsd-shell-pfctl.c',
@@ -3026,6 +3027,8 @@ class user_space(builder.Module):
'usr.bin/netstat/unix.c',
'usr.bin/vmstat/vmstat.c',
'usr.sbin/arp/arp.c',
+ 'usr.sbin/ifmcstat/ifmcstat.c',
+ 'usr.sbin/ifmcstat/printb.c',
],
mm.generator['source'](['-DINET'])
)
diff --git a/rtemsbsd/include/machine/rtems-bsd-commands.h b/rtemsbsd/include/machine/rtems-bsd-commands.h
index 036734ee..d314471f 100644
--- a/rtemsbsd/include/machine/rtems-bsd-commands.h
+++ b/rtemsbsd/include/machine/rtems-bsd-commands.h
@@ -50,6 +50,8 @@ int rtems_bsd_command_arp(int argc, char **argv);
int rtems_bsd_command_ifconfig(int argc, char **argv);
+int rtems_bsd_command_ifmcstat(int argc, char **argv);
+
int rtems_bsd_command_netstat(int argc, char **argv);
int rtems_bsd_command_nvmecontrol(int argc, char **argv);
diff --git a/rtemsbsd/include/rtems/netcmds-config.h b/rtemsbsd/include/rtems/netcmds-config.h
index bba2d307..bc493af4 100644
--- a/rtemsbsd/include/rtems/netcmds-config.h
+++ b/rtemsbsd/include/rtems/netcmds-config.h
@@ -30,7 +30,11 @@ extern rtems_shell_cmd_t rtems_shell_PING_Command;
extern rtems_shell_cmd_t rtems_shell_PING6_Command;
extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command;
+
+extern rtems_shell_cmd_t rtems_shell_IFMCSTAT_Command;
+
extern rtems_shell_cmd_t rtems_shell_ROUTE_Command;
+
extern rtems_shell_cmd_t rtems_shell_NETSTAT_Command;
extern rtems_shell_cmd_t rtems_shell_DHCPCD_Command;
diff --git a/rtemsbsd/rtems/rtems-bsd-shell-ifmcstat.c b/rtemsbsd/rtems/rtems-bsd-shell-ifmcstat.c
new file mode 100644
index 00000000..c8fbd4a1
--- /dev/null
+++ b/rtemsbsd/rtems/rtems-bsd-shell-ifmcstat.c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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 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.
+ */
+
+#include <rtems/netcmds-config.h>
+#include <machine/rtems-bsd-commands.h>
+
+rtems_shell_cmd_t rtems_shell_IFMCSTAT_Command = {
+ .name = "ifmcstat",
+ .usage = "ifmcstat [args]",
+ .topic = "net",
+ .command = rtems_bsd_command_ifmcstat
+};
diff --git a/testsuite/media01/test_main.c b/testsuite/media01/test_main.c
index 09d0b9e2..dcab3220 100644
--- a/testsuite/media01/test_main.c
+++ b/testsuite/media01/test_main.c
@@ -240,6 +240,7 @@ early_initialization(void)
&rtems_shell_NETSTAT_Command, \
&rtems_shell_SYSCTL_Command, \
&rtems_shell_IFCONFIG_Command, \
+ &rtems_shell_IFMCSTAT_Command, \
&rtems_shell_VMSTAT_Command
#define CONFIGURE_SHELL_COMMAND_CPUINFO
--
2.26.2
More information about the devel
mailing list