From: Sebastian Schrader Date: Fri, 19 Oct 2018 14:34:29 +0000 (+0200) Subject: [5184] Parse authoritative flag X-Git-Tag: 259-libyang-adapt-authoritative_base~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09987b3f2d552cb2e5f4048e7b9f9418f2d1f24c;p=thirdparty%2Fkea.git [5184] Parse authoritative flag --- diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll index 2daf7dd60d..e42eadd516 100644 --- a/src/bin/dhcp4/dhcp4_lexer.ll +++ b/src/bin/dhcp4/dhcp4_lexer.ll @@ -1556,6 +1556,17 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} } } +\"authoritative\" { + switch(driver.ctx_) { + case isc::dhcp::Parser4Context::DHCP4: + case isc::dhcp::Parser4Context::SUBNET4: + case isc::dhcp::Parser4Context::SHARED_NETWORK: + return isc::dhcp::Dhcp4Parser::make_AUTHORITATIVE(driver.loc_); + default: + return isc::dhcp::Dhcp4Parser::make_STRING("authoritative", driver.loc_); + } +} + \"next-server\" { switch(driver.ctx_) { case isc::dhcp::Parser4Context::DHCP4: diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index 1ec2c8a823..1a90aeb793 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -67,6 +67,7 @@ using namespace std; ECHO_CLIENT_ID "echo-client-id" MATCH_CLIENT_ID "match-client-id" + AUTHORITATIVE "authoritative" NEXT_SERVER "next-server" SERVER_HOSTNAME "server-hostname" BOOT_FILE_NAME "boot-file-name" @@ -451,6 +452,7 @@ global_param: valid_lifetime | dhcp_ddns | echo_client_id | match_client_id + | authoritative | next_server | server_hostname | boot_file_name @@ -501,6 +503,11 @@ match_client_id: MATCH_CLIENT_ID COLON BOOLEAN { ctx.stack_.back()->set("match-client-id", match); }; +authoritative: AUTHORITATIVE COLON BOOLEAN { + ElementPtr prf(new BoolElement($3, ctx.loc2pos(@3))); + ctx.stack_.back()->set("authoritative", prf); +}; + interfaces_config: INTERFACES_CONFIG { ElementPtr i(new MapElement(ctx.loc2pos(@1))); @@ -1041,6 +1048,7 @@ subnet4_param: valid_lifetime | reservation_mode | relay | match_client_id + | authoritative | next_server | server_hostname | boot_file_name @@ -1169,6 +1177,7 @@ shared_network_param: name | rebind_timer | option_data_list | match_client_id + | authoritative | next_server | server_hostname | boot_file_name diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 2b8ad3cdbf..efa04ffd12 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -515,7 +515,8 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, // decline-probation-period, dhcp4o6-port, echo-client-id, // user-context are handled in global_parser.parse() which // sets global parameters. - // match-client-id is derived to subnet scope level. + // match-client-id and authoritative are derived to subnet scope + // level. if ( (config_pair.first == "renew-timer") || (config_pair.first == "rebind-timer") || (config_pair.first == "valid-lifetime") || @@ -524,6 +525,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, (config_pair.first == "echo-client-id") || (config_pair.first == "user-context") || (config_pair.first == "match-client-id") || + (config_pair.first == "authoritative") || (config_pair.first == "next-server") || (config_pair.first == "server-hostname") || (config_pair.first == "boot-file-name") || diff --git a/src/bin/dhcp4/tests/get_config_unittest.cc b/src/bin/dhcp4/tests/get_config_unittest.cc index c92cee901a..91b50c37d0 100644 --- a/src/bin/dhcp4/tests/get_config_unittest.cc +++ b/src/bin/dhcp4/tests/get_config_unittest.cc @@ -2049,6 +2049,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2125,6 +2126,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2202,6 +2204,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2280,6 +2283,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2306,6 +2310,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 2,\n" " \"match-client-id\": true,\n" @@ -2332,6 +2337,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 3,\n" " \"match-client-id\": true,\n" @@ -2358,6 +2364,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 4,\n" " \"match-client-id\": true,\n" @@ -2436,6 +2443,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1024,\n" " \"match-client-id\": true,\n" @@ -2462,6 +2470,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 100,\n" " \"match-client-id\": true,\n" @@ -2488,6 +2497,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2514,6 +2524,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 34,\n" " \"match-client-id\": true,\n" @@ -2595,6 +2606,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"bar\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2673,6 +2685,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"bar\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2754,6 +2767,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"bootfile.efi\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2832,6 +2846,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2910,6 +2925,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -2988,6 +3004,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -3014,6 +3031,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 2,\n" " \"match-client-id\": false,\n" @@ -3093,6 +3111,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": false,\n" @@ -3119,6 +3138,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 2,\n" " \"match-client-id\": true,\n" @@ -3197,6 +3217,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -3275,6 +3296,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -3305,6 +3327,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 2,\n" " \"match-client-id\": true,\n" @@ -3387,6 +3410,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -3897,6 +3921,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -3975,6 +4000,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4097,6 +4123,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4315,6 +4342,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4402,6 +4430,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4497,6 +4526,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4532,6 +4562,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 2,\n" " \"match-client-id\": true,\n" @@ -4619,6 +4650,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4714,6 +4746,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -4831,6 +4864,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5040,6 +5074,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5133,6 +5168,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5230,6 +5266,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5410,6 +5447,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5488,6 +5526,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5566,6 +5605,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5644,6 +5684,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"client-class\": \"alpha\",\n" " \"id\": 1,\n" @@ -5803,6 +5844,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -5896,6 +5938,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 123,\n" " \"match-client-id\": true,\n" @@ -5922,6 +5965,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 234,\n" " \"match-client-id\": true,\n" @@ -6003,6 +6047,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 542,\n" " \"match-client-id\": true,\n" @@ -6139,6 +6184,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 234,\n" " \"match-client-id\": true,\n" @@ -6237,6 +6283,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -6263,6 +6310,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 2,\n" " \"match-client-id\": true,\n" @@ -6289,6 +6337,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 3,\n" " \"match-client-id\": true,\n" @@ -6315,6 +6364,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 4,\n" " \"match-client-id\": true,\n" @@ -6585,6 +6635,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -6663,6 +6714,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"2001:db8::123/45\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -6741,6 +6793,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"ethX\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -6819,6 +6872,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"ethX\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"2001:db8::543/21\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -6897,6 +6951,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"vlan123\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -7001,6 +7056,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -7079,6 +7135,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -7157,6 +7214,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -7236,6 +7294,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -7319,6 +7378,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" @@ -7523,6 +7583,7 @@ const char* UNPARSED_CONFIGS[] = { " \"shared-networks\": [\n" " {\n" " \"comment\": \"A shared network\",\n" +" \"authoritative\": false,\n" " \"match-client-id\": true,\n" " \"name\": \"foo\",\n" " \"option-data\": [ ],\n" @@ -7536,6 +7597,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 100,\n" " \"match-client-id\": true,\n" @@ -7691,6 +7753,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 123,\n" " \"match-client-id\": true,\n" @@ -7717,6 +7780,7 @@ const char* UNPARSED_CONFIGS[] = { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" +" \"authoritative\": false,\n" " \"boot-file-name\": \"\",\n" " \"id\": 542,\n" " \"match-client-id\": true,\n" diff --git a/src/lib/dhcpsrv/cfgmgr.h b/src/lib/dhcpsrv/cfgmgr.h index d03988ac56..1d01fc690b 100644 --- a/src/lib/dhcpsrv/cfgmgr.h +++ b/src/lib/dhcpsrv/cfgmgr.h @@ -92,6 +92,19 @@ public: /// @param datadir New data directory. void setDataDir(const std::string& datadir); + /// @brief Sets whether server should NAK unknown clients in DHCPv4 + /// + /// @param echo should unknown clients be rejected or not + void authoritative(const bool enabled) { + authoritative_ = enabled; + } + + /// @brief Returns whether server should NAK requests for unknown leases + /// @return true if requests for unknown leases should be NAKed, false otherwise + bool authoritative() const { + return (authoritative_); + } + /// @brief Updates the DHCP-DDNS client configuration to the given value. /// /// Passes the new configuration to the D2ClientMgr instance, @@ -270,6 +283,9 @@ private: /// @brief directory where data files (e.g. server-id) are stored std::string datadir_; + /// Indicates whether v4 server should NAK requests for unknown addresses + bool authoritative_; + /// @brief Manages the DHCP-DDNS client and its configuration. D2ClientMgr d2_client_mgr_; diff --git a/src/lib/dhcpsrv/network.cc b/src/lib/dhcpsrv/network.cc index 376e2568d8..f07725be66 100644 --- a/src/lib/dhcpsrv/network.cc +++ b/src/lib/dhcpsrv/network.cc @@ -195,6 +195,9 @@ Network4::toElement() const { // Set match-client-id map->set("match-client-id", Element::create(getMatchClientId())); + // Set authoritative + map->set("authoritative", Element::create(getAuthoritative())); + return (map); } diff --git a/src/lib/dhcpsrv/network.h b/src/lib/dhcpsrv/network.h index 4f1d0fa736..3ce6cac481 100644 --- a/src/lib/dhcpsrv/network.h +++ b/src/lib/dhcpsrv/network.h @@ -368,7 +368,7 @@ public: /// @brief Constructor. Network4() - : Network(), match_client_id_(true) { + : Network(), match_client_id_(true), authoritative_(false) { } /// @brief Returns the flag indicating if the client identifiers should @@ -388,6 +388,24 @@ public: match_client_id_ = match; } + /// @brief Returns the flag indicating if requests for unknown IP addresses + /// should be rejected with DHCPNAK instead of ignored. + /// + /// @return true if requests for unknown IP addresses should be rejected, + /// false otherwise. + bool getAuthoritative() const { + return (authoritative_); + } + + /// @brief Sets the flag indicating if requests for unknown IP addresses + /// should be rejected with DHCPNAK instead of ignored. + /// + /// @param match If this value is true, the requests for unknown IP + /// addresses will be rejected with DHCPNAK messages + void setAuthoritative(const bool authoritative) { + authoritative_ = authoritative; + } + /// @brief Unparses network object. /// /// @return A pointer to unparsed network configuration. @@ -404,6 +422,9 @@ private: /// @brief Should server use client identifiers for client lease /// lookup. bool match_client_id_; + + /// @brief Should requests for unknown IP addresses be rejected. + bool authoritative_; }; /// @brief Specialization of the @ref Network object for DHCPv6 case. diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index c763c98339..0b124fc7ee 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -712,6 +712,12 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params, bool match_client_id = getBoolean(params, "match-client-id"); subnet4->setMatchClientId(match_client_id); + // Set the authoritative value for the subnet. It is always present. + // If not explicitly specified, the default value was filled in when + // SimpleParser4::setAllDefaults was called. + bool authoritative = getBoolean(params, "authoritative"); + subnet4->setAuthoritative(authoritative); + // Set next-server. The default value is 0.0.0.0. Nevertheless, the // user could have messed that up by specifying incorrect value. // To avoid using 0.0.0.0, user can specify "". diff --git a/src/lib/dhcpsrv/parsers/shared_network_parser.cc b/src/lib/dhcpsrv/parsers/shared_network_parser.cc index 2e77490f9a..640e341eea 100644 --- a/src/lib/dhcpsrv/parsers/shared_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/shared_network_parser.cc @@ -65,6 +65,11 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) { "match-client-id")); } + if (shared_network_data->contains("authoritative")) { + shared_network->setAuthoritative(getBoolean(shared_network_data, + "authoritative")); + } + if (shared_network_data->contains("client-class")) { std::string client_class = getString(shared_network_data, "client-class"); if (!client_class.empty()) { diff --git a/src/lib/dhcpsrv/parsers/simple_parser4.cc b/src/lib/dhcpsrv/parsers/simple_parser4.cc index 78895feff8..b6a356397a 100644 --- a/src/lib/dhcpsrv/parsers/simple_parser4.cc +++ b/src/lib/dhcpsrv/parsers/simple_parser4.cc @@ -63,6 +63,7 @@ const SimpleDefaults SimpleParser4::GLOBAL4_DEFAULTS = { { "dhcp4o6-port", Element::integer, "0" }, { "echo-client-id", Element::boolean, "true" }, { "match-client-id", Element::boolean, "true" }, + { "authoritative", Element::boolean, "false" }, { "next-server", Element::string, "0.0.0.0" }, { "server-hostname", Element::string, "" }, { "boot-file-name", Element::string, "" }, @@ -125,6 +126,7 @@ const ParamsList SimpleParser4::INHERIT_TO_SUBNET4 = { "client-class", "interface", "match-client-id", + "authoritative", "next-server", "rebind-timer", "relay", diff --git a/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc index eb72937a42..13deb658c2 100644 --- a/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc @@ -125,6 +125,7 @@ TEST(CfgSharedNetworks4Test, unparse) { std::string expected = "[\n" " {\n" + " \"authoritative\": false,\n" " \"interface\": \"eth1\",\n" " \"match-client-id\": true,\n" " \"name\": \"dog\",\n" @@ -137,6 +138,7 @@ TEST(CfgSharedNetworks4Test, unparse) { " \"valid-lifetime\": 300\n" " },\n" " {\n" + " \"authoritative\": false,\n" " \"interface\": \"eth0\",\n" " \"match-client-id\": true,\n" " \"name\": \"frog\",\n" diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index c02b4f5247..f622d441d5 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -769,6 +769,7 @@ TEST(CfgSubnets4Test, unparseSubnet) { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" + " \"authoritative\": false,\n" " \"reservation-mode\": \"all\",\n" " \"option-data\": [ ],\n" " \"pools\": [ ]\n" @@ -787,6 +788,7 @@ TEST(CfgSubnets4Test, unparseSubnet) { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" + " \"authoritative\": false,\n" " \"reservation-mode\": \"all\",\n" " \"user-context\": {},\n" " \"option-data\": [ ],\n" @@ -806,6 +808,7 @@ TEST(CfgSubnets4Test, unparseSubnet) { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" + " \"authoritative\": false,\n" " \"reservation-mode\": \"all\",\n" " \"option-data\": [ ],\n" " \"pools\": [ ]\n," @@ -851,6 +854,7 @@ TEST(CfgSubnets4Test, unparsePool) { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" + " \"authoritative\": false,\n" " \"reservation-mode\": \"all\",\n" " \"option-data\": [],\n" " \"pools\": [\n" diff --git a/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc b/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc index 4842fbd37d..c7578ed937 100644 --- a/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc @@ -131,6 +131,7 @@ public: " \"rebind-timer\": 200," " \"valid-lifetime\": 300," " \"match-client-id\": false," + " \"authoritative\": false," " \"next-server\": \"\"," " \"server-hostname\": \"\"," " \"boot-file-name\": \"\"," @@ -152,6 +153,7 @@ public: " \"rebind-timer\": 20," " \"valid-lifetime\": 30," " \"match-client-id\": false," + " \"authoritative\": false," " \"next-server\": \"\"," " \"server-hostname\": \"\"," " \"boot-file-name\": \"\"," diff --git a/src/lib/dhcpsrv/tests/shared_network_unittest.cc b/src/lib/dhcpsrv/tests/shared_network_unittest.cc index 77159241a6..cbbc01e51c 100644 --- a/src/lib/dhcpsrv/tests/shared_network_unittest.cc +++ b/src/lib/dhcpsrv/tests/shared_network_unittest.cc @@ -316,6 +316,7 @@ TEST(SharedNetwork4Test, unparse) { std::string expected = "{\n" " \"comment\": \"bar\",\n" + " \"authoritative\": false,\n" " \"interface\": \"eth1\",\n" " \"match-client-id\": false,\n" " \"name\": \"frog\",\n" @@ -332,6 +333,7 @@ TEST(SharedNetwork4Test, unparse) { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" + " \"authoritative\": false,\n" " \"id\": 1,\n" " \"match-client-id\": true,\n" " \"next-server\": \"0.0.0.0\",\n" @@ -352,6 +354,7 @@ TEST(SharedNetwork4Test, unparse) { " \"4o6-interface\": \"\",\n" " \"4o6-interface-id\": \"\",\n" " \"4o6-subnet\": \"\",\n" + " \"authoritative\": false,\n" " \"id\": 2,\n" " \"match-client-id\": true,\n" " \"next-server\": \"0.0.0.0\",\n"