[ofa-general] ***SPAM*** [PATCH] ibsim/sim_mad.c: Better error handling in send_trap

Hal Rosenstock hnrose at comcast.net
Tue Mar 3 11:12:17 PST 2009


In send_trap, validate trap number prior to determining trap function 
Made trapnum parameter to send_trap unsigned
Also, removed unneeded enum init of NO_NODE in NODE_TYPES

Signed-off-by: Hal Rosenstock <hal.rosenstock at gmail.com>

---
diff --git a/ibsim/sim.h b/ibsim/sim.h
index f0e1e16..09812ba 100644
--- a/ibsim/sim.h
+++ b/ibsim/sim.h
@@ -72,7 +72,7 @@
 #define MAXHOPS 16
 
 enum NODE_TYPES {
-	NO_NODE = 0,
+	NO_NODE,
 	HCA_NODE,
 	SWITCH_NODE,
 	ROUTER_NODE,
@@ -289,7 +289,7 @@ void *sim_cmd_thread(void *file);
 
 // sim_mad.c
 int process_packet(Client * cl, void *p, int size, Client ** dcl);
-int send_trap(Port * port, int trapnum);
+int send_trap(Port * port, unsigned trapnum);
 
 extern Port *default_port;
 extern int simverb;
diff --git a/ibsim/sim_mad.c b/ibsim/sim_mad.c
index d73ce25..32a667e 100644
--- a/ibsim/sim_mad.c
+++ b/ibsim/sim_mad.c
@@ -1163,7 +1163,7 @@ int process_packet(Client * cl, void *p, int size, Client ** dcl)
 		return -1;
 
 	if (rpc.method == 0x7) {
-		IBWARN("got trap repress - drop");
+		IBWARN("lid %u got trap repress - dropping", ntohs(r->dlid));
 		*dcl = 0;
 		return 0;
 	}
@@ -1280,20 +1280,21 @@ static int encode_trap_header(char *buf)
 	return 0;
 }
 
-int send_trap(Port * port, int trapnum)
+int send_trap(Port * port, unsigned trapnum)
 {
 	struct sim_request req;
 	Client *cl;
 	int ret, lid = port->lid;
 	char *data = req.mad + 64;	/* data offset */
-	EncodeTrapfn *encode_trapfn = encodetrap[trapnum];
+	EncodeTrapfn *encode_trapfn;
 	Port *destport;
 
-	if (!encode_trapfn) {
+	if (trapnum >= TRAP_NUM_LAST) {
 		IBWARN("trap number %d not supported", trapnum);
 		return -1;
 	}
 
+	encode_trapfn = encodetrap[trapnum];
 	memset(req.mad, 0, sizeof(req.mad));
 	encode_trap_header(req.mad);
 	if (encode_trapfn(port, data) < 0)



More information about the general mailing list