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 <net/if.h> |
---|
33 | |
---|
34 | #include <assert.h> |
---|
35 | #include <ifaddrs.h> |
---|
36 | #include <stdio.h> |
---|
37 | #include <stdlib.h> |
---|
38 | #include <sysexits.h> |
---|
39 | |
---|
40 | #include <machine/rtems-bsd-commands.h> |
---|
41 | |
---|
42 | #include <rtems.h> |
---|
43 | #include <rtems/stackchk.h> |
---|
44 | #include <rtems/bsd/bsd.h> |
---|
45 | |
---|
46 | #ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
47 | #include <rtems/bsd/test/network-config.h> |
---|
48 | #endif |
---|
49 | |
---|
50 | static void |
---|
51 | default_network_set_self_prio(rtems_task_priority prio) |
---|
52 | { |
---|
53 | rtems_status_code sc; |
---|
54 | |
---|
55 | sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio); |
---|
56 | assert(sc == RTEMS_SUCCESSFUL); |
---|
57 | } |
---|
58 | |
---|
59 | static void |
---|
60 | default_network_ifconfig_lo0(void) |
---|
61 | { |
---|
62 | int exit_code; |
---|
63 | char *lo0[] = { |
---|
64 | "ifconfig", |
---|
65 | "lo0", |
---|
66 | "inet", |
---|
67 | "127.0.0.1", |
---|
68 | "netmask", |
---|
69 | "255.255.255.0", |
---|
70 | NULL |
---|
71 | }; |
---|
72 | char *lo0_inet6[] = { |
---|
73 | "ifconfig", |
---|
74 | "lo0", |
---|
75 | "inet6", |
---|
76 | "::1", |
---|
77 | "prefixlen", |
---|
78 | "128", |
---|
79 | NULL |
---|
80 | }; |
---|
81 | |
---|
82 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0), lo0); |
---|
83 | assert(exit_code == EX_OK); |
---|
84 | |
---|
85 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0_inet6), lo0_inet6); |
---|
86 | assert(exit_code == EX_OK); |
---|
87 | } |
---|
88 | |
---|
89 | static void |
---|
90 | default_network_ifconfig_hwif0(char *ifname) |
---|
91 | { |
---|
92 | int exit_code; |
---|
93 | char *ifcfg[] = { |
---|
94 | "ifconfig", |
---|
95 | ifname, |
---|
96 | #ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
97 | "up", |
---|
98 | #else |
---|
99 | "inet", |
---|
100 | NET_CFG_SELF_IP, |
---|
101 | "netmask", |
---|
102 | NET_CFG_NETMASK, |
---|
103 | #endif |
---|
104 | NULL |
---|
105 | }; |
---|
106 | |
---|
107 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg); |
---|
108 | assert(exit_code == EX_OK); |
---|
109 | } |
---|
110 | |
---|
111 | static void |
---|
112 | default_network_route_hwif0(char *ifname) |
---|
113 | { |
---|
114 | #ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
115 | int exit_code; |
---|
116 | char *dflt_route[] = { |
---|
117 | "route", |
---|
118 | "add", |
---|
119 | "-host", |
---|
120 | NET_CFG_GATEWAY_IP, |
---|
121 | "-iface", |
---|
122 | ifname, |
---|
123 | NULL |
---|
124 | }; |
---|
125 | char *dflt_route2[] = { |
---|
126 | "route", |
---|
127 | "add", |
---|
128 | "default", |
---|
129 | NET_CFG_GATEWAY_IP, |
---|
130 | NULL |
---|
131 | }; |
---|
132 | |
---|
133 | exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route), dflt_route); |
---|
134 | assert(exit_code == EXIT_SUCCESS); |
---|
135 | |
---|
136 | exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route2), dflt_route2); |
---|
137 | assert(exit_code == EXIT_SUCCESS); |
---|
138 | #endif |
---|
139 | } |
---|
140 | |
---|
141 | static void |
---|
142 | default_network_on_exit(int exit_code, void *arg) |
---|
143 | { |
---|
144 | rtems_stack_checker_report_usage_with_plugin(NULL, |
---|
145 | rtems_printf_plugin); |
---|
146 | |
---|
147 | if (exit_code == 0) { |
---|
148 | puts("*** END OF TEST " TEST_NAME " ***"); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | static void |
---|
153 | Init(rtems_task_argument arg) |
---|
154 | { |
---|
155 | rtems_status_code sc; |
---|
156 | #ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
157 | char ifnamebuf[IF_NAMESIZE]; |
---|
158 | #endif |
---|
159 | char *ifname; |
---|
160 | |
---|
161 | puts("*** " TEST_NAME " TEST ***"); |
---|
162 | |
---|
163 | on_exit(default_network_on_exit, NULL); |
---|
164 | |
---|
165 | /* Let other tasks run to complete background work */ |
---|
166 | default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1); |
---|
167 | |
---|
168 | rtems_bsd_initialize(); |
---|
169 | |
---|
170 | #ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
171 | ifname = if_indextoname(1, &ifnamebuf[0]); |
---|
172 | assert(ifname != NULL); |
---|
173 | #else |
---|
174 | ifname = NET_CFG_INTERFACE_0; |
---|
175 | #endif |
---|
176 | |
---|
177 | /* Let the callout timer allocate its resources */ |
---|
178 | sc = rtems_task_wake_after(2); |
---|
179 | assert(sc == RTEMS_SUCCESSFUL); |
---|
180 | |
---|
181 | default_network_ifconfig_lo0(); |
---|
182 | default_network_ifconfig_hwif0(ifname); |
---|
183 | default_network_route_hwif0(ifname); |
---|
184 | |
---|
185 | test_main(); |
---|
186 | |
---|
187 | assert(0); |
---|
188 | } |
---|
189 | |
---|
190 | #include <machine/rtems-bsd-sysinit.h> |
---|
191 | |
---|
192 | SYSINIT_NEED_NET_PF_UNIX; |
---|
193 | |
---|
194 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
195 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
196 | #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER |
---|
197 | #define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER |
---|
198 | |
---|
199 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
200 | |
---|
201 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 |
---|
202 | |
---|
203 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
204 | |
---|
205 | #define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 32 |
---|
206 | #define CONFIGURE_UNLIMITED_OBJECTS |
---|
207 | #define CONFIGURE_UNIFIED_WORK_AREAS |
---|
208 | |
---|
209 | #define CONFIGURE_STACK_CHECKER_ENABLED |
---|
210 | |
---|
211 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
212 | |
---|
213 | #define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024) |
---|
214 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES |
---|
215 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
216 | |
---|
217 | #define CONFIGURE_INIT |
---|
218 | |
---|
219 | #include <rtems/confdefs.h> |
---|