Skip to content

Commit

Permalink
iscsi-scst: Add link_local parameter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bmeagherix authored and lnocturno committed Apr 22, 2024
1 parent 7bec059 commit 659c7a7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iscsi-scst/README
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -663,6 +666,7 @@ both iSCSI-SCST targets will look like:
| | | |-- reinstating
| | | `-- sid
| | `-- tid
| |-- link_local
| |-- mgmt
| |-- open_state
| |-- trace_level
Expand Down
27 changes: 27 additions & 0 deletions iscsi-scst/usr/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions iscsi-scst/usr/iscsi_scstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions iscsi-scst/usr/iscsid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions iscsi-scst/usr/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions iscsi-scst/usr/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 659c7a7

Please sign in to comment.