1 /* 2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * BSD 3 Clause License 8 * 9 * Copyright (c) 2007, The Storage Networking Industry Association. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * - Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 17 * - Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * 22 * - Neither the name of The Storage Networking Industry Association (SNIA) 23 * nor the names of its contributors may be used to endorse or promote 24 * products derived from this software without specific prior written 25 * permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */ 40 /* 41 * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 42 */ 43 44 #include <sys/note.h> 45 #include "ndmpd.h" 46 47 /* 48 * The following macros construct the message handler. 49 * ver is the suffix used to construct the handler name. 50 * mver is the suffix used to construct the structure name. 51 * ver and mver are not necessarily the same, specially when 52 * there are different structures and there is one handler 53 * for all of them. 54 */ 55 56 /* 57 * The handler function 58 * The request and reply XDR function 59 * The request and reply sizes 60 */ 61 #define HANDL(cmd, ver, mver) \ 62 { \ 63 ndmpd_##cmd##_v##ver, \ 64 XDR_AND_SIZE(ndmp_##cmd##_request_v##mver), \ 65 XDR_AND_SIZE(ndmp_##cmd##_reply_v##mver), \ 66 } 67 68 /* 69 * No handler function 70 * The request XDR function 71 * The request size 72 */ 73 #define HANDL_RQ(cmd, mver) \ 74 { \ 75 0, \ 76 XDR_AND_SIZE(ndmp_##cmd##_request_v##mver), \ 77 0, 0, \ 78 } 79 80 /* 81 * The handler function 82 * The reply XDR function 83 * The reply size 84 */ 85 #define HANDL_RS(cmd, ver, mver) \ 86 { \ 87 ndmpd_##cmd##_v##ver, \ 88 0, 0, \ 89 XDR_AND_SIZE(ndmp_##cmd##_reply_v##mver), \ 90 } 91 92 /* 93 * The handler function 94 * No reply XDR function 95 * No reply size 96 */ 97 #define HANDL_NONE(cmd, ver) \ 98 { \ 99 ndmpd_##cmd##_v##ver, \ 100 0, 0, \ 101 0, 0, \ 102 } 103 104 /* 105 * No handler for this entry 106 */ 107 #define HANDL_NULL \ 108 { \ 109 0, \ 110 0, 0, \ 111 0, 0, \ 112 } 113 114 /* 115 * LINT does not like this table as it references 116 * XDR functions from ndmp_xdr.c which is not included 117 * for LINT. 118 */ 119 #ifndef lint 120 ndmp_handler_t ndmp_msghdl_tab[] = { 121 { 122 /* NONE - 0x000 */ 123 0, 124 { 125 { 126 0, 127 AUTH_NOT_REQUIRED, 128 { 129 HANDL_NULL, 130 HANDL_NULL, 131 HANDL_NULL, 132 } 133 } 134 } 135 }, 136 { 137 /* CONFIG - 0x100 */ 138 11, 139 { 140 { 141 NDMP_CONFIG_GET_HOST_INFO, 142 AUTH_REQUIRED, 143 { 144 HANDL_RS(config_get_host_info, 2, 2), 145 HANDL_RS(config_get_host_info, 3, 3), 146 HANDL_RS(config_get_host_info, 3, 4), 147 } 148 }, 149 { 150 NDMP_CONFIG_GET_BUTYPE_ATTR, 151 AUTH_NOT_REQUIRED, 152 { 153 HANDL(config_get_butype_attr, 2, 2), 154 HANDL_NULL, 155 HANDL_NULL, 156 } 157 }, 158 { 159 NDMP_CONFIG_GET_CONNECTION_TYPE, 160 AUTH_REQUIRED, 161 { 162 HANDL_RS(config_get_mover_type, 2, 2), 163 HANDL_RS(config_get_connection_type, 3, 3), 164 HANDL_RS(config_get_connection_type, 3, 4), 165 } 166 }, 167 { 168 NDMP_CONFIG_GET_AUTH_ATTR, 169 AUTH_NOT_REQUIRED, 170 { 171 HANDL(config_get_auth_attr, 2, 2), 172 HANDL(config_get_auth_attr, 3, 3), 173 HANDL(config_get_auth_attr, 3, 4), 174 } 175 }, 176 { 177 NDMP_CONFIG_GET_BUTYPE_INFO, 178 AUTH_REQUIRED, 179 { 180 HANDL_NULL, 181 HANDL_RS(config_get_butype_info, 3, 3), 182 HANDL_RS(config_get_butype_info, 4, 4), 183 } 184 }, 185 { 186 NDMP_CONFIG_GET_FS_INFO, 187 AUTH_REQUIRED, 188 { 189 HANDL_NULL, 190 HANDL_RS(config_get_fs_info, 3, 3), 191 HANDL_RS(config_get_fs_info, 3, 4), 192 } 193 }, 194 { 195 NDMP_CONFIG_GET_TAPE_INFO, 196 AUTH_REQUIRED, 197 { 198 HANDL_NULL, 199 HANDL_RS(config_get_tape_info, 3, 3), 200 HANDL_RS(config_get_tape_info, 3, 4), 201 } 202 }, 203 { 204 NDMP_CONFIG_GET_SCSI_INFO, 205 AUTH_REQUIRED, 206 { 207 HANDL_NULL, 208 HANDL_RS(config_get_scsi_info, 3, 3), 209 HANDL_RS(config_get_scsi_info, 3, 4), 210 } 211 }, 212 { 213 NDMP_CONFIG_GET_SERVER_INFO, 214 AUTH_NOT_REQUIRED, 215 { 216 HANDL_NULL, 217 HANDL_RS(config_get_server_info, 3, 3), 218 HANDL_RS(config_get_server_info, 3, 4), 219 } 220 }, 221 { 222 NDMP_CONFIG_SET_EXT_LIST, 223 AUTH_REQUIRED, 224 { 225 HANDL_NULL, 226 HANDL_NULL, 227 HANDL(config_set_ext_list, 4, 4), 228 } 229 }, 230 { 231 NDMP_CONFIG_GET_EXT_LIST, 232 AUTH_REQUIRED, 233 { 234 HANDL_NULL, 235 HANDL_NULL, 236 HANDL_RS(config_get_ext_list, 4, 4), 237 } 238 } 239 } 240 }, 241 { 242 /* SCSI - 0x200 */ 243 7, 244 { 245 { 246 NDMP_SCSI_OPEN, 247 AUTH_REQUIRED, 248 { 249 HANDL(scsi_open, 2, 2), 250 HANDL(scsi_open, 3, 3), 251 HANDL(scsi_open, 3, 4), 252 } 253 }, 254 { 255 NDMP_SCSI_CLOSE, 256 AUTH_REQUIRED, 257 { 258 HANDL_RS(scsi_close, 2, 2), 259 HANDL_RS(scsi_close, 2, 3), 260 HANDL_RS(scsi_close, 2, 4), 261 } 262 }, 263 { 264 NDMP_SCSI_GET_STATE, 265 AUTH_REQUIRED, 266 { 267 HANDL_RS(scsi_get_state, 2, 2), 268 HANDL_RS(scsi_get_state, 2, 3), 269 HANDL_RS(scsi_get_state, 2, 4), 270 } 271 }, 272 { 273 NDMP_SCSI_SET_TARGET, 274 AUTH_REQUIRED, 275 { 276 HANDL(scsi_set_target, 2, 2), 277 HANDL(scsi_set_target, 3, 3), 278 HANDL_NULL, 279 } 280 }, 281 { 282 NDMP_SCSI_RESET_DEVICE, 283 AUTH_REQUIRED, 284 { 285 HANDL_RS(scsi_reset_device, 2, 2), 286 HANDL_RS(scsi_reset_device, 2, 3), 287 HANDL_RS(scsi_reset_device, 2, 4), 288 } 289 }, 290 { 291 NDMP_SCSI_RESET_BUS, 292 AUTH_REQUIRED, 293 { 294 HANDL_RS(scsi_reset_bus, 2, 2), 295 HANDL_RS(scsi_reset_bus, 2, 3), 296 HANDL_NULL, 297 } 298 }, 299 { 300 NDMP_SCSI_EXECUTE_CDB, 301 AUTH_REQUIRED, 302 { 303 HANDL(scsi_execute_cdb, 2, 2), 304 HANDL(scsi_execute_cdb, 2, 3), 305 HANDL(scsi_execute_cdb, 2, 4), 306 } 307 } 308 } 309 }, 310 { 311 /* TAPE - 0x300 */ 312 8, 313 { 314 { 315 NDMP_TAPE_OPEN, 316 AUTH_REQUIRED, 317 { 318 HANDL(tape_open, 2, 2), 319 HANDL(tape_open, 3, 3), 320 HANDL(tape_open, 3, 4), 321 } 322 }, 323 { 324 NDMP_TAPE_CLOSE, 325 AUTH_REQUIRED, 326 { 327 HANDL_RS(tape_close, 2, 2), 328 HANDL_RS(tape_close, 2, 3), 329 HANDL_RS(tape_close, 4, 4), 330 } 331 }, 332 { 333 NDMP_TAPE_GET_STATE, 334 AUTH_REQUIRED, 335 { 336 HANDL_RS(tape_get_state, 2, 2), 337 HANDL_RS(tape_get_state, 3, 3), 338 HANDL_RS(tape_get_state, 3, 4), 339 } 340 }, 341 { 342 NDMP_TAPE_MTIO, 343 AUTH_REQUIRED, 344 { 345 HANDL(tape_mtio, 2, 2), 346 HANDL(tape_mtio, 2, 3), 347 HANDL(tape_mtio, 2, 4), 348 } 349 }, 350 { 351 NDMP_TAPE_WRITE, 352 AUTH_REQUIRED, 353 { 354 HANDL(tape_write, 3, 2), 355 HANDL(tape_write, 3, 3), 356 HANDL(tape_write, 3, 4), 357 } 358 }, 359 { 360 NDMP_TAPE_READ, 361 AUTH_REQUIRED, 362 { 363 HANDL(tape_read, 2, 2), 364 HANDL(tape_read, 3, 3), 365 HANDL(tape_read, 3, 4), 366 } 367 }, 368 { 369 NDMP_TAPE_SET_RECORD_SIZE, 370 AUTH_REQUIRED, 371 { 372 HANDL_NULL, 373 HANDL_NULL, 374 HANDL_NULL, 375 } 376 }, 377 { 378 NDMP_TAPE_EXECUTE_CDB, 379 AUTH_REQUIRED, 380 { 381 HANDL(tape_execute_cdb, 2, 2), 382 HANDL(tape_execute_cdb, 2, 3), 383 HANDL(tape_execute_cdb, 2, 4), 384 } 385 } 386 } 387 }, 388 { 389 /* DATA - 0x400 */ 390 12, 391 { 392 { 393 NDMP_DATA_GET_STATE, 394 AUTH_REQUIRED, 395 { 396 HANDL_RS(data_get_state, 2, 2), 397 HANDL_RS(data_get_state, 3, 3), 398 HANDL_RS(data_get_state, 4, 4), 399 } 400 }, 401 { 402 NDMP_DATA_START_BACKUP, 403 AUTH_REQUIRED, 404 { 405 HANDL(data_start_backup, 2, 2), 406 HANDL(data_start_backup, 3, 3), 407 HANDL(data_start_backup, 3, 4), 408 } 409 }, 410 { 411 NDMP_DATA_START_RECOVER, 412 AUTH_REQUIRED, 413 { 414 HANDL(data_start_recover, 2, 2), 415 HANDL(data_start_recover, 3, 3), 416 HANDL(data_start_recover, 3, 4), 417 } 418 }, 419 { 420 NDMP_DATA_ABORT, 421 AUTH_REQUIRED, 422 { 423 HANDL_RS(data_abort, 2, 2), 424 HANDL_RS(data_abort, 3, 3), 425 HANDL_RS(data_abort, 3, 4), 426 } 427 }, 428 { 429 NDMP_DATA_GET_ENV, 430 AUTH_REQUIRED, 431 { 432 HANDL_RS(data_get_env, 2, 2), 433 HANDL_RS(data_get_env, 2, 3), 434 HANDL_RS(data_get_env, 4, 4), 435 } 436 }, 437 { 438 NDMP_DATA_RESVD1, 439 AUTH_REQUIRED, 440 { 441 HANDL_NULL, 442 HANDL_NULL, 443 HANDL_NULL, 444 } 445 }, 446 { 447 NDMP_DATA_RESVD2, 448 AUTH_REQUIRED, 449 { 450 HANDL_NULL, 451 HANDL_NULL, 452 HANDL_NULL, 453 } 454 }, 455 456 { 457 NDMP_DATA_STOP, 458 AUTH_REQUIRED, 459 { 460 HANDL_RS(data_stop, 2, 2), 461 HANDL_RS(data_stop, 3, 3), 462 HANDL_RS(data_stop, 3, 4), 463 } 464 }, 465 { 466 NDMP_DATA_CONTINUE, 467 AUTH_REQUIRED, 468 { 469 HANDL_NULL, 470 HANDL_NULL, 471 HANDL_NULL, 472 } 473 }, 474 { 475 NDMP_DATA_LISTEN, 476 AUTH_REQUIRED, 477 { 478 HANDL_NULL, 479 HANDL(data_listen, 3, 3), 480 HANDL(data_listen, 4, 4), 481 } 482 }, 483 { 484 NDMP_DATA_CONNECT, 485 AUTH_REQUIRED, 486 { 487 HANDL_NULL, 488 HANDL(data_connect, 3, 3), 489 HANDL(data_connect, 4, 4), 490 } 491 }, 492 { 493 NDMP_DATA_START_RECOVER_FILEHIST, 494 AUTH_REQUIRED, 495 { 496 HANDL_NULL, 497 HANDL_NULL, 498 HANDL_RS(data_start_recover_filehist, 4, 4), 499 } 500 } 501 } 502 }, 503 { 504 /* NOTIFY - 0x500 */ 505 6, 506 { 507 { 508 NDMP_NOTIFY_RESERVED, 509 AUTH_REQUIRED, 510 { 511 HANDL_NULL, 512 HANDL_NULL, 513 HANDL_NULL, 514 } 515 }, 516 517 { 518 NDMP_NOTIFY_DATA_HALTED, 519 AUTH_REQUIRED, 520 { 521 HANDL_RQ(notify_data_halted, 2), 522 HANDL_RQ(notify_data_halted, 3), 523 HANDL_RQ(notify_data_halted, 4), 524 } 525 }, 526 { 527 NDMP_NOTIFY_CONNECTION_STATUS, 528 AUTH_NOT_REQUIRED, 529 { 530 HANDL_RQ(notify_connection_status, 2), 531 HANDL_RQ(notify_connection_status, 3), 532 HANDL_RQ(notify_connection_status, 4), 533 } 534 }, 535 { 536 NDMP_NOTIFY_MOVER_HALTED, 537 AUTH_REQUIRED, 538 { 539 HANDL_RQ(notify_mover_halted, 2), 540 HANDL_RQ(notify_mover_halted, 3), 541 HANDL_RQ(notify_mover_halted, 4), 542 } 543 }, 544 { 545 NDMP_NOTIFY_MOVER_PAUSED, 546 AUTH_REQUIRED, 547 { 548 HANDL_RQ(notify_mover_paused, 2), 549 HANDL_RQ(notify_mover_paused, 3), 550 HANDL_RQ(notify_mover_paused, 4), 551 } 552 }, 553 { 554 NDMP_NOTIFY_DATA_READ, 555 AUTH_REQUIRED, 556 { 557 HANDL_RQ(notify_data_read, 2), 558 HANDL_RQ(notify_data_read, 3), 559 HANDL_RQ(notify_data_read, 4), 560 } 561 } 562 } 563 }, 564 { 565 /* LOG - 0x600 */ 566 4, 567 { 568 { 569 _NDMP_LOG_LOG, 570 AUTH_REQUIRED, 571 { 572 HANDL_RQ(log_log, 2), 573 HANDL_NULL, 574 HANDL_NULL, 575 } 576 }, 577 { 578 _NDMP_LOG_DEBUG, 579 AUTH_REQUIRED, 580 { 581 HANDL_RQ(log_debug, 2), 582 HANDL_NULL, 583 HANDL_NULL, 584 } 585 }, 586 { 587 NDMP_LOG_FILE, 588 AUTH_REQUIRED, 589 { 590 HANDL_NULL, 591 HANDL_RQ(log_file, 3), 592 HANDL_RQ(log_file, 4), 593 } 594 }, 595 { 596 NDMP_LOG_MESSAGE, 597 AUTH_REQUIRED, 598 { 599 HANDL_NULL, 600 HANDL_RQ(log_message, 3), 601 HANDL_RQ(log_message, 4), 602 } 603 } 604 } 605 }, 606 { 607 /* FH - 0x700 */ 608 6, 609 { 610 { 611 NDMP_FH_ADD_UNIX_PATH, 612 AUTH_REQUIRED, 613 { 614 HANDL_RQ(fh_add_unix_path, 2), 615 HANDL_RQ(fh_add_unix_path, 3), 616 HANDL_NULL, 617 } 618 }, 619 { 620 NDMP_FH_ADD_UNIX_DIR, 621 AUTH_REQUIRED, 622 { 623 HANDL_RQ(fh_add_unix_dir, 2), 624 HANDL_RQ(fh_add_unix_dir, 3), 625 HANDL_NULL, 626 } 627 }, 628 { 629 NDMP_FH_ADD_UNIX_NODE, 630 AUTH_REQUIRED, 631 { 632 HANDL_RQ(fh_add_unix_node, 2), 633 HANDL_RQ(fh_add_unix_node, 3), 634 HANDL_NULL, 635 } 636 }, 637 { 638 NDMP_FH_ADD_FILE, 639 AUTH_REQUIRED, 640 { 641 HANDL_NULL, 642 HANDL_RQ(fh_add_file, 3), 643 HANDL_RQ(fh_add_file, 4), 644 } 645 }, 646 { 647 NDMP_FH_ADD_DIR, 648 AUTH_REQUIRED, 649 { 650 HANDL_NULL, 651 HANDL_RQ(fh_add_dir, 3), 652 HANDL_RQ(fh_add_dir, 4), 653 } 654 }, 655 { 656 NDMP_FH_ADD_NODE, 657 AUTH_REQUIRED, 658 { 659 HANDL_NULL, 660 HANDL_RQ(fh_add_node, 3), 661 HANDL_RQ(fh_add_node, 4), 662 } 663 } 664 } 665 }, 666 { 667 /* NONE - 0x800 */ 668 0, 669 }, 670 { 671 /* CONNECT - 0x900 */ 672 4, 673 { 674 { 675 NDMP_CONNECT_OPEN, 676 AUTH_NOT_REQUIRED, 677 { 678 HANDL(connect_open, 2, 2), 679 HANDL(connect_open, 2, 3), 680 HANDL(connect_open, 2, 4), 681 } 682 }, 683 { 684 NDMP_CONNECT_AUTH, 685 AUTH_NOT_REQUIRED, 686 { 687 HANDL(connect_client_auth, 2, 2), 688 HANDL(connect_client_auth, 3, 3), 689 HANDL(connect_client_auth, 3, 4), 690 } 691 }, 692 { 693 NDMP_CONNECT_CLOSE, 694 AUTH_NOT_REQUIRED, 695 { 696 HANDL_NONE(connect_close, 2), 697 HANDL_NONE(connect_close, 3), 698 HANDL_NONE(connect_close, 3), 699 } 700 }, 701 { 702 NDMP_CONNECT_SERVER_AUTH, 703 AUTH_REQUIRED, 704 { 705 HANDL(connect_server_auth, 2, 2), 706 HANDL(connect_server_auth, 2, 3), 707 HANDL(connect_server_auth, 2, 4), 708 } 709 } 710 } 711 }, 712 { 713 /* MOVER - 0xa00 */ 714 10, 715 { 716 { 717 NDMP_MOVER_GET_STATE, 718 AUTH_REQUIRED, 719 { 720 HANDL_RS(mover_get_state, 2, 2), 721 HANDL_RS(mover_get_state, 3, 3), 722 HANDL_RS(mover_get_state, 4, 4), 723 } 724 }, 725 { 726 NDMP_MOVER_LISTEN, 727 AUTH_REQUIRED, 728 { 729 HANDL(mover_listen, 2, 2), 730 HANDL(mover_listen, 3, 3), 731 HANDL(mover_listen, 4, 4), 732 } 733 }, 734 { 735 NDMP_MOVER_CONTINUE, 736 AUTH_REQUIRED, 737 { 738 HANDL_RS(mover_continue, 2, 2), 739 HANDL_RS(mover_continue, 3, 3), 740 HANDL_RS(mover_continue, 3, 4), 741 } 742 }, 743 { 744 NDMP_MOVER_ABORT, 745 AUTH_REQUIRED, 746 { 747 HANDL_RS(mover_abort, 2, 2), 748 HANDL_RS(mover_abort, 3, 3), 749 HANDL_RS(mover_abort, 3, 4), 750 } 751 }, 752 { 753 NDMP_MOVER_STOP, 754 AUTH_REQUIRED, 755 { 756 HANDL_RS(mover_stop, 2, 2), 757 HANDL_RS(mover_stop, 2, 3), 758 HANDL_RS(mover_stop, 2, 4), 759 } 760 }, 761 { 762 NDMP_MOVER_SET_WINDOW, 763 AUTH_REQUIRED, 764 { 765 HANDL(mover_set_window, 2, 2), 766 HANDL(mover_set_window, 3, 3), 767 HANDL(mover_set_window, 3, 4), 768 } 769 }, 770 { 771 NDMP_MOVER_READ, 772 AUTH_REQUIRED, 773 { 774 HANDL(mover_read, 2, 2), 775 HANDL(mover_read, 3, 3), 776 HANDL(mover_read, 3, 4), 777 } 778 }, 779 { 780 NDMP_MOVER_CLOSE, 781 AUTH_REQUIRED, 782 { 783 HANDL_RS(mover_close, 2, 2), 784 HANDL_RS(mover_close, 2, 3), 785 HANDL_RS(mover_close, 2, 4), 786 } 787 }, 788 { 789 NDMP_MOVER_SET_RECORD_SIZE, 790 AUTH_REQUIRED, 791 { 792 HANDL(mover_set_record_size, 2, 2), 793 HANDL(mover_set_record_size, 3, 3), 794 HANDL(mover_set_record_size, 3, 4), 795 } 796 }, 797 { 798 NDMP_MOVER_CONNECT, 799 AUTH_REQUIRED, 800 { 801 HANDL_NULL, 802 HANDL(mover_connect, 3, 3), 803 HANDL(mover_connect, 4, 4), 804 } 805 } 806 } 807 } 808 }; 809 #else /* !lint */ 810 ndmp_handler_t ndmp_msghdl_tab[] = { 811 0 812 }; 813 #endif /* !lint */ 814