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
52 #include <sys/svrctl.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. */
80 static int synal_tasknr
= ANY
;
86 #ifdef BUF_CONSISTENCY_CHECK
87 extern int inet_buf_debug
;
94 _PROTOTYPE( void main
, (void) );
96 FORWARD
_PROTOTYPE( void nw_conf
, (void) );
97 FORWARD
_PROTOTYPE( void nw_init
, (void) );
103 int source
, m_type
, timerand
, fd
;
105 struct fssignon device
;
107 struct systaskinfo info
;
113 printf("Starting inet...\n");
114 printf("%s\n", version
);
118 system_hz
= sys_hz();
121 /* Read configuration. */
124 /* Get a random number */
126 fd
= open(RANDOM_DEV_NAME
, O_RDONLY
| O_NONBLOCK
);
129 r
= read(fd
, randbits
, sizeof(randbits
));
130 if (r
== sizeof(randbits
))
134 printf("unable to read random data from %s: %s\n",
135 RANDOM_DEV_NAME
, r
== -1 ? strerror(errno
) :
136 r
== 0 ? "EOF" : "not enough data");
142 printf("unable to open random device %s: %s\n",
143 RANDOM_DEV_NAME
, strerror(errno
));
147 printf("using current time for random-number seed\n");
149 r
= sysutime(UTIME_TIMEOFDAY
, &tv
);
151 r
= gettimeofday(&tv
, NULL
);
155 printf("sysutime failed: %s\n", strerror(errno
));
158 memcpy(randbits
, &tv
, sizeof(tv
));
160 init_rand256(randbits
);
163 if (svrctl(SYSSIGNON
, (void *) &info
) == -1) pause();
165 /* Our new identity as a server. */
166 this_proc
= info
.proc_nr
;
169 /* Our new identity as a server. */
170 r
= ds_retrieve_u32("inet", &tasknr
);
172 ip_panic(("inet: ds_retrieve_u32 failed for 'inet': %d", r
));
176 /* Register the device group. */
178 device
.style
= STYLE_CLONE
;
179 if (svrctl(FSSIGNON
, (void *) &device
) == -1) {
180 printf("inet: error %d on registering ethernet devices\n",
185 #ifdef BUF_CONSISTENCY_CHECK
186 inet_buf_debug
= (getenv("inetbufdebug") &&
187 (strcmp(getenv("inetbufdebug"), "on") == 0));
191 ip_warning(( "buffer consistency check enabled" ));
195 if (getenv("killerinet"))
197 ip_warning(( "killer inet active" ));
202 r
= sys_findproc(SYN_AL_NAME
, &synal_tasknr
, 0);
204 ip_panic(( "unable to find synchronous alarm task: %d\n", r
));
210 #ifdef BUF_CONSISTENCY_CHECK
213 static int buf_debug_count
= 0;
215 if (++buf_debug_count
>= inet_buf_debug
)
218 if (!bf_consistency_check())
228 if (clck_call_expire
)
230 clck_expire_timers();
235 ip_panic(("out of messages"));
237 r
= receive (ANY
, &mq
->mq_mess
);
240 ip_panic(("unable to receive: %d", r
));
243 source
= mq
->mq_mess
.m_source
;
244 m_type
= mq
->mq_mess
.m_type
;
245 if (source
== FS_PROC_NR
)
250 else if (source
== synal_tasknr
)
252 clck_tick (&mq
->mq_mess
);
256 else if (m_type
== SYN_ALARM
)
258 clck_tick(&mq
->mq_mess
);
261 else if (m_type
== PROC_EVENT
)
264 /* probably SIGTERM */
267 else if (m_type
& NOTIFY_MESSAGE
)
269 /* A driver is (re)started. */
270 eth_check_drivers(&mq
->mq_mess
);
274 else if (m_type
== DL_CONF_REPLY
|| m_type
== DL_TASK_REPLY
||
275 m_type
== DL_NAME_REPLY
|| m_type
== DL_STAT_REPLY
)
277 eth_rec(&mq
->mq_mess
);
282 printf("inet: got bad message type 0x%x from %d\n",
283 mq
->mq_mess
.m_type
, mq
->mq_mess
.m_source
);
287 ip_panic(("task is not allowed to terminate"));
290 PRIVATE
void nw_conf()
301 PRIVATE
void nw_init()
316 PUBLIC
void panic0(file
, line
)
320 printf("panic at %s, %d: ", file
, line
);
323 PUBLIC
void inet_panic()
325 printf("\ninet stacktrace: ");
328 sys_abort(RBT_PANIC
);
330 (panic
)("INET","aborted due to a panic",NO_NUM
);
336 PUBLIC
void bad_assertion(file
, line
, what
)
342 printf("assertion \"%s\" failed", what
);
347 PUBLIC
void bad_compare(file
, line
, lhs
, what
, rhs
)
355 printf("compare (%d) %s (%d) failed", lhs
, what
, rhs
);
361 * $PchId: inet.c,v 1.23 2005/06/28 14:27:22 philip Exp $