diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-02-24 15:35:57 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-02-24 15:35:57 +0000 |
commit | e0fc228d8ac39bc46d67758d7b3c5f5118b0ac72 (patch) | |
tree | 48b02841dd2e25845491c6858f9f5602ea16ea17 /sbin | |
parent | ea26b49e284e86d20f3eb27abe36aa989001b534 (diff) |
get rid of tons of structs we never use, a lot of new_someotherjunk functions
in alloc.c we never call, and a shitload of genius comments like
char *script_name; /* name of script */
char *server_name; /* name of server */
etc etc etc...
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/alloc.c | 168 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 8 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 429 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 22 | ||||
-rw-r--r-- | sbin/dhclient/print.c | 30 |
5 files changed, 98 insertions, 559 deletions
diff --git a/sbin/dhclient/alloc.c b/sbin/dhclient/alloc.c index 3f5b70aa63d..b75c4d25800 100644 --- a/sbin/dhclient/alloc.c +++ b/sbin/dhclient/alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc.c,v 1.4 2004/02/07 11:35:59 henning Exp $ */ +/* $OpenBSD: alloc.c,v 1.5 2004/02/24 15:35:55 henning Exp $ */ /* Memory allocation... */ @@ -65,24 +65,6 @@ dfree(void *ptr, char *name) free(ptr); } -struct packet * -new_packet(char *name) -{ - struct packet *rval; - - rval = dmalloc(sizeof(struct packet), name); - return (rval); -} - -struct dhcp_packet * -new_dhcp_packet(char *name) -{ - struct dhcp_packet *rval; - - rval = dmalloc(sizeof(struct dhcp_packet), name); - return (rval); -} - struct tree * new_tree(char *name) { @@ -142,154 +124,6 @@ new_hash_bucket(char *name) return (rval); } -struct lease * -new_leases(int n, char *name) -{ - struct lease *rval = dmalloc(n * sizeof(struct lease), name); - - return (rval); -} - -struct lease * -new_lease(char *name) -{ - struct lease *rval = dmalloc(sizeof(struct lease), name); - - return (rval); -} - -struct subnet * -new_subnet(char *name) -{ - struct subnet *rval = dmalloc(sizeof(struct subnet), name); - - return (rval); -} - -struct class * -new_class(char *name) -{ - struct class *rval = dmalloc(sizeof(struct class), name); - - return (rval); -} - -struct shared_network * -new_shared_network(char *name) -{ - struct shared_network *rval = - dmalloc(sizeof(struct shared_network), name); - - return (rval); -} - -struct group * -new_group(char *name) -{ - struct group *rval = dmalloc(sizeof(struct group), name); - - return (rval); -} - -struct protocol * -new_protocol(char *name) -{ - struct protocol *rval = dmalloc(sizeof(struct protocol), name); - - return (rval); -} - -struct lease_state *free_lease_states; - -struct lease_state * -new_lease_state(char *name) -{ - struct lease_state *rval; - - if (free_lease_states) { - rval = free_lease_states; - free_lease_states = - (struct lease_state *)(free_lease_states->next); - } else - rval = dmalloc(sizeof(struct lease_state), name); - return (rval); -} - -struct domain_search_list * -new_domain_search_list(char *name) -{ - struct domain_search_list *rval = - dmalloc(sizeof(struct domain_search_list), name); - - return (rval); -} - -struct name_server * -new_name_server(char *name) -{ - struct name_server *rval = - dmalloc(sizeof(struct name_server), name); - - return (rval); -} - -void -free_name_server(struct name_server *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_domain_search_list(struct domain_search_list *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_lease_state(struct lease_state *ptr, char *name) -{ - if (ptr->prl) - dfree(ptr->prl, name); - ptr->next = free_lease_states; - free_lease_states = ptr; -} - -void -free_protocol(struct protocol *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_group(struct group *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_shared_network(struct shared_network *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_class(struct class *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_subnet(struct subnet *ptr, char *name) -{ - dfree(ptr, name); -} - -void -free_lease(struct lease *ptr, char *name) -{ - dfree(ptr, name); -} - void free_hash_bucket(struct hash_bucket *ptr, char *name) { diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 8eb07f4cb52..96502b1c4ca 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.18 2004/02/24 14:49:08 henning Exp $ */ +/* $OpenBSD: dhclient.c,v 1.19 2004/02/24 15:35:56 henning Exp $ */ /* DHCP Client. */ @@ -666,12 +666,6 @@ commit_leases(void) return (0); } -int -write_lease(struct lease *lease) -{ - return (0); -} - void db_startup(void) { diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 1e0da1ad656..c5fd460241d 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,8 +1,7 @@ -/* $OpenBSD: dhcpd.h,v 1.15 2004/02/24 14:49:08 henning Exp $ */ - -/* Definitions for dhcpd... */ +/* $OpenBSD: dhcpd.h,v 1.16 2004/02/24 15:35:56 henning Exp $ */ /* + * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 1995, 1996, 1997, 1998, 1999 * The Internet Software Consortium. All rights reserved. * @@ -82,45 +81,26 @@ #define REMOTE_PORT 67 struct option_data { - int len; - u_int8_t *data; + int len; + u_int8_t *data; }; struct string_list { - struct string_list *next; - char *string; -}; - -/* A name server, from /etc/resolv.conf. */ -struct name_server { - struct name_server *next; - struct sockaddr_in addr; - time_t rcdate; -}; - -/* A domain search list element. */ -struct domain_search_list { - struct domain_search_list *next; - char *domain; - time_t rcdate; + struct string_list *next; + char *string; }; -/* A dhcp packet and the pointers to its option values. */ struct packet { - struct dhcp_packet *raw; - int packet_length; - int packet_type; - int options_valid; - int client_port; - struct iaddr client_addr; - struct interface_info *interface; /* Interface on which packet - was received. */ - struct hardware *haddr; /* Physical link address - of local sender (maybe gateway). */ - struct shared_network *shared_network; - struct option_data options[256]; - int got_requested_address; /* True if client sent the - dhcp-requested-address option. */ + struct dhcp_packet *raw; + int packet_length; + int packet_type; + int options_valid; + int client_port; + struct iaddr client_addr; + struct interface_info *interface; + struct hardware *haddr; + struct option_data options[256]; + int got_requested_address; }; struct hardware { @@ -129,161 +109,16 @@ struct hardware { u_int8_t haddr[16]; }; -/* A dhcp lease declaration structure. */ -struct lease { - struct lease *next; - struct lease *prev; - struct lease *n_uid, *n_hw; - struct lease *waitq_next; - - struct iaddr ip_addr; - time_t starts, ends, timestamp; - unsigned char *uid; - int uid_len; - int uid_max; - unsigned char uid_buf[32]; - char *hostname; - char *client_hostname; - struct host_decl *host; - struct subnet *subnet; - struct shared_network *shared_network; - struct hardware hardware_addr; - - int flags; -# define STATIC_LEASE 1 -# define BOOTP_LEASE 2 -# define DYNAMIC_BOOTP_OK 4 -# define PERSISTENT_FLAGS (DYNAMIC_BOOTP_OK) -# define EPHEMERAL_FLAGS (BOOTP_LEASE) -# define MS_NULL_TERMINATION 8 -# define ABANDONED_LEASE 16 - - struct lease_state *state; - u_int8_t releasing; -}; - -struct lease_state { - struct lease_state *next; - - struct interface_info *ip; - - time_t offered_expiry; - - struct tree_cache *options[256]; - u_int32_t expiry, renewal, rebind; - char filename[DHCP_FILE_LEN]; - char *server_name; - - struct iaddr from; - - int max_message_size; - u_int8_t *prl; - int prl_len; - int got_requested_address; /* True if client sent the - dhcp-requested-address option. */ - int got_server_identifier; /* True if client sent the - dhcp-server-identifier option. */ - struct shared_network *shared_network; /* Shared network of interface - on which request arrived. */ - - u_int32_t xid; - u_int16_t secs; - u_int16_t bootp_flags; - struct in_addr ciaddr; - struct in_addr giaddr; - u_int8_t hops; - u_int8_t offer; -}; - -#define ROOT_GROUP 0 -#define HOST_DECL 1 -#define SHARED_NET_DECL 2 -#define SUBNET_DECL 3 -#define CLASS_DECL 4 -#define GROUP_DECL 5 - -/* Group of declarations that share common parameters. */ -struct group { - struct group *next; - - struct subnet *subnet; - struct shared_network *shared_network; - - time_t default_lease_time; - time_t max_lease_time; - time_t bootp_lease_cutoff; - time_t bootp_lease_length; - - char *filename; - char *server_name; - struct iaddr next_server; - - int boot_unknown_clients; - int dynamic_bootp; - int allow_bootp; - int allow_booting; - int one_lease_per_client; - int get_lease_hostnames; - int use_host_decl_names; - int use_lease_addr_for_default_route; - int authoritative; - int always_reply_rfc1048; - - struct tree_cache *options[256]; -}; - -/* A dhcp host declaration structure. */ -struct host_decl { - struct host_decl *n_ipaddr; - char *name; - struct hardware interface; - struct tree_cache *fixed_addr; - struct group *group; -}; - -struct shared_network { - struct shared_network *next; - char *name; - struct subnet *subnets; - struct interface_info *interface; - struct lease *leases; - struct lease *insertion_point; - struct lease *last_lease; - - struct group *group; -}; - -struct subnet { - struct subnet *next_subnet; - struct subnet *next_sibling; - struct shared_network *shared_network; - struct interface_info *interface; - struct iaddr interface_address; - struct iaddr net; - struct iaddr netmask; - - struct group *group; -}; - -struct class { - char *name; - - struct group *group; -}; - -/* DHCP client lease structure... */ struct client_lease { - struct client_lease *next; /* Next lease in list. */ - time_t expiry, renewal, rebind; /* Lease timeouts. */ - struct iaddr address; /* Address being leased. */ - char *server_name; /* Name of boot server. */ - char *filename; /* Name of file we're supposed to boot. */ - struct string_list *medium; /* Network medium. */ - - unsigned int is_static : 1; /* If set, lease is from config file. */ - unsigned int is_bootp : 1; /* If set, lease was aquired with BOOTP. */ - - struct option_data options[256]; /* Options supplied with lease. */ + struct client_lease *next; + time_t expiry, renewal, rebind; + struct iaddr address; + char *server_name; + char *filename; + struct string_list *medium; + unsigned int is_static : 1; + unsigned int is_bootp : 1; + struct option_data options[256]; }; /* Possible states in which the client can be. */ @@ -297,156 +132,103 @@ enum dhcp_state { S_REBINDING }; -/* Configuration information from the config file... */ struct client_config { - struct option_data defaults[256]; /* Default values for options. */ + struct option_data defaults[256]; enum { - ACTION_DEFAULT, /* Use server value if present, - otherwise default. */ - ACTION_SUPERSEDE, /* Always use default. */ - ACTION_PREPEND, /* Prepend default to server. */ - ACTION_APPEND /* Append default to server. */ + ACTION_DEFAULT, + ACTION_SUPERSEDE, + ACTION_PREPEND, + ACTION_APPEND } default_actions[256]; - struct option_data send_options[256]; /* Send these to server. */ - u_int8_t required_options[256]; /* Options server must supply. */ - u_int8_t requested_options[256]; /* Options to request from server. */ - int requested_option_count; /* Number of requested options. */ - time_t timeout; /* Start to panic if we don't get a - lease in this time period when - SELECTING. */ - time_t initial_interval; /* All exponential backoff intervals - start here. */ - time_t retry_interval; /* If the protocol failed to produce - an address before the timeout, - try the protocol again after this - many seconds. */ - time_t select_interval; /* Wait this many seconds from the - first DHCPDISCOVER before - picking an offered lease. */ - time_t reboot_timeout; /* When in INIT-REBOOT, wait this - long before giving up and going - to INIT. */ - time_t backoff_cutoff; /* When doing exponential backoff, - never back off to an interval - longer than this amount. */ - struct string_list *media; /* Possible network media values. */ - char *script_name; /* Name of config script. */ - enum { IGNORE, ACCEPT, PREFER } bootp_policy; - /* Ignore, accept or prefer BOOTP - responses. */ - struct string_list *medium; /* Current network medium. */ - - struct iaddrlist *reject_list; /* Servers to reject. */ + struct option_data send_options[256]; + u_int8_t required_options[256]; + u_int8_t requested_options[256]; + int requested_option_count; + time_t timeout; + time_t initial_interval; + time_t retry_interval; + time_t select_interval; + time_t reboot_timeout; + time_t backoff_cutoff; + struct string_list *media; + char *script_name; + enum { IGNORE, ACCEPT, PREFER } + bootp_policy; + struct string_list *medium; + struct iaddrlist *reject_list; }; -/* Per-interface state used in the dhcp client... */ struct client_state { - struct client_lease *active; /* Currently active lease. */ - struct client_lease *new; /* New lease. */ - struct client_lease *offered_leases; /* Leases offered to us. */ - struct client_lease *leases; /* Leases we currently hold. */ - struct client_lease *alias; /* Alias lease. */ - - enum dhcp_state state; /* Current state for this interface. */ - struct iaddr destination; /* Where to send packet. */ - u_int32_t xid; /* Transaction ID. */ - u_int16_t secs; /* secs value from DHCPDISCOVER. */ - time_t first_sending; /* When was first copy sent? */ - time_t interval; /* What's the current resend interval? */ - struct string_list *medium; /* Last media type tried. */ - - struct dhcp_packet packet; /* Outgoing DHCP packet. */ - int packet_length; /* Actual length of generated packet. */ - - struct iaddr requested_address; /* Address we would like to get. */ - - struct client_config *config; /* Information from config file. */ - - char **scriptEnv; /* Client script env */ - int scriptEnvsize; /* size of the env table */ - - struct string_list *env; /* Client script environment. */ - int envc; /* Number of entries in environment. */ + struct client_lease *active; + struct client_lease *new; + struct client_lease *offered_leases; + struct client_lease *leases; + struct client_lease *alias; + enum dhcp_state state; + struct iaddr destination; + u_int32_t xid; + u_int16_t secs; + time_t first_sending; + time_t interval; + struct string_list *medium; + struct dhcp_packet packet; + int packet_length; + struct iaddr requested_address; + struct client_config *config; + char **scriptEnv; + int scriptEnvsize; + struct string_list *env; + int envc; }; -/* Information about each network interface. */ - struct interface_info { - struct interface_info *next; /* Next interface in list... */ - struct shared_network *shared_network; - /* Networks connected to this interface. */ - struct hardware hw_address; /* Its physical address. */ - struct in_addr primary_address; /* Primary interface address. */ - char name[IFNAMSIZ]; /* Its name... */ - int rfdesc; /* Its read file descriptor. */ - int wfdesc; /* Its write file descriptor, if - different. */ - unsigned char *rbuf; /* Read buffer, if required. */ - size_t rbuf_max; /* Size of read buffer. */ - size_t rbuf_offset; /* Current offset into buffer. */ - size_t rbuf_len; /* Length of data in buffer. */ - - struct ifreq *ifp; /* Pointer to ifreq struct. */ - u_int32_t flags; /* Control flags... */ + struct interface_info *next; + struct hardware hw_address; + struct in_addr primary_address; + char name[IFNAMSIZ]; + int rfdesc; + int wfdesc; + unsigned char *rbuf; + size_t rbuf_max; + size_t rbuf_offset; + size_t rbuf_len; + struct ifreq *ifp; + u_int32_t flags; #define INTERFACE_REQUESTED 1 #define INTERFACE_AUTOMATIC 2 - - /* Only used by DHCP client code. */ - struct client_state *client; - int noifmedia; - int errors; - int dead; - u_int16_t index; -}; - -struct hardware_link { - struct hardware_link *next; - char name[IFNAMSIZ]; - struct hardware address; + struct client_state *client; + int noifmedia; + int errors; + int dead; + u_int16_t index; }; struct timeout { - struct timeout *next; - time_t when; - void (*func)(void *); - void *what; + struct timeout *next; + time_t when; + void (*func)(void *); + void *what; }; struct protocol { - struct protocol *next; + struct protocol *next; int fd; void (*handler)(struct protocol *); void *local; }; -/* Bitmask of dhcp option codes. */ -typedef unsigned char option_mask[16]; - -/* DHCP Option mask manipulation macros... */ -#define OPTION_ZERO(mask) (memset(mask, 0, 16)) -#define OPTION_SET(mask, bit) (mask[bit >> 8] |= (1 << (bit & 7))) -#define OPTION_CLR(mask, bit) (mask[bit >> 8] &= ~(1 << (bit & 7))) -#define OPTION_ISSET(mask, bit) (mask[bit >> 8] & (1 << (bit & 7))) -#define OPTION_ISCLR(mask, bit) (!OPTION_ISSET(mask, bit)) - -/* An option occupies its length plus two header bytes (code and - length) for every 255 bytes that must be stored. */ -#define OPTION_SPACE(x) ((x) + 2 * ((x) / 255 + 1)) - /* Default path to dhcpd config file. */ -#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" -#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" -#define _PATH_RESOLV_CONF "/etc/resolv.conf" -#define DHCPD_LOG_FACILITY LOG_DAEMON +#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" +#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" +#define DHCPD_LOG_FACILITY LOG_DAEMON -#define MAX_TIME 0x7fffffff -#define MIN_TIME 0 +#define MAX_TIME 0x7fffffff +#define MIN_TIME 0 /* External definitions... */ /* options.c */ - void parse_options(struct packet *); void parse_option_buffer(struct packet *, unsigned char *, int); int cons_options(struct packet *, struct dhcp_packet *, int, @@ -502,43 +284,19 @@ int tree_evaluate(struct tree_cache *); /* alloc.c */ void *dmalloc(int, char *); void dfree(void *, char *); -struct packet *new_packet(char *); -struct dhcp_packet *new_dhcp_packet(char *); struct tree *new_tree(char *); struct tree_cache *new_tree_cache(char *); struct hash_table *new_hash_table(int, char *); struct hash_bucket *new_hash_bucket(char *); -struct lease *new_lease(char *); -struct lease *new_leases(int, char *); -struct subnet *new_subnet(char *); -struct class *new_class(char *); -struct shared_network *new_shared_network(char *); -struct group *new_group(char *); -struct protocol *new_protocol(char *); -struct lease_state *new_lease_state(char *); -struct domain_search_list *new_domain_search_list(char *); -struct name_server *new_name_server(char *); struct string_list *new_string_list(size_t size, char * name); -void free_name_server(struct name_server *, char *); -void free_domain_search_list(struct domain_search_list *, char *); -void free_lease_state(struct lease_state *, char *); -void free_protocol(struct protocol *, char *); -void free_group(struct group *, char *); -void free_shared_network(struct shared_network *, char *); -void free_class(struct class *, char *); -void free_subnet(struct subnet *, char *); -void free_lease(struct lease *, char *); void free_hash_bucket(struct hash_bucket *, char *); void free_hash_table(struct hash_table *, char *); void free_tree_cache(struct tree_cache *, char *); -void free_packet(struct packet *, char *); -void free_dhcp_packet(struct dhcp_packet *, char *); void free_tree(struct tree *, char *); void free_string_list(struct string_list *, char *); /* print.c */ char *print_hw_addr(int, int, unsigned char *); -void print_lease(struct lease *); void dump_raw(unsigned char *, int); void dump_packet(struct packet *); void hash_dump(struct hash_table *); @@ -567,7 +325,6 @@ extern void (*bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); extern struct timeout *timeouts; void discover_interfaces(void); -struct interface_info *setup_fallback(void); void reinitialize_interfaces(void); void dispatch(void); void got_one(struct protocol *); diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 37cb233a8ed..f360fd0201d 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,8 +1,9 @@ -/* $OpenBSD: dispatch.c,v 1.13 2004/02/24 14:49:08 henning Exp $ */ +/* $OpenBSD: dispatch.c,v 1.14 2004/02/24 15:35:56 henning Exp $ */ /* Network input dispatcher... */ /* + * Copyright 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 1995, 1996, 1997, 1998, 1999 * The Internet Software Consortium. All rights reserved. * @@ -179,25 +180,6 @@ discover_interfaces(void) freeifaddrs(ifap); } -struct interface_info * -setup_fallback(void) -{ - fallback_interface = - dmalloc(sizeof(*fallback_interface), "discover_interfaces"); - if (!fallback_interface) - error("Insufficient memory to record fallback interface."); - memset(fallback_interface, 0, sizeof(*fallback_interface)); - strlcpy(fallback_interface->name, "fallback", IFNAMSIZ); - fallback_interface->shared_network = - new_shared_network("parse_statement"); - if (!fallback_interface->shared_network) - error("No memory for shared subnet"); - memset(fallback_interface->shared_network, 0, - sizeof(struct shared_network)); - fallback_interface->shared_network->name = "fallback-net"; - return (fallback_interface); -} - void reinitialize_interfaces(void) { diff --git a/sbin/dhclient/print.c b/sbin/dhclient/print.c index 065225b06c1..d8a47e8cabf 100644 --- a/sbin/dhclient/print.c +++ b/sbin/dhclient/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.4 2004/02/07 13:59:45 henning Exp $ */ +/* $OpenBSD: print.c,v 1.5 2004/02/24 15:35:56 henning Exp $ */ /* Turn data structures into printable text. */ @@ -74,34 +74,6 @@ bad: } void -print_lease(struct lease *lease) -{ - struct tm *t; - char tbuf[32]; - - debug(" Lease %s", piaddr(lease->ip_addr)); - - t = gmtime(&lease->starts); - strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", t); - debug(" start %s", tbuf); - - t = gmtime(&lease->ends); - strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", t); - debug(" end %s", tbuf); - - t = gmtime(&lease->timestamp); - strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", t); - debug(" stamp %s", tbuf); - - debug(" hardware addr = %s", print_hw_addr( - lease->hardware_addr.htype, - lease->hardware_addr.hlen, - lease->hardware_addr.haddr)); - debug(" host %s ", - lease->host ? lease->host->name : "<none>"); -} - -void dump_packet(struct packet *tp) { struct dhcp_packet *tdp = tp->raw; |