dhcp = xzalloc(sizeof(*dhcp));
/* Put some LL options in */
p = dhcp->options;
- *p++ = DHCP_SUBNETMASK;
+ *p++ = DHO_SUBNETMASK;
*p++ = sizeof(u32);
u32 = htonl(LINKLOCAL_MASK);
memcpy(p, &u32, sizeof(u32));
p += sizeof(u32);
- *p++ = DHCP_BROADCAST;
+ *p++ = DHO_BROADCAST;
*p++ = sizeof(u32);
u32 = htonl(LINKLOCAL_BRDC);
memcpy(p, &u32, sizeof(u32));
p += sizeof(u32);
- *p++ = DHCP_END;
+ *p++ = DHO_END;
for (;;) {
dhcp->yiaddr = htonl(LINKLOCAL_ADDR |
lease->frominfo = 0;
lease->addr.s_addr = dhcp->yiaddr;
- if (get_option_addr(&lease->net.s_addr, dhcp, DHCP_SUBNETMASK) == -1)
+ if (get_option_addr(&lease->net.s_addr, dhcp, DHO_SUBNETMASK) == -1)
lease->net.s_addr = get_netmask(dhcp->yiaddr);
- if (get_option_uint32(&lease->leasetime, dhcp, DHCP_LEASETIME) == 0) {
+ if (get_option_uint32(&lease->leasetime, dhcp, DHO_LEASETIME) == 0) {
/* Ensure that we can use the lease */
t = 0;
if (t + (time_t)lease->leasetime < t) {
}
} else
lease->leasetime = DEFAULT_LEASETIME;
- if (get_option_uint32(&lease->renewaltime, dhcp, DHCP_RENEWALTIME) != 0)
+ if (get_option_uint32(&lease->renewaltime, dhcp, DHO_RENEWALTIME) != 0)
lease->renewaltime = 0;
- if (get_option_uint32(&lease->rebindtime, dhcp, DHCP_REBINDTIME) != 0)
+ if (get_option_uint32(&lease->rebindtime, dhcp, DHO_REBINDTIME) != 0)
lease->rebindtime = 0;
}
int r;
if (strcmp(msg, "NAK:") == 0)
- a = get_option_string(dhcp, DHCP_MESSAGE);
+ a = get_option_string(dhcp, DHO_MESSAGE);
else {
addr.s_addr = dhcp->yiaddr;
a = xstrdup(inet_ntoa(addr));
}
- r = get_option_addr(&addr.s_addr, dhcp, DHCP_SERVERID);
+ r = get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID);
if (dhcp->servername[0] && r == 0)
logger(lvl, "%s %s from %s `%s'", msg, a,
inet_ntoa(addr), dhcp->servername);
state->messages = 0;
/* We have to have DHCP type to work */
- if (get_option_uint8(&type, dhcp, DHCP_MESSAGETYPE) == -1) {
+ if (get_option_uint8(&type, dhcp, DHO_MESSAGETYPE) == -1) {
log_dhcp(LOG_ERR, "no DHCP type in", dhcp);
return 0;
}
* We should expand this to check IP and/or hardware address
* at the packet level. */
if (options->blacklist_len != 0 &&
- get_option_addr(&addr.s_addr, dhcp, DHCP_SERVERID) == 0)
+ get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID) == 0)
{
for (i = 0; i < options->blacklist_len; i++) {
if (options->blacklist[i] != addr.s_addr)
if (type == DHCP_OFFER && state->state == STATE_DISCOVERING) {
lease->addr.s_addr = dhcp->yiaddr;
- get_option_addr(&lease->server.s_addr, dhcp, DHCP_SERVERID);
+ get_option_addr(&lease->server.s_addr, dhcp, DHO_SERVERID);
log_dhcp(LOG_INFO, "offered", dhcp);
if (state->options & DHCPCD_TEST) {
exec_script(options, iface->name, "TEST", dhcp, NULL);
case STATE_REBINDING:
if (!(state->options & DHCPCD_INFORM)) {
get_option_addr(&lease->server.s_addr,
- dhcp, DHCP_SERVERID);
+ dhcp, DHO_SERVERID);
log_dhcp(LOG_INFO, "acknowledged", dhcp);
}
break;
* if we have space for the terminator */
if ((size_t)bytes < sizeof(struct dhcp_message)) {
p = (uint8_t *)dhcp + bytes - 1;
- while (p > dhcp->options && *p == DHCP_PAD)
+ while (p > dhcp->options && *p == DHO_PAD)
p--;
- if (*p != DHCP_END)
- *++p = DHCP_END;
+ if (*p != DHO_END)
+ *++p = DHO_END;
}
retval = handle_dhcp(state, &dhcp, options);
if (retval == 0 && state->options & DHCPCD_TEST)
else {
addr.s_addr = dhcp->yiaddr;
/* Ensure we have all the needed values */
- if (get_option_addr(&net.s_addr, dhcp, DHCP_SUBNETMASK) == -1)
+ if (get_option_addr(&net.s_addr, dhcp, DHO_SUBNETMASK) == -1)
net.s_addr = get_netmask(addr.s_addr);
- if (get_option_addr(&brd.s_addr, dhcp, DHCP_BROADCAST) == -1)
+ if (get_option_addr(&brd.s_addr, dhcp, DHO_BROADCAST) == -1)
brd.s_addr = addr.s_addr | ~net.s_addr;
}
bl += ol;
}
switch (o) {
- case DHCP_PAD:
+ case DHO_PAD:
continue;
- case DHCP_END:
+ case DHO_END:
if (overl & 1) {
/* bit 1 set means parse boot file */
overl &= ~1;
} else
goto exit;
break;
- case DHCP_OPTIONSOVERLOADED:
+ case DHO_OPTIONSOVERLOADED:
/* Ensure we only get this option once */
if (!overl)
overl = p[1];
int len;
/* If we have CSR's then we MUST use these only */
- p = get_option(dhcp, DHCP_CSR, &len, NULL);
+ p = get_option(dhcp, DHO_CSR, &len, NULL);
/* Check for crappy MS option */
if (!p)
- p = get_option(dhcp, DHCP_MSCSR, &len, NULL);
+ p = get_option(dhcp, DHO_MSCSR, &len, NULL);
if (p) {
routes = decode_rfc3442_rt(len, p);
if (routes)
}
/* OK, get our static routes first. */
- p = get_option(dhcp, DHCP_STATICROUTE, &len, NULL);
+ p = get_option(dhcp, DHO_STATICROUTE, &len, NULL);
if (p) {
e = p + len;
while (p < e) {
}
/* Now grab our routers */
- p = get_option(dhcp, DHCP_ROUTER, &len, NULL);
+ p = get_option(dhcp, DHO_ROUTER, &len, NULL);
if (p) {
e = p + len;
while (p < e) {
dhcp->xid = xid;
dhcp->cookie = htonl(MAGIC_COOKIE);
- *p++ = DHCP_MESSAGETYPE;
+ *p++ = DHO_MESSAGETYPE;
*p++ = 1;
*p++ = type;
if (type == DHCP_REQUEST) {
- *p++ = DHCP_MAXMESSAGESIZE;
+ *p++ = DHO_MAXMESSAGESIZE;
*p++ = 2;
sz = get_mtu(iface->name);
if (sz < MTU_MIN) {
}
if (iface->clientid) {
- *p++ = DHCP_CLIENTID;
+ *p++ = DHO_CLIENTID;
memcpy(p, iface->clientid, iface->clientid[0] + 1);
p += iface->clientid[0] + 1;
}
if (type != DHCP_DECLINE && type != DHCP_RELEASE) {
if (options->userclass[0]) {
- *p++ = DHCP_USERCLASS;
+ *p++ = DHO_USERCLASS;
memcpy(p, options->userclass, options->userclass[0] + 1);
p += options->userclass[0] + 1;
}
if (options->classid[0]) {
- *p++ = DHCP_CLASSID;
+ *p++ = DHO_CLASSID;
memcpy(p, options->classid, options->classid[0] + 1);
p += options->classid[0] + 1;
}
lease->addr.s_addr != iface->addr.s_addr &&
!IN_LINKLOCAL(ntohl(lease->addr.s_addr)))
{
- PUTADDR(DHCP_IPADDRESS, lease->addr);
+ PUTADDR(DHO_IPADDRESS, lease->addr);
if (lease->server.s_addr)
- PUTADDR(DHCP_SERVERID, lease->server);
+ PUTADDR(DHO_SERVERID, lease->server);
}
#undef PUTADDR
if (options->leasetime != 0) {
- *p++ = DHCP_LEASETIME;
+ *p++ = DHO_LEASETIME;
*p++ = 4;
ul = htonl(options->leasetime);
memcpy(p, &ul, 4);
type == DHCP_REQUEST)
{
if (options->hostname[0]) {
- *p++ = DHCP_HOSTNAME;
+ *p++ = DHO_HOSTNAME;
memcpy(p, options->hostname, options->hostname[0] + 1);
p += options->hostname[0] + 1;
}
if (options->fqdn != FQDN_DISABLE) {
/* IETF DHC-FQDN option (81), RFC4702 */
- *p++ = DHCP_FQDN;
+ *p++ = DHO_FQDN;
lp = p;
*p++ = 3;
/*
/* vendor is already encoded correctly, so just add it */
if (options->vendor[0]) {
- *p++ = DHCP_VENDOR;
+ *p++ = DHO_VENDOR;
memcpy(p, options->vendor, options->vendor[0] + 1);
p += options->vendor[0] + 1;
}
- *p++ = DHCP_PARAMETERREQUESTLIST;
+ *p++ = DHO_PARAMETERREQUESTLIST;
n_params = p;
*p++ = 0;
for (opt = dhcp_opts; opt->option; opt++) {
has_reqmask(options->reqmask, opt->option)))
continue;
switch (opt->option) {
- case DHCP_RENEWALTIME: /* FALLTHROUGH */
- case DHCP_REBINDTIME:
+ case DHO_RENEWALTIME: /* FALLTHROUGH */
+ case DHO_REBINDTIME:
if (type == DHCP_INFORM)
continue;
break;
}
*n_params = p - n_params - 1;
}
- *p++ = DHCP_END;
+ *p++ = DHO_END;
#ifdef BOOTP_MESSAGE_LENTH_MIN
/* Some crappy DHCP servers think they have to obey the BOOTP minimum
* message length.
* They are wrong, but we should still cater for them. */
while (p - m < BOOTP_MESSAGE_LENTH_MIN)
- *p++ = DHCP_PAD;
+ *p++ = DHO_PAD;
#endif
*message = dhcp;
/* Only write as much as we need */
while (p < e) {
o = *p;
- if (o == DHCP_END) {
+ if (o == DHO_END) {
bytes = p - (const uint8_t *)dhcp;
break;
}
p++;
- if (o != DHCP_PAD) {
+ if (o != DHO_PAD) {
l = *p++;
p += l;
}
char cidr[4];
uint8_t overl = 0;
- get_option_uint8(&overl, dhcp, DHCP_OPTIONSOVERLOADED);
+ get_option_uint8(&overl, dhcp, DHO_OPTIONSOVERLOADED);
if (!env) {
for (opt = dhcp_opts; opt->option; opt++) {
* message but are not necessarily in the options */
addr.s_addr = dhcp->yiaddr;
setvar(&ep, prefix, "ip_address", inet_ntoa(addr));
- if (get_option_addr(&net.s_addr, dhcp, DHCP_SUBNETMASK) == -1) {
+ if (get_option_addr(&net.s_addr, dhcp, DHO_SUBNETMASK) == -1) {
net.s_addr = get_netmask(addr.s_addr);
setvar(&ep, prefix, "subnet_mask", inet_ntoa(net));
}
i = inet_ntocidr(net);
snprintf(cidr, sizeof(cidr), "%d", inet_ntocidr(net));
setvar(&ep, prefix, "subnet_cidr", cidr);
- if (get_option_addr(&brd.s_addr, dhcp, DHCP_BROADCAST) == -1) {
+ if (get_option_addr(&brd.s_addr, dhcp, DHO_BROADCAST) == -1) {
brd.s_addr = addr.s_addr | ~net.s_addr;
setvar(&ep, prefix, "broadcast_address", inet_ntoa(net));
}
if (!p)
continue;
/* We only want the FQDN name */
- if (opt->option == DHCP_FQDN) {
+ if (opt->option == DHO_FQDN) {
p += 3;
pl -= 3;
}
#define DHCP_INFORM 8
/* DHCP options */
-enum DHCP_OPTIONS
+enum DHO
{
- DHCP_PAD = 0,
- DHCP_SUBNETMASK = 1,
- DHCP_ROUTER = 3,
- DHCP_DNSSERVER = 6,
- DHCP_HOSTNAME = 12,
- DHCP_DNSDOMAIN = 15,
- DHCP_MTU = 26,
- DHCP_BROADCAST = 28,
- DHCP_STATICROUTE = 33,
- DHCP_NISDOMAIN = 40,
- DHCP_NISSERVER = 41,
- DHCP_NTPSERVER = 42,
- DHCP_VENDOR = 43,
- DHCP_IPADDRESS = 50,
- DHCP_LEASETIME = 51,
- DHCP_OPTIONSOVERLOADED = 52,
- DHCP_MESSAGETYPE = 53,
- DHCP_SERVERID = 54,
- DHCP_PARAMETERREQUESTLIST = 55,
- DHCP_MESSAGE = 56,
- DHCP_MAXMESSAGESIZE = 57,
- DHCP_RENEWALTIME = 58,
- DHCP_REBINDTIME = 59,
- DHCP_CLASSID = 60,
- DHCP_CLIENTID = 61,
- DHCP_USERCLASS = 77, /* RFC 3004 */
- DHCP_FQDN = 81,
- DHCP_DNSSEARCH = 119, /* RFC 3397 */
- DHCP_CSR = 121, /* RFC 3442 */
- DHCP_MSCSR = 249, /* MS code for RFC 3442 */
- DHCP_END = 255
+ DHO_PAD = 0,
+ DHO_SUBNETMASK = 1,
+ DHO_ROUTER = 3,
+ DHO_DNSSERVER = 6,
+ DHO_HOSTNAME = 12,
+ DHO_DNSDOMAIN = 15,
+ DHO_MTU = 26,
+ DHO_BROADCAST = 28,
+ DHO_STATICROUTE = 33,
+ DHO_NISDOMAIN = 40,
+ DHO_NISSERVER = 41,
+ DHO_NTPSERVER = 42,
+ DHO_VENDOR = 43,
+ DHO_IPADDRESS = 50,
+ DHO_LEASETIME = 51,
+ DHO_OPTIONSOVERLOADED = 52,
+ DHO_MESSAGETYPE = 53,
+ DHO_SERVERID = 54,
+ DHO_PARAMETERREQUESTLIST = 55,
+ DHO_MESSAGE = 56,
+ DHO_MAXMESSAGESIZE = 57,
+ DHO_RENEWALTIME = 58,
+ DHO_REBINDTIME = 59,
+ DHO_CLASSID = 60,
+ DHO_CLIENTID = 61,
+ DHO_USERCLASS = 77, /* RFC 3004 */
+ DHO_FQDN = 81,
+ DHO_DNSSEARCH = 119, /* RFC 3397 */
+ DHO_CSR = 121, /* RFC 3442 */
+ DHO_MSCSR = 249, /* MS code for RFC 3442 */
+ DHO_END = 255
};
-/* SetFQDNHostName values - lsnybble used in flags
- * byte (see buildmsg.c), hsnybble to create order
+/* FQDN values - lsnybble used in flags
+ * hsnybble to create order
* and to allow 0x00 to mean disable
*/
enum FQDN {
FQDN_BOTH = 0x31
};
-struct fqdn
-{
- uint8_t flags;
- uint8_t r1;
- uint8_t r2;
- char *name;
-};
-
/* Sizes for DHCP options */
#define DHCP_CHADDR_LEN 16
#define SERVERNAME_LEN 64
/* Terminate the encapsulated options */
if (options->vendor[0]) {
options->vendor[0]++;
- options->vendor[options->vendor[0]] = DHCP_END;
+ options->vendor[options->vendor[0]] = DHO_END;
}
if (dhcp_run(options, &pid_fd) == 0)