1 /* this file contains the interface of the network software with rest of
2 minix. Furthermore it contains the main loop of the network task.
4 Copyright 1995 Philip Homburg
6 The valid messages and their parameters are:
9 __________________________________________________________________
11 | m_type | DEVICE | PROC_NR | COUNT | POSITION | ADDRESS |
12 |_______________|___________|_________|_______|__________|_________|
14 | NW_OPEN | minor dev | proc nr | mode | | |
15 |_______________|___________|_________|_______|__________|_________|
17 | NW_CLOSE | minor dev | proc nr | | | |
18 |_______________|___________|_________|_______|__________|_________|
20 | NW_IOCTL | minor dev | proc nr | | NWIO.. | address |
21 |_______________|___________|_________|_______|__________|_________|
23 | NW_READ | minor dev | proc nr | count | | address |
24 |_______________|___________|_________|_______|__________|_________|
26 | NW_WRITE | minor dev | proc nr | count | | address |
27 |_______________|___________|_________|_______|__________|_________|
29 | NW_CANCEL | minor dev | proc nr | | | |
30 |_______________|___________|_________|_______|__________|_________|
33 _______________________________________________________________________
35 | m_type | DL_PORT | DL_PROC | DL_COUNT | DL_STAT | DL_TIME |
36 |_______________|___________|_________|__________|____________|_________|
38 | DL_CONF_REPLY | minor dev | proc nr | rd_count | 0 | stat | time |
39 |_______________|___________|_________|__________|____________|_________|
41 | DL_TASK_REPLY | minor dev | proc nr | rd_count | err | stat | time |
42 |_______________|___________|_________|__________|____________|_________|
47 #define _MINIX_SOURCE 1
51 #include <sys/svrctl.h>
53 #include <minix/endpoint.h>
58 #include "generic/type.h"
60 #include "generic/arp.h"
61 #include "generic/assert.h"
62 #include "generic/buf.h"
63 #include "generic/clock.h"
64 #include "generic/eth.h"
65 #include "generic/event.h"
66 #include "generic/ip.h"
67 #include "generic/psip.h"
68 #include "generic/rand256.h"
69 #include "generic/sr.h"
70 #include "generic/tcp.h"
71 #include "generic/udp.h"
75 #define RANDOM_DEV_NAME "/dev/random"
77 int this_proc
; /* Process number of this server. */
82 #ifdef BUF_CONSISTENCY_CHECK
83 extern int inet_buf_debug
;
90 _PROTOTYPE( void main
, (void) );
92 FORWARD
_PROTOTYPE( void nw_conf
, (void) );
93 FORWARD
_PROTOTYPE( void nw_init
, (void) );
95 /* SEF functions and variables. */
96 FORWARD
_PROTOTYPE( void sef_local_startup
, (void) );
97 FORWARD
_PROTOTYPE( int sef_cb_init_fresh
, (int type
, sef_init_info_t
*info
) );
105 /* SEF local startup. */
110 #ifdef BUF_CONSISTENCY_CHECK
113 static int buf_debug_count
= 0;
115 if (++buf_debug_count
>= inet_buf_debug
)
118 if (!bf_consistency_check())
128 if (clck_call_expire
)
130 clck_expire_timers();
135 ip_panic(("out of messages"));
137 r
= sef_receive(ANY
, &mq
->mq_mess
);
140 ip_panic(("unable to receive: %d", r
));
143 source
= mq
->mq_mess
.m_source
;
144 m_type
= mq
->mq_mess
.m_type
;
145 if (source
== FS_PROC_NR
)
149 else if (is_notify(m_type
))
151 if (_ENDPOINT_P(source
) == CLOCK
)
153 clck_tick(&mq
->mq_mess
);
156 else if (_ENDPOINT_P(source
) == PM_PROC_NR
)
159 /* probably SIGTERM */
164 /* A driver is (re)started. */
165 eth_check_drivers(&mq
->mq_mess
);
169 else if (m_type
== DL_CONF_REPLY
|| m_type
== DL_TASK_REPLY
||
170 m_type
== DL_NAME_REPLY
|| m_type
== DL_STAT_REPLY
)
172 eth_rec(&mq
->mq_mess
);
177 printf("inet: got bad message type 0x%x from %d\n",
178 mq
->mq_mess
.m_type
, mq
->mq_mess
.m_source
);
182 ip_panic(("task is not allowed to terminate"));
185 /*===========================================================================*
186 * sef_local_startup *
187 *===========================================================================*/
188 PRIVATE
void sef_local_startup()
190 /* Register init callbacks. */
191 sef_setcb_init_fresh(sef_cb_init_fresh
);
192 sef_setcb_init_restart(sef_cb_init_restart_fail
);
194 /* No live update support for now. */
196 /* Let SEF perform startup. */
200 /*===========================================================================*
201 * sef_cb_init_fresh *
202 *===========================================================================*/
203 PRIVATE
int sef_cb_init_fresh(int type
, sef_init_info_t
*info
)
205 /* Initialize the inet server. */
209 struct fssignon device
;
214 printf("Starting inet...\n");
215 printf("%s\n", version
);
219 system_hz
= sys_hz();
222 /* Read configuration. */
225 /* Get a random number */
227 fd
= open(RANDOM_DEV_NAME
, O_RDONLY
| O_NONBLOCK
);
230 r
= read(fd
, randbits
, sizeof(randbits
));
231 if (r
== sizeof(randbits
))
235 printf("inet: unable to read random data from %s: %s\n",
236 RANDOM_DEV_NAME
, r
== -1 ? strerror(errno
) :
237 r
== 0 ? "EOF" : "not enough data");
243 printf("inet: unable to open random device %s: %s\n",
244 RANDOM_DEV_NAME
, strerror(errno
));
248 printf("inet: using current time for random-number seed\n");
249 r
= gettimeofday(&tv
, NULL
);
252 printf("sysutime failed: %s\n", strerror(errno
));
255 memcpy(randbits
, &tv
, sizeof(tv
));
257 init_rand256(randbits
);
259 /* Our new identity as a server. */
260 r
= ds_retrieve_label_num("inet", &tasknr
);
262 ip_panic(("inet: ds_retrieve_label_num failed for 'inet': %d", r
));
265 /* Register the device group. */
267 device
.style
= STYLE_CLONE
;
268 if (svrctl(FSSIGNON
, (void *) &device
) == -1) {
269 printf("inet: error %d on registering ethernet devices\n",
274 #ifdef BUF_CONSISTENCY_CHECK
275 inet_buf_debug
= (getenv("inetbufdebug") &&
276 (strcmp(getenv("inetbufdebug"), "on") == 0));
280 ip_warning(( "buffer consistency check enabled" ));
284 if (getenv("killerinet"))
286 ip_warning(( "killer inet active" ));
295 PRIVATE
void nw_conf()
306 PRIVATE
void nw_init()
321 PUBLIC
void panic0(file
, line
)
325 printf("panic at %s, %d: ", file
, line
);
328 PUBLIC
void inet_panic()
330 printf("\ninet stacktrace: ");
332 (panic
)("INET","aborted due to a panic",NO_NUM
);
337 PUBLIC
void bad_assertion(file
, line
, what
)
343 printf("assertion \"%s\" failed", what
);
348 PUBLIC
void bad_compare(file
, line
, lhs
, what
, rhs
)
356 printf("compare (%d) %s (%d) failed", lhs
, what
, rhs
);
362 * $PchId: inet.c,v 1.23 2005/06/28 14:27:22 philip Exp $