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

William Jordan bjordan.ics at gmail.com
Tue May 10 12:57:50 PDT 2005


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

Signed-off-by: Bill Jordan <bjordan at infinicon.com>

Index: cm.c
===================================================================
--- cm.c	(revision 2293)
+++ cm.c	(working copy)
@@ -70,6 +70,7 @@ static struct ib_cm {
 	struct rb_root remote_sidr_table;
 	struct idr local_id_table;
 	struct workqueue_struct *wq;
+	struct ib_cm_id *reject_handler;
 } cm;
 
 struct cm_port {
@@ -1049,10 +1050,7 @@ static int cm_req_handler(struct cm_work
 	/* 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;
+		listen_cm_id_priv = container_of(cm.reject_handler, struct
cm_id_private, id);
 	}
 	atomic_inc(&listen_cm_id_priv->refcount);
 	atomic_inc(&cm_id_priv->refcount);
@@ -3024,6 +3022,12 @@ static void cm_remove_one(struct ib_devi
 	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,32 @@ static int __init ib_cm_init(void)
 	if (!cm.wq)
 		return -ENOMEM;
 
+	cm.reject_handler = ib_create_cm_id(cm_reject_handler, NULL);
+	if (IS_ERR(cm.reject_handler)) {
+		ret = PTR_ERR(cm.reject_handler);
+		goto error2;
+	}
+	cm.reject_handler->state = IB_CM_LISTEN;
+	cm.reject_handler->service_id = 0;
+	cm.reject_handler->service_mask = ~0ULL;
+
 	ret = ib_register_client(&cm_client);
-	if (ret)
-		destroy_workqueue(cm.wq);
+	if (ret) goto error1;
+
+	return 0;
+error1:
+	cm.reject_handler->state = IB_CM_IDLE;
+	ib_destroy_cm_id(cm.reject_handler);
+error2:
+	destroy_workqueue(cm.wq);
 	return ret;
 }
 
 static void __exit ib_cm_cleanup(void)
 {
+	cm.reject_handler->state = IB_CM_IDLE;
+	ib_destroy_cm_id(cm.reject_handler);
+
 	flush_workqueue(cm.wq);
 	destroy_workqueue(cm.wq);
 	ib_unregister_client(&cm_client);



More information about the general mailing list