4 Created: Nov 11, 1992 by Philip Homburg
6 Modified: Apr 07, 2001 by Kees J. Bot
7 Read the configuration file and fill in the xx_conf[] arrays.
9 Copyright 1995 Philip Homburg
12 #define _POSIX_SOURCE 1
13 #define _NETBSD_SOURCE 1
20 #include <sys/types.h>
22 #include <minix/type.h>
23 #include <minix/sysutil.h>
24 #include <minix/syslib.h>
25 #include <minix/netsock.h>
26 #include "inet_config.h"
30 struct eth_conf eth_conf
[IP_PORT_MAX
];
31 struct psip_conf psip_conf
[IP_PORT_MAX
];
32 struct ip_conf ip_conf
[IP_PORT_MAX
];
33 struct tcp_conf tcp_conf
[IP_PORT_MAX
];
34 struct udp_conf udp_conf
[IP_PORT_MAX
];
43 int ip_forward_directed_bcast
= 0; /* Default is off */
45 static int ifdefault
= -1; /* Default network interface. */
48 static void fatal(const char *label
)
50 printf("init: %s: %s\n", label
, strerror(errno
));
54 static void check_mknod(const char *device
, mode_t mode
, int minor
)
55 /* Check if a device exists with the proper device number. */
59 dev
= makedev(major(ip_dev
), minor
);
62 if (mknod(device
, S_IFCHR
| mode
, dev
) < 0) fatal(device
);
63 printf("mknod %s c %d %d\n", device
, major(ip_dev
), minor
);
68 static unsigned char line
[256], *lineptr
;
69 static unsigned int linenr
;
71 static __dead
void error(void)
73 printf("inet: error on line %u\n", linenr
);
77 static int nextline(void)
79 /* Read a line from the configuration file, to be used by subsequent
80 * token() calls. Skip empty lines, and lines where the first character
81 * after leading "whitespace" is '#'. The last line of the file need
82 * not be terminated by a newline. Return 1 if a line was read in
83 * successfully, and 0 on EOF or error.
92 while ((r
= read(cfg_fd
, &c
, 1)) == 1) {
102 if (skip
== -1 && c
> ' ')
105 if (skip
== 0 && lp
< (unsigned char *) line
+ sizeof(line
)-1)
110 return (r
== 1 || lp
!= line
);
113 static void token(int need
)
115 /* Read a word from the configuration line. Return a null string on
116 * EOL. Return a punctuation as a one character word. If 'need' is
117 * true then an actual word is expected at this point, so err out if
121 static unsigned char c
= '\n';
123 wp
= (unsigned char *) word
;
135 if (wp
< (unsigned char *) word
+ sizeof(word
)-1) *wp
++ = c
;
136 c
= (*lineptr
!= 0) ? *lineptr
++ : ' ';
137 if (word
[0] == ';' || word
[0] == '{' || word
[0] == '}') {
141 } while (c
> ' ' && c
!= ';' && c
!= '{' && c
!= '}');
145 void inet_read_conf(void)
150 { static int first
= 1;
152 panic(( "LWIP : read_conf: called a second time" ));
155 *(u8_t
*)0 = 0xcc; /* INT 3 */
160 /* Open the configuration file. */
161 if ((cfg_fd
= open(PATH_INET_CONF
, O_RDONLY
)) == -1)
162 fatal(PATH_INET_CONF
);
167 unsigned int instance
;
169 if (strncmp(word
, "eth", 3) == 0) {
171 ifno
= strtol(word
+3, NULL
, 10);
174 strncpy(drv_name
, word
, 128);
176 sprintf(drv_name
, "%s_debug", word
);
179 instance
= strtol(word
, NULL
, 10);
181 printf("inet: Unknown device '%s'\n", word
);
185 enable
= 7; /* 1 = IP, 2 = TCP, 4 = UDP */
188 if (word
[0] == '{') {
190 while (word
[0] != '}') {
191 if (strcmp(word
, "default") == 0) {
192 if (ifdefault
!= -1) {
194 "inet: ip%d and ip%d can't both be default\n",
201 if (strcmp(word
, "no") == 0) {
203 if (strcmp(word
, "ip") == 0) {
206 if (strcmp(word
, "tcp") == 0) {
209 if (strcmp(word
, "udp") == 0) {
213 "inet: Can't do 'no %s'\n",
219 printf("inet: Unknown option '%s'\n",
223 if (word
[0] == ';') token(0);
225 if (word
[0] != '}') error();
229 if (word
[0] != ';' && word
[0] != 0) error();
231 nic_assign_driver("eth", ifno
, drv_name
, instance
, ifdefault
== ifno
);
234 if (ifdefault
== -1) {
235 printf("inet: No networks or no default network defined\n");
239 /* Set umask 0 so we can creat mode 666 devices. */
242 /* See what the device number of /dev/ip is. That's what we
243 * used last time for the network devices, so we keep doing so.
245 if (stat("/dev/ip", &st
) < 0) fatal("/dev/ip");
248 /* create protocol devices */
249 check_mknod("/dev/ip", 0600, SOCK_TYPE_IP
);
250 check_mknod("/dev/tcp", 0666, SOCK_TYPE_TCP
);
251 check_mknod("/dev/udp", 0666, SOCK_TYPE_UDP
);
254 * create hw devices, to configure ip we need also ip devices for each
256 check_mknod("/dev/ip0", 0600, SOCK_TYPES
+ 0);
257 check_mknod("/dev/eth0", 0600, SOCK_TYPES
+ 0);
259 check_mknod("/dev/ip1", 0600, SOCK_TYPES
+ 1);
260 check_mknod("/dev/eth1", 0600, SOCK_TYPES
+ 1);
262 check_mknod("/dev/ip2", 0600, SOCK_TYPES
+ 2);
263 check_mknod("/dev/eth2", 0600, SOCK_TYPES
+ 2);
265 check_mknod("/dev/ip3", 0600, SOCK_TYPES
+ 3);
266 check_mknod("/dev/eth3", 0600, SOCK_TYPES
+ 3);
268 check_mknod("/dev/ip4", 0600, SOCK_TYPES
+ 4);
269 check_mknod("/dev/eth4", 0600, SOCK_TYPES
+ 4);