if (msg->type < 0 || msg->type > 31 || !((1u << msg->type) & msgs)) {
VLOG_DBG("received unexpected %s in %s state: %s",
dhcp_type_name(msg->type), state_name(cli->state),
- dhcp_msg_to_string(msg, &cli->s));
+ dhcp_msg_to_string(msg, false, &cli->s));
} else if (msg->xid != cli->xid) {
VLOG_DBG("ignoring %s with xid != %08"PRIx32" in %s state: %s",
dhcp_type_name(msg->type), msg->xid,
- state_name(cli->state), dhcp_msg_to_string(msg, &cli->s));
+ state_name(cli->state),
+ dhcp_msg_to_string(msg, false, &cli->s));
} else {
return true;
}
{
uint32_t lease, netmask;
if (!dhcp_msg_get_secs(msg, DHCP_CODE_LEASE_TIME, 0, &lease)) {
- VLOG_WARN("%s lacks lease time: %s",
- dhcp_type_name(msg->type), dhcp_msg_to_string(msg, &cli->s));
+ VLOG_WARN("%s lacks lease time: %s", dhcp_type_name(msg->type),
+ dhcp_msg_to_string(msg, false, &cli->s));
} else if (!dhcp_msg_get_ip(msg, DHCP_CODE_SUBNET_MASK, 0, &netmask)) {
- VLOG_WARN("%s lacks netmask: %s",
- dhcp_type_name(msg->type), dhcp_msg_to_string(msg, &cli->s));
+ VLOG_WARN("%s lacks netmask: %s", dhcp_type_name(msg->type),
+ dhcp_msg_to_string(msg, false, &cli->s));
} else if (lease < MIN_ACCEPTABLE_LEASE) {
VLOG_WARN("Ignoring %s with %"PRIu32"-second lease time: %s",
dhcp_type_name(msg->type), lease,
- dhcp_msg_to_string(msg, &cli->s));
+ dhcp_msg_to_string(msg, false, &cli->s));
} else if (cli->validate_offer && !cli->validate_offer(msg, cli->aux)) {
VLOG_DBG("client validation hook refused offer: %s",
- dhcp_msg_to_string(msg, &cli->s));
+ dhcp_msg_to_string(msg, false, &cli->s));
} else {
return true;
}
if (!dhcp_msg_get_ip(&msg, DHCP_CODE_SERVER_IDENTIFIER,
0, &cli->server_ip)) {
VLOG_WARN("DHCPOFFER lacks server identifier: %s",
- dhcp_msg_to_string(&msg, &cli->s));
+ dhcp_msg_to_string(&msg, false, &cli->s));
continue;
}
- VLOG_DBG("accepting DHCPOFFER: %s", dhcp_msg_to_string(&msg, &cli->s));
+ VLOG_DBG("accepting DHCPOFFER: %s",
+ dhcp_msg_to_string(&msg, false, &cli->s));
cli->ipaddr = msg.yiaddr;
state_transition(cli, S_REQUESTING);
break;
cli->router = INADDR_ANY;
}
state_transition(cli, S_BOUND);
- VLOG_DBG("Bound: %s", dhcp_msg_to_string(&msg, &cli->s));
+ VLOG_DBG("Bound: %s", dhcp_msg_to_string(&msg, false, &cli->s));
return true;
}
}
buffer_pull(&b, b.l7 - b.data);
error = dhcp_parse(msg, &b);
if (!error) {
- VLOG_DBG("received %s", dhcp_msg_to_string(msg, &cli->s));
+ VLOG_DBG("received %s", dhcp_msg_to_string(msg, false, &cli->s));
buffer_uninit(&b);
return true;
}
* frame to have to be discarded or fragmented if it travels over a regular
* Ethernet at some point. 1500 bytes should be enough for anyone. */
if (b.size <= ETH_TOTAL_MAX) {
- VLOG_DBG("sending %s", dhcp_msg_to_string(msg, &cli->s));
+ VLOG_DBG("sending %s", dhcp_msg_to_string(msg, false, &cli->s));
error = netdev_send(cli->netdev, &b);
if (error) {
VLOG_ERR("send failed on %s: %s",
const struct arg_type *type = &types[class->type];
size_t offset;
- ds_put_char(ds, ' ');
if (class->name) {
const char *cp;
for (cp = class->name; *cp; cp++) {
return ds_cstr(ds);
}
-/* Replaces 'ds' by a string representation of 'msg'. */
+/* Replaces 'ds' by a string representation of 'msg'. If 'multiline' is
+ * false, 'ds' receives a single-line representation of 'msg', otherwise a
+ * multiline representation. */
const char *
-dhcp_msg_to_string(const struct dhcp_msg *msg, struct ds *ds)
+dhcp_msg_to_string(const struct dhcp_msg *msg, bool multiline, struct ds *ds)
{
+ char separator = multiline ? '\n' : ' ';
int code;
ds_clear(ds);
- ds_put_format(ds, "%s %s xid=%08"PRIx32" secs=%"PRIu16,
+ ds_put_format(ds, "%s%c%s%cxid=%08"PRIx32"%csecs=%"PRIu16,
(msg->op == DHCP_BOOTREQUEST ? "BOOTREQUEST"
: msg->op == DHCP_BOOTREPLY ? "BOOTREPLY"
: "<<bad DHCP op>>"),
- dhcp_type_name(msg->type), msg->xid, msg->secs);
+ separator, dhcp_type_name(msg->type),
+ separator, msg->xid,
+ separator, msg->secs);
if (msg->flags) {
- ds_put_cstr(ds, " flags=");
+ ds_put_format(ds, "%cflags=", separator);
if (msg->flags & DHCP_FLAGS_BROADCAST) {
ds_put_cstr(ds, "[BROADCAST]");
}
}
}
if (msg->ciaddr) {
- ds_put_format(ds, " ciaddr="IP_FMT, IP_ARGS(&msg->ciaddr));
+ ds_put_format(ds, "%cciaddr="IP_FMT, separator, IP_ARGS(&msg->ciaddr));
}
if (msg->yiaddr) {
- ds_put_format(ds, " yiaddr="IP_FMT, IP_ARGS(&msg->yiaddr));
+ ds_put_format(ds, "%cyiaddr="IP_FMT, separator, IP_ARGS(&msg->yiaddr));
}
if (msg->siaddr) {
- ds_put_format(ds, " siaddr="IP_FMT, IP_ARGS(&msg->siaddr));
+ ds_put_format(ds, "%csiaddr="IP_FMT, separator, IP_ARGS(&msg->siaddr));
}
if (msg->giaddr) {
- ds_put_format(ds, " giaddr="IP_FMT, IP_ARGS(&msg->giaddr));
+ ds_put_format(ds, "%cgiaddr="IP_FMT, separator, IP_ARGS(&msg->giaddr));
}
- ds_put_format(ds, " chaddr="ETH_ADDR_FMT, ETH_ADDR_ARGS(msg->chaddr));
+ ds_put_format(ds, "%cchaddr="ETH_ADDR_FMT,
+ separator, ETH_ADDR_ARGS(msg->chaddr));
for (code = 0; code < DHCP_N_OPTIONS; code++) {
const struct dhcp_option *opt = &msg->options[code];
if (opt->data) {
+ ds_put_char(ds, separator);
dhcp_option_to_string(opt, code, ds);
}
}
+ if (multiline) {
+ ds_put_char(ds, separator);
+ }
return ds_cstr(ds);
}
VLOG_DBG("invalid DHCP message dump:\n%s", ds_cstr(&ds));
ds_clear(&ds);
- dhcp_msg_to_string(msg, &ds);
+ dhcp_msg_to_string(msg, false, &ds);
VLOG_DBG("partially dissected DHCP message: %s", ds_cstr(&ds));
ds_destroy(&ds);