[openib-general] [PATCH] CM: add invalid service ID handling

Sean Hefty sean.hefty at intel.com
Tue May 10 14:47:07 PDT 2005


>Patch to respond to invalid REQs (no listener) with a REJ message.

Thanks!  See updates below.

> static int __init ib_cm_init(void)
.
>+	cm.reject_handler = ib_create_cm_id(cm_reject_handler, NULL);
.
>+	cm.reject_handler->state = IB_CM_LISTEN;
>+	cm.reject_handler->service_id = 0;
>+	cm.reject_handler->service_mask = ~0ULL;

I don't think that these assignments are necessary.

>+error1:
>+	cm.reject_handler->state = IB_CM_IDLE;
>+	ib_destroy_cm_id(cm.reject_handler);
>+error2:
>+	destroy_workqueue(cm.wq);
> 	return ret;

I reversed the order of these labels to match other areas of the code.

Modified patch below.

- Sean



Index: cm.c
===================================================================
--- cm.c	(revision 2258)
+++ cm.c	(working copy)
@@ -70,6 +70,7 @@
 	struct rb_root remote_sidr_table;
 	struct idr local_id_table;
 	struct workqueue_struct *wq;
+	struct ib_cm_id *reject_cm_id;
 } cm;
 
 struct cm_port {
@@ -1048,12 +1049,9 @@
 	}
 	/* Find matching listen request. */
 	listen_cm_id_priv = cm_find_listen(req_msg->service_id);
-	if (!listen_cm_id_priv) {
-		spin_unlock_irqrestore(&cm.lock, flags);
-		/* todo: reject with no match */
-		ret = -EINVAL;
-		goto error1;
-	}
+	if (!listen_cm_id_priv)
+		listen_cm_id_priv = container_of(cm.reject_cm_id,
+						 struct cm_id_private, id);
 	atomic_inc(&listen_cm_id_priv->refcount);
 	atomic_inc(&cm_id_priv->refcount);
 	cm_id_priv->id.state = IB_CM_REQ_RCVD;
@@ -3024,6 +3022,12 @@
 	kfree(cm_dev);
 }
 
+static int cm_reject_handler(struct ib_cm_id *cm_id, struct ib_cm_event
*event)
+{
+	ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_SERVICE_ID, NULL, 0, NULL,
0);
+	return -1;
+}
+
 static int __init ib_cm_init(void)
 {
 	int ret;
@@ -3043,14 +3047,28 @@
 	if (!cm.wq)
 		return -ENOMEM;
 
+	cm.reject_cm_id = ib_create_cm_id(cm_reject_handler, NULL);
+	if (IS_ERR(cm.reject_cm_id)) {
+		ret = PTR_ERR(cm.reject_cm_id);
+		goto error1;
+	}
+
 	ret = ib_register_client(&cm_client);
 	if (ret)
-		destroy_workqueue(cm.wq);
+		goto error2;
+
+	return 0;
+error2:
+	ib_destroy_cm_id(cm.reject_cm_id);
+error1:
+	destroy_workqueue(cm.wq);
 	return ret;
 }
 
 static void __exit ib_cm_cleanup(void)
 {
+	ib_destroy_cm_id(cm.reject_cm_id);
+
 	flush_workqueue(cm.wq);
 	destroy_workqueue(cm.wq);
 	ib_unregister_client(&cm_client);






More information about the general mailing list