⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iscsi-config.c

📁 ISCSI user client software.Client would be used to access the IPSAN server.
💻 C
📖 第 1 页 / 共 5 页
字号:
				if (value >= 0) {					if (current_entry					    && current_entry->type ==					    CONFIG_TYPE_SENDTARGETS) {						struct iscsi_sendtargets_config						*sendtargets =						    current_entry->config.						    sendtargets;						sendtargets->send_async_text =						    value;						debugmsg(5,							 "config entry %p "							 "sendtargets config%p "							 "sendasynctext %d",							 current_entry,							 sendtargets, value);					} else {						config->defaults.						    send_async_text = value;						debugmsg(5,							 "config global "							 "SendAsyncText "							 "value %d",							 value);					}				} else {					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "invalid value %s",					       line_number, pathname,					       line + 14);				}			} else if (strncasecmp(line, "ReadSize=", 9) == 0) {				int value = parse_number(line + 9);				/* for testing, allow variable read sizes 				 * to simulate varying PDU sizes 				 */				if (value < 0) {					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "invalid entry %s",					       line_number, pathname, line);				} else if (current_entry					   && current_entry->type ==					   CONFIG_TYPE_DISCOVERY_FILE) {					struct iscsi_discovery_file_config					*file_config =					    current_entry->config.file;					file_config->read_size = value;					debugmsg(5,						 "config entry %p discovery "						 "file config %p continuous %d",						 current_entry, file_config,						 value);				} else {					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "invalid entry %s",					       line_number, pathname, line);				}			} else if (strncasecmp(line, "DefaultAddress=", 15) ==				   0) {				/* allow DiscoveryFile entries to specify 				 * a default address, so that TargetAddresses 				 * can be omitted from the discovery file.				 */				if (current_entry				    && current_entry->type ==				    CONFIG_TYPE_DISCOVERY_FILE) {					struct iscsi_discovery_file_config					*file_config =					    current_entry->config.file;					char *address = line + 15;					char *port = NULL;					if ((port = strrchr(address, ':'))) {						*port = '\0';						port++;						file_config->port =						    strdup(port);					} else {						file_config->port =						    strdup("3260");					}					file_config->address = strdup(address);					debugmsg(5,						 "config entry %p discovery "						 "file config %p address %s "						 "port %d ",						 current_entry, file_config,						 file_config->address,						 file_config->port);				} else {					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "invalid entry %s",					       line_number, pathname, line);				}			} else if (strncasecmp(line, "SLPMulticast=", 13) == 0) {				char *value = parse_quoted_string(line + 13);				struct iscsi_slp_config *slp_config;				slp_multicast_seen = 1;				if ((value == NULL) || (*value == '\0')) {					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "SLPMulticast requires a list "					       "of interface names\n",					       line_number, pathname);					continue;				}				/* add an entry for SLP */				entry = calloc(1, sizeof (*entry));				if (entry == NULL) {					logmsg(AS_ERROR,					       "failed to allocate "					       "config entry");					return 0;				}				entry->line_number = line_number;				slp_config =				    calloc(1, sizeof (struct iscsi_slp_config));				if (slp_config == NULL) {					logmsg(AS_ERROR,					       "failed to allocate SLP config");					return 0;				}				entry->type = CONFIG_TYPE_SLP;				entry->config.slp = slp_config;				slp_entry = entry;				/* capture the global defaults */				memcpy(&slp_config->auth_options,				       &config->defaults.auth_options,				       sizeof (slp_config->auth_options));				if (config->defaults.slp_scopes)					slp_config->scopes =					    strdup(config->defaults.slp_scopes);				else					slp_config->scopes = NULL;				slp_config->poll_interval =				    config->defaults.slp_poll_interval;				/* multicast on the specified interfaces */				slp_config->interfaces = strdup(value);				slp_config->address = NULL;				slp_config->port = 0;				/* append it to the list of all config entries 				 */				add_config_entry(config, entry);				debugmsg(5,					 "config entry %p SLPMulticast %p = %s",					 entry, slp_config, value);				/* indented settings in the config file 				 * may modify this entry 				 */				current_entry = entry;				entry_indent = indent;			} else if (strncasecmp(line, "SLPUnicast=", 11) == 0) {				char *addr = NULL, *port = NULL;				char *sep = line;				struct iscsi_slp_config *slp_config = NULL;				/* find the start of the address */				while (*sep && *sep != '=')					sep++;				addr = ++sep;				if (*addr) {					/* look for a port number */					/* FIXME: ought to handle the IPv6 					 * syntax in the iSCSI spec 					 */					while (*sep && !isspace(c = *sep)					       && *sep != ':')						sep++;					if (*sep == ':') {						*sep = '\0';						port = ++sep;						while (*sep						       && isdigit(c = *sep))							sep++;						*sep = '\0';					} else						*sep = '\0';					/* create a new slp config entry */					entry = calloc(1, sizeof (*entry));					if (entry == NULL) {						logmsg(AS_ERROR,						       "failed to allocate "						       "config entry");						return 0;					}					entry->line_number = line_number;					slp_config =					    calloc(1, sizeof (*slp_config));					if (slp_config == NULL) {						free(entry);						entry = NULL;						logmsg(AS_ERROR,						       "failed to allocate "						       "SLP config");						return 0;					}					entry->type = CONFIG_TYPE_SLP;					entry->config.slp = slp_config;					/* capture the current global defaults 					 */					memcpy(&slp_config->auth_options,					       &config->defaults.auth_options,					       sizeof (slp_config->						       auth_options));					if (config->defaults.slp_scopes)						slp_config->scopes =						    strdup(config->defaults.							   slp_scopes);					else						slp_config->scopes = NULL;					slp_config->poll_interval =					    config->defaults.slp_poll_interval;					/* record the address and port */					slp_config->address = strdup(addr);					if (port && *port && (atoi(port) > 0))	/* FIXME: check for invalid port strings */						slp_config->port =						    atoi(port);					else						slp_config->port = ISCSI_DEFAULT_PORT;	/* FIXME: what is the default SLP port? */					slp_config->interfaces = NULL;							/* let the OS pick an interface 						 * for unicasts 						 */					/* append it to the list of all 					 * config entries 					 */					add_config_entry(config, entry);					debugmsg(5,						 "config entry %p SLPUnicast "						 "%p = %s:%d",						 entry, slp_config, addr,						 slp_config->port);					/* indented settings in the config file 					 * may modify this entry 					 */					current_entry = entry;					entry_indent = indent;				} else {					logmsg(AS_ERROR,					       "error on line %d of %s, an "					       "address is required",					       line_number, pathname);				}			} else if (strncasecmp(line, "PollInterval=", 13) == 0) {				int value = parse_time(line + 13);				if (value < 0) {					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "illegal value %s",					       line_number, pathname,					       line + 13);				} else if (current_entry					   && current_entry->type ==					   CONFIG_TYPE_SLP) {					struct iscsi_slp_config *slp =					    current_entry->config.slp;					slp->poll_interval = value;					debugmsg(5,						 "config entry %p poll "						 "interval %d",						 slp, value);				} else {					config->defaults.slp_poll_interval =					    value;					debugmsg(5,						 "config global SLP "						 "poll interval %d",						 value);				}			} else if (strncasecmp(line, "TargetName=", 11) == 0) {				/* settings for a specific iSCSI TargetName 				 * (can be quoted) 				 */				char *n = parse_quoted_string(line + 11);				struct iscsi_targetname_config				    *targetname_config;				entry = calloc(1, sizeof (*entry));				if (entry == NULL) {					logmsg(AS_ERROR,					       "failed to allocate "					       "config entry");					return 0;				}				entry->line_number = line_number;				targetname_config =				    calloc(1, sizeof (*targetname_config));				if (targetname_config == NULL) {					free(entry);					entry = NULL;					logmsg(AS_ERROR,					       "failed to allocate "					       "TargetName config");					return 0;				}				entry->type = CONFIG_TYPE_TARGETNAME;				entry->config.targetname = targetname_config;				targetname_config->TargetName = strdup(n);				/* capture the current global defaults */				targetname_config->enabled =				    config->defaults.enabled;				memcpy(&targetname_config->auth_options,				       &config->defaults.auth_options,				       sizeof (targetname_config->					       auth_options));				memcpy(&targetname_config->				       connection_timeout_options,				       &config->defaults.				       connection_timeout_options,				       sizeof (targetname_config->					       connection_timeout_options));				memcpy(&targetname_config->				       session_timeout_options,				       &config->defaults.				       session_timeout_options,				       sizeof (targetname_config->					       session_timeout_options));				memcpy(&targetname_config->				       error_timeout_options,				       &config->defaults.error_timeout_options,				       sizeof (targetname_config->					       error_timeout_options));				memcpy(&targetname_config->tcp_options,				       &config->defaults.tcp_options,				       sizeof (targetname_config->tcp_options));				memcpy(&targetname_config->iscsi_options,				       &config->defaults.iscsi_options,				       sizeof (targetname_config->					       iscsi_options));				/* append it to the list of all config entries 				 */				add_config_entry(config, entry);				debugmsg(5,					 "config entry %p targetname %p = %s",					 entry, targetname_config, n, config);				/* indented settings in the config file 				 * may modify this entry 				 */				current_entry = entry;				entry_indent = indent;			} else if (strncasecmp(line, "Enabled=", 8) == 0) {				char *str = &line[8];				int value = parse_boolean(str);				if (value >= 0) {					if (current_entry) {						if (current_entry->type ==						    CONFIG_TYPE_TARGETNAME) {							struct iscsi_targetname_config							*targetname_config =							    current_entry->							    config.targetname;							targetname_config->							    enabled = value;							debugmsg(5,								 "config entry "								 "%p targetname"								 " %p to %s %s",								 current_entry,								 targetname_config,								 targetname_config->								 TargetName,								 value ?								 "enabled" :								 "disabled");						} else {							logmsg(AS_ERROR,							       "error on line "							       "%d of %s, "							       "enabled does "							       "not apply to "							       "the current "							       "entry",							       line_number,							       pathname);						}					} else {						debugmsg(5,							 "config global "							 "targets %s",							 value ? "enabled" :							 "disabled");						config->defaults.enabled =						    value;					}				} else					logmsg(AS_ERROR,					       "error on line %d of %s, "					       "illegal value %s",					       line_number, pathname, str);			} else if ((strncasecmp(line, "Username=", 9) == 0) ||				 (strncasecmp(line, "UsernameOut=", 12) == 0) ||				 (strncasecmp(line, "OutgoingUsername=", 17) ==				  0)) {				/* Username string can be quoted */				char *u, *cp = &line[8];				/* find start of value */				while (*cp && *cp != '=') {					cp++;				}				u = parse_quoted_string(++cp);				if (current_entry) {					struct iscsi_auth_config *auth_options =					    entry_auth_options(current_entry);					if (auth_options) {						strncpy(auth_options->username,							u,							sizeof (auth_options->								username));						auth_options->						    username[sizeof							     (auth_options->							      username) - 1] =						    '\0';						debugmsg(5,							 "config entry %p "							 "outgoing username %s",							 current_entry,							 auth_options->							 username);					} else {						logmsg(AS_ERROR,						       "Invalid entry on line"						       " %d of %s,"						       " current entry cannot "						       "have an outgoing "						       "username, see man "						       "page of iscsi.conf",						       line_number, pathname);					}				} else {					/* default to use while processing the 					 * rest of the config file 					 */					strncpy(config->defaults.auth_options.						username, u,						sizeof (config->defaults.							auth_options.username));					config->defaults.auth_options.					    username[sizeof						     (config->defaults.						      auth_options.username) -						     1] = '\0';					debugmsg(5,						 "config global outgoing "						 "username %s",						 config->defaults.auth_options.						 username);				}			} else if ((strncasecmp(line, "UsernameIn=", 11) == 0)				   ||				   (strncasecmp(line, "IncomingUsername=", 17)				    == 0)) {				char *u, *cp = line + 10;				/* find start of value */				while (*cp && *cp != '=') {					cp++;				}				u = parse_quoted_string(++cp);				if (current_entry) {					struct iscsi_auth_config *auth_options =					    entry_auth_options(current_entry);					if (auth_options) {						strncpy(auth_options->							username_in, u,							sizeof (auth_options->								username_in));						auth_options->						    username_in[sizeof								(auth_options->								 username_in) -								1] = '\0';						debugmsg(5,							 "config entry %p "							 "incoming username %s",							 current_entry,							 auth_options->							 username_in);					} else {						logmsg(AS_ERROR,						       "Invalid entry on line"						       " %d of %s,"						       " current entry cannot "						       "have an incoming "						       "username, see "						       "man page of iscsi."						       "conf",						       line_number, pathname);					}				} else {					/* default to use while processing the 					 * rest of the config file 					 */					strncpy(config->defaults.auth_options.						username_in, u,						sizeof (config->defaults.							auth_options.							username_in));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -