diff options
Diffstat (limited to 'web/attachments/366217-check_dhcp.patch')
| -rw-r--r-- | web/attachments/366217-check_dhcp.patch | 418 | 
1 files changed, 418 insertions, 0 deletions
diff --git a/web/attachments/366217-check_dhcp.patch b/web/attachments/366217-check_dhcp.patch new file mode 100644 index 0000000..f22685a --- /dev/null +++ b/web/attachments/366217-check_dhcp.patch  | |||
| @@ -0,0 +1,418 @@ | |||
| 1 | --- /home/thunderboltFS/mike/usr/local/src/nagios-plugins-1.4.14/plugins-root/check_dhcp.c.old 2010-03-05 11:26:26.000000000 -0600 | ||
| 2 | +++ /home/thunderboltFS/mike/usr/local/src/nagios-plugins-1.4.14/plugins-root/check_dhcp.c 2010-03-10 17:36:02.313724052 -0600 | ||
| 3 | @@ -291,6 +291,9 @@ | ||
| 4 | /* wait for a DHCPOFFER packet */ | ||
| 5 | get_dhcp_offer(dhcp_socket); | ||
| 6 | |||
| 7 | + /* send DHCPREQUEST packet */ | ||
| 8 | + send_dhcp_request(dhcp_socket); | ||
| 9 | + | ||
| 10 | /* close socket we created */ | ||
| 11 | close_dhcp_socket(dhcp_socket); | ||
| 12 | |||
| 13 | @@ -411,7 +414,7 @@ | ||
| 14 | print_hardware_address(client_hardware_address); | ||
| 15 | |||
| 16 | return OK; | ||
| 17 | - } | ||
| 18 | + } | ||
| 19 | |||
| 20 | /* determines IP address of the client interface */ | ||
| 21 | int get_ip_address(int sock,char *interface_name){ | ||
| 22 | @@ -444,7 +447,7 @@ | ||
| 23 | int send_dhcp_discover(int sock){ | ||
| 24 | dhcp_packet discover_packet; | ||
| 25 | struct sockaddr_in sockaddr_broadcast; | ||
| 26 | - unsigned short opts; | ||
| 27 | + unsigned short opts; | ||
| 28 | |||
| 29 | |||
| 30 | /* clear the packet data structure */ | ||
| 31 | @@ -490,7 +493,7 @@ | ||
| 32 | discover_packet.options[2]='\x53'; | ||
| 33 | discover_packet.options[3]='\x63'; | ||
| 34 | |||
| 35 | - opts = 4; | ||
| 36 | + opts = 4; | ||
| 37 | /* DHCP message type is embedded in options field */ | ||
| 38 | discover_packet.options[opts++]=DHCP_OPTION_MESSAGE_TYPE; /* DHCP message type option identifier */ | ||
| 39 | discover_packet.options[opts++]='\x01'; /* DHCP message option length in bytes */ | ||
| 40 | @@ -502,7 +505,7 @@ | ||
| 41 | discover_packet.options[opts++]='\x04'; | ||
| 42 | memcpy(&discover_packet.options[opts],&requested_address,sizeof(requested_address)); | ||
| 43 | opts += sizeof(requested_address); | ||
| 44 | - } | ||
| 45 | + } | ||
| 46 | discover_packet.options[opts++]=DHCP_OPTION_END; | ||
| 47 | |||
| 48 | /* unicast fields */ | ||
| 49 | @@ -513,8 +516,8 @@ | ||
| 50 | discover_packet.hops = unicast ? 1 : 0; | ||
| 51 | |||
| 52 | /* send the DHCPDISCOVER packet to broadcast address */ | ||
| 53 | - sockaddr_broadcast.sin_family=AF_INET; | ||
| 54 | - sockaddr_broadcast.sin_port=htons(DHCP_SERVER_PORT); | ||
| 55 | + sockaddr_broadcast.sin_family=AF_INET; | ||
| 56 | + sockaddr_broadcast.sin_port=htons(DHCP_SERVER_PORT); | ||
| 57 | sockaddr_broadcast.sin_addr.s_addr = unicast ? dhcp_ip.s_addr : INADDR_BROADCAST; | ||
| 58 | bzero(&sockaddr_broadcast.sin_zero,sizeof(sockaddr_broadcast.sin_zero)); | ||
| 59 | |||
| 60 | @@ -522,10 +525,10 @@ | ||
| 61 | if(verbose){ | ||
| 62 | printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port)); | ||
| 63 | printf("DHCPDISCOVER XID: %u (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid)); | ||
| 64 | - printf("DHCDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr)); | ||
| 65 | - printf("DHCDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr)); | ||
| 66 | - printf("DHCDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr)); | ||
| 67 | - printf("DHCDISCOVER giaddr: %s\n",inet_ntoa(discover_packet.giaddr)); | ||
| 68 | + printf("DHCPDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr)); | ||
| 69 | + printf("DHCPDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr)); | ||
| 70 | + printf("DHCPDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr)); | ||
| 71 | + printf("DHCPDISCOVER giaddr: %s\n",inet_ntoa(discover_packet.giaddr)); | ||
| 72 | } | ||
| 73 | |||
| 74 | /* send the DHCPDISCOVER packet out */ | ||
| 75 | @@ -535,9 +538,110 @@ | ||
| 76 | printf("\n\n"); | ||
| 77 | |||
| 78 | return OK; | ||
| 79 | - } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | +/* sends a DHCPREQUEST broadcast message in an attempt to allow DHCP servers to drop any OFFER reservations and return those IPs to their free pools */ | ||
| 83 | +int send_dhcp_request(int sock){ | ||
| 84 | + dhcp_packet discover_packet; | ||
| 85 | + struct sockaddr_in sockaddr_broadcast; | ||
| 86 | + unsigned short opts; | ||
| 87 | + | ||
| 88 | + | ||
| 89 | + /* clear the packet data structure */ | ||
| 90 | + bzero(&discover_packet,sizeof(discover_packet)); | ||
| 91 | + | ||
| 92 | + | ||
| 93 | + /* boot request flag (backward compatible with BOOTP servers) */ | ||
| 94 | + discover_packet.op=BOOTREQUEST; | ||
| 95 | + | ||
| 96 | + /* hardware address type */ | ||
| 97 | + discover_packet.htype=ETHERNET_HARDWARE_ADDRESS; | ||
| 98 | + | ||
| 99 | + /* length of our hardware address */ | ||
| 100 | + discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; | ||
| 101 | + | ||
| 102 | + /* | ||
| 103 | + * transaction ID is supposed to be random. We won't use the address so | ||
| 104 | + * we don't care about high entropy here. time(2) is good enough. | ||
| 105 | + */ | ||
| 106 | + srand(time(NULL)); | ||
| 107 | + packet_xid=random(); | ||
| 108 | + discover_packet.xid=htonl(packet_xid); | ||
| 109 | + | ||
| 110 | + /**** WHAT THE HECK IS UP WITH THIS?!? IF I DON'T MAKE THIS CALL, ONLY ONE SERVER RESPONSE IS PROCESSED!!!! ****/ | ||
| 111 | + /* downright bizzarre... */ | ||
| 112 | + ntohl(discover_packet.xid); | ||
| 113 | + | ||
| 114 | + /*discover_packet.secs=htons(65535);*/ | ||
| 115 | + discover_packet.secs=0xFF; | ||
| 116 | + | ||
| 117 | + /* | ||
| 118 | + * server needs to know if it should broadcast or unicast its response: | ||
| 119 | + * 0x8000L == 32768 == 1 << 15 == broadcast, 0 == unicast | ||
| 120 | + */ | ||
| 121 | + discover_packet.flags = unicast ? 0 : htons(DHCP_BROADCAST_FLAG); | ||
| 122 | + | ||
| 123 | + /* our hardware address */ | ||
| 124 | + memcpy(discover_packet.chaddr,client_hardware_address,ETHERNET_HARDWARE_ADDRESS_LENGTH); | ||
| 125 | + | ||
| 126 | + /* first four bytes of options field is magic cookie (as per RFC 2132) */ | ||
| 127 | + discover_packet.options[0]='\x63'; | ||
| 128 | + discover_packet.options[1]='\x82'; | ||
| 129 | + discover_packet.options[2]='\x53'; | ||
| 130 | + discover_packet.options[3]='\x63'; | ||
| 131 | + | ||
| 132 | + opts = 4; | ||
| 133 | + /* DHCP message type is embedded in options field */ | ||
| 134 | + discover_packet.options[opts++]=DHCP_OPTION_MESSAGE_TYPE; /* DHCP message type option identifier */ | ||
| 135 | + discover_packet.options[opts++]='\x01'; /* DHCP message option length in bytes */ | ||
| 136 | + discover_packet.options[opts++]=DHCPREQUEST; | ||
| 137 | + | ||
| 138 | + /* the IP address we're requesting */ | ||
| 139 | + if(request_specific_address==TRUE){ | ||
| 140 | + discover_packet.options[opts++]=DHCP_OPTION_REQUESTED_ADDRESS; | ||
| 141 | + discover_packet.options[opts++]='\x04'; | ||
| 142 | + memcpy(&discover_packet.options[opts],&requested_address,sizeof(requested_address)); | ||
| 143 | + opts += sizeof(requested_address); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /* Set the server identifier to our own address, so that no other DHCP server will match */ | ||
| 147 | + discover_packet.options[opts++]=DHCP_OPTION_SERVER_IDENTIFIER; | ||
| 148 | + discover_packet.options[opts++]='\x04'; | ||
| 149 | + memcpy(&discover_packet.options[opts],&discover_packet.ciaddr,sizeof(discover_packet.ciaddr)); | ||
| 150 | + | ||
| 151 | + discover_packet.options[opts++]=DHCP_OPTION_END; | ||
| 152 | + | ||
| 153 | + /* unicast fields */ | ||
| 154 | + if(unicast) | ||
| 155 | + discover_packet.giaddr.s_addr = my_ip.s_addr; | ||
| 156 | + | ||
| 157 | + /* see RFC 1542, 4.1.1 */ | ||
| 158 | + discover_packet.hops = unicast ? 1 : 0; | ||
| 159 | + | ||
| 160 | + /* send the DHCPREQUEST packet to broadcast address */ | ||
| 161 | + sockaddr_broadcast.sin_family=AF_INET; | ||
| 162 | + sockaddr_broadcast.sin_port=htons(DHCP_SERVER_PORT); | ||
| 163 | + sockaddr_broadcast.sin_addr.s_addr = unicast ? dhcp_ip.s_addr : INADDR_BROADCAST; | ||
| 164 | + bzero(&sockaddr_broadcast.sin_zero,sizeof(sockaddr_broadcast.sin_zero)); | ||
| 165 | + | ||
| 166 | |||
| 167 | + if(verbose){ | ||
| 168 | + printf(_("DHCPREQUEST to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port)); | ||
| 169 | + printf("DHCPREQUEST XID: %u (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid)); | ||
| 170 | + printf("DHCPREQUEST ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr)); | ||
| 171 | + printf("DHCPREQUEST yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr)); | ||
| 172 | + printf("DHCPREQUEST siaddr: %s\n",inet_ntoa(discover_packet.siaddr)); | ||
| 173 | + printf("DHCPREQUEST giaddr: %s\n",inet_ntoa(discover_packet.giaddr)); | ||
| 174 | + } | ||
| 175 | |||
| 176 | + /* send the DHCPREQUEST packet out */ | ||
| 177 | + send_dhcp_packet(&discover_packet,sizeof(discover_packet),sock,&sockaddr_broadcast); | ||
| 178 | + | ||
| 179 | + if(verbose) | ||
| 180 | + printf("\n\n"); | ||
| 181 | + | ||
| 182 | + return OK; | ||
| 183 | + } | ||
| 184 | |||
| 185 | |||
| 186 | /* waits for a DHCPOFFER message from one or more DHCP servers */ | ||
| 187 | @@ -604,7 +708,7 @@ | ||
| 188 | printf(_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid); | ||
| 189 | |||
| 190 | continue; | ||
| 191 | - } | ||
| 192 | + } | ||
| 193 | |||
| 194 | /* check hardware address */ | ||
| 195 | result=OK; | ||
| 196 | @@ -626,7 +730,7 @@ | ||
| 197 | printf(_("DHCPOFFER hardware address did not match our own - ignoring packet\n")); | ||
| 198 | |||
| 199 | continue; | ||
| 200 | - } | ||
| 201 | + } | ||
| 202 | |||
| 203 | if(verbose){ | ||
| 204 | printf("DHCPOFFER ciaddr: %s\n",inet_ntoa(offer_packet.ciaddr)); | ||
| 205 | @@ -638,7 +742,7 @@ | ||
| 206 | add_dhcp_offer(source.sin_addr,&offer_packet); | ||
| 207 | |||
| 208 | valid_responses++; | ||
| 209 | - } | ||
| 210 | + } | ||
| 211 | |||
| 212 | if(verbose){ | ||
| 213 | printf(_("Total responses seen on the wire: %d\n"),responses); | ||
| 214 | @@ -646,7 +750,7 @@ | ||
| 215 | } | ||
| 216 | |||
| 217 | return OK; | ||
| 218 | - } | ||
| 219 | + } | ||
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | @@ -663,7 +767,7 @@ | ||
| 224 | return ERROR; | ||
| 225 | |||
| 226 | return OK; | ||
| 227 | - } | ||
| 228 | + } | ||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | @@ -713,7 +817,7 @@ | ||
| 233 | printf("errno: (%d) -> %s\n",errno,strerror(errno)); | ||
| 234 | } | ||
| 235 | return ERROR; | ||
| 236 | - } | ||
| 237 | + } | ||
| 238 | else{ | ||
| 239 | if(verbose){ | ||
| 240 | printf(_("receive_dhcp_packet() result: %d\n"),recv_result); | ||
| 241 | @@ -722,11 +826,11 @@ | ||
| 242 | |||
| 243 | memcpy(address,&source_address,sizeof(source_address)); | ||
| 244 | return OK; | ||
| 245 | - } | ||
| 246 | - } | ||
| 247 | + } | ||
| 248 | + } | ||
| 249 | |||
| 250 | return OK; | ||
| 251 | - } | ||
| 252 | + } | ||
| 253 | |||
| 254 | |||
| 255 | /* creates a socket for DHCP communication */ | ||
| 256 | @@ -749,7 +853,7 @@ | ||
| 257 | if(sock<0){ | ||
| 258 | printf(_("Error: Could not create socket!\n")); | ||
| 259 | exit(STATE_UNKNOWN); | ||
| 260 | - } | ||
| 261 | + } | ||
| 262 | |||
| 263 | if(verbose) | ||
| 264 | printf("DHCP socket: %d\n",sock); | ||
| 265 | @@ -759,13 +863,13 @@ | ||
| 266 | if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&flag,sizeof(flag))<0){ | ||
| 267 | printf(_("Error: Could not set reuse address option on DHCP socket!\n")); | ||
| 268 | exit(STATE_UNKNOWN); | ||
| 269 | - } | ||
| 270 | + } | ||
| 271 | |||
| 272 | /* set the broadcast option - we need this to listen to DHCP broadcast messages */ | ||
| 273 | if(!unicast && setsockopt(sock,SOL_SOCKET,SO_BROADCAST,(char *)&flag,sizeof flag)<0){ | ||
| 274 | printf(_("Error: Could not set broadcast option on DHCP socket!\n")); | ||
| 275 | exit(STATE_UNKNOWN); | ||
| 276 | - } | ||
| 277 | + } | ||
| 278 | |||
| 279 | /* bind socket to interface */ | ||
| 280 | #if defined(__linux__) | ||
| 281 | @@ -774,7 +878,7 @@ | ||
| 282 | if(setsockopt(sock,SOL_SOCKET,SO_BINDTODEVICE,(char *)&interface,sizeof(interface))<0){ | ||
| 283 | printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"),network_interface_name); | ||
| 284 | exit(STATE_UNKNOWN); | ||
| 285 | - } | ||
| 286 | + } | ||
| 287 | |||
| 288 | #else | ||
| 289 | strncpy(interface.ifr_name,network_interface_name,IFNAMSIZ-1); | ||
| 290 | @@ -785,10 +889,10 @@ | ||
| 291 | if(bind(sock,(struct sockaddr *)&myname,sizeof(myname))<0){ | ||
| 292 | printf(_("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n"),DHCP_CLIENT_PORT); | ||
| 293 | exit(STATE_UNKNOWN); | ||
| 294 | - } | ||
| 295 | + } | ||
| 296 | |||
| 297 | return sock; | ||
| 298 | - } | ||
| 299 | + } | ||
| 300 | |||
| 301 | |||
| 302 | /* closes DHCP socket */ | ||
| 303 | @@ -820,7 +924,7 @@ | ||
| 304 | printf(_("Requested server address: %s\n"),inet_ntoa(new_server->server_address)); | ||
| 305 | |||
| 306 | return OK; | ||
| 307 | - } | ||
| 308 | + } | ||
| 309 | |||
| 310 | |||
| 311 | |||
| 312 | @@ -924,7 +1028,7 @@ | ||
| 313 | dhcp_offer_list=new_offer; | ||
| 314 | |||
| 315 | return OK; | ||
| 316 | - } | ||
| 317 | + } | ||
| 318 | |||
| 319 | |||
| 320 | /* frees memory allocated to DHCP OFFER list */ | ||
| 321 | @@ -938,7 +1042,7 @@ | ||
| 322 | } | ||
| 323 | |||
| 324 | return OK; | ||
| 325 | - } | ||
| 326 | + } | ||
| 327 | |||
| 328 | |||
| 329 | /* frees memory allocated to requested server list */ | ||
| 330 | @@ -949,10 +1053,10 @@ | ||
| 331 | for(this_server=requested_server_list;this_server!=NULL;this_server=next_server){ | ||
| 332 | next_server=this_server->next; | ||
| 333 | free(this_server); | ||
| 334 | - } | ||
| 335 | + } | ||
| 336 | |||
| 337 | return OK; | ||
| 338 | - } | ||
| 339 | + } | ||
| 340 | |||
| 341 | |||
| 342 | /* gets state and plugin output to return */ | ||
| 343 | @@ -993,11 +1097,11 @@ | ||
| 344 | requested_responses++; | ||
| 345 | temp_server->answered=TRUE; | ||
| 346 | } | ||
| 347 | - } | ||
| 348 | - } | ||
| 349 | - } | ||
| 350 | + } | ||
| 351 | + } | ||
| 352 | + } | ||
| 353 | |||
| 354 | - } | ||
| 355 | + } | ||
| 356 | |||
| 357 | /* else check and see if we got our requested address from any server */ | ||
| 358 | else{ | ||
| 359 | @@ -1011,8 +1115,8 @@ | ||
| 360 | /* see if we got the address we requested */ | ||
| 361 | if(!memcmp(&requested_address,&temp_offer->offered_address,sizeof(requested_address))) | ||
| 362 | received_requested_address=TRUE; | ||
| 363 | - } | ||
| 364 | - } | ||
| 365 | + } | ||
| 366 | + } | ||
| 367 | |||
| 368 | result=STATE_OK; | ||
| 369 | if(valid_responses==0) | ||
| 370 | @@ -1037,7 +1141,7 @@ | ||
| 371 | if(dhcp_offer_list==NULL){ | ||
| 372 | printf(_("No DHCPOFFERs were received.\n")); | ||
| 373 | return result; | ||
| 374 | - } | ||
| 375 | + } | ||
| 376 | |||
| 377 | printf(_("Received %d DHCPOFFER(s)"),valid_responses); | ||
| 378 | |||
| 379 | @@ -1056,7 +1160,7 @@ | ||
| 380 | printf(".\n"); | ||
| 381 | |||
| 382 | return result; | ||
| 383 | - } | ||
| 384 | + } | ||
| 385 | |||
| 386 | |||
| 387 | /* process command-line arguments */ | ||
| 388 | @@ -1076,7 +1180,7 @@ | ||
| 389 | } | ||
| 390 | |||
| 391 | return validate_arguments(); | ||
| 392 | - } | ||
| 393 | + } | ||
| 394 | |||
| 395 | |||
| 396 | |||
| 397 | @@ -1181,17 +1285,17 @@ | ||
| 398 | |||
| 399 | default: | ||
| 400 | break; | ||
| 401 | - } | ||
| 402 | - } | ||
| 403 | + } | ||
| 404 | + } | ||
| 405 | |||
| 406 | return i; | ||
| 407 | - } | ||
| 408 | + } | ||
| 409 | |||
| 410 | |||
| 411 | int validate_arguments(void){ | ||
| 412 | |||
| 413 | return OK; | ||
| 414 | - } | ||
| 415 | + } | ||
| 416 | |||
| 417 | |||
| 418 | #if defined(__sun__) || defined(__solaris__) || defined(__hpux__) | ||
