source: rtems-libbsd/testsuite/include/rtems/bsd/test/default-network-init.h @ c6713d1

5-freebsd-12freebsd-9.3
Last change on this file since c6713d1 was c6713d1, checked in by Chris Johns <chrisj@…>, on Jun 27, 2016 at 3:15:11 AM

Add DEFAULT_NETWORK_PAGE_MBUFS_SIZE to allow per BSP allocation domain sizes.

  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*
2 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/stat.h>
33#include <sys/socket.h>
34
35#include <net/if.h>
36
37#include <assert.h>
38#include <fcntl.h>
39#include <ifaddrs.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <sysexits.h>
43
44#include <machine/rtems-bsd-commands.h>
45
46#include <rtems.h>
47#include <rtems/printer.h>
48#include <rtems/stackchk.h>
49#include <rtems/bsd/bsd.h>
50
51#if defined(DEFAULT_NETWORK_DHCPCD_ENABLE) && \
52    !defined(DEFAULT_NETWORK_NO_STATIC_IFCONFIG)
53#define DEFAULT_NETWORK_NO_STATIC_IFCONFIG
54#endif
55
56#ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
57#include <rtems/bsd/test/network-config.h>
58#endif
59
60#ifdef DEFAULT_NETWORK_SHELL
61#include <rtems/console.h>
62#include <rtems/shell.h>
63#endif
64
65static void
66default_network_set_self_prio(rtems_task_priority prio)
67{
68        rtems_status_code sc;
69
70        sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio);
71        assert(sc == RTEMS_SUCCESSFUL);
72}
73
74static void
75default_network_ifconfig_lo0(void)
76{
77        int exit_code;
78        char *lo0[] = {
79                "ifconfig",
80                "lo0",
81                "inet",
82                "127.0.0.1",
83                "netmask",
84                "255.255.255.0",
85                NULL
86        };
87        char *lo0_inet6[] = {
88                "ifconfig",
89                "lo0",
90                "inet6",
91                "::1",
92                "prefixlen",
93                "128",
94                "alias",
95                NULL
96        };
97
98        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0), lo0);
99        assert(exit_code == EX_OK);
100
101        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0_inet6), lo0_inet6);
102        assert(exit_code == EX_OK);
103}
104
105#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
106static void
107default_network_ifconfig_hwif0(char *ifname)
108{
109        int exit_code;
110        char *ifcfg[] = {
111                "ifconfig",
112                ifname,
113#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
114                "up",
115#else
116                "inet",
117                NET_CFG_SELF_IP,
118                "netmask",
119                NET_CFG_NETMASK,
120#endif
121                NULL
122        };
123
124        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg);
125        assert(exit_code == EX_OK);
126}
127
128static void
129default_network_route_hwif0(char *ifname)
130{
131#ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
132        int exit_code;
133        char *dflt_route[] = {
134                "route",
135                "add",
136                "-host",
137                NET_CFG_GATEWAY_IP,
138                "-iface",
139                ifname,
140                NULL
141        };
142        char *dflt_route2[] = {
143                "route",
144                "add",
145                "default",
146                NET_CFG_GATEWAY_IP,
147                NULL
148        };
149
150        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route), dflt_route);
151        assert(exit_code == EXIT_SUCCESS);
152
153        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route2), dflt_route2);
154        assert(exit_code == EXIT_SUCCESS);
155#endif
156}
157#endif
158
159#ifdef DEFAULT_NETWORK_DHCPCD_ENABLE
160static void
161default_network_dhcpcd_task(rtems_task_argument arg)
162{
163        int exit_code;
164        char *dhcpcd[] = {
165                "dhcpcd",
166                NULL
167        };
168
169        (void)arg;
170
171#ifdef DEFAULT_NETWORK_DHCPCD_NO_DHCP_DISCOVERY
172        static const char cfg[] = "nodhcp\nnodhcp6\n";
173        int fd;
174        int rv;
175        ssize_t n;
176
177        fd = open("/etc/dhcpcd.conf", O_CREAT | O_WRONLY,
178            S_IRWXU | S_IRWXG | S_IRWXO);
179        assert(fd >= 0);
180
181        n = write(fd, cfg, sizeof(cfg));
182        assert(n == (ssize_t) sizeof(cfg));
183
184        rv = close(fd);
185        assert(rv == 0);
186#endif
187
188        exit_code = rtems_bsd_command_dhcpcd(RTEMS_BSD_ARGC(dhcpcd), dhcpcd);
189        assert(exit_code == EXIT_SUCCESS);
190}
191#endif
192
193static void
194default_network_dhcpcd(void)
195{
196#ifdef DEFAULT_NETWORK_DHCPCD_ENABLE
197        rtems_status_code sc;
198        rtems_id id;
199
200        sc = rtems_task_create(
201                rtems_build_name('D', 'H', 'C', 'P'),
202                RTEMS_MAXIMUM_PRIORITY - 1,
203                2 * RTEMS_MINIMUM_STACK_SIZE,
204                RTEMS_DEFAULT_MODES,
205                RTEMS_FLOATING_POINT,
206                &id
207        );
208        assert(sc == RTEMS_SUCCESSFUL);
209
210        sc = rtems_task_start(id, default_network_dhcpcd_task, 0);
211        assert(sc == RTEMS_SUCCESSFUL);
212#endif
213}
214
215static void
216default_network_on_exit(int exit_code, void *arg)
217{
218        rtems_printer printer;
219
220        (void)arg;
221
222        rtems_print_printer_printf(&printer);
223        rtems_stack_checker_report_usage_with_plugin(&printer);
224
225        if (exit_code == 0) {
226                puts("*** END OF TEST " TEST_NAME " ***");
227        }
228}
229
230static void
231Init(rtems_task_argument arg)
232{
233        rtems_status_code sc;
234#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
235#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
236        char ifnamebuf[IF_NAMESIZE];
237#endif
238        char *ifname;
239#endif
240
241        (void)arg;
242        puts("*** " TEST_NAME " TEST ***");
243
244        on_exit(default_network_on_exit, NULL);
245
246#ifdef DEFAULT_EARLY_INITIALIZATION
247        early_initialization();
248#endif
249
250        /* Let other tasks run to complete background work */
251        default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1U);
252
253#ifdef DEFAULT_NETWORK_SHELL
254        sc = rtems_shell_init(
255                "SHLL",
256                32 * 1024,
257                1,
258                CONSOLE_DEVICE_NAME,
259                false,
260                false,
261                NULL
262        );
263        assert(sc == RTEMS_SUCCESSFUL);
264#endif
265
266#ifdef DEFAULT_NETWORK_PAGE_MBUFS_SIZE
267        rtems_bsd_allocator_domain_page_mbuf_size =
268          DEFAULT_NETWORK_PAGE_MBUFS_SIZE;
269#endif
270
271        rtems_bsd_initialize();
272
273#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
274#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
275        ifname = if_indextoname(1, &ifnamebuf[0]);
276        assert(ifname != NULL);
277#else
278        ifname = NET_CFG_INTERFACE_0;
279#endif
280#endif
281
282        /* Let the callout timer allocate its resources */
283        sc = rtems_task_wake_after(2);
284        assert(sc == RTEMS_SUCCESSFUL);
285
286        default_network_ifconfig_lo0();
287#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
288        default_network_ifconfig_hwif0(ifname);
289        default_network_route_hwif0(ifname);
290#endif
291        default_network_dhcpcd();
292
293        test_main();
294
295        assert(0);
296}
297
298#include <machine/rtems-bsd-sysinit.h>
299
300SYSINIT_NEED_NET_PF_UNIX;
301SYSINIT_NEED_NET_IF_LAGG;
302SYSINIT_NEED_NET_IF_VLAN;
303
304#include <bsp/nexus-devices.h>
305
306#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
307#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
308#define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
309#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER
310#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
311
312#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
313
314#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
315
316#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
317
318#define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 32
319#define CONFIGURE_UNLIMITED_OBJECTS
320#define CONFIGURE_UNIFIED_WORK_AREAS
321
322#define CONFIGURE_STACK_CHECKER_ENABLED
323
324#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (64 * 1024)
325#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4
326#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024)
327
328#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
329
330#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
331#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
332#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
333
334#define CONFIGURE_INIT
335
336#include <rtems/confdefs.h>
337
338#ifdef DEFAULT_NETWORK_SHELL
339
340#define CONFIGURE_SHELL_COMMANDS_INIT
341
342#include <bsp/irq-info.h>
343
344#include <rtems/netcmds-config.h>
345
346#define CONFIGURE_SHELL_USER_COMMANDS \
347  &bsp_interrupt_shell_command, \
348  &rtems_shell_BSD_Command, \
349  &rtems_shell_HOSTNAME_Command, \
350  &rtems_shell_PING_Command, \
351  &rtems_shell_ROUTE_Command, \
352  &rtems_shell_NETSTAT_Command, \
353  &rtems_shell_IFCONFIG_Command, \
354  &rtems_shell_TCPDUMP_Command, \
355  &rtems_shell_SYSCTL_Command
356
357#define CONFIGURE_SHELL_COMMAND_CPUUSE
358#define CONFIGURE_SHELL_COMMAND_PERIODUSE
359#define CONFIGURE_SHELL_COMMAND_STACKUSE
360#define CONFIGURE_SHELL_COMMAND_PROFREPORT
361
362#define CONFIGURE_SHELL_COMMAND_CP
363#define CONFIGURE_SHELL_COMMAND_PWD
364#define CONFIGURE_SHELL_COMMAND_LS
365#define CONFIGURE_SHELL_COMMAND_LN
366#define CONFIGURE_SHELL_COMMAND_LSOF
367#define CONFIGURE_SHELL_COMMAND_CHDIR
368#define CONFIGURE_SHELL_COMMAND_CD
369#define CONFIGURE_SHELL_COMMAND_MKDIR
370#define CONFIGURE_SHELL_COMMAND_RMDIR
371#define CONFIGURE_SHELL_COMMAND_CAT
372#define CONFIGURE_SHELL_COMMAND_MV
373#define CONFIGURE_SHELL_COMMAND_RM
374#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
375#define CONFIGURE_SHELL_COMMAND_SHUTDOWN
376
377#include <rtems/shellconfig.h>
378
379#endif /* DEFAULT_NETWORK_SHELL */
Note: See TracBrowser for help on using the repository browser.