[Dhcp-agent-commits] dhcp-agent Makefile.am,1.26,1.27 Makefile.in,1.25,1.26 dhcp-agent.h,1.61,1.62 d
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv16896 Modified Files: Makefile.am Makefile.in dhcp-agent.h dhcp-arp-discovery.c dhcp-client-cache.c dhcp-client-conf.c dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-com.c dhcp-daemon.c dhcp-exception.c dhcp-exception.h dhcp-files.c dhcp-files.h dhcp-globconf.c dhcp-icmp-discovery.c dhcp-interface.c dhcp-net.c dhcp-net.h dhcp-print.c dhcp-route.c dhcp-sniff.c dhcp-stringbuffer.c dhcp-sysconf.c dhcp-util.c dhcp-util.h Log Message: new exception code _mostly_ integrated; propogation is broken in several places; Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Makefile.am 24 Jun 2002 02:07:21 -0000 1.26 --- Makefile.am 30 Jun 2002 08:23:45 -0000 1.27 *************** *** 10,14 **** dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-snprintf.c \ ! dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c dhcp-stringbuffer.c dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 10,15 ---- dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-snprintf.c \ ! dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c dhcp-stringbuffer.c \ ! dhcp-exception.c dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Makefile.in 24 Jun 2002 02:07:21 -0000 1.25 --- Makefile.in 30 Jun 2002 08:23:45 -0000 1.26 *************** *** 1,5 **** ! # Makefile.in generated automatically by automake 1.4-p5 from Makefile.am ! # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, --- 1,5 ---- ! # Makefile.in generated automatically by automake 1.4-p4 from Makefile.am ! # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, *************** *** 77,81 **** bin_PROGRAMS = dhcpsniff dhcpclient ! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-snprintf.c dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c dhcp-stringbuffer.c --- 77,81 ---- bin_PROGRAMS = dhcpsniff dhcpclient ! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-snprintf.c dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c dhcp-stringbuffer.c dhcp-exception.c *************** *** 107,111 **** dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-snprintf.o \ dhcp-sniffer-ohandlers.o dhcp-rtt.o dhcp-interface.o \ ! dhcp-stringbuffer.o dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = --- 107,111 ---- dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-snprintf.o \ dhcp-sniffer-ohandlers.o dhcp-rtt.o dhcp-interface.o \ ! dhcp-stringbuffer.o dhcp-exception.o dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = *************** *** 168,172 **** cd $(srcdir) && $(ACLOCAL) ! config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) --- 168,172 ---- cd $(srcdir) && $(ACLOCAL) ! config.status: $(srcdir)/configure.in $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** dhcp-agent.h 22 Jun 2002 01:47:57 -0000 1.61 --- dhcp-agent.h 30 Jun 2002 08:23:45 -0000 1.62 *************** *** 269,273 **** } interface_control_t; - /* * DHCP raw network object. --- 269,272 ---- Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-arp-discovery.c 22 Jun 2002 01:47:57 -0000 1.6 --- dhcp-arp-discovery.c 30 Jun 2002 08:23:45 -0000 1.7 *************** *** 67,70 **** --- 67,71 ---- list_t *arg_list = NULL; unsigned char *sender_addr; + int retval; arg_list = add_to_list(arg_list, &address); *************** *** 75,94 **** while(retries--) { ! if(rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply)) ! continue; ! /* Yummy! We got a valid reply! */ ! sender_addr = arp_get_sender_hardware_address(net->arp_p); ! memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN); ! /* just free up pair. FIXME: this isn't good because we're ! * breaking the list blackbox. we need a better way to do this. ! * the datums don't need to be freed since we keep them on the stack. */ ! xfree(arg_list->next); ! xfree(arg_list); - return 0; } --- 76,114 ---- while(retries--) { ! retval = rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply); ! ! switch(retval) { ! ! case RAWNET_TIMEOUT: ! /* we timed out. retry. */ ! break; ! ! case RAWNET_OK: ! /* Yummy! We got a valid reply! */ ! sender_addr = arp_get_sender_hardware_address(net->arp_p); ! memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN); ! /* just free up pair. FIXME: this isn't good because we're ! * breaking the list blackbox. we need a better way to do this. ! * the datums don't need to be freed since we keep them on the stack. */ ! xfree(arg_list->next); ! xfree(arg_list); ! ! return 0; ! ! case RAWNET_ERROR: ! /* wops error. This is bad. */ ! push_exception("arp-discovery", "arp_discover_hardware_address", ! "received error from raw network handler."); ! return 1; ! ! default: ! /* not good. */ ! fatal_error("arp-discovery: invalid return from rawnet_transact -- this a bug report it."); ! } } *************** *** 97,101 **** --- 117,125 ---- xfree(arg_list); + push_exception("arp-discovery", "arp_discover_hardware_address", + "timeout on discovery."); + /* no response, return error. */ return 1; + } Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-cache.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-cache.c 22 Jun 2002 18:11:25 -0000 1.13 --- dhcp-client-cache.c 30 Jun 2002 08:23:45 -0000 1.14 *************** *** 84,89 **** case VARFILE_PARSE_ERROR: ! fatal_error("client-cache: parse error in cache: %s : line %d", ! varfile_get_filename(varfile), varfile_get_lineno(varfile)); case VARFILE_EOF: --- 84,91 ---- case VARFILE_PARSE_ERROR: ! push_exception("client-cache", "read_next_cache_var", ! "parser error in cache: %s : line %d", ! varfile_get_filename(varfile), varfile_get_lineno(varfile)); ! return NULL; /* XXX needs to return an error value. */ case VARFILE_EOF: *************** *** 109,115 **** varfile = create_varfile(filename, VARFILE_VARVAL_MODE); ! if(varfile == NULL) ! return -1; ! /* Read up any vars. */ --- 111,120 ---- varfile = create_varfile(filename, VARFILE_VARVAL_MODE); ! if(varfile == NULL) { ! push_exception("client-cache", "load_client_cache_proc", ! "unable to create varfile"); ! return -1; ! } ! /* Read up any vars. */ Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client-conf.c 22 Jun 2002 18:11:25 -0000 1.12 --- dhcp-client-conf.c 30 Jun 2002 08:23:45 -0000 1.13 *************** *** 113,118 **** varfile = create_varfile(fname, VARFILE_VARNAMES_MODE); ! if(varfile == NULL) return -1; while(1) { --- 113,121 ---- varfile = create_varfile(fname, VARFILE_VARNAMES_MODE); ! if(varfile == NULL) { ! push_exception("client-conf", "client_conf_load_options", ! "could not open varfile: %s", fname); return -1; + } while(1) { *************** *** 149,154 **** case VARFILE_PARSE_ERROR: ! fatal_error("client-conf: parse error in opts file: %s : %d", ! varfile_get_filename(varfile), varfile_get_lineno(varfile)); default: fatal_error("client-conf: load_options: internal error -- please report this."); --- 152,160 ---- case VARFILE_PARSE_ERROR: ! push_exception("client-conf", "read_next_cache_var", ! "parse error in opts file: %s : %d", ! varfile_get_filename(varfile), varfile_get_lineno(varfile)); ! return -1; ! default: fatal_error("client-conf: load_options: internal error -- please report this."); *************** *** 191,195 **** /* check for options file. */ fname = get_conf_options_fname(cc); ! retval = load_client_conf_proc(fname, cc, client_conf_load_options, use_default_options, dump_config_options); xfree(fname); --- 197,202 ---- /* check for options file. */ fname = get_conf_options_fname(cc); ! retval = load_client_conf_proc(fname, cc, client_conf_load_options, ! use_default_options, dump_config_options); xfree(fname); Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** dhcp-client-control.c 22 Jun 2002 01:47:57 -0000 1.22 --- dhcp-client-control.c 30 Jun 2002 08:23:45 -0000 1.23 *************** *** 70,75 **** s++; ! if(hex_string_to_value(mac_string, mac_add)) ! fatal_error("malformed mac_string for fake_client_id. please check mac address."); memcpy(s, mac_add, ETH_ADDR_LEN); --- 70,79 ---- s++; ! if(hex_string_to_value(mac_string, mac_add)) { ! push_exception("client-control", "create_fake_client_id", ! "malformed mac string: %s: -- please try another one", ! mac_string); ! return NULL; ! } memcpy(s, mac_add, ETH_ADDR_LEN); *************** *** 130,134 **** dc->cache = create_client_cache(dc); ! if((load_client_conf(dc->conf) < 0) || (load_client_cache(dc->cache, 0) < 0)) { destroy_dhcp_client_control(dc); return NULL; --- 134,147 ---- dc->cache = create_client_cache(dc); ! if(load_client_conf(dc->conf) < 0) { ! push_exception("client-control", "create_dhcp_client_control", ! "could not read client conf."); ! destroy_dhcp_client_control(dc); ! return NULL; ! } ! ! if(load_client_cache(dc->cache, 0) < 0) { ! push_exception("client-control", "create_dhcp_client_control", ! "could not read client cache."); destroy_dhcp_client_control(dc); return NULL; *************** *** 159,162 **** --- 172,177 ---- if((dc->rawnet = rawnet_create(interface, filter_buff, sport, dport, promiscuous)) == NULL) { + push_exception("client-control", "create_dhcp_client_control", + "could acquire rawnet handler."); destroy_dhcp_client_control(dc); return NULL; *************** *** 183,187 **** if(rawnet_get_hw_addr(dc->rawnet, &interface_addr)) { ! error_message("could not acquire interface address"); destroy_dhcp_client_control(dc); return NULL; --- 198,203 ---- if(rawnet_get_hw_addr(dc->rawnet, &interface_addr)) { ! push_exception("client-control", "create_dhcp_client_control", ! "could not acquire interface address."); destroy_dhcp_client_control(dc); return NULL; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** dhcp-client-states.c 24 Jun 2002 14:32:25 -0000 1.32 --- dhcp-client-states.c 30 Jun 2002 08:23:45 -0000 1.33 *************** *** 128,132 **** */ ! static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { ip_addr_t client_ip_addr; --- 128,132 ---- */ ! static int client_broadcast_arp_reply(dhcp_client_control_t *dc) { ip_addr_t client_ip_addr; *************** *** 137,147 **** build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); ! rawnet_send_packet(dc->rawnet); ! return; } /* UNARP (rfc 1868). This makes us more network friendly. */ ! static void client_broadcast_unarp(dhcp_client_control_t *dc) { ip_addr_t client_ip_addr; --- 137,151 ---- build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); ! if(rawnet_send_packet(dc->rawnet) < 0) { ! push_exception("dhcp-client-states", "client_broadcast_arp_reply", ! "could not transmit arp reply"); ! return -1; ! } ! return 0; } /* UNARP (rfc 1868). This makes us more network friendly. */ ! static int client_broadcast_unarp(dhcp_client_control_t *dc) { ip_addr_t client_ip_addr; *************** *** 152,158 **** build_unarp(dc->rawnet, client_ip_addr, client_hw_addr); ! rawnet_send_packet(dc->rawnet); ! ! return; } --- 156,166 ---- build_unarp(dc->rawnet, client_ip_addr, client_hw_addr); ! if(rawnet_send_packet(dc->rawnet) < 0) { ! push_exception("dhcp-client-states", "client_broadcast_unarp", ! "could not transmit unarp"); ! return -1; ! } ! ! return 0; } *************** *** 171,174 **** --- 179,183 ---- { list_t *options = NULL; + int retval; options = client_build_option_list(dc->conf->options, DHCP_DISCOVER_TM, *************** *** 186,194 **** build_dhcp_discover(dc->rawnet, dc->xid, dc->secs, options); ! ! if(rawnet_packet_transact(dc->rawnet, dc, client_update_packet, ! client_check_discover)) { ! error_message("timeout on DHCP DISCOVER."); ! return STATE_FATAL_ERROR; } --- 195,219 ---- build_dhcp_discover(dc->rawnet, dc->xid, dc->secs, options); ! ! retval = rawnet_packet_transact(dc->rawnet, dc, client_update_packet, ! client_check_discover); ! ! switch(retval) { ! ! case RAWNET_TIMEOUT: ! push_exception("client-states", "client_discover_offer", ! "timeout on DHCP discover."); ! return STATE_FATAL_ERROR; ! ! case RAWNET_OK: ! break; ! ! case RAWNET_ERROR: ! push_exception("client-states", "client_discover_offer", ! "received error from raw network handler."); ! return STATE_FATAL_ERROR; ! ! default: ! fatal_error("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); } *************** *** 208,212 **** /* dump cache file. */ if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { ! error_message("could not create temporary cache"); return STATE_FATAL_ERROR; } --- 233,238 ---- /* dump cache file. */ if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { ! push_exception("client-states", "client_discover_offer", ! "could not create temporary cache."); return STATE_FATAL_ERROR; } *************** *** 221,224 **** --- 247,251 ---- { list_t *options, *cache_options; + int retval; /* Build options along with the options in our cache. */ *************** *** 228,232 **** if(cache_options == NULL) { ! error_message("Could not load cache! This is not good!"); return STATE_FATAL_ERROR; } --- 255,260 ---- if(cache_options == NULL) { ! push_exception("client-states", "client_request_ack", ! "could not load cache."); return STATE_FATAL_ERROR; } *************** *** 239,245 **** build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); ! if(rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request)) { ! error_message("timeout on DHCP REQUEST."); ! return STATE_FATAL_ERROR; } --- 267,289 ---- build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); ! retval = rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request); ! ! switch(retval) { ! ! case RAWNET_TIMEOUT: ! push_exception("client-states", "client_request_ack", ! "timeout on DHCP discover."); ! return STATE_FATAL_ERROR; ! ! case RAWNET_OK: ! break; ! ! case RAWNET_ERROR: ! push_exception("client-states", "client_request_ack", ! "received error from raw network handler."); ! return STATE_FATAL_ERROR; ! ! default: ! fatal_error("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); } *************** *** 261,265 **** options = client_cache_load_option_string_list(dc->cache, 0); if(options == NULL) { ! error_message("received empty configuration cache! cannot configure host"); return STATE_FATAL_ERROR; } --- 305,310 ---- options = client_cache_load_option_string_list(dc->cache, 0); if(options == NULL) { ! push_exception("client-states", "client_setup", ! "received empty configuration cache! cannot configure host"); return STATE_FATAL_ERROR; } *************** *** 275,279 **** cache_entry_purge_list(options); ! client_broadcast_arp_reply(dc); return STATE_WAIT; --- 320,326 ---- cache_entry_purge_list(options); ! if(client_broadcast_arp_reply(dc) < 0) { ! return STATE_FATAL_ERROR; ! } return STATE_WAIT; *************** *** 335,339 **** if(rawnet_send_packet(dc->rawnet) < 0) { ! error_message("could not send packet: %s", strerror(errno)); return STATE_FATAL_ERROR; } --- 382,387 ---- if(rawnet_send_packet(dc->rawnet) < 0) { ! push_exception("client-states", "client_release", ! "could not send release."); return STATE_FATAL_ERROR; } *************** *** 344,348 **** * bringing it down later. */ ! client_broadcast_unarp(dc); /* since we're releasing the lease we should down the interface */ --- 392,398 ---- * bringing it down later. */ ! if(client_broadcast_unarp(dc) < 0) { ! return STATE_FATAL_ERROR; ! } /* since we're releasing the lease we should down the interface */ Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** dhcp-client.c 24 Jun 2002 14:32:25 -0000 1.35 --- dhcp-client.c 30 Jun 2002 08:23:45 -0000 1.36 *************** *** 84,87 **** --- 84,90 ---- static int promiscuous = 0; /* whether or not we're running in promiscious mode. */ + /* stringbuffer pointer to unroll exceptions. */ + static stringbuffer *exception_errors; + /* Utility routines. */ *************** *** 92,98 **** filename = splice_string(interface, ".conf"); ! if(init_glob_conf(filename)) ! fatal_error("could not read nor create global configuration file: %s", filename); return; } --- 95,106 ---- filename = splice_string(interface, ".conf"); ! if(init_glob_conf(filename)) { ! push_exception("main", "read_global_conf", ! "could not read nor create global configuration file: %s", filename); ! exception_errors = unroll_exceptions(); ! fatal_error_exception(exception_errors); ! } + xfree(filename); return; } *************** *** 226,231 **** case STATE_FATAL_ERROR: ! info_message("I've encountered a fatal error. I'm giving up."); ! do_shutdown(dc); case STATE_DISCOVER_OFFER: --- 234,242 ---- case STATE_FATAL_ERROR: ! push_exception("main", "do_dhcp_client_loop", ! "encountered fatal error. I'm giving up."); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); ! do_shutdown(dc); case STATE_DISCOVER_OFFER: *************** *** 266,277 **** if(get_pid_file(interface, &pid)) { ! error_message("could not get %s PID.", getprogname()); ! error_message("maybe it's not running?"); return; } if(kill(pid, SIGTERM) < 0) { ! error_message("could not send signal to %s process.", getprogname()); ! error_message("maybe it's not running?"); return; } --- 277,292 ---- if(get_pid_file(interface, &pid)) { ! push_exception("main", "do_kill_client", "Could not get PID for client %s. Maybe it's not running?", ! interface); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); return; } if(kill(pid, SIGTERM) < 0) { ! push_exception("main", "do_kill_client", "Could not send signal to client on %s. Maybe it's not running?", ! interface); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); return; } *************** *** 287,298 **** if(get_pid_file(interface, &pid)) { ! error_message("could not get %s PID.", getprogname()); ! error_message("maybe it's not running?"); return; } if(kill(pid, SIGALRM) < 0) { ! error_message("could not send signal to %s process.", getprogname()); ! error_message("maybe it's not running?"); return; } --- 302,319 ---- if(get_pid_file(interface, &pid)) { ! push_exception("main", "do_wake_client", ! "Could not get PID for client %s. Maybe it's not running?", ! interface); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); return; } if(kill(pid, SIGALRM) < 0) { ! push_exception("main", "do_wait_client", ! "Could not send signal to client on %s. Maybe it's not running?", ! interface); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); return; } *************** *** 312,317 **** /* A race condition exists between the discover and request state. * And we can't hup the client and tell it the cache has been deleted. */ ! error_message("%s already running.", getprogname()); ! error_message("I won't delete cache until it's shutdown."); return; } --- 333,341 ---- /* A race condition exists between the discover and request state. * And we can't hup the client and tell it the cache has been deleted. */ ! push_exception("main", "do_clear_cache", ! "%s already is running on %s. I won't delete the cache until it shuts down.", ! getprogname(), interface); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); return; } *************** *** 376,381 **** if(client_process_exists(interface)) { ! error_message("dhcpclient already exists on interface %s use -k to kill it", interface); ! exit(1); } --- 400,407 ---- if(client_process_exists(interface)) { ! push_exception("main", "do_client", ! "dhcpclient already exists on interface %s use -k to kill it", interface); ! exception_errors = unroll_exceptions(); ! fatal_error_exception(exception_errors); } *************** *** 405,409 **** if((dc = create_dhcp_client_control(interface, promiscuous)) == NULL) { ! error_message("encountered fatal error. cannot continue. exiting"); do_shutdown(NULL); } --- 431,438 ---- if((dc = create_dhcp_client_control(interface, promiscuous)) == NULL) { ! push_exception("main", "do_client", ! "Encountered a fatal error. I'm exiting."); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); do_shutdown(NULL); } *************** *** 435,443 **** if((dc = create_dhcp_client_control(interface, promiscuous)) == NULL) { ! error_message("encountered a fatal error. cannot continue. exiting"); do_shutdown(NULL); } ! create_pid_file(interface); if(fake_hw_addr) /* Marla, you liar, you big tourist, I need this. Now get out! */ --- 464,481 ---- if((dc = create_dhcp_client_control(interface, promiscuous)) == NULL) { ! push_exception("main", "do_client", ! "Encountered a fatal error. I'm exiting.", interface); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); do_shutdown(NULL); } ! if(create_pid_file(interface)) { ! push_exception("main", "do_client", ! "Could not create PID file for interface: %s"); ! exception_errors = unroll_exceptions(); ! error_exception(exception_errors); ! do_shutdown(NULL); ! } if(fake_hw_addr) /* Marla, you liar, you big tourist, I need this. Now get out! */ *************** *** 534,543 **** } ! if(interface == NULL && command_code != DO_VERSION) { ! /* if we were unable to attain an interface. */ ! error_message("unable to retrieve suitable interface"); ! error_message("for this operation: %s", command_string[command_code]); ! exit(1); /* can't use fatal_error for multiline error message. */ ! /* fixme: this stupidity will go with exception stack. */ } --- 572,582 ---- } ! if(interface == NULL && command_code != DO_VERSION) { ! ! push_exception("main", "main", ! "unable to retrieve suitable interface for this operation: %s", ! command_string[command_code]); ! exception_errors = unroll_exceptions(); ! fatal_error_exception(exception_errors); } Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-com.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-com.c 17 Jun 2002 13:23:07 -0000 1.9 --- dhcp-com.c 30 Jun 2002 08:23:45 -0000 1.10 *************** *** 506,510 **** if(len == 0) { ! error_message("error building parameter request: no options!"); return NULL; } --- 506,510 ---- if(len == 0) { ! warn_message("empty parameter list built!"); return NULL; } Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-daemon.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-daemon.c 17 Jun 2002 13:23:08 -0000 1.7 --- dhcp-daemon.c 30 Jun 2002 08:23:45 -0000 1.8 *************** *** 95,99 **** /* Not good. */ /* Also we haven't opened logging yet, so do it now and exit. */ ! init_log(binname); fatal_error("initialization: fork: %s", strerror(errno)); --- 95,99 ---- /* Not good. */ /* Also we haven't opened logging yet, so do it now and exit. */ ! init_log(getprogname()); fatal_error("initialization: fork: %s", strerror(errno)); Index: dhcp-exception.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-exception.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-exception.c 24 Jun 2002 14:32:25 -0000 1.2 --- dhcp-exception.c 30 Jun 2002 08:23:45 -0000 1.3 *************** *** 28,32 **** #include <dhcp-agent.h> #include <dhcp-util.h> - #include <dhcp-exception.h> static exception_t exceptions; --- 28,31 ---- *************** *** 91,93 **** --- 90,102 ---- return unrolled_exception; + } + + void clear_exceptions(void) + { + int i; + + for(i = 0; i < exceptions.cur_index; i++) + destroy_stringbuffer(exceptions.exception_message[i]); + + exceptions.cur_index = 0; } Index: dhcp-exception.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-exception.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-exception.h 24 Jun 2002 14:32:25 -0000 1.2 --- dhcp-exception.h 30 Jun 2002 08:23:45 -0000 1.3 *************** *** 36,39 **** char *fmt, ...); extern stringbuffer *unroll_exceptions(void); ! ! #define THROW_EXCEPTION(module_name, func_name, msg, return_val) { (push_exception(module_name, func_name, msg); return return_val;) } --- 36,38 ---- char *fmt, ...); extern stringbuffer *unroll_exceptions(void); ! extern void clear_exceptions(void); Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-files.c 17 Jun 2002 13:23:08 -0000 1.12 --- dhcp-files.c 30 Jun 2002 08:23:45 -0000 1.13 *************** *** 36,40 **** if((fd = open(filename, flags, mode)) < 0) { ! error_message("cannot open or create file: %s : %s", filename, strerror(errno)); return NULL; } --- 36,41 ---- if((fd = open(filename, flags, mode)) < 0) { ! push_exception("files", "file_open_proc", ! "cannot open or create file: %s : %s", filename, strerror(errno)); return NULL; } *************** *** 42,46 **** if((fp = fdopen(fd, cmode)) == NULL) { close(fd); ! error_message("cannot fdopen: %s : %s", filename, strerror(errno)); return NULL; } --- 43,48 ---- if((fp = fdopen(fd, cmode)) == NULL) { close(fd); ! push_exception("files", "file_open_proc", ! "cannot fdopen file: %s : %s", filename, strerror(errno)); return NULL; } *************** *** 64,70 **** /* delete a file. */ ! void delete_file(char *fname) { ! unlink(fname); } --- 66,72 ---- /* delete a file. */ ! int delete_file(char *fname) { ! return(unlink(fname)); } *************** *** 109,114 **** } /* create a pid file <name>.pid */ ! void create_pid_file(char *name) { FILE *fp; --- 111,117 ---- } + /* XXX - check return val. */ /* create a pid file <name>.pid */ ! int create_pid_file(char *name) { FILE *fp; *************** *** 117,122 **** fname = get_pid_file_name(name); fp = file_create_and_truncate_safe(fname, "a"); ! if(fp == NULL) ! fatal_error("could not create pid file"); fprintf(fp, "%u", getpid()); --- 120,130 ---- fname = get_pid_file_name(name); fp = file_create_and_truncate_safe(fname, "a"); ! if(fp == NULL) { ! push_exception("files", "create_pid_file", ! "cannot open or create file: %s : %s", fname, strerror(errno)); ! xfree(fname); ! return -1; ! } ! fprintf(fp, "%u", getpid()); *************** *** 124,139 **** fclose(fp); xfree(fname); ! return; } /* delete a pid file <name>.pid */ ! void delete_pid_file(char *name) { char *fname = get_pid_file_name(name); ! unlink(fname); xfree(fname); ! return; } --- 132,153 ---- fclose(fp); xfree(fname); ! return 0; } + /* XXX -- handle return val */ /* delete a pid file <name>.pid */ ! int delete_pid_file(char *name) { char *fname = get_pid_file_name(name); ! if(delete_file(fname) < 0) { ! push_exception("files", "delete_pid_file", ! "could not delete pid file: %s : %s", fname, strerror(errno)); ! xfree(fname); ! return 1; ! } xfree(fname); ! return 0; } *************** *** 150,155 **** fp = file_open_or_create_safe(fname, "r"); ! if(fp == NULL) ! fatal_error("could not open pid file"); fscanf(fp, "%u", pid); --- 164,173 ---- fp = file_open_or_create_safe(fname, "r"); ! if(fp == NULL) { ! push_exception("files", "get_pid_file", ! "could not open pid file"); ! xfree(fname); ! return 1; ! } fscanf(fp, "%u", pid); Index: dhcp-files.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-files.h 17 Jun 2002 13:23:08 -0000 1.4 --- dhcp-files.h 30 Jun 2002 08:23:45 -0000 1.5 *************** *** 32,39 **** extern int file_exists(char *fname); extern void move_file(char *fname, char *dest); ! extern void delete_file(char *fname); extern void make_file_public_read(char *fname); ! extern void create_pid_file(char *name); ! extern void delete_pid_file(char *name); extern int get_pid_file(char *name, pid_t *pid); --- 32,39 ---- extern int file_exists(char *fname); extern void move_file(char *fname, char *dest); ! extern int delete_file(char *fname); extern void make_file_public_read(char *fname); ! extern int create_pid_file(char *name); ! extern int delete_pid_file(char *name); extern int get_pid_file(char *name, pid_t *pid); Index: dhcp-globconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-globconf.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-globconf.c 22 Jun 2002 18:11:25 -0000 1.9 --- dhcp-globconf.c 30 Jun 2002 08:23:45 -0000 1.10 *************** *** 57,62 **** fp = file_open_or_create_safe(filename, "w"); ! if(fp == NULL) return -1; for(i = 0;i < GLOBAL_OPTIONS_LEN; i++) { --- 57,65 ---- fp = file_open_or_create_safe(filename, "w"); ! if(fp == NULL) { ! push_exception("glob-conf", "glob_conf_dump", ! "cannot open or create file: %s : %s", filename, strerror(errno)); return -1; + } for(i = 0;i < GLOBAL_OPTIONS_LEN; i++) { *************** *** 65,69 **** continue; ! var_string = global_config_options[i].convert_option_to_string(global_config_options[i].val, global_config_options[i].size); if(var_string == NULL) fatal_error("could not convert option to string -- this is a bug report it."); --- 68,73 ---- continue; ! var_string = global_config_options[i]. ! convert_option_to_string(global_config_options[i].val, global_config_options[i].size); if(var_string == NULL) fatal_error("could not convert option to string -- this is a bug report it."); *************** *** 87,91 **** if(global_config_options[i].val == NULL) { ! global_config_options[i].val = global_config_options[i].convert_option_to_internal(global_config_options[i].default_val); if(global_config_options[i].val == NULL) fatal_error("glob-conf: unable to convert value for option %s -- default! this is a bug. report it!"); --- 91,96 ---- if(global_config_options[i].val == NULL) { ! global_config_options[i].val = global_config_options[i]. ! convert_option_to_internal(global_config_options[i].default_val); if(global_config_options[i].val == NULL) fatal_error("glob-conf: unable to convert value for option %s -- default! this is a bug. report it!"); *************** *** 114,119 **** varfile = create_varfile(filename, VARFILE_VARVAL_MODE); ! if(varfile == NULL) ! fatal_error("glob-conf: could not open configuration file: %s: %s", filename, strerror(errno)); while(1) { --- 119,127 ---- varfile = create_varfile(filename, VARFILE_VARVAL_MODE); ! if(varfile == NULL) { ! push_exception("glob-conf", "init_globconf", ! "cannot acquire varfile: %s", filename); ! return -1; ! } while(1) { *************** *** 140,146 **** global_config_options[i].convert_option_to_internal(varfile_get_val(varfile)); ! if(global_config_options[i].val == NULL) ! fatal_error("glob-conf: unable to convert value for option %s : line no: %d -- munged variable?", ! varfile_get_name(varfile), varfile_get_lineno(varfile)); break; } --- 148,158 ---- global_config_options[i].convert_option_to_internal(varfile_get_val(varfile)); ! if(global_config_options[i].val == NULL) { ! push_exception("glob-conf", "init_globconf", ! "unable to convert value for option %s : line no: %d -- munged variable?", ! varfile_get_name(varfile), varfile_get_lineno(varfile)); ! return -1; ! } ! break; } Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-icmp-discovery.c 22 Jun 2002 01:47:57 -0000 1.16 --- dhcp-icmp-discovery.c 30 Jun 2002 08:23:45 -0000 1.17 *************** *** 54,57 **** --- 54,58 ---- { uint32_t reply_mask; + int retval; /* Build ICMP mask request packet. We don't actually care *************** *** 63,85 **** if(retries <= 0) /* let's not get hosed shall we? */ { ! error_message("icmp mask discovery: bad number of retries"); return -1; } while(retries--) { - if(rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply)) { - error_message("icmp mask discovery: timeout on discovery"); - return -1; - } - } ! /* A reply should contain the subnet mask. If we're actually ! * doing subnet mask discovery we assume any subnet mask ! * returned is valid. */ ! reply_mask = icmp_mask_get_mask(net->icmp_p); ! memcpy(subnet_mask, &reply_mask, IP_ADDR_LEN); ! return 0; } --- 64,105 ---- if(retries <= 0) /* let's not get hosed shall we? */ { ! push_exception("icmp-discovery", "icmp_subnet_mask_discovery", ! "bad number of retries: %d", retries); return -1; } while(retries--) { ! retval = rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply); ! ! switch(retval) { ! ! case RAWNET_TIMEOUT: ! break; ! ! case RAWNET_ERROR: ! push_exception("icmp-discovery", "icmp_subnet_mask_discovery", ! "received error from raw network handler."); ! return -1; ! ! case RAWNET_OK: ! ! /* A reply should contain the subnet mask. If we're actually ! * doing subnet mask discovery we assume any subnet mask ! * returned is valid. */ ! reply_mask = icmp_mask_get_mask(net->icmp_p); ! memcpy(subnet_mask, &reply_mask, IP_ADDR_LEN); ! return 0; ! ! default: ! fatal_error("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); ! } ! } ! ! push_exception("icmp-discovery", "icmp_subnet_mask_discovery", ! "timeout on icmp subnet discovery."); ! return -1; } *************** *** 160,164 **** if(route_find(net, *host_addr, &dest_mac)) { ! error_message("icmp_rtt_discovery: could not find route for address for %s -- skipping", network_address_to_string_static(*host_addr)); continue; } --- 180,185 ---- if(route_find(net, *host_addr, &dest_mac)) { ! warn_message("icmp_rtt_discovery: could not find route for address for %s -- skipping", ! network_address_to_string_static(*host_addr)); continue; } Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-interface.c 22 Jun 2002 01:47:57 -0000 1.19 --- dhcp-interface.c 30 Jun 2002 08:23:45 -0000 1.20 *************** *** 34,43 **** { ! if(intf_get(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %s", ic->interface_entry->intf_name, ! strerror(errno)); return -1; } - return 0; } --- 34,42 ---- { ! if(intf_get(ic->interface_handle, ic->interface_entry) < 0) { ! push_exception("interface", "interface_get_info", "could not lookup interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; } return 0; } *************** *** 47,52 **** { if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %s", ic->interface_entry->intf_name, ! strerror(errno)); return -1; } --- 46,52 ---- { if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! push_exception("interface", "interface_get_info", ! "could not lookup interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; } *************** *** 64,69 **** ic->interface_handle = intf_open(); ! if(ic->interface_handle == NULL) /* XXX -- update to dnet's error strings when dnet has some */ ! fatal_error("interface_control: could not acquire interface handler"); buf = xcalloc(1024); --- 64,72 ---- ic->interface_handle = intf_open(); ! if(ic->interface_handle == NULL) { /* XXX -- update to dnet's error strings when dnet has some */ ! push_exception("interface", "interface_get_info", ! "could not acquire interface handler"); ! return NULL; ! } buf = xcalloc(1024); *************** *** 96,101 **** int mtu) { ! if(interface_get_info(ic)) return -1; /* Set address if needed. */ --- 99,108 ---- int mtu) { ! if(interface_get_info(ic)) { ! push_exception("interface", "interface_up", ! "could not bring up interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; + } /* Set address if needed. */ *************** *** 117,122 **** ic->interface_entry->intf_flags |= INTF_FLAG_UP; ! if(interface_set_info(ic)) return -1; return 0; --- 124,133 ---- ic->interface_entry->intf_flags |= INTF_FLAG_UP; ! if(interface_set_info(ic)) { ! push_exception("interface", "interface_up", ! "could not bring up interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; + } return 0; *************** *** 127,137 **** { ! if(interface_get_info(ic)) return -1; ! ic->interface_entry->intf_flags &= ~INTF_FLAG_UP; ! if(interface_set_info(ic)) return -1; return 0; --- 138,156 ---- { ! if(interface_get_info(ic)) { ! push_exception("interface", "interface_up", ! "could not bring down interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; ! } ! ic->interface_entry->intf_flags &= ~INTF_FLAG_UP; ! if(interface_set_info(ic)) { ! push_exception("interface", "interface_up", ! "could not bring down interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; + } return 0; *************** *** 141,146 **** int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr) { ! if(interface_get_info(ic)) return -1; memcpy(addr, &ic->interface_entry->intf_addr.addr_ip, IP_ADDR_LEN); --- 160,169 ---- int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr) { ! if(interface_get_info(ic)) { ! push_exception("interface", "interface_up", ! "could not get interface IP address %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); return -1; + } memcpy(addr, &ic->interface_entry->intf_addr.addr_ip, IP_ADDR_LEN); *************** *** 212,222 **** interfaces = intf_open(); if(interfaces == NULL) { - - error_message("dhcp-interface: interfaces_get_available: could not obtain interface handle: %s\n", strerror(errno)); /* yes it's too long -- need exception stack. */ - xfree(interface_list); /* fixme: this isn't really * good. we should have a way to destroy a list but not its * datums if we want to. */ intf_close(interfaces); return NULL; } --- 235,244 ---- interfaces = intf_open(); if(interfaces == NULL) { xfree(interface_list); /* fixme: this isn't really * good. we should have a way to destroy a list but not its * datums if we want to. */ intf_close(interfaces); + push_exception("interface", "interface_get_proc", + "could not obtain interface handle: %s\n", strerror(errno)); return NULL; } *************** *** 241,243 **** return(interfaces_get_proc(check_interface_down)); } - --- 263,264 ---- Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** dhcp-net.c 23 Jun 2002 03:29:13 -0000 1.29 --- dhcp-net.c 30 Jun 2002 08:23:45 -0000 1.30 *************** *** 109,140 **** #endif /* HAVE_BPF_IMMEDIATE */ - /* If interface not specificed get - * a suitable one from pcap_lookupdev */ - - if(interface_name == NULL) - interface_name = pcap_lookupdev(errbuf); - - if(interface_name == NULL) { - error_message("rawnet: pcap_lookupdev: %s", errbuf); - return NULL; - } - /* Open packet capturing device. */ pcap = pcap_open_live(interface_name, SNAPLEN, promiscuous, 0, errbuf); if(pcap == NULL) { ! error_message("rawnet: pcap_openlive: %s", errbuf); return NULL; } if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) { pcap_close(pcap); - error_message("rawnet: pcap_compile: %s",pcap_geterr(pcap)); return NULL; } if(pcap_setfilter(pcap, &filter) == -1) { pcap_close(pcap); - error_message("rawnet: pcap_setfilter: %s", pcap_geterr(pcap)); return NULL; } --- 109,135 ---- #endif /* HAVE_BPF_IMMEDIATE */ /* Open packet capturing device. */ pcap = pcap_open_live(interface_name, SNAPLEN, promiscuous, 0, errbuf); if(pcap == NULL) { ! push_exception("rawnet", "initialize_pcap_device", ! "could not open pcap device: %s", ! pcap_geterr(pcap)); return NULL; } if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) { + push_exception("rawnet", "initialize_pcap_device", + "could not compile pcap filter: %s", + pcap_geterr(pcap)); pcap_close(pcap); return NULL; } if(pcap_setfilter(pcap, &filter) == -1) { + push_exception("rawnet", "initialize_pcap_device", + "could not compile pcap filter: %s", + pcap_geterr(pcap)); pcap_close(pcap); return NULL; } *************** *** 143,151 **** #if defined(HAVE_BPF_IMMEDIATE) ! /* FreeBSD (others too?) need us to set the descriptor non ! * blocking and do a bogus read. This starts the timer. */ ! fd = pcap_fileno(pcap); ! ioctl(fd, BIOCIMMEDIATE, &on); #endif /* HAVE_BPF_IMMEDIATE */ --- 138,159 ---- #if defined(HAVE_BPF_IMMEDIATE) ! /* FreeBSD, and possibly other flavors with BPF need us to ! * set the descriptor non blocking with BIOCIMMEDIATE. */ ! if(fd = pcap_fileno(pcap) < 0) { ! push_exception("rawnet", "initialize_pcap_device", ! "could not obtain pcap descriptor: %s", ! pcap_geterr(pcap)); ! pcap_close(pcap); ! return NULL; ! } ! ! if(ioctl(fd, BIOCIMMEDIATE, &on) < 0) { ! push_exception("rawnet", "initialize_pcap_device", ! "could not set BIOCIMMEDIATE: %s", ! strerror(errno)); ! pcap_close(pcap); ! return NULL; ! } #endif /* HAVE_BPF_IMMEDIATE */ *************** *** 160,166 **** if(interface_up(net->intf_handle, addr, netmask, mtu)) { ! error_message("rawnet: could not bring up interface: %s: %s", net->device, strerror(errno)); ! rawnet_destroy(net); ! return 1; } --- 168,174 ---- if(interface_up(net->intf_handle, addr, netmask, mtu)) { ! push_exception("rawnet", "interface_up", ! "could not bring interface up."); ! return -1; } *************** *** 173,179 **** { if(interface_down(net->intf_handle)) { ! error_message("rawnet: could not bring down interface: %s: %s", net->device, strerror(errno)); ! rawnet_destroy(net); ! return 1; } --- 181,187 ---- { if(interface_down(net->intf_handle)) { ! push_exception("rawnet", "interface_up", ! "could not bring interface down."); ! return -1; } *************** *** 189,192 **** --- 197,201 ---- { rawnet_t *net; + int retval; net = xcalloc(sizeof(rawnet_t)); *************** *** 201,204 **** --- 210,214 ---- net->intf_handle = create_interface_control(net->device); if(net->intf_handle == NULL) { + push_exception("rawnet", "rawnet_create", "could not acquire interface handle"); rawnet_destroy(net); return NULL; *************** *** 206,212 **** /* Is the interface up? */ ! if(!interface_is_up(net->intf_handle)) { ! /* then bring it up with dum values. */ if(rawnet_interface_up(net, 0, 0xffffff, -1)) { rawnet_destroy(net); return NULL; --- 216,235 ---- /* Is the interface up? */ ! retval = interface_is_up(net->intf_handle); ! ! if(retval == -1) { ! /* error on interface detection */ ! push_exception("rawnet", "rawnet_create", ! "error on interface detection for device: %s", device); ! rawnet_destroy(net); ! return NULL; ! } ! ! if(retval == 0) { ! /* interface down */ ! /* bring it up with dum values. */ if(rawnet_interface_up(net, 0, 0xffffff, -1)) { + push_exception("rawnet", "rawnet_create", NULL, + "error trying to bring device up: %s", device); rawnet_destroy(net); return NULL; *************** *** 214,217 **** --- 237,242 ---- } + /* any other value of retval and the interface is already up. */ + /* Get the interface and make sure its an ethernet interface or * else we're hosed. */ *************** *** 219,223 **** net->eth = eth_open(device); if(net->eth == NULL) { ! error_message("rawnet: device not supported or unavailable: %s: %s", device, strerror(errno)); rawnet_destroy(net); return NULL; --- 244,249 ---- net->eth = eth_open(device); if(net->eth == NULL) { ! push_exception("rawnet", "rawnet_create", NULL, ! "device not available or supported: %s : %s", device, strerror(errno)); rawnet_destroy(net); return NULL; *************** *** 228,231 **** --- 254,259 ---- if(net->pcap == NULL) { rawnet_destroy(net); + push_exception("rawnet", "rawnet_create", NULL, + "could not initialize pcap device for: %s", device); return NULL; } *************** *** 233,237 **** net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ! error_message("rawnet: cannot get descriptor for %s, this system may is not supported.", device); rawnet_destroy(net); return NULL; --- 261,266 ---- net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ! push_exception("rawnet", "rawnet_create", NULL, ! "could not get pcap descriptor for: %s: %s", device, pcap_geterr(net->pcap)); rawnet_destroy(net); return NULL; *************** *** 266,276 **** * address. */ ! void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { unsigned char mac_addr[ETH_ADDR_LEN]; net->fake_hw_addr = xmalloc(sizeof(eth_addr_t)); ! if(hex_string_to_value(mac_string, mac_addr)) ! fatal_error("malformed mac_string for fake client hw addr. please check mac address."); memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN); --- 295,311 ---- * address. */ ! int rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { unsigned char mac_addr[ETH_ADDR_LEN]; net->fake_hw_addr = xmalloc(sizeof(eth_addr_t)); ! if(hex_string_to_value(mac_string, mac_addr)) { ! push_exception("rawnet", "rawnet_use_fake_hw_addr", ! "malformed mac address: %s", mac_string); ! xfree(net->fake_hw_addr); ! net->fake_hw_addr = NULL; ! return -1; ! } ! memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN); *************** *** 278,282 **** reinitialize_rawnet(net, 1); ! return; } --- 313,317 ---- reinitialize_rawnet(net, 1); ! return 0; } *************** *** 330,352 **** void rawnet_down(rawnet_t *net) { ! pcap_close(net->pcap); ! net->pcap = NULL; ! eth_close(net->eth); ! net->eth = NULL; return; } int rawnet_up(rawnet_t *net) { net->pcap = initialize_pcap_device(net->device, net->pcap_filter, net->promiscuous); if(net->pcap == NULL) { return -1; } - net->pcap_fd = pcap_fileno(net->pcap); net->eth = eth_open(net->device); ! if(net->eth == NULL) return -1; return 0; --- 365,407 ---- void rawnet_down(rawnet_t *net) { ! if(net->pcap != NULL) { ! pcap_close(net->pcap); ! net->pcap = NULL; ! } ! ! if(net->eth != NULL) { ! eth_close(net->eth); ! net->eth = NULL; ! } return; } + /* XXX -- if we fail we should rawnet down it. */ int rawnet_up(rawnet_t *net) { net->pcap = initialize_pcap_device(net->device, net->pcap_filter, net->promiscuous); if(net->pcap == NULL) { + push_exception("rawnet", "rawnet_up", + "could not initialize pcap on device: %s", net->device); + return -1; + } + + if((net->pcap_fd = pcap_fileno(net->pcap)) < 0) { + push_exception("rawnet", "rawnet_create", + "could not get pcap descriptor for: %s: %s", net->device, + pcap_geterr(net->pcap)); + rawnet_down(net); return -1; } net->eth = eth_open(net->device); ! if(net->eth == NULL) { ! push_exception("rawnet", "rawnet_up", ! "could not get ethernet handler on device: %s", ! net->device); ! rawnet_down(net); return -1; + } return 0; *************** *** 498,513 **** int rawnet_send_packet(rawnet_t *net) { ! if(eth_send(net->eth, net->packet_data, net->packet_len) != net->packet_len) ! return 1; ! else ! return 0; ! } ! char *rawnet_strerror(rawnet_t *net) ! { ! return(pcap_geterr(net->pcap)); } - /* Just update the seconds field. * --- 553,565 ---- int rawnet_send_packet(rawnet_t *net) { ! if(eth_send(net->eth, net->packet_data, net->packet_len) != net->packet_len) { ! push_exception("rawnet", "rawnet_send_packet", ! "could not write to device: %s : %s", net->device, strerror(errno)); ! return -1; ! } ! return 0; } /* Just update the seconds field. * *************** *** 570,573 **** --- 622,627 ---- */ ... [truncated message content] |