From a07aca58da3320e29d6842f08653cc065b8a34d4 Mon Sep 17 00:00:00 2001 From: krw Date: Sat, 16 Dec 2017 20:47:53 +0000 Subject: [PATCH] With leases no longer in dhclient.conf, rename a bunch of functions and fields to more obvious names reflecting this separation. --- sbin/dhclient/clparse.c | 62 ++++++++++++++++++++-------------------- sbin/dhclient/dhclient.c | 50 ++++++++++++++++---------------- sbin/dhclient/dhcpd.h | 12 ++++---- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 52749f17844..243f0463a50 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.156 2017/12/13 18:53:04 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.157 2017/12/16 20:47:53 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -64,13 +64,13 @@ #include "dhctoken.h" #include "log.h" -void parse_client_statement(FILE *, char *); +void parse_conf_declaration(FILE *, char *); int parse_hex_octets(FILE *, unsigned int *, uint8_t **); int parse_option_list(FILE *, int *, uint8_t *); int parse_interface_declaration(FILE *, char *); -int parse_client_lease_statement(FILE *, char *, +int parse_lease(FILE *, char *, struct client_lease **); -void parse_client_lease_declaration(FILE *, +void parse_lease_declaration(FILE *, struct client_lease *, char *); int parse_option_decl(FILE *, int *, struct option_data *); int parse_reject_statement(FILE *); @@ -113,13 +113,13 @@ add_lease(struct client_lease_tq *tq, struct client_lease *lease) } /* - * client-conf-file :== client-declarations EOF - * client-declarations :== - * | client-declaration - * | client-declarations client-declaration + * conf :== conf_declarations EOF + * conf-declarations :== + * | conf-declaration + * | conf-declarations conf-declaration */ void -read_client_conf(char *name) +read_conf(char *name) { struct option_data *option; FILE *cfile; @@ -186,19 +186,20 @@ read_client_conf(char *name) token = peek_token(NULL, cfile); if (token == EOF) break; - parse_client_statement(cfile, name); + parse_conf_declaration(cfile, name); } fclose(cfile); } } /* - * lease-file :== client-lease-statements EOF - * client-lease-statements :== - * | client-lease-statements LEASE client-lease-statement + * lease-db :== leases EOF + * leases :== + * | LEASE lease + * | leases LEASE lease */ void -read_client_leases(char *name, struct client_lease_tq *tq) +read_lease_db(char *name, struct client_lease_tq *tq) { struct client_lease *lp; FILE *cfile; @@ -206,10 +207,10 @@ read_client_leases(char *name, struct client_lease_tq *tq) TAILQ_INIT(tq); - if ((cfile = fopen(path_dhclient_db, "r")) == NULL) + if ((cfile = fopen(path_lease_db, "r")) == NULL) return; - new_parse(path_dhclient_db); + new_parse(path_lease_db); for (;;) { token = next_token(NULL, cfile); @@ -219,7 +220,7 @@ read_client_leases(char *name, struct client_lease_tq *tq) log_warnx("%s: expecting lease", log_procname); break; } - if (parse_client_lease_statement(cfile, name, &lp) == 1) + if (parse_lease(cfile, name, &lp) == 1) add_lease(tq, lp); } @@ -227,7 +228,7 @@ read_client_leases(char *name, struct client_lease_tq *tq) } /* - * client-declaration :== + * conf-declaration :== * TOK_APPEND option-decl | * TOK_BACKOFF_CUTOFF number | * TOK_DEFAULT option-decl | @@ -251,7 +252,7 @@ read_client_leases(char *name, struct client_lease_tq *tq) * TOK_TIMEOUT number */ void -parse_client_statement(FILE *cfile, char *name) +parse_conf_declaration(FILE *cfile, char *name) { uint8_t list[DHO_COUNT]; char *val; @@ -469,7 +470,7 @@ parse_option_list(FILE *cfile, int *count, uint8_t *optlist) /* * interface-declaration :== - * INTERFACE string LBRACE client-declarations RBRACE + * INTERFACE string LBRACE conf-declarations RBRACE */ int parse_interface_declaration(FILE *cfile, char *name) @@ -508,23 +509,22 @@ parse_interface_declaration(FILE *cfile, char *name) token = next_token(NULL, cfile); return 1; } - parse_client_statement(cfile, name); + parse_conf_declaration(cfile, name); } return 0; } /* - * client-lease-statement :== - * RBRACE client-lease-declarations LBRACE + * lease :== RBRACE lease-declarations LBRACE * - * client-lease-declarations :== + * lease-declarations :== * | - * client-lease-declaration | - * client-lease-declarations client-lease-declaration + * lease-declaration | + * lease-declarations lease-declaration */ int -parse_client_lease_statement(FILE *cfile, char *name, +parse_lease(FILE *cfile, char *name, struct client_lease **lp) { struct client_lease *lease; @@ -545,7 +545,7 @@ parse_client_lease_statement(FILE *cfile, char *name, for (;;) { token = peek_token(NULL, cfile); if (token == EOF) { - parse_warn("unterminated lease declaration."); + parse_warn("unterminated lease."); free_client_lease(lease); break; } @@ -560,14 +560,14 @@ parse_client_lease_statement(FILE *cfile, char *name, } return 1; } - parse_client_lease_declaration(cfile, lease, name); + parse_lease_declaration(cfile, lease, name); } return 0; } /* - * client-lease-declaration :== + * lease-declaration :== * BOOTP | * EXPIRE time-decl | * FILENAME string | @@ -581,7 +581,7 @@ parse_client_lease_statement(FILE *cfile, char *name, * SSID string */ void -parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, +parse_lease_declaration(FILE *cfile, struct client_lease *lease, char *name) { char *val; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 24d44045a70..fce081c919a 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.540 2017/12/09 15:48:04 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.541 2017/12/16 20:47:53 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -96,7 +96,7 @@ #include "privsep.h" char *path_dhclient_conf = _PATH_DHCLIENT_CONF; -char *path_dhclient_db = NULL; +char *path_lease_db = NULL; char *log_procname; char path_option_db[PATH_MAX]; @@ -160,7 +160,7 @@ 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 rewrite_client_leases(struct interface_info *); +void write_lease_db(struct interface_info *); void rewrite_option_db(char *, struct client_lease *, struct client_lease *); char *lease_as_string(char *, char *, struct client_lease *); struct proposal *lease_as_proposal(struct client_lease *); @@ -455,11 +455,11 @@ main(int argc, char *argv[]) ignore_list = optarg; break; case 'l': - path_dhclient_db = optarg; - if (lstat(path_dhclient_db, &sb) != -1) { + path_lease_db = optarg; + if (lstat(path_lease_db, &sb) != -1) { if (S_ISREG(sb.st_mode) == 0) fatalx("'%s' is not a regular file", - path_dhclient_db); + path_lease_db); } break; case 'L': @@ -544,7 +544,7 @@ main(int argc, char *argv[]) config = calloc(1, sizeof(*config)); if (config == NULL) fatal("config"); - read_client_conf(ifi->name); + read_conf(ifi->name); if ((cmd_opts & OPT_NOACTION) != 0) return 0; @@ -559,9 +559,9 @@ main(int argc, char *argv[]) if ((pw = getpwnam("_dhcp")) == NULL) fatalx("no such user: _dhcp"); - if (path_dhclient_db == NULL && asprintf(&path_dhclient_db, "%s.%s", - _PATH_DHCLIENT_DB, ifi->name) == -1) - fatal("path_dhclient_db"); + if (path_lease_db == NULL && asprintf(&path_lease_db, "%s.%s", + _PATH_LEASE_DB, ifi->name) == -1) + fatal("path_lease_db"); /* 2nd stage (post fork) config setup. */ if (ignore_list != NULL) @@ -618,13 +618,13 @@ main(int argc, char *argv[]) take_charge(ifi, routefd); - if ((fd = open(path_dhclient_db, + if ((fd = open(path_lease_db, O_RDONLY|O_EXLOCK|O_CREAT|O_NOFOLLOW, 0640)) == -1) - fatal("open(%s)", path_dhclient_db); - read_client_leases(ifi->name, &ifi->leases); - if ((leaseFile = fopen(path_dhclient_db, "w")) == NULL) - fatal("fopen(%s)", path_dhclient_db); - rewrite_client_leases(ifi); + fatal("open(%s)", path_lease_db); + read_lease_db(ifi->name, &ifi->lease_db); + if ((leaseFile = fopen(path_lease_db, "w")) == NULL) + fatal("fopen(%s)", path_lease_db); + write_lease_db(ifi); close(fd); if (strlen(path_option_db) != 0) { @@ -932,7 +932,7 @@ dhcpnak(struct interface_info *ifi, struct option_data *options, char *info) delete_address(ifi->active->address); /* XXX Do we really want to remove a NAK'd lease from the database? */ - TAILQ_REMOVE(&ifi->leases, ifi->active, next); + TAILQ_REMOVE(&ifi->lease_db, ifi->active, next); free_client_lease(ifi->active); ifi->active = NULL; @@ -1024,7 +1024,7 @@ newlease: * dynamic leases. */ seen = 0; - TAILQ_FOREACH_SAFE(lease, &ifi->leases, next, pl) { + TAILQ_FOREACH_SAFE(lease, &ifi->lease_db, next, pl) { if (ifi->active == NULL) continue; if (ifi->ssid_len != lease->ssid_len) @@ -1036,15 +1036,15 @@ newlease: seen = 1; else if (lease_expiry(lease) < cur_time || lease->address.s_addr == ifi->active->address.s_addr) { - TAILQ_REMOVE(&ifi->leases, lease, next); + TAILQ_REMOVE(&ifi->lease_db, lease, next); free_client_lease(lease); } } if (seen == 0) - TAILQ_INSERT_HEAD(&ifi->leases, ifi->active, next); + TAILQ_INSERT_HEAD(&ifi->lease_db, ifi->active, next); - /* Write out new leases file. */ - rewrite_client_leases(ifi); + /* Write out new lease db. */ + write_lease_db(ifi); ifi->state = S_BOUND; @@ -1693,7 +1693,7 @@ free_client_lease(struct client_lease *lease) } void -rewrite_client_leases(struct interface_info *ifi) +write_lease_db(struct interface_info *ifi) { struct client_lease *lp; char *leasestr; @@ -1713,7 +1713,7 @@ rewrite_client_leases(struct interface_info *ifi) * the chonological order required. */ time(&cur_time); - TAILQ_FOREACH_REVERSE(lp, &ifi->leases, client_lease_tq, next) { + TAILQ_FOREACH_REVERSE(lp, &ifi->lease_db, client_lease_tq, next) { if (lease_expiry(lp) < cur_time) continue; leasestr = lease_as_string(ifi->name, "lease", lp); @@ -2461,7 +2461,7 @@ get_recorded_lease(struct interface_info *ifi) /* Run through the list of leases and see if one can be used. */ i = DHO_DHCP_CLIENT_IDENTIFIER; - TAILQ_FOREACH(lp, &ifi->leases, next) { + TAILQ_FOREACH(lp, &ifi->lease_db, next) { if (lp->ssid_len != ifi->ssid_len) continue; if (memcmp(lp->ssid, ifi->ssid, lp->ssid_len) != 0) diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 8e337255a2c..2cd04e1bf7b 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.241 2017/12/09 15:48:04 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.242 2017/12/16 20:47:53 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -147,11 +147,11 @@ struct interface_info { struct in_addr requested_address; struct client_lease *active; struct client_lease *offer; - struct client_lease_tq leases; + struct client_lease_tq lease_db; }; #define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" -#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" +#define _PATH_LEASE_DB "/var/db/dhclient.leases" /* options.c */ int pack_options(unsigned char *, int, @@ -204,7 +204,7 @@ void sendhup(void); /* dhclient.c */ extern char *path_dhclient_conf; -extern char *path_dhclient_db; +extern char *path_lease_db; extern char *log_procname; extern struct client_config *config; extern struct imsgbuf *unpriv_ibuf; @@ -231,8 +231,8 @@ uint32_t checksum(unsigned char *, uint32_t, uint32_t); uint32_t wrapsum(uint32_t); /* clparse.c */ -void read_client_conf(char *); -void read_client_leases(char *, struct client_lease_tq *); +void read_conf(char *); +void read_lease_db(char *, struct client_lease_tq *); /* kroute.c */ unsigned int extract_classless_route(uint8_t *, unsigned int, -- 2.20.1