2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
24 #include <WINNT/afsevent.h>
26 #ifdef HAVE_SYS_FILE_H
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
40 #include <rx/rx_globals.h>
41 #include <rx/rxstat.h>
42 #include <rx/rxstat_prototypes.h>
43 #include <afs/cellconfig.h>
46 #include <afs/audit.h>
49 #include <afs/afsutil.h>
51 #include "vlserver_internal.h"
54 const char *vl_dbaseName;
55 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
58 struct vldstats dynamic_statistics;
59 struct ubik_dbase *VL_dbase;
60 afs_uint32 HostAddress[MAXSERVERID + 1];
62 static void *CheckSignal(void*);
65 int rxJumbograms = 0; /* default is to not send and receive jumbo grams */
68 int rxkadDisableDotCheck = 0;
71 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
72 afs_uint32 SHostAddrs[ADDRSPERSITE];
75 CheckSignal_Signal(int unused)
77 #if defined(AFS_PTHREAD_ENV)
80 IOMGR_SoftSig(CheckSignal, 0);
85 CheckSignal(void *unused)
87 register int i, errorcode;
88 struct ubik_trans *trans;
91 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
92 return (void *)errorcode;
93 VLog(0, ("Dump name hash table out\n"));
94 for (i = 0; i < HASHSIZE; i++) {
97 VLog(0, ("Dump id hash table out\n"));
98 for (i = 0; i < HASHSIZE; i++) {
101 return ((void *)ubik_EndTrans(trans));
105 /* Initialize the stats for the opcodes */
107 initialize_dstats(void)
111 dynamic_statistics.start_time = (afs_uint32) time(0);
112 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
113 dynamic_statistics.requests[i] = 0;
114 dynamic_statistics.aborts[i] = 0;
118 /* check whether caller is authorized to manage RX statistics */
120 vldb_rxstat_userok(struct rx_call *call)
122 return afsconf_SuperUser(vldb_confdir, call, NULL);
125 /* Main server module */
127 #include "AFS_component_version_number.c"
130 main(int argc, char **argv)
132 register afs_int32 code;
134 struct rx_service *tservice;
135 struct rx_securityClass *sc[3];
136 struct afsconf_dir *tdir;
137 struct ktc_encryptionKey tkey;
138 struct afsconf_cell info;
140 char hostname[VL_MAXNAMELEN];
141 int noAuth = 0, index, i;
142 char commandLine[150];
143 char clones[MAXHOSTSPERCELL];
144 afs_uint32 host = ntohl(INADDR_ANY);
148 * The following signal action for AIX is necessary so that in case of a
149 * crash (i.e. core is generated) we can include the user's data section
150 * in the core dump. Unfortunately, by default, only a partial core is
151 * generated which, in many cases, isn't too useful.
153 struct sigaction nsa;
155 rx_extraPackets = 100; /* should be a switch, I guess... */
156 sigemptyset(&nsa.sa_mask);
157 nsa.sa_handler = SIG_DFL;
158 nsa.sa_flags = SA_FULLDUMP;
159 sigaction(SIGABRT, &nsa, NULL);
160 sigaction(SIGSEGV, &nsa, NULL);
164 /* Parse command line */
165 for (index = 1; index < argc; index++) {
166 if (strcmp(argv[index], "-noauth") == 0) {
168 } else if (strcmp(argv[index], "-p") == 0) {
169 lwps = atoi(argv[++index]);
171 printf("Warning: '-p %d' is too big; using %d instead\n",
175 } else if (strcmp(argv[index], "-d") == 0) {
176 if ((index + 1) >= argc) {
177 fprintf(stderr, "missing argument for -d\n");
180 debuglevel = atoi(argv[++index]);
181 LogLevel = debuglevel;
182 } else if (strcmp(argv[index], "-nojumbo") == 0) {
184 } else if (strcmp(argv[index], "-jumbo") == 0) {
186 } else if (strcmp(argv[index], "-rxbind") == 0) {
188 } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
189 rxkadDisableDotCheck = 1;
190 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
191 if ((index + 1) >= argc) {
192 fprintf(stderr, "missing argument for -rxmaxmtu\n");
195 rxMaxMTU = atoi(argv[++index]);
196 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
197 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
198 printf("rxMaxMTU %d invalid; must be between %d-%lu\n",
199 rxMaxMTU, RX_MIN_PACKET_SIZE,
200 RX_MAX_PACKET_DATA_SIZE);
204 } else if (strcmp(argv[index], "-smallmem") == 0) {
207 } else if (strcmp(argv[index], "-trace") == 0) {
208 extern char rxi_tracename[80];
209 strcpy(rxi_tracename, argv[++index]);
211 } else if (strcmp(argv[index], "-auditlog") == 0) {
212 char *fileName = argv[++index];
214 osi_audit_file(fileName);
215 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
216 rx_enablePeerRPCStats();
217 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
218 rx_enableProcessRPCStats();
220 } else if (strcmp(argv[index], "-syslog") == 0) {
221 /* set syslog logging flag */
223 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
225 serverLogSyslogFacility = atoi(argv[index] + 8);
228 /* support help flag */
230 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
231 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
232 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
233 "[-syslog[=FACILITY]] "
234 "[-enable_peer_stats] [-enable_process_stats] "
237 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
238 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
239 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
240 "[-enable_peer_stats] [-enable_process_stats] "
248 /* Initialize dirpaths */
249 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
251 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
253 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
257 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
260 serverLogSyslogTag = "vlserver";
262 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
265 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
268 ("vlserver: can't open configuration files in dir %s, giving up.\n",
269 AFSDIR_SERVER_ETC_DIRPATH);
273 /* initialize winsock */
274 if (afs_winsockInit() < 0) {
275 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
276 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
281 gethostname(hostname, sizeof(hostname));
282 th = gethostbyname(hostname);
284 printf("vlserver: couldn't get address of this host (%s).\n",
288 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
290 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
291 signal(SIGXCPU, CheckSignal_Signal);
293 /* get list of servers */
295 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
298 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
302 vldb_confdir = tdir; /* Preserve our configuration dir */
303 /* rxvab no longer supported */
304 memset(&tkey, 0, sizeof(tkey));
307 afsconf_SetNoAuthFlag(tdir, 1);
312 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
313 AFSDIR_SERVER_NETINFO_FILEPATH) {
315 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
316 ADDRSPERSITE, reason,
317 AFSDIR_SERVER_NETINFO_FILEPATH,
318 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
322 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
325 host = SHostAddrs[0];
326 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
331 ubik_CRXSecurityProc = afsconf_ClientAuth;
332 ubik_CRXSecurityRock = (char *)tdir;
333 ubik_SRXSecurityProc = afsconf_ServerAuth;
334 ubik_SRXSecurityRock = (char *)tdir;
335 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
336 ubik_CheckRXSecurityRock = (char *)tdir;
338 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
339 vl_dbaseName, &VL_dbase);
341 printf("vlserver: Ubik init failed with code %d\n", code);
347 if (rxMaxMTU != -1) {
348 rx_SetMaxMTU(rxMaxMTU);
350 rx_SetRxDeadTime(50);
352 memset(HostAddress, 0, sizeof(HostAddress));
355 sc[0] = rxnull_NewServerSecurityObject();
356 sc[1] = (struct rx_securityClass *)0;
357 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
360 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
362 if (tservice == (struct rx_service *)0) {
363 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
366 rx_SetMinProcs(tservice, 2);
369 rx_SetMaxProcs(tservice, lwps);
371 if (rxkadDisableDotCheck) {
372 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
373 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
377 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
378 RXSTATS_ExecuteRequest);
379 if (tservice == (struct rx_service *)0) {
380 printf("vlserver: Could not create rpc stats rx service\n");
383 rx_SetMinProcs(tservice, 2);
384 rx_SetMaxProcs(tservice, 4);
386 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
388 strcat(commandLine, " ");
389 strcat(commandLine, argv[i]);
392 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
393 printf("%s\n", cml_version_number); /* Goes to the log */
395 /* allow super users to manage RX statistics */
396 rx_SetRxStatUserOk(vldb_rxstat_userok);
398 rx_StartServer(1); /* Why waste this idle process?? */
400 return 0; /* not reachable */