dhcp-agent-commits Mailing List for dhcp-agent (Page 31)
Status: Alpha
Brought to you by:
actmodern
You can subscribe to this list here.
2002 |
Jan
|
Feb
(33) |
Mar
|
Apr
|
May
(19) |
Jun
(61) |
Jul
(12) |
Aug
|
Sep
(5) |
Oct
(31) |
Nov
(24) |
Dec
(56) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(9) |
Feb
|
Mar
(16) |
Apr
(4) |
May
(68) |
Jun
(70) |
Jul
(100) |
Aug
(54) |
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(7) |
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(8) |
Oct
(5) |
Nov
(6) |
Dec
(4) |
2008 |
Jan
(9) |
Feb
(20) |
Mar
(32) |
Apr
(18) |
May
(19) |
Jun
(12) |
Jul
(23) |
Aug
(7) |
Sep
(15) |
Oct
(22) |
Nov
(50) |
Dec
(68) |
2009 |
Jan
(63) |
Feb
(23) |
Mar
(43) |
Apr
(50) |
May
(110) |
Jun
(103) |
Jul
(71) |
Aug
(26) |
Sep
(16) |
Oct
(31) |
Nov
(8) |
Dec
(13) |
2010 |
Jan
(6) |
Feb
(6) |
Mar
(36) |
Apr
(57) |
May
(67) |
Jun
(70) |
Jul
(44) |
Aug
(46) |
Sep
(27) |
Oct
(2) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: Thamer Al-H. <act...@us...> - 2002-02-08 01:37:32
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv22000 Modified Files: dhcp-client-cache.c dhcp-client-conf.c dhcp-client-control.c dhcp-interface.c dhcp-ip.c dhcp-log.c dhcp-net.c dhcp-sniff.c dhcp-util.c Log Message: fixed up rest of client to use verbosity level; Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-cache.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-cache.c 3 Feb 2002 16:56:00 -0000 1.5 --- dhcp-client-cache.c 8 Feb 2002 01:37:29 -0000 1.6 *************** *** 160,164 **** } ! /* work house routine to convert from serialized state to network datum. */ static void *convert_to_network(unsigned char tag, char *string) { --- 160,164 ---- } ! /* work horse routine to convert from serialized state to network datum. */ static void *convert_to_network(unsigned char tag, char *string) { *************** *** 173,177 **** if(data == NULL) { ! error_message("option: %s may be malformed. I'll ignore and carry on.", dhcp_options_strings[tag]); return NULL; --- 173,177 ---- if(data == NULL) { ! warn_message("option: %s may be malformed. I'll ignore and carry on.", dhcp_options_strings[tag]); return NULL; *************** *** 263,267 **** if(val == NULL) { ! info_message("option %s appear malformed. skipping.."); continue; } --- 263,267 ---- if(val == NULL) { ! warn_message("option %s appear malformed. skipping.."); continue; } *************** *** 275,279 **** } ! /* work house load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void* (*convert_func)(unsigned char tag, char *string)) --- 275,279 ---- } ! /* work horse load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void* (*convert_func)(unsigned char tag, char *string)) Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-conf.c 7 Feb 2002 18:41:47 -0000 1.3 --- dhcp-client-conf.c 8 Feb 2002 01:37:29 -0000 1.4 *************** *** 84,88 **** if((fputs(dhcp_options_strings[default_config_options[i]], fp) == EOF)|| (fputs("\n", fp) == EOF)) { ! fclose(fp); return -1; --- 84,88 ---- if((fputs(dhcp_options_strings[default_config_options[i]], fp) == EOF)|| (fputs("\n", fp) == EOF)) { ! warn_message("could not dump options to file. I'm going to continue anyway."); fclose(fp); return -1; Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client-control.c 3 Feb 2002 16:56:00 -0000 1.8 --- dhcp-client-control.c 8 Feb 2002 01:37:29 -0000 1.9 *************** *** 134,139 **** if(dport == -1 || sport == -1) { ! info_message("warning could not lookup dhcp services in service db: %s", strerror(errno)); ! info_message("will use reasonable default."); sport = BOOTP_CLIENT; --- 134,139 ---- if(dport == -1 || sport == -1) { ! warn_message("could not lookup dhcp services in service db: %s", strerror(errno)); ! warn_message("will use reasonable default."); sport = BOOTP_CLIENT; Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-interface.c 5 Feb 2002 13:47:38 -0000 1.9 --- dhcp-interface.c 8 Feb 2002 01:37:29 -0000 1.10 *************** *** 1,3 **** --- 1,4 ---- /* $Header$ + * * Copyright 2001 Thamer Alharbash <tm...@wh...> * Index: dhcp-ip.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-ip.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-ip.c 5 Feb 2002 13:47:38 -0000 1.3 --- dhcp-ip.c 8 Feb 2002 01:37:29 -0000 1.4 *************** *** 1,3 **** --- 1,4 ---- /* $Header$ + * * Copyright 2001 Thamer Alharbash <tm...@wh...> * Index: dhcp-log.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-log.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-log.c 29 Jan 2002 18:05:05 -0000 1.1.1.1 --- dhcp-log.c 8 Feb 2002 01:37:29 -0000 1.2 *************** *** 3,7 **** * Copyright 2001 Thamer Alharbash <tm...@wh...> * ! * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: --- 3,7 ---- * Copyright 2001 Thamer Alharbash <tm...@wh...> * ! * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-net.c 6 Feb 2002 23:50:15 -0000 1.10 --- dhcp-net.c 8 Feb 2002 01:37:29 -0000 1.11 *************** *** 571,575 **** default: ! error_message("warning: invalid send type"); break; } --- 571,575 ---- default: ! warn_message("warning: invalid send type -- this is a bug report it please."); break; } Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sniff.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-sniff.c 31 Jan 2002 12:37:24 -0000 1.3 --- dhcp-sniff.c 8 Feb 2002 01:37:29 -0000 1.4 *************** *** 1,3 **** --- 1,4 ---- /* $Header$ + * * dhcp-tool Sniffing routines. * Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-util.c 7 Feb 2002 18:41:47 -0000 1.5 --- dhcp-util.c 8 Feb 2002 01:37:29 -0000 1.6 *************** *** 71,75 **** { va_list ap; ! if(verbosity_level <= QUIET_VERBOSITY_LEVEL) return; --- 71,75 ---- { va_list ap; ! if(verbosity_level <= QUIET_VERBOSITY_LEVEL) return; |
From: Thamer Al-H. <act...@us...> - 2002-02-07 18:41:51
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv6477 Modified Files: dhcp-agent.h dhcp-client-conf.c dhcp-client.c dhcp-util.c dhcpclient.1 Log Message: added verbosity level option; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-agent.h 5 Feb 2002 02:00:59 -0000 1.17 --- dhcp-agent.h 7 Feb 2002 18:41:47 -0000 1.18 *************** *** 37,48 **** #endif - # include <sys/time.h> # include <sys/types.h> # include <sys/socket.h> # include <sys/stat.h> - # include <unistd.h> - # include <fcntl.h> - # include <syslog.h> - # include <signal.h> # include <netinet/in.h> --- 37,44 ---- #endif # include <sys/types.h> + # include <sys/time.h> # include <sys/socket.h> # include <sys/stat.h> # include <netinet/in.h> *************** *** 54,63 **** # include <fcntl.h> # include <ctype.h> - # include <time.h> # include <unistd.h> ! # include <dnet.h> - # include <dnet/ip.h> - # include <dnet/udp.h> # include <pcap.h> --- 50,58 ---- # include <fcntl.h> # include <ctype.h> # include <unistd.h> ! # include <syslog.h> ! # include <signal.h> ! # include <time.h> # include <dnet.h> # include <pcap.h> *************** *** 153,156 **** --- 148,160 ---- #endif + /* Verbosity levels. */ + + #define QUIET_VERBOSITY_LEVEL 0 + #define ERROR_VERBOSITY_LEVEL 1 + #define NORMAL_VERBOSITY_LEVEL 2 + #define WARNING_VERBOSITY_LEVEL 3 + #define DEBUG_VERBOSITY_LEVEL 4 + #define MAX_VERBOSITY_LEVEL DEBUG_VERBOSITY_LEVEL + /* * * * * * * * * * * * Data structures. * *************** *** 501,504 **** --- 505,514 ---- extern void error_message(char *fmt, ...); extern void fatal_error(char *fmt, ...); + extern void warn_message(char *fmt, ...); + extern void debug_message(char *fmt, ...); + + extern int get_verbosity_level(void); + extern int set_verbosity_level(int verbosity_level_to_set); + extern void *xmalloc(size_t size); extern void *xcalloc(size_t size); *************** *** 789,793 **** extern void delete_pid_file(char *name); extern int get_pid_file(char *name, pid_t *pid); - /* System configuration routines. */ --- 799,802 ---- Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-conf.c 6 Feb 2002 23:50:15 -0000 1.2 --- dhcp-client-conf.c 7 Feb 2002 18:41:47 -0000 1.3 *************** *** 53,57 **** client_conf_reset_options(cc); cc->interface = dc->interface; - cc->conf_file = NULL; return cc; --- 53,56 ---- *************** *** 60,67 **** void client_conf_destroy(client_conf_t *cc) { ! if(cc->conf_file != NULL) ! xfree(cc->conf_file); ! ! xfree(cc); } --- 59,63 ---- void client_conf_destroy(client_conf_t *cc) { ! xfree(cc); } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client.c 3 Feb 2002 16:56:00 -0000 1.11 --- dhcp-client.c 7 Feb 2002 18:41:47 -0000 1.12 *************** *** 96,100 **** case STATE_FATAL_ERROR: ! error_message("I've encountered a fatal error. I'm giving up."); do_shutdown(dc); --- 96,100 ---- case STATE_FATAL_ERROR: ! info_message("I've encountered a fatal error. I'm giving up."); do_shutdown(dc); *************** *** 223,227 **** static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "cdavim:kwh:")) != -1) { switch(c) { --- 223,227 ---- static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "cdavim:kwh:l:")) != -1) { switch(c) { *************** *** 262,265 **** --- 262,274 ---- exit(0); + case 'l': + + if(set_verbosity_level(atoi(optarg))) { + error_message("illegal verbosity level: %s", optarg); + exit(1); + } + + break; + case 'h': /* fall through. */ default: *************** *** 290,294 **** fatal_error("cannot enter work directory", work_dir); } ! /* Now see if another client is running on the same interface. */ --- 299,303 ---- fatal_error("cannot enter work directory", work_dir); } ! /* Now see if another client is running on the same interface. */ *************** *** 297,304 **** exit(1); } ! /* setup umask: this is also done in go_background but the client * doesn't go into the background immediately. so do it now. */ ! umask(0); --- 306,313 ---- exit(1); } ! /* setup umask: this is also done in go_background but the client * doesn't go into the background immediately. so do it now. */ ! umask(0); Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-util.c 5 Feb 2002 02:00:59 -0000 1.4 --- dhcp-util.c 7 Feb 2002 18:41:47 -0000 1.5 *************** *** 28,31 **** --- 28,48 ---- static char msgbuff[MSG_BUFFER_SIZE]; + static int verbosity_level = NORMAL_VERBOSITY_LEVEL; + + /* set the verbosity level. */ + int set_verbosity_level(int verbosity_level_to_set) + { + if(verbosity_level_to_set < 0 || verbosity_level_to_set > MAX_VERBOSITY_LEVEL) + return 1; + + verbosity_level = verbosity_level_to_set; + return 0; + } + + /* get the current verbosity level. */ + int get_verbosity_level(void) + { + return verbosity_level; + } /* send error message. */ *************** *** 34,37 **** --- 51,57 ---- va_list ap; + if(verbosity_level <= QUIET_VERBOSITY_LEVEL) + return; + va_start(ap, fmt); *************** *** 39,43 **** if(interactive == 1) { ! fprintf(stderr, "%s", msgbuff); fprintf(stderr,"\n"); } else --- 59,63 ---- if(interactive == 1) { ! fprintf(stderr, "error: %s", msgbuff); fprintf(stderr,"\n"); } else *************** *** 51,54 **** --- 71,77 ---- { va_list ap; + + if(verbosity_level <= QUIET_VERBOSITY_LEVEL) + return; va_start(ap, fmt); *************** *** 57,61 **** if(interactive == 1) { ! fprintf(stderr, "%s", msgbuff); fprintf(stderr,"\n"); } else --- 80,84 ---- if(interactive == 1) { ! fprintf(stderr, "fatal error: %s", msgbuff); fprintf(stderr,"\n"); } else *************** *** 66,74 **** } ! /* send info message (warnings included) */ void info_message(char *fmt, ...) { va_list ap; va_start(ap, fmt); --- 89,100 ---- } ! /* send info message */ void info_message(char *fmt, ...) { va_list ap; + if(verbosity_level <= ERROR_VERBOSITY_LEVEL) + return; + va_start(ap, fmt); *************** *** 83,87 **** --- 109,155 ---- va_end(ap); } + + /* send warning messages: includes diagnostics. */ + void warn_message(char *fmt, ...) + { + va_list ap; + + if(verbosity_level <= WARNING_VERBOSITY_LEVEL) + return; + + va_start(ap, fmt); + + vsnprintf(msgbuff, sizeof(msgbuff), fmt, ap); + + if(interactive == 1) { + fprintf(stdout, "warning: %s", msgbuff); + fprintf(stdout,"\n"); + } else + info_log(msgbuff); + + va_end(ap); + } + + /* send debug message. */ + void debug_message(char *fmt, ...) + { + va_list ap; + + if(verbosity_level <= DEBUG_VERBOSITY_LEVEL) + return; + + va_start(ap, fmt); + + vsnprintf(msgbuff, sizeof(msgbuff), fmt, ap); + if(interactive == 1) { + fprintf(stdout, "debug: %s", msgbuff); + fprintf(stdout,"\n"); + } else + info_log(msgbuff); + + va_end(ap); + } + /* * Malloc and free wrapper functions in case Index: dhcpclient.1 =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcpclient.1,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcpclient.1 3 Feb 2002 16:56:00 -0000 1.6 --- dhcpclient.1 7 Feb 2002 18:41:47 -0000 1.7 *************** *** 11,14 **** --- 11,15 ---- .Op Ar -i interface name .Op Ar -m fake mac source address + .Op Ar -l verbosity_level .Sh DESCRIPTION .I *************** *** 45,48 **** --- 46,58 ---- Use a fake mac source address. Useful only for diagnostics where want to see if a specific lease based on a mac address is accessible. + .It Op Ar -l verbosity level + Verbosity level can be set to the following integers: + .Bl -tag + .It 0 No output + .It 1 Only error messages are outputed. + .It 2 Normal output; errors and info messages. + .It 3 Warning level. Output warnings along with error and info messages. + .It 4 Debug level. Lots of diagnostic output. All messages. + .El .El .Sh BUGS |
From: Thamer Al-H. <act...@us...> - 2002-02-06 23:50:19
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv11080 Modified Files: dhcp-client-conf.c dhcp-net.c Log Message: config code for options added; Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-conf.c 2002/01/29 18:05:03 1.1.1.1 --- dhcp-client-conf.c 2002/02/06 23:50:15 1.2 *************** *** 25,34 **** #include <dhcp-agent.h> ! /* ! * XXX - configuration is blah this whole thing needs to be designed properly ! * I'd still like to keep it as simple as possible. ! * This should be redone into something that's proper and works. ! * ! */ static const int default_config_options[] = { --- 25,30 ---- #include <dhcp-agent.h> ! /* Basic network configuration. ! * Here we keep the options we want by default. */ static const int default_config_options[] = { *************** *** 42,47 **** }; - static const int default_config_options_len = 6; client_conf_t *create_client_conf(dhcp_client_control_t *dc) { --- 38,49 ---- }; + static const int default_config_options_len = 7; + + static void client_conf_reset_options(client_conf_t *cc) + { + memset(cc->options, 0, sizeof(cc->options)); + } + client_conf_t *create_client_conf(dhcp_client_control_t *dc) { *************** *** 49,53 **** cc = xmalloc(sizeof(client_conf_t)); ! memset(cc->options, 0, sizeof(cc->options)); cc->interface = dc->interface; cc->conf_file = NULL; --- 51,55 ---- cc = xmalloc(sizeof(client_conf_t)); ! client_conf_reset_options(cc); cc->interface = dc->interface; cc->conf_file = NULL; *************** *** 64,87 **** } ! static void dump_default_configurations(FILE *fp) { int i; for(i = 0;i < default_config_options_len; i++) { ! fputs(dhcp_options_strings[default_config_options[i]], fp); ! fputs("\n", fp); } ! return; } - - int load_client_conf(client_conf_t *cc) - { - #ifdef not_yet - FILE *fp; - char *var; - unsigned char have_conf = 0; - #endif int i; --- 66,103 ---- } ! static char *get_conf_options_fname(client_conf_t *cc) ! { ! return(splice_string(cc->interface, ".opts")); ! } ! ! static int dump_config_options(client_conf_t *cc) { int i; + FILE *fp; + char *fname; + fname = get_conf_options_fname(cc); + fp = file_open_or_create_safe(fname, "w"); + xfree(fname); + + if(fp == NULL) + return -1; + for(i = 0;i < default_config_options_len; i++) { ! ! if((fputs(dhcp_options_strings[default_config_options[i]], fp) == EOF)|| ! (fputs("\n", fp) == EOF)) { ! ! fclose(fp); ! return -1; ! } } ! fclose(fp); ! return 0; } + static void use_default_options(client_conf_t *cc) + { int i; *************** *** 89,133 **** cc->options[default_config_options[i]] = 1; } - - return 0; ! #ifdef not_yet ! if(cc->conf_file == NULL) ! cc->conf_file = splice_string(cc->interface, ".conf"); ! fp = file_open_or_create_safe(cc->conf_file, "w+"); ! if(fp == NULL) ! return -1; ! /* Read up any vars. */ ! reread: while(!file_get_var_string(fp)) { ! if(file_parse_string(PARSE_SINGLE_STRING)) ! fatal_error("corrupt configuration: %s. exiting!", cc->conf_file); ! var = file_get_var_name(); ! ! for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! if(!strcasecmp(var, dhcp_conf_options_strings[i])) { ! /* We have an option. */ cc->options[i] = 1; ! have_conf = 1; } } } ! /* Do we have an empty configuration? If so dump default. */ ! if(!have_conf) { ! fseek(fp, SEEK_SET, 0); ! dump_default_configurations(fp); ! fseek(fp, SEEK_SET, 0); ! goto reread; /* do it again, this time we'll get the options we wrote. */ ! } ! fclose(fp); ! #endif not_yet } --- 105,171 ---- cc->options[default_config_options[i]] = 1; } ! return; ! } ! static int client_conf_load_options(client_conf_t *cc) ! { ! char *fname; ! FILE *fp; ! int i; ! fname = get_conf_options_fname(cc); ! fp = file_open_or_create_safe(fname, "r"); ! xfree(fname); ! if(fp == NULL) ! return -1; while(!file_get_var_string(fp)) { ! if(file_parse_string(PARSE_SINGLE_STRING)) { ! fclose(fp); ! return -1; ! } ! for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! ! /* as long as no error was returned from file_parse_string ! * we can just do a file_get_var_name() safely. */ ! ! if(string_matches(dhcp_options_strings[i], ! file_get_var_name())) { cc->options[i] = 1; ! break; } + } } + + fclose(fp); + return 0; + } + + int load_client_conf(client_conf_t *cc) + { ! char *fname; ! int retval; ! client_conf_reset_options(cc); ! /* check for options file. */ ! fname = get_conf_options_fname(cc); ! if(!file_exists(fname)) { ! /* it doesn't exist. use default options. */ ! use_default_options(cc); ! /* and dump it to file. */ ! retval = dump_config_options(cc); ! } else { ! /* read options file. */ ! retval = client_conf_load_options(cc); ! } ! ! xfree(fname); ! return retval; } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-net.c 2002/02/02 12:28:05 1.9 --- dhcp-net.c 2002/02/06 23:50:15 1.10 *************** *** 517,521 **** char *packet_ptr; ! /* Dump packet images. */ packet_ptr = net->packet_data; --- 517,521 ---- char *packet_ptr; ! /* Dump packet images for DHCP. */ packet_ptr = net->packet_data; *************** *** 544,548 **** char *packet_ptr; ! /* Dump packet images. */ packet_ptr = net->packet_data; --- 544,548 ---- char *packet_ptr; ! /* Dump packet images for ARP/UNARP. */ packet_ptr = net->packet_data; |
From: Thamer Al-H. <act...@us...> - 2002-02-05 13:47:41
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv16730 Modified Files: dhcp-daemon.c dhcp-files.c dhcp-interface.c dhcp-ip.c dhcp-rtt.c Log Message: fixed up magic numbers in dhcp-ip.c; fixed small bug in dhcp-rtt.c; added more comments and clean up; Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-daemon.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-daemon.c 2002/02/02 11:55:08 1.2 --- dhcp-daemon.c 2002/02/05 13:47:38 1.3 *************** *** 27,30 **** --- 27,32 ---- #include <dhcp-agent.h> + /* wrap for volatine integers, or proper sig_atomic_t types. */ + #ifdef HAVE_SIG_ATOMIC_T *************** *** 53,56 **** --- 55,59 ---- } + /* setup our interrupt handles. */ void setup_interrupt_handlers(void) { *************** *** 66,69 **** --- 69,85 ---- } + /* Our go background routine. + * here. We do all the necessary + * steps to fork completely into + * the background. + * + * Calling this will hose any + * module we're using that + * has descriptors open. + * + * Only call in a pre-initialized state. + * + */ + void go_background(char *dir) { *************** *** 163,171 **** * use them */ ! #ifdef not_yet max_descriptors = sysconf(_SC_OPEN_MAX); #elif MAX_FILES max_descriptors = MAX_FILES; ! #elif not_yet max_descriptors = getrusage(RLIMIT_NOFILES); #else --- 179,187 ---- * use them */ ! #ifdef _SC_OPEN_MAX max_descriptors = sysconf(_SC_OPEN_MAX); #elif MAX_FILES max_descriptors = MAX_FILES; ! #elif RLIMIT_NOFILES max_descriptors = getrusage(RLIMIT_NOFILES); #else *************** *** 201,207 **** open("/dev/null", O_WRONLY); /* stderr */ ! /* Now we're done. */ ! init_log(binname); return; --- 217,224 ---- open("/dev/null", O_WRONLY); /* stderr */ ! /* initialize logging. */ init_log(binname); + + /* Now we're done. */ return; Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-files.c 2002/02/02 15:28:47 1.2 --- dhcp-files.c 2002/02/05 13:47:38 1.3 *************** *** 189,192 **** --- 189,193 ---- } + /* get pid from file. */ int get_pid_file(char *name, pid_t *pid) { Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-interface.c 2002/02/02 11:55:08 1.8 --- dhcp-interface.c 2002/02/05 13:47:38 1.9 *************** *** 79,84 **** } ! /* Bring an interface up */ ! int interface_up(interface_control_t *ic, char *name, uint32_t addr, uint32_t netmask, int mtu) --- 79,83 ---- } ! /* bring an interface up */ int interface_up(interface_control_t *ic, char *name, uint32_t addr, uint32_t netmask, int mtu) *************** *** 116,119 **** --- 115,119 ---- } + /* take down an interface. */ int interface_down(interface_control_t *ic, char *name) { *************** *** 130,133 **** --- 130,134 ---- } + /* get ip address of an interface. */ int interface_get_ip_addr(interface_control_t *ic, char *name, uint32_t *addr) { Index: dhcp-ip.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-ip.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-ip.c 2002/01/30 16:06:46 1.2 --- dhcp-ip.c 2002/02/05 13:47:38 1.3 *************** *** 141,171 **** *packet = ipvhl; ! packet += 1; ! ! memcpy(packet, &ip->header.ip_tos, 1); ! packet += 1; ! memcpy(packet, &ip->header.ip_len, 2); ! packet += 2; ! memcpy(packet, &ip->header.ip_id, 2); ! packet += 2; ! memcpy(packet, &ip->header.ip_off, 2); ! packet += 2; ! memcpy(packet, &ip->header.ip_ttl, 1); ! packet += 1; ! memcpy(packet, &ip->header.ip_p, 1); ! packet += 1; /* skip checksum field. */ packet += 2; ! memcpy(packet, &ip->header.ip_src, 4); ! packet += 4; ! ! memcpy(packet, &ip->header.ip_dst, 4); return; --- 141,171 ---- *packet = ipvhl; ! packet += sizeof(ipvhl); ! memcpy(packet, &ip->header.ip_tos, sizeof(ip->header.ip_tos)); ! packet += sizeof(ip->header.ip_tos); ! memcpy(packet, &ip->header.ip_len, sizeof(ip->header.ip_len)); ! packet += sizeof(ip->header.ip_len); ! memcpy(packet, &ip->header.ip_id, sizeof(ip->header.ip_id)); ! packet += sizeof(ip->header.ip_id); ! memcpy(packet, &ip->header.ip_off, sizeof(ip->header.ip_off)); ! packet += sizeof(ip->header.ip_off); ! ! memcpy(packet, &ip->header.ip_ttl, sizeof(ip->header.ip_ttl)); ! packet += sizeof(ip->header.ip_ttl); ! memcpy(packet, &ip->header.ip_p, sizeof(ip->header.ip_p)); ! packet += sizeof(ip->header.ip_p); /* skip checksum field. */ packet += 2; ! memcpy(packet, &ip->header.ip_src, IP_ADDR_LEN); ! packet += IP_ADDR_LEN; ! ! memcpy(packet, &ip->header.ip_dst, IP_ADDR_LEN); return; Index: dhcp-rtt.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-rtt.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-rtt.c 2002/02/02 01:07:20 1.3 --- dhcp-rtt.c 2002/02/05 13:47:38 1.4 *************** *** 69,72 **** --- 69,74 ---- if(rand_value < milliseconds) milliseconds -= rand_value; + else + milliseconds += rand_value; } |
From: Thamer Al-H. <act...@us...> - 2002-02-05 02:01:02
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv25780 Modified Files: COST dhcp-agent.h dhcp-convert.c dhcp-util.c Log Message: major update to dhcp-convert; now with all options we care about converted; Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** COST 2002/01/29 18:04:59 1.1.1.1 --- COST 2002/02/05 02:00:59 1.2 *************** *** 1,5 **** In writing dhcp-agent I suffered the following: ! [ these stats are updated every major release. ] 162 pots of coffee; 421 camel filter cigarettes; 112 diet cokes; --- 1,9 ---- In writing dhcp-agent I suffered the following: ! Feb - March 2001 ! ! [ todo ] ! ! Jan - Feb 2001 162 pots of coffee; 421 camel filter cigarettes; 112 diet cokes; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-agent.h 2002/02/03 16:55:59 1.16 --- dhcp-agent.h 2002/02/05 02:00:59 1.17 *************** *** 123,127 **** /* type string limits. */ ! # define UINT32_T_STRING_SIZE 12 /* timeout as per rfc2131 */ --- 123,131 ---- /* type string limits. */ ! # define UINT32_T_STRING_SIZE 11 ! # define INT32_T_STRING_SIZE UINT32_T_STRING_SIZE /* the same. */ ! # define UINT16_T_STRING_SIZE 6 ! # define INT16_T_STRING_SIZE UINT16_T_STRING_SIZE ! # define BYTE_STRING_SIZE 5 /* timeout as per rfc2131 */ *************** *** 508,511 **** --- 512,516 ---- extern void trim_string(char *s); extern int string_matches(char *s1, char *s2); + extern int hex_string_to_value(char *string, unsigned char *dst); extern int is_string(const char *string, int len); extern int get_random(void); *************** *** 785,804 **** extern int get_pid_file(char *name, pid_t *pid); - /* serialization functions. */ - - extern char *addr_to_string(const unsigned char *data, int len); - extern char *addr_list_to_string(const unsigned char *data, int len); - extern void *string_to_addr_list(char *string); - extern void *string_to_addr(char *string); - extern void *string_addr_list_to_network(char *string, unsigned char *len_ret); - extern void *string_addr_to_network(char *string, unsigned char *len_ret); - extern char *uint32_to_string(const unsigned char *data, int len); - extern void *string_to_uint32(char *s); - extern void *string_uint32_to_network(char *s, unsigned char *len_ret); - extern char *validate_to_string(const unsigned char *data, int len); - extern void *string_uint32_to_network(char *s, unsigned char *len_ret); - extern void *strdup_wrap(char *s); - extern void *strdup_wrap_net(char *s, unsigned char *ret_len); - extern int hex_string_to_value(char *string, unsigned char *dst); /* System configuration routines. */ --- 790,793 ---- Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-convert.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-convert.c 2002/01/30 16:06:46 1.3 --- dhcp-convert.c 2002/02/05 02:00:59 1.4 *************** *** 34,139 **** /* We have four handlers: * ! * Serialize data handler: serializes from network form to serialized state. ! * Unserialize data handler: unserializes into internal form. ! * Convert serialized: converts to a type specific form -- ! * useful for internal usage. * */ option_convert_handler option_convert_handlers[] = { ! { NULL, NULL, NULL, NULL }, /* 0 */ ! { addr_to_string, string_to_addr, string_addr_to_network, ! xfree }, /* 1 */ ! { NULL, NULL, NULL, NULL }, /* 2 */ ! { addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 3 */ ! { NULL, NULL, NULL, NULL }, /* 4 */ ! { NULL, NULL, NULL, NULL }, /* 5 */ ! { addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 6 */ ! { NULL, NULL, NULL, NULL }, /* 7 */ ! { NULL, NULL, NULL, NULL }, /* 8 */ ! { NULL, NULL, NULL, NULL }, /* 9 */ ! { NULL, NULL, NULL, NULL }, /* 10 */ ! { NULL, NULL, NULL, NULL }, /* 11 */ ! { NULL, NULL, NULL, NULL }, /* 12 */ ! { NULL, NULL, NULL, NULL }, /* 13 */ ! { NULL, NULL, NULL, NULL }, /* 14 */ ! { validate_to_string, strdup_wrap, strdup_wrap_net, ! xfree }, /* 15 */ ! { NULL, NULL, NULL, NULL }, /* 16 */ ! { NULL, NULL, NULL, NULL }, /* 17 */ ! { NULL, NULL, NULL, NULL }, /* 18 */ ! { NULL, NULL, NULL, NULL }, /* 19 */ ! { NULL, NULL, NULL, NULL }, /* 20 */ ! { NULL, NULL, NULL, NULL }, /* 21 */ ! { NULL, NULL, NULL, NULL }, /* 22 */ ! { NULL, NULL, NULL, NULL }, /* 23 */ ! { NULL, NULL, NULL, NULL }, /* 24 */ ! { NULL, NULL, NULL, NULL }, /* 25 */ ! { NULL, NULL, NULL, NULL }, /* 26 */ ! { NULL, NULL, NULL, NULL }, /* 27 */ ! { NULL, NULL, NULL, NULL }, /* 28 */ ! { NULL, NULL, NULL, NULL }, /* 29 */ ! { NULL, NULL, NULL, NULL }, /* 30 */ ! { NULL, NULL, NULL, NULL }, /* 31 */ ! { NULL, NULL, NULL, NULL }, /* 32 */ ! { NULL, NULL, NULL, NULL }, /* 33 */ ! { NULL, NULL, NULL, NULL }, /* 34 */ ! { NULL, NULL, NULL, NULL }, /* 35 */ ! { NULL, NULL, NULL, NULL }, /* 36 */ ! { NULL, NULL, NULL, NULL }, /* 37 */ ! { NULL, NULL, NULL, NULL }, /* 38 */ ! { NULL, NULL, NULL, NULL }, /* 39 */ ! { NULL, NULL, NULL, NULL }, /* 40 */ ! { NULL, NULL, NULL, NULL }, /* 41 */ ! { NULL, NULL, NULL, NULL }, /* 42 */ ! { NULL, NULL, NULL, NULL }, /* 43 */ ! { NULL, NULL, NULL, NULL }, /* 44 */ ! { NULL, NULL, NULL, NULL }, /* 45 */ ! { NULL, NULL, NULL, NULL }, /* 46 */ ! { NULL, NULL, NULL, NULL }, /* 47 */ ! { NULL, NULL, NULL, NULL }, /* 48 */ ! { NULL, NULL, NULL, NULL }, /* 49 */ ! { addr_to_string, string_to_addr, ! string_addr_to_network, xfree }, /* 50 */ ! { uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 51 */ ! { NULL, NULL, NULL, NULL }, /* 52 */ ! { NULL, NULL, NULL, NULL }, /* 53 */ ! { addr_to_string, string_to_addr, ! string_addr_to_network, xfree }, /* 54 */ ! { NULL, NULL, NULL, NULL }, /* 55 */ ! { NULL, NULL, NULL, NULL }, /* 56 */ ! { NULL, NULL, NULL, NULL }, /* 57 */ ! { uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 58 */ ! { NULL, NULL, NULL, NULL }, /* 59 */ ! { NULL, NULL, NULL, NULL }, /* 60 */ ! { NULL, NULL, NULL, NULL }, /* 61 */ }; ! char *addr_to_string(const unsigned char *data, int len) { ! struct in_addr address; ! memcpy(&address.s_addr, data, 4); ! if(len < 4) return NULL; return(strdup(inet_ntoa(address))); } ! char *addr_list_to_string(const unsigned char *data, int len) { char *string; char *tmp, *new_string; ! if(len < 4) return NULL; ! string = addr_to_string(data, len); if(string == NULL) return NULL; --- 34,285 ---- /* We have four handlers: + * + * Network to serialized: take a datum in raw network format and + * serialize into serial datum. + * + * Serial to internal: take a serial and convert it to internal + * format. + * + * Serial to network: take a serial datum and turn it into a raw + * network datum. + * + * Free internal: special freeing routine used for internal datum. + * This is used so we can pass around internal datums elsewhere without + * having to understand them. * ! * All network to serialized handlers do validity checks for length ! * matching exact sizes or multiples of sizes. This is where we expect ! * malformed options to be stomped on. * */ + /* serialization functions. */ + + /* byte routines. */ + + char *network_byte_to_string_byte(const unsigned char *data, int len); + void *string_byte_to_byte(char *s); + void *string_byte_to_network(char *s, unsigned char *ret_len); + + /* address routines. */ + + char *network_addr_to_string(const unsigned char *data, int len); + char *network_addr_list_to_string(const unsigned char *data, int len); + char *addr_list_to_string(const unsigned char *data, int len); + void *string_to_addr_list(char *string); + void *string_to_addr(char *string); + void *string_addr_list_to_network(char *string, unsigned char *len_ret); + void *string_addr_to_network(char *string, unsigned char *len_ret); + char *network_addr_pair_list_to_string(const unsigned char *data, int len); + void *string_to_addr_pair_list(char *s); + void *string_addr_pair_list_to_network(char *s, unsigned char *retlen); + + /* integer routines. */ + + char *network_uint32_to_string(const unsigned char *data, int len); + char *network_int32_to_string(const unsigned char *data, int len); + char *network_uint16_to_string(const unsigned char *data, int len); + char *network_int16_to_string(const unsigned char *data, int len); + + void *string_to_uint32(char *s); + void *string_to_int32(char *s); + void *string_to_uint16(char *s); + void *string_to_int16(char *s); + + void *string_int32_to_network(char *s, unsigned char *ret_len); + void *string_uint32_to_network(char *s, unsigned char *ret_len); + void *string_int16_to_network(char *s, unsigned char *ret_len); + void *string_uint16_to_network(char *s, unsigned char *ret_len); + + char *network_uint16_list_to_string(const unsigned char *data, int len); + void *string_to_uint16_list(char *s); + void *string_uint16_list_to_network(char *s, unsigned char *retlen); + + /* network to string */ + + char *validate_network_string_to_string(const unsigned char *data, int len); + void *strdup_wrap(char *s); + void *strdup_wrap_net(char *s, unsigned char *ret_len); + option_convert_handler option_convert_handlers[] = { ! { NULL, NULL, NULL, NULL }, /* 0 */ /* pad */ ! { network_addr_to_string, string_to_addr, string_addr_to_network, ! xfree }, /* 1 */ /* subnet mask */ ! { network_int32_to_string, string_to_int32, ! string_int32_to_network, xfree }, /* 2 */ /* time offset */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 3 */ /* router. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 4 */ /* time server. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 5 */ /* name server. (old) */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 6 */ /* domain name servers. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 7 */ /* mit-lcs log server */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 8 */ /* cookie server. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 9 */ /* LPR server. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 10 */ /* Impress server. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 11 */ /* Resource Location Server. */ ! { validate_network_string_to_string, ! strdup_wrap, strdup_wrap_net, xfree }, /* 12 */ /* Host name option. */ ! { network_uint16_to_string, string_to_uint16, ! string_uint16_to_network, xfree }, /* 13 */ /* boot file size option */ ! { validate_network_string_to_string, ! strdup_wrap, strdup_wrap_net, xfree }, /* 14 */ /* merit dump file */ ! { validate_network_string_to_string, strdup_wrap, strdup_wrap_net, ! xfree }, /* 15 */ /* domain name */ ! { network_addr_to_string, string_to_addr, string_addr_to_network, ! xfree }, /* 16 */ /* swap server */ ! { validate_network_string_to_string, strdup_wrap, strdup_wrap_net, ! xfree }, /* 17 */ /* root path */ ! { validate_network_string_to_string, strdup_wrap, strdup_wrap_net, ! xfree }, /* 18 */ /* extension path */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 19 */ /* IP forwarding. */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 20 */ /* Non Local Source Routing. */ ! { network_addr_pair_list_to_string, string_to_addr_pair_list, ! string_addr_pair_list_to_network, purge_list_internal }, /* 21 */ /* Policy filter option. */ ! { network_uint16_to_string, string_to_uint16, ! string_uint16_to_network, xfree }, /* 22 */ /* maximum dgram reassembly */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 23 */ /* IP TTL */ ! { network_uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 24 */ /* MTU Aging Timeout. */ ! { network_uint16_list_to_string, string_to_uint16_list, ! string_uint16_list_to_network, purge_list_internal }, /* 25 */ /* MTU Plateau Table. */ ! { network_uint16_to_string, string_to_uint16, ! string_uint16_to_network, xfree }, /* 26 */ /* Interface MTU. */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 27 */ /* Subnets are Local */ ! { network_addr_to_string, string_to_addr, string_addr_to_network, ! xfree }, /* 28 */ /* Broadcast Address */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 29 */ /* Perform Mask Discovery */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 30 */ /* Mask Supplier */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 31 */ /* Perform Router Discovery */ ! { network_addr_to_string, string_to_addr, ! string_addr_to_network, xfree }, /* 32 */ /* Router Solicitation Address */ ! { network_addr_pair_list_to_string, string_to_addr_pair_list, ! string_addr_pair_list_to_network, purge_list_internal }, /* 33 */ /* Static Route */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 34 */ /* Trailer Encapsulation */ ! { network_uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 35 */ /* ARP Cache Timeout. */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 36 */ /* Ethernet Encapsulation */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 37 */ /* TCP Default TLL */ ! { network_uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 38 */ /* TCP Keepalive Interval */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 39 */ /* TCP Keepalive Garbage Option. */ ! { validate_network_string_to_string, strdup_wrap, ! strdup_wrap_net, xfree }, /* 40 */ /* Network Information Service Domain */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 41 */ /* Network Information Servers */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 42 */ /* Network Time Protocol Servers. */ ! { NULL, NULL, NULL, NULL }, /* 43 */ /* Vendor Specific (don't handle yet.) */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 44 */ /* NetBIOS over TCP/IP Name Server */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 45 */ /* NetBIOS over TCP/IP Name Server */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 46 */ /* NetBIOS over TCP/IP Node Type. */ ! { validate_network_string_to_string, ! strdup_wrap, strdup_wrap_net, xfree }, /* 47 */ /* NetBIOS over TCP/IP Scope */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 48 */ /* X Windows System Font Server. */ ! { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 49 */ /* X Window System Display Manager. */ ! { network_addr_to_string, string_to_addr, ! string_addr_to_network, xfree }, /* 50 */ /* Request IP Address. */ ! { network_uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 51 */ /* IP Address Lease Time */ ! { network_byte_to_string_byte, string_byte_to_byte, ! string_byte_to_network, xfree }, /* 52 */ /* Option Overload. */ ! { NULL, NULL, NULL, NULL }, /* 53 */ /* Dhcp Message Type. */ ! { network_addr_to_string, string_to_addr, ! string_addr_to_network, xfree }, /* 54 */ /* Server Identifier. */ ! { NULL, NULL, NULL, NULL }, /* 55 */ /* parameter request list. */ ! { NULL, NULL, NULL, NULL }, /* 56 */ /* message. we handle this higher. */ ! { network_uint16_list_to_string, string_to_uint16_list, ! string_uint16_list_to_network, purge_list_internal }, /* 57 */ /* Maximum DHCP message size. */ ! { network_uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 58 */ /* Renewal time. */ ! { network_uint32_to_string, string_to_uint32, ! string_uint32_to_network, xfree }, /* 59 */ /* Rebinding time. */ ! { NULL, NULL, NULL, NULL }, /* 60 */ /* Server identifier */ ! { NULL, NULL, NULL, NULL }, /* 61 */ /* Client identifier */ }; ! /* Byte conversions useful for flags, and 1/0 values. */ ! ! /* network byte value to string byte value. */ ! char *network_byte_to_string_byte(const unsigned char *data, int len) { ! char *s; ! if(len < 1) ! return NULL; ! s = xmalloc(BYTE_STRING_SIZE); ! snprintf(s, BYTE_STRING_SIZE, "0x%hhx", *(unsigned char *)data); ! ! return s; ! } ! ! /* string to internal byte value. */ ! void *string_byte_to_byte(char *s) ! { ! unsigned char *b; ! ! b = xmalloc(sizeof(unsigned char)); ! ! sscanf(s,"0x%hhx",b); ! ! return b; ! } ! ! /* string to network byte value. */ ! void *string_byte_to_network(char *s, unsigned char *ret_len) ! { ! *ret_len = 1; ! return(string_byte_to_byte); ! } ! ! /* IPv4 address conversion routines. */ ! ! /* convert one network address datum to serialized form. */ ! char *network_addr_to_string(const unsigned char *data, int len) ! { ! struct in_addr address; ! ! if(len < IP_ADDR_LEN) return NULL; + + memcpy(&address.s_addr, data, IP_ADDR_LEN); return(strdup(inet_ntoa(address))); } ! /* convert list of network address datums to serialized form. */ ! char *network_addr_list_to_string(const unsigned char *data, int len) { char *string; char *tmp, *new_string; ! if(len < IP_ADDR_LEN) return NULL; ! string = network_addr_to_string(data, len); if(string == NULL) return NULL; *************** *** 150,154 **** tmp = string; ! new_string = addr_to_string(data, len); if(new_string == NULL) { --- 296,300 ---- tmp = string; ! new_string = network_addr_to_string(data, len); if(new_string == NULL) { *************** *** 163,167 **** string = splice_string(string, new_string); xfree(tmp); ! tmp = string; string = splice_string(string, ";"); --- 309,314 ---- string = splice_string(string, new_string); xfree(tmp); ! xfree(new_string); ! tmp = string; string = splice_string(string, ";"); *************** *** 175,182 **** } void *string_to_addr(char *string) { uint32_t addr, *new_addr; ! addr = inet_addr(string); --- 322,330 ---- } + /* convert string address to internal address datum. */ void *string_to_addr(char *string) { uint32_t addr, *new_addr; ! addr = inet_addr(string); *************** *** 187,190 **** --- 335,339 ---- } + /* convert list of string addresses to internal address datum. */ void *string_to_addr_list(char *string) { *************** *** 213,220 **** return addr_list; } - - /* Addresses are stored internally in network order - * so no conversion necessary. */ void *string_addr_to_network(char *string, unsigned char *len_ret) { --- 362,367 ---- return addr_list; } + /* convert serialized address to network datum. */ void *string_addr_to_network(char *string, unsigned char *len_ret) { *************** *** 224,237 **** return addr; } - - /* - * Just call the regular string_addr_list and copy - * make new copy while destroying the old. - * - * FIXME: even though these lists are small, we - * shouldn't need to walk through them three times. - * - */ void *string_addr_list_to_network(char *string, unsigned char *len_ret) { --- 371,376 ---- return addr; } + /* convert serialized address list to network datum. */ void *string_addr_list_to_network(char *string, unsigned char *len_ret) { *************** *** 244,252 **** count++; ! data = xmalloc(count * 4); cp = data; for(ptr = addr_list;ptr;ptr = ptr->next) { ! memcpy(cp, ptr->data, 4); cp++; } --- 383,391 ---- count++; ! data = xmalloc(count * IP_ADDR_LEN); cp = data; for(ptr = addr_list;ptr;ptr = ptr->next) { ! memcpy(cp, ptr->data, IP_ADDR_LEN); cp++; } *************** *** 257,275 **** return data; } ! /* We already have a string coming in, we need to validate ! * it though; we need to make sure its null terminated. ! * Then just return a new copy. ! * ! * FIXME: all strings should conform to the RFC. ! * Add check. ! * */ ! char *validate_to_string(const unsigned char *data, int len) { char *new_string; ! if(!is_string(data, len)) { new_string = xmalloc(len + 1); memcpy(new_string, data, len); --- 396,435 ---- return data; } + + /* address pair conversion. this just adds a check to make sure len is divisible + * by 2 addresses. */ + char *network_addr_pair_list_to_string(const unsigned char *data, int len) + { + if(len == 0 || + len%(IP_ADDR_LEN * 2)) + return NULL; ! return(network_addr_list_to_string(data, len)); ! } ! ! /* string to internal address pair list (wrapper). */ ! void *string_to_addr_pair_list(char *s) ! { ! return(string_to_addr_list(s)); ! } ! ! /* string to network address pair list (wrapper). */ ! void *string_addr_pair_list_to_network(char *s, unsigned char *retlen) ! { ! return(string_addr_list_to_network(s, retlen)); ! } ! ! /* String conversions: ! * We use strdup mostly to just make copies in our conversion hook ! * array. However, for network strings we want to run them through ! * validate_network_to_string */ ! /* validate string only: fixme: add rfc character set check. */ ! char *validate_network_string_to_string(const unsigned char *data, int len) { char *new_string; ! if(!is_string(data, len)) { /* fix if needed. */ new_string = xmalloc(len + 1); memcpy(new_string, data, len); *************** *** 278,351 **** } ! /* we don't want to force terminate. ! * instead we should just consider that ! * it is malformed and return an error. */ ! return strdup(data); } ! char *uint32_to_string(const unsigned char *data, int len) { ! char *uint32_string; ! uint32_t val; ! if(len < 4) ! return NULL; ! val = ntohl(*(uint32_t *)data); ! uint32_string = xmalloc(UINT32_T_STRING_SIZE); ! snprintf(uint32_string, UINT32_T_STRING_SIZE, "%lu", (unsigned long) val); /* this may not be safe. ! * FIXME */ ! return uint32_string; } ! void *string_to_uint32(char *s) { ! uint32_t *val; ! char *val_string; ! val = xmalloc(sizeof(uint32_t)); ! ! /* must begin with an arbritrary amount ! * of white space. h'ok. */ ! val_string = splice_string(" ", s); ! *val = strtoul(val_string, NULL, 10); ! xfree(val_string); ! return val; } ! void *string_uint32_to_network(char *s, unsigned char *ret_len) { ! uint32_t *val; ! unsigned char *net_val; ! val = string_to_uint32(s); ! if(val == NULL) return NULL; ! net_val = xmalloc(sizeof(uint32_t)); ! (*(uint32_t *)net_val) = htonl(*val); ! xfree(val); ! *ret_len = sizeof(uint32_t); ! return net_val; } ! void *strdup_wrap(char *s) { ! return(strdup(s)); } ! void *strdup_wrap_net(char *s, unsigned char *ret_len) { ! unsigned char *val; ! val = strdup_wrap(s); ! *ret_len = strlen(s); ! return val; } --- 438,771 ---- } ! /* otherwise strdup a copy. */ return strdup(data); } ! /* just copy. wrapper needed to be nice to the compiler. */ ! void *strdup_wrap(char *s) { ! return(strdup(s)); ! } ! ! /* call strdup_wrap but set the ret_len appropriately. */ ! void *strdup_wrap_net(char *s, unsigned char *ret_len) ! { ! unsigned char *val; ! val = strdup_wrap(s); ! ! *ret_len = (strlen(s) + 1); ! return val; ! } ! ! /* Integer conversions: ! * More work is done here to convert to network or internal format. */ ! ! /* workhorse network int to string routine. */ ! char *network_int_to_string(const unsigned char *data, int data_len, ! size_t size, int si) ! { ! char *string; ! if(size > data_len) ! return NULL; ! if(si) { /* signed. */ ! ! switch(size) { ! ! case sizeof(int32_t): ! string = xmalloc(INT32_T_STRING_SIZE); ! snprintf(string, INT32_T_STRING_SIZE, "%ld", ntohl(*(int32_t *)data)); ! break; ! ! case sizeof(int16_t): ! string = xmalloc(INT16_T_STRING_SIZE); ! snprintf(string, INT16_T_STRING_SIZE, "%hd", ntohs(*(int16_t *)data)); ! break; ! ! default: ! /* we should never get here but we should force ourselves ! * to b0rk if we do. */ ! fatal_error("illegal size passed to int_to_string()!"); ! } ! ! } else { /* unsigned. */ ! ! switch(size) { ! ! case sizeof(uint32_t): ! string = xmalloc(UINT32_T_STRING_SIZE); ! snprintf(string, UINT32_T_STRING_SIZE, "%lu", ntohl(*(uint32_t *)data)); ! break; ! ! case sizeof(uint16_t): ! string = xmalloc(UINT16_T_STRING_SIZE); ! snprintf(string, UINT16_T_STRING_SIZE, "%hu", ntohs(*(uint16_t *)data)); ! break; ! ! default: ! /* ditto on forced b0rking. */ ! fatal_error("illegal size passed to int_to_string()!"); ! break; ! } ! } ! return string; ! } ! /* interface to *int*_to_string */ ! char *network_uint32_to_string(const unsigned char *data, int len) { ! return(network_int_to_string(data, len, sizeof(uint32_t), 0)); ! } ! char *network_int32_to_string(const unsigned char *data, int len) ! { ! return(network_int_to_string(data, len, sizeof(int32_t), 1)); ! } ! char *network_uint16_to_string(const unsigned char *data, int len) ! { ! return(network_int_to_string(data, len, sizeof(int32_t), 0)); ! } ! char *network_int16_to_string(const unsigned char *data, int len) ! { ! return(network_int_to_string(data, len, sizeof(int32_t), 1)); ! } ! char *network_uint16_list_to_string(const unsigned char *data, int len) ! { ! char *tmp; ! char *s = NULL; ! char *string = NULL; ! if(len == 0 || ! len%sizeof(uint16_t)) ! return NULL; ! for(;len > 0;len -= sizeof(uint16_t)) { ! ! s = network_uint16_to_string(data, sizeof(uint16_t)); ! if(s == NULL) ! return string; ! ! tmp = string; ! string = splice_string(s, string); ! ! if(tmp != NULL) ! xfree(tmp); ! xfree(s); ! ! tmp = string; ! string = splice_string(string, ";"); ! free(tmp); ! ! data += sizeof(uint16_t); ! } ! ! return string; } ! void *string_to_uint16_list(char *s) { ! list_t *list_ptr = NULL; ! void *val; ! char *cp, *ptr; ! ! cp = s; ! while((ptr = strchr(cp, ';')) != NULL) { ! *ptr = '\0'; ! val = string_to_uint16(cp); ! if(val == NULL) ! break; ! ! list_ptr = add_to_list(list_ptr,val); ! ! ptr++; ! if(*ptr == '\0') ! break; ! cp = ptr; ! } ! return list_ptr; ! } ! ! void *string_uint16_list_to_network(char *s, unsigned char *retlen) ! { ! unsigned char *data, *data_ptr; ! uint16_t *val; ! int len = 0; ! char *ptr; ! char *cp; ! ! for(cp = s;ptr != NULL;ptr = strchr(cp, ';')) { ! cp = ptr + 1; ! len++; ! } ! ! if(len == 0) return NULL; + + data = xmalloc(sizeof(uint16_t) * len); + cp = s; + data_ptr = data; ! while(len--) { ! ptr = strchr(cp, ';'); ! *ptr = '\0'; ! ! val = string_to_uint16(cp); ! memcpy(data_ptr, val, sizeof(uint16_t)); ! xfree(val); ! data_ptr += sizeof(uint16_t); ! } ! return data; } ! /* workhorse string to integer routine. */ ! /* i'm worried about some of the type issues here. */ ! ! static void *string_to_int(char *s, int si, size_t size) { ! void *val; ! ! /* allocate string for str* integer conversion. */ ! val = xmalloc(size); ! ! if(si) { /* signed. */ ! ! switch(size) { ! ! case sizeof(int32_t): ! *(int32_t *)val = strtol(s, NULL, 10); ! break; ! ! case sizeof(int16_t): ! *(int16_t *)val = (uint16_t)atoi(s); /* this is safe ! * because we're always getting our ! * own serialized values. they should decay fine. ! * don't use this on strings gotten from the network. */ ! break; ! default: ! /* we should never get here but we should force ourselves ! * to b0rk if we do. */ ! fatal_error("illegal size passed to string_to_int()!"); ! } ! ! } else { /* unsigned. */ ! ! switch(size) { ! ! case sizeof(uint32_t): ! *(uint32_t *)val = strtoul(s, NULL, 10); ! break; ! ! case sizeof(uint16_t): ! *(uint16_t *)val = (uint16_t)atoi(s); /* ditto on safeness. */ ! break; ! ! default: ! /* ditto on forced b0rking. */ ! fatal_error("illegal size passed to string_to_int()!"); ! ! } ! } ! ! return val; } ! /* Interface for string_to_*int* */ ! void *string_to_uint32(char *s) { ! return(string_to_int(s, 0, sizeof(uint32_t))); ! } ! void *string_to_int32(char *s) ! { ! return(string_to_int(s, 1, sizeof(uint32_t))); ! } ! void *string_to_uint16(char *s) ! { ! return(string_to_int(s, 0, sizeof(int16_t))); ! } ! void *string_to_int16(char *s) ! { ! return(string_to_int(s, 1, sizeof(uint16_t))); ! } ! ! /* string int to network. */ ! static void *string_int_to_network(char *s, unsigned char *ret_len, ! int si, size_t size) ! { ! void *val; ! unsigned char *net_val; ! ! net_val = xmalloc(size); ! *ret_len = size; ! if(si) { ! ! switch(size) { ! ! case sizeof(int32_t): ! val = string_to_int32(s); ! *(int32_t *)net_val = htonl(*(int32_t *)val); ! xfree(val); ! break; ! ! case sizeof(int16_t): ! val = string_to_int16(s); ! *(int16_t *)net_val = htons(*(int16_t *)val); ! xfree(val); ! break; ! ! default: ! /* we should never get here but we should force ourselves ! * to b0rk if we do. */ ! fatal_error("illegal size passed to string_int_to_network()!"); ! } ! ! switch(size) { ! ! case sizeof(uint32_t): ! ! val = string_to_uint32(s); ! *(uint32_t *)net_val = htonl(*(uint32_t *)val); ! xfree(val); ! break; ! ! case sizeof(uint16_t): ! val = string_to_uint16(s); ! *(uint16_t *)net_val = htons(*(uint16_t *)val); ! xfree(val); ! break; ! ! default: ! /* ditto on the b0rkination. */ ! fatal_error("illegal size passed to string_int_to_network()!"); ! } ! } ! ! return net_val; ! } ! ! /* interface to string_*int*_to_network */ ! void *string_int32_to_network(char *s, unsigned char *ret_len) ! { ! return(string_int_to_network(s, ret_len, 1, sizeof(int32_t))); ! } ! void *string_uint32_to_network(char *s, unsigned char *ret_len) ! { ! return(string_int_to_network(s, ret_len, 0, sizeof(uint32_t))); ! } ! void *string_int16_to_network(char *s, unsigned char *ret_len) ! { ! return(string_int_to_network(s, ret_len, 1, sizeof(int16_t))); } + void *string_uint16_to_network(char *s, unsigned char *ret_len) + { + return(string_int_to_network(s, ret_len, 0, sizeof(uint16_t))); + } + + /* Gee, lots of workhorses in this source file. */ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-util.c 2002/02/03 16:56:00 1.3 --- dhcp-util.c 2002/02/05 02:00:59 1.4 *************** *** 213,217 **** { char *new_string; ! if(s2 == NULL) return(strdup(s1)); --- 213,220 ---- { char *new_string; ! ! if(s1 == NULL) ! return(strdup(s2)); ! if(s2 == NULL) return(strdup(s1)); |
From: Thamer Al-H. <act...@us...> - 2002-02-03 16:56:04
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv3766 Modified Files: dhcp-agent.h dhcp-align.c dhcp-arp.c dhcp-cache-entry.c dhcp-client-cache.c dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-com.c dhcp-util.c dhcpclient.1 Log Message: fixed small discrepency in secs field after renew; fixed up xid random number generator; added tonnage of comments and much code cleaning; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-agent.h 2002/02/02 15:28:47 1.15 --- dhcp-agent.h 2002/02/03 16:55:59 1.16 *************** *** 504,514 **** extern void block_interrupts(void); extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); - extern struct timeval timeval_diff(struct timeval begin, struct timeval end); extern void info_message(char *fmt, ...); extern char *splice_string(char *s1, char *s2); extern void trim_string(char *s); extern int string_matches(char *s1, char *s2); - extern uint32_t dhcp_gen_xid(uint32_t seed); extern int is_string(const char *string, int len); /* Replacement vsnprintf, snprintf if needed. */ --- 504,513 ---- extern void block_interrupts(void); extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); extern void info_message(char *fmt, ...); extern char *splice_string(char *s1, char *s2); extern void trim_string(char *s); extern int string_matches(char *s1, char *s2); extern int is_string(const char *string, int len); + extern int get_random(void); /* Replacement vsnprintf, snprintf if needed. */ *************** *** 614,617 **** --- 613,617 ---- extern dhcp_option *dhcp_build_requested_ip_address(uint32_t address); extern dhcp_option *dhcp_build_server_identifier(uint32_t address); + extern uint32_t dhcp_gen_xid(void); /* Ether obj routines. */ Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-align.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-align.c 2002/02/02 15:28:47 1.2 --- dhcp-align.c 2002/02/03 16:56:00 1.3 *************** *** 45,81 **** /* TOS */ ! memcpy(&iphdr->ip_tos, data, 1); data++; /* TOS is one octet. */ /* len */ ! memcpy(&iphdr->ip_len, data, 2); ! data += 2; /* len is two octets. */ /* ID */ ! memcpy(&iphdr->ip_id, data, 2); ! data += 2; /* ID is two octets. */ /* offset */ ! memcpy(&iphdr->ip_off, data, 2); ! data += 2; /* offset is two octets. */ /* ttl */ ! memcpy(&iphdr->ip_ttl, data, 1); data++; /* ttl is one octet. */ /* protocol */ ! memcpy(&iphdr->ip_p, data, 1); data++; /* protocol is one octet. */ /* checksum */ ! memcpy(&iphdr->ip_sum, data, 2); ! data += 2; /* checksum is one octet. */ /* source address */ ! memcpy(&iphdr->ip_src, data, 4); ! data += 4; /* source addr is four octets. */ /* dest address */ ! memcpy(&iphdr->ip_dst, data, 4); return; --- 45,81 ---- /* TOS */ ! memcpy(&iphdr->ip_tos, data, sizeof(iphdr->ip_tos)); data++; /* TOS is one octet. */ /* len */ ! memcpy(&iphdr->ip_len, data, sizeof(iphdr->ip_len)); ! data += sizeof(iphdr->ip_len); /* len is two octets. */ /* ID */ ! memcpy(&iphdr->ip_id, data, sizeof(iphdr->ip_id)); ! data += sizeof(iphdr->ip_id); /* ID is two octets. */ /* offset */ ! memcpy(&iphdr->ip_off, data, sizeof(iphdr->ip_off)); ! data += sizeof(iphdr->ip_off); /* offset is two octets. */ /* ttl */ ! memcpy(&iphdr->ip_ttl, data, sizeof(iphdr->ip_ttl)); data++; /* ttl is one octet. */ /* protocol */ ! memcpy(&iphdr->ip_p, data, sizeof(iphdr->ip_p)); data++; /* protocol is one octet. */ /* checksum */ ! memcpy(&iphdr->ip_sum, data, sizeof(iphdr->ip_sum)); ! data += sizeof(iphdr->ip_sum); /* checksum is one octet. */ /* source address */ ! memcpy(&iphdr->ip_src, data, IP_ADDR_LEN); ! data += IP_ADDR_LEN; /* source addr is four octets. */ /* dest address */ ! memcpy(&iphdr->ip_dst, data, IP_ADDR_LEN); return; *************** *** 86,99 **** /* all 2 octets long. */ ! memcpy(&udp->uh_sport, data, 2); ! data += 2; ! memcpy(&udp->uh_dport, data, 2); ! data += 2; ! memcpy(&udp->uh_ulen, data, 2); ! data += 2; ! memcpy(&udp->uh_sum, data, 2); return; --- 86,99 ---- /* all 2 octets long. */ ! memcpy(&udp->uh_sport, data, sizeof(udp->uh_sport)); ! data += sizeof(udp->uh_sport); ! memcpy(&udp->uh_dport, data, sizeof(udp->uh_dport)); ! data += sizeof(udp->uh_dport); ! memcpy(&udp->uh_ulen, data, sizeof(udp->uh_ulen)); ! data += sizeof(udp->uh_ulen); ! memcpy(&udp->uh_sum, data, sizeof(udp->uh_sum)); return; *************** *** 103,146 **** dhcphdr *dhcp) { ! memcpy(&dhcp->op, data, 1); data++; ! memcpy(&dhcp->htype, data, 1); data++; ! memcpy(&dhcp->hlen, data, 1); data++; ! memcpy(&dhcp->hops, data, 1); data++; ! memcpy(&dhcp->xid, data, 4); ! data += 4; ! memcpy(&dhcp->secs, data, 2); ! data += 2; ! memcpy(&dhcp->flags, data, 2); ! data += 2; ! memcpy(&dhcp->ciaddr, data, 4); ! data += 4; ! memcpy(&dhcp->yiaddr, data, 4); ! data += 4; ! memcpy(&dhcp->siaddr, data, 4); ! data += 4; ! memcpy(&dhcp->giaddr, data, 4); ! data += 4; ! memcpy(&dhcp->chaddr, data, 16); ! data += 16; ! memcpy(&dhcp->sname, data, 64); ! data += 64; ! memcpy(&dhcp->file, data, 128); return; --- 103,146 ---- dhcphdr *dhcp) { ! memcpy(&dhcp->op, data, sizeof(dhcp->op)); data++; ! memcpy(&dhcp->htype, data, sizeof(dhcp->htype)); data++; ! memcpy(&dhcp->hlen, data, sizeof(dhcp->hlen)); data++; ! memcpy(&dhcp->hops, data, sizeof(dhcp->hops)); data++; ! memcpy(&dhcp->xid, data, sizeof(dhcp->xid)); ! data += sizeof(dhcp->xid); ! memcpy(&dhcp->secs, data, sizeof(dhcp->secs)); ! data += sizeof(dhcp->secs); ! memcpy(&dhcp->flags, data, sizeof(dhcp->flags)); ! data += sizeof(dhcp->flags); ! memcpy(&dhcp->ciaddr, data, IP_ADDR_LEN); ! data += IP_ADDR_LEN; ! memcpy(&dhcp->yiaddr, data, IP_ADDR_LEN); ! data += IP_ADDR_LEN; ! memcpy(&dhcp->siaddr, data, IP_ADDR_LEN); ! data += IP_ADDR_LEN; ! memcpy(&dhcp->giaddr, data, IP_ADDR_LEN); ! data += IP_ADDR_LEN; ! memcpy(&dhcp->chaddr, data, sizeof(dhcp->chaddr)); ! data += sizeof(dhcp->chaddr); ! memcpy(&dhcp->sname, data, sizeof(dhcp->sname)); ! data += sizeof(dhcp->sname); ! memcpy(&dhcp->file, data, sizeof(dhcp->file)); return; Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-arp.c 2002/02/02 12:28:05 1.5 --- dhcp-arp.c 2002/02/03 16:56:00 1.6 *************** *** 25,28 **** --- 25,29 ---- #include <dhcp-agent.h> + /* constructor */ arp_obj *arp_create(void) { *************** *** 34,37 **** --- 35,39 ---- } + /* destructor */ void arp_destroy(arp_obj *arp) { *************** *** 40,43 **** --- 42,46 ---- } + /* set routines. */ void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr) { *************** *** 93,96 **** --- 96,100 ---- } + /* dump image to packet. */ void arp_write_packet_image(arp_obj *arp, unsigned char *packet) { Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-cache-entry.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-cache-entry.c 2002/01/30 09:26:02 1.2 --- dhcp-cache-entry.c 2002/02/03 16:56:00 1.3 *************** *** 21,28 **** --- 21,33 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * Cache entry object: + * + * We use this object to hold a name/value duplet. + * */ #include <dhcp-agent.h> + /* constructors. */ cache_entry_t *make_cache_entry(char *name, char *value) { *************** *** 45,48 **** --- 50,54 ---- } + /* use alongside purge_list or similar routines. */ static void destroy_cache_entry_in_list(void *data) { *************** *** 50,53 **** --- 56,60 ---- } + /* purge list of cache entries. */ void cache_entry_purge_list(list_t *cache_list) { Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-cache.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-cache.c 2002/02/02 15:28:47 1.4 --- dhcp-client-cache.c 2002/02/03 16:56:00 1.5 *************** *** 1,3 **** --- 1,4 ---- /* $Header$ + * * Copyright 2001 Thamer Alharbash <tm...@wh...> * *************** *** 16,23 **** --- 17,30 ---- * written permission. * + * Client cache object: + * + * We use this to load cached DHCP options, save them, and conversion with + * dhcp-convert are done here to network or serialized state. + * */ #include <dhcp-agent.h> + /* constructor. */ client_cache_t *create_client_cache(dhcp_client_control_t *dc) { *************** *** 31,34 **** --- 38,42 ---- } + /* purges list in cache object. */ void purge_cache(client_cache_t *cc) { *************** *** 51,54 **** --- 59,63 ---- } + /* destructor. */ void client_cache_destroy(client_cache_t *cc) { *************** *** 60,63 **** --- 69,73 ---- } + /* read next cache entry from file. */ static cache_entry_t *read_next_cache_var(FILE *fp) { *************** *** 70,73 **** --- 80,87 ---- fatal_error("corrupt cache! try removing it and restarting it."); + /* as long as file_parse_string didn't return an error we're + * guaranteed proper strings with file_get_var_name(), + * file_get_var_val() */ + cache_entry = make_cache_entry(file_get_var_name(), file_get_var_val()); return cache_entry; *************** *** 75,78 **** --- 89,93 ---- } + /* Load up cache from filename. */ static int load_client_cache_proc(client_cache_t *cc, char *filename) { *************** *** 94,97 **** --- 109,113 ---- } + /* filename creation routines. */ static char *get_fname(client_cache_t *cc) { *************** *** 104,107 **** --- 120,124 ---- } + /* load cache (interface) */ int load_client_cache(client_cache_t *cc, unsigned char use_tmp) { *************** *** 122,125 **** --- 139,150 ---- } + /* check to see if cache is empty: + * as long as the cache file exists + * we're always guaranteed a cache + * except on filesystem corruption. + * in that case we can't do much except + * complain. using file_exists() is + * as good as it gets. + */ int client_cache_is_empty(client_cache_t *cc) { *************** *** 135,138 **** --- 160,164 ---- } + /* work house routine to convert from serialized state to network datum. */ static void *convert_to_network(unsigned char tag, char *string) { *************** *** 156,162 **** return opt; } - - /* Convert options from cache struct straight to dhcp options. */ static list_t *get_cache_options_list_proc(client_cache_t *cc, void* (*convert_func)(unsigned char tag, char *string)) --- 182,191 ---- return opt; } + /* + * Convert options from cache serialized form to whatever form convert_func, returns. + * If convert_func is NULL then just return in serialized form (sysconf needs it that way). + * + */ static list_t *get_cache_options_list_proc(client_cache_t *cc, void* (*convert_func)(unsigned char tag, char *string)) *************** *** 195,198 **** --- 224,230 ---- } + /* dump options into file. here we take data in network form and dump them in serialized form. + * we always do this to the temp file. + */ int client_cache_dump_options(client_cache_t *cc, list_t *options) *************** *** 243,246 **** --- 275,279 ---- } + /* work house load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void* (*convert_func)(unsigned char tag, char *string)) *************** *** 258,266 **** } list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) { return(client_cache_load_options_list_proc(cc, use_tmp, convert_to_network)); } ! list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { --- 291,300 ---- } + /* load options and return network list. */ list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) { return(client_cache_load_options_list_proc(cc, use_tmp, convert_to_network)); } ! /* load options and return serialized list. */ list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { *************** *** 268,271 **** --- 302,306 ---- } + /* update cache: move temp cache over real cache. */ void client_cache_update(client_cache_t *cc) { *************** *** 283,286 **** --- 318,322 ---- } + /* delete old temporary cache. */ void client_cache_delete_tmp_cache(client_cache_t *cc) { *************** *** 293,297 **** } ! void client_cache_delete_cache(client_cache_t *cc) { --- 329,333 ---- } ! /* delete cache. */ void client_cache_delete_cache(client_cache_t *cc) { Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client-control.c 2002/02/02 15:28:47 1.7 --- dhcp-client-control.c 2002/02/03 16:56:00 1.8 *************** *** 24,33 **** #include <dhcp-agent.h> void dhcp_client_update_secs(dhcp_client_control_t *dc) { ! dc->secs = (dc->started - time(NULL)); return; } void dhcp_client_reset_secs(dhcp_client_control_t *dc) { --- 24,35 ---- #include <dhcp-agent.h> + /* Update seconds field for dhcp discover packets. */ void dhcp_client_update_secs(dhcp_client_control_t *dc) { ! dc->secs = (time(NULL) - dc->started); return; } + /* reset started field for when we revert back to discover again. */ void dhcp_client_reset_secs(dhcp_client_control_t *dc) { *************** *** 36,39 **** --- 38,42 ---- } + /* create client id from a string in the format of 0x:0x:0x:0x:0x:0x */ static unsigned char *create_fake_client_id(unsigned char *mac_string) { *************** *** 54,57 **** --- 57,61 ---- } + /* create a proper client id from the interface address passed. */ static unsigned char *create_client_id(eth_addr_t interface_address) { *************** *** 67,70 **** --- 71,75 ---- } + /* dummy routine. we use this to manipulate conf/cache. */ dhcp_client_control_t *create_dhcp_client_control_dummy(char *interface) { *************** *** 78,81 **** --- 83,93 ---- } + static void update_dhcp_xid(dhcp_client_control_t *dc) + { + dc->xid = dhcp_gen_xid(); /* this is redone at discover_request too */ + return; + } + + /* create client control object */ dhcp_client_control_t *create_dhcp_client_control(char *interface) { *************** *** 143,152 **** /* xid setting */ ! /* FIXME: rfc compliant for now but robustness dictates ! * that we should update this per transaction ! * basis. */ ! ! dc->xid = dhcp_gen_xid((time(NULL) + getpid())); dhcp_client_reset_secs(dc); dhcp_client_update_secs(dc); --- 155,161 ---- /* xid setting */ + update_dhcp_xid(dc); ! /* secs settings. */ dhcp_client_reset_secs(dc); dhcp_client_update_secs(dc); *************** *** 169,175 **** return dc; } - - /* fake_hw_addr is handed to us in a C string form. */ void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr) { --- 178,184 ---- return dc; } + /* use fake address in 0x:0x:0x:0x:0x we need to notify rawnet about this. + * achtung: arp packets still have proper address so we don't fudge arp caches up. */ void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr) { *************** *** 183,186 **** --- 192,196 ---- } + /* destructor. */ void destroy_dhcp_client_control(dhcp_client_control_t *dc) { Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client-states.c 2002/02/02 15:28:47 1.11 --- dhcp-client-states.c 2002/02/03 16:56:00 1.12 *************** *** 39,43 **** } ! /* Along with the parameter request list we always build these options. */ static list_t *client_build_option_list(unsigned char *opts, unsigned char message_type, --- 39,44 ---- } ! /* Along with the parameter request list we always build these options ! * upon creating new dhcp packets. */ static list_t *client_build_option_list(unsigned char *opts, unsigned char message_type, *************** *** 75,78 **** --- 76,83 ---- } + /* these checking routines are independant of the checks done + * in client_transact. they're a more specific type of check.*/ + + /* filter to check for valid discover responses. */ static int client_discover_check(dhcp_client_control_t *dc) { *************** *** 84,87 **** --- 89,93 ---- } + /* filter to check for valid request responses. */ static int client_request_check(dhcp_client_control_t *dc) { *************** *** 127,131 **** /* UNARP (rfc 1868). This makes us more network friendly. */ - static void client_broadcast_unarp(dhcp_client_control_t *dc) { --- 133,136 ---- *************** *** 137,141 **** /* Send and wait for reply. */ - static int client_transact(dhcp_client_control_t *dc, unsigned update_secs, int (*check)(dhcp_client_control_t *dc)) --- 142,145 ---- *************** *** 196,201 **** /* run tests. */ - /* is it dhcp?. */ if(dc->rawnet->type != RAWNET_DHCP) break; --- 200,205 ---- /* run tests. */ + /* is it dhcp?. */ if(dc->rawnet->type != RAWNET_DHCP) break; *************** *** 213,216 **** --- 217,221 ---- break; + /* great: valid packet. destroy rtt object and return. */ rtt_destroy(rtt); return 0; *************** *** 223,226 **** --- 228,232 ---- } + /* do discover/offer transaction. */ int client_discover_offer(dhcp_client_control_t *dc) { *************** *** 229,234 **** options = client_build_option_list(dc->conf->options, DHCP_DISCOVER_TM, dc->client_id, dc->class_id); ! dc->secs = (time(NULL) - dc->started); /* begin keeping track of DHCP secs. */ /* Our options cleared by rawnet_build_* since they are passed * down and later purged. */ --- 235,246 ---- options = client_build_option_list(dc->conf->options, DHCP_DISCOVER_TM, dc->client_id, dc->class_id); ! ! /* when we begin transmitting discover_offer we setup our secs field. ! * this is because relay agents and dhcp servers use this to see how ! * bad off we are. */ + dhcp_client_reset_secs(dc); + dhcp_client_update_secs(dc); + /* Our options cleared by rawnet_build_* since they are passed * down and later purged. */ *************** *** 255,259 **** /* dump cache file. */ - if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { error_message("could not create temporary cache"); --- 267,270 ---- *************** *** 266,272 **** } ! /* We need to rebuild an option list of all the options we ! * got, and then send out a request see what we get back. */ ! int client_request_ack(dhcp_client_control_t *dc) { --- 277,281 ---- } ! /* do client_request_ack transaction. */ int client_request_ack(dhcp_client_control_t *dc) { *************** *** 295,298 **** --- 304,310 ---- } + /* if we got a pack we're good to go, if we haven't + * then we need to revert to discover/offer state. */ + if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM)) return STATE_SETUP; *************** *** 302,305 **** --- 314,318 ---- } + /* do setup (call do_sysconf) */ int client_setup(dhcp_client_control_t *dc) { *************** *** 308,312 **** options = client_cache_load_option_string_list(dc->cache, 0); if(options == NULL) { ! error_message("have empty configuration cache! cannot configure host"); return -1; } --- 321,325 ---- options = client_cache_load_option_string_list(dc->cache, 0); if(options == NULL) { ! error_message("received empty configuration cache! cannot configure host"); return -1; } *************** *** 323,326 **** --- 336,340 ---- } + /* wait for renewal time. */ int client_wait(dhcp_client_control_t *dc) { *************** *** 356,359 **** --- 370,374 ---- } + /* release lease. */ int client_release(dhcp_client_control_t *dc) { Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client.c 2002/02/02 15:34:03 1.10 --- dhcp-client.c 2002/02/03 16:56:00 1.11 *************** *** 25,32 **** #include <dhcp-agent.h> ! int interactive = 1; ! char *binname = NULL; ! char *work_dir = "/etc/dhcpclient"; static void do_shutdown(dhcp_client_control_t *dc) { --- 25,33 ---- #include <dhcp-agent.h> ! int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ ! char *binname = NULL; /* we need a name. */ ! char *work_dir = CLIENT_WORK_DIR; /* our default working directory */ + /* do a graceful shutdown. */ static void do_shutdown(dhcp_client_control_t *dc) { *************** *** 42,50 **** /* * Our initialize client state function. ! * We can be in two states. * The discover/offer state, or we can * be in the request state where we * already have a configuration. * */ --- 43,55 ---- /* * Our initialize client state function. ! * We can be in two states. ! * * The discover/offer state, or we can * be in the request state where we * already have a configuration. * + * We always ask for configuration info on + * startup so we can't begin in any other + * state except these two. */ *************** *** 56,60 **** return STATE_REQUEST_ACK; } ! static void usage(char *s) { --- 61,66 ---- return STATE_REQUEST_ACK; } ! ! /* print usage info. */ static void usage(char *s) { *************** *** 63,66 **** --- 69,73 ---- } + /* main loop: if only_setup is called we exit after setup. */ static int do_client_dhcp_loop(int only_setup, dhcp_client_control_t *dc, int state) { *************** *** 121,124 **** --- 128,132 ---- } + /* kill a running client. */ static void do_kill_client(char *interface) { *************** *** 139,142 **** --- 147,151 ---- } + /* wake up a client. send sigalarm. */ static void do_wake_client(char *interface) { *************** *** 157,162 **** } ! /* A bit of a hack here since we need only parts of a control structure. */ ! static void do_clear_cache(char *interface) { --- 166,170 ---- } ! /* delete existing cache. make sure no other client is running. */ static void do_clear_cache(char *interface) { *************** *** 164,168 **** dhcp_client_control_t *dc; client_cache_t *cc; ! if(!get_pid_file(interface, &pid)) { /* A race condition exists between the discover and request state. --- 172,176 ---- dhcp_client_control_t *dc; client_cache_t *cc; ! if(!get_pid_file(interface, &pid)) { /* A race condition exists between the discover and request state. *************** *** 192,195 **** --- 200,204 ---- } + /* check for existing client. */ static int client_process_exists(char *interface) { Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-com.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-com.c 2002/01/30 16:06:46 1.2 --- dhcp-com.c 2002/02/03 16:56:00 1.3 *************** *** 90,93 **** --- 90,94 ---- } + /* create option. */ dhcp_option *create_dhcp_option(const unsigned char *opt_data, unsigned char len, unsigned char tag) { *************** *** 104,107 **** --- 105,109 ---- } + /* destroy dhcp option. */ void destroy_dhcp_option(dhcp_option *option) { *************** *** 111,117 **** return; } - - /* Copy DHCP option safely. */ static dhcp_option *process_next_dhcp_option(const unsigned char *opt_data, int len, unsigned char *optlen) --- 113,118 ---- return; } + /* copy DHCP option safely. */ static dhcp_option *process_next_dhcp_option(const unsigned char *opt_data, int len, unsigned char *optlen) *************** *** 131,140 **** } ! /* ! * After creating a new object this function ! * will read in a packet image. ! * ! */ ! int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) { --- 132,136 ---- } ! /* read packet image. */ int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) { *************** *** 333,338 **** /* tests. */ ! /* Return 1 on valid magic cookie, and 0 on invalid cookie. */ ! int dhcp_valid_magic_cookie(dhcp_obj *dhcp) { --- 329,333 ---- /* tests. */ ! /* test for valid cookie. */ int dhcp_valid_magic_cookie(dhcp_obj *dhcp) { *************** *** 345,349 **** } ! static int dhcp_is_type_proc(dhcp_obj *dhcp, unsigned char type) { dhcp_option *opt; --- 340,345 ---- } ! /* test for type. */ ! int dhcp_is_type(dhcp_obj *dhcp, unsigned char type) { dhcp_option *opt; *************** *** 366,375 **** return 0; } - - int dhcp_is_type(dhcp_obj *dhcp, unsigned char type) - { - return(dhcp_is_type_proc(dhcp, type)); - } int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len) { --- 362,367 ---- return 0; } + /* test for option validity. */ int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len) { *************** *** 380,383 **** --- 372,376 ---- } + /* test for existance of option. */ int dhcp_have_option(dhcp_obj *dhcp, unsigned char tag) { *************** *** 402,431 **** int dhcp_have_atleast_requested_options(dhcp_obj *dhcp, unsigned char *options) { - dhcp_option *option; - int len = 0; - int matches = 0; int i; for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! if(options[i]) ! len++; ! } ! ! dhcp_reset_option_seek(dhcp); ! ! while((option = dhcp_get_next_option(dhcp)) != NULL) { ! ! if(option->tag < MAX_OPTIONS_HANDLED && ! options[option->tag]) ! matches++; } - ! /* At least or greater than. */ ! if(len >= matches) ! return 1; ! else ! return 0; ! } --- 395,406 ---- int dhcp_have_atleast_requested_options(dhcp_obj *dhcp, unsigned char *options) { int i; for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! if(options[i] && !dhcp_have_option(dhcp, i)) ! return 1; } ! return 0; } *************** *** 457,462 **** } ! /* accept an array of 1/0s telling us which options to build the request option. */ ! dhcp_option *dhcp_build_parameter_request_list_option(unsigned char *requested_options) { --- 432,436 ---- } ! /* accept bit array telling us which options to build the request option. */ dhcp_option *dhcp_build_parameter_request_list_option(unsigned char *requested_options) { *************** *** 466,470 **** /* Grab length so we can just malloc all at once. */ - for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { if(requested_options[i]) --- 440,443 ---- *************** *** 650,653 **** --- 623,627 ---- /* dhcp set options, add options. */ + /* replace options with list passed (convenience). */ void dhcp_set_options(dhcp_obj *dhcp, list_t *options) { *************** *** 657,660 **** --- 631,635 ---- } + /* write options to packet pointer. */ void dhcp_write_options(dhcp_obj *dhcp, unsigned char *packet) { *************** *** 695,701 **** return; } - - /* Write image out to packet. */ void dhcp_write_packet_image(dhcp_obj *dhcp, unsigned char *packet) { --- 670,675 ---- return; } + /* write dhcp image out to packet. */ void dhcp_write_packet_image(dhcp_obj *dhcp, unsigned char *packet) { *************** *** 703,737 **** memcpy(packet, &dhcp->fixedheader.op, 1); ! packet += 1; memcpy(packet, &dhcp->fixedheader.htype, 1); ! packet += 1; memcpy(packet, &dhcp->fixedheader.hlen, 1); ! packet += 1; memcpy(packet, &dhcp->fixedheader.hops, 1); ! packet += 1; memcpy(packet, &dhcp->fixedheader.xid, 4); ! packet += 4; memcpy(packet, &dhcp->fixedheader.secs, 2); ! packet += 2; memcpy(packet, &dhcp->fixedheader.flags, 2); ! packet += 2; ! memcpy(packet, &dhcp->fixedheader.ciaddr, 4); ! packet += 4; ! memcpy(packet, &dhcp->fixedheader.yiaddr, 4); ! packet += 4; ! memcpy(packet, &dhcp->fixedheader.siaddr, 4); ! packet += 4; ! memcpy(packet, &dhcp->fixedheader.giaddr, 4); ! packet += 4; memcpy(packet, &dhcp->fixedheader.chaddr, DHCP_CHADDR_SIZE); --- 677,711 ---- memcpy(packet, &dhcp->fixedheader.op, 1); ! packet += sizeof(dhcp->fixedheader.op); memcpy(packet, &dhcp->fixedheader.htype, 1); ! packet += sizeof(dhcp->fixedheader.htype); memcpy(packet, &dhcp->fixedheader.hlen, 1); ! packet += sizeof(dhcp->fixedheader.hlen); memcpy(packet, &dhcp->fixedheader.hops, 1); ! packet += sizeof(dhcp->fixedheader.hops); memcpy(packet, &dhcp->fixedheader.xid, 4); ! packet += sizeof(dhcp->fixedheader.xid); memcpy(packet, &dhcp->fixedheader.secs, 2); ! packet += sizeof(dhcp->fixedheader.secs); memcpy(packet, &dhcp->fixedheader.flags, 2); ! packet += sizeof(dhcp->fixedheader.flags); ! memcpy(packet, &dhcp->fixedheader.ciaddr, IP_ADDR_LEN); ! packet += IP_ADDR_LEN; ! memcpy(packet, &dhcp->fixedheader.yiaddr, IP_ADDR_LEN); ! packet += IP_ADDR_LEN; ! memcpy(packet, &dhcp->fixedheader.siaddr, IP_ADDR_LEN); ! packet += IP_ADDR_LEN; ! memcpy(packet, &dhcp->fixedheader.giaddr, IP_ADDR_LEN); ! packet += IP_ADDR_LEN; memcpy(packet, &dhcp->fixedheader.chaddr, DHCP_CHADDR_SIZE); *************** *** 746,751 **** /* Now dump cookie. */ ! memcpy(packet, &dhcp->magic_cookie, 4); ! packet += 4; /* Now write options. */ --- 720,725 ---- /* Now dump cookie. */ ! memcpy(packet, &dhcp->magic_cookie, sizeof(dhcp->magic_cookie)); ! packet += sizeof(dhcp->magic_cookie); /* Now write options. */ *************** *** 756,763 **** } ! uint32_t dhcp_gen_xid(uint32_t seed) { ! /* fixme: no need to keep setting the seed. */ ! srand(seed); ! return rand(); } --- 730,736 ---- } ! /* generate xid. */ ! uint32_t dhcp_gen_xid(void) { ! return(get_random()); } Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-util.c 2002/01/30 09:26:03 1.2 --- dhcp-util.c 2002/02/03 16:56:00 1.3 *************** *** 29,32 **** --- 29,33 ---- static char msgbuff[MSG_BUFFER_SIZE]; + /* send error message. */ void error_message(char *fmt, ...) { *************** *** 45,49 **** va_end(ap); } ! void fatal_error(char *fmt, ...) { --- 46,51 ---- va_end(ap); } ! ! /* send error message and exit. (convenience) */ void fatal_error(char *fmt, ...) { *************** *** 64,67 **** --- 66,70 ---- } + /* send info message (warnings included) */ void info_message(char *fmt, ...) { *************** *** 137,159 **** #endif - - /* Calculate the difference between two timeval structs. - * An assumption is made that end is greater than begin */ - - struct timeval timeval_diff(struct timeval begin, struct timeval end) - { - struct timeval difference = { 0, 0 }; - - if(begin.tv_usec > end.tv_usec) { - end.tv_sec--; - end.tv_usec += 1000000; - } - - difference.tv_sec = end.tv_sec - begin.tv_sec; - difference.tv_usec = end.tv_usec - begin.tv_usec; ! return difference; ! } void add_interrupt_handler(int sigtype, void (*sighandler)(int)) { --- 140,147 ---- #endif ! /* signal manipulation routines. */ + /* add signal handler. */ void add_interrupt_handler(int sigtype, void (*sighandler)(int)) { *************** *** 172,175 **** --- 160,164 ---- } + /* block all signals. */ void block_interrupts(void) { *************** *** 182,188 **** return; } - - /* Check for signals */ int check_for_interrupts(void) { --- 171,176 ---- return; } + /* unblock signals temporarily so we can receive pending signals. */ int check_for_interrupts(void) { *************** *** 201,204 **** --- 189,193 ---- } + /* suspend indefinetly for a signal (useful for alarm). */ void suspend_for_interrupts(void) { *************** *** 211,214 **** --- 200,204 ---- /* String routines. */ + /* * Splice two strings together. *************** *** 234,243 **** } ! /* ! * Trim any trailing or prepended white spaces. ! * Make a copy, then copy out then copy back in ! * with a trailing null. ! */ ! void trim_string(char *s) { --- 224,228 ---- } ! /* trim preprending and trailing space. also get rid of newlines. */ void trim_string(char *s) { *************** *** 277,280 **** --- 262,266 ---- } + /* is a valid C string? */ int is_string(const char *string, int len) { *************** *** 293,298 **** } ! /* More string ugliness. This needs to be made cleaner. */ ! int hex_string_to_value(char *string, unsigned char *dst) { --- 279,283 ---- } ! /* parse hex string (0x:0x...0x) to value. (not fun to write) */ int hex_string_to_value(char *string, unsigned char *dst) { *************** *** 333,336 **** --- 318,322 ---- } + /* check if two strings match using strlen and strcmp */ int string_matches(char *s1, char *s2) { *************** *** 340,342 **** --- 326,346 ---- else return 0; + } + + /* initialize random seed. */ + static void init_rand(void) + { + srandom(getpid() + time(NULL)); + } + + int get_random(void) + { + static unsigned char have_init_random = 0; + + if(!have_init_random) { + init_rand(); + have_init_random = 1; + } + + return(random()); } Index: dhcpclient.1 =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcpclient.1,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcpclient.1 2002/02/02 15:34:04 1.5 --- dhcpclient.1 2002/02/03 16:56:00 1.6 *************** *** 16,23 **** foreground until it initializes its interface, and then go into the background and renew its lease when it needs to. You may safely run ! more than one dhcpclient per interface since it stores all its data ! in control files named after the interface it is configuring. ! Currently only the basic networking DHCP options are handled. The ! interfaces IP address, routing, and domain name system are setup. .Sh OPTIONS .Bl -tag --- 16,24 ---- foreground until it initializes its interface, and then go into the background and renew its lease when it needs to. You may safely run ! more than one dhcpclient per host since it stores all its data in ! control files named after the interface it is configuring. It is not ! safe to run more than one dhcpclient per interface. Currently only ! the basic networking DHCP options are handled. The interfaces IP ! address, routing, and domain name system are setup. .Sh OPTIONS .Bl -tag |
From: Thamer Al-H. <act...@us...> - 2002-02-02 15:34:08
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv28551 Modified Files: dhcp-client.c dhcpclient.1 Log Message: updated man page; fixed up usage() in dhcpclient; Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client.c 2002/02/02 15:28:47 1.9 --- dhcp-client.c 2002/02/02 15:34:03 1.10 *************** *** 59,63 **** static void usage(char *s) { ! printf("usage: %s [-vkwa] [-d directory] [-i interface name]\n", s); exit(0); } --- 59,63 ---- static void usage(char *s) { ! printf("usage: %s [-cavkw] [-d directory] [-i interface name] [ -m mac address ]\n", s); exit(0); } Index: dhcpclient.1 =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcpclient.1,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcpclient.1 2002/01/31 23:15:44 1.4 --- dhcpclient.1 2002/02/02 15:34:04 1.5 *************** *** 6,10 **** .Sh SYNOPSIS .Nm dhcpclient ! .Op -av .Op -k .Op Ar -d working directory --- 6,10 ---- .Sh SYNOPSIS .Nm dhcpclient ! .Op -avckw .Op -k .Op Ar -d working directory *************** *** 38,41 **** --- 38,44 ---- .It Op -w Wake current dhcpclient on specificed interface. This forces a renew. + .It Op -c + Clear cache. Should be used if client crashes and leaves corrupt + cache. .It Op Ar -m fake mac address Use a fake mac source address. Useful only for diagnostics where |
From: Thamer Al-H. <act...@us...> - 2002-02-02 15:28:51
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv27321 Modified Files: config.h.in configure configure.in dhcp-agent.h dhcp-align.c dhcp-client-cache.c dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-files.c Log Message: added -c option to clear cache; fixed up some more comments; Index: config.h.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/config.h.in,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** config.h.in 2002/02/02 11:55:08 1.4 --- config.h.in 2002/02/02 15:28:46 1.5 *************** *** 19,22 **** --- 19,25 ---- #undef HAVE_INTTYPES_H + /* Define if you have the `rename' function. */ + #undef HAVE_RENAME + /* Define if you have the <signal.h> header file. */ #undef HAVE_SIGNAL_H Index: configure =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** configure 2002/02/02 11:55:08 1.8 --- configure 2002/02/02 15:28:47 1.9 *************** *** 2378,2382 **** done ! for ac_func in strdup uname calloc daemon do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` --- 2378,2382 ---- done ! for ac_func in strdup uname calloc daemon rename do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` Index: configure.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.in,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** configure.in 2002/02/02 11:55:08 1.8 --- configure.in 2002/02/02 15:28:47 1.9 *************** *** 32,36 **** dnl check for functions ! AC_CHECK_FUNCS(strdup uname calloc daemon) AC_CHECK_FUNCS(sprintf vsnprintf, --- 32,36 ---- dnl check for functions ! AC_CHECK_FUNCS(strdup uname calloc daemon rename) AC_CHECK_FUNCS(sprintf vsnprintf, Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-agent.h 2002/02/02 12:28:05 1.14 --- dhcp-agent.h 2002/02/02 15:28:47 1.15 *************** *** 743,746 **** --- 743,747 ---- extern void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr); + extern dhcp_client_control_t *create_dhcp_client_control_dummy(char *interface); /* dhcp client conf */ Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-align.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-align.c 2002/01/29 18:05:03 1.1.1.1 --- dhcp-align.c 2002/02/02 15:28:47 1.2 *************** *** 21,25 **** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * Since structures may be padded we simply can't guarantee * alignment unless we copy each member out individually. * Yes I know this is extreme since most packet structures --- 21,25 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * Since structures may be padded. We simply can't guarantee * alignment unless we copy each member out individually. * Yes I know this is extreme since most packet structures Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-cache.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-cache.c 2002/01/30 09:26:02 1.3 --- dhcp-client-cache.c 2002/02/02 15:28:47 1.4 *************** *** 124,137 **** int client_cache_is_empty(client_cache_t *cc) { ! int retval; ! ! load_client_cache(cc, 0); ! if(cc->vars == NULL) retval = 1; ! else ! retval = 0; - purge_cache(cc); return retval; } --- 124,135 ---- int client_cache_is_empty(client_cache_t *cc) { ! int retval = 0; ! char *fname; ! fname = get_fname(cc); ! if(file_exists(fname)) retval = 1; ! xfree(fname); return retval; } *************** *** 170,174 **** void *data; - for(cache = cc->vars;cache;cache = cache->next) { --- 168,171 ---- Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client-control.c 2002/02/01 19:56:10 1.6 --- dhcp-client-control.c 2002/02/02 15:28:47 1.7 *************** *** 67,70 **** --- 67,81 ---- } + dhcp_client_control_t *create_dhcp_client_control_dummy(char *interface) + { + dhcp_client_control_t *dc; + + dc = xmalloc(sizeof(dhcp_client_control_t)); + memset(dc, 0, sizeof(dhcp_client_control_t)); + dc->interface = strdup(interface); + + return dc; + } + dhcp_client_control_t *create_dhcp_client_control(char *interface) { Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client-states.c 2002/02/02 12:28:05 1.10 --- dhcp-client-states.c 2002/02/02 15:28:47 1.11 *************** *** 21,25 **** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * These are the individual client state functions. */ --- 21,27 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * These are the individual client state functions, ! * along with their utility routines. ! * */ Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client.c 2002/02/02 00:48:06 1.8 --- dhcp-client.c 2002/02/02 15:28:47 1.9 *************** *** 53,60 **** if(client_cache_is_empty(dc->cache)) { return STATE_DISCOVER_OFFER; ! } else /* If the cache isn't empty ! * we assume we're in the request stage. ! * XXX -- fixme do integrity check in ! * case of crash or corruption. */ return STATE_REQUEST_ACK; } --- 53,57 ---- if(client_cache_is_empty(dc->cache)) { return STATE_DISCOVER_OFFER; ! } else /* if not empty we assume we can request the options. */ return STATE_REQUEST_ACK; } *************** *** 160,163 **** --- 157,195 ---- } + /* A bit of a hack here since we need only parts of a control structure. */ + + static void do_clear_cache(char *interface) + { + pid_t pid; + dhcp_client_control_t *dc; + client_cache_t *cc; + + if(!get_pid_file(interface, &pid)) { + /* A race condition exists between the discover and request state. + * So we can't hup the client and tell it the cache has been deleted. */ + error_message("dhcpclient already running. i won't delete cache until it's shutdown."); + return; + } + + /* As long as no client is being run we can go ahead and delete the cache. + * We need a client cache structure though, pass it a dummy structure + * with the interface. That's all it needs. + * (this is the hack). + */ + + dc = create_dhcp_client_control_dummy(interface); + cc = create_client_cache(dc); + + /* now delete. */ + client_cache_delete_cache(cc); + client_cache_delete_tmp_cache(cc); + + /* all done. */ + destroy_dhcp_client_control(dc); + client_cache_destroy(cc); + + return; + } + static int client_process_exists(char *interface) { *************** *** 182,186 **** static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "davim:kwh:")) != -1) { switch(c) { --- 214,218 ---- static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "cdavim:kwh:")) != -1) { switch(c) { *************** *** 214,217 **** --- 246,254 ---- chdir(work_dir); do_wake_client(interface); + exit(0); + + case 'c': + chdir(work_dir); + do_clear_cache(interface); exit(0); Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-files.c 2002/01/29 18:05:05 1.1.1.1 --- dhcp-files.c 2002/02/02 15:28:47 1.2 *************** *** 130,137 **** void move_file(char *fname, char *dest) { unlink(dest); link(fname, dest); unlink(fname); ! return; } --- 130,140 ---- void move_file(char *fname, char *dest) { + #ifdef HAVE_RENAME + rename(fname, dest); + #else /* HAVE_RENAME */ unlink(dest); link(fname, dest); unlink(fname); ! #endif /* HAVE_RENAME */ return; } |
From: Thamer Al-H. <act...@us...> - 2002-02-02 12:28:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv26656 Modified Files: dhcp-agent.h dhcp-arp.c dhcp-client-states.c dhcp-net.c Log Message: implemented unarp in client; no idea if its actually working in a useful way; need to test against something that handles unarp; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-agent.h 2002/02/02 00:48:06 1.13 --- dhcp-agent.h 2002/02/02 12:28:05 1.14 *************** *** 471,474 **** --- 471,476 ---- eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr); + void rawnet_build_unarp(rawnet_t *net, uint32_t source_addr, + eth_addr_t source_hw_addr); extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-arp.c 2002/02/02 00:48:06 1.4 --- dhcp-arp.c 2002/02/02 12:28:05 1.5 *************** *** 123,125 **** return; } - --- 123,124 ---- Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-states.c 2002/02/02 00:48:06 1.9 --- dhcp-client-states.c 2002/02/02 12:28:05 1.10 *************** *** 26,29 **** --- 26,32 ---- #include <dhcp-agent.h> + static uint32_t client_ip_addr; + static eth_addr_t client_hw_addr; + static sig_atomic_t have_alarm = 0; *************** *** 88,91 **** --- 91,111 ---- } + /* Called after initialization. + * This lets us do things like arp and unarp + * without having to sift through the cache. + */ + + static int client_update_addresses(dhcp_client_control_t *dc) + { + + if(rawnet_get_interface_hw_addr(dc->rawnet, &client_hw_addr) || + interface_get_ip_addr(dc->interface_control, dc->interface, &client_ip_addr)) { + error_message("could get get hardware and ip addresses after initialization."); + return -1; + } + + return 0; + } + /* * Use this to send out a broadcast reply claiming that we own the *************** *** 97,116 **** static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { - uint32_t ip_addr; - eth_addr_t hw_addr; - - /* Get our IP address from rawnet. - * We don't get it from the cache. - * This is quicker, and since it should be - * setup it's more correct. - */ - - if(rawnet_get_interface_hw_addr(dc->rawnet, &hw_addr) || - interface_get_ip_addr(dc->interface_control, dc->interface, &ip_addr)) { - error_message("warning: could get get hardware and ip addresses to generate arp reply. this is bad, but i'll keep going."); - return; - } ! rawnet_build_arp_reply_broadcast(dc->rawnet, ip_addr, hw_addr); rawnet_send_packet(dc->rawnet); --- 117,122 ---- static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { ! rawnet_build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); *************** *** 118,121 **** --- 124,137 ---- } + /* UNARP (rfc 1868). This makes us more network friendly. */ + + static void client_broadcast_unarp(dhcp_client_control_t *dc) + { + rawnet_build_unarp(dc->rawnet, client_ip_addr, client_hw_addr); + rawnet_send_packet(dc->rawnet); + + return; + } + /* Send and wait for reply. */ *************** *** 296,299 **** --- 312,318 ---- do_sysconf(options, dc); cache_entry_purge_list(options); + + if(client_update_addresses(dc)) + return -1; client_broadcast_arp_reply(dc); *************** *** 360,363 **** --- 379,387 ---- client_cache_delete_cache(dc->cache); + /* We should still have our interface up, so go ahead and send UNARP before + * bringing it down later. */ + + client_broadcast_unarp(dc); + return 0; /* called from do_shutdown() so no real state returned */ } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-net.c 2002/02/02 00:48:06 1.8 --- dhcp-net.c 2002/02/02 12:28:05 1.9 *************** *** 65,69 **** /* constants we need. */ ! static const eth_addr_t eth_broadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; static const uint32_t ip_addr_broadcast = 0xffffffff; --- 65,70 ---- /* constants we need. */ ! static const eth_addr_t eth_null = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; ! static const eth_addr_t eth_broadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; static const uint32_t ip_addr_broadcast = 0xffffffff; *************** *** 414,423 **** uint32_t sender_ip_addr, eth_addr_t target_hw_addr, ! uint32_t target_ip_addr) { arp_set_hardware_type(net->arp_p, ARP_HRD_ETH); arp_set_protocol_type(net->arp_p, ARP_PRO_IP); ! arp_set_hardware_len(net->arp_p, ETH_ADDR_LEN); arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); arp_set_op(net->arp_p, opcode); --- 415,425 ---- uint32_t sender_ip_addr, eth_addr_t target_hw_addr, ! uint32_t target_ip_addr, ! uint8_t hardware_len) /* for unarp it's 0 */ { arp_set_hardware_type(net->arp_p, ARP_HRD_ETH); arp_set_protocol_type(net->arp_p, ARP_PRO_IP); ! arp_set_hardware_len(net->arp_p, hardware_len); arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); arp_set_op(net->arp_p, opcode); *************** *** 645,649 **** { build_eth_broadcast(net, sender_hw_addr, ETH_TYPE_ARP); ! build_arp(net, opcode, sender_hw_addr, sender_ip_addr, target_hw_addr, target_ip_addr); net->type = RAWNET_ARP; --- 647,652 ---- { build_eth_broadcast(net, sender_hw_addr, ETH_TYPE_ARP); ! build_arp(net, opcode, sender_hw_addr, sender_ip_addr, target_hw_addr, ! target_ip_addr, ETH_ADDR_LEN); net->type = RAWNET_ARP; *************** *** 672,675 **** --- 675,693 ---- } + /* only one way to build unarp, so don't procify it. */ + + void rawnet_build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) + { + build_eth_broadcast(net, source_hw_addr, ETH_TYPE_ARP); + build_arp(net, ARP_OP_REPLY, eth_null, source_addr, eth_null, ip_addr_broadcast, 0); + + net->type = RAWNET_ARP; + net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN + ARP_HDR_LEN; + + rawnet_write_packet(net); + + return; + } + /* Create a dhcp discover message. */ |
From: Thamer Al-H. <act...@us...> - 2002-02-02 11:55:12
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv20570 Modified Files: config.h.in configure configure.in dhcp-daemon.c dhcp-interface.c Log Message: fixed bug in dhcp-daemon when using daemon(); updated configure.in for more function checks; Index: config.h.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/config.h.in,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** config.h.in 2002/01/31 11:09:13 1.3 --- config.h.in 2002/02/02 11:55:08 1.4 *************** *** 7,10 **** --- 7,16 ---- #undef CLIENT_WORK_DIR + /* Define if you have the `calloc' function. */ + #undef HAVE_CALLOC + + /* Define if you have the `daemon' function. */ + #undef HAVE_DAEMON + /* Define if you have the <getopt.h> header file. */ #undef HAVE_GETOPT_H Index: configure =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** configure 2002/01/31 14:43:22 1.7 --- configure 2002/02/02 11:55:08 1.8 *************** *** 2378,2382 **** done ! for ac_func in strdup uname do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` --- 2378,2382 ---- done ! for ac_func in strdup uname calloc daemon do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` Index: configure.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.in,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** configure.in 2002/01/31 14:43:22 1.7 --- configure.in 2002/02/02 11:55:08 1.8 *************** *** 32,36 **** dnl check for functions ! AC_CHECK_FUNCS(strdup uname) AC_CHECK_FUNCS(sprintf vsnprintf, --- 32,36 ---- dnl check for functions ! AC_CHECK_FUNCS(strdup uname calloc daemon) AC_CHECK_FUNCS(sprintf vsnprintf, Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-daemon.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-daemon.c 2002/01/29 18:05:05 1.1.1.1 --- dhcp-daemon.c 2002/02/02 11:55:08 1.2 *************** *** 137,141 **** } ! /* * Step 4: chdir() in case --- 137,143 ---- } ! ! #endif ! /* * Step 4: chdir() in case *************** *** 144,150 **** * */ ! chdir(dir); - #endif /* We won't rely on daemon() to set --- 146,151 ---- * */ ! chdir(dir); /* We won't rely on daemon() to set Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-interface.c 2002/02/02 00:48:06 1.7 --- dhcp-interface.c 2002/02/02 11:55:08 1.8 *************** *** 107,111 **** info.intf_info |= INTF_INFO_MTU; ! info.intf_info |= INTF_INFO_FLAGS; info.intf_flags |= INTF_FLAG_UP; --- 107,111 ---- info.intf_info |= INTF_INFO_MTU; ! info.intf_info |= INTF_INFO_FLAGS; info.intf_flags |= INTF_FLAG_UP; |
From: Thamer Al-H. <act...@us...> - 2002-02-02 01:07:24
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv12510 Modified Files: dhcp-rtt.c Log Message: rtt mechanism now fully compliant with rfc; Index: dhcp-rtt.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-rtt.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-rtt.c 2002/01/30 10:25:56 1.2 --- dhcp-rtt.c 2002/02/02 01:07:20 1.3 *************** *** 54,64 **** { time_t milliseconds; milliseconds = SECS_TO_MSECS(rtt->timeout.tv_sec); milliseconds += rtt->timeout.tv_usec; milliseconds *= 2; ! rtt->timeout = make_timeval(milliseconds); return; } --- 54,75 ---- { time_t milliseconds; + int rand_value; milliseconds = SECS_TO_MSECS(rtt->timeout.tv_sec); milliseconds += rtt->timeout.tv_usec; milliseconds *= 2; + + rand_value = rand()%MILLISECOND_RAND_TIMEOUT; ! /* Add or subtract random small value. */ ! if(rand()%10 > 5) /* we're safe adding. */ ! milliseconds += rand()%MILLISECOND_RAND_TIMEOUT; ! else { /* we're not safe subtracting. don't go below 0. */ + if(rand_value < milliseconds) + milliseconds -= rand_value; + } + + rtt->timeout = make_timeval(milliseconds); return; } |
From: Thamer Al-H. <act...@us...> - 2002-02-02 00:48:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv8532 Modified Files: dhcp-agent.h dhcp-arp.c dhcp-client-states.c dhcp-client.c dhcp-interface.c dhcp-net.c Log Message: arp replies now generated after setup (working); rawnet_send now checks packet->len and returns error accordingly. Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-agent.h 2002/02/01 19:56:10 1.12 --- dhcp-agent.h 2002/02/02 00:48:06 1.13 *************** *** 660,664 **** extern void arp_set_hardware_len(arp_obj *arp, uint8_t len); extern void arp_set_protocol_len(arp_obj *arp, uint8_t len); ! extern void arp_set_op(arp_obj *arp, uint8_t op); extern void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr); extern void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr); --- 660,664 ---- extern void arp_set_hardware_len(arp_obj *arp, uint8_t len); extern void arp_set_protocol_len(arp_obj *arp, uint8_t len); ! extern void arp_set_op(arp_obj *arp, uint16_t op); extern void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr); extern void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr); Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-arp.c 2002/02/01 18:31:17 1.3 --- dhcp-arp.c 2002/02/02 00:48:06 1.4 *************** *** 63,69 **** } ! void arp_set_op(arp_obj *arp, uint8_t op) { ! arp->header.ar_op = op; return; } --- 63,69 ---- } ! void arp_set_op(arp_obj *arp, uint16_t op) { ! arp->header.ar_op = htons(op); return; } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client-states.c 2002/02/01 19:56:10 1.8 --- dhcp-client-states.c 2002/02/02 00:48:06 1.9 *************** *** 113,118 **** rawnet_build_arp_reply_broadcast(dc->rawnet, ip_addr, hw_addr); ! if(rawnet_send_packet(dc->rawnet)) ! error_message("warning: could not send arp reply: %s", strerror(errno)); return; --- 113,117 ---- rawnet_build_arp_reply_broadcast(dc->rawnet, ip_addr, hw_addr); ! rawnet_send_packet(dc->rawnet); return; *************** *** 318,326 **** rawnet_down(dc->rawnet); - info_message("waiting for renew."); alarm(dc->renewal_time); suspend_for_interrupts(); /* if we got a shutdown or HUP it will be caught later. */ if(have_alarm) { - info_message("renewing lease."); have_alarm = 0; } --- 317,323 ---- Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client.c 2002/01/31 14:43:22 1.7 --- dhcp-client.c 2002/02/02 00:48:06 1.8 *************** *** 33,37 **** info_message("shutting down."); client_release(dc); ! interface_down(dc->interface_control, dc->interface); delete_pid_file(dc->interface); --- 33,38 ---- info_message("shutting down."); client_release(dc); ! if(interface_down(dc->interface_control, dc->interface)) ! error_message("warning: could not bring interface down."); delete_pid_file(dc->interface); *************** *** 284,287 **** --- 285,293 ---- state = do_client_dhcp_loop(1, dc, state); + /* flush stdout to get messages out _now_ + * in case things break in forking into child. */ + fflush(stdout); + fflush(stderr); + /* Go in background now before main loop. */ if(want_background) { /* are we interactive? if so stay in foreground. */ Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-interface.c 2002/02/01 19:56:10 1.6 --- dhcp-interface.c 2002/02/02 00:48:06 1.7 *************** *** 97,101 **** } else ! info.intf_info &= ~(INTF_INFO_ADDR); /* Set mtu to default if not passed. */ --- 97,101 ---- } else ! info.intf_info &= ~INTF_INFO_ADDR; /* Set mtu to default if not passed. */ *************** *** 118,128 **** int interface_down(interface_control_t *ic, char *name) { ! struct intf_info info; ! if(interface_get_info(ic, name)) return -1; - - info.intf_flags &= ~(INTF_FLAG_UP); if(interface_set_info(ic, name)) return -1; --- 118,127 ---- int interface_down(interface_control_t *ic, char *name) { ! if(interface_get_info(ic, name)) return -1; + info.intf_flags &= ~INTF_FLAG_UP; + if(interface_set_info(ic, name)) return -1; *************** *** 140,141 **** --- 139,141 ---- return 0; } + Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-net.c 2002/02/01 19:56:10 1.7 --- dhcp-net.c 2002/02/02 00:48:06 1.8 *************** *** 393,397 **** int rawnet_send_packet(rawnet_t *net) { ! return(eth_send(net->eth, net->packet_data, net->packet_len)); } --- 393,400 ---- 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; } *************** *** 414,419 **** { ! arp_set_hardware_type(net->arp_p, DLT_EN10MB); ! arp_set_protocol_type(net->arp_p, ETH_TYPE_IP); arp_set_hardware_len(net->arp_p, ETH_ADDR_LEN); arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); --- 417,422 ---- { ! arp_set_hardware_type(net->arp_p, ARP_HRD_ETH); ! arp_set_protocol_type(net->arp_p, ARP_PRO_IP); arp_set_hardware_len(net->arp_p, ETH_ADDR_LEN); arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); *************** *** 615,619 **** * */ ! if(total_len > DEFAULT_MTU) fatal_error("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); --- 618,622 ---- * */ ! if(total_len > DEFAULT_MTU) fatal_error("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); *************** *** 645,649 **** net->type = RAWNET_ARP; ! net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN; rawnet_write_packet(net); --- 648,652 ---- net->type = RAWNET_ARP; ! net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN + ARP_HDR_LEN; rawnet_write_packet(net); |
From: Thamer Al-H. <act...@us...> - 2002-02-01 19:56:14
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv31489 Modified Files: dhcp-agent.h dhcp-client-control.c dhcp-client-states.c dhcp-interface.c dhcp-net.c Log Message: arp-reply send implemented in client_setup() it doesn't work though :-); Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-agent.h 2002/02/01 18:31:17 1.11 --- dhcp-agent.h 2002/02/01 19:56:10 1.12 *************** *** 457,461 **** extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); ! extern unsigned char *rawnet_get_interface_addr(rawnet_t *net); extern char *rawnet_strerror(rawnet_t *net); extern int rawnet_send_packet(rawnet_t *net); --- 457,461 ---- extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); ! extern int rawnet_get_interface_hw_addr(rawnet_t *net, eth_addr_t *addr); extern char *rawnet_strerror(rawnet_t *net); extern int rawnet_send_packet(rawnet_t *net); *************** *** 654,657 **** --- 654,659 ---- extern arp_obj *arp_create(void); extern void arp_destroy(arp_obj *arp); + extern void arp_write_packet_image(arp_obj *arp, unsigned char *packet); + extern void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr); extern void arp_set_protocol_type(arp_obj *arp, uint16_t pro); *************** *** 754,757 **** --- 756,760 ---- extern int interface_down(interface_control_t *ic, char *name); extern void destroy_interface_control(interface_control_t *ic); + extern int interface_get_ip_addr(interface_control_t *ic, char *name, uint32_t *addr); /* client states */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-control.c 2002/01/31 14:43:22 1.5 --- dhcp-client-control.c 2002/02/01 19:56:10 1.6 *************** *** 54,58 **** } ! static unsigned char *create_client_id(unsigned char *interface_address) { unsigned char *s; --- 54,58 ---- } ! static unsigned char *create_client_id(eth_addr_t interface_address) { unsigned char *s; *************** *** 61,65 **** *s = DLT_EN10MB; s++; ! memcpy(s, interface_address, ETH_ADDR_LEN); s--; --- 61,65 ---- *s = DLT_EN10MB; s++; ! memcpy(s, interface_address.data, ETH_ADDR_LEN); s--; *************** *** 72,76 **** int dport, sport; char filter_buff[GENERIC_BUFFSIZE]; ! unsigned char *interface_addr; #ifdef HAVE_UNAME --- 72,76 ---- int dport, sport; char filter_buff[GENERIC_BUFFSIZE]; ! eth_addr_t interface_addr; #ifdef HAVE_UNAME *************** *** 148,154 **** #endif /* HAVE_UNAME */ ! interface_addr = rawnet_get_interface_addr(dc->rawnet); dc->client_id = create_client_id(interface_addr); - xfree(interface_addr); return dc; --- 148,158 ---- #endif /* HAVE_UNAME */ ! if(rawnet_get_interface_hw_addr(dc->rawnet, &interface_addr)) { ! error_message("could not acquire interface address"); ! destroy_dhcp_client_control(dc); ! return NULL; ! } ! dc->client_id = create_client_id(interface_addr); return dc; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client-states.c 2002/02/01 18:31:17 1.7 --- dhcp-client-states.c 2002/02/01 19:56:10 1.8 *************** *** 97,101 **** static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { ! return; } --- 97,119 ---- static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { ! uint32_t ip_addr; ! eth_addr_t hw_addr; ! ! /* Get our IP address from rawnet. ! * We don't get it from the cache. ! * This is quicker, and since it should be ! * setup it's more correct. ! */ ! ! if(rawnet_get_interface_hw_addr(dc->rawnet, &hw_addr) || ! interface_get_ip_addr(dc->interface_control, dc->interface, &ip_addr)) { ! error_message("warning: could get get hardware and ip addresses to generate arp reply. this is bad, but i'll keep going."); ! return; ! } ! ! rawnet_build_arp_reply_broadcast(dc->rawnet, ip_addr, hw_addr); ! if(rawnet_send_packet(dc->rawnet)) ! error_message("warning: could not send arp reply: %s", strerror(errno)); ! return; } *************** *** 280,283 **** --- 298,303 ---- cache_entry_purge_list(options); + client_broadcast_arp_reply(dc); + return STATE_WAIT; } Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-interface.c 2002/02/01 18:31:17 1.5 --- dhcp-interface.c 2002/02/01 19:56:10 1.6 *************** *** 130,131 **** --- 130,141 ---- return 0; } + + int interface_get_ip_addr(interface_control_t *ic, char *name, uint32_t *addr) + { + if(interface_get_info(ic, name)) + return -1; + + memcpy(addr, &info.intf_addr.addr_ip, IP_ADDR_LEN); + + return 0; + } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-net.c 2002/02/01 18:31:17 1.6 --- dhcp-net.c 2002/02/01 19:56:10 1.7 *************** *** 110,126 **** } ! unsigned char *rawnet_get_interface_addr(rawnet_t *net) { ! char *addr; ! eth_addr_t eth_addr; ! ! addr = malloc(ETH_HDR_LEN); ! eth_get(net->eth, ð_addr); ! memcpy(addr, ð_addr.data, ETH_HDR_LEN); ! ! return addr; } - /* * Initialization of packet capturing device. --- 110,118 ---- } ! int rawnet_get_interface_hw_addr(rawnet_t *net, eth_addr_t *addr) { ! return(eth_get(net->eth, addr)); } /* * Initialization of packet capturing device. *************** *** 230,239 **** } ! void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string) { unsigned char *mac_addr; ! if(raw->client_hw_addr != NULL) ! xfree(raw->client_hw_addr); mac_addr = xmalloc(ETH_ADDR_LEN); --- 222,231 ---- } ! void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { unsigned char *mac_addr; ! if(net->client_hw_addr != NULL) ! xfree(net->client_hw_addr); mac_addr = xmalloc(ETH_ADDR_LEN); *************** *** 241,245 **** fatal_error("malformed mac_string for fake client hw addr. please check mac address."); ! raw->client_hw_addr = mac_addr; return; --- 233,237 ---- fatal_error("malformed mac_string for fake client hw addr. please check mac address."); ! net->client_hw_addr = mac_addr; return; *************** *** 414,423 **** * we need. */ ! static void build_arp_proc(rawnet_t *net, ! uint16_t opcode, ! eth_addr_t sender_hw_addr, ! uint32_t sender_ip_addr, ! eth_addr_t target_hw_addr, ! uint32_t target_ip_addr) { --- 406,415 ---- * we need. */ ! static void build_arp(rawnet_t *net, ! uint16_t opcode, ! eth_addr_t sender_hw_addr, ! uint32_t sender_ip_addr, ! eth_addr_t target_hw_addr, ! uint32_t target_ip_addr) { *************** *** 516,523 **** } ! static void rawnet_write_packet(rawnet_t *net, uint16_t ip_len) { char *packet_ptr; ! /* Dump packet images. */ --- 508,515 ---- } ! static void rawnet_write_packet_dhcp(rawnet_t *net) { char *packet_ptr; ! /* Dump packet images. */ *************** *** 538,544 **** /* Run the IP checksum routine. */ ! ip_checksum((net->packet_data + ETH_HDR_LEN), ip_len); } static void rawnet_build_dhcp_proc(rawnet_t *net, uint32_t xid, time_t secs, uint32_t ciaddr, uint32_t yiaddr, uint32_t siaddr, --- 530,577 ---- /* Run the IP checksum routine. */ ! ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); ! ! return; } + static void rawnet_write_packet_arp(rawnet_t *net) + { + char *packet_ptr; + + /* Dump packet images. */ + + packet_ptr = net->packet_data; + memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ + + eth_write_packet_image(net->ether_p, packet_ptr); + packet_ptr += ETH_HDR_LEN; + + arp_write_packet_image(net->arp_p, packet_ptr); + + return; + } + + static void rawnet_write_packet(rawnet_t *net) + { + + switch(net->type) { + + case RAWNET_DHCP: + rawnet_write_packet_dhcp(net); + break; + + case RAWNET_ARP: + rawnet_write_packet_arp(net); + break; + + default: + error_message("warning: invalid send type"); + break; + } + + return; + } + + static void rawnet_build_dhcp_proc(rawnet_t *net, uint32_t xid, time_t secs, uint32_t ciaddr, uint32_t yiaddr, uint32_t siaddr, *************** *** 596,604 **** net->packet_len = total_len; ! rawnet_write_packet(net, ip_len); return; } void rawnet_build_arp_reply(rawnet_t *net, --- 629,653 ---- net->packet_len = total_len; ! rawnet_write_packet(net); return; } + static void build_arp_proc(rawnet_t *net, + uint16_t opcode, + eth_addr_t sender_hw_addr, + uint32_t sender_ip_addr, + eth_addr_t target_hw_addr, + uint32_t target_ip_addr) + { + build_eth_broadcast(net, sender_hw_addr, ETH_TYPE_ARP); + build_arp(net, opcode, sender_hw_addr, sender_ip_addr, target_hw_addr, target_ip_addr); + + net->type = RAWNET_ARP; + net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN; + + rawnet_write_packet(net); + return; + } void rawnet_build_arp_reply(rawnet_t *net, |
From: Thamer Al-H. <act...@us...> - 2002-02-01 18:31:21
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv7929 Modified Files: CAVEATS Makefile.am Makefile.in dhcp-agent.h dhcp-arp.c dhcp-client-states.c dhcp-eth.c dhcp-interface.c dhcp-net.c dhcp-sysconf.c Log Message: added arp construction; cleaned up dhcp-interface.c; Index: CAVEATS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/CAVEATS,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** CAVEATS 2002/01/29 18:04:59 1.1.1.1 --- CAVEATS 2002/02/01 18:31:17 1.2 *************** *** 5,6 **** --- 5,9 ---- needs to be fixed. It currently does not overload bootp fields to make up for this. + + -- dhcpclient spoofing mac address may not work on all systems or + NICs. test to be sure. Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 2002/01/31 23:15:44 1.5 --- Makefile.am 2002/02/01 18:31:17 1.6 *************** *** 1,3 **** ! CFLAGS = -s -Wall -O2 AUTOMAKE_OPTIONS = gnu --- 1,3 ---- ! CFLAGS = -Wall -g AUTOMAKE_OPTIONS = gnu Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.in 2002/01/31 23:15:44 1.5 --- Makefile.in 2002/02/01 18:31:17 1.6 *************** *** 69,73 **** VERSION = @VERSION@ ! CFLAGS = -s -Wall -O2 AUTOMAKE_OPTIONS = foreign --- 69,73 ---- VERSION = @VERSION@ ! CFLAGS = -Wall -g AUTOMAKE_OPTIONS = foreign Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-agent.h 2002/01/31 23:15:44 1.10 --- dhcp-agent.h 2002/02/01 18:31:17 1.11 *************** *** 449,453 **** * * * * * * * * * * * */ ! /* Net/Socket routines. */ extern int port_for_service(const char *serv, const char *proto); --- 449,453 ---- * * * * * * * * * * * */ ! /* Net/Rawnet routines. */ extern int port_for_service(const char *serv, const char *proto); *************** *** 464,467 **** --- 464,475 ---- extern void rawnet_build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); extern void rawnet_build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); + extern void rawnet_build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, + eth_addr_t source_hw_addr); + extern void rawnet_build_arp_reply(rawnet_t *net, + uint32_t source_addr, + uint32_t dest_addr, + eth_addr_t source_hw_addr, + eth_addr_t dest_hw_addr); + extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); extern int rawnet_wait(rawnet_t *net, struct timeval tm); *************** *** 618,622 **** extern void eth_set_src_address(eth_obj *eth, eth_addr_t addr); extern void eth_set_dst_address(eth_obj *eth, eth_addr_t addr); - extern void eth_set_dst_address_broadcast(eth_obj *eth); extern void eth_set_type(eth_obj *eth, uint16_t type); --- 626,629 ---- *************** *** 647,658 **** extern arp_obj *arp_create(void); extern void arp_destroy(arp_obj *arp); ! extern void arp_set_format_hardware_addr(arp_obj *arp, uint16_t hdr_addr); ! extern void arp_set_format_protocol_address(arp_obj *arp, uint16_t pro); ! extern void arp_set_hw_len(arp_obj *arp, uint8_t len); extern void arp_set_op(arp_obj *arp, uint8_t op); ! extern void arp_set_sender_hardware_address(arp_obj *arp, unsigned char *addr); ! extern void arp_set_sender_protocol_address(arp_obj *arp, unsigned char *addr); ! extern void arp_set_target_hardware_address(arp_obj *arp, unsigned char *addr); ! extern void arp_set_target_protocol_address(arp_obj *arp, unsigned char *addr); /* UDP obj routines. */ --- 654,666 ---- extern arp_obj *arp_create(void); extern void arp_destroy(arp_obj *arp); ! extern void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr); ! extern void arp_set_protocol_type(arp_obj *arp, uint16_t pro); ! extern void arp_set_hardware_len(arp_obj *arp, uint8_t len); ! extern void arp_set_protocol_len(arp_obj *arp, uint8_t len); extern void arp_set_op(arp_obj *arp, uint8_t op); ! extern void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr); ! extern void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr); ! extern void arp_set_target_hardware_address(arp_obj *arp, eth_addr_t addr); ! extern void arp_set_target_protocol_address(arp_obj *arp, uint32_t addr); /* UDP obj routines. */ Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-arp.c 2002/01/31 23:15:44 1.2 --- dhcp-arp.c 2002/02/01 18:31:17 1.3 *************** *** 40,58 **** } ! void arp_set_format_hardware_addr(arp_obj *arp, uint16_t hdr_addr) { ! memcpy(&arp->header.ar_hrd, &hdr_addr, sizeof(uint16_t)); return; } ! void arp_set_format_protocol_address(arp_obj *arp, uint16_t pro) { ! memcpy(&arp->header.ar_pro, &pro, sizeof(uint16_t)); return; } ! void arp_set_hw_len(arp_obj *arp, uint8_t len) { ! memcpy(&arp->header.ar_pro, &len, sizeof(uint8_t)); return; } --- 40,63 ---- } ! void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr) { ! arp->header.ar_hrd = htons(hdr_addr); return; } ! void arp_set_protocol_type(arp_obj *arp, uint16_t pro) { ! arp->header.ar_pro = htons(pro); return; } ! void arp_set_hardware_len(arp_obj *arp, uint8_t len) { ! arp->header.ar_hln = len; ! return; ! } ! void arp_set_protocol_len(arp_obj *arp, uint8_t len) ! { ! arp->header.ar_pln = len; return; } *************** *** 60,88 **** void arp_set_op(arp_obj *arp, uint8_t op) { ! memcpy(&arp->header.ar_op, &op, sizeof(uint8_t)); return; } ! void arp_set_sender_hardware_address(arp_obj *arp, unsigned char *addr) { ! memcpy(&arp->arp_data.ar_sha, addr, ETH_ADDR_LEN); return; } ! void arp_set_sender_protocol_address(arp_obj *arp, unsigned char *addr) { ! memcpy(&arp->arp_data.ar_spa, addr, IP_ADDR_LEN); return; } ! void arp_set_target_hardware_address(arp_obj *arp, unsigned char *addr) { ! memcpy(&arp->arp_data.ar_tha, addr, ETH_ADDR_LEN); return; } ! void arp_set_target_protocol_address(arp_obj *arp, unsigned char *addr) { ! memcpy(&arp->arp_data.ar_tpa, addr, IP_ADDR_LEN); return; } --- 65,125 ---- void arp_set_op(arp_obj *arp, uint8_t op) { ! arp->header.ar_op = op; return; } ! void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr) { ! memcpy(&arp->arp_data.ar_sha, &addr.data, ETH_ADDR_LEN); return; } ! void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr) { ! memcpy(&arp->arp_data.ar_spa, &addr, IP_ADDR_LEN); return; } ! void arp_set_target_hardware_address(arp_obj *arp, eth_addr_t addr) { ! memcpy(&arp->arp_data.ar_tha, &addr.data, ETH_ADDR_LEN); return; } ! void arp_set_target_protocol_address(arp_obj *arp, uint32_t addr) { ! memcpy(&arp->arp_data.ar_tpa, &addr, IP_ADDR_LEN); return; } + + void arp_write_packet_image(arp_obj *arp, unsigned char *packet) + { + memcpy(packet, &arp->header.ar_hrd, sizeof(arp->header.ar_hrd)); + packet += sizeof(arp->header.ar_hrd); + + memcpy(packet, &arp->header.ar_pro, sizeof(arp->header.ar_pro)); + packet += sizeof(arp->header.ar_pro); + + memcpy(packet, &arp->header.ar_hln, sizeof(arp->header.ar_hln)); + packet += sizeof(arp->header.ar_hln); + + memcpy(packet, &arp->header.ar_pln, sizeof(arp->header.ar_pln)); + packet += sizeof(arp->header.ar_pln); + + memcpy(packet, &arp->header.ar_op, sizeof(arp->header.ar_op)); + packet += sizeof(arp->header.ar_op); + + memcpy(packet, &arp->arp_data.ar_sha, sizeof(arp->arp_data.ar_sha)); + packet += sizeof(arp->arp_data.ar_sha); + + memcpy(packet, &arp->arp_data.ar_spa, sizeof(arp->arp_data.ar_spa)); + packet += sizeof(arp->arp_data.ar_spa); + + memcpy(packet, &arp->arp_data.ar_tha, sizeof(arp->arp_data.ar_tha)); + packet += sizeof(arp->arp_data.ar_tha); + + memcpy(packet, &arp->arp_data.ar_tpa, sizeof(arp->arp_data.ar_tpa)); + + return; + } + Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client-states.c 2002/01/31 12:37:24 1.6 --- dhcp-client-states.c 2002/02/01 18:31:17 1.7 *************** *** 88,91 **** --- 88,104 ---- } + /* + * Use this to send out a broadcast reply claiming that we own the + * IP. To prevent a poisoned cache we use the actual interface hw + * addr as opposed to any fake one we may have been passed. + * + */ + + static void client_broadcast_arp_reply(dhcp_client_control_t *dc) + { + + return; + } + /* Send and wait for reply. */ Index: dhcp-eth.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-eth.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-eth.c 2002/01/30 16:06:46 1.2 --- dhcp-eth.c 2002/02/01 18:31:17 1.3 *************** *** 63,72 **** } - void eth_set_dst_address_broadcast(eth_obj *eth) - { - memcpy(ð->header.eth_dst.data, ETH_ADDR_BROADCAST, ETH_ADDR_LEN); - return; - } - void eth_set_dst_address(eth_obj *eth, eth_addr_t addr) { --- 63,66 ---- Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-interface.c 2002/01/31 23:15:44 1.4 --- dhcp-interface.c 2002/02/01 18:31:17 1.5 *************** *** 26,29 **** --- 26,53 ---- #include <dhcp-agent.h> + static struct intf_info info; + + /* Internal utilities */ + + static int interface_get_info(interface_control_t *ic, char *name) + { + if(intf_get(ic, name, &info) < 0) { + error_message("could not lookup interface %s : %d", name, strerror(errno)); + return -1; + } + + return 0; + } + + static int interface_set_info(interface_control_t *ic, char *name) + { + if(intf_set(ic, name, &info) < 0) { + error_message("could not lookup interface %s : %d", name, strerror(errno)); + return -1; + } + + return 0; + } + /* Initialize interface handle. */ *************** *** 48,57 **** int interface_is_up(interface_control_t *ic, char *name) { ! struct intf_info info; ! ! if(intf_get(ic, name, &info) < 0) { ! error_message("could not acquire interface %s", name); ! return -1; ! } return(info.intf_flags&INTF_FLAG_UP); --- 72,78 ---- int interface_is_up(interface_control_t *ic, char *name) { ! ! if(interface_get_info(ic, name)) ! return 0; return(info.intf_flags&INTF_FLAG_UP); *************** *** 63,83 **** int mtu) { ! struct intf_info info; ! ! if(intf_get(ic, name, &info) < 0) { ! error_message("could not lookup interface %s : %d", name, strerror(errno)); return -1; - } /* Set address if needed. */ if(addr != INADDR_ANY) { info.intf_addr.addr_type = ADDR_TYPE_IP; - info.intf_addr.addr_bits = 0; addr_mtob(&netmask, IP_ADDR_LEN, &info.intf_addr.addr_bits); ! memcpy(&info.intf_addr.addr_ip, &addr, 4); info.intf_info |= INTF_INFO_ADDR; ! } ! /* Set mtu to default if not passed. */ --- 84,102 ---- int mtu) { ! if(interface_get_info(ic, name)) return -1; /* Set address if needed. */ if(addr != INADDR_ANY) { + info.intf_addr.addr_type = ADDR_TYPE_IP; addr_mtob(&netmask, IP_ADDR_LEN, &info.intf_addr.addr_bits); ! memcpy(&info.intf_addr.addr_ip, &addr, IP_ADDR_LEN); info.intf_info |= INTF_INFO_ADDR; ! ! } else ! info.intf_info &= ~(INTF_INFO_ADDR); ! /* Set mtu to default if not passed. */ *************** *** 91,98 **** info.intf_flags |= INTF_FLAG_UP; ! if(intf_set(ic, name, &info) < 0) { ! error_message("could not bring interface up %s : %s", name, strerror(errno)); return -1; - } return 0; --- 110,115 ---- info.intf_flags |= INTF_FLAG_UP; ! if(interface_set_info(ic, name)) return -1; return 0; *************** *** 102,117 **** { struct intf_info info; ! ! if(intf_get(ic, name, &info) < 0) { ! error_message("could not lookup interface %s : %d", name, strerror(errno)); return -1; - } ! info.intf_flags &= ~(INTF_FLAG_UP&info.intf_flags); ! if(intf_set(ic, name, &info) < 0) { ! error_message("could not lookup interface %s : %d", name, strerror(errno)); return -1; - } return 0; --- 119,130 ---- { struct intf_info info; ! ! if(interface_get_info(ic, name)) return -1; ! info.intf_flags &= ~(INTF_FLAG_UP); ! if(interface_set_info(ic, name)) return -1; return 0; Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-net.c 2002/01/31 14:43:22 1.5 --- dhcp-net.c 2002/02/01 18:31:17 1.6 *************** *** 63,66 **** --- 63,71 ---- #include <dhcp-agent.h> + /* constants we need. */ + + static const eth_addr_t eth_broadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; + static const uint32_t ip_addr_broadcast = 0xffffffff; + /* Get port number for named service. */ *************** *** 409,417 **** * we need. */ static void build_eth_broadcast(rawnet_t *net, eth_addr_t client_hw_addr, uint16_t type) { ! eth_set_dst_address_broadcast(net->ether_p); eth_set_src_address(net->ether_p, client_hw_addr); eth_set_type(net->ether_p, type); --- 414,444 ---- * we need. */ + static void build_arp_proc(rawnet_t *net, + uint16_t opcode, + eth_addr_t sender_hw_addr, + uint32_t sender_ip_addr, + eth_addr_t target_hw_addr, + uint32_t target_ip_addr) + { + + arp_set_hardware_type(net->arp_p, DLT_EN10MB); + arp_set_protocol_type(net->arp_p, ETH_TYPE_IP); + arp_set_hardware_len(net->arp_p, ETH_ADDR_LEN); + arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); + arp_set_op(net->arp_p, opcode); + arp_set_sender_hardware_address(net->arp_p, sender_hw_addr); + arp_set_sender_protocol_address(net->arp_p, sender_ip_addr); + arp_set_target_hardware_address(net->arp_p, target_hw_addr); + arp_set_target_protocol_address(net->arp_p, target_ip_addr); + + return; + } + static void build_eth_broadcast(rawnet_t *net, eth_addr_t client_hw_addr, uint16_t type) + { ! eth_set_dst_address(net->ether_p, eth_broadcast); eth_set_src_address(net->ether_p, client_hw_addr); eth_set_type(net->ether_p, type); *************** *** 433,437 **** ip_set_source_addr(net->ip_p, 0); ! ip_set_dest_addr(net->ip_p, 0xffffffff); return; --- 460,464 ---- ip_set_source_addr(net->ip_p, 0); ! ip_set_dest_addr(net->ip_p, ip_addr_broadcast); return; *************** *** 571,574 **** --- 598,620 ---- rawnet_write_packet(net, ip_len); + return; + } + + + void rawnet_build_arp_reply(rawnet_t *net, + uint32_t source_addr, + uint32_t dest_addr, + eth_addr_t source_hw_addr, + eth_addr_t dest_hw_addr) + { + build_arp_proc(net, ARP_OP_REPLY, source_hw_addr, source_addr, dest_hw_addr, dest_addr); + return; + } + + void rawnet_build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) + { + + rawnet_build_arp_reply(net, source_addr, ip_addr_broadcast, + source_hw_addr, eth_broadcast); return; } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-sysconf.c 2002/01/30 16:06:46 1.3 --- dhcp-sysconf.c 2002/02/01 18:31:17 1.4 *************** *** 226,230 **** if(interface_up(dc->interface_control, dc->interface, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); ! return; } --- 226,230 ---- if(interface_up(dc->interface_control, dc->interface, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); ! return; } |
From: Thamer Al-H. <act...@us...> - 2002-02-01 00:42:07
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv18625 Modified Files: README THANKS Log Message: Dug Song now spelled right; sorry; Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** README 2002/02/01 00:22:08 1.3 --- README 2002/02/01 00:42:03 1.4 *************** *** 35,39 **** http://www.tcpdump.org/ ! You will also need Dug Sung's libdnet (0.8 or above). http://libdnet.sourceforge.net/ --- 35,39 ---- http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (0.8 or above). http://libdnet.sourceforge.net/ Index: THANKS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/THANKS,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** THANKS 2002/01/29 18:05:00 1.1.1.1 --- THANKS 2002/02/01 00:42:03 1.2 *************** *** 9,13 **** http://www.fiction.net/blong/programs/snprintf.c ! -- Dug Sung, and the others behind libdnet. -- The Tcpdump Group for their work on libpcap --- 9,13 ---- http://www.fiction.net/blong/programs/snprintf.c ! -- Dug Song, and the others behind libdnet. -- The Tcpdump Group for their work on libpcap |
From: Thamer Al-H. <act...@us...> - 2002-02-01 00:22:12
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv12381 Modified Files: README Log Message: removed do_sysconf is lame note in README ; this is actually a syncmail test ; Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** README 2002/02/01 00:18:04 1.2 --- README 2002/02/01 00:22:08 1.3 *************** *** 14,23 **** appreciated. ! The current code base suffers from some overengineering (see hoop ! jumping in do_sysconf()), but it works. Next release will clean this ! up. ! ! Only the desperate and depraved would run the client on a production ! machine. Portability and Caveats --- 14,19 ---- appreciated. ! Please know that, only the desperate and depraved would run the ! client on a production machine. Portability and Caveats |