Browse Source

[5020] Changes after review.

Tomek Mrugalski 8 years ago
parent
commit
1c43f8dc08

+ 20 - 0
src/bin/dhcp4/dhcp4_lexer.ll

@@ -196,6 +196,26 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
     }
 }
 
+\"raw\" {
+    std::cout << "RAW regexp" << std::endl;
+    switch(driver.ctx_) {
+    case isc::dhcp::Parser4Context::INTERFACES_CONFIG:
+        return  isc::dhcp::Dhcp4Parser::make_DHCP_SOCKET_TYPE_RAW(driver.loc_);
+    default:
+        return isc::dhcp::Dhcp4Parser::make_STRING("raw", driver.loc_);
+    }
+}
+
+\"udp\" {
+    std::cout << "RAW regexp" << std::endl;
+    switch(driver.ctx_) {
+    case isc::dhcp::Parser4Context::INTERFACES_CONFIG:
+        return  isc::dhcp::Dhcp4Parser::make_DHCP_SOCKET_TYPE_UDP(driver.loc_);
+    default:
+        return isc::dhcp::Dhcp4Parser::make_STRING("udp", driver.loc_);
+    }
+}
+
 \"interfaces\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser4Context::INTERFACES_CONFIG:

+ 13 - 5
src/bin/dhcp4/dhcp4_parser.yy

@@ -53,6 +53,8 @@ using namespace std;
   INTERFACES_CONFIG "interfaces-config"
   INTERFACES "interfaces"
   DHCP_SOCKET_TYPE "dhcp-socket-type"
+  DHCP_SOCKET_TYPE_RAW "raw"
+  DHCP_SOCKET_TYPE_UDP "udp"
 
   ECHO_CLIENT_ID "echo-client-id"
   MATCH_CLIENT_ID "match-client-id"
@@ -443,12 +445,18 @@ interfaces_list: INTERFACES {
     ctx.leave();
 };
 
-dhcp_socket_type: DHCP_SOCKET_TYPE {
-    ctx.enter(ctx.NO_KEYWORD);
-} COLON STRING {
-    ElementPtr type(new StringElement($4, ctx.loc2pos(@4)));
+dhcp_socket_type: dhcp_socket_type_raw
+                | dhcp_socket_type_udp
+                ;
+
+dhcp_socket_type_raw: DHCP_SOCKET_TYPE COLON DHCP_SOCKET_TYPE_RAW {
+    ElementPtr type(new StringElement("raw", ctx.loc2pos(@3)));
+    ctx.stack_.back()->set("dhcp-socket-type", type);
+};
+
+dhcp_socket_type_udp: DHCP_SOCKET_TYPE COLON DHCP_SOCKET_TYPE_UDP {
+    ElementPtr type(new StringElement("udp", ctx.loc2pos(@3)));
     ctx.stack_.back()->set("dhcp-socket-type", type);
-    ctx.leave();
 };
 
 lease_database: LEASE_DATABASE {

+ 1 - 1
src/bin/dhcp4/json_config_parser.cc

@@ -585,7 +585,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
             // In principle we could have the following code structured as a series
             // of long if else if clauses. That would give a marginal performance
             // boost, but would make the code less readable. We had serious issues
-            // with the parser code debuggability, so I decided to keep it as a
+            // with the parser code debugability, so I decided to keep it as a
             // series of independent ifs.
 
             if (config_pair.first == "option-def") {

+ 1 - 1
src/bin/dhcp6/json_config_parser.cc

@@ -859,7 +859,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
             // In principle we could have the following code structured as a series
             // of long if else if clauses. That would give a marginal performance
             // boost, but would make the code less readable. We had serious issues
-            // with the parser code debuggability, so I decided to keep it as a
+            // with the parser code debugability, so I decided to keep it as a
             // series of independent ifs.
 
             if (config_pair.first == "option-def") {

+ 8 - 3
src/lib/dhcpsrv/parsers/ifaces_config_parser.cc

@@ -62,7 +62,11 @@ IfacesConfigParser::parse(const CfgIfacePtr& cfg,
                 }
             }
 
-            isc_throw(DhcpConfigError, "usupported parameter '"
+            // This should never happen as the input produced by the parser
+            // see (src/bin/dhcpX/dhcpX_parser.yy) should not produce any
+            // other parameter, so this case is only to catch bugs in
+            // the parser.
+            isc_throw(DhcpConfigError, "unsupported parameter '"
                       << element.first << "'");
         } catch (const std::exception& ex) {
             // Append line number where the error occurred.
@@ -72,8 +76,9 @@ IfacesConfigParser::parse(const CfgIfacePtr& cfg,
     }
 
     // User hasn't specified the socket type. Log that we are using
-    // the default type.
-    if (!socket_type_specified) {
+    // the default type. Log it only if this is DHCPv4. (DHCPv6 does not use
+    // raw sockets).
+    if (!socket_type_specified && (protocol_ == AF_INET) ) {
         LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_SOCKET_TYPE_DEFAULT)
             .arg(cfg->socketTypeToText());
     }

+ 1 - 1
src/lib/dhcpsrv/parsers/ifaces_config_parser.h

@@ -19,7 +19,7 @@ namespace dhcp {
 ///
 /// This parser parses the "interfaces-config" parameter which holds the
 /// full configuration of the DHCP server with respect to the use of
-/// interfaces, sockets and alike.
+/// interfaces, DHCP traffic sockets and alike.
 ///
 /// This parser is used in both DHCPv4 and DHCPv6. Derived parsers
 /// are not needed.