Exemplo n.º 1
0
/*ARGSUSED*/
static int
cldhcp(cli_ent_t *cliptr, char *valstr, boolean_t out)
{
	static boolean_t	first_time = B_TRUE;
	static int		ret = CLI_CONT;

	if (first_time) {
		/*
		 * Set DHCP's idea of the client_id from our cached value.
		 */
		cliptr = find_cli_ent(BI_CLIENT_ID);
		if (CLF_ISMOD(cliptr)) {
			dhcp_set_client_id(cliptr->varptr, cliptr->varlen);
		}

		bootlog("wanboot", BOOTLOG_INFO, "Starting DHCP configuration");

		(void) ipv4_setpromiscuous(B_TRUE);
		if (dhcp() == 0) {
			bootlog("wanboot", BOOTLOG_INFO,
			    "DHCP configuration succeeded");
		} else {
			bootlog("wanboot", BOOTLOG_CRIT,
			    "DHCP configuration failed");
			ret = CLI_FAIL;
		}
		(void) ipv4_setpromiscuous(B_FALSE);

		first_time = B_FALSE;
	}

	return (ret);
}
Exemplo n.º 2
0
/*
 * Return the net-config-strategy: "dhcp", "manual" or "rarp"
 */
static char *
net_config_strategy(void)
{
	static char	ncs[8];		/* "dhcp" or "manual" */
	size_t		len = sizeof (ncs);

	if (ncs[0] == '\0' &&
	    bootinfo_get(BI_NET_CONFIG_STRATEGY, ncs, &len, NULL) !=
	    BI_E_SUCCESS) {
		/*
		 * Support for old PROMs: create the net-config-strategy
		 * property under /chosen with an appropriate value.  If we
		 * have a bootp-response (not interested in its value, just
		 * its presence) then we did DHCP; otherwise configuration
		 * is manual.
		 */
		if (bootinfo_get(BI_BOOTP_RESPONSE, NULL, NULL,
		    NULL) == BI_E_BUF2SMALL) {
			(void) strcpy(ncs, "dhcp");
		} else {
			(void) strcpy(ncs, "manual");
		}
		(void) bootinfo_put(BI_NET_CONFIG_STRATEGY, ncs, strlen(ncs),
		    BI_R_CHOSEN);

		bootlog("wanboot", BOOTLOG_INFO,
		    "Default net-config-strategy: %s", ncs);
	}

	return (ncs);
}
Exemplo n.º 3
0
/*
 * Informational output to the user (if interactive) or the bootlogger.
 */
static void
info(const char *msg, boolean_t interactive)
{
	if (interactive) {
		printf("%s\n", msg);
	} else {
		bootlog("wanboot", BOOTLOG_INFO, "%s", msg);
	}
}
Exemplo n.º 4
0
boolean_t
wanboot_verify_config(void)
{
	/*
	 * Check that the wanboot.conf file defines a valid root_server
	 * URL, and check that, if given, the boot_logger URL is valid.
	 */
	if (config_incomplete(0, B_FALSE)) {
		bootlog("wanboot", BOOTLOG_CRIT,
		    "incomplete boot configuration");
		return (B_FALSE);
	}
	return (B_TRUE);
}
intrusive_ref_ptr<DevFs> //return value is a pointer to DevFs
#else //WITH_DEVFS
void                     //return value is void
#endif //WITH_DEVFS
basicFilesystemSetup(intrusive_ref_ptr<Device> dev)
{
    bootlog("Mounting MountpointFs as / ... ");
    FilesystemManager& fsm=FilesystemManager::instance();
    intrusive_ref_ptr<FilesystemBase> rootFs(new MountpointFs);
    bootlog(fsm.kmount("/",rootFs)==0 ? "Ok\n" : "Failed\n");
    
    #ifdef WITH_DEVFS
    bootlog("Mounting DevFs as /dev ... ");
    StringPart sp("dev");
    int r1=rootFs->mkdir(sp,0755); 
    intrusive_ref_ptr<DevFs> devfs(new DevFs);
    int r2=fsm.kmount("/dev",devfs);
    bool devFsOk=(r1==0 && r2==0);
    bootlog(devFsOk ? "Ok\n" : "Failed\n");
    if(!devFsOk) return devfs;
    fsm.setDevFs(devfs);
    #endif //WITH_DEVFS
    
    bootlog("Mounting Fat32Fs as /sd ... ");
    bool fat32failed=false;
    intrusive_ref_ptr<FileBase> disk;
    #ifdef WITH_DEVFS
    if(dev) devfs->addDevice("sda",dev);
    StringPart sda("sda");
    if(devfs->open(disk,sda,O_RDWR,0)<0) fat32failed=true;
    #else //WITH_DEVFS
    if(dev && dev->open(disk,intrusive_ref_ptr<FilesystemBase>(0),O_RDWR,0)<0)
        fat32failed=true;
    #endif //WITH_DEVFS
    
    intrusive_ref_ptr<Fat32Fs> fat32;
    if(fat32failed==false)
    {
        fat32=new Fat32Fs(disk);
        if(fat32->mountFailed()) fat32failed=true;
    }
    if(fat32failed==false)
    {
        StringPart sd("sd");
        fat32failed=rootFs->mkdir(sd,0755)!=0;
        fat32failed=fsm.kmount("/sd",fat32)!=0;
    }
    bootlog(fat32failed==0 ? "Ok\n" : "Failed\n");
    
    #ifdef WITH_DEVFS
    return devfs;
    #endif //WITH_DEVFS
}
Exemplo n.º 6
0
/*
 * Function:	_write_message
 * Description:
 * Scope:	private
 * Parameters:	dest	- [RO]
 *			  [LOG	  - write only to the log file
 *			   SCR	  - write only to the display
 *			   LOGSCR - write to both the file and display]
 *			  specifies where the message should be recorded
 *		type	- [RO]
 *			  [STATMSG - status message
 *			   ERRMSG  - non-reconcilable problem
 *			   WARNMSG - advisory warning]
 *			  notification type
 *		format	- [RO]
 *			  [LEVEL0   - base level message
 *			   LEVEL1   - first level message
 *			   LEVEL2   - second level message
 *			   LEVEL3   - third level message
 *			   CONTINUE - message continuation from preceding
 *				      message
 *			   LISTITEM - item type message
 *			   FMTPARTIAL  - part of a message (more to come)]
 *			  format of the message (used by the formatting routine)
 *		buf	- [RO]
 *			  assembled message, unformatted
 * Return:	none
 */
static void
_write_message(u_char dest, u_int type, u_int format, char *buf)
{

	/*
	 * if the text is targetted for the remote log facility, write it
	 * using the currently registered file logging function
	 */
	if ((dest & LOG) && bootlog_available()) {
		switch (type) {
		    /* progress msgs use same format as status msgs */
		    case PROGMSG:
			    bootlog("ident", BOOTLOG_PROGRESS, "%s", buf);
			    break;

		    case STATMSG:
			    bootlog("ident", BOOTLOG_INFO, "%s", buf);
			    break;
			break;

		    case WARNMSG:
			    bootlog("ident", BOOTLOG_WARNING, "%s", buf);
			    break;
			break;

		    case ERRMSG:
			    bootlog("ident", BOOTLOG_EMERG, "%s", buf);
			    break;
			break;
		}
	}

	/*
	 * if the text is targetted for the log file, write it
	 * using the currently registered file logging function
	 */
	if (dest & LOG) {
		switch (type) {
			/*
			 * progress msgs use same format as status
			 * msgs when writing to the local log
			 */
		    case PROGMSG:
		    case STATMSG:
			(*_log_func)(format,
				_dflt_status_format(format, buf));
			break;

		    case WARNMSG:
			(*_log_func)(format, _dflt_warning_format(format, buf));
			break;

		    case ERRMSG:
			(*_log_func)(format, _dflt_error_format(format, buf));
			break;
		}
	}

	/*
	 * if the text is targetted for the display, write it
	 * using the currently registered display logging function
	 */
	if (dest & SCR) {
		switch (type) {
		    case ERRMSG:
			(*_error_func)(format, buf);
			break;
			/*
			 * progress msgs use same format as status
			 * msgs when writing to the screen
			 */
		    case PROGMSG:
		    case STATMSG:
			(*_status_func)(format, buf);
			break;
		    case WARNMSG:
			(*_warning_func)(format, buf);
			break;
		}
	}
}
Exemplo n.º 7
0
boolean_t
wanboot_init_interface(char *boot_arguments)
{
	boolean_t	interactive;
	int		which;

#if	defined(__sparcv9)
	/*
	 * Get the keys from PROM before we allow the user
	 * to override them from the CLI.
	 */
	get_prom_encr_keys();
	get_prom_hash_keys();
#endif	/* defined(__sparcv9) */

	/*
	 * If there is already a bootp-response property under
	 * /chosen then the PROM must have done DHCP for us;
	 * invoke dhcp() to 'bind' the interface.
	 */
	if (bootinfo_get(BI_BOOTP_RESPONSE, NULL, NULL, NULL) ==
	    BI_E_BUF2SMALL) {
		(void) cldhcp(NULL, NULL, 0);
	}

	/*
	 * Obtain default interface values from bootinfo.
	 */
	bootinfo_defaults(CLF_IF);

	/*
	 * Process the boot arguments (following the "-o" option).
	 */
	if (boot_arguments != NULL) {
		(void) cli_eval_buf(boot_arguments,
		    (CLF_ARG | CLF_IF | CLF_BM));
	}

	/*
	 * Stash away any interface/bootmisc parameter values we got
	 * from either the PROM or the boot arguments.
	 */
	update_bootinfo(CLF_IF | CLF_BM);

	/*
	 * If we don't already have a value for bootserver, try to
	 * deduce one.  Refresh wbcli's idea of these values.
	 */
	determine_bootserver_url();
	bootinfo_defaults(CLF_BM);

	/*
	 * Check that the information we have collected thus far is sufficient.
	 */
	interactive = args_specified_prompt;

	if (interactive) {
		/*
		 * Drop into the boot interpreter to allow the input
		 * of keys, bootserver and bootmisc, and in the case
		 * that net-config-strategy == "manual" the interface
		 * parameters.
		 */
		which = CLF_BM | CLF_CMD;
		if (strcmp(net_config_strategy(), "manual") == 0)
			which |= CLF_IF;

		do {
			cli_interpret(which);
			update_bootinfo(CLF_IF | CLF_BM);
		} while (config_incomplete(CLF_IF, interactive));
	} else {
		/*
		 * The user is not to be given the opportunity to
		 * enter further values; fail.
		 */
		if (config_incomplete(CLF_IF, interactive)) {
			bootlog("wanboot", BOOTLOG_CRIT,
			    "interface incorrectly configured");
			return (B_FALSE);
		}
	}

	/*
	 * If a wanboot-enabled PROM hasn't processed client-id in
	 * network-boot-arguments, or no value for client-id has been
	 * specified to the boot interpreter, then provide a default
	 * client-id based on our MAC address.
	 */
	generate_default_clientid();

	/*
	 * If net-config-strategy == "manual" then we must setup
	 * the interface now; if "dhcp" then it will already have
	 * been setup.
	 */
	if (strcmp(net_config_strategy(), "manual") == 0)
		setup_interface();
	return (B_TRUE);
}