diff options
author | Erik Kline <ek@google.com> | 2018-02-22 20:18:22 -0800 |
---|---|---|
committer | Erik Kline <ek@google.com> | 2018-02-22 23:15:12 -0800 |
commit | 54b9dd65e678372832618d3bd43cac1f23be07f8 (patch) | |
tree | 38ea7a9d5992b90c0fa905d1d634f36f20dc4755 | |
parent | 1f332b2ddeae8f103d5e349047679458c5ea50dc (diff) | |
download | dnsmasq-54b9dd65e678372832618d3bd43cac1f23be07f8.tar.gz |
Nuke all reference to /etc/ethers
Test: as follows
- built
- flashed
- booted
- basic USB tethering works as expected
Bug: 38364896
Change-Id: I2ea3fad39b0fbd521c2a26f548f46e036095586b
-rwxr-xr-x | src/config.h | 1 | ||||
-rwxr-xr-x | src/dhcp.c | 160 | ||||
-rwxr-xr-x | src/dnsmasq.c | 25 | ||||
-rwxr-xr-x | src/dnsmasq.h | 3 | ||||
-rwxr-xr-x | src/option.c | 2 |
5 files changed, 10 insertions, 181 deletions
diff --git a/src/config.h b/src/config.h index 9e43696..5a88c1d 100755 --- a/src/config.h +++ b/src/config.h @@ -33,7 +33,6 @@ #define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */ #define SMALLDNAME 40 /* most domain names are smaller than this */ #define HOSTSFILE "/etc/hosts" -#define ETHERSFILE "/etc/ethers" #ifdef __uClinux__ # define RESOLVFILE "/etc/config/resolv.conf" #else @@ -653,166 +653,6 @@ struct dhcp_config *find_config(struct dhcp_config *configs, return candidate; } -void dhcp_read_ethers(void) -{ - FILE *f = fopen(ETHERSFILE, "r"); - unsigned int flags; - char *buff = daemon->namebuff; - char *ip, *cp; - struct in_addr addr; - unsigned char hwaddr[ETHER_ADDR_LEN]; - struct dhcp_config **up, *tmp; - struct dhcp_config *config; - int count = 0, lineno = 0; - - addr.s_addr = 0; /* eliminate warning */ - - if (!f) - { - my_syslog(MS_DHCP | LOG_ERR, _("failed to read %s: %s"), ETHERSFILE, strerror(errno)); - return; - } - - /* This can be called again on SIGHUP, so remove entries created last time round. */ - for (up = &daemon->dhcp_conf, config = daemon->dhcp_conf; config; config = tmp) - { - tmp = config->next; - if (config->flags & CONFIG_FROM_ETHERS) - { - *up = tmp; - /* cannot have a clid */ - if (config->flags & CONFIG_NAME) - free(config->hostname); - free(config->hwaddr); - free(config); - } - else - up = &config->next; - } - - while (fgets(buff, MAXDNAME, f)) - { - char *host = NULL; - - lineno++; - - while (strlen(buff) > 0 && isspace((int)buff[strlen(buff)-1])) - buff[strlen(buff)-1] = 0; - - if ((*buff == '#') || (*buff == '+') || (*buff == 0)) - continue; - - for (ip = buff; *ip && !isspace((int)*ip); ip++); - for(; *ip && isspace((int)*ip); ip++) - *ip = 0; - if (!*ip || parse_hex(buff, hwaddr, ETHER_ADDR_LEN, NULL, NULL) != ETHER_ADDR_LEN) - { - my_syslog(MS_DHCP | LOG_ERR, _("bad line at %s line %d"), ETHERSFILE, lineno); - continue; - } - - /* check for name or dotted-quad */ - for (cp = ip; *cp; cp++) - if (!(*cp == '.' || (*cp >='0' && *cp <= '9'))) - break; - - if (!*cp) - { - if ((addr.s_addr = inet_addr(ip)) == (in_addr_t)-1) - { - my_syslog(MS_DHCP | LOG_ERR, _("bad address at %s line %d"), ETHERSFILE, lineno); - continue; - } - - flags = CONFIG_ADDR; - - for (config = daemon->dhcp_conf; config; config = config->next) - if ((config->flags & CONFIG_ADDR) && config->addr.s_addr == addr.s_addr) - break; - } - else - { - int nomem; - if (!(host = canonicalise(ip, &nomem)) || !legal_hostname(host)) - { - if (!nomem) - my_syslog(MS_DHCP | LOG_ERR, _("bad name at %s line %d"), ETHERSFILE, lineno); - free(host); - continue; - } - - flags = CONFIG_NAME; - - for (config = daemon->dhcp_conf; config; config = config->next) - if ((config->flags & CONFIG_NAME) && hostname_isequal(config->hostname, host)) - break; - } - - if (config && (config->flags & CONFIG_FROM_ETHERS)) - { - my_syslog(MS_DHCP | LOG_ERR, _("ignoring %s line %d, duplicate name or IP address"), ETHERSFILE, lineno); - continue; - } - - if (!config) - { - for (config = daemon->dhcp_conf; config; config = config->next) - { - struct hwaddr_config *conf_addr = config->hwaddr; - if (conf_addr && - conf_addr->next == NULL && - conf_addr->wildcard_mask == 0 && - conf_addr->hwaddr_len == ETHER_ADDR_LEN && - (conf_addr->hwaddr_type == ARPHRD_ETHER || conf_addr->hwaddr_type == 0) && - memcmp(conf_addr->hwaddr, hwaddr, ETHER_ADDR_LEN) == 0) - break; - } - - if (!config) - { - if (!(config = whine_malloc(sizeof(struct dhcp_config)))) - continue; - config->flags = CONFIG_FROM_ETHERS; - config->hwaddr = NULL; - config->domain = NULL; - config->next = daemon->dhcp_conf; - daemon->dhcp_conf = config; - } - - config->flags |= flags; - - if (flags & CONFIG_NAME) - { - config->hostname = host; - host = NULL; - } - - if (flags & CONFIG_ADDR) - config->addr = addr; - } - - config->flags |= CONFIG_NOCLID; - if (!config->hwaddr) - config->hwaddr = whine_malloc(sizeof(struct hwaddr_config)); - if (config->hwaddr) - { - memcpy(config->hwaddr->hwaddr, hwaddr, ETHER_ADDR_LEN); - config->hwaddr->hwaddr_len = ETHER_ADDR_LEN; - config->hwaddr->hwaddr_type = ARPHRD_ETHER; - config->hwaddr->wildcard_mask = 0; - config->hwaddr->next = NULL; - } - count++; - - free(host); - - } - - fclose(f); - - my_syslog(MS_DHCP | LOG_INFO, _("read %s - %d addresses"), ETHERSFILE, count); -} - void check_dhcp_hosts(int fatal) { /* If the same IP appears in more than one host config, then DISCOVER diff --git a/src/dnsmasq.c b/src/dnsmasq.c index 5aca297..3d7bdb5 100755 --- a/src/dnsmasq.c +++ b/src/dnsmasq.c @@ -855,22 +855,17 @@ static void poll_resolv() } } -void clear_cache_and_reload(time_t now) -{ - if (daemon->port != 0) - cache_reload(); - +void clear_cache_and_reload(time_t now) { + if (daemon->port != 0) cache_reload(); + #ifdef HAVE_DHCP - if (daemon->dhcp) - { - if (daemon->options & OPT_ETHERS) - dhcp_read_ethers(); - reread_dhcp(); - dhcp_update_configs(daemon->dhcp_conf); - check_dhcp_hosts(0); - lease_update_from_configs(); - lease_update_file(now); - lease_update_dns(); + if (daemon->dhcp) { + reread_dhcp(); + dhcp_update_configs(daemon->dhcp_conf); + check_dhcp_hosts(0); + lease_update_from_configs(); + lease_update_file(now); + lease_update_dns(); } #endif } diff --git a/src/dnsmasq.h b/src/dnsmasq.h index 6d5efc9..5b696b2 100755 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -168,7 +168,6 @@ struct event_desc { #define OPT_NO_NEG (1u<<11) #define OPT_NODOTS_LOCAL (1u<<12) #define OPT_NOWILD (1u<<13) -#define OPT_ETHERS (1u<<14) #define OPT_RESOLV_DOMAIN (1u<<15) #define OPT_NO_FORK (1u<<16) #define OPT_AUTHORITATIVE (1u<<17) @@ -457,7 +456,6 @@ struct dhcp_config { #define CONFIG_ADDR 32 #define CONFIG_NETID 64 #define CONFIG_NOCLID 128 -#define CONFIG_FROM_ETHERS 256 /* entry created by /etc/ethers */ #define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */ #define CONFIG_DECLINED 1024 /* address declined by client */ #define CONFIG_BANK 2048 /* from dhcp hosts file */ @@ -774,7 +772,6 @@ struct dhcp_config *find_config(struct dhcp_config *configs, unsigned char *hwaddr, int hw_len, int hw_type, char *hostname); void dhcp_update_configs(struct dhcp_config *configs); -void dhcp_read_ethers(void); void check_dhcp_hosts(int fatal); struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr); char *strip_hostname(char *hostname); diff --git a/src/option.c b/src/option.c index addf039..627754f 100755 --- a/src/option.c +++ b/src/option.c @@ -126,7 +126,6 @@ static const struct myoption opts[] = { "domain-needed", 0, 0, 'D' }, { "dhcp-lease-max", 1, 0, 'X' }, { "bind-interfaces", 0, 0, 'z' }, - { "read-ethers", 0, 0, 'Z' }, { "alias", 1, 0, 'V' }, { "dhcp-vendorclass", 1, 0, 'U' }, { "dhcp-userclass", 1, 0, 'j' }, @@ -262,7 +261,6 @@ static struct { { LOPT_PTR, ARG_DUP, "name,target", gettext_noop("Specify PTR DNS record."), NULL }, { LOPT_INTNAME, ARG_DUP, "name,interface", gettext_noop("Give DNS name to IPv4 address of interface."), NULL }, { 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL }, - { 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE }, { '1', OPT_DBUS, NULL, gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL }, { '2', ARG_DUP, "interface", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL }, { '3', ARG_DUP, "[=<id>[,<id>]]", gettext_noop("Enable dynamic address allocation for bootp."), NULL }, |