-int
-lnet_accept(lnet_ni_t *blind_ni, cfs_socket_t *sock, __u32 magic)
-{
- lnet_acceptor_connreq_t cr;
- __u32 peer_ip;
- int peer_port;
- int rc;
- int flip;
- lnet_ni_t *ni;
- char *str;
-
- /* CAVEAT EMPTOR: I may be called by an LND in any thread's context if
- * I passed the new socket "blindly" to the single NI that needed an
- * acceptor. If so, blind_ni != NULL... */
-
- LASSERT (sizeof(cr) <= 16); /* not too big for the stack */
-
- rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
- LASSERT (rc == 0); /* we succeeded before */
-
- if (!lnet_accept_magic(magic, LNET_PROTO_ACCEPTOR_MAGIC)) {
-
- if (lnet_accept_magic(magic, LNET_PROTO_MAGIC)) {
- /* future version compatibility!
- * When LNET unifies protocols over all LNDs, the first
- * thing sent will be a version query. I send back
- * LNET_PROTO_ACCEPTOR_MAGIC to tell her I'm "old" */
-
- memset (&cr, 0, sizeof(cr));
- cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC;
- cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
- rc = libcfs_sock_write(sock, &cr, sizeof(cr),
- accept_timeout);
-
- if (rc != 0)
- CERROR("Error sending magic+version in response"
- "to LNET magic from %u.%u.%u.%u: %d\n",
- HIPQUAD(peer_ip), rc);
- return -EPROTO;
- }
-
- if (magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC))
- str = "'old' socknal/tcpnal";
- else if (lnet_accept_magic(magic, LNET_PROTO_RA_MAGIC))
- str = "'old' ranal";
- else if (lnet_accept_magic(magic, LNET_PROTO_OPENIB_MAGIC))
- str = "'old' openibnal";
- else
- str = "unrecognised";
-
- LCONSOLE_ERROR("Refusing connection from %u.%u.%u.%u magic %08x: "
- " %s acceptor protocol\n",
- HIPQUAD(peer_ip), magic, str);
- return -EPROTO;
- }
-
- flip = (magic != LNET_PROTO_ACCEPTOR_MAGIC);
-
- rc = libcfs_sock_read(sock, &cr.acr_version,
- sizeof(cr.acr_version),
- accept_timeout);
- if (rc != 0) {
- CERROR("Error %d reading connection request version from "
- "%u.%u.%u.%u\n", rc, HIPQUAD(peer_ip));
- return -EIO;
- }
-
- if (flip)
- __swab32s(&cr.acr_version);
-
- if (cr.acr_version != LNET_PROTO_ACCEPTOR_VERSION) {
- /* future version compatibility!
- * An acceptor-specific protocol rev will first send a version
- * query. I send back my current version to tell her I'm
- * "old". */
- int peer_version = cr.acr_version;
-
- memset (&cr, 0, sizeof(cr));
- cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC;
- cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
-
- rc = libcfs_sock_write(sock, &cr, sizeof(cr),
- accept_timeout);
-
- if (rc != 0)
- CERROR("Error sending magic+version in response"
- "to version %d from %u.%u.%u.%u: %d\n",
- peer_version, HIPQUAD(peer_ip), rc);
- return -EPROTO;
- }
-
- rc = libcfs_sock_read(sock, &cr.acr_nid,
- sizeof(cr) -
- offsetof(lnet_acceptor_connreq_t, acr_nid),
- accept_timeout);
- if (rc != 0) {
- CERROR("Error %d reading connection request from "
- "%u.%u.%u.%u\n", rc, HIPQUAD(peer_ip));
- return -EIO;
- }
-
- if (flip)
- __swab64s(&cr.acr_nid);
-
- ni = lnet_net2ni(LNET_NIDNET(cr.acr_nid));
- if (ni == NULL || /* no matching net */
- ni->ni_nid != cr.acr_nid) { /* right NET, wrong NID! */
- if (ni != NULL)
- lnet_ni_decref(ni);
- LCONSOLE_ERROR("Refusing connection from %u.%u.%u.%u for %s: "
- " No matching NI\n",
- HIPQUAD(peer_ip), libcfs_nid2str(cr.acr_nid));
- return -EPERM;
- }
-
- if (ni->ni_lnd->lnd_accept == NULL) {
- /* This catches a request for the loopback LND */
- lnet_ni_decref(ni);
- LCONSOLE_ERROR("Refusing connection from %u.%u.%u.%u for %s: "
- " NI doesn not accept IP connections\n",
- HIPQUAD(peer_ip), libcfs_nid2str(cr.acr_nid));
- return -EPERM;
- }
-
- CDEBUG(D_NET, "Accept %s from %u.%u.%u.%u%s\n",
- libcfs_nid2str(cr.acr_nid), HIPQUAD(peer_ip),
- blind_ni == NULL ? "" : " (blind)");
-
- if (blind_ni == NULL) {
- /* called by the acceptor: call into the requested NI... */
- rc = ni->ni_lnd->lnd_accept(ni, sock);
- } else {
- /* portals_compatible set and the (only) NI called me to verify
- * and skip the connection request... */
- LASSERT (the_lnet.ln_ptlcompat != 0);
- LASSERT (ni == blind_ni);
- rc = 0;
- }
-
- lnet_ni_decref(ni);
- return rc;
+ if (magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC))
+ str = "'old' socknal/tcpnal";
+ else
+ str = "unrecognised";
+
+ LCONSOLE_ERROR_MSG(0x11f, "Refusing connection from %pI4h"
+ " magic %08x: %s acceptor protocol\n",
+ &peer_ip, magic, str);
+ return -EPROTO;
+ }
+
+ flip = (magic != LNET_PROTO_ACCEPTOR_MAGIC);
+
+ rc = lnet_sock_read(sock, &cr.acr_version,
+ sizeof(cr.acr_version),
+ accept_timeout);
+ if (rc != 0) {
+ CERROR("Error %d reading connection request version from "
+ "%pI4h\n", rc, &peer_ip);
+ return -EIO;
+ }
+
+ if (flip)
+ __swab32s(&cr.acr_version);
+
+ if (cr.acr_version != LNET_PROTO_ACCEPTOR_VERSION) {
+ /* future version compatibility!
+ * An acceptor-specific protocol rev will first send a version
+ * query. I send back my current version to tell her I'm
+ * "old". */
+ int peer_version = cr.acr_version;
+
+ memset(&cr, 0, sizeof(cr));
+ cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC;
+ cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
+
+ rc = lnet_sock_write(sock, &cr, sizeof(cr),
+ accept_timeout);
+
+ if (rc != 0)
+ CERROR("Error sending magic+version in response"
+ "to version %d from %pI4h: %d\n",
+ peer_version, &peer_ip, rc);
+ return -EPROTO;
+ }
+
+ rc = lnet_sock_read(sock, &cr.acr_nid,
+ sizeof(cr) -
+ offsetof(struct lnet_acceptor_connreq, acr_nid),
+ accept_timeout);
+ if (rc != 0) {
+ CERROR("Error %d reading connection request from "
+ "%pI4h\n", rc, &peer_ip);
+ return -EIO;
+ }
+
+ if (flip)
+ __swab64s(&cr.acr_nid);
+
+ ni = lnet_nid2ni_addref(cr.acr_nid);
+ if (ni == NULL || /* no matching net */
+ ni->ni_nid != cr.acr_nid) { /* right NET, wrong NID! */
+ if (ni != NULL)
+ lnet_ni_decref(ni);
+ LCONSOLE_ERROR_MSG(0x120, "Refusing connection from %pI4h "
+ "for %s: No matching NI\n",
+ &peer_ip, libcfs_nid2str(cr.acr_nid));
+ return -EPERM;
+ }
+
+ if (ni->ni_net->net_lnd->lnd_accept == NULL) {
+ /* This catches a request for the loopback LND */
+ lnet_ni_decref(ni);
+ LCONSOLE_ERROR_MSG(0x121, "Refusing connection from %pI4h "
+ "for %s: NI doesn not accept IP connections\n",
+ &peer_ip, libcfs_nid2str(cr.acr_nid));
+ return -EPERM;
+ }
+
+ CDEBUG(D_NET, "Accept %s from %pI4h\n",
+ libcfs_nid2str(cr.acr_nid), &peer_ip);
+
+ rc = ni->ni_net->net_lnd->lnd_accept(ni, sock);
+
+ lnet_ni_decref(ni);
+ return rc;