]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
iscsi-target: Refactor iscsit_get_np sockaddr matching into iscsit_check_np_match
authorNicholas Bellinger <nab@linux-iscsi.org>
Tue, 19 Feb 2013 04:59:27 +0000 (20:59 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 19 Feb 2013 05:03:33 +0000 (21:03 -0800)
This patch refactors the sockaddr matching logic in iscsit_get_np() into
a seperate iscsit_check_np_match() that can be used by external code.

Cc: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/iscsi/iscsi_target.c
drivers/target/iscsi/iscsi_target.h

index 339f97f7085b941ea4f2f92c3030b5fd1544c33f..23a98e6583064ddbfeddb392f6c7c8f356900298 100644 (file)
@@ -264,16 +264,50 @@ int iscsit_deaccess_np(struct iscsi_np *np, struct iscsi_portal_group *tpg)
        return 0;
 }
 
-static struct iscsi_np *iscsit_get_np(
+bool iscsit_check_np_match(
        struct __kernel_sockaddr_storage *sockaddr,
+       struct iscsi_np *np,
        int network_transport)
 {
        struct sockaddr_in *sock_in, *sock_in_e;
        struct sockaddr_in6 *sock_in6, *sock_in6_e;
-       struct iscsi_np *np;
-       int ip_match = 0;
+       bool ip_match = false;
        u16 port;
 
+       if (sockaddr->ss_family == AF_INET6) {
+               sock_in6 = (struct sockaddr_in6 *)sockaddr;
+               sock_in6_e = (struct sockaddr_in6 *)&np->np_sockaddr;
+
+               if (!memcmp(&sock_in6->sin6_addr.in6_u,
+                           &sock_in6_e->sin6_addr.in6_u,
+                           sizeof(struct in6_addr)))
+                       ip_match = true;
+
+               port = ntohs(sock_in6->sin6_port);
+       } else {
+               sock_in = (struct sockaddr_in *)sockaddr;
+               sock_in_e = (struct sockaddr_in *)&np->np_sockaddr;
+
+               if (sock_in->sin_addr.s_addr == sock_in_e->sin_addr.s_addr)
+                       ip_match = true;
+
+               port = ntohs(sock_in->sin_port);
+       }
+
+       if ((ip_match == true) && (np->np_port == port) &&
+           (np->np_network_transport == network_transport))
+               return true;
+
+       return false;
+}
+
+static struct iscsi_np *iscsit_get_np(
+       struct __kernel_sockaddr_storage *sockaddr,
+       int network_transport)
+{
+       struct iscsi_np *np;
+       bool match;
+
        spin_lock_bh(&np_lock);
        list_for_each_entry(np, &g_np_list, np_list) {
                spin_lock(&np->np_thread_lock);
@@ -282,29 +316,8 @@ static struct iscsi_np *iscsit_get_np(
                        continue;
                }
 
-               if (sockaddr->ss_family == AF_INET6) {
-                       sock_in6 = (struct sockaddr_in6 *)sockaddr;
-                       sock_in6_e = (struct sockaddr_in6 *)&np->np_sockaddr;
-
-                       if (!memcmp(&sock_in6->sin6_addr.in6_u,
-                                   &sock_in6_e->sin6_addr.in6_u,
-                                   sizeof(struct in6_addr)))
-                               ip_match = 1;
-
-                       port = ntohs(sock_in6->sin6_port);
-               } else {
-                       sock_in = (struct sockaddr_in *)sockaddr;
-                       sock_in_e = (struct sockaddr_in *)&np->np_sockaddr;
-
-                       if (sock_in->sin_addr.s_addr ==
-                           sock_in_e->sin_addr.s_addr)
-                               ip_match = 1;
-
-                       port = ntohs(sock_in->sin_port);
-               }
-
-               if ((ip_match == 1) && (np->np_port == port) &&
-                   (np->np_network_transport == network_transport)) {
+               match = iscsit_check_np_match(sockaddr, np, network_transport);
+               if (match == true) {
                        /*
                         * Increment the np_exports reference count now to
                         * prevent iscsit_del_np() below from being called
index f1e4f3155baca39328eee9c4763dab4431efd508..b1a1e63507070e7a3e06885febb4f52367f88c57 100644 (file)
@@ -8,6 +8,8 @@ extern struct iscsi_tiqn *iscsit_add_tiqn(unsigned char *);
 extern void iscsit_del_tiqn(struct iscsi_tiqn *);
 extern int iscsit_access_np(struct iscsi_np *, struct iscsi_portal_group *);
 extern int iscsit_deaccess_np(struct iscsi_np *, struct iscsi_portal_group *);
+extern bool iscsit_check_np_match(struct __kernel_sockaddr_storage *,
+                               struct iscsi_np *, int);
 extern struct iscsi_np *iscsit_add_np(struct __kernel_sockaddr_storage *,
                                char *, int);
 extern int iscsit_reset_np_thread(struct iscsi_np *, struct iscsi_tpg_np *,