eval '(exit $?0)' && eval 'PERL=`which perl5`; exec $PERL -wS $0 ${1+"$@"}' & eval 'setenv PERL `which perl5`; exec $PERL -wS $0 $argv:q' if 0; ### Local Variables: *** ### mode:perl *** ### comment-column:0 *** ### comment-start: "### " *** ### comment-end: "***" *** ### End: *** # # ****************DO NOT MOVE OR CHANGE LINES ABOVE THIS********************* # # The first set of lines runs perl from any shell. The second set of lines # identifies the rest of the file as PERL for EMACS autoformatting. # See end of copyright for more information. # # # ------------------------------------------------------------------- # X-BONE # # http://www.isi.edu/xbone # USC Information Sciences Institute (USC/ISI) # Marina del Rey, California 90292, USA # Copyright (c) 1998-2005 # # ------------------------------------------------------------------- # # Copyright (c) 1998-2005 by the University of Southern California. # All rights reserved. # # Permission to use, copy, modify, and distribute this software and # its documentation in source and binary forms for non-commercial # purposes and without fee is hereby granted, provided that the above # copyright notice appear in all copies and that both the copyright # notice and this permission notice appear in supporting # documentation, and that any documentation, advertising materials, # and other materials related to such distribution and use acknowledge # that the software was developed by the University of Southern # California, Information Sciences Institute. The name of the # University may not be used to endorse or promote products derived # from this software without specific prior written permission. # # THE UNIVERSITY OF SOUTHERN CALIFORNIA MAKES NO REPRESENTATIONS ABOUT # THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. THIS SOFTWARE IS # PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, # INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # Other copyrights might apply to parts of this software and are so # noted when applicable. # # ------------------------------------------------------------------- # # Effort partly sponsored by the Defense Advanced Research Projects # Agency (DARPA) and Air Force Research Laboratory, Air Force Materiel # Command, USAF, under agreement numbers F30602-98-1-0200 (X-Bone) and # F30602-01-2-0529 (DynaBone). The views and conclusions contained # herein are those of the authors and should not be interpreted as # necessarily representing the official policies or endorsements, # either expressed or implied, of the Defense Advanced Research # Projects Agency (DARPA), the Air Force Research Laboratory, or the # U.S. Government. # # This work was partly supported by the NSF STI-XTEND (ANI-0230789) # and NETFS (ANI-0129689) projects. Any opinions, findings, and # conclusions or recommendations expressed in this material are those # of the authors and do not necessarily reflect the views of the # National Science Foundation. # # ------------------------------------------------------------------- # $RCSfile: xb-node-daemon.pl,v $ # # $Revision: 1.146 $ # $Author: pingali $ # $Date: 2005/04/21 00:25:13 $ # $State: Exp $ # ---------------------------------------------------------------------------- # The first lines start PERL on any system where perl is in the path. # This is a modified version of the "start perl" script provided in # the PERL man pages, which starts perl on the remainder of the file # regardless of whether it is run under sh, csh, or perl. # # This version is modified to dynamically locate the perl path, rather # than requiring it be hard-coded. # set library search path BEGIN { use strict; use sigtrap; use FindBin; use Config; delete $ENV{PATH}; my $version = $Config{'version'}; my $arch = $Config{'archname'}; my $ldir = $FindBin::RealBin; foreach my $p ($ldir, "$ldir/modules", "$ldir/modules/cpan", "$ldir/modules/cpan/lib/perl5/$version", "$ldir/modules/cpan/lib/perl5/$version/$arch", "$ldir/modules/cpan/lib/perl5/site_perl/mach", "$ldir/modules/cpan/lib/perl5/site_perl/mach/$arch", "$ldir/modules/cpan/lib/perl5/site_perl/$version", "$ldir/modules/cpan/lib/perl5/site_perl/$version/$arch", "$ldir/modules/cpan/lib/perl5/site_perl/$version/mach", "$ldir/modules/cpan/lib/perl5/site_perl/$version/mach/$arch", ) { if(-d $p) { unshift @INC, $p; } } # untaint the resulting include path so "use" works foreach my $i (@INC) { if($i =~ /(.*)/) { $i = $1;} } }; ############################################################################## # END OF PREFIX - PUT YOUR PERL CODE BELOW # ############################################################################## # Primary Author: Yu-Shun Wang # Description: This is the new XBone daemon main program file. # Notes: # - TODO: Grep for "TODO"s, those are unfinished tasks & too many of them. use strict; use warnings; use diagnostics; use Getopt::Long; use Data::Dumper; use FindBin; use IO::Socket; use IO::Select; use Net::hostent; use AppConfig; use AppConfig::Getopt; use File::Temp qw(tempfile tempdir); use LWP::UserAgent; use IO::Socket::SSL 0.92; use IO::Socket::Multicast; use IO::Socket::SSLv6; use IO::Socket::Multicast6; use Socket6; use vars qw(@ISA); use XB_Params; use XB_Log; use XB_API; use XB_Common; use XB_CTL; use XB_CTL_parser; use XB_IPsec; use XB_SMIME; use XB_VN_funcs; use XB_VN_IPalloc; use XB_VN_DNS; use XB_XML_GUI; use XB_XML_scan; use XB_LDAP; #use sigtrap; #use POSIX "sys_wait_h"; #use Config; # flags for Data::Dumper $Data::Dumper::Indent = 1; $Data::Dumper::Purity = 1; my $modname = "Main::"; # configuration options: %XB_Params::node_opts = ( "auto" => $XB_Params::auto, # basic configuration options "conf" => $XB_Params::conf, "workdir" => $XB_Params::workdir, "state_file" => $XB_Params::state_file, "pidfile" => $XB_Params::pidfile, "daemon_type" => $XB_Params::daemon_type, "background" => 0 , # node IP config options "hostname" => `hostname`, "ctl_addr" => $XB_Params::ctl_addr, "ctl_addr6" => $XB_Params::ctl_addr6, "app_addr" => $XB_Params::app_addr, "app_addr6" => $XB_Params::app_addr6, # XBone network parameters "ipproto" => $XB_Params::ipproto, "xbone_mcast_addr" => $XB_Params::xbone_mcast_addr, "xbone_mcast_addrv6" => $XB_Params::xbone_mcast_addrv6, "xbone_api_port" => $XB_Params::xbone_api_port, "xbone_ctl_port" => $XB_Params::xbone_ctl_port, # logging options "log_dest" => $XB_Params::log_dest, "log_mask" => $XB_Params::log_mask, "log_file" => $XB_Params::log_file, # X.509 certificate & key info "node_cert" => $XB_Params::node_cert, "node_key" => $XB_Params::node_key, "ca_cert" => $XB_Params::ca_cert, "ca_path" => $XB_Params::ca_path, # ACLs: for overlay manager & users "ovl_manager" => \@XB_Params::ovl_manager, "user_acl" => \%XB_Params::user_acl, "shared_user_acl" => [{}], #empty shared acl list # features & capabilities # - os [should only set these for buddy host; i.e., Cisco] "os" => $XB_Params::os, "os_version" => $XB_Params::os_version, "kern_version" => $XB_Params::kern_version, "node_arch" => $XB_Params::node_arch, # - routing (static vs. dynamic) "routing" => $XB_Params::routing, # - ipsec "IPsec" => $XB_Params::IPsec, # - qos "qos" => $XB_Params::qos, # - [optional] address server options "addrserv" => $XB_Params::addrserv, "netv4" => $XB_Params::netv4, "netv6" => $XB_Params::netv6, "addr_server" => $XB_Params::addr_server, # legacy options "address_type" => $XB_Params::address_type, "control_protocol" => $XB_Params::control_protocol, "linkv4" => $XB_Params::linkv4, "linkv6" => $XB_Params::linkv6, # - [optional] DDNS (Dynamic DNS update) server/zone/key info "xbone_net" => $XB_Params::XBONE_NET, "dns" => $XB_Params::dns, "name_server" => $XB_Params::name_server, "forward_zone" => $XB_Params::forward_zone, "reverse_zone" => $XB_Params::reverse_zone, "reverse_zone6" => $XB_Params::reverse_zone6, "dns_key_file" => $XB_Params::dns_key_file, # - [optional] Dynamic routing options "zebra_dir" => $XB_Params::zebra_dir, # - [optional] Force router options "force-router" => 0, # - [optional] Cisco platform options "cisco_buddy_username" => $XB_Params::CISCO_BUDDY_USERNAME, "cisco_buddy_password" => $XB_Params::CISCO_BUDDY_PASSWORD, "cisco_buddy_enable_password"=> $XB_Params::CISCO_BUDDY_ENABLE_PASSWORD, # - [optional] register attributes "register" => \%XB_Params::register, # - [optional] Ldap options "ldap" => \%XB_Params::ldap, ); # array of option descriptions for Getopt::Long & AppConfig my @opts_spec = ( "auto|a=s", # disable automatic mode # basic configuration options "conf|c=s", # config file "workdir|w=s", # working dir "state_file|s=s", # state file "pidfile|pid=s", # state file "daemon_type|t=s", # daemon type "background|bg", # run in the background # node IP config options "hostname|h=s", # hostname "ctl_addr|caddr=s", # addr for control connection IPv4 "ctl_addr6|caddr6=s", # addr for control connection IPv6 "app_addr|aaddr=s", # addr for app/data connection IPv4 "app_addr6|aaddr6=s", # addr for app/data connection IPv6 # XBone network parameters "ipproto|ip=s", "xbone_mcast_addr|mcast=s", "xbone_mcast_addrv6|mcastv6=s", "xbone_ctl_port|ctl=i", "xbone_api_port|api=i", # logging options "log_dest|d=i", "log_mask|m=s", "log_file|l=s", # X.509 certificate & key info "node_cert|cert=s", "node_key|key=s", "ca_cert|ca=s", "ca_path|cp=s", # ACLs: for overlay manager & users "ovl_manager|om=s@", "user_acl|acl=s%", # node features & capabilities # - os [should only set these for buddy host; i.e., Cisco] "os=s", "os_version|over=s", "kern_version|kver=s", "node_arch|arch=s", # - routing/IPsec/QoS "routing|rt=s", "IPsec|sec=s", "qos|q=s", # address server options [optional] "addrserv|as", # enable address server / IP allocator "netv4|n4=s", # - Overlay net v4 block "netv6|n6=s", # - Overlay net v6 block "addr_server|asname=s", # remote address server # legacy options "address_type|atype=s", "control_protocol|cc=s", "linkv4|l4=s", # - Overlay link v4 block "linkv6|l6=s", # - Overlay link v6 block # DNS related options "xbone_net|xb=s", "dns=s", "name_server|ns=s", "forward_zone|fzone=s", "reverse_zone|rzone=s", "reverse_zone6|rzone6=s", "dns_key_file|dnskey=s", # Dynamic routing related options "zebra_dir|zd=s", # Force router option "force-router|fr", # Cisco platform option "cisco_buddy_username|ciscouname=s", "cisco_buddy_password|ciscopw=s", "cisco_buddy_enable_password|ciscoenpw=s", # variables to be registered with the main xbone daemon "register|reg=s%", # variables to be registered with the main xbone daemon "ldap=s%", ); #=> command line option & config file option hashes my %cmdl_opts; # hash of args from command line my $file_opts; # obj of args from config file my $ldap_opts; # obj of args from ldap server #=> socket handles my ($api_sock, $ctl_sock, $mcast_send_sock, $mcast_recv_sock); my ($api_sock6, $ctl_sock6, $mcast_send_sock6, $mcast_recv_sock6); my ($sel, @ready); #=> timer my ($now, $next_refresh, $next_data_refresh, $next_check); #=> state variable: %XB_Params::node_state = ( "state" => "idle", "node" => "", "creator" => "", "application" => "", "name" => "", "start" => 0, "level" => 0 ); # ============================================================================ # Program structure of X-Bone node daemon: # ============================================================================ # X-Bone node main blocks: # o Initialization # - configuration variables: # - command line, configuration file, default values # - paths & files: # - log file, state file, cert/key, temp file system # - initialization & verification of system capabilities # - logging, ACL, OS, IP, IPsec, QoS, IP address server, etc. # - read & restore state file # - bind sockets # o Main loop # - periodic tasks: refresh/heartbeat, expiration checks # - listen on socket # - switch based on incoming messages & events # - exception handling # - termination # - clean up - files, states, systems # - exit # ============================================================================ # ======================================================================== # Process Command Line & Configuration File Options # ======================================================================== # Description: # Get options from command line and config file. Option precedence: # Command Line > Configuration File > LDAP configuration > Default in XB_Params.pm # Arguments: # - # Returns: # - # Exceptions: # - sub get_opts { #=> get command line options if (GetOptions(\%cmdl_opts, @opts_spec)==0) { print "Usage: ./xb-node-daemon.pl [