diff options
author | Chris Johns <chrisj@rtems.org> | 2023-04-23 13:23:57 -1000 |
---|---|---|
committer | KinseyMoore <48726349+KinseyMoore@users.noreply.github.com> | 2023-04-25 21:45:23 -0500 |
commit | 91190eb2a762f89b7389605fbae2aae5644bc5e1 (patch) | |
tree | 2437376124eb6d614275777faa4891d071a25f5c | |
parent | waf: Remove config.ini support until needed (diff) | |
download | rtems-net-services-91190eb2a762f89b7389605fbae2aae5644bc5e1.tar.bz2 |
waf: Support for config.inc to handle NTP servers
- The config.inc fields are now optional
-rw-r--r-- | config.inc | 3 | ||||
-rw-r--r-- | net/legacy/net_adapter.c | 66 | ||||
-rw-r--r-- | net/libbsd/net_adapter.c | 6 | ||||
-rw-r--r-- | netservices.py | 49 | ||||
-rwxr-xr-x | testsuites/include/network-config.h.in | 47 | ||||
-rw-r--r-- | testsuites/ntp01/test_main.c | 9 |
6 files changed, 156 insertions, 24 deletions
diff --git a/config.inc b/config.inc new file mode 100644 index 0000000..f4411f4 --- /dev/null +++ b/config.inc @@ -0,0 +1,3 @@ +NET_CFG_IFACE = lo0 +NET_CFG_IFACE_OPTS = +NET_CFG_BOOT_PROT = dhcp diff --git a/net/legacy/net_adapter.c b/net/legacy/net_adapter.c index b622895..3f5542e 100644 --- a/net/legacy/net_adapter.c +++ b/net/legacy/net_adapter.c @@ -33,8 +33,72 @@ * SUCH DAMAGE. */ +#include <stdio.h> + +#include <rtems.h> +#include <rtems/dhcp.h> +#include <rtems/rtems_bsdnet.h> + +#include <bsp.h> + #include <net_adapter.h> +#include <network-config.h> + +static char* iface = NET_CFG_IFACE; +static char* boot_prot = NET_CFG_BOOT_PROT; + +static struct rtems_bsdnet_ifconfig ifcfg = { + RTEMS_BSP_NETWORK_DRIVER_NAME, + RTEMS_BSP_NETWORK_DRIVER_ATTACH +}; + +struct rtems_bsdnet_config rtems_bsdnet_config; + +static bool rtems_net_legacy_config(struct rtems_bsdnet_config* bsd) { + if (bsd->ifconfig == NULL) { + bsd->ifconfig = &ifcfg; + } + ifcfg.name = iface; +#ifdef NET_CFG_SELF_IP + ifcfg.ip_address = NET_CFG_SELF_IP; +#endif +#ifdef NET_CFG_NETMASK + ifcfg.ip_netmask = NET_CFG_NETMASK; +#endif +#ifdef NET_CFG_GATEWAY_IP + bsd->gateway = NET_CFG_GATEWAY_IP; +#endif +#ifdef NET_CFG_DOMAINNAME + bsd->domainname = NET_CFG_DOMAINNAME; +#endif +#ifdef NET_CFG_DNS_IP + bsd->name_server[0] = NET_CFG_DNS_IP; +#endif + if (strcmp(boot_prot, "static") == 0) { + bsd->bootp = NULL; + } else if (strcmp(boot_prot, "bootp") == 0) { + bsd->bootp = rtems_bsdnet_do_bootp; + } else if (strcmp(boot_prot, "dhcp") == 0) { + bsd->bootp = rtems_bsdnet_do_dhcp; + } else { + printf("%s: %d: invalid network configuration: %s\n", + __FILE__, __LINE__, boot_prot); + return false; + } + return true; +} + int net_start(void) { - return 1; + int rv; + rv = rtems_net_legacy_config(&rtems_bsdnet_config); + if (!rv) { + return -1; + } + rv = rtems_bsdnet_initialize_network(); + if (rv != 0) { + printf("error: legacy stack initialization failed\n"); + return -1; + } + return 0; } diff --git a/net/libbsd/net_adapter.c b/net/libbsd/net_adapter.c index 3760c89..561f15a 100644 --- a/net/libbsd/net_adapter.c +++ b/net/libbsd/net_adapter.c @@ -108,7 +108,7 @@ default_network_set_self_prio(rtems_task_priority prio) assert(sc == RTEMS_SUCCESSFUL); } -int net_start() +int net_start(void) { char *ifname; char ifnamebuf[IF_NAMESIZE]; @@ -129,11 +129,11 @@ int net_start() /* Let the callout timer allocate its resources */ sc = rtems_task_wake_after(2); assert(sc == RTEMS_SUCCESSFUL); - + rtems_bsd_ifconfig_lo0(); default_network_ifconfig_hwif0(ifname); default_network_dhcpcd(); - + // needs to wait for DHCP to finish return 0; } diff --git a/netservices.py b/netservices.py index ff76944..e9eeb0c 100644 --- a/netservices.py +++ b/netservices.py @@ -66,10 +66,14 @@ def net_config_header(bld): if not os.path.exists(bld.env.NET_CONFIG): bld.fatal('network configuraiton \'%s\' not found' % (bld.env.NET_CONFIG)) - net_tags = [ - 'NET_CFG_IFACE', 'NET_CFG_IFACE_OPTS', 'NET_CFG_BOOT_PROT', 'NET_CFG_SELF_IP', - 'NET_CFG_NETMASK', 'NET_CFG_MAC_ADDR', 'NET_CFG_GATEWAY_IP', - 'NET_CFG_DOMAINNNAME', 'NET_CFG_DNS_IP', 'NET_CFG_NTP_IP' + net_manditory_tags = [ + 'NET_CFG_IFACE', + 'NET_CFG_BOOT_PROT', + ] + net_optional_tags = [ + 'NET_CFG_IFACE_OPTS', 'NET_CFG_SELF_IP', 'NET_CFG_NETMASK', + 'NET_CFG_MAC_ADDR', 'NET_CFG_GATEWAY_IP', 'NET_CFG_DOMAINNAME', + 'NET_CFG_DNS_IP', 'NET_CFG_NTP_IP' ] try: net_cfg_lines = open(bld.env.NET_CONFIG).readlines() @@ -84,17 +88,24 @@ def net_config_header(bld): if not l.strip().startswith('NET_CFG_'): bld.fatal('network configuration \'%s\' ' \ 'invalid config: %d: %s' % (bld.env.NET_CONFIG, lc, l)) - ls = l.split('=') + ls = l.strip().split('#', 1)[0] + if len(ls) == 0: + continue + ls = ls.split('=') if len(ls) != 2: bld.fatal('network configuration \'%s\' ' \ 'parse error: %d: %s' % (bld.env.NET_CONFIG, lc, l)) lhs = ls[0].strip() rhs = ls[1].strip() - if lhs in net_tags: + if lhs in net_manditory_tags or lhs in net_optional_tags: net_defaults[lhs] = rhs else: bld.fatal('network configuration \'%s\' ' \ 'invalid config: %d: %s' % (bld.env.NET_CONFIG, lc, l)) + for cfg in net_manditory_tags: + if cfg not in net_defaults: + bld.fatal('network configuration \'%s\' ' \ + 'manditory config not found: %s' % (bld.env.NET_CONFIG, cfg)) for cfg in net_defaults: sed += "-e 's/@%s@/%s/' " % (cfg, net_defaults[cfg]) bld(target=bld.env.NETWORK_CONFIG, @@ -135,7 +146,8 @@ def check_net_lib(conf, lib, name): net_name = 'NET_' + name.upper() conf.check_cc(lib=lib, ldflags=['-lrtemsdefaultconfig'], - uselib_store=net_name, mandatory=False) + uselib_store=net_name, + mandatory=False) if 'LIB_' + net_name in conf.env: conf.env.NET_NAME = name # clean up the check @@ -159,9 +171,11 @@ def bsp_configure(conf, arch_bsp): add_flags(conf.env.CFLAGS, section_flags) add_flags(conf.env.CXXFLAGS, section_flags) - stacks = [check_net_lib(conf, 'bsd', 'libbsd'), - check_net_lib(conf, 'networking', 'legacy'), - check_net_lib(conf, 'lwip', 'lwip')] + stacks = [ + check_net_lib(conf, 'bsd', 'libbsd'), + check_net_lib(conf, 'networking', 'legacy'), + check_net_lib(conf, 'lwip', 'lwip') + ] stack_count = stacks.count(True) if stack_count == 0: conf.fatal('No networking stack found') @@ -185,7 +199,7 @@ def build(bld): net_inc = str(bld.path.find_node(os.path.join(net_root, 'include'))) net_adapter_source = net_root + '/net_adapter.c' - inc = bld.env.IFLAGS + ['include', net_inc] + inc = bld.env.IFLAGS + ['include', net_inc] cflags = ['-g', bld.env.OPTIMIZATION] ntp_source_files = [] @@ -236,20 +250,15 @@ def build(bld): if ext == '.h': subpath = removeprefix(removeprefix(path, root_path), "/") bld.install_files( - os.path.join("${PREFIX}", - arch_lib_path, - "include", - subpath), - os.path.join(path, name) - ) + os.path.join("${PREFIX}", arch_lib_path, "include", + subpath), os.path.join(path, name)) [install_headers(path) for path in ntp_incl] libs = ['rtemstest'] ntp_test_incl = ntp_incl + ['testsuites'] - ntp_test_sources = ['testsuites/ntp01/test_main.c', - net_adapter_source] + ntp_test_sources = ['testsuites/ntp01/test_main.c', net_adapter_source] bld.program(features='c', target='ntp01.exe', @@ -271,7 +280,7 @@ def build(bld): defines=[net_def], includes=ttcp_test_incl, lib=libs, - use=['ttcp', net_use]) + use=['ttcp', net_use]) tlnt_test_incl = inc + ['testsuites'] tlnt_test_sources = ['testsuites/telnetd01/init.c'] diff --git a/testsuites/include/network-config.h.in b/testsuites/include/network-config.h.in new file mode 100755 index 0000000..b5201b2 --- /dev/null +++ b/testsuites/include/network-config.h.in @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023. Chris Johns <chrisj@rtems.org>. All rights reserved. + * + * 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. + */ + +#ifndef _TEST_NETWORK_CONFIG_H_ +#define _TEST_NETWORK_CONFIG_H_ + +#define NET_CFG_IFACE "@NET_CFG_IFACE@" + +#define NET_CFG_BOOT_PROT "@NET_CFG_BOOT_PROT@" + +#define NET_CFG_SELF_IP "@NET_CFG_SELF_IP@" + +#define NET_CFG_NETMASK "@NET_CFG_NETMASK@" + +#define NET_CFG_MAC_ADDR "@NET_CFG_MAC_ADDR@" + +#define NET_CFG_GATEWAY_IP "@NET_CFG_GATEWAY_IP@" + +#define NET_CFG_DOMAINNAME "@NET_CFG_DOMAINNAME@" + +#define NET_CFG_DNS_IP "@NET_CFG_DNS_IP@" + +#define NET_CFG_NTP_IP "@NET_CFG_NTP_IP@" + +#endif /* _TEST_NETWORK_CONFIG_H_ */ diff --git a/testsuites/ntp01/test_main.c b/testsuites/ntp01/test_main.c index 76c2f9e..9e2db07 100644 --- a/testsuites/ntp01/test_main.c +++ b/testsuites/ntp01/test_main.c @@ -40,17 +40,26 @@ #include <net_adapter.h> #include <net_adapter_extra.h> +#include <network-config.h> #include <tmacros.h> const char rtems_test_name[] = "NTP 1"; static const char etc_resolv_conf[] = +#ifdef NET_CFG_NTP_IP + "nameserver " NET_CFG_DNS_IP "\n"; +#else "nameserver 8.8.8.8\n"; +#endif static const char etc_ntp_conf[] = "tos minclock 3 maxclock 6\n" +#ifdef NET_CFG_NTP_IP + "server " NET_CFG_NTP_IP "\n" +#else "pool 0.freebsd.pool.ntp.org iburst\n" +#endif "restrict default limited kod nomodify notrap noquery nopeer\n" "restrict source limited kod nomodify notrap noquery\n" "restrict 10.0.0.0 mask 255.0.0.0\n" |