summaryrefslogtreecommitdiffstats
path: root/plugins-root/check_dhcp.c
diff options
context:
space:
mode:
authorHolger Weiss <hweiss@users.sourceforge.net>2007-04-20 17:25:40 +0000
committerHolger Weiss <hweiss@users.sourceforge.net>2007-04-20 17:25:40 +0000
commit9b2a0c3d29395059ac380cffd3454535b1692a50 (patch)
treea79823eec1131b741d6cf075d257327ba579551d /plugins-root/check_dhcp.c
parentcc4f750432b7f7622379c150a42362366684c929 (diff)
downloadmonitoring-plugins-9b2a0c3d29395059ac380cffd3454535b1692a50.tar.gz
Use the 'server identifier' option instead of the 'siaddr' field as the
DHCP server address; see RFC 2131, 2. (Denis Knauf - 1667488) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1694 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-root/check_dhcp.c')
-rw-r--r--plugins-root/check_dhcp.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index 245946b5..993531cd 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -182,6 +182,7 @@ typedef struct requested_server_struct{
182#define DHCP_OPTION_BROADCAST_ADDRESS 28 182#define DHCP_OPTION_BROADCAST_ADDRESS 28
183#define DHCP_OPTION_REQUESTED_ADDRESS 50 183#define DHCP_OPTION_REQUESTED_ADDRESS 50
184#define DHCP_OPTION_LEASE_TIME 51 184#define DHCP_OPTION_LEASE_TIME 51
185#define DHCP_OPTION_SERVER_IDENTIFIER 54
185#define DHCP_OPTION_RENEWAL_TIME 58 186#define DHCP_OPTION_RENEWAL_TIME 58
186#define DHCP_OPTION_REBINDING_TIME 59 187#define DHCP_OPTION_REBINDING_TIME 59
187 188
@@ -765,9 +766,9 @@ int add_requested_server(struct in_addr server_address){
765int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){ 766int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
766 dhcp_offer *new_offer; 767 dhcp_offer *new_offer;
767 int x; 768 int x;
768 int y;
769 unsigned option_type; 769 unsigned option_type;
770 unsigned option_length; 770 unsigned option_length;
771 struct in_addr serv_ident = {0};
771 772
772 if(offer_packet==NULL) 773 if(offer_packet==NULL)
773 return ERROR; 774 return ERROR;
@@ -789,23 +790,28 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
789 printf("Option: %d (0x%02X)\n",option_type,option_length); 790 printf("Option: %d (0x%02X)\n",option_type,option_length);
790 791
791 /* get option data */ 792 /* get option data */
792 if(option_type==DHCP_OPTION_LEASE_TIME){ 793 switch(option_type){
794 case DHCP_OPTION_LEASE_TIME:
793 memcpy(&dhcp_lease_time, &offer_packet->options[x],sizeof(dhcp_lease_time)); 795 memcpy(&dhcp_lease_time, &offer_packet->options[x],sizeof(dhcp_lease_time));
794 dhcp_lease_time = ntohl(dhcp_lease_time); 796 dhcp_lease_time = ntohl(dhcp_lease_time);
795 } 797 break;
796 if(option_type==DHCP_OPTION_RENEWAL_TIME){ 798 case DHCP_OPTION_RENEWAL_TIME:
797 memcpy(&dhcp_renewal_time, &offer_packet->options[x],sizeof(dhcp_renewal_time)); 799 memcpy(&dhcp_renewal_time, &offer_packet->options[x],sizeof(dhcp_renewal_time));
798 dhcp_renewal_time = ntohl(dhcp_renewal_time); 800 dhcp_renewal_time = ntohl(dhcp_renewal_time);
799 } 801 break;
800 if(option_type==DHCP_OPTION_REBINDING_TIME){ 802 case DHCP_OPTION_REBINDING_TIME:
801 memcpy(&dhcp_rebinding_time, &offer_packet->options[x],sizeof(dhcp_rebinding_time)); 803 memcpy(&dhcp_rebinding_time, &offer_packet->options[x],sizeof(dhcp_rebinding_time));
802 dhcp_rebinding_time = ntohl(dhcp_rebinding_time); 804 dhcp_rebinding_time = ntohl(dhcp_rebinding_time);
805 break;
806 case DHCP_OPTION_SERVER_IDENTIFIER:
807 memcpy(&serv_ident.s_addr, &offer_packet->options[x],sizeof(serv_ident.s_addr));
808 break;
803 } 809 }
804 810
805 /* skip option data we're ignoring */ 811 /* skip option data we're ignoring */
806 else 812 if(option_type!=DHCP_OPTION_REBINDING_TIME)
807 for(y=0;y<option_length;y++,x++); 813 x+=option_length;
808 } 814 }
809 815
810 if(verbose){ 816 if(verbose){
811 if(dhcp_lease_time==DHCP_INFINITE_TIME) 817 if(dhcp_lease_time==DHCP_INFINITE_TIME)
@@ -826,7 +832,19 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
826 if(new_offer==NULL) 832 if(new_offer==NULL)
827 return ERROR; 833 return ERROR;
828 834
829 new_offer->server_address=source; 835 /*
836 * RFC 2131 (2.) says: "DHCP clarifies the interpretation of the
837 * 'siaddr' field as the address of the server to use in the next step
838 * of the client's bootstrap process. A DHCP server may return its own
839 * address in the 'siaddr' field, if the server is prepared to supply
840 * the next bootstrap service (e.g., delivery of an operating system
841 * executable image). A DHCP server always returns its own address in
842 * the 'server identifier' option." 'serv_ident' is the 'server
843 * identifier' option, 'source' is the 'siaddr' field or (if 'siaddr'
844 * wasn't available) the IP address we received the DHCPOFFER from. If
845 * 'serv_ident' isn't available for some reason, we use 'source'.
846 */
847 new_offer->server_address=serv_ident.s_addr?serv_ident:source;
830 new_offer->offered_address=offer_packet->yiaddr; 848 new_offer->offered_address=offer_packet->yiaddr;
831 new_offer->lease_time=dhcp_lease_time; 849 new_offer->lease_time=dhcp_lease_time;
832 new_offer->renewal_time=dhcp_renewal_time; 850 new_offer->renewal_time=dhcp_renewal_time;