BIND 10 trac1224, updated. 1b328591b9bd5f366bc6e205aad0cde28e447442 [1224] Added dhcp4.h (import from includes/dhcp.h from ISC DHCP)
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Oct 19 16:27:28 UTC 2011
The branch, trac1224 has been updated
via 1b328591b9bd5f366bc6e205aad0cde28e447442 (commit)
via 61488d93393fff47ea8cce1c2b41ac004802caaf (commit)
via 0a54d27ad889cc8931bc5a0b6549325c4fb3e45f (commit)
from 81c031de6abed68c9fb4a89b2a71474f36488b9b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1b328591b9bd5f366bc6e205aad0cde28e447442
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Oct 19 18:26:56 2011 +0200
[1224] Added dhcp4.h (import from includes/dhcp.h from ISC DHCP)
commit 61488d93393fff47ea8cce1c2b41ac004802caaf
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Oct 19 18:26:18 2011 +0200
[1224] Limited verbosity of several methods.
commit 0a54d27ad889cc8931bc5a0b6549325c4fb3e45f
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Oct 19 18:23:46 2011 +0200
[1224] DHCP::Pkt4 unittests are now passing.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/dhcp4.h | 191 +++++++++++++++++++++++++++++
src/lib/dhcp/pkt4.cc | 36 +++++-
src/lib/dhcp/pkt4.h | 8 ++
src/lib/dhcp/pkt6.cc | 3 +-
src/lib/dhcp/tests/option6_ia_unittest.cc | 4 +-
src/lib/dhcp/tests/pkt4_unittest.cc | 43 +++++++
src/lib/dhcp/tests/pkt6_unittest.cc | 3 +-
7 files changed, 280 insertions(+), 8 deletions(-)
create mode 100644 src/lib/dhcp/dhcp4.h
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/dhcp4.h b/src/lib/dhcp/dhcp4.h
new file mode 100644
index 0000000..854dca6
--- /dev/null
+++ b/src/lib/dhcp/dhcp4.h
@@ -0,0 +1,191 @@
+/* dhcp.h
+
+ Protocol structures... */
+
+/*
+ * Copyright (c) 2004-2011 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1995-2003 by Internet Software Consortium
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Internet Systems Consortium, Inc.
+ * 950 Charter Street
+ * Redwood City, CA 94063
+ * <info at isc.org>
+ * https://www.isc.org/
+ *
+ * This software has been written for Internet Systems Consortium
+ * by Ted Lemon in cooperation with Vixie Enterprises. To learn more
+ * about Internet Systems Consortium, see ``https://www.isc.org''.
+ * To learn more about Vixie Enterprises, see ``http://www.vix.com''.
+ */
+
+/*
+ * NOTE: This files is imported from ISC DHCP. It uses C notation.
+ * Format kept for easier merge.
+ */
+
+#ifndef DHCP_H
+#define DHCP_H
+
+#define DHCP_UDP_OVERHEAD (20 + /* IP header */ \
+ 8) /* UDP header */
+#define DHCP_SNAME_LEN 64
+#define DHCP_FILE_LEN 128
+#define DHCP_FIXED_NON_UDP 236
+#define DHCP_FIXED_LEN (DHCP_FIXED_NON_UDP + DHCP_UDP_OVERHEAD)
+ /* Everything but options. */
+#define BOOTP_MIN_LEN 300
+
+#define DHCP_MTU_MAX 1500
+#define DHCP_MTU_MIN 576
+
+#define DHCP_MAX_OPTION_LEN (DHCP_MTU_MAX - DHCP_FIXED_LEN)
+#define DHCP_MIN_OPTION_LEN (DHCP_MTU_MIN - DHCP_FIXED_LEN)
+
+/* BOOTP (rfc951) message types */
+#define BOOTREQUEST 1
+#define BOOTREPLY 2
+
+/* Possible values for flags field... */
+#define BOOTP_BROADCAST 32768L
+
+/* Possible values for hardware type (htype) field... */
+#define HTYPE_ETHER 1 /* Ethernet 10Mbps */
+#define HTYPE_IEEE802 6 /* IEEE 802.2 Token Ring... */
+#define HTYPE_FDDI 8 /* FDDI... */
+
+/* Magic cookie validating dhcp options field (and bootp vendor
+ extensions field). */
+#define DHCP_OPTIONS_COOKIE "\143\202\123\143"
+
+/* DHCP Option codes: */
+
+#define DHO_PAD 0
+#define DHO_SUBNET_MASK 1
+#define DHO_TIME_OFFSET 2
+#define DHO_ROUTERS 3
+#define DHO_TIME_SERVERS 4
+#define DHO_NAME_SERVERS 5
+#define DHO_DOMAIN_NAME_SERVERS 6
+#define DHO_LOG_SERVERS 7
+#define DHO_COOKIE_SERVERS 8
+#define DHO_LPR_SERVERS 9
+#define DHO_IMPRESS_SERVERS 10
+#define DHO_RESOURCE_LOCATION_SERVERS 11
+#define DHO_HOST_NAME 12
+#define DHO_BOOT_SIZE 13
+#define DHO_MERIT_DUMP 14
+#define DHO_DOMAIN_NAME 15
+#define DHO_SWAP_SERVER 16
+#define DHO_ROOT_PATH 17
+#define DHO_EXTENSIONS_PATH 18
+#define DHO_IP_FORWARDING 19
+#define DHO_NON_LOCAL_SOURCE_ROUTING 20
+#define DHO_POLICY_FILTER 21
+#define DHO_MAX_DGRAM_REASSEMBLY 22
+#define DHO_DEFAULT_IP_TTL 23
+#define DHO_PATH_MTU_AGING_TIMEOUT 24
+#define DHO_PATH_MTU_PLATEAU_TABLE 25
+#define DHO_INTERFACE_MTU 26
+#define DHO_ALL_SUBNETS_LOCAL 27
+#define DHO_BROADCAST_ADDRESS 28
+#define DHO_PERFORM_MASK_DISCOVERY 29
+#define DHO_MASK_SUPPLIER 30
+#define DHO_ROUTER_DISCOVERY 31
+#define DHO_ROUTER_SOLICITATION_ADDRESS 32
+#define DHO_STATIC_ROUTES 33
+#define DHO_TRAILER_ENCAPSULATION 34
+#define DHO_ARP_CACHE_TIMEOUT 35
+#define DHO_IEEE802_3_ENCAPSULATION 36
+#define DHO_DEFAULT_TCP_TTL 37
+#define DHO_TCP_KEEPALIVE_INTERVAL 38
+#define DHO_TCP_KEEPALIVE_GARBAGE 39
+#define DHO_NIS_DOMAIN 40
+#define DHO_NIS_SERVERS 41
+#define DHO_NTP_SERVERS 42
+#define DHO_VENDOR_ENCAPSULATED_OPTIONS 43
+#define DHO_NETBIOS_NAME_SERVERS 44
+#define DHO_NETBIOS_DD_SERVER 45
+#define DHO_NETBIOS_NODE_TYPE 46
+#define DHO_NETBIOS_SCOPE 47
+#define DHO_FONT_SERVERS 48
+#define DHO_X_DISPLAY_MANAGER 49
+#define DHO_DHCP_REQUESTED_ADDRESS 50
+#define DHO_DHCP_LEASE_TIME 51
+#define DHO_DHCP_OPTION_OVERLOAD 52
+#define DHO_DHCP_MESSAGE_TYPE 53
+#define DHO_DHCP_SERVER_IDENTIFIER 54
+#define DHO_DHCP_PARAMETER_REQUEST_LIST 55
+#define DHO_DHCP_MESSAGE 56
+#define DHO_DHCP_MAX_MESSAGE_SIZE 57
+#define DHO_DHCP_RENEWAL_TIME 58
+#define DHO_DHCP_REBINDING_TIME 59
+#define DHO_VENDOR_CLASS_IDENTIFIER 60
+#define DHO_DHCP_CLIENT_IDENTIFIER 61
+#define DHO_NWIP_DOMAIN_NAME 62
+#define DHO_NWIP_SUBOPTIONS 63
+#define DHO_USER_CLASS 77
+#define DHO_FQDN 81
+#define DHO_DHCP_AGENT_OPTIONS 82
+#define DHO_AUTHENTICATE 90 /* RFC3118, was 210 */
+#define DHO_CLIENT_LAST_TRANSACTION_TIME 91
+#define DHO_ASSOCIATED_IP 92
+#define DHO_SUBNET_SELECTION 118 /* RFC3011! */
+#define DHO_DOMAIN_SEARCH 119 /* RFC3397 */
+#define DHO_VIVCO_SUBOPTIONS 124
+#define DHO_VIVSO_SUBOPTIONS 125
+
+#define DHO_END 255
+
+/* DHCP message types. */
+#define DHCPDISCOVER 1
+#define DHCPOFFER 2
+#define DHCPREQUEST 3
+#define DHCPDECLINE 4
+#define DHCPACK 5
+#define DHCPNAK 6
+#define DHCPRELEASE 7
+#define DHCPINFORM 8
+#define DHCPLEASEQUERY 10
+#define DHCPLEASEUNASSIGNED 11
+#define DHCPLEASEUNKNOWN 12
+#define DHCPLEASEACTIVE 13
+
+
+/* Relay Agent Information option subtypes: */
+#define RAI_CIRCUIT_ID 1
+#define RAI_REMOTE_ID 2
+#define RAI_AGENT_ID 3
+#define RAI_LINK_SELECT 5
+
+/* FQDN suboptions: */
+#define FQDN_NO_CLIENT_UPDATE 1
+#define FQDN_SERVER_UPDATE 2
+#define FQDN_ENCODED 3
+#define FQDN_RCODE1 4
+#define FQDN_RCODE2 5
+#define FQDN_HOSTNAME 6
+#define FQDN_DOMAINNAME 7
+#define FQDN_FQDN 8
+#define FQDN_SUBOPTION_COUNT 8
+
+/* Enterprise Suboptions: */
+#define VENDOR_ISC_SUBOPTIONS 2495
+
+#define DHCP4_CLIENT_PORT 68
+#define DHCP4_SERVER_PORT 67
+
+
+#endif /* DHCP_H */
+
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index b4d5996..478cbad 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -33,7 +33,7 @@ Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
ifindex_(0),
local_port_(DHCP4_SERVER_PORT),
remote_port_(DHCP4_CLIENT_PORT),
- op_(BOOTREPLY),
+ op_(DHCPTypeToBootpType(msg_type)),
htype_(HTYPE_ETHER),
hlen_(0),
hops_(0),
@@ -74,6 +74,10 @@ Pkt4::Pkt4(const uint8_t* data, size_t len)
bufferOut_(DHCPV4_PKT_HDR_LEN),
msg_type_(DHCPDISCOVER)
{
+ if (len < DHCPV4_PKT_HDR_LEN) {
+ isc_throw(OutOfRange, "Truncated DHCPv4 packet (len=" << len
+ << " received, at least 236 bytes expected.");
+ }
bufferIn_.writeData(data, len);
}
@@ -104,19 +108,19 @@ Pkt4::toText() {
tmp << "localAddr=[" << local_addr_.toText() << "]:" << local_port_
<< " remoteAddr=[" << remote_addr_.toText()
<< "]:" << remote_port_ << endl;
- tmp << "msgtype=" << msg_type_
- << ", transid=0x" << hex << transid_ << dec
+ tmp << "msgtype=" << msg_type_
+ << ", transid=0x" << hex << transid_ << dec
<< endl;
return tmp.str();
}
-void
+void
Pkt4::setHWAddr(uint8_t hType, uint8_t hlen, const uint8_t* macAddr) {
/// TODO Rewrite this once support for client-identifier option
/// is implemented (ticket 1228?)
if (hlen>MAX_CHADDR_LEN) {
- isc_throw(OutOfRange, "Hardware address (len=" << hlen
+ isc_throw(OutOfRange, "Hardware address (len=" << hlen
<< " too long. Max " << MAX_CHADDR_LEN << " supported.");
}
htype_ = hType;
@@ -149,5 +153,27 @@ Pkt4::setFile(const uint8_t* file, size_t fileLen /*= MAX_FILE_LEN*/) {
// no need to store snameLen as any empty space is filled with 0s
}
+uint8_t
+Pkt4::DHCPTypeToBootpType(uint8_t dhcpType) {
+ switch (dhcpType) {
+ case DHCPDISCOVER:
+ case DHCPREQUEST:
+ case DHCPDECLINE:
+ case DHCPRELEASE:
+ case DHCPINFORM:
+ case DHCPLEASEQUERY:
+ return (BOOTREQUEST);
+ case DHCPACK:
+ case DHCPNAK:
+ case DHCPOFFER:
+ case DHCPLEASEUNASSIGNED:
+ case DHCPLEASEUNKNOWN:
+ case DHCPLEASEACTIVE:
+ return (BOOTREPLY);
+ default:
+ isc_throw(OutOfRange, "Invalid message type: "
+ << static_cast<int>(dhcpType) );
+ }
+}
};
diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h
index 85135f9..cc20ad8 100644
--- a/src/lib/dhcp/pkt4.h
+++ b/src/lib/dhcp/pkt4.h
@@ -269,6 +269,14 @@ public:
protected:
+ /// converts DHCP message type to BOOTP op type
+ ///
+ /// @param dhcpType DHCP message type (e.g. DHCPDISCOVER)
+ ///
+ /// @return BOOTP type (BOOTREQUEST or BOOTREPLY)
+ uint8_t
+ DHCPTypeToBootpType(uint8_t dhcpType);
+
/// local address (dst if receiving packet, src if sending packet)
isc::asiolink::IOAddress local_addr_;
diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc
index 65bd95e..ef73f79 100644
--- a/src/lib/dhcp/pkt6.cc
+++ b/src/lib/dhcp/pkt6.cc
@@ -124,7 +124,8 @@ Pkt6::packUDP() {
cout << "Packet build failed:" << e.what() << endl;
return (false);
}
- cout << "Packet built, len=" << len() << endl;
+ // Limited verbosity of this method
+ // cout << "Packet built, len=" << len() << endl;
return (true);
}
diff --git a/src/lib/dhcp/tests/option6_ia_unittest.cc b/src/lib/dhcp/tests/option6_ia_unittest.cc
index ab949de..0368048 100644
--- a/src/lib/dhcp/tests/option6_ia_unittest.cc
+++ b/src/lib/dhcp/tests/option6_ia_unittest.cc
@@ -220,7 +220,9 @@ TEST_F(Option6IATest, suboptions_unpack) {
Option6IA* ia = 0;
EXPECT_NO_THROW({
ia = new Option6IA(D6O_IA_NA, buf, 128, 4, 44);
- cout << "Parsed option:" << endl << ia->toText() << endl;
+
+ // let's limit verbosity of this test
+ // cout << "Parsed option:" << endl << ia->toText() << endl;
});
ASSERT_TRUE(ia);
diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc
index 22a4f04..4c1f13d 100644
--- a/src/lib/dhcp/tests/pkt4_unittest.cc
+++ b/src/lib/dhcp/tests/pkt4_unittest.cc
@@ -302,6 +302,49 @@ TEST(Pkt4Test, hwAddr) {
/// longer than 16 bytes should be stored in client-identifier option
}
+TEST(Pkt4Test, msgTypes) {
+
+ struct msgType {
+ uint8_t dhcp;
+ uint8_t bootp;
+ };
+
+ msgType types[] = {
+ {DHCPDISCOVER, BOOTREQUEST},
+ {DHCPOFFER, BOOTREPLY},
+ {DHCPREQUEST, BOOTREQUEST},
+ {DHCPDECLINE, BOOTREQUEST},
+ {DHCPACK, BOOTREPLY},
+ {DHCPNAK, BOOTREPLY},
+ {DHCPRELEASE, BOOTREQUEST},
+ {DHCPINFORM, BOOTREQUEST},
+ {DHCPLEASEQUERY, BOOTREQUEST},
+ {DHCPLEASEUNASSIGNED, BOOTREPLY},
+ {DHCPLEASEUNKNOWN, BOOTREPLY},
+ {DHCPLEASEACTIVE, BOOTREPLY}
+ };
+
+ Pkt4* pkt = 0;
+ for (int i=0; i < sizeof(types)/sizeof(msgType); i++) {
+
+ pkt = new Pkt4(types[i].dhcp, 0);
+ EXPECT_EQ(types[i].dhcp, pkt->getType());
+
+ EXPECT_EQ(types[i].bootp, pkt->getOp());
+
+ delete pkt;
+ pkt = 0;
+ }
+
+ EXPECT_THROW(
+ pkt = new Pkt4(100, 0), // there's no message type 100
+ OutOfRange
+ );
+ if (pkt) {
+ delete pkt;
+ }
+}
+
// this test verifies handling of sname field
TEST(Pkt4Test, sname) {
diff --git a/src/lib/dhcp/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc
index 2819f7d..0f110ba 100644
--- a/src/lib/dhcp/tests/pkt6_unittest.cc
+++ b/src/lib/dhcp/tests/pkt6_unittest.cc
@@ -108,7 +108,8 @@ TEST_F(Pkt6Test, unpack_solicit1) {
EXPECT_FALSE(sol->getOption(D6O_IA_TA));
EXPECT_FALSE(sol->getOption(D6O_IAADDR));
- std::cout << sol->toText();
+ // let's limit verbosity of this test
+ // std::cout << sol->toText();
delete sol;
}
More information about the bind10-changes
mailing list