/* * babd.c - Babylon Config Daemon source * Copyright (C) 1997-2000 SpellCaster Telecommunications Inc. * Copyright (C) 2003,2007 Benjamin C. R. LaHaise * $Id: babd.cc,v 1.15 2004/10/20 05:09:54 bcrl Exp $ * Released under the GNU Public License. See LICENSE file for details. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "compat.h" #include "config.h" #include "babd.h" #include "d_aps_if.h" #include "aps_if.h" #include "link.h" #include "iface.h" #include "ctrlfd.h" #include "radius.h" #include "selectops.h" #include "dfs_parser.h" SelectEventHandler *selectObjs[2][BAB_OPEN_MAX]; unsigned long interim_update_interval = 6 * 3600 * 100UL; extern void radius_GetConfig(void (*cbf)(void *, OptionSet_t *), void *obj, OptionSet_t *options); extern void write_link_state(int, CLink *, int verbose); extern void write_link_options(int, CLink *); extern "C" { #include "md5.h" }; #define MAX_IFS 500 #define FLAGS_GOOD (IFF_UP | IFF_BROADCAST) #define FLAGS_MASK (IFF_UP | IFF_BROADCAST | IFF_POINTOPOINT | IFF_LOOPBACK | IFF_NOARP) #define CONTROL_PATH "/tmp/.bab_control" /* FIXME: relocate in /dev/? */ static char control_path[PATH_MAX] = CONTROL_PATH; const char *sysname = ""; static int finished = 0; int b_control_fd, b_sock_fd, b_sock6_fd; int am_radius_client = 0; int am_radius_acct_client = 0; int do_userland_only = 0; // Used to disable creating network interfaces void get_config(void); void do_chap_auth(CfgMessage_t *active, CfgMessage_t *auth_buf); void print_usage(); void print_debuglevels(); int broken_acfc=0; /* Don't turn off ACFC after LCP if we were told to if 1 */ int dyn_ip_enabled = -1; /* set if we've enabled dynamic ips; * -1=default -- don't warn if config file * doesn't exist. */ /* Options we support (see the man page) */ static char shrt_options[] = "a:fd:rpinhsu:c:C:y:" #ifdef USE_L2TP "2:" #endif "SU" ; static struct option long_options[] = { { "radius-acct", required_argument, NULL, 'a' }, { "no-fork", no_argument, NULL, 'f' }, { "debug", required_argument, NULL, 'd' }, { "want-mlcp", no_argument, NULL, 'M' }, { "enable-routing", no_argument, NULL, 'R' }, { "enable-proxyarp", no_argument, NULL, 'P' }, { "enable-pfc", no_argument, NULL, 'F' }, { "disable-routing", no_argument, NULL, 'r' }, { "disable-proxyarp", no_argument, NULL, 'p' }, { "enable-dynamicip", no_argument, NULL, 'i' }, { "disable-dynamicip", no_argument, NULL, 'I' }, { "scan-chan", no_argument, NULL, 's' }, { "broken-acfc", no_argument, NULL, 'B' }, #ifdef USE_L2TP { "enable-l2tp", required_argument, NULL, '2' }, #endif { "system-name", required_argument, NULL, 'n' }, { "help", no_argument, NULL, 'h' }, { "help-debug", no_argument, NULL, 'D' }, { "config-file", required_argument, NULL, 'c' }, { "control-socket", required_argument, NULL, 'C' }, { "dynamic-file", required_argument, NULL, 'y' }, { "radius", required_argument, NULL, 'u' }, { "restore-state", no_argument, NULL, 'S' }, { "userland-only", no_argument, NULL, 'U' }, { 0, 0, 0, 0 } }; static char *cmdname; const char DEFAULT_CFG_FILE[]= "/etc/babylon/babylon.conf"; const char DEFAULT_DYN_FILE[]= "/etc/babylon/dynamic_ip.conf"; static char configFile[MAXPATHLEN]; char dynamicFile[MAXPATHLEN]; int do_bdial(ctrlfd_t *cfd, const char *site, const char *phone, Call *call, int lcp_timeout, int lcp_interval, const char *dev_class) { OptionSet_t *options = new OptionSet_t; if (lcp_timeout || lcp_interval) { policy_t *policy = new policy_t; if (lcp_timeout) policy->Set(P_ECHO, lcp_timeout); if (lcp_interval) policy->Set(P_ECHO_INTERVAL, lcp_interval); if (options->pol) delete options->pol; options->pol = policy; } call->ident = ++callIdent; call->set_cfd(cfd); Log(LF_DEBUG|LF_CALL, "do_bdial: call=%p #%d site: %s num: %s...", call, call->ident, site, phone); strncpy(options->site, site, SITE_NAME_LEN-1); strncpy(options->phone, phone, PHONE_LEN-1); if (dev_class) strncpy(options->dev_class, dev_class, CLASS_NAME_LEN); else options->dev_class[0] = 0; options->SetCall(call); babd_GetConfig(DialGotConfig, NULL, options); delete options; return 0; } void cmd_bdial (ctrlfd_t *cfd, char *args) { char *site, *num, *p; const char *dev_class = ""; int wait_for_hangup = 0; int lcp_timeout = 0; int lcp_interval = 0; if (!args[0] || !strcmp(args, "--help")) goto usage; if (!strncmp("--class=", args, 8)) { args += 8; dev_class = args; while (*args && !isspace(*args)) args++; if (*args) *args++ = 0; while (*args && isspace(*args)) args++; } if (!strncmp("--wait-for-hangup ", args, 18)) { args += 18; wait_for_hangup = 1; } if (!strncmp("--lcp-timeout=", args, 14)) { args += 14; lcp_timeout = atoi(args); while (*args && !isspace(*args)) args++; if (*args && isspace(*args)) args++; } if (!strncmp("--lcp-interval=", args, 15)) { args += 15; lcp_interval = atoi(args); while (*args && !isspace(*args)) args++; if (*args && isspace(*args)) args++; } for (p=args; *p && isspace(*p); p++) ; site = p; for (; *p && !isspace(*p); p++) ; if (*p) *p++ = 0; for (; *p && isspace(*p); p++) ; num = p; for (; *p && !isspace(*p); p++) ; *p = 0; do_bdial(cfd, site, num, new Call(wait_for_hangup), lcp_timeout, lcp_interval, dev_class); return; usage: cfd->printf("usage:\n"); cfd->printf(" bdial [--class=] [--wait-for-hangup] [--lcp-timeout=