#include <gpxe/udp.h>
#include <gpxe/async.h>
#include <gpxe/retry.h>
+#include <gpxe/hotplug.h>
/** BOOTP/DHCP server port */
#define BOOTPS_PORT 67
/** Network device being configured */
struct net_device *netdev;
+ /** Persistent reference to network device */
+ struct reference netdev_ref;
/** Options obtained from server */
struct dhcp_option_block *options;
* @v rc Return status code
*/
static void dhcp_done ( struct dhcp_session *dhcp, int rc ) {
+
/* Free up options if we failed */
if ( rc != 0 ) {
if ( dhcp->options ) {
}
}
+ /* Stop retry timer */
+ stop_timer ( &dhcp->timer );
+
/* Close UDP connection */
udp_close ( &dhcp->udp );
+ /* Release reference on net device */
+ ref_del ( &dhcp->netdev_ref );
+
/* Mark async operation as complete */
async_done ( &dhcp->aop, rc );
}
.newdata = dhcp_newdata,
};
+/**
+ * Forget reference to net_device
+ *
+ * @v ref Persistent reference
+ */
+static void dhcp_forget_netdev ( struct reference *ref ) {
+ struct dhcp_session *dhcp
+ = container_of ( ref, struct dhcp_session, netdev_ref );
+
+ /* Kill DHCP session immediately */
+ dhcp_done ( dhcp, -ENETUNREACH );
+}
+
/**
* Initiate DHCP on a network interface
*
goto out;
}
+ /* Add persistent reference to net device */
+ dhcp->netdev_ref.forget = dhcp_forget_netdev;
+ ref_add ( &dhcp->netdev_ref, &dhcp->netdev->references );
+
/* Proof of concept: just send a single DHCPDISCOVER */
dhcp_send_request ( dhcp );