Browse Source

[1186] Part 4 of review changes

 - added consts in packOption6, unpackOptions6
 - removed version() method
 - alignments fixed in dhcp6.h
Tomek Mrugalski 13 years ago
parent
commit
92b2aa9c96

+ 0 - 1
src/lib/dhcp/Makefile.am

@@ -22,5 +22,4 @@ EXTRA_DIST  = README
 
 libdhcp_la_CXXFLAGS = $(AM_CXXFLAGS)
 libdhcp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
-libdhcp_la_LDFLAGS  = $(LOG4CPLUS_LDFLAGS)
 libdhcp_la_LIBADD   = $(top_builddir)/src/lib/util/libutil.la

+ 10 - 10
src/lib/dhcp/dhcp6.h

@@ -22,18 +22,18 @@
 #define D6O_IA_NA                               3
 #define D6O_IA_TA                               4
 #define D6O_IAADDR                              5
-#define D6O_ORO                                         6
+#define D6O_ORO                                 6
 #define D6O_PREFERENCE                          7
 #define D6O_ELAPSED_TIME                        8
 #define D6O_RELAY_MSG                           9
 /* Option code 10 unassigned. */
 #define D6O_AUTH                                11
 #define D6O_UNICAST                             12
-#define D6O_STATUS_CODE                                 13
+#define D6O_STATUS_CODE                         13
 #define D6O_RAPID_COMMIT                        14
 #define D6O_USER_CLASS                          15
 #define D6O_VENDOR_CLASS                        16
-#define D6O_VENDOR_OPTS                                 17
+#define D6O_VENDOR_OPTS                         17
 #define D6O_INTERFACE_ID                        18
 #define D6O_RECONF_MSG                          19
 #define D6O_RECONF_ACCEPT                       20
@@ -43,7 +43,7 @@
 #define D6O_DOMAIN_SEARCH                       24 /* RFC3646 */
 #define D6O_IA_PD                               25 /* RFC3633 */
 #define D6O_IAPREFIX                            26 /* RFC3633 */
-#define D6O_NIS_SERVERS                                 27 /* RFC3898 */
+#define D6O_NIS_SERVERS                         27 /* RFC3898 */
 #define D6O_NISP_SERVERS                        28 /* RFC3898 */
 #define D6O_NIS_DOMAIN_NAME                     29 /* RFC3898 */
 #define D6O_NISP_DOMAIN_NAME                    30 /* RFC3898 */
@@ -55,13 +55,13 @@
 #define D6O_GEOCONF_CIVIC                       36 /* RFC4776 */
 #define D6O_REMOTE_ID                           37 /* RFC4649 */
 #define D6O_SUBSCRIBER_ID                       38 /* RFC4580 */
-#define D6O_CLIENT_FQDN                                 39 /* RFC4704 */
+#define D6O_CLIENT_FQDN                         39 /* RFC4704 */
 #define D6O_PANA_AGENT                          40 /* paa-option */
 #define D6O_NEW_POSIX_TIMEZONE                  41 /* RFC4833 */
 #define D6O_NEW_TZDB_TIMEZONE                   42 /* RFC4833 */
-#define D6O_ERO                                         43 /* RFC4994 */
+#define D6O_ERO                                 43 /* RFC4994 */
 #define D6O_LQ_QUERY                            44 /* RFC5007 */
-#define D6O_CLIENT_DATA                                 45 /* RFC5007 */
+#define D6O_CLIENT_DATA                         45 /* RFC5007 */
 #define D6O_CLT_TIME                            46 /* RFC5007 */
 #define D6O_LQ_RELAY_DATA                       47 /* RFC5007 */
 #define D6O_LQ_CLIENT_LINK                      48 /* RFC5007 */
@@ -76,7 +76,7 @@
 #define STATUS_NotOnLink         4
 #define STATUS_UseMulticast      5
 #define STATUS_NoPrefixAvail     6
-#define STATUS_UnknownQueryType          7
+#define STATUS_UnknownQueryType  7
 #define STATUS_MalformedQuery    8
 #define STATUS_NotConfigured     9
 #define STATUS_NotAllowed       10
@@ -106,8 +106,8 @@ extern const int dhcpv6_type_name_max;
 /* DUID type definitions (RFC3315 section 9).
  */
 #define DUID_LLT        1
-#define DUID_EN                 2
-#define DUID_LL                 3
+#define DUID_EN         2
+#define DUID_LL         3
 
 /* Offsets into IA_*'s where Option spaces commence.  */
 #define IA_NA_OFFSET 12 /* IAID, T1, T2, all 4 octets each */

+ 5 - 9
src/lib/dhcp/libdhcp.cc

@@ -28,13 +28,9 @@ using namespace isc::dhcp;
 // static array with factories for options
 std::map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
 
-std::string
-LibDHCP::version() {
-    return PACKAGE_VERSION;
-}
-
 unsigned int
-LibDHCP::unpackOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
+LibDHCP::unpackOptions6(const boost::shared_array<uint8_t> buf,
+                        unsigned int buf_len,
                         unsigned int offset, unsigned int parse_len,
                         isc::dhcp::Option::Option6Lst& options) {
     if (offset + parse_len > buf_len) {
@@ -44,7 +40,7 @@ LibDHCP::unpackOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
     }
     unsigned int end = offset + parse_len;
 
-    while (offset<end) {
+    while ( offset +4 <= end ) {
         unsigned int opt_type = buf[offset]*256 + buf[offset+1];
         offset += 2;
         unsigned int opt_len = buf[offset]*256 + buf[offset+1];
@@ -92,9 +88,9 @@ unsigned int
 LibDHCP::packOptions6(boost::shared_array<uint8_t> data,
                       unsigned int data_len,
                       unsigned int offset,
-                      isc::dhcp::Option::Option6Lst& options) {
+                      const isc::dhcp::Option::Option6Lst& options) {
     try {
-        for (isc::dhcp::Option::Option6Lst::iterator it = options.begin();
+        for (isc::dhcp::Option::Option6Lst::const_iterator it = options.begin();
              it != options.end();
              ++it) {
             unsigned short opt_len = (*it).second->len();

+ 2 - 9
src/lib/dhcp/libdhcp.h

@@ -24,13 +24,6 @@ namespace dhcp {
 class LibDHCP {
 
 public:
-    /// Returns version of the library.
-    ///
-    /// @return string that contains libdhcp version.
-    ///
-    static std::string
-    version();
-
     /// Builds collection of options.
     ///
     /// Builds raw (on-wire) data for provided collection of options.
@@ -46,7 +39,7 @@ public:
     static unsigned int
     packOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
                  unsigned int offset,
-                 isc::dhcp::Option::Option6Lst& options);
+                 const isc::dhcp::Option::Option6Lst& options);
 
     ///
     /// Parses provided buffer and creates Option objects.
@@ -62,7 +55,7 @@ public:
     /// @return offset to first byte after last parsed option
     ///
     static unsigned int
-    unpackOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
+    unpackOptions6(const boost::shared_array<uint8_t> buf, unsigned int buf_len,
                    unsigned int offset, unsigned int parse_len,
                    isc::dhcp::Option::Option6Lst& options_);
 

+ 0 - 6
src/lib/dhcp/tests/libdhcp_unittest.cc

@@ -33,12 +33,6 @@ public:
     }
 };
 
-TEST_F(LibDhcpTest, basic) {
-    // dummy test
-
-    EXPECT_EQ(LibDHCP::version(), PACKAGE_VERSION);
-}
-
 TEST_F(LibDhcpTest, packOptions6) {
     boost::shared_array<uint8_t> buf(new uint8_t[512]);
     isc::dhcp::Option::Option6Lst opts; // list of options