dispatcher.c revision 6e93b38e61e2cf3c36f56dc2dac897f37b908dfe
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/***********************************************************
Copyright 1988, 1989 by Carnegie Mellon University
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
#include <signal.h>
#include "impl.h"
#include "error.h"
#include "trace.h"
#include "signals.h"
#include "snmp.h"
#include "pdu.h"
#include "snmprelay_msg.h"
#include "agent.h"
#include "subtree.h"
#include "session.h"
#include "config.h"
#include "dispatcher.h"
#include "res.h"
#include "sea_i18n.h"
/***** LOCAL CONSTANTS ******/
/*
* select() will returned at least every
* POLL_INTERVAL seconds to test if some
* sessions have SNMP requests that have
* timeout (<==> the SNMP agnet has not
* responded)
*/
#define POLL_INTERVAL 240
/***** GLOBAL VARIABLES ******/
int relay_agent_trap_port = 162;
char *relay_agent_name = NULL;
char *sec_config_file ;
char *pid_file;
char *name_oid_file;
int relay_agent_max_agent_time_out= 987654321;
/*
* the name of the directory that
* contains the configuration files
*/
char *config_dir = NULL;
char *resource_file = NULL;
/* There are two available modes to run the snmprelayd */
/* 1) MODE_SPLIT: we send a request for each variable */
/* 2) MODE_GROUP: we try to group the variables */
int mode = MODE_GROUP;
int recovery_on = FALSE;
static int port = 0; /* relay agent port */
static char default_config_dir[] = "/etc/snmp/conf";
static char default_resource_file[] = "/etc/snmp/conf/snmpdx.rsrc";
static char default_error_file[] = "/var/snmp/snmpdx.log";
static char default_relay_agent_name[] = "relay-agent";
static char default_pid_file[] = "/var/snmp/snmpdx.st";
static char default_name_oid_file[] = "/etc/snmp/conf/enterprises.oid";
static void application_end();
static void signals_sighup(int siq);
static void signals_exit(int siq);
static void signals_child(int siq);
static void init_relay_agent();
static void dispatcher_init();
static void dispatcher_loop();
static void print_usage();
/*
* this function is called by error_exit()
*/
static void
{
}
static void
signals_sighup(int siq)
{
if(trace_level > 0)
}
static void
signals_exit(int sig)
{
/*
* SIGTERM is a normal exit, don't log it to console.
*/
else
}
static void
{
/*
* find agent matches the name, then modify
* the process id, operstatus
*/
return;
if (port)
else if (ap->agentPortNumber)
else
/* init the subtrees of relay agent */
}
static void
{
struct sockaddr_in me;
/* init my_ip_address (we need it before parsing the config file) */
if(trace_level > 0)
trace("Local IP Addresss : %s\n\n",
/* init the config_dir pointer and then parse the configuration files */
if(config_dir == NULL)
/* read enterprise name-oid file */
if(name_oid_file == NULL)
/* set up the relay agent name */
if(sec_config_file == NULL)
if(relay_agent_name == NULL)
/* read the resource file */
if(resource_file == NULL)
/* init clients_sd and agents_sd */
if(clients_sd < 0)
if(trace_level > 0)
if (agents_sd < 0)
if (trap_sd < 0)
}
static void dispatcher_loop()
{
int numfds;
int count;
while(1)
{
if(sighup)
{
}
if(trace_level > 1)
{
}
numfds = 0;
numfds++;
/* we compute the timeout according to the */
/* timeout of the pending requests */
if(count > 0)
{
{
/* we read the responses of the agents */
session_read();
continue;
}
{
/* working on the trap */
continue;
}
{
/* we dispatch the requests of the application */
continue;
}
}
else
{
switch(count)
{
case 0:
/* we check if some requests have timeout */
break;
case -1:
{
break;
}
else
{
}
}
}
}
}
/*
* \t[-m GROUP | SPLIT (default GROUP)]\n\
*/
static void print_usage()
{
MGET("Usage: snmpdx [-h]") );
MGET("[-h (to get help on usage)]") );
MGET("[-p port (default "),
MGET(")]"));
MGET("[-r resource-file (default "),
MGET(")]"));
MGET("[-a access-control-file (default "),
MGET(")]"));
MGET("[-c config-dir (default "),
MGET(")]"));
MGET("[-i pid-file (default "),
MGET(")]"));
MGET("[-o enterprise-oid-file (default "),
MGET(")]"));
MGET("[-y (to invoke recovery module)]"));
MGET("[-m GROUP | SPLIT (default GROUP)]"));
MGET("[-d trace-level (range 0.."),
MGET(", default "),
MGET(")]"));
exit(1);
}
int
{
int arg;
int Fails ;
char *str;
int level;
char *error_file = NULL;
extern char *optarg;
extern int optind;
int opt;
optind = 1;
{
char domain_path[MAXPATHLEN];
}
/* parse arguments */
switch(opt){
case 'h':
case '?':
print_usage();
break;
case 'f':
print_usage () ;
} else {
}
break ;
case 'y':
break;
case 'p':
{
print_usage();
}
break;
case 'n':
if(relay_agent_name == NULL)
{
exit(1);
}
break;
case 'o':
{
print_usage();
}
if(name_oid_file == NULL)
{
exit(1);
}
break;
case 'c':
{
print_usage();
}
if(config_dir == NULL)
{
exit(1);
}
break;
case 'a':
{
print_usage();
}
if(sec_config_file == NULL)
{
exit(1);
}
break;
case 'r':
{
print_usage();
}
if(resource_file == NULL)
{
exit(1);
}
break;
case 'i':
{
print_usage();
}
{
exit(1);
}
break;
case 'd':
{
print_usage();
}
{
print_usage();
}
{
print_usage();
}
break;
case 'm':
{
print_usage();
}
{
mode = MODE_GROUP;
}
else
{
mode = MODE_SPLIT;
}
else
{
print_usage();
}
break;
default:
print_usage();
break;
}
}
/*
if(error_file == NULL)
{
error_file = default_error_file;
}
error_open(error_file);
*/
if(trace_level == 0)
{
/* run the daemon in backgound */
int pid;
switch(pid)
{
case -1:
break;
case 0: /* child process */
break;
default: /* parent process */
exit(0);
break;
}
}
{
}
{
}
if(trace_level == 0)
{
{
}
}
if(trace_level == 0)
{
/* background */
{
}
/* set process group ID */
setpgrp();
}
return (0);
}