diff options
Diffstat (limited to 'libbsd/libdl/dl_libbsd.c')
-rw-r--r-- | libbsd/libdl/dl_libbsd.c | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/libbsd/libdl/dl_libbsd.c b/libbsd/libdl/dl_libbsd.c new file mode 100644 index 0000000..71a1c7b --- /dev/null +++ b/libbsd/libdl/dl_libbsd.c @@ -0,0 +1,185 @@ +/* + * Copyright 2018 Chris Johns <chrisj@rtems.org> + * + * 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 <sys/param.h> + +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sysexits.h> +#include <unistd.h> + +#include <machine/rtems-bsd-rc-conf.h> +#include <machine/rtems-bsd-rc-conf-services.h> +#include <machine/rtems-bsd-commands.h> + +#include <rtems.h> +#include <rtems/console.h> +#include <rtems/shell.h> + +#define IFACE_IPV4(iface) \ + "ifconfig_" # iface "=\"inet " NET_CFG_SELF_IP " netmask " NET_CFG_NETMASK "\"\n" + +#define IFACE_ALIAS(iface) \ + "ifconfig_" # iface "_alias0=\"ether 10:22:33:44:55:66\"\n" \ + "ifconfig_" # iface "_alias1=\"inet 10.1.1.111 netmask 0xffffffff\"\n" + +#define RC_CONF_IFACES_IPV4 \ + IFACE_IPV4(dmc0) \ + IFACE_IPV4(sm0) \ + IFACE_IPV4(cgem0) \ + IFACE_IPV4(fec0) \ + IFACE_IPV4(em0) \ + IFACE_IPV4(re0) + +#define RC_CONF_IFACES_ALIAS \ + IFACE_ALIAS(dmc0) \ + IFACE_ALIAS(sm0) \ + IFACE_ALIAS(cgem0) \ + IFACE_ALIAS(fec0) \ + IFACE_ALIAS(em0) \ + IFACE_ALIAS(re0) + +#define RC_CONF_IFACES \ + RC_CONF_IFACES_IPV4 \ + RC_CONF_IFACES_ALIAS + +#define IFACE_VLAN(iface) \ + "vlans_" # iface "=\"101 102\"\n" \ + "ifconfig_" # iface "_101=\"inet 192.0.101.1/24\"\n" \ + "ifconfig_" # iface "_102=\"DHCP\"\n" + +#define RC_CONF_VLANS \ + IFACE_VLAN(dmc0) \ + IFACE_VLAN(sm0) \ + IFACE_VLAN(cgem0) \ + IFACE_VLAN(fec0) \ + IFACE_VLAN(em0) \ + IFACE_VLAN(re0) + +static const char* rc_conf_text = \ + "#\n" \ + "# Tests rc.conf. Add every NIC\n" \ + "#\n" \ + "\n" \ + "syslog_priority=\"debug\"\n" \ + "\n" \ + "hostname=\"rctest\"\n" \ + "\n" \ + "create_args_myvlan=\"vlan 102\"\n" \ + "create_args_yourvlan=\"vlan 202\"\n" \ + "\n" \ + RC_CONF_IFACES \ + "\n" \ + RC_CONF_VLANS \ + "\n" \ + "defaultrouter=\"" NET_CFG_GATEWAY_IP "\"\n" \ + "defaultroute_delay=\"5\"\n" \ + "\n" \ + "dhcpcd_options=\"-h foobar\"\n" \ + "\n" \ + "telnetd_enable=\"YES\"\n" \ + "telnetd_options=\"-v -C 10 -P 50 -L\"\n" \ + "\n" \ + "ftpd_enable=\"YES\"\n" \ + "ftpd_options=\"-v -p 21 -C 10 -P 150 -L -I 10 -R /\"\n" \ + "\n" \ + "pf_enable=\"YES\"\n" \ + "pf_rules=\"/etc/mypf.conf\"\n" \ + "pf_flags=\"-q -z\"\n" \ + "\n"; + +static const char* pf_conf_text = "pass all\n"; +static const char* pf_os_text = "# empty\n"; + +static void +test_rc_conf_script(void) +{ + const char* ifconfg_args[] = { + "ifconfig", NULL + }; + const char* netstat_args[] = { + "netstat", "-rn", NULL + }; + const char* pfctl_args[] = { + "pfctl", "-s", "rules", NULL + }; + + printf("--------------- rc.conf -----------------\n"); + printf(rc_conf_text); + printf("-----------------------------------------\n"); + + assert(rtems_bsd_run_rc_conf_script("internal", rc_conf_text, 15, true) == 0); + + printf("-------------- IFCONFIG -----------------\n"); + rtems_bsd_command_ifconfig(1, (char**) ifconfg_args); + printf("-------------- NETSTAT ------------------\n"); + rtems_bsd_command_netstat(2, (char**) netstat_args); + printf("-------------- PFCTL --------------------\n"); + rtems_bsd_command_pfctl(RTEMS_BSD_ARGC(pfctl_args), (char **) pfctl_args); + printf("-----------------------------------------\n"); +} + +static void +waiter(int fd, int secs, void *arg) +{ + int* toggle = (int*) arg; + const char* toggles = "|/-|\\-"; + printf("\b%c", toggles[*toggle]); + fflush(stdout); + ++(*toggle); + if (*toggle >= 6) + *toggle = 0; +} + +static void +shell(void) +{ + int toggle = 1; + rtems_status_code sc; + printf("Press any key for the shell .... -"); + fflush(stdout); + sc = rtems_shell_wait_for_input(STDIN_FILENO, 10, waiter, &toggle); + if (sc == RTEMS_SUCCESSFUL) { + rtems_shell_init("SHLL", + 32 * 1024, + 1, + CONSOLE_DEVICE_NAME, + false, + true, + NULL); + } +} + +void +rtems_main(void) +{ + test_rc_conf_script(); + shell(); +} |