1 /* config.c config file reader
3 * $Id: config.c,v 1.3 1995/03/19 17:21:06 bdale Exp $
5 * Copyright 1991, Michael Westerhof, Sun Microsystems, Inc.
6 * This software may be freely used, distributed, or modified, providing
7 * this header is not removed.
20 static void cerr(); /* General error printer */
21 static void init_config();
22 static void c_interface();
23 static void print_config();
29 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
30 * open and read the interface config file. Also initialize the iface defs
31 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
43 if((cf = fopen(f,"r"))==NULL){
44 syslog(LOG_ERR, "Config file %s not found or could not be opened",f);
48 while(fgets(buf, 255, cf)!=NULL){
50 if((p = strtok(buf, " \t\n\r")) == NULL)continue;
51 if(*p=='#' || *p==';')continue;
53 if(strcmp(p,"interface")==0)c_interface();
54 /* else if(strcmp(p,"whatever")==0)c_dowhatever(); */
55 else cerr("Unrecognized command: %s",p);
58 if(ifs_top==0)cerr("No interfaces defined","");
60 if(debugd)print_config();
66 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
67 * Initialize defaults and setup the interface structures
68 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
75 for(i=0;i<MAX_IFACES;i++){
76 ifs[i].type = IF_TYPE_NONE;
79 ifs[i].devname = NULL;
82 ifs[i].private = NULL;
88 ifs[i].out_overruns = 0;
89 ifs[i].martians_in = 0;
100 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
101 * Print out the config table (DEBUG)
102 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
110 if(cerrflag==0) syslog(LOG_DEBUG, "%d interfaces:\n",ifs_top);
111 else syslog(LOG_DEBUG, "%d interfaces (there are errors):\n", ifs_top);
112 for(i=0;i<ifs_top;i++){
114 if(ifs[i].id == NULL) id = "(none)";
117 if(ifs[i].devname == NULL) dev = "(none)";
118 else dev = ifs[i].devname;
120 if(ifs[i].type == IF_TYPE_NONE){
121 syslog(LOG_DEBUG,"interface %-4s type NONE devicename %s unit %d\n",
122 id, dev, ifs[i].unit);
123 } else if(ifs[i].type == IF_TYPE_SLIP){
124 syslog(LOG_DEBUG,"interface %-4s type slip devicename %s speed %d\n",
125 id, dev, ifs[i].unit);
126 } else if(ifs[i].type == IF_TYPE_TUN){
127 syslog(LOG_DEBUG,"interface %-4s type tun devicename %s\n",
129 } else if(ifs[i].type == IF_TYPE_IPUDP){
130 syslog(LOG_DEBUG,"interface %-4s type udp port %d\n",
132 } else if(ifs[i].type == IF_TYPE_IPIP){
133 syslog(LOG_DEBUG,"interface %-4s type ip protocol id %d\n",
136 syslog(LOG_DEBUG,"interface %-4s type UNKNOWN devicename %s unit %d\n",
137 id, dev, ifs[i].unit);
143 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
144 * Print a general config file error
145 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
152 syslog(LOG_ERR,"Config file error at line %d:\n",clineno);
153 (void)fprintf(stderr,s,a);
154 (void)fprintf(stderr,"\n");
159 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
160 * Handle the "define" command
161 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
169 if(ifs_top>=MAX_IFACES){
170 cerr("Too many interfaces defined","");
176 if((q = strtok((char *)NULL, " \t\n\r"))){
177 ifs[ifs_top].id = strdup(q);
180 if((q = strtok((char *)NULL, " \t\n\r"))){
181 if(strcmp(q,"tunnel")==0){
182 ifs[ifs_top].type = IF_TYPE_TUN;
183 ifs[ifs_top].ifopen = tun_open;
184 ifs[ifs_top].ifread = tun_read;
185 ifs[ifs_top].ifsend = tun_send;
186 } else if(strcmp(q,"slip")==0){
187 ifs[ifs_top].type = IF_TYPE_SLIP;
188 ifs[ifs_top].ifopen = slip_open;
189 ifs[ifs_top].ifread = slip_read;
190 ifs[ifs_top].ifsend = slip_send;
191 } else if(strcmp(q,"ip")==0){
192 ifs[ifs_top].type = IF_TYPE_IPIP;
193 ifs[ifs_top].ifopen = ip_open;
194 ifs[ifs_top].ifread = ip_read;
195 ifs[ifs_top].ifsend = ip_send;
196 } else if(strcmp(q,"udp")==0){
197 ifs[ifs_top].type = IF_TYPE_IPUDP;
198 ifs[ifs_top].ifopen = ip_open;
199 ifs[ifs_top].ifread = ip_read;
200 ifs[ifs_top].ifsend = ip_send;
201 } else cerr("Bad interface type: %s",q);
204 if((q = strtok((char *)NULL, " \t\n\r"))){
205 ifs[ifs_top].devname = strdup(q);
208 if((q = strtok((char *)NULL, " \t\n\r"))){
209 ifs[ifs_top].unit = atoi(q);
212 if(syntax)cerr("Syntax error (interface <name> <type> <device> <int>","");