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_INIT_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
52 #include <sys/svrctl.h>
57 #include "generic/type.h"
59 #include "generic/arp.h"
60 #include "generic/assert.h"
61 #include "generic/buf.h"
62 #include "generic/clock.h"
63 #include "generic/eth.h"
64 #include "generic/event.h"
65 #include "generic/ip.h"
66 #include "generic/psip.h"
67 #include "generic/rand256.h"
68 #include "generic/sr.h"
69 #include "generic/tcp.h"
70 #include "generic/udp.h"
74 #define RANDOM_DEV_NAME "/dev/random"
76 int this_proc
; /* Process number of this server. */
79 static int synal_tasknr
= ANY
;
85 #ifdef BUF_CONSISTENCY_CHECK
86 extern int inet_buf_debug
;
89 _PROTOTYPE( void main
, (void) );
91 FORWARD
_PROTOTYPE( void nw_conf
, (void) );
92 FORWARD
_PROTOTYPE( void nw_init
, (void) );
98 int source
, timerand
, fd
;
99 struct fssignon device
;
101 struct systaskinfo info
;
107 printf("Starting inet...\n");
108 printf("%s\n", version
);
111 /* Read configuration. */
114 /* Get a random number */
116 fd
= open(RANDOM_DEV_NAME
, O_RDONLY
| O_NONBLOCK
);
119 r
= read(fd
, randbits
, sizeof(randbits
));
120 if (r
== sizeof(randbits
))
124 printf("unable to read random data from %s: %s\n",
125 RANDOM_DEV_NAME
, r
== -1 ? strerror(errno
) :
126 r
== 0 ? "EOF" : "not enough data");
132 printf("unable to open random device %s: %s\n",
133 RANDOM_DEV_NAME
, strerror(errno
));
137 printf("using current time for random-number seed\n");
139 r
= sysutime(UTIME_TIMEOFDAY
, &tv
);
141 r
= gettimeofday(&tv
, NULL
);
145 printf("sysutime failed: %s\n", strerror(errno
));
148 memcpy(randbits
, &tv
, sizeof(tv
));
150 init_rand256(randbits
);
153 if (svrctl(SYSSIGNON
, (void *) &info
) == -1) pause();
155 /* Our new identity as a server. */
156 this_proc
= info
.proc_nr
;
159 /* Our new identity as a server. */
160 if ((this_proc
= getprocnr()) < 0)
161 ip_panic(( "unable to get own process nr\n"));
164 /* Register the device group. */
166 device
.style
= STYLE_CLONE
;
167 if (svrctl(FSSIGNON
, (void *) &device
) == -1) {
168 printf("inet: error %d on registering ethernet devices\n",
173 #ifdef BUF_CONSISTENCY_CHECK
174 inet_buf_debug
= (getenv("inetbufdebug") &&
175 (strcmp(getenv("inetbufdebug"), "on") == 0));
179 ip_warning(( "buffer consistency check enabled" ));
183 if (getenv("killerinet"))
185 ip_warning(( "killer inet active" ));
190 r
= sys_findproc(SYN_AL_NAME
, &synal_tasknr
, 0);
192 ip_panic(( "unable to find synchronous alarm task: %d\n", r
));
198 #ifdef BUF_CONSISTENCY_CHECK
201 static int buf_debug_count
= 0;
203 if (++buf_debug_count
>= inet_buf_debug
)
206 if (!bf_consistency_check())
216 if (clck_call_expire
)
218 clck_expire_timers();
223 ip_panic(("out of messages"));
225 r
= receive (ANY
, &mq
->mq_mess
);
228 ip_panic(("unable to receive: %d", r
));
231 source
= mq
->mq_mess
.m_source
;
232 if (source
== FS_PROC_NR
)
237 else if (source
== synal_tasknr
)
239 clck_tick (&mq
->mq_mess
);
243 else if (mq
->mq_mess
.m_type
== SYN_ALARM
)
245 clck_tick(&mq
->mq_mess
);
248 else if (mq
->mq_mess
.m_type
== PROC_EVENT
)
251 /* probably SIGTERM */
254 else if (mq
->mq_mess
.m_type
& NOTIFY_MESSAGE
)
256 /* A driver is (re)started. */
257 eth_check_drivers(&mq
->mq_mess
);
261 else if (mq
->mq_mess
.m_type
== DL_TASK_REPLY
)
263 eth_rec(&mq
->mq_mess
);
268 printf("inet: got bad message type 0x%x from %d\n",
269 mq
->mq_mess
.m_type
, mq
->mq_mess
.m_source
);
273 ip_panic(("task is not allowed to terminate"));
276 PRIVATE
void nw_conf()
287 PRIVATE
void nw_init()
302 PUBLIC
void panic0(file
, line
)
306 printf("panic at %s, %d: ", file
, line
);
309 PUBLIC
void inet_panic()
311 printf("\ninet stacktrace: ");
314 sys_abort(RBT_PANIC
);
316 (panic
)("INET","aborted due to a panic",NO_NUM
);
322 PUBLIC
void bad_assertion(file
, line
, what
)
328 printf("assertion \"%s\" failed", what
);
333 PUBLIC
void bad_compare(file
, line
, lhs
, what
, rhs
)
341 printf("compare (%d) %s (%d) failed", lhs
, what
, rhs
);
347 * $PchId: inet.c,v 1.23 2005/06/28 14:27:22 philip Exp $