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