Skip to content

Commit

Permalink
dhcp: request HOSTNAME and other common options
Browse files Browse the repository at this point in the history
hostname no longer set by default (bnc#861476)
  • Loading branch information
mtomaschewski committed Feb 5, 2014
1 parent b6480fa commit 7b58b4e
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 45 deletions.
4 changes: 2 additions & 2 deletions dhcp4/device.c
Expand Up @@ -289,8 +289,8 @@ ni_dhcp4_acquire(ni_dhcp4_device_t *dev, const ni_dhcp4_request_t *info)
if (classid)
strncpy(config->classid, classid, sizeof(config->classid) - 1);

config->flags = DHCP4_DO_ARP | DHCP4_DO_CSR | DHCP4_DO_MSCSR;
config->flags |= ni_dhcp4_do_bits(info->update);
config->flags = DHCP4_DO_DEFAULT;
config->flags |= ni_dhcp4_do_bits(config->update);

if (ni_debug & NI_TRACE_DHCP) {
ni_trace("Received request:");
Expand Down
27 changes: 19 additions & 8 deletions dhcp4/dhcp.h
Expand Up @@ -91,14 +91,25 @@ typedef struct ni_dhcp4_device {
#define NI_DHCP4_DISCOVERY_TIMEOUT 20 /* seconds */

enum {
DHCP4_DO_ARP = 0x0001,
DHCP4_DO_HOSTNAME = 0x0002,
DHCP4_DO_RESOLVER = 0x0004,
DHCP4_DO_NIS = 0x0008,
DHCP4_DO_NTP = 0x0010,
DHCP4_DO_CSR = 0x0020,
DHCP4_DO_MSCSR = 0x0040,
DHCP4_DO_GATEWAY = 0x0080,
DHCP4_DO_ARP = 0x00000001, /* TODO: -> wickedd */
DHCP4_DO_HOSTNAME = 0x00000002,
DHCP4_DO_RESOLVER = 0x00000004,
DHCP4_DO_NIS = 0x00000008,
DHCP4_DO_NTP = 0x00000010,
DHCP4_DO_CSR = 0x00000020,
DHCP4_DO_MSCSR = 0x00000040,
DHCP4_DO_GATEWAY = 0x00000080,
DHCP4_DO_ROOT = 0x00000100,
DHCP4_DO_NDS = 0x00000200,
DHCP4_DO_SMB = 0x00000400,
DHCP4_DO_SIP = 0x00000800,
DHCP4_DO_LPR = 0x00001000,
DHCP4_DO_LOG = 0x00002000,
DHCP4_DO_DEFAULT = DHCP4_DO_ARP|DHCP4_DO_HOSTNAME|DHCP4_DO_RESOLVER|
DHCP4_DO_NIS|DHCP4_DO_NTP|DHCP4_DO_CSR|
DHCP4_DO_GATEWAY|DHCP4_DO_ROOT|
DHCP4_DO_NDS|DHCP4_DO_SMB|DHCP4_DO_SIP|
DHCP4_DO_LPR|DHCP4_DO_LOG
};

/*
Expand Down
1 change: 1 addition & 0 deletions dhcp4/main.c
Expand Up @@ -330,6 +330,7 @@ dhcp4_test_req_init(ni_dhcp4_request_t *req, const char *request)
{
/* Apply some defaults */
req->acquire_timeout = 10;
req->update = ~0;

if (!ni_string_empty(request)) {
xml_document_t *doc;
Expand Down
97 changes: 63 additions & 34 deletions dhcp4/protocol.c
Expand Up @@ -397,7 +397,8 @@ ni_dhcp4_build_message(const ni_dhcp4_device_t *dev,

if (options->hostname && options->hostname[0]) {
if (options->fqdn == FQDN_DISABLE) {
ni_dhcp4_option_puts(msgbuf, DHCP4_HOSTNAME, options->hostname);
ni_dhcp4_option_puts(msgbuf, DHCP4_HOSTNAME,
options->hostname);
} else {
/* IETF DHC-FQDN option(81)
* http://tools.ietf.org/html/rfc4702#section-2.1
Expand All @@ -421,54 +422,65 @@ ni_dhcp4_build_message(const ni_dhcp4_device_t *dev,
}

params_begin = ni_dhcp4_option_begin(msgbuf, DHCP4_PARAMETERREQUESTLIST);
if (msg_code != DHCP4_INFORM) {
ni_buffer_putc(msgbuf, DHCP4_RENEWALTIME);
ni_buffer_putc(msgbuf, DHCP4_REBINDTIME);
}
ni_buffer_putc(msgbuf, DHCP4_NETMASK);
ni_buffer_putc(msgbuf, DHCP4_BROADCAST);
ni_buffer_putc(msgbuf, DHCP4_MTU);

if (msg_code == DHCP4_DISCOVER) {
/* dhcp4cd says we should include just a single option
* in discovery packets.
* I'm not convinced this is right, but let's do it
* this way.
*/
ni_buffer_putc(msgbuf, DHCP4_DNSSERVER);
} else {
if (msg_code != DHCP4_INFORM) {
ni_buffer_putc(msgbuf, DHCP4_RENEWALTIME);
ni_buffer_putc(msgbuf, DHCP4_REBINDTIME);
}
ni_buffer_putc(msgbuf, DHCP4_NETMASK);
ni_buffer_putc(msgbuf, DHCP4_BROADCAST);

if (options->flags & DHCP4_DO_CSR)
ni_buffer_putc(msgbuf, DHCP4_CSR);
if (options->flags & DHCP4_DO_MSCSR)
ni_buffer_putc(msgbuf, DHCP4_MSCSR);

/* RFC 3442 states classless static routes should be
* before routers and static routes as classless static
* routes override them both */
if (options->flags & DHCP4_DO_CSR) {
ni_buffer_putc(msgbuf, DHCP4_CSR);
}
if (options->flags & DHCP4_DO_MSCSR) {
ni_buffer_putc(msgbuf, DHCP4_MSCSR);
}
/* RFC 3442 states classless static routes should be
* before routers and static routes as classless static
* routes override them both */
if (options->flags & DHCP4_DO_GATEWAY) {
ni_buffer_putc(msgbuf, DHCP4_STATICROUTE);
ni_buffer_putc(msgbuf, DHCP4_ROUTERS);
}
if (options->flags & DHCP4_DO_HOSTNAME) {
ni_buffer_putc(msgbuf, DHCP4_HOSTNAME);
}
if (options->flags & DHCP4_DO_RESOLVER) {
ni_buffer_putc(msgbuf, DHCP4_DNSSEARCH);
ni_buffer_putc(msgbuf, DHCP4_DNSDOMAIN);
ni_buffer_putc(msgbuf, DHCP4_DNSSERVER);

if (options->flags & DHCP4_DO_NIS) {
ni_buffer_putc(msgbuf, DHCP4_NISDOMAIN);
ni_buffer_putc(msgbuf, DHCP4_NISSERVER);
}
if (options->flags & DHCP4_DO_NTP)
ni_buffer_putc(msgbuf, DHCP4_NTPSERVER);
ni_buffer_putc(msgbuf, DHCP4_MTU);
}
if (options->flags & DHCP4_DO_NIS) {
ni_buffer_putc(msgbuf, DHCP4_NISDOMAIN);
ni_buffer_putc(msgbuf, DHCP4_NISSERVER);
}
if (options->flags & DHCP4_DO_NTP) {
ni_buffer_putc(msgbuf, DHCP4_NTPSERVER);
}
if (options->flags & DHCP4_DO_ROOT) {
ni_buffer_putc(msgbuf, DHCP4_ROOTPATH);
ni_buffer_putc(msgbuf, DHCP4_SIPSERVER);
}
if (options->flags & DHCP4_DO_LPR) {
ni_buffer_putc(msgbuf, DHCP4_LPRSERVER);
}
if (options->flags & DHCP4_DO_LOG) {
ni_buffer_putc(msgbuf, DHCP4_LOGSERVER);
}
if (options->flags & DHCP4_DO_NDS) {
ni_buffer_putc(msgbuf, DHCP4_NDS_SERVER);
ni_buffer_putc(msgbuf, DHCP4_NDS_TREE);
ni_buffer_putc(msgbuf, DHCP4_NDS_CTX);
}
if (options->flags & DHCP4_DO_SIP) {
ni_buffer_putc(msgbuf, DHCP4_SIPSERVER);
}
if (options->flags & DHCP4_DO_SMB) {
ni_buffer_putc(msgbuf, DHCP4_NETBIOSNAMESERVER);
ni_buffer_putc(msgbuf, DHCP4_NETBIOSDDSERVER);
ni_buffer_putc(msgbuf, DHCP4_NETBIOSNODETYPE);
ni_buffer_putc(msgbuf, DHCP4_NETBIOSSCOPE);
}

ni_dhcp4_option_end(msgbuf, params_begin);
}
ni_buffer_putc(msgbuf, DHCP4_END);
Expand Down Expand Up @@ -885,6 +897,7 @@ ni_dhcp4_parse_response(const ni_dhcp4_message_t *message, ni_buffer_t *options,
ni_string_array_t dns_domain = NI_STRING_ARRAY_INIT;
ni_string_array_t nis_servers = NI_STRING_ARRAY_INIT;
char *nisdomain = NULL;
char *tmp = NULL;
int opt_overload = 0;
int msg_type = -1;
int use_bootserver = 1;
Expand Down Expand Up @@ -1014,6 +1027,19 @@ ni_dhcp4_parse_response(const ni_dhcp4_message_t *message, ni_buffer_t *options,
ni_dhcp4_decode_dnssearch(&buf, &dns_search, "dns-search domain");
break;

case DHCP4_NDS_SERVER:
ni_dhcp4_decode_address_list(&buf, &lease->nds_servers);
break;
case DHCP4_NDS_CTX:
if (!ni_dhcp4_option_get_printable(&buf, &tmp, "nds-context"))
ni_string_array_append(&lease->nds_context, tmp);
ni_string_free(&tmp);
break;
case DHCP4_NDS_TREE:
ni_dhcp4_option_get_printable(&buf, &lease->nds_tree,
"nds-tree");
break;

case DHCP4_CSR:
case DHCP4_MSCSR:
ni_route_array_destroy(&classless_routes);
Expand Down Expand Up @@ -1282,6 +1308,9 @@ static const char *__dhcp4_option_names[256] = {
[DHCP4_CLIENTID] = "DHCP4_CLIENTID",
[DHCP4_USERCLASS] = "DHCP4_USERCLASS",
[DHCP4_FQDN] = "DHCP4_FQDN",
[DHCP4_NDS_SERVER] = "DHCP4_NDS_SERVER",
[DHCP4_NDS_TREE] = "DHCP4_NDS_TREE",
[DHCP4_NDS_CTX] = "DHCP4_NDS_CTX",
[DHCP4_DNSSEARCH] = "DHCP4_DNSSEARCH",
[DHCP4_SIPSERVER] = "DHCP4_SIPSERVER",
[DHCP4_CSR] = "DHCP4_CSR",
Expand Down
3 changes: 3 additions & 0 deletions dhcp4/protocol.h
Expand Up @@ -108,6 +108,9 @@ enum DHCP4_OPTIONS {
DHCP4_SLPSERVERS = 78, /* RFC 2610 */
DHCP4_SLPSCOPES = 79,
DHCP4_FQDN = 81,
DHCP4_NDS_SERVER = 85, /* RFC 2241 */
DHCP4_NDS_TREE = 86, /* RFC 2241 */
DHCP4_NDS_CTX = 87, /* RFC 2241 */
DHCP4_DNSSEARCH = 119, /* RFC 3397 */
DHCP4_SIPSERVER = 120, /* RFC 3361 */
DHCP4_CSR = 121, /* RFC 3442 */
Expand Down
2 changes: 1 addition & 1 deletion src/leaseinfo.c
Expand Up @@ -557,9 +557,9 @@ __ni_leaseinfo_dump(FILE *out, const ni_addrconf_lease_t *lease,

/* end wicked specific vars */

#endif
__ni_leaseinfo_print_string(out, prefix, "HOSTNAME", lease->hostname,
NULL, 0);
#endif

__ni_leaseinfo_print_addrs(out, prefix, lease->addrs, lease->family);

Expand Down

0 comments on commit 7b58b4e

Please sign in to comment.