changeset 13001:1e6b26d10a55

6950768 dhcpagent may incorrectly abandon a deleted interface
author Vasumathi Sundaram <Vasumathi.Sundaram@oracle.COM>
date Mon, 02 Aug 2010 16:06:35 -0400
parents 28d31e0a7784
children f246a5b54a71
files usr/src/cmd/cmd-inet/sbin/dhcpagent/agent.c usr/src/cmd/cmd-inet/sbin/dhcpagent/bound.c usr/src/cmd/cmd-inet/sbin/dhcpagent/release.c usr/src/cmd/cmd-inet/sbin/dhcpagent/renew.c usr/src/cmd/cmd-inet/sbin/dhcpagent/select.c usr/src/cmd/cmd-inet/sbin/dhcpagent/states.c usr/src/cmd/cmd-inet/sbin/dhcpagent/util.c usr/src/cmd/cmd-inet/sbin/dhcpagent/util.h
diffstat 8 files changed, 48 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/agent.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/agent.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 #include <sys/types.h>
@@ -1446,9 +1445,7 @@
 
 		if ((isv6 && !check_main_lif(dsmp, &msg.ifam, msglen)) ||
 		    (!isv6 && !verify_lif(dsmp->dsm_lif))) {
-			dsmp->dsm_droprelease = B_TRUE;
-			(void) script_start(dsmp, isv6 ? EVENT_DROP6 :
-			    EVENT_DROP, dhcp_drop, NULL, NULL);
+			finished_smach(dsmp, DHCP_IPC_E_INVIF);
 			continue;
 		}
 
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/bound.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/bound.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  *
  * BOUND state of the DHCP client state machine.
  */
@@ -152,6 +151,7 @@
 		}
 
 		dsmp->dsm_curstart_monosec = dsmp->dsm_newstart_monosec;
+		write_lease_to_hostconf(dsmp);
 		break;
 
 	case SELECTING:
@@ -275,6 +275,7 @@
 		    EVENT_EXTEND, bound_event_cb, NULL, NULL);
 
 		dsmp->dsm_curstart_monosec = dsmp->dsm_newstart_monosec;
+		write_lease_to_hostconf(dsmp);
 
 		/* Stop sending requests now */
 		stop_pkt_retransmission(dsmp);
@@ -302,13 +303,6 @@
 		return (B_FALSE);
 	}
 
-	/*
-	 * remove any stale hostconf file that might be lying around for
-	 * this state machine. (in general, it's harmless, since we'll write a
-	 * fresh one when we exit anyway, but just to reduce confusion..)
-	 */
-
-	(void) remove_hostconf(dsmp->dsm_name, dsmp->dsm_isv6);
 	return (B_TRUE);
 }
 
@@ -340,6 +334,7 @@
 		(void) script_start(dsmp, EVENT_BOUND6, bound_event_cb, NULL,
 		    NULL);
 		dsmp->dsm_curstart_monosec = dsmp->dsm_newstart_monosec;
+		write_lease_to_hostconf(dsmp);
 		return;
 	}
 
@@ -419,6 +414,7 @@
 	}
 
 	dsmp->dsm_curstart_monosec = dsmp->dsm_newstart_monosec;
+	write_lease_to_hostconf(dsmp);
 }
 
 /*
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/release.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/release.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,14 +19,11 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  *
  * DECLINE/RELEASE configuration functionality for the DHCP client.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <unistd.h>
 #include <string.h>
@@ -156,6 +153,8 @@
 	    dsmp->dsm_name);
 	(void) set_smach_state(dsmp, RELEASING);
 
+	(void) remove_hostconf(dsmp->dsm_name, dsmp->dsm_isv6);
+
 	if (dsmp->dsm_isv6) {
 		dpkt = init_pkt(dsmp, DHCPV6_MSG_RELEASE);
 		(void) add_pkt_opt(dpkt, DHCPV6_OPT_SERVERID,
@@ -237,24 +236,7 @@
 			    "used bootp; not writing lease file for %s",
 			    dsmp->dsm_name);
 		} else {
-			PKT_LIST *plp[2];
-			const char *hcfile;
-
-			hcfile = ifname_to_hostconf(dsmp->dsm_name,
-			    dsmp->dsm_isv6);
-			plp[0] = dsmp->dsm_ack;
-			plp[1] = dsmp->dsm_orig_ack;
-			if (write_hostconf(dsmp->dsm_name, plp, 2,
-			    monosec_to_time(dsmp->dsm_curstart_monosec),
-			    dsmp->dsm_isv6) != -1) {
-				dhcpmsg(MSG_DEBUG, "wrote lease to %s", hcfile);
-			} else if (errno == EROFS) {
-				dhcpmsg(MSG_DEBUG, "%s is on a read-only file "
-				    "system; not saving lease", hcfile);
-			} else {
-				dhcpmsg(MSG_ERR, "cannot write %s (reboot will "
-				    "not use cached configuration)", hcfile);
-			}
+			write_lease_to_hostconf(dsmp);
 		}
 	} else {
 		dhcpmsg(MSG_DEBUG, "%s in state %s; not saving lease",
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/renew.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/renew.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,12 +19,9 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <time.h>
 #include <netinet/in.h>
@@ -34,6 +31,7 @@
 #include <netinet/udp_var.h>
 #include <libinetutil.h>
 #include <dhcpmsg.h>
+#include <dhcp_hostconf.h>
 #include <string.h>
 
 #include "packet.h"
@@ -275,6 +273,8 @@
 		return (1);
 	}
 
+	(void) remove_hostconf(dsmp->dsm_name, dsmp->dsm_isv6);
+
 	dhcpmsg(MSG_INFO, "last lease expired on %s -- restarting DHCP",
 	    dsmp->dsm_name);
 
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/select.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/select.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,14 +19,11 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  *
  * SELECTING state of the client state machine.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -41,6 +38,7 @@
 #include <netinet/ip_var.h>
 #include <netinet/udp_var.h>
 #include <dhcpmsg.h>
+#include <dhcp_hostconf.h>
 
 #include "states.h"
 #include "agent.h"
@@ -136,6 +134,9 @@
 
 	}
 
+	/* Remove the stale hostconf file, if there is any */
+	(void) remove_hostconf(dsmp->dsm_name, dsmp->dsm_isv6);
+
 	dsmp->dsm_offer_timer = iu_schedule_timer(tq,
 	    dsmp->dsm_offer_wait, dhcp_requesting, dsmp);
 	if (dsmp->dsm_offer_timer == -1) {
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/states.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/states.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  *
  * This module contains core functions for managing DHCP state machine
  * instances.
@@ -1612,7 +1611,7 @@
 	}
 
 smach_terminate:
-	finished_smach(dsmp, DHCP_IPC_E_UNKIF);
+	finished_smach(dsmp, DHCP_IPC_E_INVIF);
 	release_smach(dsmp);
 
 	return (B_FALSE);
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/util.c	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/util.c	Mon Aug 02 16:06:35 2010 -0400
@@ -19,12 +19,9 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -41,6 +38,7 @@
 #include <netdb.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <dhcp_hostconf.h>
 
 #include "states.h"
 #include "agent.h"
@@ -685,3 +683,25 @@
 	}
 	return (status);
 }
+
+void
+write_lease_to_hostconf(dhcp_smach_t *dsmp)
+{
+	PKT_LIST *plp[2];
+	const char *hcfile;
+
+	hcfile = ifname_to_hostconf(dsmp->dsm_name, dsmp->dsm_isv6);
+	plp[0] = dsmp->dsm_ack;
+	plp[1] = dsmp->dsm_orig_ack;
+	if (write_hostconf(dsmp->dsm_name, plp, 2,
+	    monosec_to_time(dsmp->dsm_curstart_monosec),
+	    dsmp->dsm_isv6) != -1) {
+		dhcpmsg(MSG_DEBUG, "wrote lease to %s", hcfile);
+	} else if (errno == EROFS) {
+		dhcpmsg(MSG_DEBUG, "%s is on a read-only file "
+		    "system; not saving lease", hcfile);
+	} else {
+		dhcpmsg(MSG_ERR, "cannot write %s (reboot will "
+		    "not use cached configuration)", hcfile);
+	}
+}
--- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/util.h	Mon Aug 02 12:39:37 2010 -0700
+++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/util.h	Mon Aug 02 16:06:35 2010 -0400
@@ -19,15 +19,12 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 #ifndef	UTIL_H
 #define	UTIL_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <netinet/dhcp.h>
@@ -77,6 +74,7 @@
 const char	*iffile_to_hostname(const char *);
 int		dhcpv6_status_code(const dhcpv6_option_t *, uint_t,
     const char **, const char **, uint_t *);
+void		write_lease_to_hostconf(dhcp_smach_t *);
 
 #ifdef	__cplusplus
 }