diff options
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/Makefile | 6 | ||||
-rw-r--r-- | sbin/dhclient/alloc.c | 242 | ||||
-rw-r--r-- | sbin/dhclient/bpf.c | 294 | ||||
-rw-r--r-- | sbin/dhclient/cdefs.h | 57 | ||||
-rw-r--r-- | sbin/dhclient/clparse.c | 945 | ||||
-rw-r--r-- | sbin/dhclient/conflex.c | 569 | ||||
-rw-r--r-- | sbin/dhclient/convert.c | 81 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 1395 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 794 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 348 | ||||
-rw-r--r-- | sbin/dhclient/errwarn.c | 164 | ||||
-rw-r--r-- | sbin/dhclient/ethernet.c | 44 | ||||
-rw-r--r-- | sbin/dhclient/hash.c | 96 | ||||
-rw-r--r-- | sbin/dhclient/icmp.c | 55 | ||||
-rw-r--r-- | sbin/dhclient/inet.c | 53 | ||||
-rw-r--r-- | sbin/dhclient/openbsd.h | 96 | ||||
-rw-r--r-- | sbin/dhclient/osdep.h | 84 | ||||
-rw-r--r-- | sbin/dhclient/site.h | 100 | ||||
-rw-r--r-- | sbin/dhclient/tree.c | 11 |
19 files changed, 2398 insertions, 3036 deletions
diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile index 640b419c820..6ecf774527e 100644 --- a/sbin/dhclient/Makefile +++ b/sbin/dhclient/Makefile @@ -32,10 +32,6 @@ .include <bsd.own.mk> -CLIENT_PATH = '"PATH=/usr/bin:/usr/sbin:/bin:/sbin"' -CPPFLAGS+= -I${.CURDIR}/.. -I${.CURDIR}/../includes \ - -DCLIENT_PATH=${CLIENT_PATH} -Wall - SRCS= dhclient.c clparse.c \ alloc.c dispatch.c hash.c memory.c print.c bpf.c icmp.c options.c \ tree.c conflex.c errwarn.c inet.c packet.c socket.c convert.c \ @@ -44,6 +40,8 @@ SRCS= dhclient.c clparse.c \ PROG= dhclient MAN= dhclient.8 dhclient.conf.5 dhclient.leases.5 dhclient-script.8 +CFLAGS+=-Wall + beforeinstall: ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ ${.CURDIR}/dhclient-script ${DESTDIR}/sbin/dhclient-script diff --git a/sbin/dhclient/alloc.c b/sbin/dhclient/alloc.c index ad976a33d25..7f747a3ab19 100644 --- a/sbin/dhclient/alloc.c +++ b/sbin/dhclient/alloc.c @@ -45,74 +45,74 @@ struct dhcp_packet *dhcp_free_list; struct packet *packet_free_list; -void * dmalloc(size, name) - int size; - char *name; +void * +dmalloc(int size, char *name) { void *foo = calloc(size, sizeof(char)); + if (!foo) - warn ("No memory for %s.", name); + warn("No memory for %s.", name); return foo; } -void dfree(ptr, name) - void *ptr; - char *name; +void +dfree(void *ptr, char *name) { if (!ptr) { - warn ("dfree %s: free on null pointer.", name); + warn("dfree %s: free on null pointer.", name); return; } - free (ptr); + free(ptr); } -struct packet *new_packet(name) - char *name; +struct packet * +new_packet(char *name) { struct packet *rval; + rval = (struct packet *)dmalloc(sizeof(struct packet), name); return rval; } -struct dhcp_packet *new_dhcp_packet(name) - char *name; +struct dhcp_packet * +new_dhcp_packet(char *name) { struct dhcp_packet *rval; + rval = (struct dhcp_packet *)dmalloc(sizeof(struct dhcp_packet), - name); + name); return rval; } -struct tree *new_tree(name) - char *name; +struct tree * +new_tree(char *name) { struct tree *rval = dmalloc(sizeof(struct tree), name); + return rval; } -struct string_list *new_string_list(size, name) - size_t size; - char * name; +struct string_list * +new_string_list(size_t size, char * name) { struct string_list *rval; - rval =dmalloc(sizeof(struct string_list) + size, name); - if (rval != NULL) + rval = dmalloc(sizeof(struct string_list) + size, name); + if (rval != NULL) rval->string = ((char *)rval) + sizeof(struct string_list); return rval; } struct tree_cache *free_tree_caches; -struct tree_cache *new_tree_cache(name) - char *name; +struct tree_cache * +new_tree_cache(char *name) { struct tree_cache *rval; if (free_tree_caches) { rval = free_tree_caches; - free_tree_caches = - (struct tree_cache *)(rval->value); + free_tree_caches = (struct tree_cache *)(rval->value); } else { rval = dmalloc(sizeof(struct tree_cache), name); if (!rval) @@ -121,224 +121,216 @@ struct tree_cache *new_tree_cache(name) return rval; } -struct hash_table *new_hash_table(count, name) - int count; - char *name; +struct hash_table * +new_hash_table(int count, char *name) { struct hash_table *rval; - rval = dmalloc(sizeof (struct hash_table) - - (DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)) - + (count * sizeof(struct hash_bucket *)), name); + + rval = dmalloc(sizeof (struct hash_table) - + (DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)) + + (count * sizeof(struct hash_bucket *)), name); if (rval == NULL) return NULL; rval->hash_count = count; return rval; } -struct hash_bucket *new_hash_bucket(name) - char *name; +struct hash_bucket * +new_hash_bucket(char *name) { struct hash_bucket *rval = dmalloc(sizeof(struct hash_bucket), name); + return rval; } -struct lease *new_leases(n, name) - int n; - char *name; +struct lease * +new_leases(int n, char *name) { struct lease *rval = dmalloc(n * sizeof(struct lease), name); + return rval; } -struct lease *new_lease(name) - char *name; +struct lease * +new_lease(char *name) { struct lease *rval = dmalloc(sizeof(struct lease), name); + return rval; } -struct subnet *new_subnet(name) - char *name; +struct subnet * +new_subnet(char *name) { struct subnet *rval = dmalloc(sizeof(struct subnet), name); + return rval; } -struct class *new_class(name) - char *name; +struct class * +new_class(char *name) { struct class *rval = dmalloc(sizeof(struct class), name); + return rval; } -struct shared_network *new_shared_network(name) - char *name; +struct shared_network * +new_shared_network(char *name) { struct shared_network *rval = - dmalloc (sizeof(struct shared_network), name); + dmalloc(sizeof(struct shared_network), name); + return rval; } -struct group *new_group(name) - char *name; +struct group * +new_group(char *name) { struct group *rval = - dmalloc(sizeof(struct group), name); + dmalloc(sizeof(struct group), name); + return rval; } -struct protocol *new_protocol(name) - char *name; +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 (name) - char *name; +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); - } + (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 (name) - char *name; +struct domain_search_list * +new_domain_search_list(char *name) { struct domain_search_list *rval = - dmalloc (sizeof (struct domain_search_list), name); + dmalloc(sizeof (struct domain_search_list), name); + return rval; } -struct name_server *new_name_server (name) - char *name; +struct name_server * +new_name_server(char *name) { struct name_server *rval = - dmalloc (sizeof (struct name_server), name); + dmalloc(sizeof (struct name_server), name); + return rval; } -void free_name_server (ptr, name) - struct name_server *ptr; - char *name; +void +free_name_server(struct name_server *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_domain_search_list (ptr, name) - struct domain_search_list *ptr; - char *name; +void +free_domain_search_list(struct domain_search_list *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_lease_state (ptr, name) - struct lease_state *ptr; - char *name; +void +free_lease_state(struct lease_state *ptr, char *name) { if (ptr->prl) - dfree (ptr->prl, name); + dfree(ptr->prl, name); ptr->next = free_lease_states; free_lease_states = ptr; } -void free_protocol (ptr, name) - struct protocol *ptr; - char *name; +void +free_protocol(struct protocol *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_group (ptr, name) - struct group *ptr; - char *name; +void +free_group(struct group *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_shared_network (ptr, name) - struct shared_network *ptr; - char *name; +void +free_shared_network(struct shared_network *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_class (ptr, name) - struct class *ptr; - char *name; +void +free_class(struct class *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_subnet (ptr, name) - struct subnet *ptr; - char *name; +void +free_subnet(struct subnet *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_lease (ptr, name) - struct lease *ptr; - char *name; +void +free_lease(struct lease *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_hash_bucket (ptr, name) - struct hash_bucket *ptr; - char *name; +void +free_hash_bucket(struct hash_bucket *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_hash_table (ptr, name) - struct hash_table *ptr; - char *name; +void +free_hash_table(struct hash_table *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_tree_cache (ptr, name) - struct tree_cache *ptr; - char *name; +void +free_tree_cache(struct tree_cache *ptr, char *name) { ptr->value = (unsigned char *)free_tree_caches; free_tree_caches = ptr; } -void free_packet (ptr, name) - struct packet *ptr; - char *name; +void +free_packet(struct packet *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_dhcp_packet (ptr, name) - struct dhcp_packet *ptr; - char *name; +void +free_dhcp_packet(struct dhcp_packet *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_tree (ptr, name) - struct tree *ptr; - char *name; +void +free_tree(struct tree *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } -void free_string_list (ptr, name) - struct string_list *ptr; - char *name; +void +free_string_list(struct string_list *ptr, char *name) { - dfree (ptr, name); + dfree(ptr, name); } diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index ae377c41436..5d82f2fbbe7 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -53,13 +53,13 @@ /* Reinitializes the specified interface after an address change. This is not required for packet-filter APIs. */ -void if_reinitialize_send (info) - struct interface_info *info; +void +if_reinitialize_send(struct interface_info *info) { } -void if_reinitialize_receive (info) - struct interface_info *info; +void +if_reinitialize_receive(struct interface_info *info) { } @@ -67,58 +67,56 @@ void if_reinitialize_receive (info) Opens a packet filter for each interface and adds it to the select mask. */ -int if_register_bpf (info) - struct interface_info *info; +int +if_register_bpf(struct interface_info *info) { - int sock; - char filename[50]; - int b; + int sock, b; + char filename[50]; /* Open a BPF device */ for (b = 0; 1; b++) { snprintf(filename, sizeof(filename), BPF_FORMAT, b); - sock = open (filename, O_RDWR, 0); + sock = open(filename, O_RDWR, 0); if (sock < 0) { - if (errno == EBUSY) { + if (errno == EBUSY) continue; - } else { + else { if (!b) - error ("No bpf devices.%s%s%s", - " Please read the README", - " section for your operating", - " system."); - error ("Can't find free bpf: %m"); + error("No bpf devices.%s%s%s", + " Please read the README", + " section for your operating", + " system."); + error("Can't find free bpf: %m"); } - } else { + } else break; - } } /* Set the BPF device to point at this interface. */ - if (ioctl (sock, BIOCSETIF, info -> ifp) < 0) - error ("Can't attach interface %s to bpf device %s: %m", - info -> name, filename); + if (ioctl(sock, BIOCSETIF, info->ifp) < 0) + error("Can't attach interface %s to bpf device %s: %m", + info->name, filename); - return sock; + return (sock); } -void if_register_send (info) - struct interface_info *info; +void +if_register_send(struct interface_info *info) { /* If we're using the bpf API for sending and receiving, we don't need to register this interface twice. */ - info -> wfdesc = info -> rfdesc; + info->wfdesc = info->rfdesc; if (!quiet_interface_discovery) - note ("Sending on BPF/%s/%s%s%s", - info -> name, - print_hw_addr (info -> hw_address.htype, - info -> hw_address.hlen, - info -> hw_address.haddr), - (info -> shared_network ? "/" : ""), - (info -> shared_network ? - info -> shared_network -> name : "")); + note("Sending on BPF/%s/%s%s%s", + info->name, + print_hw_addr(info->hw_address.htype, + info->hw_address.hlen, + info->hw_address.haddr), + (info->shared_network ? "/" : ""), + (info->shared_network ? + info->shared_network->name : "")); } /* Packet filter program... @@ -127,23 +125,23 @@ void if_register_send (info) struct bpf_insn dhcp_bpf_filter [] = { /* Make sure this is an IP packet... */ - BPF_STMT (BPF_LD + BPF_H + BPF_ABS, 12), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), + BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), /* Make sure it's a UDP packet... */ - BPF_STMT (BPF_LD + BPF_B + BPF_ABS, 23), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6), + BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6), /* Make sure this isn't a fragment... */ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20), BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0), /* Get the IP header length... */ - BPF_STMT (BPF_LDX + BPF_B + BPF_MSH, 14), + BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14), /* Make sure it's to the right port... */ - BPF_STMT (BPF_LD + BPF_H + BPF_IND, 16), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1), /* patch */ + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1), /* patch */ /* If we passed all the tests, ask for the whole packet. */ BPF_STMT(BPF_RET+BPF_K, (u_int)-1), @@ -152,7 +150,7 @@ struct bpf_insn dhcp_bpf_filter [] = { BPF_STMT(BPF_RET+BPF_K, 0), }; -int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn); +int dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(struct bpf_insn); struct bpf_insn dhcp_bpf_tr_filter [] = { /* accept all token ring packets due to variable length header */ @@ -165,43 +163,43 @@ struct bpf_insn dhcp_bpf_tr_filter [] = { BPF_STMT(BPF_RET+BPF_K, 0), }; -int dhcp_bpf_tr_filter_len = (sizeof dhcp_bpf_tr_filter / - sizeof (struct bpf_insn)); +int dhcp_bpf_tr_filter_len = + (sizeof(dhcp_bpf_tr_filter) / sizeof(struct bpf_insn)); -void if_register_receive (info) - struct interface_info *info; +void +if_register_receive(struct interface_info *info) { - int flag = 1, sz; - struct bpf_version v; - struct bpf_program p; + int flag = 1, sz; + struct bpf_version v; + struct bpf_program p; /* Open a BPF device and hang it on this interface... */ - info -> rfdesc = if_register_bpf (info); + info->rfdesc = if_register_bpf(info); /* Make sure the BPF version is in range... */ - if (ioctl (info -> rfdesc, BIOCVERSION, &v) < 0) - error ("Can't get BPF version: %m"); + if (ioctl(info->rfdesc, BIOCVERSION, &v) < 0) + error("Can't get BPF version: %m"); if (v.bv_major != BPF_MAJOR_VERSION || v.bv_minor < BPF_MINOR_VERSION) - error ("Kernel BPF version out of range - recompile dhcpd!"); + error("Kernel BPF version out of range - recompile dhcpd!"); /* Set immediate mode so that reads return as soon as a packet comes in, rather than waiting for the input buffer to fill with packets. */ - if (ioctl (info -> rfdesc, BIOCIMMEDIATE, &flag) < 0) - error ("Can't set immediate mode on bpf device: %m"); + if (ioctl(info->rfdesc, BIOCIMMEDIATE, &flag) < 0) + error("Can't set immediate mode on bpf device: %m"); /* Get the required BPF buffer length from the kernel. */ - if (ioctl (info -> rfdesc, BIOCGBLEN, &sz) < 0) - error ("Can't get bpf buffer length: %m"); + if (ioctl(info->rfdesc, BIOCGBLEN, &sz) < 0) + error("Can't get bpf buffer length: %m"); info->rbuf_max = sz; - info -> rbuf = malloc (info -> rbuf_max); - if (!info -> rbuf) - error ("Can't allocate %lu bytes for bpf input buffer.", - (unsigned long) info -> rbuf_max); - info -> rbuf_offset = 0; - info -> rbuf_len = 0; + info->rbuf = malloc(info->rbuf_max); + if (!info->rbuf) + error("Can't allocate %lu bytes for bpf input buffer.", + (unsigned long)info->rbuf_max); + info->rbuf_offset = 0; + info->rbuf_len = 0; /* Set up the bpf filter program structure. */ p.bf_len = dhcp_bpf_filter_len; @@ -210,106 +208,96 @@ void if_register_receive (info) /* Patch the server port into the BPF program... XXX changes to filter program may require changes to the insn number(s) used below! XXX */ - dhcp_bpf_filter [8].k = ntohs (local_port); + dhcp_bpf_filter[8].k = ntohs(local_port); - if (ioctl (info -> rfdesc, BIOCSETF, &p) < 0) - error ("Can't install packet filter program: %m"); + if (ioctl(info->rfdesc, BIOCSETF, &p) < 0) + error("Can't install packet filter program: %m"); if (!quiet_interface_discovery) - note ("Listening on BPF/%s/%s%s%s", - info -> name, - print_hw_addr (info -> hw_address.htype, - info -> hw_address.hlen, - info -> hw_address.haddr), - (info -> shared_network ? "/" : ""), - (info -> shared_network ? - info -> shared_network -> name : "")); + note("Listening on BPF/%s/%s%s%s", + info->name, + print_hw_addr(info->hw_address.htype, + info->hw_address.hlen, + info->hw_address.haddr), + (info->shared_network ? "/" : ""), + (info->shared_network ? + info->shared_network->name : "")); } -ssize_t send_packet (interface, packet, raw, len, from, to, hto) - struct interface_info *interface; - struct packet *packet; - struct dhcp_packet *raw; - size_t len; - struct in_addr from; - struct sockaddr_in *to; - struct hardware *hto; +ssize_t +send_packet(struct interface_info *interface, struct packet *packet, + struct dhcp_packet *raw, size_t len, struct in_addr from, + struct sockaddr_in *to, struct hardware *hto) { - int bufp = 0; - unsigned char buf [256]; - struct iovec iov [2]; - int result; + int bufp = 0; + unsigned char buf[256]; + struct iovec iov[2]; + int result; - if (!strcmp (interface -> name, "fallback")) - return send_fallback (interface, packet, raw, - len, from, to, hto); + if (!strcmp(interface->name, "fallback")) + return (send_fallback(interface, packet, raw, + len, from, to, hto)); /* Assemble the headers... */ - assemble_hw_header (interface, buf, &bufp, hto); - assemble_udp_ip_header (interface, buf, &bufp, from.s_addr, - to -> sin_addr.s_addr, to -> sin_port, - (unsigned char *)raw, len); + assemble_hw_header(interface, buf, &bufp, hto); + assemble_udp_ip_header(interface, buf, &bufp, from.s_addr, + to->sin_addr.s_addr, to->sin_port, (unsigned char *)raw, len); /* Fire it off */ - iov [0].iov_base = (char *)buf; - iov [0].iov_len = bufp; - iov [1].iov_base = (char *)raw; - iov [1].iov_len = len; + iov[0].iov_base = (char *)buf; + iov[0].iov_len = bufp; + iov[1].iov_base = (char *)raw; + iov[1].iov_len = len; - result = writev(interface -> wfdesc, iov, 2); + result = writev(interface->wfdesc, iov, 2); if (result < 0) - warn ("send_packet: %m"); + warn("send_packet: %m"); return result; } -ssize_t receive_packet (interface, buf, len, from, hfrom) - struct interface_info *interface; - unsigned char *buf; - size_t len; - struct sockaddr_in *from; - struct hardware *hfrom; +ssize_t +receive_packet(struct interface_info *interface, unsigned char *buf, + size_t len, struct sockaddr_in *from, struct hardware *hfrom) { - int length = 0; - int offset = 0; - struct bpf_hdr hdr; + int length = 0; + int offset = 0; + struct bpf_hdr hdr; /* All this complexity is because BPF doesn't guarantee that only one packet will be returned at a time. We're getting what we deserve, though - this is a terrible abuse - of the BPF interface. Sigh. */ + of the BPF interface. Sigh. */ /* Process packets until we get one we can return or until we've done a read and gotten nothing we can return... */ do { /* If the buffer is empty, fill it. */ - if (interface -> rbuf_offset == interface -> rbuf_len) { - length = read (interface -> rfdesc, - interface -> rbuf, - interface -> rbuf_max); + if (interface->rbuf_offset == interface->rbuf_len) { + length = read(interface->rfdesc, interface->rbuf, + interface->rbuf_max); if (length <= 0) - return length; - interface -> rbuf_offset = 0; - interface -> rbuf_len = length; + return (length); + interface->rbuf_offset = 0; + interface->rbuf_len = length; } /* If there isn't room for a whole bpf header, something went wrong, but we'll ignore it and hope it goes away... XXX */ - if (interface -> rbuf_len - - interface -> rbuf_offset < sizeof hdr) { - interface -> rbuf_offset = interface -> rbuf_len; + if (interface->rbuf_len - interface->rbuf_offset < sizeof hdr) { + interface->rbuf_offset = interface->rbuf_len; continue; } /* Copy out a bpf header... */ - memcpy (&hdr, &interface -> rbuf [interface -> rbuf_offset], - sizeof hdr); + memcpy(&hdr, &interface->rbuf [interface->rbuf_offset], + sizeof(hdr)); /* If the bpf header plus data doesn't fit in what's left of the buffer, stick head in sand yet again... */ - if (interface -> rbuf_offset + - hdr.bh_hdrlen + hdr.bh_caplen > interface -> rbuf_len) { - interface -> rbuf_offset = interface -> rbuf_len; + if (interface->rbuf_offset + hdr.bh_hdrlen + hdr.bh_caplen > + interface->rbuf_len) { + interface->rbuf_offset = interface->rbuf_len; continue; } @@ -317,81 +305,77 @@ ssize_t receive_packet (interface, buf, len, from, hfrom) the packet won't fit in the input buffer, all we can do is drop it. */ if (hdr.bh_caplen != hdr.bh_datalen) { - interface -> rbuf_offset += - hdr.bh_hdrlen = hdr.bh_caplen; + interface->rbuf_offset += hdr.bh_hdrlen = hdr.bh_caplen; continue; } /* Skip over the BPF header... */ - interface -> rbuf_offset += hdr.bh_hdrlen; + interface->rbuf_offset += hdr.bh_hdrlen; /* Decode the physical header... */ offset = decode_hw_header (interface, - interface -> rbuf, - interface -> rbuf_offset, - hfrom); + interface->rbuf, interface->rbuf_offset, hfrom); /* If a physical layer checksum failed (dunno of any physical layer that supports this, but WTH), skip this packet. */ if (offset < 0) { - interface -> rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset += hdr.bh_caplen; continue; } - interface -> rbuf_offset += offset; + interface->rbuf_offset += offset; hdr.bh_caplen -= offset; /* Decode the IP and UDP headers... */ - offset = decode_udp_ip_header (interface, - interface -> rbuf, - interface -> rbuf_offset, - from, - (unsigned char *)0, - hdr.bh_caplen); + offset = decode_udp_ip_header (interface, interface->rbuf, + interface->rbuf_offset, from, NULL, hdr.bh_caplen); /* If the IP or UDP checksum was bad, skip the packet... */ if (offset < 0) { - interface -> rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset += hdr.bh_caplen; continue; } - interface -> rbuf_offset += offset; + interface->rbuf_offset += offset; hdr.bh_caplen -= offset; /* If there's not enough room to stash the packet data, we have to skip it (this shouldn't happen in real life, though). */ if (hdr.bh_caplen > len) { - interface -> rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset += hdr.bh_caplen; continue; } /* Copy out the data in the packet... */ - memcpy (buf, interface -> rbuf + interface -> rbuf_offset, + memcpy(buf, interface->rbuf + interface->rbuf_offset, hdr.bh_caplen); - interface -> rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset += hdr.bh_caplen; return hdr.bh_caplen; } while (!length); - return 0; + return (0); } -int can_unicast_without_arp () +int +can_unicast_without_arp(void) { - return 1; + return (1); } -int can_receive_unicast_unconfigured (ip) - struct interface_info *ip; +int +can_receive_unicast_unconfigured(struct interface_info *ip) { - return 1; + return (1); } -void maybe_setup_fallback () +void +maybe_setup_fallback(void) { - struct interface_info *fbi; - fbi = setup_fallback (); + struct interface_info *fbi; + + fbi = setup_fallback(); if (fbi) { - if_register_fallback (fbi); - add_protocol ("fallback", fallback_interface -> wfdesc, - fallback_discard, fallback_interface); + if_register_fallback(fbi); + add_protocol("fallback", fallback_interface->wfdesc, + fallback_discard, fallback_interface); } } diff --git a/sbin/dhclient/cdefs.h b/sbin/dhclient/cdefs.h deleted file mode 100644 index 2bc67a5251a..00000000000 --- a/sbin/dhclient/cdefs.h +++ /dev/null @@ -1,57 +0,0 @@ -/* cdefs.h - - Standard C definitions... */ - -/* - * Copyright (c) 1996 The Internet Software Consortium. - * All Rights Reserved. - * Copyright (c) 1995 RadioMail Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of RadioMail Corporation, the Internet Software - * Consortium nor the names of its contributors may be used to endorse - * or promote products derived from this software without specific - * prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY RADIOMAIL CORPORATION, THE INTERNET - * SOFTWARE CONSORTIUM AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL RADIOMAIL CORPORATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * This software was written for RadioMail Corporation by Ted Lemon - * under a contract with Vixie Enterprises. Further modifications have - * been made for the Internet Software Consortium under a contract - * with Vixie Laboratories. - */ - -#if (defined (__GNUC__) || defined (__STDC__)) && !defined (BROKEN_ANSI) -#define PROTO(x) x -#define KandR(x) -#define ANSI_DECL(x) x -#if defined (__GNUC__) -#define INLINE inline -#else -#define INLINE -#endif /* __GNUC__ */ -#else -#define PROTO(x) () -#define KandR(x) x -#define ANSI_DECL(x) -#define INLINE -#endif /* __GNUC__ || __STDC__ */ diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index bdce34d7814..13dde3f89bb 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -45,28 +45,29 @@ struct client_config top_level_config; -char client_script_name [] = "/sbin/dhclient-script"; +char client_script_name[] = "/sbin/dhclient-script"; /* client-conf-file :== client-declarations EOF client-declarations :== <nil> | client-declaration | client-declarations client-declaration */ -int read_client_conf () +int +read_client_conf(void) { - FILE *cfile; - char *val; - int token; - struct client_config *config; - struct interface_info *ip; + FILE *cfile; + char *val; + int token; + struct client_config *config; + struct interface_info *ip; - new_parse (path_dhclient_conf); + new_parse(path_dhclient_conf); /* Set up the initial dhcp option universe. */ - initialize_universes (); + initialize_universes(); /* Initialize the top level client configuration. */ - memset (&top_level_config, 0, sizeof top_level_config); + memset(&top_level_config, 0, sizeof top_level_config); /* Set some defaults... */ top_level_config.timeout = 60; @@ -78,93 +79,84 @@ int read_client_conf () top_level_config.bootp_policy = ACCEPT; top_level_config.script_name = client_script_name; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_SUBNET_MASK; + [top_level_config.requested_option_count++] = DHO_SUBNET_MASK; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_BROADCAST_ADDRESS; + [top_level_config.requested_option_count++] = DHO_BROADCAST_ADDRESS; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_TIME_OFFSET; + [top_level_config.requested_option_count++] = DHO_TIME_OFFSET; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_ROUTERS; + [top_level_config.requested_option_count++] = DHO_ROUTERS; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_DOMAIN_NAME; + [top_level_config.requested_option_count++] = DHO_DOMAIN_NAME; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_DOMAIN_NAME_SERVERS; + [top_level_config.requested_option_count++] = + DHO_DOMAIN_NAME_SERVERS; top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_HOST_NAME; + [top_level_config.requested_option_count++] = DHO_HOST_NAME; - if ((cfile = fopen (path_dhclient_conf, "r")) != NULL) { + if ((cfile = fopen(path_dhclient_conf, "r")) != NULL) { do { - token = peek_token (&val, cfile); + token = peek_token(&val, cfile); if (token == EOF) break; - parse_client_statement (cfile, - (struct interface_info *)0, - &top_level_config); + parse_client_statement(cfile, NULL, &top_level_config); } while (1); - token = next_token (&val, cfile); /* Clear the peek buffer */ - fclose (cfile); + token = next_token(&val, cfile); /* Clear the peek buffer */ + fclose(cfile); } /* Set up state and config structures for clients that don't have per-interface configuration declarations. */ - config = (struct client_config *)0; - for (ip = interfaces; ip; ip = ip -> next) { - if (!ip -> client) { - ip -> client = (struct client_state *) - malloc (sizeof (struct client_state)); - if (!ip -> client) - error ("no memory for client state."); - memset (ip -> client, 0, sizeof *(ip -> client)); + config = NULL; + for (ip = interfaces; ip; ip = ip->next) { + if (!ip->client) { + ip->client = malloc(sizeof(struct client_state)); + if (!ip->client) + error("no memory for client state."); + memset(ip->client, 0, sizeof *(ip->client)); } - if (!ip -> client -> config) { + if (!ip->client->config) { if (!config) { - config = (struct client_config *) - malloc (sizeof (struct client_config)); + config = malloc(sizeof(struct client_config)); if (!config) - error ("no memory for client config."); - memcpy (config, &top_level_config, - sizeof top_level_config); + error("no memory for client config."); + memcpy(config, &top_level_config, + sizeof(top_level_config)); } - ip -> client -> config = config; + ip->client->config = config; } } - return !warnings_occurred; + return (!warnings_occurred); } /* lease-file :== client-lease-statements EOF client-lease-statements :== <nil> | client-lease-statements LEASE client-lease-statement */ -void read_client_leases () +void +read_client_leases(void) { - FILE *cfile; - char *val; - int token; + FILE *cfile; + char *val; + int token; - new_parse (path_dhclient_db); + new_parse(path_dhclient_db); /* Open the lease file. If we can't open it, just return - we can safely trust the server to remember our state. */ - if ((cfile = fopen (path_dhclient_db, "r")) == NULL) + if ((cfile = fopen(path_dhclient_db, "r")) == NULL) return; do { - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token == EOF) break; if (token != LEASE) { - warn ("Corrupt lease file - possible data loss!"); - skip_to_semi (cfile); + warn("Corrupt lease file - possible data loss!"); + skip_to_semi(cfile); break; } else - parse_client_lease_statement (cfile, 0); + parse_client_lease_statement(cfile, 0); } while (1); } @@ -187,328 +179,292 @@ void read_client_leases () LEASE client-lease-statement | ALIAS client-lease-statement */ -void parse_client_statement (cfile, ip, config) - FILE *cfile; - struct interface_info *ip; - struct client_config *config; +void +parse_client_statement(FILE *cfile, struct interface_info *ip, + struct client_config *config) { - int token; - char *val; - struct option *option; + int token; + char *val; + struct option *option; - switch (next_token (&val, cfile)) { - case SEND: - parse_option_decl (cfile, &config -> send_options [0]); + switch (next_token(&val, cfile)) { + case SEND: + parse_option_decl(cfile, &config->send_options[0]); return; - - case DEFAULT: - option = parse_option_decl (cfile, &config -> defaults [0]); + case DEFAULT: + option = parse_option_decl(cfile, &config->defaults[0]); if (option) - config -> default_actions [option -> code] = - ACTION_DEFAULT; + config->default_actions[option->code] = ACTION_DEFAULT; return; - - case SUPERSEDE: - option = parse_option_decl (cfile, &config -> defaults [0]); + case SUPERSEDE: + option = parse_option_decl(cfile, &config->defaults[0]); if (option) - config -> default_actions [option -> code] = - ACTION_SUPERSEDE; + config->default_actions[option->code] = + ACTION_SUPERSEDE; return; - - case APPEND: - option = parse_option_decl (cfile, &config -> defaults [0]); + case APPEND: + option = parse_option_decl(cfile, &config->defaults[0]); if (option) - config -> default_actions [option -> code] = - ACTION_APPEND; + config->default_actions[option->code] = ACTION_APPEND; return; - - case PREPEND: - option = parse_option_decl (cfile, &config -> defaults [0]); + case PREPEND: + option = parse_option_decl(cfile, &config->defaults[0]); if (option) - config -> default_actions [option -> code] = - ACTION_PREPEND; + config->default_actions[option->code] = ACTION_PREPEND; return; - case MEDIA: - parse_string_list (cfile, &config -> media, 1); + case MEDIA: + parse_string_list(cfile, &config->media, 1); return; - - case HARDWARE: - if (ip) { - parse_hardware_param (cfile, &ip -> hw_address); - } else { - parse_warn ("hardware address parameter %s", + case HARDWARE: + if (ip) + parse_hardware_param(cfile, &ip->hw_address); + else { + parse_warn("hardware address parameter %s", "not allowed here."); - skip_to_semi (cfile); + skip_to_semi(cfile); } return; - - case REQUEST: - config -> requested_option_count = - parse_option_list (cfile, config -> requested_options); + case REQUEST: + config->requested_option_count = + parse_option_list(cfile, config->requested_options); return; - - case REQUIRE: - memset (config -> required_options, 0, - sizeof config -> required_options); - parse_option_list (cfile, config -> required_options); + case REQUIRE: + memset(config->required_options, 0, + sizeof(config->required_options)); + parse_option_list(cfile, config->required_options); return; - - case TIMEOUT: - parse_lease_time (cfile, &config -> timeout); + case TIMEOUT: + parse_lease_time(cfile, &config->timeout); return; - - case RETRY: - parse_lease_time (cfile, &config -> retry_interval); + case RETRY: + parse_lease_time(cfile, &config->retry_interval); return; - - case SELECT_TIMEOUT: - parse_lease_time (cfile, &config -> select_interval); + case SELECT_TIMEOUT: + parse_lease_time(cfile, &config->select_interval); return; - - case REBOOT: - parse_lease_time (cfile, &config -> reboot_timeout); + case REBOOT: + parse_lease_time(cfile, &config->reboot_timeout); return; - - case BACKOFF_CUTOFF: - parse_lease_time (cfile, &config -> backoff_cutoff); + case BACKOFF_CUTOFF: + parse_lease_time(cfile, &config->backoff_cutoff); return; - - case INITIAL_INTERVAL: - parse_lease_time (cfile, &config -> initial_interval); + case INITIAL_INTERVAL: + parse_lease_time(cfile, &config->initial_interval); return; - - case SCRIPT: - config -> script_name = parse_string (cfile); + case SCRIPT: + config->script_name = parse_string(cfile); return; - - case INTERFACE: + case INTERFACE: if (ip) - parse_warn ("nested interface declaration."); + parse_warn("nested interface declaration."); parse_interface_declaration (cfile, config); return; - - case LEASE: - parse_client_lease_statement (cfile, 1); + case LEASE: + parse_client_lease_statement(cfile, 1); return; - - case ALIAS: - parse_client_lease_statement (cfile, 2); + case ALIAS: + parse_client_lease_statement(cfile, 2); return; - - case REJECT: - parse_reject_statement (cfile, config); + case REJECT: + parse_reject_statement(cfile, config); return; - - default: - parse_warn ("expecting a statement."); - skip_to_semi (cfile); + default: + parse_warn("expecting a statement."); + skip_to_semi(cfile); break; } - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != SEMI) { - parse_warn ("semicolon expected."); - skip_to_semi (cfile); + parse_warn("semicolon expected."); + skip_to_semi(cfile); } } -int parse_X (cfile, buf, max) - FILE *cfile; - u_int8_t *buf; - int max; +int +parse_X(FILE *cfile, u_int8_t *buf, int max) { - int token; - char *val; - int len; + int token; + char *val; + int len; - token = peek_token (&val, cfile); + token = peek_token(&val, cfile); if (token == NUMBER_OR_NAME || token == NUMBER) { len = 0; do { - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != NUMBER && token != NUMBER_OR_NAME) { - parse_warn ("expecting hexadecimal constant."); - skip_to_semi (cfile); - return 0; + parse_warn("expecting hexadecimal constant."); + skip_to_semi(cfile); + return (0); } - convert_num (&buf [len], val, 16, 8); + convert_num(&buf[len], val, 16, 8); if (len++ > max) { - parse_warn ("hexadecimal constant too long."); - skip_to_semi (cfile); - return 0; + parse_warn("hexadecimal constant too long."); + skip_to_semi(cfile); + return (0); } token = peek_token (&val, cfile); if (token == COLON) - token = next_token (&val, cfile); + token = next_token(&val, cfile); } while (token == COLON); val = (char *)buf; } else if (token == STRING) { - token = next_token (&val, cfile); - len = strlen (val); + token = next_token(&val, cfile); + len = strlen(val); if (len + 1 > max) { - parse_warn ("string constant too long."); - skip_to_semi (cfile); - return 0; + parse_warn("string constant too long."); + skip_to_semi(cfile); + return (0); } - memcpy (buf, val, len + 1); + memcpy(buf, val, len + 1); } else { - parse_warn ("expecting string or hexadecimal data"); - skip_to_semi (cfile); - return 0; + parse_warn("expecting string or hexadecimal data"); + skip_to_semi(cfile); + return (0); } - return len; + return (len); } /* option-list :== option_name | option_list COMMA option_name */ -int parse_option_list (cfile, list) - FILE *cfile; - u_int8_t *list; +int +parse_option_list (FILE *cfile, u_int8_t *list) { - int ix, i; - int token; - char *val; + int ix, i; + int token; + char *val; ix = 0; do { - token = next_token (&val, cfile); - if (!is_identifier (token)) { - parse_warn ("expected option name."); - skip_to_semi (cfile); - return 0; + token = next_token(&val, cfile); + if (!is_identifier(token)) { + parse_warn("expected option name."); + skip_to_semi(cfile); + return (0); } - for (i = 0; i < 256; i++) { - if (!strcasecmp (dhcp_options [i].name, val)) + for (i = 0; i < 256; i++) + if (!strcasecmp(dhcp_options[i].name, val)) break; - } + if (i == 256) { - parse_warn ("%s: unexpected option name.", val); - skip_to_semi (cfile); - return 0; + parse_warn("%s: unexpected option name.", val); + skip_to_semi(cfile); + return (0); } - list [ix++] = i; + list[ix++] = i; if (ix == 256) { - parse_warn ("%s: too many options.", val); - skip_to_semi (cfile); - return 0; + parse_warn("%s: too many options.", val); + skip_to_semi(cfile); + return (0); } - token = next_token (&val, cfile); + token = next_token(&val, cfile); } while (token == COMMA); if (token != SEMI) { - parse_warn ("expecting semicolon."); - skip_to_semi (cfile); - return 0; + parse_warn("expecting semicolon."); + skip_to_semi(cfile); + return (0); } - return ix; + return (ix); } /* interface-declaration :== INTERFACE string LBRACE client-declarations RBRACE */ -void parse_interface_declaration (cfile, outer_config) - FILE *cfile; - struct client_config *outer_config; +void +parse_interface_declaration(FILE *cfile, struct client_config *outer_config) { - int token; - char *val; - - struct interface_info *ip; + int token; + char *val; + struct interface_info *ip; - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != STRING) { - parse_warn ("expecting interface name (in quotes)."); - skip_to_semi (cfile); + parse_warn("expecting interface name (in quotes)."); + skip_to_semi(cfile); return; } - ip = interface_or_dummy (val); + ip = interface_or_dummy(val); - if (!ip -> client) - make_client_state (ip); + if (!ip->client) + make_client_state(ip); - if (!ip -> client -> config) - make_client_config (ip, outer_config); + if (!ip->client->config) + make_client_config(ip, outer_config); - ip -> flags &= ~INTERFACE_AUTOMATIC; + ip->flags &= ~INTERFACE_AUTOMATIC; interfaces_requested = 1; - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != LBRACE) { - parse_warn ("expecting left brace."); - skip_to_semi (cfile); + parse_warn("expecting left brace."); + skip_to_semi(cfile); return; } do { - token = peek_token (&val, cfile); + token = peek_token(&val, cfile); if (token == EOF) { - parse_warn ("unterminated interface declaration."); + parse_warn("unterminated interface declaration."); return; } if (token == RBRACE) break; - parse_client_statement (cfile, ip, ip -> client -> config); + parse_client_statement(cfile, ip, ip->client->config); } while (1); - token = next_token (&val, cfile); + token = next_token(&val, cfile); } -struct interface_info *interface_or_dummy (name) - char *name; +struct interface_info * +interface_or_dummy(char *name) { - struct interface_info *ip; + struct interface_info *ip; /* Find the interface (if any) that matches the name. */ - for (ip = interfaces; ip; ip = ip -> next) { - if (!strcmp (ip -> name, name)) + for (ip = interfaces; ip; ip = ip->next) + if (!strcmp (ip->name, name)) break; - } /* If it's not a real interface, see if it's on the dummy list. */ - if (!ip) { - for (ip = dummy_interfaces; ip; ip = ip -> next) { - if (!strcmp (ip -> name, name)) + if (!ip) + for (ip = dummy_interfaces; ip; ip = ip->next) + if (!strcmp (ip->name, name)) break; - } - } /* If we didn't find an interface, make a dummy interface as a placeholder. */ if (!ip) { - ip = ((struct interface_info *)malloc (sizeof *ip)); + ip = malloc(sizeof *ip); if (!ip) error ("Insufficient memory to record interface %s", name); - memset (ip, 0, sizeof *ip); - strlcpy (ip -> name, name, IFNAMSIZ); - ip -> next = dummy_interfaces; + memset(ip, 0, sizeof *ip); + strlcpy(ip->name, name, IFNAMSIZ); + ip->next = dummy_interfaces; dummy_interfaces = ip; } - return ip; + return (ip); } -void make_client_state (ip) - struct interface_info *ip; +void +make_client_state(struct interface_info *ip) { - ip -> client = - ((struct client_state *)malloc (sizeof *(ip -> client))); - if (!ip -> client) - error ("no memory for state on %s\n", ip -> name); - memset (ip -> client, 0, sizeof *(ip -> client)); + ip->client = malloc(sizeof *(ip->client)); + if (!ip->client) + error("no memory for state on %s\n", ip->name); + memset(ip->client, 0, sizeof *(ip->client)); } -void make_client_config (ip, config) - struct interface_info *ip; - struct client_config *config; +void +make_client_config(struct interface_info *ip, struct client_config *config) { - ip -> client -> config = - ((struct client_config *) - malloc (sizeof (struct client_config))); - if (!ip -> client -> config) - error ("no memory for config for %s\n", ip -> name); - memset (ip -> client -> config, 0, - sizeof *(ip -> client -> config)); - memcpy (ip -> client -> config, config, sizeof *config); + ip->client->config = malloc(sizeof(struct client_config)); + if (!ip->client->config) + error("no memory for config for %s\n", ip->name); + memset(ip->client->config, 0, sizeof *(ip->client->config)); + memcpy(ip->client->config, config, sizeof *config); } /* client-lease-statement :== @@ -520,56 +476,55 @@ void make_client_config (ip, config) client-lease-declarations client-lease-declaration */ -void parse_client_lease_statement (cfile, is_static) - FILE *cfile; - int is_static; +void +parse_client_lease_statement(FILE *cfile, int is_static) { - struct client_lease *lease, *lp, *pl; - struct interface_info *ip; - int token; - char *val; + struct client_lease *lease, *lp, *pl; + struct interface_info *ip; + int token; + char *val; - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != LBRACE) { - parse_warn ("expecting left brace."); - skip_to_semi (cfile); + parse_warn("expecting left brace."); + skip_to_semi(cfile); return; } - lease = (struct client_lease *)malloc (sizeof (struct client_lease)); + lease = malloc(sizeof(struct client_lease)); if (!lease) error ("no memory for lease.\n"); - memset (lease, 0, sizeof *lease); - lease -> is_static = is_static; + memset(lease, 0, sizeof *lease); + lease->is_static = is_static; - ip = (struct interface_info *)0; + ip = NULL; do { - token = peek_token (&val, cfile); + token = peek_token(&val, cfile); if (token == EOF) { - parse_warn ("unterminated lease declaration."); + parse_warn("unterminated lease declaration."); return; } if (token == RBRACE) break; - parse_client_lease_declaration (cfile, lease, &ip); + parse_client_lease_declaration(cfile, lease, &ip); } while (1); - token = next_token (&val, cfile); + token = next_token(&val, cfile); /* If the lease declaration didn't include an interface declaration that we recognized, it's of no use to us. */ if (!ip) { - free_client_lease (lease); + free_client_lease(lease); return; } /* Make sure there's a client state structure... */ - if (!ip -> client) - make_client_state (ip); + if (!ip->client) + make_client_state(ip); /* If this is an alias lease, it doesn't need to be sorted in. */ if (is_static == 2) { - ip -> client -> alias = lease; + ip->client->alias = lease; return; } @@ -577,16 +532,16 @@ void parse_client_lease_statement (cfile, is_static) active lease but is still on the lease list, so scan the lease list looking for a lease with the same address, and if we find it, toss it. */ - pl = (struct client_lease *)0; - for (lp = ip -> client -> leases; lp; lp = lp -> next) { - if (lp -> address.len == lease -> address.len && - !memcmp (lp -> address.iabuf, lease -> address.iabuf, - lease -> address.len)) { + pl = NULL; + for (lp = ip->client->leases; lp; lp = lp->next) { + if (lp->address.len == lease->address.len && + !memcmp(lp->address.iabuf, lease->address.iabuf, + lease->address.len)) { if (pl) - pl -> next = lp -> next; + pl->next = lp->next; else - ip -> client -> leases = lp -> next; - free_client_lease (lp); + ip->client->leases = lp->next; + free_client_lease(lp); break; } } @@ -594,8 +549,8 @@ void parse_client_lease_statement (cfile, is_static) /* If this is a preloaded lease, just put it on the list of recorded leases - don't make it the active lease. */ if (is_static) { - lease -> next = ip -> client -> leases; - ip -> client -> leases = lease; + lease->next = ip->client->leases; + ip->client->leases = lease; return; } @@ -610,22 +565,20 @@ void parse_client_lease_statement (cfile, is_static) then if the old active lease has expired, we dump it; if not, we put it on the list of leases for this interface which are still valid but no longer active. */ - if (ip -> client -> active) { - if (ip -> client -> active -> expiry < cur_time) - free_client_lease (ip -> client -> active); - else if (ip -> client -> active -> address.len == - lease -> address.len && - !memcmp (ip -> client -> active -> address.iabuf, - lease -> address.iabuf, - lease -> address.len)) - free_client_lease (ip -> client -> active); + if (ip->client->active) { + if (ip->client->active->expiry < cur_time) + free_client_lease(ip->client->active); + else if (ip->client->active->address.len == + lease->address.len && + !memcmp(ip->client->active->address.iabuf, + lease->address.iabuf, lease->address.len)) + free_client_lease (ip->client->active); else { - ip -> client -> active -> next = - ip -> client -> leases; - ip -> client -> leases = ip -> client -> active; + ip->client->active->next = ip->client->leases; + ip->client->leases = ip->client->active; } } - ip -> client -> active = lease; + ip->client->active = lease; /* phew. */ } @@ -641,130 +594,118 @@ void parse_client_lease_statement (cfile, is_static) REBIND time-decl | EXPIRE time-decl */ -void parse_client_lease_declaration (cfile, lease, ipp) - FILE *cfile; - struct client_lease *lease; - struct interface_info **ipp; +void +parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, + struct interface_info **ipp) { - int token; - char *val; - struct interface_info *ip; + int token; + char *val; + struct interface_info *ip; - switch (next_token (&val, cfile)) { - case BOOTP: - lease -> is_bootp = 1; + switch(next_token (&val, cfile)) { + case BOOTP: + lease->is_bootp = 1; break; - - case INTERFACE: - token = next_token (&val, cfile); + case INTERFACE: + token = next_token(&val, cfile); if (token != STRING) { - parse_warn ("expecting interface name (in quotes)."); - skip_to_semi (cfile); + parse_warn("expecting interface name (in quotes)."); + skip_to_semi(cfile); break; } - ip = interface_or_dummy (val); + ip = interface_or_dummy(val); *ipp = ip; break; - - case FIXED_ADDR: - if (!parse_ip_addr (cfile, &lease -> address)) + case FIXED_ADDR: + if (!parse_ip_addr(cfile, &lease->address)) return; break; - - case MEDIUM: - parse_string_list (cfile, &lease -> medium, 0); + case MEDIUM: + parse_string_list(cfile, &lease->medium, 0); return; - - case FILENAME: - lease -> filename = parse_string (cfile); + case FILENAME: + lease->filename = parse_string(cfile); return; - - case SERVER_NAME: - lease -> server_name = parse_string (cfile); + case SERVER_NAME: + lease->server_name = parse_string(cfile); return; - - case RENEW: - lease -> renewal = parse_date (cfile); + case RENEW: + lease->renewal = parse_date(cfile); return; - - case REBIND: - lease -> rebind = parse_date (cfile); + case REBIND: + lease->rebind = parse_date(cfile); return; - - case EXPIRE: - lease -> expiry = parse_date (cfile); + case EXPIRE: + lease->expiry = parse_date(cfile); return; - - case OPTION: - parse_option_decl (cfile, lease -> options); + case OPTION: + parse_option_decl(cfile, lease->options); return; - - default: - parse_warn ("expecting lease declaration."); - skip_to_semi (cfile); + default: + parse_warn("expecting lease declaration."); + skip_to_semi(cfile); break; } - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != SEMI) { - parse_warn ("expecting semicolon."); - skip_to_semi (cfile); + parse_warn("expecting semicolon."); + skip_to_semi(cfile); } } -struct option *parse_option_decl (cfile, options) - FILE *cfile; - struct option_data *options; +struct option * +parse_option_decl(FILE *cfile, struct option_data *options) { - char *val; - int token; - u_int8_t buf [4]; - u_int8_t hunkbuf [1024]; - int hunkix = 0; - char *vendor; - char *fmt; - struct universe *universe; - struct option *option; - struct iaddr ip_addr; - u_int8_t *dp; - int len; - int nul_term = 0; - - token = next_token (&val, cfile); - if (!is_identifier (token)) { - parse_warn ("expecting identifier after option keyword."); + char *val; + int token; + u_int8_t buf[4]; + u_int8_t hunkbuf[1024]; + int hunkix = 0; + char *vendor; + char *fmt; + struct universe *universe; + struct option *option; + struct iaddr ip_addr; + u_int8_t *dp; + int len; + int nul_term = 0; + + token = next_token(&val, cfile); + if (!is_identifier(token)) { + parse_warn("expecting identifier after option keyword."); if (token != SEMI) - skip_to_semi (cfile); - return (struct option *)0; + skip_to_semi(cfile); + return (NULL); } - vendor = malloc (strlen (val) + 1); + /* XXXFIX asprintf */ + vendor = malloc(strlen(val) + 1); if (!vendor) - error ("no memory for vendor information."); - strlcpy (vendor, val, strlen(val) + 1); + error("no memory for vendor information."); + strlcpy(vendor, val, strlen(val) + 1); token = peek_token (&val, cfile); if (token == DOT) { /* Go ahead and take the DOT token... */ - token = next_token (&val, cfile); + token = next_token(&val, cfile); /* The next token should be an identifier... */ - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (!is_identifier (token)) { - parse_warn ("expecting identifier after '.'"); + parse_warn("expecting identifier after '.'"); if (token != SEMI) - skip_to_semi (cfile); - return (struct option *)0; + skip_to_semi(cfile); + return (NULL); } /* Look up the option name hash table for the specified vendor. */ - universe = ((struct universe *) - hash_lookup (&universe_hash, - (unsigned char *)vendor, 0)); + universe = ((struct universe *)hash_lookup(&universe_hash, + (unsigned char *)vendor, 0)); /* If it's not there, we can't parse the rest of the declaration. */ if (!universe) { - parse_warn ("no vendor named %s.", vendor); - skip_to_semi (cfile); - return (struct option *)0; + parse_warn("no vendor named %s.", vendor); + skip_to_semi(cfile); + return (NULL); } } else { /* Use the default hash table, which contains all the @@ -774,236 +715,218 @@ struct option *parse_option_decl (cfile, options) } /* Look up the actual option info... */ - option = (struct option *)hash_lookup (universe -> hash, - (unsigned char *)val, 0); + option = (struct option *)hash_lookup(universe->hash, + (unsigned char *)val, 0); /* If we didn't get an option structure, it's an undefined option. */ if (!option) { if (val == vendor) - parse_warn ("no option named %s", val); + parse_warn("no option named %s", val); else - parse_warn ("no option named %s for vendor %s", + parse_warn("no option named %s for vendor %s", val, vendor); - skip_to_semi (cfile); - return (struct option *)0; + skip_to_semi(cfile); + return (NULL); } /* Free the initial identifier token. */ - free (vendor); + free(vendor); /* Parse the option data... */ do { - for (fmt = option -> format; *fmt; fmt++) { + for (fmt = option->format; *fmt; fmt++) { if (*fmt == 'A') break; switch (*fmt) { - case 'X': - len = parse_X (cfile, &hunkbuf [hunkix], - sizeof hunkbuf - hunkix); + case 'X': + len = parse_X(cfile, &hunkbuf[hunkix], + sizeof hunkbuf - hunkix); hunkix += len; - break; - - case 't': /* Text string... */ - token = next_token (&val, cfile); + break; + case 't': /* Text string... */ + token = next_token(&val, cfile); if (token != STRING) { - parse_warn ("expecting string."); - skip_to_semi (cfile); - return (struct option *)0; + parse_warn("expecting string."); + skip_to_semi(cfile); + return (NULL); } - len = strlen (val); + len = strlen(val); if (hunkix + len + 1 > sizeof hunkbuf) { - parse_warn ("option data buffer %s", - "overflow"); - skip_to_semi (cfile); - return (struct option *)0; + parse_warn("option data buffer %s", + "overflow"); + skip_to_semi(cfile); + return (NULL); } - memcpy (&hunkbuf [hunkix], val, len + 1); + memcpy(&hunkbuf[hunkix], val, len + 1); nul_term = 1; hunkix += len; break; - - case 'I': /* IP address. */ + case 'I': /* IP address. */ if (!parse_ip_addr (cfile, &ip_addr)) - return (struct option *)0; + return (NULL); len = ip_addr.len; dp = ip_addr.iabuf; - - alloc: +alloc: if (hunkix + len > sizeof hunkbuf) { parse_warn ("option data buffer %s", - "overflow"); - skip_to_semi (cfile); - return (struct option *)0; + "overflow"); + skip_to_semi(cfile); + return (NULL); } - memcpy (&hunkbuf [hunkix], dp, len); + memcpy (&hunkbuf[hunkix], dp, len); hunkix += len; break; - - case 'L': /* Unsigned 32-bit integer... */ - case 'l': /* Signed 32-bit integer... */ - token = next_token (&val, cfile); + case 'L': /* Unsigned 32-bit integer... */ + case 'l': /* Signed 32-bit integer... */ + token = next_token(&val, cfile); if (token != NUMBER) { - need_number: - parse_warn ("expecting number."); +need_number: + parse_warn("expecting number."); if (token != SEMI) - skip_to_semi (cfile); - return (struct option *)0; + skip_to_semi(cfile); + return (NULL); } convert_num (buf, val, 0, 32); len = 4; dp = buf; goto alloc; - - case 's': /* Signed 16-bit integer. */ - case 'S': /* Unsigned 16-bit integer. */ - token = next_token (&val, cfile); + case 's': /* Signed 16-bit integer. */ + case 'S': /* Unsigned 16-bit integer. */ + token = next_token(&val, cfile); if (token != NUMBER) goto need_number; - convert_num (buf, val, 0, 16); + convert_num(buf, val, 0, 16); len = 2; dp = buf; goto alloc; - - case 'b': /* Signed 8-bit integer. */ - case 'B': /* Unsigned 8-bit integer. */ - token = next_token (&val, cfile); + case 'b': /* Signed 8-bit integer. */ + case 'B': /* Unsigned 8-bit integer. */ + token = next_token(&val, cfile); if (token != NUMBER) goto need_number; - convert_num (buf, val, 0, 8); + convert_num(buf, val, 0, 8); len = 1; dp = buf; goto alloc; - - case 'f': /* Boolean flag. */ - token = next_token (&val, cfile); - if (!is_identifier (token)) { - parse_warn ("expecting identifier."); - bad_flag: + case 'f': /* Boolean flag. */ + token = next_token(&val, cfile); + if (!is_identifier(token)) { + parse_warn("expecting identifier."); +bad_flag: if (token != SEMI) - skip_to_semi (cfile); - return (struct option *)0; + skip_to_semi(cfile); + return (NULL); } - if (!strcasecmp (val, "true") - || !strcasecmp (val, "on")) - buf [0] = 1; - else if (!strcasecmp (val, "false") - || !strcasecmp (val, "off")) - buf [0] = 0; + if (!strcasecmp(val, "true") || + !strcasecmp(val, "on")) + buf[0] = 1; + else if (!strcasecmp(val, "false") || + !strcasecmp (val, "off")) + buf[0] = 0; else { - parse_warn ("expecting boolean."); + parse_warn("expecting boolean."); goto bad_flag; } len = 1; dp = buf; goto alloc; - - default: - warn ("Bad format %c in parse_option_param.", - *fmt); - skip_to_semi (cfile); - return (struct option *)0; + default: + warn("Bad format %c in parse_option_param.", + *fmt); + skip_to_semi(cfile); + return (NULL); } } - token = next_token (&val, cfile); + token = next_token(&val, cfile); } while (*fmt == 'A' && token == COMMA); if (token != SEMI) { - parse_warn ("semicolon expected."); - skip_to_semi (cfile); - return (struct option *)0; + parse_warn("semicolon expected."); + skip_to_semi(cfile); + return (NULL); } - options [option -> code].data = - (unsigned char *)malloc (hunkix + nul_term); - if (!options [option -> code].data) - error ("out of memory allocating option data."); - memcpy (options [option -> code].data, hunkbuf, hunkix + nul_term); - options [option -> code].len = hunkix; - return option; + options[option->code].data = malloc(hunkix + nul_term); + if (!options[option->code].data) + error("out of memory allocating option data."); + memcpy(options[option->code].data, hunkbuf, hunkix + nul_term); + options[option->code].len = hunkix; + return (option); } -void parse_string_list (cfile, lp, multiple) - FILE *cfile; - struct string_list **lp; - int multiple; +void +parse_string_list (FILE *cfile, struct string_list **lp, int multiple) { - int token; - char *val; - struct string_list *cur, *tmp; + int token; + char *val; + struct string_list *cur, *tmp; /* Find the last medium in the media list. */ - if (*lp) { - for (cur = *lp; cur -> next; cur = cur -> next) - ; - } else { - cur = (struct string_list *)0; - } + if (*lp) + for (cur = *lp; cur->next; cur = cur->next) + ; /* nothing */ + else + cur = NULL; do { - token = next_token (&val, cfile); + token = next_token(&val, cfile); if (token != STRING) { - parse_warn ("Expecting media options."); - skip_to_semi (cfile); + parse_warn("Expecting media options."); + skip_to_semi(cfile); return; } -#ifdef OH_THE_HORROR - tmp = (struct string_list *)malloc (strlen (val) + 1 + - sizeof - (struct string_list *)); -#endif + /* XXXFIX asprintf */ tmp = new_string_list(strlen(val) + 1, "parse tmp"); if (tmp == NULL) error ("no memory for string list entry."); - - strlcpy (tmp -> string, val, strlen(val) + 1); - tmp -> next = NULL; + strlcpy (tmp->string, val, strlen(val) + 1); + tmp->next = NULL; /* Store this medium at the end of the media list. */ if (cur) - cur -> next = tmp; + cur->next = tmp; else *lp = tmp; cur = tmp; - token = next_token (&val, cfile); + token = next_token(&val, cfile); } while (multiple && token == COMMA); if (token != SEMI) { - parse_warn ("expecting semicolon."); - skip_to_semi (cfile); + parse_warn("expecting semicolon."); + skip_to_semi(cfile); } } -void parse_reject_statement (cfile, config) - FILE *cfile; - struct client_config *config; +void +parse_reject_statement(FILE *cfile, struct client_config *config) { - int token; - char *val; - struct iaddr addr; - struct iaddrlist *list; + int token; + char *val; + struct iaddr addr; + struct iaddrlist *list; do { if (!parse_ip_addr (cfile, &addr)) { - parse_warn ("expecting IP address."); - skip_to_semi (cfile); + parse_warn("expecting IP address."); + skip_to_semi(cfile); return; } - list = (struct iaddrlist *)malloc (sizeof (struct iaddrlist)); + list = malloc(sizeof(struct iaddrlist)); if (!list) - error ("no memory for reject list!"); + error("no memory for reject list!"); - list -> addr = addr; - list -> next = config -> reject_list; - config -> reject_list = list; + list->addr = addr; + list->next = config->reject_list; + config->reject_list = list; - token = next_token (&val, cfile); + token = next_token(&val, cfile); } while (token == COMMA); if (token != SEMI) { - parse_warn ("expecting semicolon."); - skip_to_semi (cfile); + parse_warn("expecting semicolon."); + skip_to_semi(cfile); } } diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index 58136a2bc1a..92a67774066 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -52,8 +52,8 @@ char *cur_line; char *tlname; int eol_token; -static char line1 [81]; -static char line2 [81]; +static char line1[81]; +static char line2[81]; static int lpos; static int line; static int tlpos; @@ -61,38 +61,32 @@ static int tline; static int token; static int ugflag; static char *tval; -static char tokbuf [1500]; +static char tokbuf[1500]; -#ifdef OLD_LEXER -char comments [4096]; -int comment_index; -#endif +static int get_char(FILE *); +static int get_token(FILE *); +static void skip_to_eol(FILE *); +static int read_string(FILE *); +static int read_number(int, FILE *); +static int read_num_or_name(int, FILE *); +static int intern(char *, int); - -static int get_char PROTO ((FILE *)); -static int get_token PROTO ((FILE *)); -static void skip_to_eol PROTO ((FILE *)); -static int read_string PROTO ((FILE *)); -static int read_number PROTO ((int, FILE *)); -static int read_num_or_name PROTO ((int, FILE *)); -static int intern PROTO ((char *, int)); - -void new_parse (name) - char *name; +void +new_parse(char *name) { tlname = name; lpos = line = 1; cur_line = line1; prev_line = line2; token_line = cur_line; - cur_line [0] = prev_line [0] = 0; + cur_line[0] = prev_line[0] = 0; warnings_occurred = 0; } -static int get_char (cfile) - FILE *cfile; +static int +get_char(FILE *cfile) { - int c = getc (cfile); + int c = getc (cfile); if (!ugflag) { if (c == EOL) { if (cur_line == line1) { @@ -104,11 +98,11 @@ static int get_char (cfile) } line++; lpos = 1; - cur_line [0] = 0; + cur_line[0] = 0; } else if (c != EOF) { if (lpos <= 81) { - cur_line [lpos - 1] = c; - cur_line [lpos] = 0; + cur_line[lpos - 1] = c; + cur_line[lpos] = 0; } lpos++; } @@ -117,13 +111,12 @@ static int get_char (cfile) return c; } -static int get_token (cfile) - FILE *cfile; +static int +get_token (FILE *cfile) { - int c; - int ttok; - static char tb [2]; - int l, p, u; + int c, ttok; + static char tb[2]; + int l, p, u; do { l = line; @@ -132,33 +125,33 @@ static int get_token (cfile) c = get_char (cfile); - if (!(c == '\n' && eol_token) && isascii (c) && isspace (c)) + if (!(c == '\n' && eol_token) && isascii(c) && isspace(c)) continue; if (c == '#') { - skip_to_eol (cfile); + skip_to_eol(cfile); continue; } if (c == '"') { lexline = l; lexchar = p; - ttok = read_string (cfile); + ttok = read_string(cfile); break; } - if ((isascii (c) && isdigit (c)) || c == '-') { + if ((isascii(c) && isdigit(c)) || c == '-') { lexline = l; lexchar = p; - ttok = read_number (c, cfile); + ttok = read_number(c, cfile); break; - } else if (isascii (c) && isalpha (c)) { + } else if (isascii(c) && isalpha(c)) { lexline = l; lexchar = p; - ttok = read_num_or_name (c, cfile); + ttok = read_num_or_name(c, cfile); break; } else { lexline = l; lexchar = p; - tb [0] = c; - tb [1] = 0; + tb[0] = c; + tb[1] = 0; tval = tb; ttok = c; break; @@ -167,11 +160,10 @@ static int get_token (cfile) return ttok; } -int next_token (rval, cfile) - char **rval; - FILE *cfile; +int +next_token(char **rval, FILE *cfile) { - int rv; + int rv; if (token) { if (lexline != tline) @@ -181,46 +173,46 @@ int next_token (rval, cfile) rv = token; token = 0; } else { - rv = get_token (cfile); + rv = get_token(cfile); token_line = cur_line; } if (rval) *rval = tval; -#ifdef DEBUG_TOKENS - fprintf (stderr, "%s:%d ", tval, rv); -#endif - return rv; + + return (rv); } -int peek_token (rval, cfile) - char **rval; - FILE *cfile; +int +peek_token(char **rval, FILE *cfile) { - int x; + int x; if (!token) { tlpos = lexchar; tline = lexline; - token = get_token (cfile); + token = get_token(cfile); if (lexline != tline) token_line = prev_line; - x = lexchar; lexchar = tlpos; tlpos = x; - x = lexline; lexline = tline; tline = x; + x = lexchar; + lexchar = tlpos; + tlpos = x; + x = lexline; + lexline = tline; + tline = x; } if (rval) *rval = tval; -#ifdef DEBUG_TOKENS - fprintf (stderr, "(%s:%d) ", tval, token); -#endif - return token; + + return (token); } -static void skip_to_eol (cfile) - FILE *cfile; +static void +skip_to_eol(FILE *cfile) { - int c; + int c; + do { - c = get_char (cfile); + c = get_char(cfile); if (c == EOF) return; if (c == EOL) @@ -228,309 +220,304 @@ static void skip_to_eol (cfile) } while (1); } -static int read_string (cfile) - FILE *cfile; +static int +read_string(FILE *cfile) { - int i; - int bs = 0; - int c; + int i, c, bs = 0; - for (i = 0; i < sizeof tokbuf; i++) { - c = get_char (cfile); + for (i = 0; i < sizeof(tokbuf); i++) { + c = get_char(cfile); if (c == EOF) { - parse_warn ("eof in string constant"); + parse_warn("eof in string constant"); break; } if (bs) { bs = 0; - tokbuf [i] = c; + tokbuf[i] = c; } else if (c == '\\') bs = 1; else if (c == '"') break; else - tokbuf [i] = c; + tokbuf[i] = c; } /* Normally, I'd feel guilty about this, but we're talking about strings that'll fit in a DHCP packet here... */ - if (i == sizeof tokbuf) { - parse_warn ("string constant larger than internal buffer"); + if (i == sizeof(tokbuf)) { + parse_warn("string constant larger than internal buffer"); --i; } - tokbuf [i] = 0; + tokbuf[i] = 0; tval = tokbuf; - return STRING; + return (STRING); } -static int read_number (c, cfile) - int c; - FILE *cfile; +static int +read_number(int c, FILE *cfile) { - int seenx = 0; - int i = 0; - int token = NUMBER; + int seenx = 0, i = 0, token = NUMBER; - tokbuf [i++] = c; - for (; i < sizeof tokbuf; i++) { - c = get_char (cfile); - if (!seenx && c == 'x') { + tokbuf[i++] = c; + for (; i < sizeof(tokbuf); i++) { + c = get_char(cfile); + if (!seenx && c == 'x') seenx = 1; - } else if (!isascii (c) || !isxdigit (c)) { - ungetc (c, cfile); + else if (!isascii(c) || !isxdigit(c)) { + ungetc(c, cfile); ugflag = 1; break; } - tokbuf [i] = c; + tokbuf[i] = c; } - if (i == sizeof tokbuf) { + if (i == sizeof(tokbuf)) { parse_warn ("numeric token larger than internal buffer"); --i; } - tokbuf [i] = 0; + tokbuf[i] = 0; tval = tokbuf; - return token; + + return (token); } -static int read_num_or_name (c, cfile) - int c; - FILE *cfile; +static int +read_num_or_name (int c, FILE *cfile) { - int i = 0; - int rv = NUMBER_OR_NAME; - tokbuf [i++] = c; - for (; i < sizeof tokbuf; i++) { - c = get_char (cfile); - if (!isascii (c) || - (c != '-' && c != '_' && !isalnum (c))) { - ungetc (c, cfile); + int i = 0; + int rv = NUMBER_OR_NAME; + + tokbuf[i++] = c; + for (; i < sizeof(tokbuf); i++) { + c = get_char(cfile); + if (!isascii(c) || (c != '-' && c != '_' && !isalnum(c))) { + ungetc(c, cfile); ugflag = 1; break; } - if (!isxdigit (c)) + if (!isxdigit(c)) rv = NAME; - tokbuf [i] = c; + tokbuf[i] = c; } - if (i == sizeof tokbuf) { - parse_warn ("token larger than internal buffer"); + if (i == sizeof(tokbuf)) { + parse_warn("token larger than internal buffer"); --i; } - tokbuf [i] = 0; + tokbuf[i] = 0; tval = tokbuf; - return intern (tval, rv); + + return (intern(tval, rv)); } -static int intern (atom, dfv) - char *atom; - int dfv; +static int +intern(char *atom, int dfv) { - if (!isascii (atom [0])) + if (!isascii(atom[0])) return dfv; - switch (tolower (atom [0])) { - case 'a': - if (!strcasecmp (atom + 1, "lways-reply-rfc1048")) - return ALWAYS_REPLY_RFC1048; - if (!strcasecmp (atom + 1, "ppend")) - return APPEND; - if (!strcasecmp (atom + 1, "llow")) - return ALLOW; - if (!strcasecmp (atom + 1, "lias")) - return ALIAS; - if (!strcasecmp (atom + 1, "bandoned")) - return ABANDONED; - if (!strcasecmp (atom + 1, "uthoritative")) - return AUTHORITATIVE; + switch(tolower(atom[0])) { + case 'a': + if (!strcasecmp(atom + 1, "lways-reply-rfc1048")) + return (ALWAYS_REPLY_RFC1048); + if (!strcasecmp(atom + 1, "ppend")) + return (APPEND); + if (!strcasecmp(atom + 1, "llow")) + return (ALLOW); + if (!strcasecmp(atom + 1, "lias")) + return (ALIAS); + if (!strcasecmp(atom + 1, "bandoned")) + return (ABANDONED); + if (!strcasecmp(atom + 1, "uthoritative")) + return (AUTHORITATIVE); break; - case 'b': - if (!strcasecmp (atom + 1, "ackoff-cutoff")) - return BACKOFF_CUTOFF; - if (!strcasecmp (atom + 1, "ootp")) - return BOOTP; - if (!strcasecmp (atom + 1, "ooting")) - return BOOTING; - if (!strcasecmp (atom + 1, "oot-unknown-clients")) - return BOOT_UNKNOWN_CLIENTS; - case 'c': - if (!strcasecmp (atom + 1, "lass")) - return CLASS; - if (!strcasecmp (atom + 1, "iaddr")) - return CIADDR; - if (!strcasecmp (atom + 1, "lient-identifier")) - return CLIENT_IDENTIFIER; - if (!strcasecmp (atom + 1, "lient-hostname")) - return CLIENT_HOSTNAME; + case 'b': + if (!strcasecmp(atom + 1, "ackoff-cutoff")) + return (BACKOFF_CUTOFF); + if (!strcasecmp(atom + 1, "ootp")) + return (BOOTP); + if (!strcasecmp(atom + 1, "ooting")) + return (BOOTING); + if (!strcasecmp(atom + 1, "oot-unknown-clients")) + return (BOOT_UNKNOWN_CLIENTS); + case 'c': + if (!strcasecmp(atom + 1, "lass")) + return (CLASS); + if (!strcasecmp(atom + 1, "iaddr")) + return (CIADDR); + if (!strcasecmp(atom + 1, "lient-identifier")) + return (CLIENT_IDENTIFIER); + if (!strcasecmp(atom + 1, "lient-hostname")) + return (CLIENT_HOSTNAME); break; - case 'd': - if (!strcasecmp (atom + 1, "omain")) - return DOMAIN; - if (!strcasecmp (atom + 1, "eny")) - return DENY; - if (!strncasecmp (atom + 1, "efault", 6)) { - if (!atom [7]) - return DEFAULT; - if (!strcasecmp (atom + 7, "-lease-time")) - return DEFAULT_LEASE_TIME; + case 'd': + if (!strcasecmp(atom + 1, "omain")) + return (DOMAIN); + if (!strcasecmp(atom + 1, "eny")) + return (DENY); + if (!strncasecmp(atom + 1, "efault", 6)) { + if (!atom[7]) + return (DEFAULT); + if (!strcasecmp(atom + 7, "-lease-time")) + return (DEFAULT_LEASE_TIME); break; } - if (!strncasecmp (atom + 1, "ynamic-bootp", 12)) { - if (!atom [13]) - return DYNAMIC_BOOTP; - if (!strcasecmp (atom + 13, "-lease-cutoff")) - return DYNAMIC_BOOTP_LEASE_CUTOFF; - if (!strcasecmp (atom + 13, "-lease-length")) - return DYNAMIC_BOOTP_LEASE_LENGTH; + if (!strncasecmp(atom + 1, "ynamic-bootp", 12)) { + if (!atom[13]) + return (DYNAMIC_BOOTP); + if (!strcasecmp(atom + 13, "-lease-cutoff")) + return (DYNAMIC_BOOTP_LEASE_CUTOFF); + if (!strcasecmp(atom + 13, "-lease-length")) + return (DYNAMIC_BOOTP_LEASE_LENGTH); break; } break; - case 'e': - if (!strcasecmp (atom + 1, "thernet")) - return ETHERNET; - if (!strcasecmp (atom + 1, "nds")) - return ENDS; - if (!strcasecmp (atom + 1, "xpire")) - return EXPIRE; + case 'e': + if (!strcasecmp(atom + 1, "thernet")) + return (ETHERNET); + if (!strcasecmp(atom + 1, "nds")) + return (ENDS); + if (!strcasecmp(atom + 1, "xpire")) + return (EXPIRE); break; - case 'f': - if (!strcasecmp (atom + 1, "ilename")) - return FILENAME; - if (!strcasecmp (atom + 1, "ixed-address")) - return FIXED_ADDR; - if (!strcasecmp (atom + 1, "ddi")) - return FDDI; + case 'f': + if (!strcasecmp(atom + 1, "ilename")) + return (FILENAME); + if (!strcasecmp(atom + 1, "ixed-address")) + return (FIXED_ADDR); + if (!strcasecmp(atom + 1, "ddi")) + return (FDDI); break; - case 'g': - if (!strcasecmp (atom + 1, "iaddr")) - return GIADDR; - if (!strcasecmp (atom + 1, "roup")) - return GROUP; - if (!strcasecmp (atom + 1, "et-lease-hostnames")) - return GET_LEASE_HOSTNAMES; + case 'g': + if (!strcasecmp(atom + 1, "iaddr")) + return (GIADDR); + if (!strcasecmp(atom + 1, "roup")) + return (GROUP); + if (!strcasecmp(atom + 1, "et-lease-hostnames")) + return (GET_LEASE_HOSTNAMES); break; - case 'h': - if (!strcasecmp (atom + 1, "ost")) - return HOST; - if (!strcasecmp (atom + 1, "ardware")) - return HARDWARE; - if (!strcasecmp (atom + 1, "ostname")) - return HOSTNAME; + case 'h': + if (!strcasecmp(atom + 1, "ost")) + return (HOST); + if (!strcasecmp(atom + 1, "ardware")) + return (HARDWARE); + if (!strcasecmp(atom + 1, "ostname")) + return (HOSTNAME); break; - case 'i': - if (!strcasecmp (atom + 1, "nitial-interval")) - return INITIAL_INTERVAL; - if (!strcasecmp (atom + 1, "nterface")) - return INTERFACE; + case 'i': + if (!strcasecmp(atom + 1, "nitial-interval")) + return (INITIAL_INTERVAL); + if (!strcasecmp(atom + 1, "nterface")) + return (INTERFACE); break; - case 'l': - if (!strcasecmp (atom + 1, "ease")) - return LEASE; + case 'l': + if (!strcasecmp(atom + 1, "ease")) + return (LEASE); break; - case 'm': - if (!strcasecmp (atom + 1, "ax-lease-time")) - return MAX_LEASE_TIME; + case 'm': + if (!strcasecmp(atom + 1, "ax-lease-time")) + return (MAX_LEASE_TIME); if (!strncasecmp (atom + 1, "edi", 3)) { - if (!strcasecmp (atom + 4, "a")) - return MEDIA; - if (!strcasecmp (atom + 4, "um")) - return MEDIUM; + if (!strcasecmp(atom + 4, "a")) + return (MEDIA); + if (!strcasecmp(atom + 4, "um")) + return (MEDIUM); break; } break; - case 'n': - if (!strcasecmp (atom + 1, "ameserver")) - return NAMESERVER; - if (!strcasecmp (atom + 1, "etmask")) - return NETMASK; - if (!strcasecmp (atom + 1, "ext-server")) - return NEXT_SERVER; - if (!strcasecmp (atom + 1, "ot")) - return TOKEN_NOT; + case 'n': + if (!strcasecmp(atom + 1, "ameserver")) + return (NAMESERVER); + if (!strcasecmp(atom + 1, "etmask")) + return (NETMASK); + if (!strcasecmp(atom + 1, "ext-server")) + return (NEXT_SERVER); + if (!strcasecmp(atom + 1, "ot")) + return (TOKEN_NOT); break; - case 'o': - if (!strcasecmp (atom + 1, "ption")) - return OPTION; - if (!strcasecmp (atom + 1, "ne-lease-per-client")) - return ONE_LEASE_PER_CLIENT; + case 'o': + if (!strcasecmp(atom + 1, "ption")) + return (OPTION); + if (!strcasecmp(atom + 1, "ne-lease-per-client")) + return (ONE_LEASE_PER_CLIENT); break; - case 'p': - if (!strcasecmp (atom + 1, "repend")) - return PREPEND; - if (!strcasecmp (atom + 1, "acket")) - return PACKET; + case 'p': + if (!strcasecmp(atom + 1, "repend")) + return (PREPEND); + if (!strcasecmp(atom + 1, "acket")) + return (PACKET); break; - case 'r': - if (!strcasecmp (atom + 1, "ange")) - return RANGE; - if (!strcasecmp (atom + 1, "equest")) - return REQUEST; - if (!strcasecmp (atom + 1, "equire")) - return REQUIRE; - if (!strcasecmp (atom + 1, "etry")) - return RETRY; - if (!strcasecmp (atom + 1, "enew")) - return RENEW; - if (!strcasecmp (atom + 1, "ebind")) - return REBIND; - if (!strcasecmp (atom + 1, "eboot")) - return REBOOT; - if (!strcasecmp (atom + 1, "eject")) - return REJECT; + case 'r': + if (!strcasecmp(atom + 1, "ange")) + return (RANGE); + if (!strcasecmp(atom + 1, "equest")) + return (REQUEST); + if (!strcasecmp(atom + 1, "equire")) + return (REQUIRE); + if (!strcasecmp(atom + 1, "etry")) + return (RETRY); + if (!strcasecmp(atom + 1, "enew")) + return (RENEW); + if (!strcasecmp(atom + 1, "ebind")) + return (REBIND); + if (!strcasecmp(atom + 1, "eboot")) + return (REBOOT); + if (!strcasecmp(atom + 1, "eject")) + return (REJECT); break; - case 's': - if (!strcasecmp (atom + 1, "earch")) - return SEARCH; - if (!strcasecmp (atom + 1, "tarts")) - return STARTS; - if (!strcasecmp (atom + 1, "iaddr")) - return SIADDR; - if (!strcasecmp (atom + 1, "ubnet")) - return SUBNET; - if (!strcasecmp (atom + 1, "hared-network")) - return SHARED_NETWORK; - if (!strcasecmp (atom + 1, "erver-name")) - return SERVER_NAME; - if (!strcasecmp (atom + 1, "erver-identifier")) - return SERVER_IDENTIFIER; - if (!strcasecmp (atom + 1, "elect-timeout")) - return SELECT_TIMEOUT; - if (!strcasecmp (atom + 1, "end")) - return SEND; - if (!strcasecmp (atom + 1, "cript")) - return SCRIPT; - if (!strcasecmp (atom + 1, "upersede")) - return SUPERSEDE; + case 's': + if (!strcasecmp(atom + 1, "earch")) + return (SEARCH); + if (!strcasecmp(atom + 1, "tarts")) + return (STARTS); + if (!strcasecmp(atom + 1, "iaddr")) + return (SIADDR); + if (!strcasecmp(atom + 1, "ubnet")) + return (SUBNET); + if (!strcasecmp(atom + 1, "hared-network")) + return (SHARED_NETWORK); + if (!strcasecmp(atom + 1, "erver-name")) + return (SERVER_NAME); + if (!strcasecmp(atom + 1, "erver-identifier")) + return (SERVER_IDENTIFIER); + if (!strcasecmp(atom + 1, "elect-timeout")) + return (SELECT_TIMEOUT); + if (!strcasecmp(atom + 1, "end")) + return (SEND); + if (!strcasecmp(atom + 1, "cript")) + return (SCRIPT); + if (!strcasecmp(atom + 1, "upersede")) + return (SUPERSEDE); break; - case 't': - if (!strcasecmp (atom + 1, "imestamp")) - return TIMESTAMP; - if (!strcasecmp (atom + 1, "imeout")) - return TIMEOUT; - if (!strcasecmp (atom + 1, "oken-ring")) - return TOKEN_RING; + case 't': + if (!strcasecmp(atom + 1, "imestamp")) + return (TIMESTAMP); + if (!strcasecmp(atom + 1, "imeout")) + return (TIMEOUT); + if (!strcasecmp(atom + 1, "oken-ring")) + return (TOKEN_RING); break; - case 'u': + case 'u': if (!strncasecmp (atom + 1, "se", 2)) { - if (!strcasecmp (atom + 3, "r-class")) - return USER_CLASS; - if (!strcasecmp (atom + 3, "-host-decl-names")) - return USE_HOST_DECL_NAMES; - if (!strcasecmp (atom + 3, + if (!strcasecmp(atom + 3, "r-class")) + return (USER_CLASS); + if (!strcasecmp(atom + 3, "-host-decl-names")) + return (USE_HOST_DECL_NAMES); + if (!strcasecmp(atom + 3, "-lease-addr-for-default-route")) - return USE_LEASE_ADDR_FOR_DEFAULT_ROUTE; + return (USE_LEASE_ADDR_FOR_DEFAULT_ROUTE); break; } - if (!strcasecmp (atom + 1, "id")) - return UID; - if (!strcasecmp (atom + 1, "nknown-clients")) - return UNKNOWN_CLIENTS; + if (!strcasecmp(atom + 1, "id")) + return (UID); + if (!strcasecmp(atom + 1, "nknown-clients")) + return (UNKNOWN_CLIENTS); break; - case 'v': - if (!strcasecmp (atom + 1, "endor-class")) - return VENDOR_CLASS; + case 'v': + if (!strcasecmp(atom + 1, "endor-class")) + return (VENDOR_CLASS); break; - case 'y': - if (!strcasecmp (atom + 1, "iaddr")) - return YIADDR; + case 'y': + if (!strcasecmp(atom + 1, "iaddr")) + return (YIADDR); break; } - return dfv; + return (dfv); } diff --git a/sbin/dhclient/convert.c b/sbin/dhclient/convert.c index 12afe87a40a..ab8c52c3925 100644 --- a/sbin/dhclient/convert.c +++ b/sbin/dhclient/convert.c @@ -43,71 +43,72 @@ #include "dhcpd.h" -u_int32_t getULong (buf) - unsigned char *buf; +u_int32_t +getULong(unsigned char *buf) { - u_int32_t ibuf; + u_int32_t ibuf; - memcpy (&ibuf, buf, sizeof (ibuf)); - return ntohl (ibuf); + memcpy(&ibuf, buf, sizeof(ibuf)); + return (ntohl(ibuf)); } -int32_t getLong (buf) - unsigned char *buf; +int32_t +getLong(unsigned char *(buf)) { - int32_t ibuf; + int32_t ibuf; - memcpy (&ibuf, buf, sizeof (ibuf)); - return ntohl (ibuf); + memcpy(&ibuf, buf, sizeof(ibuf)); + return (ntohl(ibuf)); } -u_int16_t getUShort (buf) - unsigned char *buf; +u_int16_t +getUShort(unsigned char *buf) { - u_int16_t ibuf; + u_int16_t ibuf; - memcpy (&ibuf, buf, sizeof (ibuf)); - return ntohs (ibuf); + memcpy(&ibuf, buf, sizeof(ibuf)); + return (ntohs(ibuf)); } -int16_t getShort (buf) - unsigned char *buf; +int16_t +getShort(unsigned char *buf) { - int16_t ibuf; + int16_t ibuf; - memcpy (&ibuf, buf, sizeof (ibuf)); - return ntohs (ibuf); + memcpy(&ibuf, buf, sizeof(ibuf)); + + return (ntohs(ibuf)); } -void putULong (obuf, val) - unsigned char *obuf; - u_int32_t val; +void +putULong(unsigned char *obuf, u_int32_t val) { - u_int32_t tmp = htonl (val); - memcpy (obuf, &tmp, sizeof tmp); + u_int32_t tmp = htonl(val); + + memcpy(obuf, &tmp, sizeof tmp); } -void putLong (obuf, val) - unsigned char *obuf; - int32_t val; +void +putLong(unsigned char *obuf, int32_t val) { - int32_t tmp = htonl (val); - memcpy (obuf, &tmp, sizeof tmp); + int32_t tmp = htonl(val); + + memcpy(obuf, &tmp, sizeof(tmp)); } -void putUShort (obuf, val) - unsigned char *obuf; - unsigned int val; +void +putUShort(unsigned char *obuf, unsigned int val) { - u_int16_t tmp = htons (val); - memcpy (obuf, &tmp, sizeof tmp); + u_int16_t tmp = htons(val); + + memcpy(obuf, &tmp, sizeof(tmp)); } -void putShort (obuf, val) - unsigned char *obuf; - int val; +void +putShort (unsigned char *obuf, int val) { - int16_t tmp = htons (val); - memcpy (obuf, &tmp, sizeof tmp); + int16_t tmp = htons(val); + + memcpy(obuf, &tmp, sizeof(tmp)); } diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 2c0b82b391b..f7fc46ef328 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -69,10 +69,12 @@ #define middlechar(c) (borderchar(c) || hyphenchar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) +#define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" + TIME cur_time; TIME default_lease_time = 43200; /* 12 hours... */ TIME max_lease_time = 86400; /* 24 hours... */ -struct tree_cache *global_options [256]; +struct tree_cache *global_options[256]; char *path_dhclient_conf = _PATH_DHCLIENT_CONF; char *path_dhclient_db = _PATH_DHCLIENT_DB; @@ -101,12 +103,12 @@ int unknown_ok = 1; static char copyright[] = "Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium."; -static char arr [] = "All rights reserved."; -static char message [] = "Internet Software Consortium DHCP Client"; -static char contrib [] = "Please contribute if you find this software useful."; -static char url [] = "For info, please visit http://www.isc.org/dhcp-contrib.html"; +static char arr[] = "All rights reserved."; +static char message[] = "Internet Software Consortium DHCP Client"; +static char contrib[] = "Please contribute if you find this software useful."; +static char url[] = "For info, please visit http://www.isc.org/dhcp-contrib.html"; -static void usage PROTO ((char *)); +static void usage(char *); static int check_option (struct client_lease *l, int option); @@ -210,16 +212,15 @@ routehandler(struct protocol *p) return; die: - script_init(ip, "FAIL", (struct string_list *)0); + script_init(ip, "FAIL", NULL); if (ip->client->alias) script_write_params(ip, "alias_", ip->client->alias); script_go(ip); exit(1); } -int main (argc, argv) - int argc; - char **argv; +int +main(int argc, char *argv[]) { int i, fd; struct servent *ent; @@ -228,60 +229,56 @@ int main (argc, argv) int quiet = 0; char *s; - s = strrchr (argv [0], '/'); + s = strrchr(argv[0], '/'); if (!s) - s = argv [0]; + s = argv[0]; else s++; /* Initially, log errors to stderr as well as to syslogd. */ - openlog (s, LOG_NDELAY, DHCPD_LOG_FACILITY); - -#if !(defined (DEBUG) || defined (SYSLOG_4_2) || defined (__CYGWIN32__)) - setlogmask (LOG_UPTO (LOG_INFO)); -#endif + openlog(s, LOG_NDELAY, DHCPD_LOG_FACILITY); + setlogmask(LOG_UPTO(LOG_INFO)); for (i = 1; i < argc; i++) { - if (!strcmp (argv [i], "-p")) { + if (!strcmp(argv[i], "-p")) { if (++i == argc) - usage (s); - local_port = htons(atoi(argv [i])); + usage(s); + local_port = htons(atoi(argv[i])); debug("binding to user-specified port %d", - ntohs(local_port)); - } else if (!strcmp (argv [i], "-d")) { + ntohs(local_port)); + } else if (!strcmp(argv[i], "-d")) { no_daemon = 1; - } else if (!strcmp (argv [i], "-D")) { + } else if (!strcmp(argv[i], "-D")) { save_scripts = 1; - } else if (!strcmp (argv [i], "-cf")) { + } else if (!strcmp(argv[i], "-cf")) { if (++i == argc) usage (s); - path_dhclient_conf = argv [i]; - } else if (!strcmp (argv [i], "-pf")) { + path_dhclient_conf = argv[i]; + } else if (!strcmp(argv[i], "-pf")) { if (++i == argc) usage (s); - path_dhclient_pid = argv [i]; - } else if (!strcmp (argv [i], "-lf")) { + path_dhclient_pid = argv[i]; + } else if (!strcmp(argv[i], "-lf")) { if (++i == argc) usage (s); - path_dhclient_db = argv [i]; - } else if (!strcmp (argv [i], "-q")) { + path_dhclient_db = argv[i]; + } else if (!strcmp(argv[i], "-q")) { quiet = 1; quiet_interface_discovery = 1; - } else if (!strcmp (argv [i], "-u")) { + } else if (!strcmp(argv[i], "-u")) { unknown_ok = 0; - } else if (!strcmp (argv [i], "-1")) { + } else if (!strcmp(argv[i], "-1")) { onetry = 1; - } else if (argv [i][0] == '-') { + } else if (argv[i][0] == '-') { usage (s); } else { struct interface_info *tmp = - ((struct interface_info *) - dmalloc (sizeof *tmp, "specified_interface")); + dmalloc (sizeof *tmp, "specified_interface"); if (!tmp) error ("Insufficient memory to %s %s", - "record interface", argv [i]); - memset (tmp, 0, sizeof *tmp); - strlcpy (tmp->name, argv [i], IFNAMSIZ); + "record interface", argv[i]); + memset(tmp, 0, sizeof *tmp); + strlcpy(tmp->name, argv[i], IFNAMSIZ); tmp->next = interfaces; tmp->flags = INTERFACE_REQUESTED; interfaces_requested = 1; @@ -335,9 +332,8 @@ int main (argc, argv) /* If no broadcast interfaces were discovered, call the script and tell it so. */ if (!interfaces) { - script_init((struct interface_info *)0, "NBI", - (struct string_list *)0); - script_go((struct interface_info *)0); + script_init(NULL, "NBI", NULL); + script_go(NULL); note("No broadcast interfaces found - exiting."); /* Nothing more to do. */ @@ -352,7 +348,7 @@ int main (argc, argv) INTERFACE_AUTOMATIC)) != INTERFACE_REQUESTED)) continue; - script_init(ip, "PREINIT", (struct string_list *)0); + script_init(ip, "PREINIT", NULL); if (ip->client->alias) script_write_params(ip, "alias_", ip->client->alias); @@ -368,9 +364,8 @@ int main (argc, argv) are relevant should be running, so now we once again call discover_interfaces(), and this time ask it to actually set up the interfaces. */ - discover_interfaces(interfaces_requested - ? DISCOVER_REQUESTED - : DISCOVER_RUNNING); + discover_interfaces(interfaces_requested ? DISCOVER_REQUESTED : + DISCOVER_RUNNING); /* Make up a seed for the random number generator from current time plus the sum of the last four bytes of each @@ -380,9 +375,8 @@ int main (argc, argv) seed = 0; /* Unfortunately, what's on the stack isn't random. :') */ for(ip = interfaces; ip; ip = ip->next) { int junk; - memcpy(&junk, - &ip->hw_address.haddr [ip->hw_address.hlen - - sizeof seed], sizeof seed); + memcpy(&junk, &ip->hw_address.haddr[ip->hw_address.hlen - + sizeof seed], sizeof seed); seed += junk; } srandom(seed + cur_time); @@ -400,11 +394,11 @@ int main (argc, argv) dispatch(); /*NOTREACHED*/ - return 0; + return (0); } -static void usage (appname) - char *appname; +static void +usage (char *appname) { note("%s", message); note("%s", copyright); @@ -451,14 +445,13 @@ void cleanup () * can no longer legitimately use the lease. */ -void state_reboot (ipp) - void *ipp; +void +state_reboot (void *ipp) { struct interface_info *ip = ipp; /* If we don't remember an active lease, go straight to INIT. */ - if (!ip->client->active || - ip->client->active->is_bootp) { + if (!ip->client->active || ip->client->active->is_bootp) { state_init (ip); return; } @@ -469,27 +462,27 @@ void state_reboot (ipp) /* make_request doesn't initialize xid because it normally comes from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER, so pick an xid now. */ - ip->client->xid = random (); + ip->client->xid = random(); /* Make a DHCPREQUEST packet, and set appropriate per-interface flags. */ - make_request (ip, ip->client->active); + make_request(ip, ip->client->active); ip->client->destination = iaddr_broadcast; ip->client->first_sending = cur_time; ip->client->interval = ip->client->config->initial_interval; /* Zap the medium list... */ - ip->client->medium = (struct string_list *)0; + ip->client->medium = NULL; /* Send out the first DHCPREQUEST packet. */ - send_request (ip); + send_request(ip); } /* Called when a lease has completely expired and we've been unable to renew it. */ -void state_init (ipp) - void *ipp; +void +state_init(void *ipp) { struct interface_info *ip = ipp; @@ -506,14 +499,14 @@ void state_init (ipp) /* Add an immediate timeout to cause the first DHCPDISCOVER packet to go out. */ - send_discover (ip); + send_discover(ip); } /* state_selecting is called when one or more DHCPOFFER packets have been received and a configurable period of time has passed. */ -void state_selecting (ipp) - void *ipp; +void +state_selecting(void *ipp) { struct interface_info *ip = ipp; @@ -523,39 +516,39 @@ void state_selecting (ipp) /* Cancel state_selecting and send_discover timeouts, since either one could have got us here. */ - cancel_timeout (state_selecting, ip); - cancel_timeout (send_discover, ip); + cancel_timeout(state_selecting, ip); + cancel_timeout(send_discover, ip); /* We have received one or more DHCPOFFER packets. Currently, the only criterion by which we judge leases is whether or not we get a response when we arp for them. */ - picked = (struct client_lease *)0; + picked = NULL; for (lp = ip->client->offered_leases; lp; lp = next) { next = lp->next; /* Check to see if we got an ARPREPLY for the address in this particular lease. */ if (!picked) { - script_init (ip, "ARPCHECK", lp->medium); - script_write_params (ip, "check_", lp); + script_init(ip, "ARPCHECK", lp->medium); + script_write_params(ip, "check_", lp); /* If the ARPCHECK code detects another machine using the offered address, it exits nonzero. We need to send a DHCPDECLINE and toss the lease. */ if (script_go (ip)) { - make_decline (ip, lp); - send_decline (ip); + make_decline(ip, lp); + send_decline(ip); goto freeit; } picked = lp; - picked->next = (struct client_lease *)0; + picked->next = NULL; } else { - freeit: - free_client_lease (lp); +freeit: + free_client_lease(lp); } } - ip->client->offered_leases = (struct client_lease *)0; + ip->client->offered_leases = NULL; /* If we just tossed all the leases we were offered, go back to square one. */ @@ -566,7 +559,7 @@ void state_selecting (ipp) } /* If it was a BOOTREPLY, we can just take the address right now. */ - if (!picked->options [DHO_DHCP_MESSAGE_TYPE].len) { + if (!picked->options[DHO_DHCP_MESSAGE_TYPE].len) { ip->client->new = picked; /* Make up some lease expiry times @@ -578,7 +571,7 @@ void state_selecting (ipp) ip->client->state = S_REQUESTING; /* Bind to the address we received. */ - bind_lease (ip); + bind_lease(ip); return; } @@ -589,21 +582,21 @@ void state_selecting (ipp) ip->client->interval = ip->client->config->initial_interval; /* Make a DHCPREQUEST packet from the lease we picked. */ - make_request (ip, picked); + make_request(ip, picked); ip->client->xid = ip->client->packet.xid; /* Toss the lease we picked - we'll get it back in a DHCPACK. */ - free_client_lease (picked); + free_client_lease(picked); /* Add an immediate timeout to send the first DHCPREQUEST packet. */ - send_request (ip); + send_request(ip); } /* state_requesting is called when we receive a DHCPACK message after having sent out one or more DHCPREQUEST packets. */ -void dhcpack (packet) - struct packet *packet; +void +dhcpack(struct packet *packet) { struct interface_info *ip = packet->interface; struct client_lease *lease; @@ -611,10 +604,9 @@ void dhcpack (packet) /* If we're not receptive to an offer right now, or if the offer has an unrecognizable transaction id, then just drop it. */ if (packet->interface->client->xid != packet->raw->xid || - (packet->interface->hw_address.hlen != - packet->raw->hlen) || - (memcmp (packet->interface->hw_address.haddr, - packet->raw->chaddr, packet->raw->hlen))) { + (packet->interface->hw_address.hlen != packet->raw->hlen) || + (memcmp(packet->interface->hw_address.haddr, + packet->raw->chaddr, packet->raw->hlen))) { #if defined (DEBUG) debug ("DHCPACK in wrong transaction."); #endif @@ -631,24 +623,23 @@ void dhcpack (packet) return; } - note ("DHCPACK from %s", piaddr (packet->client_addr)); + note("DHCPACK from %s", piaddr (packet->client_addr)); - lease = packet_to_lease (packet); + lease = packet_to_lease(packet); if (!lease) { - note ("packet_to_lease failed."); + note("packet_to_lease failed."); return; } ip->client->new = lease; /* Stop resending DHCPREQUEST. */ - cancel_timeout (send_request, ip); + cancel_timeout(send_request, ip); /* Figure out the lease time. */ - if (ip->client->new->options [DHO_DHCP_LEASE_TIME].data) - ip->client->new->expiry = - getULong (ip->client -> - new->options [DHO_DHCP_LEASE_TIME].data); + if (ip->client->new->options[DHO_DHCP_LEASE_TIME].data) + ip->client->new->expiry = getULong( + ip->client->new->options[DHO_DHCP_LEASE_TIME].data); else ip->client->new->expiry = default_lease_time; /* A number that looks negative here is really just very large, @@ -658,24 +649,19 @@ void dhcpack (packet) /* Take the server-provided renewal time if there is one; otherwise figure it out according to the spec. */ - if (ip->client->new->options [DHO_DHCP_RENEWAL_TIME].len) - ip->client->new->renewal = - getULong (ip->client -> - new->options [DHO_DHCP_RENEWAL_TIME].data); + if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len) + ip->client->new->renewal = getULong( + ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data); else - ip->client->new->renewal = - ip->client->new->expiry / 2; + ip->client->new->renewal = ip->client->new->expiry / 2; /* Same deal with the rebind time. */ - if (ip->client->new->options [DHO_DHCP_REBINDING_TIME].len) - ip->client->new->rebind = - getULong (ip->client->new -> - options [DHO_DHCP_REBINDING_TIME].data); + if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len) + ip->client->new->rebind = getULong( + ip->client->new->options[DHO_DHCP_REBINDING_TIME].data); else - ip->client->new->rebind = - ip->client->new->renewal + - ip->client->new->renewal / 2 + - ip->client->new->renewal / 4; + ip->client->new->rebind = ip->client->new->renewal + + ip->client->new->renewal / 2 + ip->client->new->renewal / 4; ip->client->new->expiry += cur_time; /* Lease lengths can never be negative. */ @@ -688,26 +674,23 @@ void dhcpack (packet) if (ip->client->new->rebind < cur_time) ip->client->new->rebind = TIME_MAX; - bind_lease (ip); + bind_lease(ip); } -void bind_lease (ip) - struct interface_info *ip; +void +bind_lease(struct interface_info *ip) { /* Remember the medium. */ ip->client->new->medium = ip->client->medium; /* Write out the new lease. */ - write_client_lease (ip, ip->client->new, 0); + write_client_lease(ip, ip->client->new, 0); /* Run the client script with the new parameters. */ - script_init (ip, (ip->client->state == S_REQUESTING - ? "BOUND" - : (ip->client->state == S_RENEWING - ? "RENEW" - : (ip->client->state == S_REBOOTING - ? "REBOOT" : "REBIND"))), - ip->client->new->medium); + script_init(ip, (ip->client->state == S_REQUESTING ? "BOUND" : + (ip->client->state == S_RENEWING ? "RENEW" : + (ip->client->state == S_REBOOTING ? "REBOOT" : "REBIND"))), + ip->client->new->medium); if (ip->client->active && ip->client->state != S_REBOOTING) script_write_params (ip, "old_", ip->client->active); script_write_params (ip, "new_", ip->client->new); @@ -719,18 +702,17 @@ void bind_lease (ip) if (ip->client->active) free_client_lease (ip->client->active); ip->client->active = ip->client->new; - ip->client->new = (struct client_lease *)0; + ip->client->new = NULL; /* Set up a timeout to start the renewal process. */ - add_timeout (ip->client->active->renewal, - state_bound, ip); + add_timeout (ip->client->active->renewal, state_bound, ip); note ("bound to %s -- renewal in %d seconds.", - piaddr (ip->client->active->address), - ip->client->active->renewal - cur_time); + piaddr (ip->client->active->address), + ip->client->active->renewal - cur_time); ip->client->state = S_BOUND; - reinitialize_interfaces (); - go_daemon (); + reinitialize_interfaces(); + go_daemon(); } /* state_bound is called when we've successfully bound to a particular @@ -738,22 +720,20 @@ void bind_lease (ip) expected to unicast a DHCPREQUEST to the server that gave us our original lease. */ -void state_bound (ipp) - void *ipp; +void +state_bound (void *ipp) { struct interface_info *ip = ipp; ASSERT_STATE(state, S_BOUND); /* T1 has expired. */ - make_request (ip, ip->client->active); + make_request(ip, ip->client->active); ip->client->xid = ip->client->packet.xid; - if (ip->client->active -> - options [DHO_DHCP_SERVER_IDENTIFIER].len == 4) { - memcpy (ip->client->destination.iabuf, - ip->client->active -> - options [DHO_DHCP_SERVER_IDENTIFIER].data, 4); + if (ip->client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) { + memcpy(ip->client->destination.iabuf, ip->client->active-> + options[DHO_DHCP_SERVER_IDENTIFIER].data, 4); ip->client->destination.len = 4; } else ip->client->destination = iaddr_broadcast; @@ -763,26 +743,28 @@ void state_bound (ipp) ip->client->state = S_RENEWING; /* Send the first packet immediately. */ - send_request (ip); + send_request(ip); } -int commit_leases () +int +commit_leases(void) { - return 0; + return (0); } -int write_lease (lease) - struct lease *lease; +int +write_lease(struct lease *lease) { - return 0; + return (0); } -void db_startup () +void +db_startup(void) { } -void bootp (packet) - struct packet *packet; +void +bootp(struct packet *packet) { struct iaddrlist *ap; @@ -793,41 +775,35 @@ void bootp (packet) on it. */ for (ap = packet->interface->client->config->reject_list; ap; ap = ap->next) { - if (addr_eq (packet->client_addr, ap->addr)) { - note ("BOOTREPLY from %s rejected.", - piaddr (ap->addr)); + if (addr_eq(packet->client_addr, ap->addr)) { + note("BOOTREPLY from %s rejected.", piaddr(ap->addr)); return; } - } - - dhcpoffer (packet); - + } + dhcpoffer(packet); } -void dhcp (packet) - struct packet *packet; +void +dhcp(struct packet *packet) { struct iaddrlist *ap; - void (*handler) PROTO ((struct packet *)); + void (*handler)(struct packet *); char *type; switch (packet->packet_type) { - case DHCPOFFER: + case DHCPOFFER: handler = dhcpoffer; type = "DHCPOFFER"; break; - - case DHCPNAK: + case DHCPNAK: handler = dhcpnak; type = "DHCPNACK"; break; - - case DHCPACK: + case DHCPACK: handler = dhcpack; type = "DHCPACK"; break; - - default: + default: return; } @@ -836,23 +812,22 @@ void dhcp (packet) for (ap = packet->interface->client->config->reject_list; ap; ap = ap->next) { if (addr_eq (packet->client_addr, ap->addr)) { - note ("%s from %s rejected.", - type, piaddr (ap->addr)); + note("%s from %s rejected.", type, piaddr(ap->addr)); return; } } - (*handler) (packet); + (*handler)(packet); } -void dhcpoffer (packet) - struct packet *packet; +void +dhcpoffer(struct packet *packet) { struct interface_info *ip = packet->interface; struct client_lease *lease, *lp; int i; int arp_timeout_needed, stop_selecting; - char *name = (packet->options [DHO_DHCP_MESSAGE_TYPE].len - ? "DHCPOFFER" : "BOOTREPLY"); + char *name = + (packet->options[DHO_DHCP_MESSAGE_TYPE].len ? "DHCPOFFER" : "BOOTREPLY"); #ifdef DEBUG_PACKET dump_packet (packet); @@ -862,25 +837,24 @@ void dhcpoffer (packet) has an unrecognizable transaction id, then just drop it. */ if (ip->client->state != S_SELECTING || packet->interface->client->xid != packet->raw->xid || - (packet->interface->hw_address.hlen != - packet->raw->hlen) || - (memcmp (packet->interface->hw_address.haddr, - packet->raw->chaddr, packet->raw->hlen))) { + (packet->interface->hw_address.hlen != packet->raw->hlen) || + (memcmp(packet->interface->hw_address.haddr, + packet->raw->chaddr, packet->raw->hlen))) { #if defined (DEBUG) debug ("%s in wrong transaction.", name); #endif return; } - note ("%s from %s", name, piaddr (packet->client_addr)); + note("%s from %s", name, piaddr(packet->client_addr)); /* If this lease doesn't supply the minimum required parameters, blow it off. */ - for (i = 0; ip->client->config->required_options [i]; i++) { - if (!packet->options [ip->client->config -> - required_options [i]].len) { - note ("%s isn't satisfactory.", name); + for (i = 0; ip->client->config->required_options[i]; i++) { + if (!packet->options[ip->client->config-> + required_options[i]].len) { + note("%s isn't satisfactory.", name); return; } } @@ -890,7 +864,7 @@ void dhcpoffer (packet) lease; lease = lease->next) { if (lease->address.len == sizeof packet->raw->yiaddr && !memcmp (lease->address.iabuf, - &packet->raw->yiaddr, lease->address.len)) { + &packet->raw->yiaddr, lease->address.len)) { debug ("%s already seen.", name); return; } @@ -898,38 +872,38 @@ void dhcpoffer (packet) lease = packet_to_lease (packet); if (!lease) { - note ("packet_to_lease failed."); + note("packet_to_lease failed."); return; } /* If this lease was acquired through a BOOTREPLY, record that fact. */ - if (!packet->options [DHO_DHCP_MESSAGE_TYPE].len) + if (!packet->options[DHO_DHCP_MESSAGE_TYPE].len) lease->is_bootp = 1; /* Record the medium under which this lease was offered. */ lease->medium = ip->client->medium; /* Send out an ARP Request for the offered IP address. */ - script_init (ip, "ARPSEND", lease->medium); - script_write_params (ip, "check_", lease); + script_init(ip, "ARPSEND", lease->medium); + script_write_params(ip, "check_", lease); /* If the script can't send an ARP request without waiting, we'll be waiting when we do the ARPCHECK, so don't wait now. */ - if (script_go (ip)) + if (script_go(ip)) arp_timeout_needed = 0; else arp_timeout_needed = 2; /* Figure out when we're supposed to stop selecting. */ - stop_selecting = (ip->client->first_sending + - ip->client->config->select_interval); + stop_selecting = + (ip->client->first_sending + ip->client->config->select_interval); /* If this is the lease we asked for, put it at the head of the list, and don't mess with the arp request timeout. */ if (lease->address.len == ip->client->requested_address.len && - !memcmp (lease->address.iabuf, - ip->client->requested_address.iabuf, - ip->client->requested_address.len)) { + !memcmp(lease->address.iabuf, + ip->client->requested_address.iabuf, + ip->client->requested_address.len)) { lease->next = ip->client->offered_leases; ip->client->offered_leases = lease; } else { @@ -942,13 +916,13 @@ void dhcpoffer (packet) arp_timeout_needed = 0; /* Put the lease at the end of the list. */ - lease->next = (struct client_lease *)0; + lease->next = NULL; if (!ip->client->offered_leases) ip->client->offered_leases = lease; else { for (lp = ip->client->offered_leases; lp->next; - lp = lp->next) - ; + lp = lp->next) + ; /* nothing */ lp->next = lease; } } @@ -973,103 +947,99 @@ void dhcpoffer (packet) /* Allocate a client_lease structure and initialize it from the parameters in the specified packet. */ -struct client_lease *packet_to_lease (packet) - struct packet *packet; +struct client_lease * +packet_to_lease(struct packet *packet) { struct client_lease *lease; int i; - lease = (struct client_lease *)malloc (sizeof (struct client_lease)); + lease = malloc(sizeof(struct client_lease)); if (!lease) { - warn ("dhcpoffer: no memory to record lease."); - return (struct client_lease *)0; + warn("dhcpoffer: no memory to record lease."); + return (NULL); } - memset (lease, 0, sizeof *lease); + memset(lease, 0, sizeof *lease); /* Copy the lease options. */ for (i = 0; i < 256; i++) { - if (packet->options [i].len) { - lease->options [i].data = - (unsigned char *) - malloc (packet->options [i].len + 1); - if (!lease->options [i].data) { - warn ("dhcpoffer: no memory for option %d", - i); - free_client_lease (lease); - return (struct client_lease *)0; + if (packet->options[i].len) { + lease->options[i].data = + malloc(packet->options[i].len + 1); + if (!lease->options[i].data) { + warn ("dhcpoffer: no memory for option %d", i); + free_client_lease(lease); + return (NULL); } else { - memcpy (lease->options [i].data, - packet->options [i].data, - packet->options [i].len); - lease->options [i].len = - packet->options [i].len; - lease->options [i].data - [lease->options [i].len] = 0; + memcpy(lease->options[i].data, + packet->options[i].data, + packet->options[i].len); + lease->options[i].len = + packet->options[i].len; + lease->options[i].data[lease->options[i].len] = + 0; } if (!check_option(lease,i)) { /* ignore a bogus lease offer */ warn ("Invalid lease option - ignoring offer"); - free_client_lease (lease); + free_client_lease(lease); return (NULL); } } } - lease->address.len = sizeof (packet->raw->yiaddr); - memcpy (lease->address.iabuf, &packet->raw->yiaddr, - lease->address.len); + lease->address.len = sizeof(packet->raw->yiaddr); + memcpy(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len); /* If the server name was filled out, copy it. */ - if ((!packet->options [DHO_DHCP_OPTION_OVERLOAD].len || - !(packet->options [DHO_DHCP_OPTION_OVERLOAD].data [0] & 2)) && - packet->raw->sname [0]) { - lease->server_name = malloc (DHCP_SNAME_LEN + 1); + if ((!packet->options[DHO_DHCP_OPTION_OVERLOAD].len || + !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) && + packet->raw->sname[0]) { + lease->server_name = malloc(DHCP_SNAME_LEN + 1); if (!lease->server_name) { - warn ("dhcpoffer: no memory for server name."); - free_client_lease (lease); - return (struct client_lease *)0; + warn("dhcpoffer: no memory for server name."); + free_client_lease(lease); + return (NULL); } memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN); lease->server_name[DHCP_SNAME_LEN]='\0'; - if (! res_hnok (lease->server_name) ) { - warn ("Bogus server name %s", lease->server_name ); - free_client_lease (lease); - return (struct client_lease *)0; + if (!res_hnok(lease->server_name) ) { + warn("Bogus server name %s", lease->server_name ); + free_client_lease(lease); + return (NULL); } } /* Ditto for the filename. */ - if ((!packet->options [DHO_DHCP_OPTION_OVERLOAD].len || - !(packet->options [DHO_DHCP_OPTION_OVERLOAD].data [0] & 1)) && - packet->raw->file [0]) { + if ((!packet->options[DHO_DHCP_OPTION_OVERLOAD].len || + !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) && + packet->raw->file[0]) { /* Don't count on the NUL terminator. */ lease->filename = malloc(DHCP_FILE_LEN + 1); if (!lease->filename) { - warn ("dhcpoffer: no memory for filename."); - free_client_lease (lease); - return (struct client_lease *)0; + warn("dhcpoffer: no memory for filename."); + free_client_lease(lease); + return (NULL); } memcpy(lease->filename, packet->raw->file, DHCP_FILE_LEN); lease->filename[DHCP_FILE_LEN]='\0'; } return lease; -} +} -void dhcpnak (packet) - struct packet *packet; +void +dhcpnak(struct packet *packet) { struct interface_info *ip = packet->interface; /* If we're not receptive to an offer right now, or if the offer has an unrecognizable transaction id, then just drop it. */ if (packet->interface->client->xid != packet->raw->xid || - (packet->interface->hw_address.hlen != - packet->raw->hlen) || - (memcmp (packet->interface->hw_address.haddr, - packet->raw->chaddr, packet->raw->hlen))) { + (packet->interface->hw_address.hlen != packet->raw->hlen) || + (memcmp(packet->interface->hw_address.haddr, + packet->raw->chaddr, packet->raw->hlen))) { #if defined (DEBUG) debug ("DHCPNAK in wrong transaction."); #endif @@ -1086,29 +1056,29 @@ void dhcpnak (packet) return; } - note ("DHCPNAK from %s", piaddr (packet->client_addr)); + note("DHCPNAK from %s", piaddr (packet->client_addr)); if (!ip->client->active) { - note ("DHCPNAK with no active lease.\n"); + note("DHCPNAK with no active lease.\n"); return; } - free_client_lease (ip->client->active); - ip->client->active = (struct client_lease *)0; + free_client_lease(ip->client->active); + ip->client->active = NULL; /* Stop sending DHCPREQUEST packets... */ - cancel_timeout (send_request, ip); + cancel_timeout(send_request, ip); ip->client->state = S_INIT; - state_init (ip); + state_init(ip); } /* Send out a DHCPDISCOVER packet, and set a timeout to send out another one after the right interval has expired. If we don't get an offer by the time we reach the panic interval, call the panic function. */ -void send_discover (ipp) - void *ipp; +void +send_discover(void *ipp) { struct interface_info *ip = ipp; @@ -1132,27 +1102,23 @@ void send_discover (ipp) if (!ip->client->offered_leases && ip->client->config->media) { int fail = 0; - again: +again: if (ip->client->medium) { - ip->client->medium = - ip->client->medium->next; + ip->client->medium = ip->client->medium->next; increase = 0; } if (!ip->client->medium) { if (fail) - error ("No valid media types for %s!", - ip->name); - ip->client->medium = - ip->client->config->media; + error("No valid media types for %s!", ip->name); + ip->client->medium = ip->client->config->media; increase = 1; } - note ("Trying medium \"%s\" %d", - ip->client->medium->string, increase); - script_init (ip, "MEDIUM", ip->client->medium); - if (script_go (ip)) { + note("Trying medium \"%s\" %d", ip->client->medium->string, + increase); + script_init(ip, "MEDIUM", ip->client->medium); + if (script_go (ip)) goto again; - } } /* If we're supposed to increase the interval, do so. If it's @@ -1202,13 +1168,10 @@ void send_discover (ipp) ntohs (sockaddr_broadcast.sin_port), ip->client->interval); /* Send out a packet. */ - result = send_packet (ip, (struct packet *)0, - &ip->client->packet, - ip->client->packet_length, - inaddr_any, &sockaddr_broadcast, - (struct hardware *)0); + result = send_packet(ip, NULL, &ip->client->packet, + ip->client->packet_length, inaddr_any, &sockaddr_broadcast, NULL); - add_timeout (cur_time + ip->client->interval, send_discover, ip); + add_timeout(cur_time + ip->client->interval, send_discover, ip); } /* state_panic gets called if we haven't received any offers in a preset @@ -1216,15 +1179,15 @@ void send_discover (ipp) haven't yet expired, and failing that, we call the client script and hope it can do something. */ -void state_panic (ipp) - void *ipp; +void +state_panic (void *ipp) { struct interface_info *ip = ipp; struct client_lease *loop = ip->client->active; struct client_lease *lp; - note ("No DHCPOFFERS received."); + note("No DHCPOFFERS received."); /* We may not have an active lease, but we may have some predefined leases that we can try. */ @@ -1234,17 +1197,16 @@ void state_panic (ipp) /* Run through the list of leases and see if one can be used. */ while (ip->client->active) { if (ip->client->active->expiry > cur_time) { - note ("Trying recorded lease %s", - piaddr (ip->client->active->address)); + note("Trying recorded lease %s", + piaddr(ip->client->active->address)); /* Run the client script with the existing parameters. */ - script_init (ip, "TIMEOUT", - ip->client->active->medium); - script_write_params (ip, "new_", - ip->client->active); + script_init(ip, "TIMEOUT", + ip->client->active->medium); + script_write_params(ip, "new_", ip->client->active); if (ip->client->alias) - script_write_params (ip, "alias_", - ip->client->alias); + script_write_params(ip, "alias_", + ip->client->alias); /* If the old lease is still good and doesn't yet need renewal, go into BOUND state and @@ -1254,18 +1216,18 @@ void state_panic (ipp) ip->client->active->renewal) { ip->client->state = S_BOUND; note ("bound: renewal in %d seconds.", - ip->client->active->renewal - - cur_time); - add_timeout ((ip->client -> - active->renewal), - state_bound, ip); + ip->client->active->renewal - + cur_time); + add_timeout( + ip->client->active->renewal, + state_bound, ip); } else { ip->client->state = S_BOUND; - note ("bound: immediate renewal."); - state_bound (ip); + note("bound: immediate renewal."); + state_bound(ip); } - reinitialize_interfaces (); - go_daemon (); + reinitialize_interfaces(); + go_daemon(); return; } } @@ -1273,19 +1235,18 @@ void state_panic (ipp) /* If there are no other leases, give up. */ if (!ip->client->leases) { ip->client->leases = ip->client->active; - ip->client->active = (struct client_lease *)0; + ip->client->active = NULL; break; } - activate_next: +activate_next: /* Otherwise, put the active lease at the end of the lease list, and try another lease.. */ for (lp = ip->client->leases; lp->next; lp = lp->next) ; lp->next = ip->client->active; - if (lp->next) { - lp->next->next = (struct client_lease *)0; - } + if (lp->next) + lp->next->next = NULL; ip->client->active = ip->client->leases; ip->client->leases = ip->client->leases->next; @@ -1303,19 +1264,19 @@ void state_panic (ipp) and try again later. */ if (onetry) exit(1); - note ("No working leases in persistent database - sleeping.\n"); - script_init (ip, "FAIL", (struct string_list *)0); + note("No working leases in persistent database - sleeping.\n"); + script_init(ip, "FAIL", NULL); if (ip->client->alias) - script_write_params (ip, "alias_", ip->client->alias); + script_write_params(ip, "alias_", ip->client->alias); script_go (ip); ip->client->state = S_INIT; - add_timeout (cur_time + ip->client->config->retry_interval, - state_init, ip); - go_daemon (); + add_timeout(cur_time + ip->client->config->retry_interval, state_init, + ip); + go_daemon(); } -void send_request (ipp) - void *ipp; +void +send_request(void *ipp) { struct interface_info *ip = ipp; @@ -1338,12 +1299,12 @@ void send_request (ipp) reused our old address. In the former case, we're hosed anyway. This is not a win-prone situation. */ if ((ip->client->state == S_REBOOTING || - ip->client->state == S_REQUESTING) && + ip->client->state == S_REQUESTING) && interval > ip->client->config->reboot_timeout) { - cancel: +cancel: ip->client->state = S_INIT; - cancel_timeout (send_request, ip); - state_init (ip); + cancel_timeout(send_request, ip); + state_init(ip); return; } @@ -1352,10 +1313,10 @@ void send_request (ipp) if (ip->client->state == S_REBOOTING && !ip->client->medium && ip->client->active->medium ) { - script_init (ip, "MEDIUM", ip->client->active->medium); + script_init(ip, "MEDIUM", ip->client->active->medium); /* If the medium we chose won't fly, go to INIT state. */ - if (script_go (ip)) + if (script_go(ip)) goto cancel; /* Record the medium. */ @@ -1367,43 +1328,37 @@ void send_request (ipp) if (ip->client->state != S_REQUESTING && cur_time > ip->client->active->expiry) { /* Run the client script with the new parameters. */ - script_init (ip, "EXPIRE", (struct string_list *)0); - script_write_params (ip, "old_", ip->client->active); + script_init(ip, "EXPIRE", NULL); + script_write_params(ip, "old_", ip->client->active); if (ip->client->alias) - script_write_params (ip, "alias_", - ip->client->alias); - script_go (ip); + script_write_params (ip, "alias_", ip->client->alias); + script_go(ip); /* Now do a preinit on the interface so that we can discover a new address. */ - script_init (ip, "PREINIT", (struct string_list *)0); + script_init(ip, "PREINIT", NULL); if (ip->client->alias) - script_write_params (ip, "alias_", - ip->client->alias); - script_go (ip); + script_write_params(ip, "alias_", ip->client->alias); + script_go(ip); ip->client->state = S_INIT; - state_init (ip); + state_init(ip); return; } /* Do the exponential backoff... */ if (!ip->client->interval) - ip->client->interval = - ip->client->config->initial_interval; - else { - ip->client->interval += - ((random () >> 2) % - (2 * ip->client->interval)); - } + ip->client->interval = ip->client->config->initial_interval; + else + ip->client->interval += ((random () >> 2) % + (2 * ip->client->interval)); /* Don't backoff past cutoff. */ if (ip->client->interval > ip->client->config->backoff_cutoff) ip->client->interval = - ((ip->client->config->backoff_cutoff / 2) - + ((random () >> 2) - % ip->client->interval)); + ((ip->client->config->backoff_cutoff / 2) + + ((random () >> 2) % ip->client->interval)); /* If the backoff would take us to the expiry time, just set the timeout to the expiry time. */ @@ -1411,7 +1366,7 @@ void send_request (ipp) cur_time + ip->client->interval > ip->client->active->expiry) ip->client->interval = - ip->client->active->expiry - cur_time + 1; + ip->client->active->expiry - cur_time + 1; /* If the lease T2 time has elapsed, or if we're not yet bound, broadcast the DHCPREQUEST rather than unicasting. */ @@ -1421,16 +1376,15 @@ void send_request (ipp) cur_time > ip->client->active->rebind) destination.sin_addr.s_addr = INADDR_BROADCAST; else - memcpy (&destination.sin_addr.s_addr, - ip->client->destination.iabuf, - sizeof destination.sin_addr.s_addr); + memcpy(&destination.sin_addr.s_addr, + ip->client->destination.iabuf, + sizeof destination.sin_addr.s_addr); destination.sin_port = remote_port; destination.sin_family = AF_INET; destination.sin_len = sizeof destination; if (ip->client->state != S_REQUESTING) - memcpy (&from, ip->client->active->address.iabuf, - sizeof from); + memcpy(&from, ip->client->active->address.iabuf, sizeof from); else from.s_addr = INADDR_ANY; @@ -1444,135 +1398,116 @@ void send_request (ipp) ip->client->packet.secs = htons (65535); } - note ("DHCPREQUEST on %s to %s port %d", ip->name, - inet_ntoa (destination.sin_addr), - ntohs (destination.sin_port)); + note("DHCPREQUEST on %s to %s port %d", ip->name, + inet_ntoa (destination.sin_addr), ntohs(destination.sin_port)); if (destination.sin_addr.s_addr != INADDR_BROADCAST && fallback_interface) - result = send_packet (fallback_interface, - (struct packet *)0, - &ip->client->packet, - ip->client->packet_length, - from, &destination, - (struct hardware *)0); + result = send_packet(fallback_interface, NULL, + &ip->client->packet, ip->client->packet_length, from, + &destination, NULL); else /* Send out a packet. */ - result = send_packet (ip, (struct packet *)0, - &ip->client->packet, - ip->client->packet_length, - from, &destination, - (struct hardware *)0); - - add_timeout (cur_time + ip->client->interval, - send_request, ip); + result = send_packet (ip, NULL, &ip->client->packet, + ip->client->packet_length, from, &destination, NULL); + + add_timeout(cur_time + ip->client->interval, send_request, ip); } -void send_decline (ipp) - void *ipp; +void +send_decline(void *ipp) { struct interface_info *ip = ipp; - int result; - note ("DHCPDECLINE on %s to %s port %d", ip->name, - inet_ntoa (sockaddr_broadcast.sin_addr), - ntohs (sockaddr_broadcast.sin_port)); + note("DHCPDECLINE on %s to %s port %d", ip->name, + inet_ntoa (sockaddr_broadcast.sin_addr), + ntohs (sockaddr_broadcast.sin_port)); /* Send out a packet. */ - result = send_packet (ip, (struct packet *)0, - &ip->client->packet, - ip->client->packet_length, - inaddr_any, &sockaddr_broadcast, - (struct hardware *)0); + result = send_packet(ip, NULL, &ip->client->packet, + ip->client->packet_length, inaddr_any, &sockaddr_broadcast, NULL); } -void send_release (ipp) - void *ipp; +void +send_release(void *ipp) { struct interface_info *ip = ipp; int result; - note ("DHCPRELEASE on %s to %s port %d", ip->name, - inet_ntoa (sockaddr_broadcast.sin_addr), - ntohs (sockaddr_broadcast.sin_port)); + note("DHCPRELEASE on %s to %s port %d", ip->name, + inet_ntoa (sockaddr_broadcast.sin_addr), + ntohs (sockaddr_broadcast.sin_port)); /* Send out a packet. */ - result = send_packet (ip, (struct packet *)0, - &ip->client->packet, - ip->client->packet_length, - inaddr_any, &sockaddr_broadcast, - (struct hardware *)0); + result = send_packet(ip, NULL, &ip->client->packet, + ip->client->packet_length, inaddr_any, &sockaddr_broadcast, NULL); } -void make_discover (ip, lease) - struct interface_info *ip; - struct client_lease *lease; +void +make_discover(struct interface_info *ip, struct client_lease *lease) { unsigned char discover = DHCPDISCOVER; int i; - struct tree_cache *options [256]; - struct tree_cache option_elements [256]; + struct tree_cache *options[256]; + struct tree_cache option_elements[256]; - memset (option_elements, 0, sizeof option_elements); - memset (options, 0, sizeof options); - memset (&ip->client->packet, 0, sizeof (ip->client->packet)); + memset(option_elements, 0, sizeof(option_elements)); + memset(options, 0, sizeof options); + memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */ i = DHO_DHCP_MESSAGE_TYPE; - options [i] = &option_elements [i]; - options [i]->value = &discover; - options [i]->len = sizeof discover; - options [i]->buf_size = sizeof discover; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &option_elements[i]; + options[i]->value = &discover; + options[i]->len = sizeof discover; + options[i]->buf_size = sizeof discover; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Request the options we want */ i = DHO_DHCP_PARAMETER_REQUEST_LIST; - options [i] = &option_elements [i]; - options [i]->value = ip->client->config->requested_options; - options [i]->len = ip->client->config->requested_option_count; - options [i]->buf_size = + options[i] = &option_elements[i]; + options[i]->value = ip->client->config->requested_options; + options[i]->len = ip->client->config->requested_option_count; + options[i]->buf_size = ip->client->config->requested_option_count; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* If we had an address, try to get it again. */ if (lease) { ip->client->requested_address = lease->address; i = DHO_DHCP_REQUESTED_ADDRESS; - options [i] = &option_elements [i]; - options [i]->value = lease->address.iabuf; - options [i]->len = lease->address.len; - options [i]->buf_size = lease->address.len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; - } else { + options[i] = &option_elements[i]; + options[i]->value = lease->address.iabuf; + options[i]->len = lease->address.len; + options[i]->buf_size = lease->address.len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; + } else ip->client->requested_address.len = 0; - } /* Send any options requested in the config file. */ - for (i = 0; i < 256; i++) { - if (!options [i] && - ip->client->config->send_options [i].data) { - options [i] = &option_elements [i]; - options [i]->value = ip->client->config -> - send_options [i].data; - options [i]->len = ip->client->config -> - send_options [i].len; - options [i]->buf_size = ip->client->config -> - send_options [i].len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + for (i = 0; i < 256; i++) + if (!options[i] && + ip->client->config->send_options[i].data) { + options[i] = &option_elements[i]; + options[i]->value = + ip->client->config->send_options[i].data; + options[i]->len = + ip->client->config->send_options[i].len; + options[i]->buf_size = + ip->client->config->send_options[i].len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; } - } /* Set up the option buffer... */ - ip->client->packet_length = - cons_options ((struct packet *)0, &ip->client->packet, 0, - options, 0, 0, 0, (u_int8_t *)0, 0); + ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, + options, 0, 0, 0, NULL, 0); if (ip->client->packet_length < BOOTP_MIN_LEN) ip->client->packet_length = BOOTP_MIN_LEN; @@ -1580,111 +1515,106 @@ void make_discover (ip, lease) ip->client->packet.htype = ip->hw_address.htype; ip->client->packet.hlen = ip->hw_address.hlen; ip->client->packet.hops = 0; - ip->client->packet.xid = arc4random (); + ip->client->packet.xid = arc4random(); ip->client->packet.secs = 0; /* filled in by send_discover. */ - if (can_receive_unicast_unconfigured (ip)) + if (can_receive_unicast_unconfigured(ip)) ip->client->packet.flags = 0; else - ip->client->packet.flags = htons (BOOTP_BROADCAST); - - memset (&(ip->client->packet.ciaddr), - 0, sizeof ip->client->packet.ciaddr); - memset (&(ip->client->packet.yiaddr), - 0, sizeof ip->client->packet.yiaddr); - memset (&(ip->client->packet.siaddr), - 0, sizeof ip->client->packet.siaddr); - memset (&(ip->client->packet.giaddr), - 0, sizeof ip->client->packet.giaddr); - memcpy (ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); + ip->client->packet.flags = htons(BOOTP_BROADCAST); + + memset(&(ip->client->packet.ciaddr), + 0, sizeof ip->client->packet.ciaddr); + memset(&(ip->client->packet.yiaddr), + 0, sizeof ip->client->packet.yiaddr); + memset(&(ip->client->packet.siaddr), + 0, sizeof ip->client->packet.siaddr); + memset(&(ip->client->packet.giaddr), + 0, sizeof ip->client->packet.giaddr); + memcpy(ip->client->packet.chaddr, + ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET - dump_packet (sendpkt); - dump_raw ((unsigned char *)ip->client->packet, - sendpkt->packet_length); + dump_packet(sendpkt); + dump_raw((unsigned char *)ip->client->packet, sendpkt->packet_length); #endif } -void make_request (ip, lease) - struct interface_info *ip; - struct client_lease *lease; +void +make_request(struct interface_info *ip, struct client_lease * lease) { unsigned char request = DHCPREQUEST; int i; - struct tree_cache *options [256]; - struct tree_cache option_elements [256]; + struct tree_cache *options[256]; + struct tree_cache option_elements[256]; - memset (options, 0, sizeof options); - memset (&ip->client->packet, 0, sizeof (ip->client->packet)); + memset(options, 0, sizeof options); + memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */ i = DHO_DHCP_MESSAGE_TYPE; - options [i] = &option_elements [i]; - options [i]->value = &request; - options [i]->len = sizeof request; - options [i]->buf_size = sizeof request; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &option_elements[i]; + options[i]->value = &request; + options[i]->len = sizeof request; + options[i]->buf_size = sizeof request; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Request the options we want */ i = DHO_DHCP_PARAMETER_REQUEST_LIST; - options [i] = &option_elements [i]; - options [i]->value = ip->client->config->requested_options; - options [i]->len = ip->client->config->requested_option_count; - options [i]->buf_size = + options[i] = &option_elements[i]; + options[i]->value = ip->client->config->requested_options; + options[i]->len = ip->client->config->requested_option_count; + options[i]->buf_size = ip->client->config->requested_option_count; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* If we are requesting an address that hasn't yet been assigned to us, use the DHCP Requested Address option. */ if (ip->client->state == S_REQUESTING) { /* Send back the server identifier... */ i = DHO_DHCP_SERVER_IDENTIFIER; - options [i] = &option_elements [i]; - options [i]->value = lease->options [i].data; - options [i]->len = lease->options [i].len; - options [i]->buf_size = lease->options [i].len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &option_elements[i]; + options[i]->value = lease->options[i].data; + options[i]->len = lease->options[i].len; + options[i]->buf_size = lease->options[i].len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; } if (ip->client->state == S_REQUESTING || ip->client->state == S_REBOOTING) { ip->client->requested_address = lease->address; i = DHO_DHCP_REQUESTED_ADDRESS; - options [i] = &option_elements [i]; - options [i]->value = lease->address.iabuf; - options [i]->len = lease->address.len; - options [i]->buf_size = lease->address.len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; - } else { + options[i] = &option_elements[i]; + options[i]->value = lease->address.iabuf; + options[i]->len = lease->address.len; + options[i]->buf_size = lease->address.len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; + } else ip->client->requested_address.len = 0; - } /* Send any options requested in the config file. */ - for (i = 0; i < 256; i++) { - if (!options [i] && - ip->client->config->send_options [i].data) { - options [i] = &option_elements [i]; - options [i]->value = ip->client->config -> - send_options [i].data; - options [i]->len = ip->client->config -> - send_options [i].len; - options [i]->buf_size = ip->client->config -> - send_options [i].len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + for (i = 0; i < 256; i++) + if (!options[i] && + ip->client->config->send_options[i].data) { + options[i] = &option_elements[i]; + options[i]->value = + ip->client->config->send_options[i].data; + options[i]->len = + ip->client->config->send_options[i].len; + options[i]->buf_size = + ip->client->config->send_options[i].len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; } - } /* Set up the option buffer... */ - ip->client->packet_length = - cons_options ((struct packet *)0, &ip->client->packet, 0, - options, 0, 0, 0, (u_int8_t *)0, 0); + ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, + options, 0, 0, 0, NULL, 0); if (ip->client->packet_length < BOOTP_MIN_LEN) ip->client->packet_length = BOOTP_MIN_LEN; @@ -1700,95 +1630,90 @@ void make_request (ip, lease) if (ip->client->state == S_BOUND || ip->client->state == S_RENEWING || ip->client->state == S_REBINDING) { - memcpy (&ip->client->packet.ciaddr, - lease->address.iabuf, lease->address.len); + memcpy(&ip->client->packet.ciaddr, + lease->address.iabuf, lease->address.len); ip->client->packet.flags = 0; } else { - memset (&ip->client->packet.ciaddr, 0, - sizeof ip->client->packet.ciaddr); - if (can_receive_unicast_unconfigured (ip)) + memset(&ip->client->packet.ciaddr, 0, + sizeof ip->client->packet.ciaddr); + if (can_receive_unicast_unconfigured(ip)) ip->client->packet.flags = 0; else ip->client->packet.flags = htons (BOOTP_BROADCAST); } memset (&ip->client->packet.yiaddr, 0, - sizeof ip->client->packet.yiaddr); + sizeof ip->client->packet.yiaddr); memset (&ip->client->packet.siaddr, 0, - sizeof ip->client->packet.siaddr); + sizeof ip->client->packet.siaddr); memset (&ip->client->packet.giaddr, 0, - sizeof ip->client->packet.giaddr); + sizeof ip->client->packet.giaddr); memcpy (ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); + ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET - dump_packet (sendpkt); - dump_raw ((unsigned char *)ip->client->packet, sendpkt->packet_length); + dump_packet(sendpkt); + dump_raw((unsigned char *)ip->client->packet, sendpkt->packet_length); #endif } -void make_decline (ip, lease) - struct interface_info *ip; - struct client_lease *lease; +void +make_decline(struct interface_info *ip, struct client_lease *lease) { unsigned char decline = DHCPDECLINE; int i; - struct tree_cache *options [256]; + struct tree_cache *options[256]; struct tree_cache message_type_tree; struct tree_cache requested_address_tree; struct tree_cache server_id_tree; struct tree_cache client_id_tree; - memset (options, 0, sizeof options); - memset (&ip->client->packet, 0, sizeof (ip->client->packet)); + memset(options, 0, sizeof options); + memset(&ip->client->packet, 0, sizeof (ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */ i = DHO_DHCP_MESSAGE_TYPE; - options [i] = &message_type_tree; - options [i]->value = &decline; - options [i]->len = sizeof decline; - options [i]->buf_size = sizeof decline; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &message_type_tree; + options[i]->value = &decline; + options[i]->len = sizeof decline; + options[i]->buf_size = sizeof decline; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Send back the server identifier... */ i = DHO_DHCP_SERVER_IDENTIFIER; - options [i] = &server_id_tree; - options [i]->value = lease->options [i].data; - options [i]->len = lease->options [i].len; - options [i]->buf_size = lease->options [i].len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &server_id_tree; + options[i]->value = lease->options[i].data; + options[i]->len = lease->options[i].len; + options[i]->buf_size = lease->options[i].len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Send back the address we're declining. */ i = DHO_DHCP_REQUESTED_ADDRESS; - options [i] = &requested_address_tree; - options [i]->value = lease->address.iabuf; - options [i]->len = lease->address.len; - options [i]->buf_size = lease->address.len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &requested_address_tree; + options[i]->value = lease->address.iabuf; + options[i]->len = lease->address.len; + options[i]->buf_size = lease->address.len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Send the uid if the user supplied one. */ i = DHO_DHCP_CLIENT_IDENTIFIER; - if (ip->client->config->send_options [i].len) { - options [i] = &client_id_tree; - options [i]->value = ip->client->config -> - send_options [i].data; - options [i]->len = ip->client->config -> - send_options [i].len; - options [i]->buf_size = ip->client->config -> - send_options [i].len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + if (ip->client->config->send_options[i].len) { + options[i] = &client_id_tree; + options[i]->value = ip->client->config->send_options[i].data; + options[i]->len = ip->client->config->send_options[i].len; + options[i]->buf_size = ip->client->config->send_options[i].len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; } /* Set up the option buffer... */ - ip->client->packet_length = - cons_options ((struct packet *)0, &ip->client->packet, 0, - options, 0, 0, 0, (u_int8_t *)0, 0); + ip->client->packet_length = cons_options (NULL, &ip->client->packet, 0, + options, 0, 0, 0, NULL, 0); if (ip->client->packet_length < BOOTP_MIN_LEN) ip->client->packet_length = BOOTP_MIN_LEN; @@ -1802,58 +1727,56 @@ void make_decline (ip, lease) /* ciaddr must always be zero. */ memset (&ip->client->packet.ciaddr, 0, - sizeof ip->client->packet.ciaddr); + sizeof ip->client->packet.ciaddr); memset (&ip->client->packet.yiaddr, 0, - sizeof ip->client->packet.yiaddr); + sizeof ip->client->packet.yiaddr); memset (&ip->client->packet.siaddr, 0, - sizeof ip->client->packet.siaddr); + sizeof ip->client->packet.siaddr); memset (&ip->client->packet.giaddr, 0, - sizeof ip->client->packet.giaddr); + sizeof ip->client->packet.giaddr); memcpy (ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); + ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET - dump_packet (sendpkt); - dump_raw ((unsigned char *)ip->client->packet, sendpkt->packet_length); + dump_packet(sendpkt); + dump_raw((unsigned char *)ip->client->packet, sendpkt->packet_length); #endif } -void make_release (ip, lease) - struct interface_info *ip; - struct client_lease *lease; +void +make_release(struct interface_info *ip, struct client_lease *lease) { unsigned char request = DHCPRELEASE; int i; - struct tree_cache *options [256]; + struct tree_cache *options[256]; struct tree_cache message_type_tree; struct tree_cache server_id_tree; - memset (options, 0, sizeof options); - memset (&ip->client->packet, 0, sizeof (ip->client->packet)); + memset(options, 0, sizeof options); + memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPRELEASE */ i = DHO_DHCP_MESSAGE_TYPE; - options [i] = &message_type_tree; - options [i]->value = &request; - options [i]->len = sizeof request; - options [i]->buf_size = sizeof request; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &message_type_tree; + options[i]->value = &request; + options[i]->len = sizeof request; + options[i]->buf_size = sizeof request; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Send back the server identifier... */ i = DHO_DHCP_SERVER_IDENTIFIER; - options [i] = &server_id_tree; - options [i]->value = lease->options [i].data; - options [i]->len = lease->options [i].len; - options [i]->buf_size = lease->options [i].len; - options [i]->timeout = 0xFFFFFFFF; - options [i]->tree = (struct tree *)0; + options[i] = &server_id_tree; + options[i]->value = lease->options[i].data; + options[i]->len = lease->options[i].len; + options[i]->buf_size = lease->options[i].len; + options[i]->timeout = 0xFFFFFFFF; + options[i]->tree = NULL; /* Set up the option buffer... */ - ip->client->packet_length = - cons_options ((struct packet *)0, &ip->client->packet, 0, - options, 0, 0, 0, (u_int8_t *)0, 0); + ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, + options, 0, 0, 0, NULL, 0); if (ip->client->packet_length < BOOTP_MIN_LEN) ip->client->packet_length = BOOTP_MIN_LEN; @@ -1861,30 +1784,30 @@ void make_release (ip, lease) ip->client->packet.htype = ip->hw_address.htype; ip->client->packet.hlen = ip->hw_address.hlen; ip->client->packet.hops = 0; - ip->client->packet.xid = random (); + ip->client->packet.xid = random(); ip->client->packet.secs = 0; ip->client->packet.flags = 0; memset (&ip->client->packet.ciaddr, 0, - sizeof ip->client->packet.ciaddr); + sizeof ip->client->packet.ciaddr); memset (&ip->client->packet.yiaddr, 0, - sizeof ip->client->packet.yiaddr); + sizeof ip->client->packet.yiaddr); memset (&ip->client->packet.siaddr, 0, - sizeof ip->client->packet.siaddr); + sizeof ip->client->packet.siaddr); memset (&ip->client->packet.giaddr, 0, - sizeof ip->client->packet.giaddr); + sizeof ip->client->packet.giaddr); memcpy (ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); + ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET - dump_packet (sendpkt); - dump_raw ((unsigned char *)ip->client->packet, + dump_packet(sendpkt); + dump_raw((unsigned char *)ip->client->packet, ip->client->packet_length); #endif } -void free_client_lease (lease) - struct client_lease *lease; +void +free_client_lease(struct client_lease *lease) { int i; @@ -1893,31 +1816,31 @@ void free_client_lease (lease) if (lease->filename) free (lease->filename); for (i = 0; i < 256; i++) { - if (lease->options [i].len) - free (lease->options [i].data); + if (lease->options[i].len) + free (lease->options[i].data); } free (lease); } FILE *leaseFile; -void rewrite_client_leases () +void +rewrite_client_leases(void) { struct interface_info *ip; struct client_lease *lp; if (leaseFile) - fclose (leaseFile); - leaseFile = fopen (path_dhclient_db, "w"); + fclose(leaseFile); + leaseFile = fopen(path_dhclient_db, "w"); if (!leaseFile) - error ("can't create %s: %m", path_dhclient_db); + error("can't create %s: %m", path_dhclient_db); /* Write out all the leases attached to configured interfaces that we know about. */ for (ip = interfaces; ip; ip = ip->next) { - for (lp = ip->client->leases; lp; lp = lp->next) { + for (lp = ip->client->leases; lp; lp = lp->next) write_client_lease (ip, lp, 1); - } if (ip->client->active) write_client_lease (ip, ip->client->active, 1); } @@ -1925,19 +1848,17 @@ void rewrite_client_leases () /* Write out any leases that are attached to interfaces that aren't currently configured. */ for (ip = dummy_interfaces; ip; ip = ip->next) { - for (lp = ip->client->leases; lp; lp = lp->next) { - write_client_lease (ip, lp, 1); - } + for (lp = ip->client->leases; lp; lp = lp->next) + write_client_lease(ip, lp, 1); if (ip->client->active) - write_client_lease (ip, ip->client->active, 1); + write_client_lease(ip, ip->client->active, 1); } - fflush (leaseFile); + fflush(leaseFile); } -void write_client_lease (ip, lease, rewrite) - struct interface_info *ip; - struct client_lease *lease; - int rewrite; +void +write_client_lease(struct interface_info *ip, struct client_lease *lease, + int rewrite) { int i; struct tm *t; @@ -1956,108 +1877,92 @@ void write_client_lease (ip, lease, rewrite) return; if (!leaseFile) { /* XXX */ - leaseFile = fopen (path_dhclient_db, "w"); + leaseFile = fopen(path_dhclient_db, "w"); if (!leaseFile) - error ("can't create %s: %m", path_dhclient_db); + error("can't create %s: %m", path_dhclient_db); } - fprintf (leaseFile, "lease {\n"); + fprintf(leaseFile, "lease {\n"); if (lease->is_bootp) - fprintf (leaseFile, " bootp;\n"); - fprintf (leaseFile, " interface \"%s\";\n", ip->name); - fprintf (leaseFile, " fixed-address %s;\n", - piaddr (lease->address)); + fprintf(leaseFile, " bootp;\n"); + fprintf(leaseFile, " interface \"%s\";\n", ip->name); + fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address)); if (lease->filename) - fprintf (leaseFile, " filename \"%s\";\n", - lease->filename); + fprintf(leaseFile, " filename \"%s\";\n", lease->filename); if (lease->server_name) - fprintf (leaseFile, " server-name \"%s\";\n", - lease->server_name); + fprintf(leaseFile, " server-name \"%s\";\n", + lease->server_name); if (lease->medium) - fprintf (leaseFile, " medium \"%s\";\n", - lease->medium->string); - for (i = 0; i < 256; i++) { - if (lease->options [i].len) { - fprintf (leaseFile, - " option %s %s;\n", - dhcp_options [i].name, - pretty_print_option - (i, lease->options [i].data, - lease->options [i].len, 1, 1)); - } - } + fprintf(leaseFile, " medium \"%s\";\n", lease->medium->string); + for (i = 0; i < 256; i++) + if (lease->options[i].len) + fprintf(leaseFile, " option %s %s;\n", + dhcp_options[i].name, + pretty_print_option(i, lease->options[i].data, + lease->options[i].len, 1, 1)); /* Note: the following is not a Y2K bug - it's a Y1.9K bug. Until somebody invents a time machine, I think we can safely disregard it. */ t = gmtime (&lease->renewal); - fprintf (leaseFile, - " renew %d %d/%d/%d %02d:%02d:%02d;\n", - t->tm_wday, t->tm_year + 1900, - t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); + fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n", + t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); t = gmtime (&lease->rebind); - fprintf (leaseFile, - " rebind %d %d/%d/%d %02d:%02d:%02d;\n", - t->tm_wday, t->tm_year + 1900, - t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); + fprintf(leaseFile, " rebind %d %d/%d/%d %02d:%02d:%02d;\n", + t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); t = gmtime (&lease->expiry); - fprintf (leaseFile, - " expire %d %d/%d/%d %02d:%02d:%02d;\n", - t->tm_wday, t->tm_year + 1900, - t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - fprintf (leaseFile, "}\n"); - fflush (leaseFile); + fprintf(leaseFile, " expire %d %d/%d/%d %02d:%02d:%02d;\n", + t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + fprintf(leaseFile, "}\n"); + fflush(leaseFile); } /* Variables holding name of script and file pointer for writing to script. Needless to say, this is not reentrant - only one script can be invoked at a time. */ -char scriptName [256]; +char scriptName[256]; FILE *scriptFile; -void script_init (ip, reason, medium) - struct interface_info *ip; - char *reason; - struct string_list *medium; +void +script_init(struct interface_info *ip, char *reason, struct string_list *medium) { if (ip) { ip->client->scriptEnvsize = 100; - ip->client->scriptEnv = malloc(ip->client->scriptEnvsize - * sizeof(char *)); + ip->client->scriptEnv = + malloc(ip->client->scriptEnvsize * sizeof(char *)); if (ip->client->scriptEnv == NULL) - error ("script_init: no memory for environment initialization"); + error("script_init: no memory for environment initialization"); ip->client->scriptEnv[0]=strdup(CLIENT_PATH); if (ip->client->scriptEnv[0] == NULL) - error ("script_init: no memory for environment initialization"); + error("script_init: no memory for environment initialization"); - ip->client->scriptEnv[1]=NULL; + ip->client->scriptEnv[1] = NULL; script_set_env(ip->client, "", "interface", ip->name); if (medium) script_set_env(ip->client, "", "medium", - medium->string); + medium->string); script_set_env(ip->client, "", "reason", reason); } } -void script_write_params (ip, prefix, lease) - struct interface_info *ip; - char *prefix; - struct client_lease *lease; +void +script_write_params (struct interface_info *ip, char *prefix, + struct client_lease *lease) { int i; - u_int8_t dbuf [1500]; + u_int8_t dbuf[1500]; int len = 0; char tbuf[128]; script_set_env(ip->client, prefix, "ip_address", - piaddr(lease->address)); + piaddr(lease->address)); /* For the benefit of Linux (and operating systems which may have similar needs), compute the network address based on @@ -2066,113 +1971,112 @@ void script_write_params (ip, prefix, lease) broadcast address, not the host address all zeroes broadcast address). */ - if (lease->options [DHO_SUBNET_MASK].len && - (lease->options [DHO_SUBNET_MASK].len < - sizeof lease->address.iabuf)) { + if (lease->options[DHO_SUBNET_MASK].len && + (lease->options[DHO_SUBNET_MASK].len < + sizeof lease->address.iabuf)) { struct iaddr netmask, subnet, broadcast; memcpy (netmask.iabuf, - lease->options [DHO_SUBNET_MASK].data, - lease->options [DHO_SUBNET_MASK].len); - netmask.len = lease->options [DHO_SUBNET_MASK].len; + lease->options[DHO_SUBNET_MASK].data, + lease->options[DHO_SUBNET_MASK].len); + netmask.len = lease->options[DHO_SUBNET_MASK].len; subnet = subnet_number (lease->address, netmask); if (subnet.len) { script_set_env(ip->client, prefix, "network_number", - piaddr(subnet)); - if (!lease->options [DHO_BROADCAST_ADDRESS].len) { + piaddr(subnet)); + if (!lease->options[DHO_BROADCAST_ADDRESS].len) { broadcast = broadcast_addr (subnet, netmask); if (broadcast.len) script_set_env(ip->client, prefix, - "broadcast_address", - piaddr(broadcast)); + "broadcast_address", + piaddr(broadcast)); } } } if (lease->filename) - script_set_env(ip->client, prefix, "filename", - lease->filename); + script_set_env(ip->client, prefix, "filename", lease->filename); if (lease->server_name) script_set_env(ip->client, prefix, "server_name", - lease->server_name); + lease->server_name); for (i = 0; i < 256; i++) { u_int8_t *dp = NULL; - if (ip->client->config->defaults [i].len) { - if (lease->options [i].len) { - switch (ip->client -> - config->default_actions [i]) { - case ACTION_DEFAULT: - dp = lease->options [i].data; - len = lease->options [i].len; + if (ip->client->config->defaults[i].len) { + if (lease->options[i].len) { + switch( + ip->client->config->default_actions[i]) { + case ACTION_DEFAULT: + dp = lease->options[i].data; + len = lease->options[i].len; break; - case ACTION_SUPERSEDE: + case ACTION_SUPERSEDE: supersede: dp = ip->client -> - config->defaults [i].data; + config->defaults[i].data; len = ip->client -> - config->defaults [i].len; + config->defaults[i].len; break; - case ACTION_PREPEND: + case ACTION_PREPEND: len = (ip->client -> - config->defaults [i].len + - lease->options [i].len); + config->defaults[i].len + + lease->options[i].len); if (len > sizeof dbuf) { warn ("no space to %s %s", "prepend option", - dhcp_options [i].name); + dhcp_options[i].name); goto supersede; } dp = dbuf; memcpy (dp, ip->client-> - config->defaults [i].data, + config->defaults[i].data, ip->client-> - config->defaults [i].len); + config->defaults[i].len); memcpy (dp + ip->client-> - config->defaults [i].len, - lease->options [i].data, - lease->options [i].len); - dp [len] = '\0'; + config->defaults[i].len, + lease->options[i].data, + lease->options[i].len); + dp[len] = '\0'; break; - case ACTION_APPEND: + case ACTION_APPEND: len = (ip->client -> - config->defaults [i].len + - lease->options [i].len); + config->defaults[i].len + + lease->options[i].len); if (len > sizeof dbuf) { warn ("no space to %s %s", "append option", - dhcp_options [i].name); + dhcp_options[i].name); goto supersede; } dp = dbuf; memcpy (dp, - lease->options [i].data, - lease->options [i].len); - memcpy (dp + lease->options [i].len, + lease->options[i].data, + lease->options[i].len); + memcpy (dp + lease->options[i].len, ip->client-> - config->defaults [i].data, + config->defaults[i].data, ip->client-> - config->defaults [i].len); - dp [len] = '\0'; + config->defaults[i].len); + dp[len] = '\0'; } } else { dp = ip->client -> - config->defaults [i].data; + config->defaults[i].data; len = ip->client -> - config->defaults [i].len; + config->defaults[i].len; } - } else if (lease->options [i].len) { - len = lease->options [i].len; - dp = lease->options [i].data; + } else if (lease->options[i].len) { + len = lease->options[i].len; + dp = lease->options[i].data; } else { len = 0; } if (len) { - char name [256]; + char name[256]; if (dhcp_option_ev_name (name, sizeof name, - &dhcp_options [i])) + &dhcp_options[i])) script_set_env(ip->client, prefix, name, pretty_print_option (i, dp, len, 0, 0)); } @@ -2181,15 +2085,15 @@ void script_write_params (ip, prefix, lease) script_set_env(ip->client, prefix, "expiry", tbuf); } -int script_go (ip) - struct interface_info *ip; +int +script_go(struct interface_info *ip) { char *scriptName; - char *argv [2]; + char *argv[2]; char **envp; - char *epp [3]; - char reason [] = "REASON=NBI"; - static char client_path [] = CLIENT_PATH; + char *epp[3]; + char reason[] = "REASON=NBI"; + static char client_path[] = CLIENT_PATH; int pid, wpid, wstatus; if (ip) { @@ -2197,58 +2101,56 @@ int script_go (ip) envp = ip->client ->scriptEnv; } else { scriptName = top_level_config.script_name; - epp [0] = reason; - epp [1] = client_path; - epp [2] = (char *)0; + epp[0] = reason; + epp[1] = client_path; + epp[2] = NULL; envp = epp; } - argv [0] = scriptName; - argv [1] = (char *)0; + argv[0] = scriptName; + argv[1] = NULL; - pid = fork (); + pid = fork(); if (pid < 0) { - error ("fork: %m"); + error("fork: %m"); wstatus = 0; } else if (pid) { do { wpid = wait (&wstatus); } while (wpid != pid && wpid > 0); if (wpid < 0) { - error ("wait: %m"); + error("wait: %m"); wstatus = 0; } } else { - execve (scriptName, argv, envp); - error ("execve (%s, ...): %m", scriptName); + execve(scriptName, argv, envp); + error("execve (%s, ...): %m", scriptName); exit (0); } - if (ip) { + if (ip) script_flush_env(ip->client); - } - return wstatus & 0xff; + + return (wstatus & 0xff); } -void script_set_env (client, prefix, name, value) - struct client_state *client; - const char *prefix; - const char *name; - const char *value; +void +script_set_env(struct client_state *client, const char *prefix, + const char *name, const char *value) { int i, namelen; namelen = strlen(name); - for (i = 0; client->scriptEnv[i]; i++) { + for (i = 0; client->scriptEnv[i]; i++) if (strncmp(client->scriptEnv[i], name, namelen) == 0 && client->scriptEnv[i][namelen] == '=') break; - } - if (client->scriptEnv[i]) { + + if (client->scriptEnv[i]) /* Reuse the slot. */ free(client->scriptEnv[i]); - } else { + else { /* New variable. Expand if necessary. */ if (i >= client->scriptEnvsize - 1) { char **newscriptEnv; @@ -2278,7 +2180,8 @@ void script_set_env (client, prefix, name, value) + 1 + strlen(value) + 1, "%s%s=%s", prefix, name, value); } -void script_flush_env(struct client_state *client) +void +script_flush_env(struct client_state *client) { int i; @@ -2289,27 +2192,26 @@ void script_flush_env(struct client_state *client) client->scriptEnvsize = 0; } -int dhcp_option_ev_name (buf, buflen, option) - char *buf; - size_t buflen; - struct option *option; +int +dhcp_option_ev_name(char *buf, size_t buflen, struct option *option) { int i; - for (i = 0; option->name [i]; i++) { + for (i = 0; option->name[i]; i++) { if (i + 1 == buflen) return 0; - if (option->name [i] == '-') - buf [i] = '_'; + if (option->name[i] == '-') + buf[i] = '_'; else - buf [i] = option->name [i]; + buf[i] = option->name[i]; } - buf [i] = 0; + buf[i] = 0; return 1; } -void go_daemon () +void +go_daemon(void) { static int state = 0; int pid; @@ -2329,43 +2231,46 @@ void go_daemon () log_perror = 0; /* Become a daemon... */ - if ((pid = fork ()) < 0) + if ((pid = fork()) < 0) error ("Can't fork daemon: %m"); else if (pid) exit (0); /* Become session leader and get pid... */ - pid = setsid (); + pid = setsid(); /* Close standard I/O descriptors. */ close(0); close(1); close(2); - write_client_pid_file (); + write_client_pid_file(); } -void write_client_pid_file () +void +write_client_pid_file() { FILE *pf; int pfdesc; - pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644); + pfdesc = open(path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (pfdesc < 0) { - warn ("Can't create %s: %m", path_dhclient_pid); + warn("Can't create %s: %m", path_dhclient_pid); return; } pf = fdopen (pfdesc, "w"); if (!pf) - warn ("Can't fdopen %s: %m", path_dhclient_pid); + warn("Can't fdopen %s: %m", path_dhclient_pid); else { - fprintf (pf, "%ld\n", (long)getpid ()); - fclose (pf); + fprintf(pf, "%ld\n", (long)getpid ()); + fclose(pf); } } -int check_option (struct client_lease *l, int option) { +int +check_option(struct client_lease *l, int option) +{ char *opbuf; char *sbuf; @@ -2467,8 +2372,7 @@ int check_option (struct client_lease *l, int option) { } int -res_hnok(dn) - const char *dn; +res_hnok(const char *dn) { int pch = PERIOD, ch = *dn++; @@ -2496,7 +2400,9 @@ res_hnok(dn) * return how many if so, * otherwise, return 0 */ -int ipv4addrs(char * buf) { +int +ipv4addrs(char * buf) +{ struct in_addr jnk; int count = 0; @@ -2515,9 +2421,10 @@ int ipv4addrs(char * buf) { /* Format the specified option as a string */ -char *option_as_string (unsigned int code, unsigned char *data, int len) +char * +option_as_string(unsigned int code, unsigned char *data, int len) { - static char optbuf [32768]; /* XXX */ + static char optbuf[32768]; /* XXX */ char *op = optbuf; int opleft = sizeof(optbuf); unsigned char *dp = data; @@ -2553,7 +2460,7 @@ char *option_as_string (unsigned int code, unsigned char *data, int len) goto toobig; *op = 0; return optbuf; - toobig: +toobig: warn ("dhcp option too large"); return "<error>"; } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 9936965615b..3b33a15a486 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -40,17 +40,12 @@ * Enterprises, see ``http://www.vix.com''. */ -#ifndef __CYGWIN32__ #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> #include <sys/un.h> #include <arpa/inet.h> #include <netdb.h> -#else -#define fd_set cygwin_fd_set -#include <sys/types.h> -#endif #include <fcntl.h> #include <stdio.h> #include <unistd.h> @@ -60,13 +55,11 @@ #include <ctype.h> #include <time.h> -#include "cdefs.h" #include "osdep.h" #include "dhcp.h" #include "tree.h" #include "hash.h" #include "inet.h" -#include "sysconf.h" struct option_data { int len; @@ -404,14 +397,14 @@ struct hardware_link { struct timeout { struct timeout *next; TIME when; - void (*func) PROTO ((void *)); + void (*func)(void *); void *what; }; struct protocol { struct protocol *next; int fd; - void (*handler) PROTO ((struct protocol *)); + void (*handler) (struct protocol *); void *local; }; @@ -430,48 +423,14 @@ typedef unsigned char option_mask [16]; #define OPTION_SPACE(x) ((x) + 2 * ((x) / 255 + 1)) /* Default path to dhcpd config file. */ -#ifdef DEBUG -#undef _PATH_DHCPD_CONF -#define _PATH_DHCPD_CONF "dhcpd.conf" -#undef _PATH_DHCPD_DB -#define _PATH_DHCPD_DB "dhcpd.leases" -#else -#ifndef _PATH_DHCPD_CONF -#define _PATH_DHCPD_CONF "/etc/dhcpd.conf" -#endif - -#ifndef _PATH_DHCPD_DB -#define _PATH_DHCPD_DB "/etc/dhcpd.leases" -#endif - -#ifndef _PATH_DHCPD_PID -#define _PATH_DHCPD_PID "/var/run/dhcpd.pid" -#endif -#endif - -#ifndef _PATH_DHCLIENT_CONF #define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" -#endif - -#ifndef _PATH_DHCLIENT_PID #define _PATH_DHCLIENT_PID "/var/run/dhclient.pid" -#endif - -#ifndef _PATH_DHCLIENT_DB -#define _PATH_DHCLIENT_DB "/etc/dhclient.leases" -#endif - -#ifndef _PATH_RESOLV_CONF +#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" #define _PATH_RESOLV_CONF "/etc/resolv.conf" -#endif - -#ifndef _PATH_DHCRELAY_PID #define _PATH_DHCRELAY_PID "/var/run/dhcrelay.pid" -#endif - -#ifndef DHCPD_LOG_FACILITY +#define _PATH_DHCLIENT_PID "/var/run/dhclient.pid" +#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" #define DHCPD_LOG_FACILITY LOG_DAEMON -#endif #define MAX_TIME 0x7fffffff #define MIN_TIME 0 @@ -480,18 +439,18 @@ typedef unsigned char option_mask [16]; /* options.c */ -void parse_options PROTO ((struct packet *)); -void parse_option_buffer PROTO ((struct packet *, unsigned char *, int)); -int cons_options PROTO ((struct packet *, struct dhcp_packet *, int, +void parse_options (struct packet *); +void parse_option_buffer (struct packet *, unsigned char *, int); +int cons_options (struct packet *, struct dhcp_packet *, int, struct tree_cache **, int, int, int, - u_int8_t *, int)); -int store_options PROTO ((unsigned char *, int, struct tree_cache **, - unsigned char *, int, int, int, int)); -char *pretty_print_option PROTO ((unsigned int, - unsigned char *, int, int, int)); -void do_packet PROTO ((struct interface_info *, + u_int8_t *, int); +int store_options (unsigned char *, int, struct tree_cache **, + unsigned char *, int, int, int, int); +char *pretty_print_option (unsigned int, + unsigned char *, int, int, int); +void do_packet (struct interface_info *, struct dhcp_packet *, int, - unsigned int, struct iaddr, struct hardware *)); + unsigned int, struct iaddr, struct hardware *); /* errwarn.c */ extern int warnings_occurred; @@ -510,14 +469,8 @@ extern u_int16_t remote_port; extern int log_priority; extern int log_perror; -extern char *path_dhcpd_conf; -extern char *path_dhcpd_db; -extern char *path_dhcpd_pid; - -int main PROTO ((int, char **)); -void cleanup PROTO ((void)); -void lease_pinged PROTO ((struct iaddr, u_int8_t *, int)); -void lease_ping_timeout PROTO ((void *)); +int main (int, char **); +void cleanup (void); /* conflex.c */ extern int lexline, lexchar; @@ -525,295 +478,223 @@ extern char *token_line, *tlname; extern char comments [4096]; extern int comment_index; extern int eol_token; -void new_parse PROTO ((char *)); -int next_token PROTO ((char **, FILE *)); -int peek_token PROTO ((char **, FILE *)); +void new_parse (char *); +int next_token (char **, FILE *); +int peek_token (char **, FILE *); /* confpars.c */ -int readconf PROTO ((void)); -void read_leases PROTO ((void)); -int parse_statement PROTO ((FILE *, - struct group *, int, struct host_decl *, int)); -void parse_allow_deny PROTO ((FILE *, struct group *, int)); -void skip_to_semi PROTO ((FILE *)); -int parse_boolean PROTO ((FILE *)); -int parse_semi PROTO ((FILE *)); -int parse_lbrace PROTO ((FILE *)); -void parse_host_declaration PROTO ((FILE *, struct group *)); -char *parse_host_name PROTO ((FILE *)); -void parse_class_declaration PROTO ((FILE *, struct group *, int)); -void parse_lease_time PROTO ((FILE *, TIME *)); -void parse_shared_net_declaration PROTO ((FILE *, struct group *)); -void parse_subnet_declaration PROTO ((FILE *, struct shared_network *)); -void parse_group_declaration PROTO ((FILE *, struct group *)); -void parse_hardware_param PROTO ((FILE *, struct hardware *)); -char *parse_string PROTO ((FILE *)); -struct tree *parse_ip_addr_or_hostname PROTO ((FILE *, int)); -struct tree_cache *parse_fixed_addr_param PROTO ((FILE *)); -void parse_option_param PROTO ((FILE *, struct group *)); -TIME parse_timestamp PROTO ((FILE *)); -struct lease *parse_lease_declaration PROTO ((FILE *)); -void parse_address_range PROTO ((FILE *, struct subnet *)); -TIME parse_date PROTO ((FILE *)); -unsigned char *parse_numeric_aggregate PROTO ((FILE *, +int readconf (void); +void read_leases (void); +int parse_statement (FILE *, + struct group *, int, struct host_decl *, int); +void parse_allow_deny (FILE *, struct group *, int); +void skip_to_semi (FILE *); +int parse_boolean (FILE *); +int parse_semi (FILE *); +int parse_lbrace (FILE *); +void parse_host_declaration (FILE *, struct group *); +char *parse_host_name (FILE *); +void parse_class_declaration (FILE *, struct group *, int); +void parse_lease_time (FILE *, TIME *); +void parse_shared_net_declaration (FILE *, struct group *); +void parse_subnet_declaration (FILE *, struct shared_network *); +void parse_group_declaration (FILE *, struct group *); +void parse_hardware_param (FILE *, struct hardware *); +char *parse_string (FILE *); +struct tree *parse_ip_addr_or_hostname (FILE *, int); +struct tree_cache *parse_fixed_addr_param (FILE *); +void parse_option_param (FILE *, struct group *); +TIME parse_timestamp (FILE *); +struct lease *parse_lease_declaration (FILE *); +void parse_address_range (FILE *, struct subnet *); +TIME parse_date (FILE *); +unsigned char *parse_numeric_aggregate (FILE *, unsigned char *, int *, - int, int, int)); -void convert_num PROTO ((unsigned char *, char *, int, int)); + int, int, int); +void convert_num (unsigned char *, char *, int, int); /* tree.c */ -pair cons PROTO ((caddr_t, pair)); -struct tree_cache *tree_cache PROTO ((struct tree *)); -struct tree *tree_host_lookup PROTO ((char *)); -struct dns_host_entry *enter_dns_host PROTO ((char *)); -struct tree *tree_const PROTO ((unsigned char *, int)); -struct tree *tree_concat PROTO ((struct tree *, struct tree *)); -struct tree *tree_limit PROTO ((struct tree *, int)); -int tree_evaluate PROTO ((struct tree_cache *)); +pair cons (caddr_t, pair); +struct tree_cache *tree_cache (struct tree *); +struct tree *tree_host_lookup (char *); +struct dns_host_entry *enter_dns_host (char *); +struct tree *tree_const (unsigned char *, int); +struct tree *tree_concat (struct tree *, struct tree *); +struct tree *tree_limit (struct tree *, int); +int tree_evaluate (struct tree_cache *); /* dhcp.c */ extern int outstanding_pings; -void dhcp PROTO ((struct packet *)); -void dhcpdiscover PROTO ((struct packet *)); -void dhcprequest PROTO ((struct packet *)); -void dhcprelease PROTO ((struct packet *)); -void dhcpdecline PROTO ((struct packet *)); -void dhcpinform PROTO ((struct packet *)); -void nak_lease PROTO ((struct packet *, struct iaddr *cip)); -void ack_lease PROTO ((struct packet *, struct lease *, unsigned int, TIME)); -void dhcp_reply PROTO ((struct lease *)); -struct lease *find_lease PROTO ((struct packet *, - struct shared_network *, int *)); -struct lease *mockup_lease PROTO ((struct packet *, +void dhcp (struct packet *); +void dhcpdiscover (struct packet *); +void dhcprequest (struct packet *); +void dhcprelease (struct packet *); +void dhcpdecline (struct packet *); +void dhcpinform (struct packet *); +void nak_lease (struct packet *, struct iaddr *cip); +void ack_lease (struct packet *, struct lease *, unsigned int, TIME); +void dhcp_reply (struct lease *); +struct lease *find_lease (struct packet *, + struct shared_network *, int *); +struct lease *mockup_lease (struct packet *, struct shared_network *, - struct host_decl *)); + struct host_decl *); /* bootp.c */ -void bootp PROTO ((struct packet *)); +void bootp (struct packet *); /* memory.c */ -void enter_host PROTO ((struct host_decl *)); -struct host_decl *find_hosts_by_haddr PROTO ((int, unsigned char *, int)); -struct host_decl *find_hosts_by_uid PROTO ((unsigned char *, int)); -struct subnet *find_host_for_network PROTO ((struct host_decl **, +void enter_host (struct host_decl *); +struct host_decl *find_hosts_by_haddr (int, unsigned char *, int); +struct host_decl *find_hosts_by_uid (unsigned char *, int); +struct subnet *find_host_for_network (struct host_decl **, struct iaddr *, - struct shared_network *)); -void new_address_range PROTO ((struct iaddr, struct iaddr, - struct subnet *, int)); -extern struct subnet *find_grouped_subnet PROTO ((struct shared_network *, - struct iaddr)); -extern struct subnet *find_subnet PROTO ((struct iaddr)); -void enter_shared_network PROTO ((struct shared_network *)); -int subnet_inner_than PROTO ((struct subnet *, struct subnet *, int)); -void enter_subnet PROTO ((struct subnet *)); -void enter_lease PROTO ((struct lease *)); -int supersede_lease PROTO ((struct lease *, struct lease *, int)); -void release_lease PROTO ((struct lease *)); -void abandon_lease PROTO ((struct lease *, char *)); -struct lease *find_lease_by_uid PROTO ((unsigned char *, int)); -struct lease *find_lease_by_hw_addr PROTO ((unsigned char *, int)); -struct lease *find_lease_by_ip_addr PROTO ((struct iaddr)); -void uid_hash_add PROTO ((struct lease *)); -void uid_hash_delete PROTO ((struct lease *)); -void hw_hash_add PROTO ((struct lease *)); -void hw_hash_delete PROTO ((struct lease *)); -struct class *add_class PROTO ((int, char *)); -struct class *find_class PROTO ((int, unsigned char *, int)); -struct group *clone_group PROTO ((struct group *, char *)); -void write_leases PROTO ((void)); -void dump_subnets PROTO ((void)); + struct shared_network *); +void new_address_range (struct iaddr, struct iaddr, + struct subnet *, int); +extern struct subnet *find_grouped_subnet (struct shared_network *, + struct iaddr); +extern struct subnet *find_subnet (struct iaddr); +void enter_shared_network (struct shared_network *); +int subnet_inner_than (struct subnet *, struct subnet *, int); +void enter_subnet (struct subnet *); +void enter_lease (struct lease *); +int supersede_lease (struct lease *, struct lease *, int); +void release_lease (struct lease *); +void abandon_lease (struct lease *, char *); +struct lease *find_lease_by_uid (unsigned char *, int); +struct lease *find_lease_by_hw_addr (unsigned char *, int); +struct lease *find_lease_by_ip_addr (struct iaddr); +void uid_hash_add (struct lease *); +void uid_hash_delete (struct lease *); +void hw_hash_add (struct lease *); +void hw_hash_delete (struct lease *); +struct class *add_class (int, char *); +struct class *find_class (int, unsigned char *, int); +struct group *clone_group (struct group *, char *); +void write_leases (void); +void dump_subnets (void); /* alloc.c */ -VOIDPTR dmalloc PROTO ((int, char *)); -void dfree PROTO ((VOIDPTR, char *)); -struct packet *new_packet PROTO ((char *)); -struct dhcp_packet *new_dhcp_packet PROTO ((char *)); -struct tree *new_tree PROTO ((char *)); -struct tree_cache *new_tree_cache PROTO ((char *)); -struct hash_table *new_hash_table PROTO ((int, char *)); -struct hash_bucket *new_hash_bucket PROTO ((char *)); -struct lease *new_lease PROTO ((char *)); -struct lease *new_leases PROTO ((int, char *)); -struct subnet *new_subnet PROTO ((char *)); -struct class *new_class PROTO ((char *)); -struct shared_network *new_shared_network PROTO ((char *)); -struct group *new_group PROTO ((char *)); -struct protocol *new_protocol PROTO ((char *)); -struct lease_state *new_lease_state PROTO ((char *)); -struct domain_search_list *new_domain_search_list PROTO ((char *)); -struct name_server *new_name_server PROTO ((char *)); -struct string_list *new_string_list PROTO ((size_t size, char * name)); -void free_name_server PROTO ((struct name_server *, char *)); -void free_domain_search_list PROTO ((struct domain_search_list *, char *)); -void free_lease_state PROTO ((struct lease_state *, char *)); -void free_protocol PROTO ((struct protocol *, char *)); -void free_group PROTO ((struct group *, char *)); -void free_shared_network PROTO ((struct shared_network *, char *)); -void free_class PROTO ((struct class *, char *)); -void free_subnet PROTO ((struct subnet *, char *)); -void free_lease PROTO ((struct lease *, char *)); -void free_hash_bucket PROTO ((struct hash_bucket *, char *)); -void free_hash_table PROTO ((struct hash_table *, char *)); -void free_tree_cache PROTO ((struct tree_cache *, char *)); -void free_packet PROTO ((struct packet *, char *)); -void free_dhcp_packet PROTO ((struct dhcp_packet *, char *)); -void free_tree PROTO ((struct tree *, char *)); -void free_string_list PROTO ((struct string_list *, char *)); +VOIDPTR dmalloc (int, char *); +void dfree (VOIDPTR, 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 PROTO ((int, int, unsigned char *)); -void print_lease PROTO ((struct lease *)); -void dump_raw PROTO ((unsigned char *, int)); -void dump_packet PROTO ((struct packet *)); -void hash_dump PROTO ((struct hash_table *)); +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 *); /* socket.c */ #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \ || defined (USE_SOCKET_FALLBACK) -int if_register_socket PROTO ((struct interface_info *)); +int if_register_socket (struct interface_info *); #endif #if defined (USE_SOCKET_FALLBACK) && !defined (USE_SOCKET_SEND) -void if_reinitialize_fallback PROTO ((struct interface_info *)); -void if_register_fallback PROTO ((struct interface_info *)); -ssize_t send_fallback PROTO ((struct interface_info *, +void if_reinitialize_fallback (struct interface_info *); +void if_register_fallback (struct interface_info *); +ssize_t send_fallback (struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, - struct sockaddr_in *, struct hardware *)); + struct sockaddr_in *, struct hardware *); #endif #ifdef USE_SOCKET_SEND -void if_reinitialize_send PROTO ((struct interface_info *)); -void if_register_send PROTO ((struct interface_info *)); -ssize_t send_packet PROTO ((struct interface_info *, +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, - struct sockaddr_in *, struct hardware *)); + struct sockaddr_in *, struct hardware *); #endif #if defined (USE_SOCKET_FALLBACK) -void fallback_discard PROTO ((struct protocol *)); +void fallback_discard (struct protocol *); #endif #ifdef USE_SOCKET_RECEIVE -void if_reinitialize_receive PROTO ((struct interface_info *)); -void if_register_receive PROTO ((struct interface_info *)); -ssize_t receive_packet PROTO ((struct interface_info *, +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, unsigned char *, size_t, - struct sockaddr_in *, struct hardware *)); + struct sockaddr_in *, struct hardware *); #endif #if defined (USE_SOCKET_SEND) -int can_unicast_without_arp PROTO ((void)); -int can_receive_unicast_unconfigured PROTO ((struct interface_info *)); -void maybe_setup_fallback PROTO ((void)); +int can_unicast_without_arp (void); +int can_receive_unicast_unconfigured (struct interface_info *); +void maybe_setup_fallback (void); #endif /* bpf.c */ #if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE) -int if_register_bpf PROTO ( (struct interface_info *)); +int if_register_bpf (struct interface_info *); #endif #ifdef USE_BPF_SEND -void if_reinitialize_send PROTO ((struct interface_info *)); -void if_register_send PROTO ((struct interface_info *)); -ssize_t send_packet PROTO ((struct interface_info *, +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, - struct sockaddr_in *, struct hardware *)); + struct sockaddr_in *, struct hardware *); #endif #ifdef USE_BPF_RECEIVE -void if_reinitialize_receive PROTO ((struct interface_info *)); -void if_register_receive PROTO ((struct interface_info *)); -ssize_t receive_packet PROTO ((struct interface_info *, +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, unsigned char *, size_t, - struct sockaddr_in *, struct hardware *)); + struct sockaddr_in *, struct hardware *); #endif #if defined (USE_BPF_SEND) -int can_unicast_without_arp PROTO ((void)); -int can_receive_unicast_unconfigured PROTO ((struct interface_info *)); -void maybe_setup_fallback PROTO ((void)); -#endif - -/* lpf.c */ -#if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE) -int if_register_lpf PROTO ( (struct interface_info *)); -#endif -#ifdef USE_LPF_SEND -void if_reinitialize_send PROTO ((struct interface_info *)); -void if_register_send PROTO ((struct interface_info *)); -ssize_t send_packet PROTO ((struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *)); -#endif -#ifdef USE_LPF_RECEIVE -void if_reinitialize_receive PROTO ((struct interface_info *)); -void if_register_receive PROTO ((struct interface_info *)); -ssize_t receive_packet PROTO ((struct interface_info *, - unsigned char *, size_t, - struct sockaddr_in *, struct hardware *)); -#endif -#if defined (USE_LPF_SEND) -int can_unicast_without_arp PROTO ((void)); -int can_receive_unicast_unconfigured PROTO ((struct interface_info *)); -void maybe_setup_fallback PROTO ((void)); -#endif - -/* nit.c */ -#if defined (USE_NIT_SEND) || defined (USE_NIT_RECEIVE) -int if_register_nit PROTO ( (struct interface_info *)); -#endif - -#ifdef USE_NIT_SEND -void if_reinitialize_send PROTO ((struct interface_info *)); -void if_register_send PROTO ((struct interface_info *)); -ssize_t send_packet PROTO ((struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *)); -#endif -#ifdef USE_NIT_RECEIVE -void if_reinitialize_receive PROTO ((struct interface_info *)); -void if_register_receive PROTO ((struct interface_info *)); -ssize_t receive_packet PROTO ((struct interface_info *, - unsigned char *, size_t, - struct sockaddr_in *, struct hardware *)); -#endif -#if defined (USE_NIT_SEND) -int can_unicast_without_arp PROTO ((void)); -int can_receive_unicast_unconfigured PROTO ((struct interface_info *)); -void maybe_setup_fallback PROTO ((void)); -#endif - -#ifdef USE_DLPI_SEND -void if_reinitialize_send PROTO ((struct interface_info *)); -void if_register_send PROTO ((struct interface_info *)); -ssize_t send_packet PROTO ((struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *)); -#endif -#ifdef USE_DLPI_RECEIVE -void if_reinitialize_receive PROTO ((struct interface_info *)); -void if_register_receive PROTO ((struct interface_info *)); -ssize_t receive_packet PROTO ((struct interface_info *, - unsigned char *, size_t, - struct sockaddr_in *, struct hardware *)); -#endif -#if defined (USE_DLPI_SEND) -int can_unicast_without_arp PROTO ((void)); -int can_receive_unicast_unconfigured PROTO ((struct interface_info *)); -void maybe_setup_fallback PROTO ((void)); +int can_unicast_without_arp (void); +int can_receive_unicast_unconfigured (struct interface_info *); +void maybe_setup_fallback (void); #endif /* raw.c */ #ifdef USE_RAW_SEND -void if_reinitialize_send PROTO ((struct interface_info *)); -void if_register_send PROTO ((struct interface_info *)); -ssize_t send_packet PROTO ((struct interface_info *, +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, - struct sockaddr_in *, struct hardware *)); -int can_unicast_without_arp PROTO ((void)); -int can_receive_unicast_unconfigured PROTO ((struct interface_info *)); -void maybe_setup_fallback PROTO ((void)); + struct sockaddr_in *, struct hardware *); +int can_unicast_without_arp (void); +int can_receive_unicast_unconfigured (struct interface_info *); +void maybe_setup_fallback (void); #endif /* dispatch.c */ @@ -821,30 +702,29 @@ extern struct interface_info *interfaces, *dummy_interfaces, *fallback_interface; extern struct protocol *protocols; extern int quiet_interface_discovery; -extern void (*bootp_packet_handler) PROTO ((struct interface_info *, +extern void (*bootp_packet_handler) (struct interface_info *, struct dhcp_packet *, int, unsigned int, - struct iaddr, struct hardware *)); + struct iaddr, struct hardware *); extern struct timeout *timeouts; -void discover_interfaces PROTO ((int)); -struct interface_info *setup_fallback PROTO ((void)); -void reinitialize_interfaces PROTO ((void)); -void dispatch PROTO ((void)); -int locate_network PROTO ((struct packet *)); -void got_one PROTO ((struct protocol *)); -void add_timeout PROTO ((TIME, void (*) PROTO ((void *)), void *)); -void cancel_timeout PROTO ((void (*) PROTO ((void *)), void *)); -void add_protocol PROTO ((char *, int, - void (*) PROTO ((struct protocol *)), void *)); - -void remove_protocol PROTO ((struct protocol *)); +void discover_interfaces (int); +struct interface_info *setup_fallback (void); +void reinitialize_interfaces (void); +void dispatch (void); +int locate_network (struct packet *); +void got_one (struct protocol *); +void add_timeout (TIME, void (*)(void *), void *); +void cancel_timeout (void (*) (void *), void *); +void add_protocol (char *, int, void (*)(struct protocol *), void *); + +void remove_protocol (struct protocol *); /* hash.c */ -struct hash_table *new_hash PROTO ((void)); -void add_hash PROTO ((struct hash_table *, unsigned char *, - int, unsigned char *)); -void delete_hash_entry PROTO ((struct hash_table *, unsigned char *, int)); -unsigned char *hash_lookup PROTO ((struct hash_table *, unsigned char *, int)); +struct hash_table *new_hash (void); +void add_hash (struct hash_table *, unsigned char *, + int, unsigned char *); +void delete_hash_entry (struct hash_table *, unsigned char *, int); +unsigned char *hash_lookup (struct hash_table *, unsigned char *, int); /* tables.c */ extern struct option dhcp_options [256]; @@ -853,25 +733,25 @@ extern int sizeof_dhcp_option_default_priority_list; extern char *hardware_types [256]; extern struct hash_table universe_hash; extern struct universe dhcp_universe; -void initialize_universes PROTO ((void)); +void initialize_universes (void); /* convert.c */ -u_int32_t getULong PROTO ((unsigned char *)); -int32_t getLong PROTO ((unsigned char *)); -u_int16_t getUShort PROTO ((unsigned char *)); -int16_t getShort PROTO ((unsigned char *)); -void putULong PROTO ((unsigned char *, u_int32_t)); -void putLong PROTO ((unsigned char *, int32_t)); -void putUShort PROTO ((unsigned char *, unsigned int)); -void putShort PROTO ((unsigned char *, int)); +u_int32_t getULong (unsigned char *); +int32_t getLong (unsigned char *); +u_int16_t getUShort (unsigned char *); +int16_t getShort (unsigned char *); +void putULong (unsigned char *, u_int32_t); +void putLong (unsigned char *, int32_t); +void putUShort (unsigned char *, unsigned int); +void putShort (unsigned char *, int); /* inet.c */ -struct iaddr subnet_number PROTO ((struct iaddr, struct iaddr)); -struct iaddr ip_addr PROTO ((struct iaddr, struct iaddr, u_int32_t)); -struct iaddr broadcast_addr PROTO ((struct iaddr, struct iaddr)); -u_int32_t host_addr PROTO ((struct iaddr, struct iaddr)); -int addr_eq PROTO ((struct iaddr, struct iaddr)); -char *piaddr PROTO ((struct iaddr)); +struct iaddr subnet_number (struct iaddr, struct iaddr); +struct iaddr ip_addr (struct iaddr, struct iaddr, u_int32_t); +struct iaddr broadcast_addr (struct iaddr, struct iaddr); +u_int32_t host_addr (struct iaddr, struct iaddr); +int addr_eq (struct iaddr, struct iaddr); +char *piaddr (struct iaddr); /* dhclient.c */ extern char *path_dhclient_conf; @@ -881,173 +761,161 @@ extern int interfaces_requested; extern struct client_config top_level_config; -void dhcpoffer PROTO ((struct packet *)); -void dhcpack PROTO ((struct packet *)); -void dhcpnak PROTO ((struct packet *)); - -void send_discover PROTO ((void *)); -void send_request PROTO ((void *)); -void send_release PROTO ((void *)); -void send_decline PROTO ((void *)); - -void state_reboot PROTO ((void *)); -void state_init PROTO ((void *)); -void state_selecting PROTO ((void *)); -void state_requesting PROTO ((void *)); -void state_bound PROTO ((void *)); -void state_panic PROTO ((void *)); - -void bind_lease PROTO ((struct interface_info *)); - -void make_discover PROTO ((struct interface_info *, struct client_lease *)); -void make_request PROTO ((struct interface_info *, struct client_lease *)); -void make_decline PROTO ((struct interface_info *, struct client_lease *)); -void make_release PROTO ((struct interface_info *, struct client_lease *)); - -void free_client_lease PROTO ((struct client_lease *)); -void rewrite_client_leases PROTO ((void)); -void write_client_lease PROTO ((struct interface_info *, - struct client_lease *, int)); - -void script_init PROTO ((struct interface_info *, char *, - struct string_list *)); -void script_write_params PROTO ((struct interface_info *, - char *, struct client_lease *)); -int script_go PROTO ((struct interface_info *)); -void client_envadd PROTO ((struct client_state *, - const char *, const char *, const char *, ...)); +void dhcpoffer (struct packet *); +void dhcpack (struct packet *); +void dhcpnak (struct packet *); + +void send_discover (void *); +void send_request (void *); +void send_release (void *); +void send_decline (void *); + +void state_reboot (void *); +void state_init (void *); +void state_selecting (void *); +void state_requesting (void *); +void state_bound (void *); +void state_panic (void *); + +void bind_lease (struct interface_info *); + +void make_discover (struct interface_info *, struct client_lease *); +void make_request (struct interface_info *, struct client_lease *); +void make_decline (struct interface_info *, struct client_lease *); +void make_release (struct interface_info *, struct client_lease *); + +void free_client_lease (struct client_lease *); +void rewrite_client_leases (void); +void write_client_lease (struct interface_info *, + struct client_lease *, int); + +void script_init (struct interface_info *, char *, + struct string_list *); +void script_write_params (struct interface_info *, + char *, struct client_lease *); +int script_go (struct interface_info *); +void client_envadd (struct client_state *, + const char *, const char *, const char *, ...); void script_set_env (struct client_state *, const char *, const char *, const char *); void script_flush_env(struct client_state *); int dhcp_option_ev_name (char *, size_t, struct option *); -struct client_lease *packet_to_lease PROTO ((struct packet *)); -void go_daemon PROTO ((void)); -void write_client_pid_file PROTO ((void)); -void status_message PROTO ((struct sysconf_header *, void *)); -void client_location_changed PROTO ((void)); +struct client_lease *packet_to_lease (struct packet *); +void go_daemon (void); +void write_client_pid_file (void); +void client_location_changed (void); /* db.c */ -int write_lease PROTO ((struct lease *)); -int commit_leases PROTO ((void)); -void db_startup PROTO ((void)); -void new_lease_file PROTO ((void)); +int write_lease (struct lease *); +int commit_leases (void); +void db_startup (void); +void new_lease_file (void); /* packet.c */ -u_int32_t checksum PROTO ((unsigned char *, unsigned, u_int32_t)); -u_int32_t wrapsum PROTO ((u_int32_t)); -void assemble_hw_header PROTO ((struct interface_info *, unsigned char *, - int *, struct hardware *)); -void assemble_udp_ip_header PROTO ((struct interface_info *, unsigned char *, +u_int32_t checksum (unsigned char *, unsigned, u_int32_t); +u_int32_t wrapsum (u_int32_t); +void assemble_hw_header (struct interface_info *, unsigned char *, + int *, struct hardware *); +void assemble_udp_ip_header (struct interface_info *, unsigned char *, int *, u_int32_t, u_int32_t, unsigned int, - unsigned char *, int)); -ssize_t decode_hw_header PROTO ((struct interface_info *, unsigned char *, - int, struct hardware *)); -ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *, + unsigned char *, int); +ssize_t decode_hw_header (struct interface_info *, unsigned char *, + int, struct hardware *); +ssize_t decode_udp_ip_header (struct interface_info *, unsigned char *, int, struct sockaddr_in *, - unsigned char *, int)); + unsigned char *, int); /* ethernet.c */ -void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *, - int *, struct hardware *)); -ssize_t decode_ethernet_header PROTO ((struct interface_info *, +void assemble_ethernet_header (struct interface_info *, unsigned char *, + int *, struct hardware *); +ssize_t decode_ethernet_header (struct interface_info *, unsigned char *, - int, struct hardware *)); + int, struct hardware *); /* tr.c */ -void assemble_tr_header PROTO ((struct interface_info *, unsigned char *, - int *, struct hardware *)); -ssize_t decode_tr_header PROTO ((struct interface_info *, +void assemble_tr_header (struct interface_info *, unsigned char *, + int *, struct hardware *); +ssize_t decode_tr_header (struct interface_info *, unsigned char *, - int, struct hardware *)); + int, struct hardware *); /* dhxpxlt.c */ -void convert_statement PROTO ((FILE *)); -void convert_host_statement PROTO ((FILE *, jrefproto)); -void convert_host_name PROTO ((FILE *, jrefproto)); -void convert_class_statement PROTO ((FILE *, jrefproto, int)); -void convert_class_decl PROTO ((FILE *, jrefproto)); -void convert_lease_time PROTO ((FILE *, jrefproto, char *)); -void convert_shared_net_statement PROTO ((FILE *, jrefproto)); -void convert_subnet_statement PROTO ((FILE *, jrefproto)); -void convert_subnet_decl PROTO ((FILE *, jrefproto)); -void convert_host_decl PROTO ((FILE *, jrefproto)); -void convert_hardware_decl PROTO ((FILE *, jrefproto)); -void convert_hardware_addr PROTO ((FILE *, jrefproto)); -void convert_filename_decl PROTO ((FILE *, jrefproto)); -void convert_servername_decl PROTO ((FILE *, jrefproto)); -void convert_ip_addr_or_hostname PROTO ((FILE *, jrefproto, int)); -void convert_fixed_addr_decl PROTO ((FILE *, jrefproto)); -void convert_option_decl PROTO ((FILE *, jrefproto)); -void convert_timestamp PROTO ((FILE *, jrefproto)); -void convert_lease_statement PROTO ((FILE *, jrefproto)); -void convert_address_range PROTO ((FILE *, jrefproto)); -void convert_date PROTO ((FILE *, jrefproto, char *)); -void convert_numeric_aggregate PROTO ((FILE *, jrefproto, int, int, int, int)); -void indent PROTO ((int)); +void convert_statement (FILE *); +void convert_host_statement (FILE *, jrefproto); +void convert_host_name (FILE *, jrefproto); +void convert_class_statement (FILE *, jrefproto, int); +void convert_class_decl (FILE *, jrefproto); +void convert_lease_time (FILE *, jrefproto, char *); +void convert_shared_net_statement (FILE *, jrefproto); +void convert_subnet_statement (FILE *, jrefproto); +void convert_subnet_decl (FILE *, jrefproto); +void convert_host_decl (FILE *, jrefproto); +void convert_hardware_decl (FILE *, jrefproto); +void convert_hardware_addr (FILE *, jrefproto); +void convert_filename_decl (FILE *, jrefproto); +void convert_servername_decl (FILE *, jrefproto); +void convert_ip_addr_or_hostname (FILE *, jrefproto, int); +void convert_fixed_addr_decl (FILE *, jrefproto); +void convert_option_decl (FILE *, jrefproto); +void convert_timestamp (FILE *, jrefproto); +void convert_lease_statement (FILE *, jrefproto); +void convert_address_range (FILE *, jrefproto); +void convert_date (FILE *, jrefproto, char *); +void convert_numeric_aggregate (FILE *, jrefproto, int, int, int, int); +void indent (int); /* route.c */ -void add_route_direct PROTO ((struct interface_info *, struct in_addr)); -void add_route_net PROTO ((struct interface_info *, struct in_addr, - struct in_addr)); -void add_route_default_gateway PROTO ((struct interface_info *, - struct in_addr)); -void remove_routes PROTO ((struct in_addr)); -void remove_if_route PROTO ((struct interface_info *, struct in_addr)); -void remove_all_if_routes PROTO ((struct interface_info *)); -void set_netmask PROTO ((struct interface_info *, struct in_addr)); -void set_broadcast_addr PROTO ((struct interface_info *, struct in_addr)); -void set_ip_address PROTO ((struct interface_info *, struct in_addr)); +void add_route_direct (struct interface_info *, struct in_addr); +void add_route_net (struct interface_info *, struct in_addr, + struct in_addr); +void add_route_default_gateway (struct interface_info *, + struct in_addr); +void remove_routes (struct in_addr); +void remove_if_route (struct interface_info *, struct in_addr); +void remove_all_if_routes (struct interface_info *); +void set_netmask (struct interface_info *, struct in_addr); +void set_broadcast_addr (struct interface_info *, struct in_addr); +void set_ip_address (struct interface_info *, struct in_addr); /* clparse.c */ -int read_client_conf PROTO ((void)); -void read_client_leases PROTO ((void)); -void parse_client_statement PROTO ((FILE *, struct interface_info *, - struct client_config *)); -int parse_X PROTO ((FILE *, u_int8_t *, int)); -int parse_option_list PROTO ((FILE *, u_int8_t *)); -void parse_interface_declaration PROTO ((FILE *, struct client_config *)); -struct interface_info *interface_or_dummy PROTO ((char *)); -void make_client_state PROTO ((struct interface_info *)); -void make_client_config PROTO ((struct interface_info *, - struct client_config *)); -void parse_client_lease_statement PROTO ((FILE *, int)); -void parse_client_lease_declaration PROTO ((FILE *, struct client_lease *, - struct interface_info **)); -struct option *parse_option_decl PROTO ((FILE *, struct option_data *)); -void parse_string_list PROTO ((FILE *, struct string_list **, int)); -int parse_ip_addr PROTO ((FILE *, struct iaddr *)); -void parse_reject_statement PROTO ((FILE *, struct client_config *)); +int read_client_conf (void); +void read_client_leases (void); +void parse_client_statement (FILE *, struct interface_info *, + struct client_config *); +int parse_X (FILE *, u_int8_t *, int); +int parse_option_list (FILE *, u_int8_t *); +void parse_interface_declaration (FILE *, struct client_config *); +struct interface_info *interface_or_dummy (char *); +void make_client_state (struct interface_info *); +void make_client_config (struct interface_info *, + struct client_config *); +void parse_client_lease_statement (FILE *, int); +void parse_client_lease_declaration (FILE *, struct client_lease *, + struct interface_info **); +struct option *parse_option_decl (FILE *, struct option_data *); +void parse_string_list (FILE *, struct string_list **, int); +int parse_ip_addr (FILE *, struct iaddr *); +void parse_reject_statement (FILE *, struct client_config *); /* dhcrelay.c */ -void relay PROTO ((struct interface_info *, struct dhcp_packet *, int, - unsigned int, struct iaddr, struct hardware *)); +void relay (struct interface_info *, struct dhcp_packet *, int, + unsigned int, struct iaddr, struct hardware *); /* icmp.c */ -void icmp_startup PROTO ((int, void (*) PROTO ((struct iaddr, - u_int8_t *, int)))); -int icmp_echorequest PROTO ((struct iaddr *)); -void icmp_echoreply PROTO ((struct protocol *)); +void icmp_startup (int, void (*)(struct iaddr, u_int8_t *, int)); +int icmp_echorequest (struct iaddr *); +void icmp_echoreply (struct protocol *); /* dns.c */ -void dns_startup PROTO ((void)); -int ns_inaddr_lookup PROTO ((u_int16_t, struct iaddr)); -void dns_packet PROTO ((struct protocol *)); +void dns_startup (void); +int ns_inaddr_lookup (u_int16_t, struct iaddr); +void dns_packet (struct protocol *); /* resolv.c */ extern char path_resolv_conf []; struct name_server *name_servers; struct domain_search_list *domains; -void read_resolv_conf PROTO ((TIME)); -struct sockaddr_in *pick_name_server PROTO ((void)); - -/* inet_addr.c */ -#ifdef NEED_INET_ATON -int inet_aton PROTO ((const char *, struct in_addr *)); -#endif - -/* sysconf.c */ -void sysconf_startup PROTO ((void (*) (struct sysconf_header *, void *))); -void sysconf_restart PROTO ((void *)); -void sysconf_message PROTO ((struct protocol *proto)); +void read_resolv_conf (TIME); +struct sockaddr_in *pick_name_server (void); diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index c92f1591c44..54ef5aba9e6 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -46,7 +46,6 @@ #include <poll.h> #include <net/if_media.h> - /* Most boxes has less than 16 interfaces, so this might be a good guess. */ #define INITIAL_IFREQ_COUNT 16 @@ -55,9 +54,9 @@ struct protocol *protocols; struct timeout *timeouts; static struct timeout *free_timeouts; static int interfaces_invalidated; -void (*bootp_packet_handler) PROTO ((struct interface_info *, - struct dhcp_packet *, int, unsigned int, - struct iaddr, struct hardware *)); +void (*bootp_packet_handler)(struct interface_info *, + struct dhcp_packet *, int, unsigned int, + struct iaddr, struct hardware *); static int interface_status(struct interface_info *ifinfo); @@ -68,8 +67,8 @@ int quiet_interface_discovery; register that interface with the network I/O software, figure out what subnet it's on, and add it to the list of interfaces. */ -void discover_interfaces (state) - int state; +void +discover_interfaces(int state) { struct interface_info *tmp; struct interface_info *last, *next; @@ -89,8 +88,7 @@ void discover_interfaces (state) /* If we already have a list of interfaces, and we're running as a DHCP server, the interfaces were requested. */ if (interfaces && (state == DISCOVER_SERVER || - state == DISCOVER_RELAY || - state == DISCOVER_REQUESTED)) + state == DISCOVER_RELAY || state == DISCOVER_REQUESTED)) ir = 0; else if (state == DISCOVER_UNCONFIGURED) ir = INTERFACE_REQUESTED | INTERFACE_AUTOMATIC; @@ -106,12 +104,12 @@ void discover_interfaces (state) if ((ifa->ifa_flags & IFF_LOOPBACK) || (ifa->ifa_flags & IFF_POINTOPOINT) || (!(ifa->ifa_flags & IFF_UP) && - state != DISCOVER_UNCONFIGURED)) + state != DISCOVER_UNCONFIGURED)) continue; /* See if we've seen an interface that matches this one. */ - for (tmp = interfaces; tmp; tmp = tmp -> next) - if (!strcmp (tmp -> name, ifa -> ifa_name)) + for (tmp = interfaces; tmp; tmp = tmp->next) + if (!strcmp (tmp->name, ifa->ifa_name)) break; /* If there isn't already an interface by this name, @@ -121,25 +119,25 @@ void discover_interfaces (state) dmalloc (sizeof *tmp, "discover_interfaces")); if (!tmp) error ("Insufficient memory to %s %s", - "record interface", ifa -> ifa_name); - strlcpy (tmp -> name, ifa -> ifa_name, sizeof(tmp->name)); - tmp -> next = interfaces; - tmp -> flags = ir; - tmp -> noifmedia = tmp -> dead = tmp->errors = 0; + "record interface", ifa->ifa_name); + strlcpy (tmp->name, ifa->ifa_name, sizeof(tmp->name)); + tmp->next = interfaces; + tmp->flags = ir; + tmp->noifmedia = tmp->dead = tmp->errors = 0; interfaces = tmp; } /* If we have the capability, extract link information and record it in a linked list. */ - if (ifa -> ifa_addr->sa_family == AF_LINK) { + if (ifa->ifa_addr->sa_family == AF_LINK) { struct sockaddr_dl *foo = ((struct sockaddr_dl *) - (ifa -> ifa_addr)); - tmp -> index = foo->sdl_index; - tmp -> hw_address.hlen = foo -> sdl_alen; - tmp -> hw_address.htype = HTYPE_ETHER; /* XXX */ - memcpy (tmp -> hw_address.haddr, - LLADDR (foo), foo -> sdl_alen); - } else if (ifa -> ifa_addr->sa_family == AF_INET) { + (ifa->ifa_addr)); + tmp->index = foo->sdl_index; + tmp->hw_address.hlen = foo->sdl_alen; + tmp->hw_address.htype = HTYPE_ETHER; /* XXX */ + memcpy(tmp->hw_address.haddr, + LLADDR (foo), foo->sdl_alen); + } else if (ifa->ifa_addr->sa_family == AF_INET) { struct iaddr addr; /* Get a pointer to the address... */ @@ -152,58 +150,56 @@ void discover_interfaces (state) /* If this is the first real IP address we've found, keep a pointer to ifreq structure in which we found it. */ - if (!tmp -> ifp) { - int len = (IFNAMSIZ + - ifa -> ifa_addr->sa_len); + if (!tmp->ifp) { + int len = (IFNAMSIZ + ifa->ifa_addr->sa_len); tif = (struct ifreq *)malloc (len); if (!tif) - error ("no space to remember ifp."); + error("no space to remember ifp."); strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ); memcpy(&tif->ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len); - tmp -> ifp = tif; - tmp -> primary_address = foo.sin_addr; + tmp->ifp = tif; + tmp->primary_address = foo.sin_addr; } /* Grab the address... */ addr.len = 4; - memcpy (addr.iabuf, &foo.sin_addr.s_addr, - addr.len); + memcpy(addr.iabuf, &foo.sin_addr.s_addr, addr.len); /* If there's a registered subnet for this address, connect it together... */ - if ((subnet = find_subnet (addr))) { + if ((subnet = find_subnet(addr))) { /* If this interface has multiple aliases on the same subnet, ignore all but the first we encounter. */ - if (!subnet -> interface) { - subnet -> interface = tmp; - subnet -> interface_address = addr; - } else if (subnet -> interface != tmp) { + if (!subnet->interface) { + subnet->interface = tmp; + subnet->interface_address = addr; + } else if (subnet->interface != tmp) { warn ("Multiple %s %s: %s %s", "interfaces match the", "same subnet", - subnet -> interface -> name, - tmp -> name); + subnet->interface->name, + tmp->name); } - share = subnet -> shared_network; - if (tmp -> shared_network && - tmp -> shared_network != share) { + share = subnet->shared_network; + if (tmp->shared_network && + tmp->shared_network != share) { warn ("Interface %s matches %s", - tmp -> name, + tmp->name, "multiple shared networks"); } else { - tmp -> shared_network = share; + tmp->shared_network = share; } - if (!share -> interface) { - share -> interface = tmp; - } else if (share -> interface != tmp) { + if (!share->interface) { + share->interface = tmp; + } else if (share->interface != tmp) { warn ("Multiple %s %s: %s %s", "interfaces match the", "same shared network", - share -> interface -> name, - tmp -> name); + share->interface->name, + tmp->name); } } } @@ -220,94 +216,92 @@ void discover_interfaces (state) /* Weed out the interfaces that did not have IP addresses. */ last = (struct interface_info *)0; for (tmp = interfaces; tmp; tmp = next) { - next = tmp -> next; - if ((tmp -> flags & INTERFACE_AUTOMATIC) && + next = tmp->next; + if ((tmp->flags & INTERFACE_AUTOMATIC) && state == DISCOVER_REQUESTED) - tmp -> flags &= ~(INTERFACE_AUTOMATIC | + tmp->flags &= ~(INTERFACE_AUTOMATIC | INTERFACE_REQUESTED); - if (!tmp -> ifp || !(tmp -> flags & INTERFACE_REQUESTED)) { - if ((tmp -> flags & INTERFACE_REQUESTED) != ir) - error ("%s: not found", tmp -> name); + if (!tmp->ifp || !(tmp->flags & INTERFACE_REQUESTED)) { + if ((tmp->flags & INTERFACE_REQUESTED) != ir) + error ("%s: not found", tmp->name); if (!last) - interfaces = interfaces -> next; + interfaces = interfaces->next; else - last -> next = tmp -> next; + last->next = tmp->next; /* Remember the interface in case we need to know about it later. */ - tmp -> next = dummy_interfaces; + tmp->next = dummy_interfaces; dummy_interfaces = tmp; continue; } last = tmp; - memcpy (&foo, &tmp -> ifp -> ifr_addr, - sizeof tmp -> ifp -> ifr_addr); + memcpy (&foo, &tmp->ifp->ifr_addr, sizeof tmp->ifp->ifr_addr); /* We must have a subnet declaration for each interface. */ - if (!tmp -> shared_network && (state == DISCOVER_SERVER)) { - warn ("No subnet declaration for %s (%s).", - tmp -> name, inet_ntoa (foo.sin_addr)); - warn ("Please write a subnet declaration in your %s", - "dhcpd.conf file for the"); - error ("network segment to which interface %s %s", - tmp -> name, "is attached."); + if (!tmp->shared_network && (state == DISCOVER_SERVER)) { + warn("No subnet declaration for %s (%s).", + tmp->name, inet_ntoa (foo.sin_addr)); + warn("Please write a subnet declaration in your %s", + "dhcpd.conf file for the"); + error("network segment to which interface %s %s", + tmp->name, "is attached."); } /* Find subnets that don't have valid interface addresses... */ - for (subnet = (tmp -> shared_network - ? tmp -> shared_network -> subnets - : (struct subnet *)0); - subnet; subnet = subnet -> next_sibling) { - if (!subnet -> interface_address.len) { + for (subnet = (tmp->shared_network ? + tmp->shared_network->subnets : NULL); + subnet; subnet = subnet->next_sibling) { + if (!subnet->interface_address.len) { /* Set the interface address for this subnet to the first address we found. */ - subnet -> interface_address.len = 4; - memcpy (subnet -> interface_address.iabuf, + subnet->interface_address.len = 4; + memcpy(subnet->interface_address.iabuf, &foo.sin_addr.s_addr, 4); } } /* Register the interface... */ - if_register_receive (tmp); - if_register_send (tmp); + if_register_receive(tmp); + if_register_send(tmp); } /* Now register all the remaining interfaces as protocols. */ - for (tmp = interfaces; tmp; tmp = tmp -> next) { - add_protocol (tmp -> name, tmp -> rfdesc, got_one, tmp); - } + for (tmp = interfaces; tmp; tmp = tmp->next) + add_protocol (tmp->name, tmp->rfdesc, got_one, tmp); freeifaddrs(ifap); - maybe_setup_fallback (); + maybe_setup_fallback(); } -struct interface_info *setup_fallback () +struct interface_info * +setup_fallback(void) { fallback_interface = - ((struct interface_info *) - dmalloc (sizeof *fallback_interface, "discover_interfaces")); + 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"; + 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 +reinitialize_interfaces(void) { struct interface_info *ip; - for (ip = interfaces; ip; ip = ip -> next) { + for (ip = interfaces; ip; ip = ip->next) { if_reinitialize_receive (ip); if_reinitialize_send (ip); } @@ -323,7 +317,8 @@ void reinitialize_interfaces () addressing information from it, and then call through the bootp_packet_handler hook to try to do something with it. */ -void dispatch () +void +dispatch(void) { struct protocol *l; int nfds = 0; @@ -334,10 +329,10 @@ void dispatch () int to_msec; nfds = 0; - for (l = protocols; l; l = l -> next) { + for (l = protocols; l; l = l->next) ++nfds; - } - fds = (struct pollfd *)malloc ((nfds) * sizeof (struct pollfd)); + + fds = malloc((nfds) * sizeof (struct pollfd)); if (fds == NULL) error ("Can't allocate poll structures."); @@ -345,14 +340,14 @@ void dispatch () /* Call any expired timeouts, and then if there's still a timeout registered, time out the select call then. */ - another: +another: if (timeouts) { struct timeout *t; - if (timeouts -> when <= cur_time) { + if (timeouts->when <= cur_time) { t = timeouts; - timeouts = timeouts -> next; - (*(t -> func)) (t -> what); - t -> next = free_timeouts; + timeouts = timeouts->next; + (*(t->func)) (t->what); + t->next = free_timeouts; free_timeouts = t; goto another; } @@ -363,7 +358,7 @@ void dispatch () * timeout and blocking indefinetely. */ - howlong = timeouts -> when - cur_time; + howlong = timeouts->when - cur_time; if (howlong > INT_MAX / 1000) howlong = INT_MAX / 1000; to_msec = howlong * 1000; @@ -373,10 +368,10 @@ void dispatch () /* Set up the descriptors to be polled. */ i = 0; - for (l = protocols; l; l = l -> next) { - struct interface_info *ip = l -> local; + for (l = protocols; l; l = l->next) { + struct interface_info *ip = l->local; if (ip && (l->handler != got_one || !ip->dead)) { - fds [i].fd = l -> fd; + fds [i].fd = l->fd; fds [i].events = POLLIN; fds [i].revents = 0; ++i; @@ -403,14 +398,14 @@ void dispatch () GET_TIME (&cur_time); i = 0; - for (l = protocols; l; l = l -> next) { + for (l = protocols; l; l = l->next) { struct interface_info *ip; ip = l->local; if ((fds [i].revents & POLLIN)) { fds [i].revents = 0; if (ip && (l->handler != got_one || !ip->dead)) - (*(l -> handler)) (l); + (*(l->handler)) (l); if (interfaces_invalidated) break; } @@ -421,28 +416,28 @@ void dispatch () } -void got_one (l) - struct protocol *l; +void +got_one(struct protocol *l) { struct sockaddr_in from; struct hardware hfrom; struct iaddr ifrom; size_t result; union { - unsigned char packbuf [4095]; /* Packet input buffer. + unsigned char packbuf[4095]; /* Packet input buffer. Must be as large as largest possible MTU. */ struct dhcp_packet packet; } u; - struct interface_info *ip = l -> local; + struct interface_info *ip = l->local; if ((result = - receive_packet (ip, u.packbuf, sizeof u, &from, &hfrom)) == -1) { - warn ("receive_packet failed on %s: %s", ip -> name, - strerror(errno)); + receive_packet(ip, u.packbuf, sizeof u, &from, &hfrom)) == -1) { + warn("receive_packet failed on %s: %s", ip->name, + strerror(errno)); ip->errors++; - if ((! interface_status(ip)) - || (ip->noifmedia && ip->errors > 20)) { + if ((! interface_status(ip)) || + (ip->noifmedia && ip->errors > 20)) { /* our interface has gone away. */ warn("Interface %s no longer appears valid.", ip->name); @@ -459,10 +454,10 @@ void got_one (l) if (bootp_packet_handler) { ifrom.len = 4; - memcpy (ifrom.iabuf, &from.sin_addr, ifrom.len); + memcpy(ifrom.iabuf, &from.sin_addr, ifrom.len); - (*bootp_packet_handler) (ip, &u.packet, result, - from.sin_port, ifrom, &hfrom); + (*bootp_packet_handler)(ip, &u.packet, result, + from.sin_port, ifrom, &hfrom); } } @@ -520,51 +515,49 @@ interface_status(struct interface_info *ifinfo) goto inactive; } } - inactive: +inactive: return(0); - active: +active: return(1); } -int locate_network (packet) - struct packet *packet; +int +locate_network(struct packet *packet) { struct iaddr ia; /* If this came through a gateway, find the corresponding subnet... */ - if (packet -> raw -> giaddr.s_addr) { + if (packet->raw->giaddr.s_addr) { struct subnet *subnet; ia.len = 4; - memcpy (ia.iabuf, &packet -> raw -> giaddr, 4); + memcpy (ia.iabuf, &packet->raw->giaddr, 4); subnet = find_subnet (ia); if (subnet) - packet -> shared_network = subnet -> shared_network; + packet->shared_network = subnet->shared_network; else - packet -> shared_network = (struct shared_network *)0; - } else { - packet -> shared_network = - packet -> interface -> shared_network; - } - if (packet -> shared_network) + packet->shared_network = (struct shared_network *)0; + } else + packet->shared_network = + packet->interface->shared_network; + + if (packet->shared_network) return 1; return 0; } -void add_timeout (when, where, what) - TIME when; - void (*where) PROTO ((void *)); - void *what; +void +add_timeout(TIME when, void (*where)(void *), void *what) { struct timeout *t, *q; /* See if this timeout supersedes an existing timeout. */ t = (struct timeout *)0; - for (q = timeouts; q; q = q -> next) { - if (q -> func == where && q -> what == what) { + for (q = timeouts; q; q = q->next) { + if (q->func == where && q->what == what) { if (t) - t -> next = q -> next; + t->next = q->next; else - timeouts = q -> next; + timeouts = q->next; break; } t = q; @@ -575,57 +568,56 @@ void add_timeout (when, where, what) if (!q) { if (free_timeouts) { q = free_timeouts; - free_timeouts = q -> next; - q -> func = where; - q -> what = what; + free_timeouts = q->next; + q->func = where; + q->what = what; } else { q = (struct timeout *)malloc (sizeof (struct timeout)); if (!q) error ("Can't allocate timeout structure!"); - q -> func = where; - q -> what = what; + q->func = where; + q->what = what; } } - q -> when = when; + q->when = when; /* Now sort this timeout into the timeout list. */ /* Beginning of list? */ - if (!timeouts || timeouts -> when > q -> when) { - q -> next = timeouts; + if (!timeouts || timeouts->when > q->when) { + q->next = timeouts; timeouts = q; return; } /* Middle of list? */ - for (t = timeouts; t -> next; t = t -> next) { - if (t -> next -> when > q -> when) { - q -> next = t -> next; - t -> next = q; + for (t = timeouts; t->next; t = t->next) { + if (t->next->when > q->when) { + q->next = t->next; + t->next = q; return; } } /* End of list. */ - t -> next = q; - q -> next = (struct timeout *)0; + t->next = q; + q->next = (struct timeout *)0; } -void cancel_timeout (where, what) - void (*where) PROTO ((void *)); - void *what; +void +cancel_timeout(void (*where)(void *), void *what) { struct timeout *t, *q; /* Look for this timeout on the list, and unlink it if we find it. */ t = (struct timeout *)0; - for (q = timeouts; q; q = q -> next) { - if (q -> func == where && q -> what == what) { + for (q = timeouts; q; q = q->next) { + if (q->func == where && q->what == what) { if (t) - t -> next = q -> next; + t->next = q->next; else - timeouts = q -> next; + timeouts = q->next; break; } t = q; @@ -633,17 +625,15 @@ void cancel_timeout (where, what) /* If we found the timeout, put it on the free list. */ if (q) { - q -> next = free_timeouts; + q->next = free_timeouts; free_timeouts = q; } } /* Add a protocol to the list of protocols... */ -void add_protocol (name, fd, handler, local) - char *name; - int fd; - void (*handler) PROTO ((struct protocol *)); - void *local; +void +add_protocol(char *name, int fd, void (*handler)(struct protocol *), + void *local) { struct protocol *p; @@ -651,27 +641,27 @@ void add_protocol (name, fd, handler, local) if (!p) error ("can't allocate protocol struct for %s", name); - p -> fd = fd; - p -> handler = handler; - p -> local = local; + p->fd = fd; + p->handler = handler; + p->local = local; - p -> next = protocols; + p->next = protocols; protocols = p; } -void remove_protocol (proto) - struct protocol *proto; +void +remove_protocol(struct protocol *proto) { struct protocol *p, *next, *prev; prev = (struct protocol *)0; for (p = protocols; p; p = next) { - next = p -> next; + next = p->next; if (p == proto) { if (prev) - prev -> next = p -> next; + prev->next = p->next; else - protocols = p -> next; + protocols = p->next; free (p); } } diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c index 7916ae04e0e..7c3deb00d4d 100644 --- a/sbin/dhclient/errwarn.c +++ b/sbin/dhclient/errwarn.c @@ -43,130 +43,123 @@ #include "dhcpd.h" #include <errno.h> -static void do_percentm PROTO ((char *obuf, size_t size, char *ibuf)); +static void do_percentm(char *obuf, size_t size, char *ibuf); -static char mbuf [1024]; -static char fbuf [1024]; +static char mbuf[1024]; +static char fbuf[1024]; int warnings_occurred; /* Log an error message, then exit... */ -void error (char * fmt, ...) - KandR (char *fmt;) - va_dcl +void +error(char *fmt, ...) { - va_list list; + va_list list; - do_percentm (fbuf, sizeof(fbuf), fmt); + do_percentm(fbuf, sizeof(fbuf), fmt); - va_start (list, fmt); - vsnprintf (mbuf, sizeof mbuf, fbuf, list); - va_end (list); + va_start(list, fmt); + vsnprintf(mbuf, sizeof mbuf, fbuf, list); + va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_ERR, "%s", mbuf); + syslog(log_priority | LOG_ERR, "%s", mbuf); #endif - /* Also log it to stderr? */ - if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); - } - - syslog (LOG_CRIT, "exiting."); - if (log_perror) { - fprintf (stderr, "exiting.\n"); - fflush (stderr); - } - cleanup (); - exit (1); + /* Also log it to stderr? */ + if (log_perror) { + write (2, mbuf, strlen(mbuf)); + write (2, "\n", 1); + } + + syslog(LOG_CRIT, "exiting."); + if (log_perror) { + fprintf(stderr, "exiting.\n"); + fflush(stderr); + } + cleanup(); + exit(1); } /* Log a warning message... */ -int warn (char * fmt, ...) - KandR (char *fmt;) - va_dcl +int +warn(char * fmt, ...) { - va_list list; + va_list list; - do_percentm (fbuf, sizeof(fbuf), fmt); + do_percentm(fbuf, sizeof(fbuf), fmt); - va_start (list, fmt); - vsnprintf (mbuf, sizeof mbuf, fbuf, list); - va_end (list); + va_start(list, fmt); + vsnprintf(mbuf, sizeof mbuf, fbuf, list); + va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_ERR, "%s", mbuf); + syslog(log_priority | LOG_ERR, "%s", mbuf); #endif - if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); - } + if (log_perror) { + write (2, mbuf, strlen (mbuf)); + write (2, "\n", 1); + } - return 0; + return 0; } /* Log a note... */ - -int note (char * fmt, ...) - KandR (char *fmt;) - va_dcl +int +note(char * fmt, ...) { - va_list list; + va_list list; - do_percentm (fbuf, sizeof(fbuf), fmt); + do_percentm(fbuf, sizeof(fbuf), fmt); - va_start (list, fmt); - vsnprintf (mbuf, sizeof mbuf, fbuf, list); - va_end (list); + va_start(list, fmt); + vsnprintf(mbuf, sizeof mbuf, fbuf, list); + va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_INFO, "%s", mbuf); + syslog (log_priority | LOG_INFO, "%s", mbuf); #endif - if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); - } + if (log_perror) { + write (2, mbuf, strlen (mbuf)); + write (2, "\n", 1); + } - return 0; + return 0; } /* Log a debug message... */ -int debug (char * fmt, ...) - KandR (char *fmt;) - va_dcl +int +debug(char * fmt, ...) { - va_list list; + va_list list; - do_percentm (fbuf, sizeof(fbuf), fmt); + do_percentm(fbuf, sizeof(fbuf), fmt); - va_start (list, fmt); - vsnprintf (mbuf, sizeof mbuf, fbuf, list); - va_end (list); + va_start(list, fmt); + vsnprintf(mbuf, sizeof mbuf, fbuf, list); + va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_DEBUG, "%s", mbuf); + syslog (log_priority | LOG_DEBUG, "%s", mbuf); #endif - if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); - } + if (log_perror) { + write (2, mbuf, strlen (mbuf)); + write (2, "\n", 1); + } - return 0; + return 0; } /* Find %m in the input string and substitute an error message string. */ -static void do_percentm (obuf, size, ibuf) - char *obuf; - size_t size; - char *ibuf; +static void +do_percentm(char *obuf, size_t size, char *ibuf) { char ch; char *s = ibuf; @@ -199,26 +192,25 @@ static void do_percentm (obuf, size, ibuf) } -int parse_warn (char * fmt, ...) - KandR (char *fmt;) - va_dcl +int +parse_warn(char * fmt, ...) { va_list list; - static char spaces [] = " "; + static char spaces[] = " "; - do_percentm (mbuf, sizeof(mbuf), fmt); - snprintf (fbuf, sizeof fbuf, "%s line %d: %s", - tlname, lexline, mbuf); - VA_start (list, fmt); - vsnprintf (mbuf, sizeof mbuf, fbuf, list); - va_end (list); + do_percentm(mbuf, sizeof(mbuf), fmt); + snprintf(fbuf, sizeof fbuf, "%s line %d: %s", tlname, lexline, mbuf); +/* XXXFIX */ + VA_start(list, fmt); + vsnprintf(mbuf, sizeof mbuf, fbuf, list); + va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_ERR, "%s", mbuf); - syslog (log_priority | LOG_ERR, "%s", token_line); + syslog(log_priority | LOG_ERR, "%s", mbuf); + syslog(log_priority | LOG_ERR, "%s", token_line); if (lexline < 81) - syslog (log_priority | LOG_ERR, - "%s^", &spaces [sizeof spaces - lexchar]); + syslog(log_priority | LOG_ERR, + "%s^", &spaces [sizeof spaces - lexchar]); #endif if (log_perror) { diff --git a/sbin/dhclient/ethernet.c b/sbin/dhclient/ethernet.c index 1adface63a8..1e83e7faf02 100644 --- a/sbin/dhclient/ethernet.c +++ b/sbin/dhclient/ethernet.c @@ -48,45 +48,41 @@ /* Assemble an hardware header... */ /* XXX currently only supports ethernet; doesn't check for other types. */ -void assemble_ethernet_header (interface, buf, bufix, to) - struct interface_info *interface; - unsigned char *buf; - int *bufix; - struct hardware *to; +void +assemble_ethernet_header(struct interface_info *interface, unsigned char *buf, + int *bufix, struct hardware *to) { struct ether_header eh; if (to && to -> hlen == 6) /* XXX */ - memcpy (eh.ether_dhost, to -> haddr, sizeof eh.ether_dhost); + memcpy(eh.ether_dhost, to -> haddr, sizeof eh.ether_dhost); else - memset (eh.ether_dhost, 0xff, sizeof (eh.ether_dhost)); - if (interface -> hw_address.hlen == sizeof (eh.ether_shost)) - memcpy (eh.ether_shost, interface -> hw_address.haddr, - sizeof (eh.ether_shost)); + memset(eh.ether_dhost, 0xff, sizeof (eh.ether_dhost)); + if (interface->hw_address.hlen == sizeof(eh.ether_shost)) + memcpy(eh.ether_shost, interface->hw_address.haddr, + sizeof(eh.ether_shost)); else - memset (eh.ether_shost, 0x00, sizeof (eh.ether_shost)); + memset(eh.ether_shost, 0x00, sizeof(eh.ether_shost)); - eh.ether_type = htons (ETHERTYPE_IP); + eh.ether_type = htons(ETHERTYPE_IP); - memcpy (&buf [*bufix], &eh, ETHER_HEADER_SIZE); + memcpy(&buf[*bufix], &eh, ETHER_HEADER_SIZE); *bufix += ETHER_HEADER_SIZE; } /* Decode a hardware header... */ -ssize_t decode_ethernet_header (interface, buf, bufix, from) - struct interface_info *interface; - unsigned char *buf; - int bufix; - struct hardware *from; +ssize_t +decode_ethernet_header(struct interface_info *interface, unsigned char *buf, + int bufix, struct hardware *from) { - struct ether_header eh; + struct ether_header eh; - memcpy (&eh, buf + bufix, ETHER_HEADER_SIZE); + memcpy(&eh, buf + bufix, ETHER_HEADER_SIZE); - memcpy (from -> haddr, eh.ether_shost, sizeof (eh.ether_shost)); - from -> htype = ARPHRD_ETHER; - from -> hlen = sizeof eh.ether_shost; + memcpy(from->haddr, eh.ether_shost, sizeof(eh.ether_shost)); + from->htype = ARPHRD_ETHER; + from->hlen = sizeof eh.ether_shost; - return sizeof eh; + return sizeof eh; } diff --git a/sbin/dhclient/hash.c b/sbin/dhclient/hash.c index b4bba2186c9..2ead7f40944 100644 --- a/sbin/dhclient/hash.c +++ b/sbin/dhclient/hash.c @@ -42,42 +42,38 @@ #include "dhcpd.h" -static int do_hash PROTO ((unsigned char *, int, int)); +static int do_hash(unsigned char *, int, int); -struct hash_table *new_hash () +struct hash_table * +new_hash(void) { - struct hash_table *rv = new_hash_table (DEFAULT_HASH_SIZE, "new_hash"); + struct hash_table *rv = new_hash_table(DEFAULT_HASH_SIZE, "new_hash"); if (!rv) return rv; - memset (&rv -> buckets [0], 0, - DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *)); + memset(&rv->buckets [0], 0, + DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)); return rv; } -static int do_hash (name, len, size) - unsigned char *name; - int len; - int size; +static int +do_hash(unsigned char *name, int len, int size) { - register int accum = 0; - register unsigned char *s = name; + int accum = 0; + unsigned char *s = name; int i = len; + while (i--) { /* Add the character in... */ accum += *s++; /* Add carry back in... */ - while (accum > 255) { + while (accum > 255) accum = (accum & 255) + (accum >> 8); - } } - return accum % size; + return (accum % size); } -void add_hash (table, name, len, pointer) - struct hash_table *table; - int len; - unsigned char *name; - unsigned char *pointer; +void add_hash(struct hash_table *table, unsigned char *name, int len, + unsigned char *pointer) { int hashno; struct hash_bucket *bp; @@ -87,24 +83,22 @@ void add_hash (table, name, len, pointer) if (!len) len = strlen ((char *)name); - hashno = do_hash (name, len, table -> hash_count); - bp = new_hash_bucket ("add_hash"); + hashno = do_hash(name, len, table->hash_count); + bp = new_hash_bucket("add_hash"); if (!bp) { - warn ("Can't add %s to hash table.", name); + warn("Can't add %s to hash table.", name); return; } - bp -> name = name; - bp -> value = pointer; - bp -> next = table -> buckets [hashno]; - bp -> len = len; - table -> buckets [hashno] = bp; + bp->name = name; + bp->value = pointer; + bp->next = table->buckets [hashno]; + bp->len = len; + table->buckets[hashno] = bp; } -void delete_hash_entry (table, name, len) - struct hash_table *table; - int len; - unsigned char *name; +void +delete_hash_entry(struct hash_table *table, unsigned char *name, int len) { int hashno; struct hash_bucket *bp, *pbp = (struct hash_bucket *)0; @@ -114,31 +108,27 @@ void delete_hash_entry (table, name, len) if (!len) len = strlen ((char *)name); - hashno = do_hash (name, len, table -> hash_count); + hashno = do_hash(name, len, table->hash_count); /* Go through the list looking for an entry that matches; if we find it, delete it. */ - for (bp = table -> buckets [hashno]; bp; bp = bp -> next) { - if ((!bp -> len && - !strcmp ((char *)bp -> name, (char *)name)) || - (bp -> len == len && - !memcmp (bp -> name, name, len))) { - if (pbp) { - pbp -> next = bp -> next; - } else { - table -> buckets [hashno] = bp -> next; - } - free_hash_bucket (bp, "delete_hash_entry"); + for (bp = table->buckets [hashno]; bp; bp = bp->next) { + if ((!bp->len && + !strcmp ((char *)bp->name, (char *)name)) || + (bp->len == len && !memcmp (bp->name, name, len))) { + if (pbp) + pbp->next = bp->next; + else + table->buckets [hashno] = bp->next; + free_hash_bucket(bp, "delete_hash_entry"); break; } pbp = bp; /* jwg, 9/6/96 - nice catch! */ } } -unsigned char *hash_lookup (table, name, len) - struct hash_table *table; - unsigned char *name; - int len; +unsigned char * +hash_lookup (struct hash_table *table, unsigned char *name, int len) { int hashno; struct hash_bucket *bp; @@ -149,11 +139,11 @@ unsigned char *hash_lookup (table, name, len) if (!len) len = strlen ((char *)name); - hashno = do_hash (name, len, table -> hash_count); + hashno = do_hash(name, len, table->hash_count); - for (bp = table -> buckets [hashno]; bp; bp = bp -> next) { - if (len == bp -> len && !memcmp (bp -> name, name, len)) - return bp -> value; - } - return (unsigned char *)0; + for (bp = table->buckets [hashno]; bp; bp = bp->next) + if (len == bp->len && !memcmp (bp->name, name, len)) + return bp->value; + + return (NULL); } diff --git a/sbin/dhclient/icmp.c b/sbin/dhclient/icmp.c index 8a215e862e1..51f301da04c 100644 --- a/sbin/dhclient/icmp.c +++ b/sbin/dhclient/icmp.c @@ -51,9 +51,8 @@ static int icmp_protocol_fd; /* Initialize the ICMP protocol. */ -void icmp_startup (routep, handler) - int routep; - void (*handler) PROTO ((struct iaddr, u_int8_t *, int)); +void +icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int)) { struct protoent *proto; int protocol = 1; @@ -61,13 +60,13 @@ void icmp_startup (routep, handler) /* Only initialize icmp once. */ if (icmp_protocol_initialized) - error ("attempted to reinitialize icmp protocol"); + error("attempted to reinitialize icmp protocol"); icmp_protocol_initialized = 1; /* Get the protocol number (should be 1). */ proto = getprotobyname ("icmp"); if (proto) - protocol = proto -> p_proto; + protocol = proto->p_proto; /* Get a raw socket for the ICMP protocol. */ icmp_protocol_fd = socket (AF_INET, SOCK_RAW, protocol); @@ -76,29 +75,28 @@ void icmp_startup (routep, handler) /* Make sure it does routing... */ state = 0; - if (setsockopt (icmp_protocol_fd, SOL_SOCKET, SO_DONTROUTE, - (char *)&state, sizeof state) < 0) - error ("Unable to disable SO_DONTROUTE on ICMP socket: %m"); + if (setsockopt(icmp_protocol_fd, SOL_SOCKET, SO_DONTROUTE, + (char *)&state, sizeof state) < 0) + error("Unable to disable SO_DONTROUTE on ICMP socket: %m"); - add_protocol ("icmp", icmp_protocol_fd, icmp_echoreply, - (void *)handler); + add_protocol("icmp", icmp_protocol_fd, icmp_echoreply, (void *)handler); } -int icmp_echorequest (addr) - struct iaddr *addr; +int +icmp_echorequest (struct iaddr *addr) { struct sockaddr_in to; struct icmp icmp; int status; if (!icmp_protocol_initialized) - error ("attempt to use ICMP protocol before initialization."); + error("attempt to use ICMP protocol before initialization."); memset(&to, 0, sizeof to); to.sin_len = sizeof to; to.sin_family = AF_INET; - to.sin_port = 0; /* unused. */ - memcpy (&to.sin_addr, addr -> iabuf, sizeof to.sin_addr); /* XXX */ + to.sin_port = 0; + memcpy (&to.sin_addr, addr->iabuf, sizeof to.sin_addr); /* XXX */ icmp.icmp_type = ICMP_ECHO; icmp.icmp_code = 0; @@ -111,22 +109,22 @@ int icmp_echorequest (addr) icmp.icmp_id = (u_int32_t)addr; #endif - icmp.icmp_cksum = wrapsum (checksum ((unsigned char *)&icmp, + icmp.icmp_cksum = wrapsum(checksum((unsigned char *)&icmp, sizeof icmp, 0)); /* Send the ICMP packet... */ status = sendto (icmp_protocol_fd, (char *)&icmp, sizeof icmp, 0, - (struct sockaddr *)&to, sizeof to); + (struct sockaddr *)&to, sizeof to); if (status < 0) - warn ("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr)); + warn("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr)); if (status != sizeof icmp) return 0; return 1; } -void icmp_echoreply (protocol) - struct protocol *protocol; +void +icmp_echoreply(struct protocol *protocol) { struct icmp *icfrom; struct sockaddr_in from; @@ -134,10 +132,10 @@ void icmp_echoreply (protocol) int status, len; socklen_t salen; struct iaddr ia; - void (*handler) PROTO ((struct iaddr, u_int8_t *, int)); + void (*handler)(struct iaddr, u_int8_t *, int); salen = sizeof from; - status = recvfrom (protocol -> fd, (char *)icbuf, sizeof icbuf, 0, + status = recvfrom (protocol->fd, (char *)icbuf, sizeof icbuf, 0, (struct sockaddr *)&from, &salen); if (status < 0) { warn ("icmp_echoreply: %m"); @@ -145,23 +143,20 @@ void icmp_echoreply (protocol) } /* Probably not for us. */ - if (status < (sizeof (struct ip)) + (sizeof *icfrom)) { + if (status < (sizeof (struct ip)) + (sizeof *icfrom)) return; - } len = status - sizeof (struct ip); icfrom = (struct icmp *)(icbuf + sizeof (struct ip)); /* Silently discard ICMP packets that aren't echoreplies. */ - if (icfrom -> icmp_type != ICMP_ECHOREPLY) { + if (icfrom->icmp_type != ICMP_ECHOREPLY) return; - } /* If we were given a second-stage handler, call it. */ - if (protocol -> local) { - handler = ((void (*) PROTO ((struct iaddr, - u_int8_t *, int))) - protocol -> local); + if (protocol->local) { + handler = ((void (*)(struct iaddr, u_int8_t *, int)) + protocol->local); memcpy (ia.iabuf, &from.sin_addr, sizeof from.sin_addr); ia.len = sizeof from.sin_addr; diff --git a/sbin/dhclient/inet.c b/sbin/dhclient/inet.c index 16097b08185..79166c16262 100644 --- a/sbin/dhclient/inet.c +++ b/sbin/dhclient/inet.c @@ -44,9 +44,8 @@ /* Return just the network number of an internet address... */ -struct iaddr subnet_number (addr, mask) - struct iaddr addr; - struct iaddr mask; +struct iaddr +subnet_number(struct iaddr addr, struct iaddr mask) { int i; struct iaddr rv; @@ -68,18 +67,16 @@ struct iaddr subnet_number (addr, mask) * maybe this isn't a problem. */ -struct iaddr ip_addr (subnet, mask, host_address) - struct iaddr subnet; - struct iaddr mask; - u_int32_t host_address; +struct iaddr +ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address) { int i, j, k; u_int32_t swaddr; struct iaddr rv; unsigned char habuf [sizeof swaddr]; - swaddr = htonl (host_address); - memcpy (habuf, &swaddr, sizeof swaddr); + swaddr = htonl(host_address); + memcpy(habuf, &swaddr, sizeof swaddr); /* Combine the subnet address and the host address. If the host address is bigger than can fit in the subnet, @@ -92,16 +89,15 @@ struct iaddr ip_addr (subnet, mask, host_address) rv.len = 0; return rv; } - for (k = i - 1; k >= 0; k--) { + for (k = i - 1; k >= 0; k--) if (habuf [k]) { rv.len = 0; return rv; } - } - rv.iabuf [i + j] |= habuf [i]; + rv.iabuf[i + j] |= habuf[i]; break; } else - rv.iabuf [i + j] = habuf [i]; + rv.iabuf[i + j] = habuf[i]; } return rv; @@ -111,9 +107,8 @@ struct iaddr ip_addr (subnet, mask, host_address) for which the host portion of the address is all ones (the standard broadcast address). */ -struct iaddr broadcast_addr (subnet, mask) - struct iaddr subnet; - struct iaddr mask; +struct iaddr +broadcast_addr(struct iaddr subnet, struct iaddr mask) { int i; struct iaddr rv; @@ -123,17 +118,15 @@ struct iaddr broadcast_addr (subnet, mask) return rv; } - for (i = 0; i < subnet.len; i++) { + for (i = 0; i < subnet.len; i++) rv.iabuf [i] = subnet.iabuf [i] | (~mask.iabuf [i] & 255); - } rv.len = subnet.len; return rv; } -u_int32_t host_addr (addr, mask) - struct iaddr addr; - struct iaddr mask; +u_int32_t +host_addr(struct iaddr addr, struct iaddr mask) { int i; u_int32_t swaddr; @@ -147,32 +140,30 @@ u_int32_t host_addr (addr, mask) rv.iabuf [i] = addr.iabuf [i] & ~mask.iabuf [i]; /* Copy out up to 32 bits... */ - memcpy (&swaddr, &rv.iabuf [rv.len - sizeof swaddr], sizeof swaddr); + memcpy(&swaddr, &rv.iabuf [rv.len - sizeof swaddr], sizeof swaddr); /* Swap it and return it. */ - return ntohl (swaddr); + return ntohl(swaddr); } -int addr_eq (addr1, addr2) - struct iaddr addr1, addr2; +int +addr_eq(struct iaddr addr1, struct iaddr addr2) { if (addr1.len != addr2.len) return 0; - return memcmp (addr1.iabuf, addr2.iabuf, addr1.len) == 0; + return memcmp(addr1.iabuf, addr2.iabuf, addr1.len) == 0; } -char *piaddr (addr) - struct iaddr addr; +char *piaddr(struct iaddr addr) { - static char pbuf [32]; + static char pbuf[32]; char *s; struct in_addr a; memcpy(&a, &(addr.iabuf), sizeof(struct in_addr)); - if (addr.len == 0) { + if (addr.len == 0) strlcpy (pbuf, "<null address>", sizeof(pbuf)); - } else { s = inet_ntoa(a); if (s != NULL) diff --git a/sbin/dhclient/openbsd.h b/sbin/dhclient/openbsd.h deleted file mode 100644 index 3ce9db4e0fb..00000000000 --- a/sbin/dhclient/openbsd.h +++ /dev/null @@ -1,96 +0,0 @@ -/* netbsd.h - - System dependencies for OpenBSD... */ - -/* - * Copyright (c) 1996 The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND - * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE INTERNET SOFTWARE CONSORTIUM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * This software was written for the Internet Software Consortium by Ted Lemon - * under a contract with Vixie Laboratories. - */ - -#include <syslog.h> -#include <sys/types.h> -#include <string.h> -#include <paths.h> -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#include <setjmp.h> -#include <limits.h> - -#include <sys/wait.h> -#include <signal.h> - -extern int h_errno; - -#include <net/if.h> -#include <net/if_dl.h> -#include <net/route.h> -#include <sys/sockio.h> - -#define ifr_netmask ifr_addr - -/* Varargs stuff... */ -#include <stdarg.h> -#define VA_DOTDOTDOT ... -#define va_dcl -#define VA_start(list, last) va_start (list, last) - -#ifndef _PATH_DHCPD_PID -#define _PATH_DHCPD_PID "/var/run/dhcpd.pid" -#endif -#ifndef _PATH_DHCPD_DB -#define _PATH_DHCPD_DB "/var/db/dhcpd.leases" -#endif -#ifndef _PATH_DHCLIENT_PID -#define _PATH_DHCLIENT_PID "/var/run/dhclient.pid" -#endif -#ifndef _PATH_DHCLIENT_DB -#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" -#endif - -#define EOL '\n' -#define VOIDPTR void * - -/* Time stuff... */ -#include <sys/time.h> -#define TIME time_t -#define GET_TIME(x) time ((x)) - -#define HAVE_SA_LEN -#define HAVE_MKSTEMP - -#if defined (USE_DEFAULT_NETWORK) -# define USE_BPF -#endif - -#if defined(__alpha__) || (defined(__sparc64__) && defined(__arch64__)) -#define PTRSIZE_64BIT -#endif diff --git a/sbin/dhclient/osdep.h b/sbin/dhclient/osdep.h index 88b0582263d..dff42d72af5 100644 --- a/sbin/dhclient/osdep.h +++ b/sbin/dhclient/osdep.h @@ -36,12 +36,6 @@ * under a contract with Vixie Laboratories. */ -#include "site.h" - -/* Porting:: - - If you add a new network API, you must add a check for it below: */ - #if !defined (USE_SOCKETS) && \ !defined (USE_SOCKET_SEND) && \ !defined (USE_SOCKET_RECEIVE) && \ @@ -51,19 +45,53 @@ !defined (USE_BPF) && \ !defined (USE_BPF_SEND) && \ !defined (USE_BPF_RECEIVE) && \ - !defined (USE_LPF) && \ - !defined (USE_LPF_SEND) && \ - !defined (USE_LPF_RECEIVE) && \ - !defined (USE_NIT) && \ - !defined (USE_NIT_SEND) && \ - !defined (USE_NIT_RECEIVE) && \ - !defined (USR_DLPI_SEND) && \ - !defined (USE_DLPI_RECEIVE) # define USE_DEFAULT_NETWORK #endif +#include <syslog.h> +#include <sys/types.h> +#include <string.h> +#include <paths.h> +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <setjmp.h> +#include <limits.h> + +#include <sys/wait.h> +#include <signal.h> + +extern int h_errno; + +#include <net/if.h> +#include <net/if_dl.h> +#include <net/route.h> +#include <sys/sockio.h> + +#define ifr_netmask ifr_addr + +/* Varargs stuff... */ +#include <stdarg.h> +#define VA_DOTDOTDOT ... +#define va_dcl +#define VA_start(list, last) va_start (list, last) + +#define EOL '\n' +#define VOIDPTR void * + +/* Time stuff... */ +#include <sys/time.h> +#define TIME time_t +#define GET_TIME(x) time ((x)) + +#define HAVE_SA_LEN +#define HAVE_MKSTEMP -#include "openbsd.h" +#define USE_BPF + +#if defined(__alpha__) || (defined(__sparc64__) && defined(__arch64__)) +#define PTRSIZE_64BIT +#endif #if !defined (TIME_MAX) # define TIME_MAX 2147483647 @@ -90,26 +118,6 @@ # define USE_BPF_RECEIVE #endif -#ifdef USE_LPF -# define USE_LPF_SEND -# define USE_LPF_RECEIVE -#endif - -#ifdef USE_NIT -# define USE_NIT_SEND -# define USE_NIT_RECEIVE -#endif - -#ifdef USE_DLPI -# define USE_DLPI_SEND -# define USE_DLPI_RECEIVE -#endif - -#ifdef USE_UPF -# define USE_UPF_SEND -# define USE_UPF_RECEIVE -#endif - /* Porting:: If you add support for sending packets directly out an interface, @@ -150,12 +158,6 @@ # define PACKET_DECODING #endif -/* If we don't have a DLPI packet filter, we have to filter in userland. - Probably not worth doing, actually. */ -#if defined (USE_DLPI_RECEIVE) && !defined (USE_DLPI_PFMOD) -# define USERLAND_FILTER -#endif - /* jmp_buf is assumed to be a struct unless otherwise defined in the system header. */ #ifndef jbp_decl diff --git a/sbin/dhclient/site.h b/sbin/dhclient/site.h deleted file mode 100644 index 30fdb703005..00000000000 --- a/sbin/dhclient/site.h +++ /dev/null @@ -1,100 +0,0 @@ -/* Site-specific definitions. - - For supported systems, you shouldn't need to make any changes here. - However, you may want to, in order to deal with site-specific - differences. */ - -/* Add any site-specific definitions and inclusions here... */ - -/* #include <site-foo-bar.h> */ -/* #define SITE_FOOBAR */ - -/* Define this if you don't want dhcpd to run as a daemon and do want - to see all its output printed to stdout instead of being logged via - syslog(). This also makes dhcpd use the dhcpd.conf in its working - directory and write the dhcpd.leases file there. */ - -/* #define DEBUG */ - -/* Define this to see what the parser is parsing. You probably don't - want to see this. */ - -/* #define DEBUG_TOKENS */ - -/* Define this to see dumps of incoming and outgoing packets. This - slows things down quite a bit... */ - -/* #define DEBUG_PACKET */ - -/* Define this if you want to see dumps of tree evaluations. The most - common reason for doing this is to watch what happens with DNS name - lookups. */ - -/* #define DEBUG_EVAL */ - -/* Define this if you want the dhcpd.pid file to go somewhere other than - the default (which varies from system to system, but is usually either - /etc or /var/run. */ - -/* #define _PATH_DHCPD_PID "/var/run/dhcpd.pid" */ - -/* Define this if you want the dhcpd.leases file (the dynamic lease database) - to go somewhere other than the default location, which is normally - /etc/dhcpd.leases. */ - -/* #define _PATH_DHCPD_DB "/etc/dhcpd.leases" */ - -/* Define this if you want the dhcpd.conf file to go somewhere other than - the default location. By default, it goes in /etc/dhcpd.conf. */ - -/* #define _PATH_DHCPD_CONF "/etc/dhcpd.conf" */ - -/* Network API definitions. You do not need to choose one of these - if - you don't choose, one will be chosen for you in your system's config - header. DON'T MESS WITH THIS UNLESS YOU KNOW WHAT YOU'RE DOING!!! */ - -/* Define this to use the standard BSD socket API. - - On many systems, the BSD socket API does not provide the ability to - send packets to the 255.255.255.255 broadcast address, which can - prevent some clients (e.g., Win95) from seeing replies. This is - not a problem on Solaris. - - In addition, the BSD socket API will not work when more than one - network interface is configured on the server. - - However, the BSD socket API is about as efficient as you can get, so if - the aforementioned problems do not matter to you, or if no other - API is supported for your system, you may want to go with it. */ - -/* #define USE_SOCKETS */ - -/* Define this to use the Sun Streams NIT API. - - The Sun Streams NIT API is only supported on SunOS 4.x releases. */ - -/* #define USE_NIT */ - -/* Define this to use the Berkeley Packet Filter API. - - The BPF API is available on all 4.4-BSD derivatives, including - NetBSD, FreeBSD and BSDI's BSD/OS. It's also available on - DEC Alpha OSF/1 in a compatibility mode supported by the Alpha OSF/1 - packetfilter interface. */ - -/* #define USE_BPF */ - -/* Define this to use the raw socket API. - - The raw socket API is provided on many BSD derivatives, and provides - a way to send out raw IP packets. It is only supported for sending - packets - packets must be received with the regular socket API. - This code is experimental - I've never gotten it to actually transmit - a packet to the 255.255.255.255 broadcast address - so use it at your - own risk. */ - -/* #define USE_RAW_SOCKETS */ - -/* Define this to change the logging facility used by dhcpd. */ - -/* #define DHCPD_LOG_FACILITY LOG_DAEMON */ diff --git a/sbin/dhclient/tree.c b/sbin/dhclient/tree.c index e8912ae63fe..f4653b6f2c6 100644 --- a/sbin/dhclient/tree.c +++ b/sbin/dhclient/tree.c @@ -42,12 +42,11 @@ #include "dhcpd.h" -static TIME tree_evaluate_recurse PROTO ((int *, unsigned char **, int *, - struct tree *)); -static TIME do_host_lookup PROTO ((int *, unsigned char **, int *, - struct dns_host_entry *)); -static void do_data_copy PROTO ((int *, unsigned char **, int *, - unsigned char *, int)); +static TIME tree_evaluate_recurse (int *, unsigned char **, int *, struct tree *); +static TIME do_host_lookup (int *, unsigned char **, int *, + struct dns_host_entry *); +static void do_data_copy (int *, unsigned char **, int *, + unsigned char *, int); pair cons (car, cdr) caddr_t car; |