2 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5 * Copyright (c) 2009 HNR Consulting. All rights reserved.
6 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 * Implementation of osm_infr_rcv_t.
41 * This object represents the InformInfo Receiver object.
42 * This object is part of the opensm family of objects.
47 #endif /* HAVE_CONFIG_H */
50 #include <iba/ib_types.h>
51 #include <arpa/inet.h>
52 #include <sys/socket.h>
53 #include <complib/cl_qmap.h>
54 #include <complib/cl_passivelock.h>
55 #include <complib/cl_debug.h>
56 #include <complib/cl_qlist.h>
57 #include <opensm/osm_file_ids.h>
58 #define FILE_ID OSM_FILE_SA_INFORMINFO_C
59 #include <vendor/osm_vendor_api.h>
60 #include <opensm/osm_port.h>
61 #include <opensm/osm_node.h>
62 #include <opensm/osm_switch.h>
63 #include <opensm/osm_helper.h>
64 #include <opensm/osm_sa.h>
65 #include <opensm/osm_inform.h>
66 #include <opensm/osm_pkey.h>
68 #define SA_IIR_RESP_SIZE SA_ITEM_RESP_SIZE(inform_rec)
69 #define SA_II_RESP_SIZE SA_ITEM_RESP_SIZE(inform)
71 typedef struct osm_iir_search_ctxt {
72 const ib_inform_info_record_t *p_rcvd_rec;
75 ib_gid_t subscriber_gid;
76 ib_net16_t subscriber_enum;
78 osm_physp_t *p_req_physp;
80 } osm_iir_search_ctxt_t;
82 /**********************************************************************
83 o13-14.1.1: Except for Set(InformInfo) requests with Inform-
84 Info:LIDRangeBegin=0xFFFF, managers that support event forwarding
85 shall, upon receiving a Set(InformInfo), verify that the requester
86 originating the Set(InformInfo) and a Trap() source identified by Inform-
87 can access each other - can use path record to verify that.
88 **********************************************************************/
89 static boolean_t validate_ports_access_rights(IN osm_sa_t * sa,
90 IN osm_infr_t * p_infr_rec)
92 boolean_t valid = TRUE;
93 osm_physp_t *p_requester_physp;
96 uint16_t lid_range_begin, lid_range_end, lid;
98 OSM_LOG_ENTER(sa->p_log);
100 /* get the requester physp from the request address */
101 p_requester_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
102 &p_infr_rec->report_addr);
104 if (ib_gid_is_notzero(&p_infr_rec->inform_record.inform_info.gid)) {
105 /* a gid is defined */
107 p_infr_rec->inform_record.inform_info.gid.unicast.
110 p_port = osm_get_port_by_guid(sa->p_subn, portguid);
111 if (p_port == NULL) {
112 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4301: "
113 "Invalid port guid: 0x%016" PRIx64 "\n",
114 cl_ntoh64(portguid));
119 /* make sure that the requester and destination port can access
120 each other according to the current partitioning. */
121 if (!osm_physp_share_pkey
122 (sa->p_log, p_port->p_physp, p_requester_physp,
123 sa->p_subn->opt.allow_both_pkeys)) {
124 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
125 "port and requester don't share pkey\n");
132 /* gid is zero - check if LID range is defined */
134 cl_ntoh16(p_infr_rec->inform_record.inform_info.
136 /* if lid is 0xFFFF - meaning all endports managed by the manager */
137 if (lid_range_begin == 0xFFFF)
141 cl_ntoh16(p_infr_rec->inform_record.inform_info.
144 lids_size = cl_ptr_vector_get_size(&sa->p_subn->port_lid_tbl);
146 /* lid_range_end is set to zero if no range desired. In this
147 case - just make it equal to the lid_range_begin. */
148 if (lid_range_end == 0)
149 lid_range_end = lid_range_begin;
150 else if (lid_range_end >= lids_size)
151 lid_range_end = lids_size - 1;
153 if (lid_range_begin >= lids_size) {
154 /* requested lids are out of range */
155 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4302: "
156 "Given LIDs (%u-%u) are out of range (%zu)\n",
157 lid_range_begin, lid_range_end, lids_size);
162 /* go over all defined lids within the range and make sure that the
163 requester port can access them according to current partitioning. */
164 for (lid = lid_range_begin; lid <= lid_range_end; lid++) {
165 p_port = osm_get_port_by_lid_ho(sa->p_subn, lid);
169 /* make sure that the requester and destination port can access
170 each other according to the current partitioning. */
171 if (!osm_physp_share_pkey
172 (sa->p_log, p_port->p_physp, p_requester_physp,
173 sa->p_subn->opt.allow_both_pkeys)) {
174 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
175 "port and requester don't share pkey\n");
183 OSM_LOG_EXIT(sa->p_log);
187 static boolean_t validate_infr(IN osm_sa_t * sa, IN osm_infr_t * p_infr_rec)
189 boolean_t valid = TRUE;
191 OSM_LOG_ENTER(sa->p_log);
193 valid = validate_ports_access_rights(sa, p_infr_rec);
195 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
196 "Invalid Access for InformInfo\n");
200 OSM_LOG_EXIT(sa->p_log);
204 /**********************************************************************
205 o13-12.1.1: Confirm a valid request for event subscription by responding
206 with an InformInfo attribute that is a copy of the data in the
207 Set(InformInfo) request.
208 **********************************************************************/
209 static void infr_rcv_respond(IN osm_sa_t * sa, IN osm_madw_t * p_madw)
214 OSM_LOG_ENTER(sa->p_log);
216 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
217 "Generating successful InformInfo response\n");
219 item = malloc(SA_II_RESP_SIZE);
221 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4303: "
222 "rec_item alloc failed\n");
226 memcpy(&item->resp.inform,
227 ib_sa_mad_get_payload_ptr(osm_madw_get_sa_mad_ptr(p_madw)),
228 sizeof(ib_inform_info_t));
230 cl_qlist_init(&rec_list);
231 cl_qlist_insert_tail(&rec_list, &item->list_item);
233 osm_sa_respond(sa, p_madw, sizeof(ib_inform_info_t), &rec_list);
236 OSM_LOG_EXIT(sa->p_log);
239 static void sa_inform_info_rec_by_comp_mask(IN osm_sa_t * sa,
240 IN const osm_infr_t * p_infr,
241 osm_iir_search_ctxt_t * p_ctxt)
243 ib_net64_t comp_mask;
245 osm_port_t *p_subscriber_port;
246 osm_physp_t *p_subscriber_physp;
247 const osm_physp_t *p_req_physp;
248 osm_sa_item_t *p_rec_item;
250 OSM_LOG_ENTER(sa->p_log);
252 comp_mask = p_ctxt->comp_mask;
253 p_req_physp = p_ctxt->p_req_physp;
255 if (comp_mask & IB_IIR_COMPMASK_SUBSCRIBERGID &&
256 memcmp(&p_infr->inform_record.subscriber_gid,
257 &p_ctxt->subscriber_gid,
258 sizeof(p_infr->inform_record.subscriber_gid)))
261 if (comp_mask & IB_IIR_COMPMASK_ENUM &&
262 p_infr->inform_record.subscriber_enum != p_ctxt->subscriber_enum)
265 /* Implement any other needed search cases */
267 /* Ensure pkey is shared before returning any records */
268 portguid = p_infr->inform_record.subscriber_gid.unicast.interface_id;
269 p_subscriber_port = osm_get_port_by_guid(sa->p_subn, portguid);
270 if (p_subscriber_port == NULL) {
271 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 430D: "
272 "Invalid subscriber port guid: 0x%016" PRIx64 "\n",
273 cl_ntoh64(portguid));
277 /* get the subscriber InformInfo physical port */
278 p_subscriber_physp = p_subscriber_port->p_physp;
279 /* make sure that the requester and subscriber port can access each
280 other according to the current partitioning. */
281 if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_subscriber_physp,
282 sa->p_subn->opt.allow_both_pkeys)) {
283 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
284 "requester and subscriber ports don't share pkey\n");
288 p_rec_item = malloc(SA_IIR_RESP_SIZE);
289 if (p_rec_item == NULL) {
290 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 430E: "
291 "rec_item alloc failed\n");
295 memcpy(&p_rec_item->resp.inform_rec, &p_infr->inform_record,
296 sizeof(ib_inform_info_record_t));
299 * Per C15-0.2-1.16, InformInfoRecords shall always be
300 * provided with the QPN set to 0, except for the case
301 * of a trusted request, in which case the actual
302 * subscriber QPN shall be returned.
304 if (p_ctxt->sm_key == 0)
305 ib_inform_info_set_qpn(&p_rec_item->resp.inform_rec.inform_info, 0);
307 cl_qlist_insert_tail(p_ctxt->p_list, &p_rec_item->list_item);
310 OSM_LOG_EXIT(sa->p_log);
313 static void sa_inform_info_rec_by_comp_mask_cb(IN cl_list_item_t * p_list_item,
316 const osm_infr_t *p_infr = (osm_infr_t *) p_list_item;
317 osm_iir_search_ctxt_t *p_ctxt = context;
319 sa_inform_info_rec_by_comp_mask(p_ctxt->sa, p_infr, p_ctxt);
322 /**********************************************************************
323 Received a Get(InformInfoRecord) or GetTable(InformInfoRecord) MAD
324 **********************************************************************/
325 static void infr_rcv_process_get_method(osm_sa_t * sa, IN osm_madw_t * p_madw)
327 char gid_str[INET6_ADDRSTRLEN];
328 ib_sa_mad_t *p_rcvd_mad;
329 const ib_inform_info_record_t *p_rcvd_rec;
331 osm_iir_search_ctxt_t context;
332 osm_physp_t *p_req_physp;
335 OSM_LOG_ENTER(sa->p_log);
338 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
340 (ib_inform_info_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
342 cl_plock_acquire(sa->p_lock);
344 /* update the requester physical port */
345 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
346 osm_madw_get_mad_addr_ptr
348 if (p_req_physp == NULL) {
349 cl_plock_release(sa->p_lock);
350 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4309: "
351 "Cannot find requester physical port\n");
355 if (OSM_LOG_IS_ACTIVE_V2(sa->p_log, OSM_LOG_DEBUG)) {
356 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
357 "Requester port GUID 0x%" PRIx64 "\n",
358 cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
359 osm_dump_inform_info_record_v2(sa->p_log, p_rcvd_rec,
360 FILE_ID, OSM_LOG_DEBUG);
363 cl_qlist_init(&rec_list);
365 context.p_rcvd_rec = p_rcvd_rec;
366 context.p_list = &rec_list;
367 context.comp_mask = p_rcvd_mad->comp_mask;
368 context.subscriber_gid = p_rcvd_rec->subscriber_gid;
369 context.subscriber_enum = p_rcvd_rec->subscriber_enum;
371 context.p_req_physp = p_req_physp;
372 context.sm_key = p_rcvd_mad->sm_key;
374 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
375 "Query Subscriber GID:%s(%02X) Enum:0x%X(%02X)\n",
376 inet_ntop(AF_INET6, p_rcvd_rec->subscriber_gid.raw,
377 gid_str, sizeof gid_str),
378 (p_rcvd_mad->comp_mask & IB_IIR_COMPMASK_SUBSCRIBERGID) != 0,
379 cl_ntoh16(p_rcvd_rec->subscriber_enum),
380 (p_rcvd_mad->comp_mask & IB_IIR_COMPMASK_ENUM) != 0);
382 cl_qlist_apply_func(&sa->p_subn->sa_infr_list,
383 sa_inform_info_rec_by_comp_mask_cb, &context);
385 /* clear reserved and pad fields in InformInfoRecord */
386 for (item = (osm_sa_item_t *) cl_qlist_head(&rec_list);
387 item != (osm_sa_item_t *) cl_qlist_end(&rec_list);
388 item = (osm_sa_item_t *) cl_qlist_next(&item->list_item)) {
389 memset(item->resp.inform_rec.reserved, 0, sizeof(item->resp.inform_rec.reserved));
390 memset(item->resp.inform_rec.pad, 0, sizeof(item->resp.inform_rec.pad));
393 cl_plock_release(sa->p_lock);
395 osm_sa_respond(sa, p_madw, sizeof(ib_inform_info_record_t), &rec_list);
398 OSM_LOG_EXIT(sa->p_log);
401 /*********************************************************************
402 Received a Set(InformInfo) MAD
403 **********************************************************************/
404 static void infr_rcv_process_set_method(osm_sa_t * sa, IN osm_madw_t * p_madw)
406 ib_sa_mad_t *p_sa_mad;
407 ib_inform_info_t *p_recvd_inform_info;
408 osm_infr_t inform_info_rec; /* actual inform record to be stored for reports */
411 uint8_t resp_time_val;
414 OSM_LOG_ENTER(sa->p_log);
418 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
419 p_recvd_inform_info =
420 (ib_inform_info_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
423 if (OSM_LOG_IS_ACTIVE_V2(sa->p_log, OSM_LOG_DEBUG))
424 osm_dump_inform_info_v2(sa->p_log, p_recvd_inform_info,
425 FILE_ID, OSM_LOG_DEBUG);
429 cl_plock_excl_acquire(sa->p_lock);
431 /* define the inform record */
432 inform_info_rec.inform_record.inform_info = *p_recvd_inform_info;
434 /* following C13-32.1.2 Tbl 120: we only copy the source address vector */
435 inform_info_rec.report_addr = p_madw->mad_addr;
437 /* we will need to know the mad srvc to send back through */
438 inform_info_rec.h_bind = p_madw->h_bind;
439 inform_info_rec.sa = sa;
441 /* update the subscriber GID according to mad address */
442 res = osm_get_gid_by_mad_addr(sa->p_log, sa->p_subn, &p_madw->mad_addr,
443 &inform_info_rec.inform_record.
445 if (res != IB_SUCCESS) {
446 cl_plock_release(sa->p_lock);
448 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4308: "
449 "Subscribe Request from unknown LID: %u\n",
450 cl_ntoh16(p_madw->mad_addr.dest_lid));
451 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_REQ_INVALID);
455 /* HACK: enum is always 0 (currently) */
456 inform_info_rec.inform_record.subscriber_enum = 0;
458 /* Subscribe values above 1 are undefined */
459 if (p_recvd_inform_info->subscribe > 1) {
460 cl_plock_release(sa->p_lock);
462 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 430A: "
463 "Invalid subscribe: %d\n",
464 p_recvd_inform_info->subscribe);
465 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_REQ_INVALID);
470 * Per C15-0.2-1.16, SubnAdmSet(InformInfo) subscriptions for
471 * SM security traps shall be provided only if they come from a
474 if ((p_sa_mad->sm_key == 0) && p_recvd_inform_info->is_generic &&
475 ((cl_ntoh16(p_recvd_inform_info->g_or_v.generic.trap_num) >= SM_BAD_MKEY_TRAP) &&
476 (cl_ntoh16(p_recvd_inform_info->g_or_v.generic.trap_num) <= SM_BAD_SWITCH_PKEY_TRAP))) {
477 cl_plock_release(sa->p_lock);
479 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 430B "
480 "Request for security trap from non-trusted requester: "
481 "Given SM_Key:0x%016" PRIx64 "\n",
482 cl_ntoh64(p_sa_mad->sm_key));
483 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_REQ_INVALID);
488 * MODIFICATIONS DONE ON INCOMING REQUEST:
491 * Internally we keep the QPN field of the InformInfo updated
492 * so we can simply compare it in the record - when finding such.
494 if (p_recvd_inform_info->subscribe) {
495 ib_inform_info_set_qpn(&inform_info_rec.inform_record.
497 inform_info_rec.report_addr.addr_type.
500 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
501 "Subscribe Request with QPN: 0x%06X\n",
502 cl_ntoh32(inform_info_rec.report_addr.addr_type.gsi.
505 ib_inform_info_get_qpn_resp_time(p_recvd_inform_info->g_or_v.
506 generic.qpn_resp_time_val,
507 &qpn, &resp_time_val);
509 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
510 "UnSubscribe Request with QPN: 0x%06X\n",
514 /* If record exists with matching InformInfo */
515 p_infr = osm_infr_get_by_rec(sa->p_subn, sa->p_log, &inform_info_rec);
517 /* check to see if the request was for subscribe */
518 if (p_recvd_inform_info->subscribe) {
519 /* validate the request for a new or update InformInfo */
520 if (validate_infr(sa, &inform_info_rec) != TRUE) {
521 cl_plock_release(sa->p_lock);
523 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4305: "
524 "Failed to validate a new inform object\n");
526 /* o13-13.1.1: we need to set the subscribe bit to 0 */
527 p_recvd_inform_info->subscribe = 0;
528 osm_sa_send_error(sa, p_madw,
529 IB_SA_MAD_STATUS_REQ_INVALID);
533 /* ok - we can try and create a new entry */
534 if (p_infr == NULL) {
535 /* Create the instance of the osm_infr_t object */
536 p_infr = osm_infr_new(&inform_info_rec);
537 if (p_infr == NULL) {
538 cl_plock_release(sa->p_lock);
540 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4306: "
541 "Failed to create a new inform object\n");
543 /* o13-13.1.1: we need to set the subscribe bit to 0 */
544 p_recvd_inform_info->subscribe = 0;
545 osm_sa_send_error(sa, p_madw,
546 IB_SA_MAD_STATUS_NO_RESOURCES);
550 OSM_LOG(sa->p_log, OSM_LOG_VERBOSE,
551 "Adding event subscription for port 0x%" PRIx64 "\n",
552 cl_ntoh64(inform_info_rec.inform_record.subscriber_gid.unicast.interface_id));
554 /* Add this new osm_infr_t object to subnet object */
555 osm_infr_insert_to_db(sa->p_subn, sa->p_log, p_infr);
557 /* Update the old instance of the osm_infr_t object */
558 p_infr->inform_record = inform_info_rec.inform_record;
559 /* We got an UnSubscribe request */
560 } else if (p_infr == NULL) {
561 cl_plock_release(sa->p_lock);
563 /* No Such Item - So Error */
564 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4307: "
565 "Failed to UnSubscribe to non existing inform object\n");
567 /* o13-13.1.1: we need to set the subscribe bit to 0 */
568 p_recvd_inform_info->subscribe = 0;
569 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_REQ_INVALID);
572 /* Delete this object from the subnet list of informs */
573 OSM_LOG(sa->p_log, OSM_LOG_VERBOSE,
574 "Removing event subscription for port 0x%" PRIx64 "\n",
575 cl_ntoh64(inform_info_rec.inform_record.subscriber_gid.unicast.interface_id));
576 osm_infr_remove_from_db(sa->p_subn, sa->p_log, p_infr);
579 cl_plock_release(sa->p_lock);
581 /* send the success response */
582 infr_rcv_respond(sa, p_madw);
585 OSM_LOG_EXIT(sa->p_log);
588 void osm_infr_rcv_process(IN void *context, IN void *data)
590 osm_sa_t *sa = context;
591 osm_madw_t *p_madw = data;
592 ib_sa_mad_t *p_sa_mad;
594 OSM_LOG_ENTER(sa->p_log);
598 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
600 CL_ASSERT(p_sa_mad->attr_id == IB_MAD_ATTR_INFORM_INFO);
602 if (p_sa_mad->method != IB_MAD_METHOD_SET) {
603 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
604 "Unsupported Method (%s) for InformInfo\n",
605 ib_get_sa_method_str(p_sa_mad->method));
606 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
610 infr_rcv_process_set_method(sa, p_madw);
613 OSM_LOG_EXIT(sa->p_log);
616 void osm_infir_rcv_process(IN void *context, IN void *data)
618 osm_sa_t *sa = context;
619 osm_madw_t *p_madw = data;
620 ib_sa_mad_t *p_sa_mad;
622 OSM_LOG_ENTER(sa->p_log);
626 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
628 CL_ASSERT(p_sa_mad->attr_id == IB_MAD_ATTR_INFORM_INFO_RECORD);
630 if (p_sa_mad->method != IB_MAD_METHOD_GET &&
631 p_sa_mad->method != IB_MAD_METHOD_GETTABLE) {
632 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
633 "Unsupported Method (%s) for InformInfoRecord\n",
634 ib_get_sa_method_str(p_sa_mad->method));
635 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
639 infr_rcv_process_get_method(sa, p_madw);
642 OSM_LOG_EXIT(sa->p_log);