summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-13 19:19:09 +0200
committerGitHub <noreply@github.com>2023-10-13 19:19:09 +0200
commit60bdbe5f9ef2c853e4ae214ce61bedc0d880bd2e (patch)
tree8a4f5e2f2f28976f80ba9b5e68dd19ba917e35f4
parentbf70f5f847e3407af572d1768cca747af270b993 (diff)
parentb6d3acf5e3f685d6048905d4bef84ebfbb9f4815 (diff)
downloadmonitoring-plugins-60bdbe5.tar.gz
Merge pull request #1906 from monitoring-plugins/check_dhcp_rogue_detection
check_dhcp: merged patch from #752
-rw-r--r--plugins-root/check_dhcp.c43
-rw-r--r--po/de.po15
-rw-r--r--po/fr.po6
-rw-r--r--po/monitoring-plugins.pot15
4 files changed, 62 insertions, 17 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index 0ddace5b..5ba9372e 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -150,6 +150,7 @@ typedef struct dhcp_offer_struct{
150 uint32_t lease_time; /* lease time in seconds */ 150 uint32_t lease_time; /* lease time in seconds */
151 uint32_t renewal_time; /* renewal time in seconds */ 151 uint32_t renewal_time; /* renewal time in seconds */
152 uint32_t rebinding_time; /* rebinding time in seconds */ 152 uint32_t rebinding_time; /* rebinding time in seconds */
153 bool desired; /* is this offer desired (necessary in exclusive mode) */
153 struct dhcp_offer_struct *next; 154 struct dhcp_offer_struct *next;
154}dhcp_offer; 155}dhcp_offer;
155 156
@@ -192,7 +193,8 @@ typedef struct requested_server_struct{
192#define ETHERNET_HARDWARE_ADDRESS 1 /* used in htype field of dhcp packet */ 193#define ETHERNET_HARDWARE_ADDRESS 1 /* used in htype field of dhcp packet */
193#define ETHERNET_HARDWARE_ADDRESS_LENGTH 6 /* length of Ethernet hardware addresses */ 194#define ETHERNET_HARDWARE_ADDRESS_LENGTH 6 /* length of Ethernet hardware addresses */
194 195
195uint8_t unicast = 0; /* unicast mode: mimic a DHCP relay */ 196bool unicast = false; /* unicast mode: mimic a DHCP relay */
197bool exclusive = false; /* exclusive mode aka "rogue DHCP server detection" */
196struct in_addr my_ip; /* our address (required for relay) */ 198struct in_addr my_ip; /* our address (required for relay) */
197struct in_addr dhcp_ip; /* server to query (if in unicast mode) */ 199struct in_addr dhcp_ip; /* server to query (if in unicast mode) */
198unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH]=""; 200unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH]="";
@@ -894,6 +896,7 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
894 new_offer->lease_time=dhcp_lease_time; 896 new_offer->lease_time=dhcp_lease_time;
895 new_offer->renewal_time=dhcp_renewal_time; 897 new_offer->renewal_time=dhcp_renewal_time;
896 new_offer->rebinding_time=dhcp_rebinding_time; 898 new_offer->rebinding_time=dhcp_rebinding_time;
899 new_offer->desired=false; /* exclusive mode: we'll check that in get_results */
897 900
898 901
899 if(verbose){ 902 if(verbose){
@@ -939,7 +942,7 @@ int free_requested_server_list(void){
939 942
940/* gets state and plugin output to return */ 943/* gets state and plugin output to return */
941int get_results(void){ 944int get_results(void){
942 dhcp_offer *temp_offer; 945 dhcp_offer *temp_offer, *undesired_offer=NULL;
943 requested_server *temp_server; 946 requested_server *temp_server;
944 int result; 947 int result;
945 uint32_t max_lease_time=0; 948 uint32_t max_lease_time=0;
@@ -974,11 +977,19 @@ int get_results(void){
974 if(!temp_server->answered){ 977 if(!temp_server->answered){
975 requested_responses++; 978 requested_responses++;
976 temp_server->answered=true; 979 temp_server->answered=true;
980 temp_offer->desired=true;
977 } 981 }
978 } 982 }
979 } 983 }
980 } 984 }
981 985
986 /* exclusive mode: check for undesired offers */
987 for(temp_offer=dhcp_offer_list;temp_offer!=NULL;temp_offer=temp_offer->next) {
988 if (!temp_offer->desired) {
989 undesired_offer=temp_offer; /* Checks only for the first undesired offer */
990 break; /* no further checks needed */
991 }
992 }
982 } 993 }
983 994
984 /* else check and see if we got our requested address from any server */ 995 /* else check and see if we got our requested address from any server */
@@ -1006,6 +1017,9 @@ int get_results(void){
1006 else if(request_specific_address && !received_requested_address) 1017 else if(request_specific_address && !received_requested_address)
1007 result=STATE_WARNING; 1018 result=STATE_WARNING;
1008 1019
1020 if(exclusive && undesired_offer)
1021 result=STATE_CRITICAL;
1022
1009 if(result==0) /* garrett honeycutt 2005 */ 1023 if(result==0) /* garrett honeycutt 2005 */
1010 printf("OK: "); 1024 printf("OK: ");
1011 else if(result==1) 1025 else if(result==1)
@@ -1023,6 +1037,13 @@ int get_results(void){
1023 1037
1024 printf(_("Received %d DHCPOFFER(s)"),valid_responses); 1038 printf(_("Received %d DHCPOFFER(s)"),valid_responses);
1025 1039
1040
1041 if(exclusive && undesired_offer){
1042 printf(_(", Rogue DHCP Server detected! Server %s"),inet_ntoa(undesired_offer->server_address));
1043 printf(_(" offered %s \n"),inet_ntoa(undesired_offer->offered_address));
1044 return result;
1045 }
1046
1026 if(requested_servers>0) 1047 if(requested_servers>0)
1027 printf(_(", %s%d of %d requested servers responded"),((requested_responses<requested_servers) && requested_responses>0)?"only ":"",requested_responses,requested_servers); 1048 printf(_(", %s%d of %d requested servers responded"),((requested_responses<requested_servers) && requested_responses>0)?"only ":"",requested_responses,requested_servers);
1028 1049
@@ -1065,16 +1086,16 @@ int call_getopt(int argc, char **argv){
1065 {"interface", required_argument,0,'i'}, 1086 {"interface", required_argument,0,'i'},
1066 {"mac", required_argument,0,'m'}, 1087 {"mac", required_argument,0,'m'},
1067 {"unicast", no_argument, 0,'u'}, 1088 {"unicast", no_argument, 0,'u'},
1089 {"exclusive", no_argument, 0,'x'},
1068 {"verbose", no_argument, 0,'v'}, 1090 {"verbose", no_argument, 0,'v'},
1069 {"version", no_argument, 0,'V'}, 1091 {"version", no_argument, 0,'V'},
1070 {"help", no_argument, 0,'h'}, 1092 {"help", no_argument, 0,'h'},
1071 {0,0,0,0} 1093 {0,0,0,0}
1072 }; 1094 };
1073 1095
1074 while(1){ 1096 int c=0;
1075 int c=0; 1097 while(true){
1076 1098 c=getopt_long(argc,argv,"+hVvxt:s:r:t:i:m:u",long_options,&option_index);
1077 c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index);
1078 1099
1079 if(c==-1||c==EOF||c==1) 1100 if(c==-1||c==EOF||c==1)
1080 break; 1101 break;
@@ -1121,7 +1142,10 @@ int call_getopt(int argc, char **argv){
1121 break; 1142 break;
1122 1143
1123 case 'u': /* unicast testing */ 1144 case 'u': /* unicast testing */
1124 unicast=1; 1145 unicast=true;
1146 break;
1147 case 'x': /* exclusive testing aka "rogue DHCP server detection" */
1148 exclusive=true;
1125 break; 1149 break;
1126 1150
1127 case 'V': /* version */ 1151 case 'V': /* version */
@@ -1135,7 +1159,6 @@ int call_getopt(int argc, char **argv){
1135 case 'v': /* verbose */ 1159 case 'v': /* verbose */
1136 verbose=1; 1160 verbose=1;
1137 break; 1161 break;
1138
1139 case '?': /* help */ 1162 case '?': /* help */
1140 usage5 (); 1163 usage5 ();
1141 break; 1164 break;
@@ -1372,6 +1395,8 @@ void print_help(void){
1372 printf (" %s\n", _("MAC address to use in the DHCP request")); 1395 printf (" %s\n", _("MAC address to use in the DHCP request"));
1373 printf (" %s\n", "-u, --unicast"); 1396 printf (" %s\n", "-u, --unicast");
1374 printf (" %s\n", _("Unicast testing: mimic a DHCP relay, requires -s")); 1397 printf (" %s\n", _("Unicast testing: mimic a DHCP relay, requires -s"));
1398 printf (" %s\n", "-x, --exclusive");
1399 printf (" %s\n", _("Only requested DHCP server may response (rogue DHCP server detection), requires -s"));
1375 1400
1376 printf (UT_SUPPORT); 1401 printf (UT_SUPPORT);
1377 return; 1402 return;
@@ -1382,7 +1407,7 @@ void
1382print_usage(void){ 1407print_usage(void){
1383 1408
1384 printf ("%s\n", _("Usage:")); 1409 printf ("%s\n", _("Usage:"));
1385 printf (" %s [-v] [-u] [-s serverip] [-r requestedip] [-t timeout]\n",progname); 1410 printf (" %s [-v] [-u] [-x] [-s serverip] [-r requestedip] [-t timeout]\n",progname);
1386 printf (" [-i interface] [-m mac]\n"); 1411 printf (" [-i interface] [-m mac]\n");
1387 1412
1388 return; 1413 return;
diff --git a/po/de.po b/po/de.po
index 6d79f9d1..1b666f4c 100644
--- a/po/de.po
+++ b/po/de.po
@@ -9,7 +9,7 @@ msgid ""
9msgstr "" 9msgstr ""
10"Project-Id-Version: PACKAGE VERSION\n" 10"Project-Id-Version: PACKAGE VERSION\n"
11"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n" 11"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
12"POT-Creation-Date: 2023-10-01 00:46+0200\n" 12"POT-Creation-Date: 2023-10-01 15:10+0200\n"
13"PO-Revision-Date: 2004-12-23 17:46+0100\n" 13"PO-Revision-Date: 2004-12-23 17:46+0100\n"
14"Last-Translator: \n" 14"Last-Translator: \n"
15"Language-Team: Monitoring Plugin Development Team <devel@monitoring-plugins." 15"Language-Team: Monitoring Plugin Development Team <devel@monitoring-plugins."
@@ -4989,6 +4989,14 @@ msgid "Received %d DHCPOFFER(s)"
4989msgstr "" 4989msgstr ""
4990 4990
4991#, c-format 4991#, c-format
4992msgid ", Rogue DHCP Server detected! Server %s"
4993msgstr ""
4994
4995#, c-format
4996msgid " offered %s \n"
4997msgstr ""
4998
4999#, c-format
4992msgid ", %s%d of %d requested servers responded" 5000msgid ", %s%d of %d requested servers responded"
4993msgstr "" 5001msgstr ""
4994 5002
@@ -5056,6 +5064,11 @@ msgstr ""
5056msgid "Unicast testing: mimic a DHCP relay, requires -s" 5064msgid "Unicast testing: mimic a DHCP relay, requires -s"
5057msgstr "" 5065msgstr ""
5058 5066
5067msgid ""
5068"Only requested DHCP server may response (rogue DHCP server detection), "
5069"requires -s"
5070msgstr ""
5071
5059msgid "specify a target" 5072msgid "specify a target"
5060msgstr "" 5073msgstr ""
5061 5074
diff --git a/po/fr.po b/po/fr.po
index c59042dd..a85945ae 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -5210,9 +5210,6 @@ msgstr ", %s%d de %d serveurs ont répondus"
5210msgid ", requested address (%s) was %soffered" 5210msgid ", requested address (%s) was %soffered"
5211msgstr ", l'adresse demandée (%s) %s été offerte" 5211msgstr ", l'adresse demandée (%s) %s été offerte"
5212 5212
5213msgid "not "
5214msgstr "n'as pas"
5215
5216#, c-format 5213#, c-format
5217msgid ", max lease time = " 5214msgid ", max lease time = "
5218msgstr ", bail maximum = " 5215msgstr ", bail maximum = "
@@ -5221,9 +5218,6 @@ msgstr ", bail maximum = "
5221msgid "Infinity" 5218msgid "Infinity"
5222msgstr "Infini" 5219msgstr "Infini"
5223 5220
5224msgid "Got unexpected non-option argument"
5225msgstr ""
5226
5227#, c-format 5221#, c-format
5228msgid "Error: DLPI stream API failed to get MAC in check_ctrl: %s.\n" 5222msgid "Error: DLPI stream API failed to get MAC in check_ctrl: %s.\n"
5229msgstr "" 5223msgstr ""
diff --git a/po/monitoring-plugins.pot b/po/monitoring-plugins.pot
index 90424b73..6b63fd97 100644
--- a/po/monitoring-plugins.pot
+++ b/po/monitoring-plugins.pot
@@ -8,7 +8,7 @@ msgid ""
8msgstr "" 8msgstr ""
9"Project-Id-Version: PACKAGE VERSION\n" 9"Project-Id-Version: PACKAGE VERSION\n"
10"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n" 10"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
11"POT-Creation-Date: 2023-10-01 00:46+0200\n" 11"POT-Creation-Date: 2023-10-01 15:10+0200\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n" 14"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -4816,6 +4816,14 @@ msgid "Received %d DHCPOFFER(s)"
4816msgstr "" 4816msgstr ""
4817 4817
4818#, c-format 4818#, c-format
4819msgid ", Rogue DHCP Server detected! Server %s"
4820msgstr ""
4821
4822#, c-format
4823msgid " offered %s \n"
4824msgstr ""
4825
4826#, c-format
4819msgid ", %s%d of %d requested servers responded" 4827msgid ", %s%d of %d requested servers responded"
4820msgstr "" 4828msgstr ""
4821 4829
@@ -4883,6 +4891,11 @@ msgstr ""
4883msgid "Unicast testing: mimic a DHCP relay, requires -s" 4891msgid "Unicast testing: mimic a DHCP relay, requires -s"
4884msgstr "" 4892msgstr ""
4885 4893
4894msgid ""
4895"Only requested DHCP server may response (rogue DHCP server detection), "
4896"requires -s"
4897msgstr ""
4898
4886msgid "specify a target" 4899msgid "specify a target"
4887msgstr "" 4900msgstr ""
4888 4901