Beispiel #1
0
/**
 * iface_create_ifaces_from_boot_contexts - create ifaces based on boot info
 * @ifaces: list to store ifaces in
 * @targets: list of targets to create ifaces from
 *
 * This function will create a iface struct based on the boot info
 * and it will create (or update if existing already) a iface rec in
 * the ifaces dir based on the info.
 */
int iface_create_ifaces_from_boot_contexts(struct list_head *ifaces,
					   struct list_head *targets)
{
	struct boot_context *context;
	struct iface_rec *iface, *tmp_iface;
	int rc = 0;

	list_for_each_entry(context, targets, list) {
		rc = 0;
		/* use dummy name. If valid it will get overwritten below */
		iface = iface_alloc(DEFAULT_IFACENAME, &rc);
		if (!iface) {
			log_error("Could not setup iface %s for boot\n",
				  context->iface);
			goto fail;
		}
		if (!iface_setup_from_boot_context(iface, context)) {
			/* no offload so forget it */
			free(iface);
			continue;
		}

		rc = iface_conf_write(iface);
		if (rc) {
			log_error("Could not setup default iface conf "
				  "for %s.", iface->name);
			free(iface);
			goto fail;
		}
		list_add_tail(&iface->list, ifaces);
	}
Beispiel #2
0
/*
 * Parse "interface" keyword.
 */
static int
InterfaceFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
	struct mystate *softc;
	struct iface *iface;
	Jim_Obj *ipobj;
	const char *ip;
	const char *name;
	int error;

	iface = NULL;
	ipobj = NULL;
	ip = name = NULL;
	error = 0;

	if (argc != 3)
		return (JIM_ERR);

	softc = Jim_CmdPrivData(interp);

	/* Name of the interface. */
	name = Jim_GetString(argv[1], NULL);

	softc->block_parsing = 1;
	/* Body of the block */
	error = Jim_EvalObj(interp, argv[2]);
	if (error) {
		printf("couldn't evaluate\n");
		return (JIM_ERR);
	}
	softc->block_parsing = 0;

	/* Take our hidden variable */
	ipobj = Jim_GetVariableStr(interp, JCONF_VAR_IP, JIM_NONE);
	assert(ipobj != NULL);

	ip = Jim_GetString(ipobj, NULL);
	if (ip == NULL) {
		Jim_fprintf(interp, interp->cookie_stdout, "NULL!\n");
		return (JIM_ERR);
	}
	iface = iface_alloc(ip, name);
	assert(iface != NULL);
	INSERT(softc->head, iface);
	return (JIM_OK);
}
Beispiel #3
0
int iface_for_each_iface(void *data, int skip_def, int *nr_found,
			 iface_op_fn *fn)
{
	DIR *iface_dirfd;
	struct dirent *iface_dent;
	struct iface_rec *iface, *def_iface;
	int err = 0, i = 0;

	if (!skip_def) {
		while ((def_iface = default_ifaces[i++])) {
			iface = iface_alloc(def_iface->name, &err);
			if (!iface) {
				log_error("Could not add iface %s.",
					  def_iface->name);
				continue;
			}
			iface_copy(iface, def_iface);
			err = fn(data, iface);
			free(iface);
			if (err)
				return err;
			(*nr_found)++;
		}
	}

	iface_dirfd = opendir(IFACE_CONFIG_DIR);
	if (!iface_dirfd)
		return errno;

	while ((iface_dent = readdir(iface_dirfd))) {
		if (!strcmp(iface_dent->d_name, ".") ||
		    !strcmp(iface_dent->d_name, ".."))
			continue;

		log_debug(5, "iface_for_each_iface found %s",
			 iface_dent->d_name);
		iface = iface_alloc(iface_dent->d_name, &err);
		if (!iface || err) {
			if (err == ISCSI_ERR_INVAL)
				log_error("Invalid iface name %s. Must be "
					  "from 1 to %d characters.",
					   iface_dent->d_name,
					   ISCSI_MAX_IFACE_LEN - 1);
			else
				log_error("Could not add iface %s.",
					  iface_dent->d_name);
			continue;
		}

		err = idbm_lock();
		if (err) {
			free(iface);
			continue;
		}

		err = __iface_conf_read(iface);
		idbm_unlock();
		if (err) {
			log_error("Could not read def iface %s (err %d)",
				  iface->name, err);
			free(iface);
			continue;
		}

		if (!iface_is_valid(iface)) {
			log_debug(5, "iface is not valid "
				  "Iface settings " iface_fmt,
				  iface_str(iface));
			free(iface);
			continue;
		}

		err = fn(data, iface);
		free(iface);
		if (err)
			break;
		(*nr_found)++;
	}

	closedir(iface_dirfd);
	return err;
}