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>
17 #include <WINNT/afsevent.h>
20 #ifdef HAVE_SYS_FILE_H
26 #include <rx/rx_globals.h>
27 #include <rx/rxstat.h>
29 #include <afs/cellconfig.h>
32 #include <afs/audit.h>
33 #include <afs/com_err.h>
36 #include <afs/afsutil.h>
39 #include "vlserver_internal.h"
42 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
45 struct vldstats dynamic_statistics;
46 struct ubik_dbase *VL_dbase;
47 afs_uint32 rd_HostAddress[MAXSERVERID + 1];
48 afs_uint32 wr_HostAddress[MAXSERVERID + 1];
50 static void *CheckSignal(void*);
53 int rxJumbograms = 0; /* default is to not send and receive jumbo grams */
56 int rxkadDisableDotCheck = 0;
58 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
59 afs_uint32 SHostAddrs[ADDRSPERSITE];
62 CheckSignal_Signal(int unused)
64 #if defined(AFS_PTHREAD_ENV)
67 IOMGR_SoftSig(CheckSignal, 0);
72 CheckSignal(void *unused)
78 Init_VLdbase(&ctx, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
79 return (void *)(intptr_t)errorcode;
80 VLog(0, ("Dump name hash table out\n"));
81 for (i = 0; i < HASHSIZE; i++) {
84 VLog(0, ("Dump id hash table out\n"));
85 for (i = 0; i < HASHSIZE; i++) {
88 return ((void *)(intptr_t)ubik_EndTrans(ctx.trans));
92 /* Initialize the stats for the opcodes */
94 initialize_dstats(void)
98 dynamic_statistics.start_time = (afs_uint32) time(0);
99 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
100 dynamic_statistics.requests[i] = 0;
101 dynamic_statistics.aborts[i] = 0;
105 /* check whether caller is authorized to manage RX statistics */
107 vldb_rxstat_userok(struct rx_call *call)
109 return afsconf_SuperUser(vldb_confdir, call, NULL);
112 /* Main server module */
114 #include "AFS_component_version_number.c"
138 main(int argc, char **argv)
142 struct rx_service *tservice;
143 struct rx_securityClass **securityClasses;
144 afs_int32 numClasses;
145 struct afsconf_dir *tdir;
146 struct ktc_encryptionKey tkey;
147 struct afsconf_cell info;
149 char hostname[VL_MAXNAMELEN];
151 char clones[MAXHOSTSPERCELL];
152 afs_uint32 host = ntohl(INADDR_ANY);
153 struct cmd_syndesc *opts;
159 char *auditFileName = NULL;
160 char *interface = NULL;
161 char *optstring = NULL;
165 * The following signal action for AIX is necessary so that in case of a
166 * crash (i.e. core is generated) we can include the user's data section
167 * in the core dump. Unfortunately, by default, only a partial core is
168 * generated which, in many cases, isn't too useful.
170 struct sigaction nsa;
172 rx_extraPackets = 100; /* should be a switch, I guess... */
173 sigemptyset(&nsa.sa_mask);
174 nsa.sa_handler = SIG_DFL;
175 nsa.sa_flags = SA_FULLDUMP;
176 sigaction(SIGABRT, &nsa, NULL);
177 sigaction(SIGSEGV, &nsa, NULL);
181 /* Initialize dirpaths */
182 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
184 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
186 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
191 vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH);
192 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
193 logFile = strdup(AFSDIR_SERVER_VLOG_FILEPATH);
195 cmd_DisableAbbreviations();
196 cmd_DisablePositionalCommands();
197 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
199 /* vlserver specific options */
200 cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG,
201 CMD_OPTIONAL, "disable authentication");
202 cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG,
203 CMD_OPTIONAL, "optimise for small memory systems");
205 /* general server options */
206 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
207 CMD_OPTIONAL, "location of audit log");
208 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
209 CMD_OPTIONAL, "interface to use for audit logging");
210 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
211 CMD_OPTIONAL, "configuration location");
212 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE,
213 CMD_OPTIONAL, "debug level");
214 cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE,
215 CMD_OPTIONAL, "database file");
216 cmd_AddParmAlias(opts, OPT_database, "-db");
217 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
218 CMD_OPTIONAL, "location of logfile");
219 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
220 "number of threads");
221 #if !defined(AFS_NT40_ENV)
222 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
223 CMD_OPTIONAL, "log to syslog");
227 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
228 CMD_OPTIONAL, "enable RX transport statistics");
229 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
230 CMD_OPTIONAL, "enable RX RPC statistics");
231 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
232 CMD_OPTIONAL, "disable jumbograms");
233 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG,
234 CMD_OPTIONAL, "enable jumbograms");
235 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG,
236 CMD_OPTIONAL, "bind only to the primary interface");
237 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
238 CMD_OPTIONAL, "maximum MTU for RX");
239 cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE,
240 CMD_OPTIONAL, "rx trace file");
243 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
244 CMD_FLAG, CMD_OPTIONAL,
245 "permit Kerberos 5 principals with dots");
247 code = cmd_Parse(argc, argv, &opts);
251 /* vlserver options */
252 cmd_OptionAsFlag(opts, OPT_noauth, &noAuth);
253 cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem);
254 if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) {
255 extern char rxi_tracename[80];
256 strcpy(rxi_tracename, optstring);
261 /* general server options */
263 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
265 if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) {
266 if (osi_audit_interface(interface)) {
267 printf("Invalid audit interface '%s'\n", interface);
273 cmd_OptionAsString(opts, OPT_config, &configDir);
274 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
275 cmd_OptionAsString(opts, OPT_database, &vl_dbaseName);
276 cmd_OptionAsString(opts, OPT_logfile, &logFile);
278 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
280 printf("Warning: '-p %d' is too big; using %d instead\n",
286 if (cmd_OptionPresent(opts, OPT_syslog)) {
288 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
293 if (cmd_OptionPresent(opts, OPT_peer))
294 rx_enablePeerRPCStats();
295 if (cmd_OptionPresent(opts, OPT_process))
296 rx_enableProcessRPCStats();
297 if (cmd_OptionPresent(opts, OPT_nojumbo))
299 if (cmd_OptionPresent(opts, OPT_jumbo))
302 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
304 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
307 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
310 osi_audit_file(auditFileName);
314 serverLogSyslogTag = "vlserver";
316 OpenLog(logFile); /* set up logging */
319 tdir = afsconf_Open(configDir);
322 ("vlserver: can't open configuration files in dir %s, giving up.\n",
327 /* initialize winsock */
328 if (afs_winsockInit() < 0) {
329 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
330 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
335 gethostname(hostname, sizeof(hostname));
336 th = gethostbyname(hostname);
338 printf("vlserver: couldn't get address of this host (%s).\n",
342 memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
344 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
345 signal(SIGXCPU, CheckSignal_Signal);
347 /* get list of servers */
349 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
352 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
356 vldb_confdir = tdir; /* Preserve our configuration dir */
357 /* rxvab no longer supported */
358 memset(&tkey, 0, sizeof(tkey));
361 afsconf_SetNoAuthFlag(tdir, 1);
366 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
367 AFSDIR_SERVER_NETINFO_FILEPATH) {
369 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
370 ADDRSPERSITE, reason,
371 AFSDIR_SERVER_NETINFO_FILEPATH,
372 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
376 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
379 host = SHostAddrs[0];
380 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
385 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
386 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
387 afsconf_CheckAuth, tdir);
389 ubik_SyncWriterCacheProc = vlsynccache;
391 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
392 vl_dbaseName, &VL_dbase);
394 printf("vlserver: Ubik init failed: %s\n", afs_error_message(code));
400 if (rxMaxMTU != -1) {
401 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
402 printf("rxMaxMTU %d invalid\n", rxMaxMTU);
406 rx_SetRxDeadTime(50);
408 memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
409 memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
412 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
415 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
416 securityClasses, numClasses,
418 if (tservice == (struct rx_service *)0) {
419 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
422 rx_SetMinProcs(tservice, 2);
425 rx_SetMaxProcs(tservice, lwps);
427 if (rxkadDisableDotCheck) {
428 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
429 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
433 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
434 securityClasses, numClasses,
435 RXSTATS_ExecuteRequest);
436 if (tservice == (struct rx_service *)0) {
437 printf("vlserver: Could not create rpc stats rx service\n");
440 rx_SetMinProcs(tservice, 2);
441 rx_SetMaxProcs(tservice, 4);
443 LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
444 printf("%s\n", cml_version_number); /* Goes to the log */
446 /* allow super users to manage RX statistics */
447 rx_SetRxStatUserOk(vldb_rxstat_userok);
449 rx_StartServer(1); /* Why waste this idle process?? */
451 return 0; /* not reachable */