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();
24 struct interface ifs[MAX_IFACES];
31 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
32 * open and read the interface config file. Also initialize the iface defs
33 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
45 if((cf = fopen(f,"r"))==NULL){
46 syslog(LOG_ERR, "Config file %s not found or could not be opened",f);
50 while(fgets(buf, 255, cf)!=NULL){
52 if((p = strtok(buf, " \t\n\r")) == NULL)continue;
53 if(*p=='#' || *p==';')continue;
55 if(strcmp(p,"interface")==0)c_interface();
56 /* else if(strcmp(p,"whatever")==0)c_dowhatever(); */
57 else cerr("Unrecognized command: %s",p);
60 if(ifs_top==0)cerr("No interfaces defined","");
62 if(debugd)print_config();
68 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
69 * Initialize defaults and setup the interface structures
70 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
77 for(i=0;i<MAX_IFACES;i++){
78 ifs[i].type = IF_TYPE_NONE;
81 ifs[i].devname = NULL;
84 ifs[i].private = NULL;
90 ifs[i].out_overruns = 0;
91 ifs[i].martians_in = 0;
102 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
103 * Print out the config table (DEBUG)
104 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
112 if(cerrflag==0) syslog(LOG_DEBUG, "%d interfaces:\n",ifs_top);
113 else syslog(LOG_DEBUG, "%d interfaces (there are errors):\n", ifs_top);
114 for(i=0;i<ifs_top;i++){
116 if(ifs[i].id == NULL) id = "(none)";
119 if(ifs[i].devname == NULL) dev = "(none)";
120 else dev = ifs[i].devname;
122 if(ifs[i].type == IF_TYPE_NONE){
123 syslog(LOG_DEBUG,"interface %-4s type NONE devicename %s unit %d\n",
124 id, dev, ifs[i].unit);
125 } else if(ifs[i].type == IF_TYPE_SLIP){
126 syslog(LOG_DEBUG,"interface %-4s type slip devicename %s speed %d\n",
127 id, dev, ifs[i].unit);
128 } else if(ifs[i].type == IF_TYPE_TUN){
129 syslog(LOG_DEBUG,"interface %-4s type tun devicename %s\n",
131 } else if(ifs[i].type == IF_TYPE_IPUDP){
132 syslog(LOG_DEBUG,"interface %-4s type udp port %d\n",
134 } else if(ifs[i].type == IF_TYPE_IPIP){
135 syslog(LOG_DEBUG,"interface %-4s type ip protocol id %d\n",
138 syslog(LOG_DEBUG,"interface %-4s type UNKNOWN devicename %s unit %d\n",
139 id, dev, ifs[i].unit);
145 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
146 * Print a general config file error
147 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
154 syslog(LOG_ERR,"Config file error at line %d:\n",clineno);
155 (void)fprintf(stderr,s,a);
156 (void)fprintf(stderr,"\n");
161 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
162 * Handle the "define" command
163 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
171 if(ifs_top>=MAX_IFACES){
172 cerr("Too many interfaces defined","");
178 if((q = strtok((char *)NULL, " \t\n\r"))){
179 ifs[ifs_top].id = strdup(q);
182 if((q = strtok((char *)NULL, " \t\n\r"))){
183 if(strcmp(q,"tunnel")==0){
184 ifs[ifs_top].type = IF_TYPE_TUN;
185 ifs[ifs_top].ifopen = tun_open;
186 ifs[ifs_top].ifread = tun_read;
187 ifs[ifs_top].ifsend = tun_send;
188 } else if(strcmp(q,"slip")==0){
189 ifs[ifs_top].type = IF_TYPE_SLIP;
190 ifs[ifs_top].ifopen = slip_open;
191 ifs[ifs_top].ifread = slip_read;
192 ifs[ifs_top].ifsend = slip_send;
193 } else if(strcmp(q,"ip")==0){
194 ifs[ifs_top].type = IF_TYPE_IPIP;
195 ifs[ifs_top].ifopen = ip_open;
196 ifs[ifs_top].ifread = ip_read;
197 ifs[ifs_top].ifsend = ip_send;
198 } else if(strcmp(q,"udp")==0){
199 ifs[ifs_top].type = IF_TYPE_IPUDP;
200 ifs[ifs_top].ifopen = ip_open;
201 ifs[ifs_top].ifread = ip_read;
202 ifs[ifs_top].ifsend = ip_send;
203 } else cerr("Bad interface type: %s",q);
206 if((q = strtok((char *)NULL, " \t\n\r"))){
207 ifs[ifs_top].devname = strdup(q);
210 if((q = strtok((char *)NULL, " \t\n\r"))){
211 ifs[ifs_top].unit = atoi(q);
214 if(syntax)cerr("Syntax error (interface <name> <type> <device> <int>","");