/** * Reset the network device * * @v snp SNP interface * @v ext_verify Extended verification required * @ret efirc EFI status code */ static EFI_STATUS EFIAPI efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); int rc; DBGC2 ( snpdev, "SNPDEV %p RESET (%s extended verification)\n", snpdev, ( ext_verify ? "with" : "without" ) ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) return EFI_NOT_READY; netdev_close ( snpdev->netdev ); efi_snp_set_state ( snpdev ); if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) { DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n", snpdev, snpdev->netdev->name, strerror ( rc ) ); return EFIRC ( rc ); } efi_snp_set_state ( snpdev ); return 0; }
/** * Close PXE network device * */ static void pxe_netdev_close ( void ) { assert ( pxe_netdev != NULL ); netdev_rx_unfreeze ( pxe_netdev ); netdev_irq ( pxe_netdev, 0 ); netdev_close ( pxe_netdev ); undi_tx_count = 0; }
/** * Shut down the network device * * @v snp SNP interface * @ret efirc EFI status code */ static EFI_STATUS EFIAPI efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); DBGC2 ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev ); netdev_close ( snpdev->netdev ); snpdev->mode.State = EfiSimpleNetworkStarted; return 0; }
static void discovery_local_port_cb(const struct ofp_port *port, void *d_) { struct discovery *d = d_; if (port) { char name[OFP_MAX_PORT_NAME_LEN + 1]; struct netdev *netdev; int retval; /* Check that this was really a change. */ get_port_name(port, name, sizeof name); if (d->dhcp && !strcmp(netdev_get_name(dhclient_get_netdev(d->dhcp)), name)) { return; } /* Destroy current DHCP client. */ dhclient_destroy(d->dhcp); d->dhcp = NULL; /* Bring local network device up. */ retval = netdev_open(name, NETDEV_ETH_TYPE_NONE, &netdev); if (retval) { VLOG_ERR(LOG_MODULE, "Could not open %s device, discovery disabled: %s", name, strerror(retval)); return; } retval = netdev_turn_flags_on(netdev, NETDEV_UP, true); if (retval) { VLOG_ERR(LOG_MODULE, "Could not bring %s device up, discovery disabled: %s", name, strerror(retval)); return; } netdev_close(netdev); /* Initialize DHCP client. */ retval = dhclient_create(name, modify_dhcp_request, validate_dhcp_offer, (void *) d->s, &d->dhcp); if (retval) { VLOG_ERR(LOG_MODULE, "Failed to initialize DHCP client, " "discovery disabled: %s", strerror(retval)); return; } dhclient_set_max_timeout(d->dhcp, 3); dhclient_init(d->dhcp, 0); } else { dhclient_destroy(d->dhcp); d->dhcp = NULL; } }
/** * Execute "dhcp" command for a network device * * @v netdev Network device * @ret rc Exit code */ static int dhcp_exec_netdev ( struct net_device *netdev ) { int rc; if ( ( rc = dhcp ( netdev ) ) != 0 ) { printf ( "Could not configure %s: %s\n", netdev->name, strerror ( rc ) ); /* Close device on failure, to avoid memory exhaustion */ netdev_close ( netdev ); return 1; } return 0; }
/** * Shut down the network device * * @v snp SNP interface * @ret efirc EFI status code */ static EFI_STATUS EFIAPI efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); DBGC2 ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) return EFI_NOT_READY; netdev_close ( snpdev->netdev ); efi_snp_set_state ( snpdev ); return 0; }
/** * Reset the network device * * @v snp SNP interface * @v ext_verify Extended verification required * @ret efirc EFI status code */ static EFI_STATUS EFIAPI efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); int rc; DBGC2 ( snpdev, "SNPDEV %p RESET (%s extended verification)\n", snpdev, ( ext_verify ? "with" : "without" ) ); netdev_close ( snpdev->netdev ); snpdev->mode.State = EfiSimpleNetworkStarted; if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) { DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n", snpdev, snpdev->netdev->name, strerror ( rc ) ); return RC_TO_EFIRC ( rc ); } snpdev->mode.State = EfiSimpleNetworkInitialized; return 0; }
/** * Close network device * * @v netdev Network device */ void ifclose ( struct net_device *netdev ) { netdev_close ( netdev ); }
/** * Close PXE network device * */ static void pxe_netdev_close ( void ) { netdev_irq ( pxe_netdev, 0 ); netdev_close ( pxe_netdev ); undi_tx_count = 0; }