iscsi-scst: Add link_local parameter

Add a link_local parameter to control whether an IPv6 SendTargets
response includes link local addresses.  The default is to preserve
the existing behavior and include them.
This commit is contained in:
Brian Meagher
2024-04-22 10:21:15 +03:00
committed by Gleb Chesnokov
parent 7bec05916c
commit 659c7a7875
6 changed files with 43 additions and 0 deletions
+4
View File
@@ -200,6 +200,9 @@ is /sys/kernel/scst_tgt/targets/iscsi. It has the following entries:
iSCSI-SCST attributes before it starts accepting new connections. 0
by default.
- link_local - if set, makes the response to an IPv6 SendTargets include
any link local addresses. Default is set.
- open_state - read-only attribute, which allows to see if the user
space part of iSCSI-SCST connected to the kernel part.
@@ -663,6 +666,7 @@ both iSCSI-SCST targets will look like:
| | | |-- reinstating
| | | `-- sid
| | `-- tid
| |-- link_local
| |-- mgmt
| |-- open_state
| |-- trace_level
+27
View File
@@ -644,6 +644,16 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
goto out_free;
}
snprintf(res_str, sizeof(res_str), "%s", isns_entity_target_name);
} else if (strcasecmp(ISCSI_LINK_LOCAL_ATTR_NAME, pp) == 0) {
if (target != NULL) {
log_error("Not NULL target %s for global attribute %s",
target->name, pp);
res = -EINVAL;
goto out_free;
}
snprintf(res_str, sizeof(res_str), "%d\n", send_targets_link_local);
if (send_targets_link_local != DEFAULT_SEND_TARGETS_LINK_LOCAL)
add_key_mark(res_str, sizeof(res_str), 0);
} else {
log_error("Unknown attribute %s", pp);
res = -EINVAL;
@@ -1067,6 +1077,23 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
} else if (strcasecmp(ISCSI_ISNS_ENTITY_ATTR_NAME, pp) == 0) {
pp = config_sep_string(&p);
strlcpy(isns_entity_target_name, pp, sizeof(isns_entity_target_name));
} else if (strcasecmp(ISCSI_LINK_LOCAL_ATTR_NAME, pp) == 0) {
if (target != NULL) {
log_error("Not NULL target %s for global attribute %s",
target->name, pp);
res = -EINVAL;
goto out_free;
}
pp = config_sep_string(&p);
if (strcmp(pp, "1") == 0)
send_targets_link_local = 1;
else if (strcmp(pp, "0") == 0)
send_targets_link_local = 0;
else {
log_error("Unknown value %s", pp);
res = -EINVAL;
goto out_free;
}
} else {
log_error("Unknown attribute %s", pp);
res = -EINVAL;
+3
View File
@@ -961,6 +961,9 @@ int main(int argc, char **argv)
S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR, 0);
if (err != 0)
exit(err);
err = kernel_attr_add(NULL, ISCSI_LINK_LOCAL_ATTR_NAME, 0644, 0);
if (err != 0)
exit(err);
if ((ipc_fd = iscsi_adm_request_listen()) < 0) {
perror("Opening AF_LOCAL socket failed");
+2
View File
@@ -307,6 +307,8 @@ extern void session_free(struct session *session);
extern struct connection *conn_find(struct session *session, u16 cid);
/* target.c */
#define DEFAULT_SEND_TARGETS_LINK_LOCAL 1
extern int send_targets_link_local;
extern struct __qelem targets_list;
extern int target_create(const char *name, struct target **out_target);
extern void target_free(struct target *target);
+1
View File
@@ -26,6 +26,7 @@
#define ISCSI_TARGET_REDIRECTION_VALUE_TEMP "temp"
#define ISCSI_TARGET_REDIRECTION_VALUE_PERM "perm"
#define ISCSI_TARGET_ALIAS_ATTR_NAME "alias"
#define ISCSI_LINK_LOCAL_ATTR_NAME "link_local"
struct iscsi_key;
+6
View File
@@ -33,6 +33,8 @@
struct __qelem targets_list = LIST_HEAD_INIT(targets_list);
int send_targets_link_local = DEFAULT_SEND_TARGETS_LINK_LOCAL;
const char *iscsi_make_full_initiator_name(int per_portal_acl,
const char *initiator_name, const char *target_portal,
char *buf, int size)
@@ -204,6 +206,10 @@ static void target_print_addr(struct connection *conn, char *addr, int family)
{
char taddr[NI_MAXHOST + NI_MAXSERV + 5];
/* Maybe skip IPv6 link local addresses */
if (family == AF_INET6 && !send_targets_link_local && (strncasecmp(addr, "fe80:", 5) == 0))
return;
snprintf(taddr, sizeof(taddr),
(family == AF_INET) ? "%s:%d,1" : "[%s]:%d,1",
addr, server_port);