Esempio n. 1
0
int dhcp ( struct net_device *netdev ) {
	uint8_t *chaddr;
	uint8_t hlen;
	uint16_t flags;
	int rc;

	/* Check we can open the interface first */
	if ( ( rc = ifopen ( netdev ) ) != 0 )
		return rc;

	/* Wait for link-up */
	if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
		return rc;

	/* Perform DHCP */
	chaddr = dhcp_chaddr ( netdev, &hlen, &flags );
	printf ( "DHCP (%s ", netdev->name );
	while ( hlen-- )
		printf ( "%02x%c", *(chaddr++), ( hlen ? ':' : ')' ) );

	if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 ) {
		rc = monojob_wait ( "" );
	} else if ( rc > 0 ) {
		printf ( " using cached\n" );
		rc = 0;
	}

	return rc;
}
Esempio n. 2
0
/**
 * Fetch an image
 *
 * @v uri_string	URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
 * @v name		Name for image, or NULL
 * @v register_image	Image registration routine
 * @ret rc		Return status code
 */
int imgfetch ( struct image *image, const char *uri_string,
	       int ( * image_register ) ( struct image *image ) ) {
	char uri_string_redacted[ strlen ( uri_string ) + 3 /* "***" */
				  + 1 /* NUL */ ];
	struct uri *uri;
	const char *password;
	int rc;

	if ( ! ( uri = parse_uri ( uri_string ) ) )
		return -ENOMEM;

	image_set_uri ( image, uri );

	/* Redact password portion of URI, if necessary */
	password = uri->password;
	if ( password )
		uri->password = "******";
	unparse_uri ( uri_string_redacted, sizeof ( uri_string_redacted ),
		      uri, URI_ALL );
	uri->password = password;

	if ( ( rc = create_downloader ( &monojob, image, image_register,
					LOCATION_URI, uri ) ) == 0 )
		rc = monojob_wait ( uri_string_redacted );

	uri_put ( uri );
	return rc;
}
Esempio n. 3
0
int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
	int rc;

	/* Perform PXE Boot Server Discovery */
	printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
	if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
		rc = monojob_wait ( "" );

	return rc;
}
Esempio n. 4
0
/**
 * Get time and date via NTP
 *
 * @v hostname		Hostname
 * @ret rc		Return status code
 */
int ntp ( const char *hostname ) {
	int rc;

	/* Start NTP client */
	if ( ( rc = start_ntp ( &monojob, hostname ) ) != 0 )
		return rc;

	/* Wait for NTP to complete */
	if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 )
		return rc;

	return 0;
}
Esempio n. 5
0
/**
 * Ping a host
 *
 * @v hostname		Hostname
 * @v timeout		Timeout between pings, in ticks
 * @v len		Payload length
 * @ret rc		Return status code
 */
int ping ( const char *hostname, unsigned long timeout, size_t len ) {
	int rc;

	/* Create pinger */
	if ( ( rc = create_pinger ( &monojob, hostname, timeout,
				    len, ping_callback ) ) != 0 ) {
		printf ( "Could not start ping: %s\n", strerror ( rc ) );
		return rc;
	}

	/* Wait for ping to complete */
	if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
		printf ( "Finished: %s\n", strerror ( rc ) );
		return rc;
	}

	return 0;
}
Esempio n. 6
0
int dhcp ( struct net_device *netdev ) {
	int rc;

	/* Check we can open the interface first */
	if ( ( rc = ifopen ( netdev ) ) != 0 )
		return rc;

	/* Wait for link-up */
	if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
		return rc;

	/* Perform DHCP */
	printf ( "DHCP (%s %s)", netdev->name,
		 netdev->ll_protocol->ntoa ( netdev->ll_addr ) );
	if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 )
		rc = monojob_wait ( "" );

	return rc;
}