aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/dhcp/dhcp4_packet.c
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-10-15 15:47:55 +0000
committerNeale Ranns <nranns@cisco.com>2019-10-25 17:56:06 +0000
commit6bcc6a45573f387fa6c1682069da7ee9036cabe2 (patch)
tree2471089b417624c5eeda998db113edeb5b4b5c95 /src/plugins/dhcp/dhcp4_packet.c
parentd7b306657d205fddd781e982aec5f3c3dc69fa88 (diff)
dhcp: fix crash on unicast renewal send
Type: fix - when the addresses were learnt a copy of the client was sent to the main thread, this meant the unicast adjacecny was saved on the copy not on the original. - Add logging. - Improve the proxy-node that hands the clint packets so the DHCP packets are traced. - allow a renewal to configure new address data Change-Id: I6ab0afcccbc4a1cdefdd1b8beeda8fc7ba20ec1f Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/plugins/dhcp/dhcp4_packet.c')
-rw-r--r--src/plugins/dhcp/dhcp4_packet.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/plugins/dhcp/dhcp4_packet.c b/src/plugins/dhcp/dhcp4_packet.c
new file mode 100644
index 00000000000..7592120ffea
--- /dev/null
+++ b/src/plugins/dhcp/dhcp4_packet.c
@@ -0,0 +1,122 @@
+/*
+ * dhcp4_packet.c: dhcp packet format functions
+ *
+ * Copyright (c) 2013 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dhcp/dhcp4_packet.h>
+#include <vnet/ip/format.h>
+
+u8 *
+format_dhcp_packet_type (u8 * s, va_list * args)
+{
+ dhcp_packet_type_t pt = va_arg (*args, dhcp_packet_type_t);
+
+ switch (pt)
+ {
+ case DHCP_PACKET_DISCOVER:
+ s = format (s, "discover");
+ break;
+ case DHCP_PACKET_OFFER:
+ s = format (s, "offer");
+ break;
+ case DHCP_PACKET_REQUEST:
+ s = format (s, "request");
+ break;
+ case DHCP_PACKET_ACK:
+ s = format (s, "ack");
+ break;
+ case DHCP_PACKET_NAK:
+ s = format (s, "nack");
+ break;
+ }
+ return (s);
+}
+
+u8 *
+format_dhcp_header (u8 * s, va_list * args)
+{
+ dhcp_header_t *d = va_arg (*args, dhcp_header_t *);
+ u32 max_bytes = va_arg (*args, u32);
+ dhcp_option_t *o;
+ u32 tmp;
+
+ s = format (s, "opcode:%s", (d->opcode == 1 ? "request" : "reply"));
+ s = format (s, " hw[type:%d addr-len:%d addr:%U]",
+ d->hardware_type, d->hardware_address_length,
+ format_hex_bytes, d->client_hardware_address,
+ d->hardware_address_length);
+ s = format (s, " hops%d", d->hops);
+ s = format (s, " transaction-ID:0x%x", d->transaction_identifier);
+ s = format (s, " seconds:%d", d->seconds);
+ s = format (s, " flags:0x%x", d->flags);
+ s = format (s, " client:%U", format_ip4_address, &d->client_ip_address);
+ s = format (s, " your:%U", format_ip4_address, &d->your_ip_address);
+ s = format (s, " server:%U", format_ip4_address, &d->server_ip_address);
+ s = format (s, " gateway:%U", format_ip4_address, &d->gateway_ip_address);
+ s = format (s, " cookie:%U", format_ip4_address, &d->magic_cookie);
+
+ o = (dhcp_option_t *) d->options;
+
+ while (o->option != 0xFF /* end of options */ &&
+ (u8 *) o < (u8 *) d + max_bytes)
+ {
+ switch (o->option)
+ {
+ case 53: /* dhcp message type */
+ tmp = o->data[0];
+ s =
+ format (s, ", option-53: type:%U", format_dhcp_packet_type, tmp);
+ break;
+ case 54: /* dhcp server address */
+ s = format (s, ", option-54: server:%U",
+ format_ip4_address, &o->data_as_u32[0]);
+ break;
+ case 58: /* lease renew time in seconds */
+ s = format (s, ", option-58: renewal:%d",
+ clib_host_to_net_u32 (o->data_as_u32[0]));
+ break;
+ case 1: /* subnet mask */
+ s = format (s, ", option-1: subnet-mask:%d",
+ clib_host_to_net_u32 (o->data_as_u32[0]));
+ break;
+ case 3: /* router address */
+ s = format (s, ", option-3: router:%U",
+ format_ip4_address, &o->data_as_u32[0]);
+ break;
+ case 6: /* domain server address */
+ s = format (s, ", option-6: domian-server:%U",
+ format_hex_bytes, o->data, o->length);
+ break;
+ case 12: /* hostname */
+ s = format (s, ", option-12: hostname:%U",
+ format_hex_bytes, o->data, o->length);
+ break;
+ default:
+ tmp = o->option;
+ s = format (s, " option-%d: skipped", tmp);
+ break;
+ }
+ o = (dhcp_option_t *) (((u8 *) o) + (o->length + 2));
+ }
+ return (s);
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */