| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /******************************************************************************* |
|---|
| 2 | 3 | * This file contains the login functions used by the iSCSI Target driver. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
|---|
| 7 | 8 | * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | 9 | ******************************************************************************/ |
|---|
| 18 | 10 | |
|---|
| 19 | 11 | #include <crypto/hash.h> |
|---|
| .. | .. |
|---|
| 23 | 15 | #include <linux/sched/signal.h> |
|---|
| 24 | 16 | #include <linux/idr.h> |
|---|
| 25 | 17 | #include <linux/tcp.h> /* TCP_NODELAY */ |
|---|
| 18 | +#include <net/ip.h> |
|---|
| 26 | 19 | #include <net/ipv6.h> /* ipv6_addr_v4mapped() */ |
|---|
| 27 | 20 | #include <scsi/iscsi_proto.h> |
|---|
| 28 | 21 | #include <target/target_core_base.h> |
|---|
| .. | .. |
|---|
| 579 | 572 | } |
|---|
| 580 | 573 | |
|---|
| 581 | 574 | /* |
|---|
| 582 | | - * Check for any connection recovery entires containing CID. |
|---|
| 575 | + * Check for any connection recovery entries containing CID. |
|---|
| 583 | 576 | * We use the original ExpStatSN sent in the first login request |
|---|
| 584 | 577 | * to acknowledge commands for the failed connection. |
|---|
| 585 | 578 | * |
|---|
| .. | .. |
|---|
| 863 | 856 | struct sockaddr_storage *sockaddr) |
|---|
| 864 | 857 | { |
|---|
| 865 | 858 | struct socket *sock = NULL; |
|---|
| 866 | | - int backlog = ISCSIT_TCP_BACKLOG, ret, opt = 0, len; |
|---|
| 859 | + int backlog = ISCSIT_TCP_BACKLOG, ret, len; |
|---|
| 867 | 860 | |
|---|
| 868 | 861 | switch (np->np_network_transport) { |
|---|
| 869 | 862 | case ISCSI_TCP: |
|---|
| .. | .. |
|---|
| 883 | 876 | np->np_network_transport); |
|---|
| 884 | 877 | return -EINVAL; |
|---|
| 885 | 878 | } |
|---|
| 886 | | - |
|---|
| 887 | | - np->np_ip_proto = IPPROTO_TCP; |
|---|
| 888 | | - np->np_sock_type = SOCK_STREAM; |
|---|
| 889 | 879 | |
|---|
| 890 | 880 | ret = sock_create(sockaddr->ss_family, np->np_sock_type, |
|---|
| 891 | 881 | np->np_ip_proto, &sock); |
|---|
| .. | .. |
|---|
| 908 | 898 | /* |
|---|
| 909 | 899 | * Set SO_REUSEADDR, and disable Nagel Algorithm with TCP_NODELAY. |
|---|
| 910 | 900 | */ |
|---|
| 911 | | - /* FIXME: Someone please explain why this is endian-safe */ |
|---|
| 912 | | - opt = 1; |
|---|
| 913 | | - if (np->np_network_transport == ISCSI_TCP) { |
|---|
| 914 | | - ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, |
|---|
| 915 | | - (char *)&opt, sizeof(opt)); |
|---|
| 916 | | - if (ret < 0) { |
|---|
| 917 | | - pr_err("kernel_setsockopt() for TCP_NODELAY" |
|---|
| 918 | | - " failed: %d\n", ret); |
|---|
| 919 | | - goto fail; |
|---|
| 920 | | - } |
|---|
| 921 | | - } |
|---|
| 922 | | - |
|---|
| 923 | | - /* FIXME: Someone please explain why this is endian-safe */ |
|---|
| 924 | | - ret = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, |
|---|
| 925 | | - (char *)&opt, sizeof(opt)); |
|---|
| 926 | | - if (ret < 0) { |
|---|
| 927 | | - pr_err("kernel_setsockopt() for SO_REUSEADDR" |
|---|
| 928 | | - " failed\n"); |
|---|
| 929 | | - goto fail; |
|---|
| 930 | | - } |
|---|
| 931 | | - |
|---|
| 932 | | - ret = kernel_setsockopt(sock, IPPROTO_IP, IP_FREEBIND, |
|---|
| 933 | | - (char *)&opt, sizeof(opt)); |
|---|
| 934 | | - if (ret < 0) { |
|---|
| 935 | | - pr_err("kernel_setsockopt() for IP_FREEBIND" |
|---|
| 936 | | - " failed\n"); |
|---|
| 937 | | - goto fail; |
|---|
| 938 | | - } |
|---|
| 901 | + if (np->np_network_transport == ISCSI_TCP) |
|---|
| 902 | + tcp_sock_set_nodelay(sock->sk); |
|---|
| 903 | + sock_set_reuseaddr(sock->sk); |
|---|
| 904 | + ip_sock_set_freebind(sock->sk); |
|---|
| 939 | 905 | |
|---|
| 940 | 906 | ret = kernel_bind(sock, (struct sockaddr *)&np->np_sockaddr, len); |
|---|
| 941 | 907 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 1160 | 1126 | |
|---|
| 1161 | 1127 | if (!zalloc_cpumask_var(&conn->conn_cpumask, GFP_KERNEL)) { |
|---|
| 1162 | 1128 | pr_err("Unable to allocate conn->conn_cpumask\n"); |
|---|
| 1163 | | - goto free_mask; |
|---|
| 1129 | + goto free_conn_ops; |
|---|
| 1164 | 1130 | } |
|---|
| 1165 | 1131 | |
|---|
| 1166 | 1132 | return conn; |
|---|
| 1167 | 1133 | |
|---|
| 1168 | | -free_mask: |
|---|
| 1169 | | - free_cpumask_var(conn->conn_cpumask); |
|---|
| 1134 | +free_conn_ops: |
|---|
| 1135 | + kfree(conn->conn_ops); |
|---|
| 1170 | 1136 | put_transport: |
|---|
| 1171 | 1137 | iscsit_put_transport(conn->conn_transport); |
|---|
| 1172 | 1138 | free_conn: |
|---|