1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
|
#ifndef ISCSI_TARGET_CORE_H
#define ISCSI_TARGET_CORE_H
#include <linux/in.h>
#include <linux/configfs.h>
#include <net/sock.h>
#include <net/tcp.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/iscsi_proto.h>
#include <target/target_core_base.h>
#define ISCSIT_VERSION "v4.1.0-rc2"
#define ISCSI_MAX_DATASN_MISSING_COUNT 16
#define ISCSI_TX_THREAD_TCP_TIMEOUT 2
#define ISCSI_RX_THREAD_TCP_TIMEOUT 2
#define SECONDS_FOR_ASYNC_LOGOUT 10
#define SECONDS_FOR_ASYNC_TEXT 10
#define SECONDS_FOR_LOGOUT_COMP 15
#define WHITE_SPACE " \t\v\f\n\r"
#define ISCSIT_MIN_TAGS 16
#define ISCSIT_EXTRA_TAGS 8
/* struct iscsi_node_attrib sanity values */
#define NA_DATAOUT_TIMEOUT 3
#define NA_DATAOUT_TIMEOUT_MAX 60
#define NA_DATAOUT_TIMEOUT_MIX 2
#define NA_DATAOUT_TIMEOUT_RETRIES 5
#define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
#define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
#define NA_NOPIN_TIMEOUT 15
#define NA_NOPIN_TIMEOUT_MAX 60
#define NA_NOPIN_TIMEOUT_MIN 3
#define NA_NOPIN_RESPONSE_TIMEOUT 30
#define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
#define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
#define NA_RANDOM_DATAIN_PDU_OFFSETS 0
#define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
#define NA_RANDOM_R2T_OFFSETS 0
#define NA_DEFAULT_ERL 0
#define NA_DEFAULT_ERL_MAX 2
#define NA_DEFAULT_ERL_MIN 0
/* struct iscsi_tpg_attrib sanity values */
#define TA_AUTHENTICATION 1
#define TA_LOGIN_TIMEOUT 15
#define TA_LOGIN_TIMEOUT_MAX 30
#define TA_LOGIN_TIMEOUT_MIN 5
#define TA_NETIF_TIMEOUT 2
#define TA_NETIF_TIMEOUT_MAX 15
#define TA_NETIF_TIMEOUT_MIN 2
#define TA_GENERATE_NODE_ACLS 0
#define TA_DEFAULT_CMDSN_DEPTH 64
#define TA_DEFAULT_CMDSN_DEPTH_MAX 512
#define TA_DEFAULT_CMDSN_DEPTH_MIN 1
#define TA_CACHE_DYNAMIC_ACLS 0
/* Enabled by default in demo mode (generic_node_acls=1) */
#define TA_DEMO_MODE_WRITE_PROTECT 1
/* Disabled by default in production mode w/ explict ACLs */
#define TA_PROD_MODE_WRITE_PROTECT 0
#define TA_CACHE_CORE_NPS 0
#define ISCSI_IOV_DATA_BUFFER 5
enum iscsit_transport_type {
ISCSI_TCP = 0,
ISCSI_SCTP_TCP = 1,
ISCSI_SCTP_UDP = 2,
ISCSI_IWARP_TCP = 3,
ISCSI_IWARP_SCTP = 4,
ISCSI_INFINIBAND = 5,
};
/* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
enum target_conn_state_table {
TARG_CONN_STATE_FREE = 0x1,
TARG_CONN_STATE_XPT_UP = 0x3,
TARG_CONN_STATE_IN_LOGIN = 0x4,
TARG_CONN_STATE_LOGGED_IN = 0x5,
TARG_CONN_STATE_IN_LOGOUT = 0x6,
TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7,
TARG_CONN_STATE_CLEANUP_WAIT = 0x8,
};
/* RFC-3720 7.3.2 Session State Diagram for a Target */
enum target_sess_state_table {
TARG_SESS_STATE_FREE = 0x1,
TARG_SESS_STATE_ACTIVE = 0x2,
TARG_SESS_STATE_LOGGED_IN = 0x3,
TARG_SESS_STATE_FAILED = 0x4,
TARG_SESS_STATE_IN_CONTINUE = 0x5,
};
/* struct iscsi_data_count->type */
enum data_count_type {
ISCSI_RX_DATA = 1,
ISCSI_TX_DATA = 2,
};
/* struct iscsi_datain_req->dr_complete */
enum datain_req_comp_table {
DATAIN_COMPLETE_NORMAL = 1,
DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
DATAIN_COMPLETE_CONNECTION_RECOVERY = 3,
};
/* struct iscsi_datain_req->recovery */
enum datain_req_rec_table {
DATAIN_WITHIN_COMMAND_RECOVERY = 1,
DATAIN_CONNECTION_RECOVERY = 2,
};
/* struct iscsi_portal_group->state */
enum tpg_state_table {
TPG_STATE_FREE = 0,
TPG_STATE_ACTIVE = 1,
TPG_STATE_INACTIVE = 2,
TPG_STATE_COLD_RESET = 3,
};
/* struct iscsi_tiqn->tiqn_state */
enum tiqn_state_table {
TIQN_STATE_ACTIVE = 1,
TIQN_STATE_SHUTDOWN = 2,
};
/* struct iscsi_cmd->cmd_flags */
enum cmd_flags_table {
ICF_GOT_LAST_DATAOUT = 0x00000001,
ICF_GOT_DATACK_SNACK = 0x00000002,
ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004,
ICF_SENT_LAST_R2T = 0x00000008,
ICF_WITHIN_COMMAND_RECOVERY = 0x00000010,
ICF_CONTIG_MEMORY = 0x00000020,
ICF_ATTACHED_TO_RQUEUE = 0x00000040,
ICF_OOO_CMDSN = 0x00000080,
IFC_SENDTARGETS_ALL = 0x00000100,
IFC_SENDTARGETS_SINGLE = 0x00000200,
};
/* struct iscsi_cmd->i_state */
enum cmd_i_state_table {
ISTATE_NO_STATE = 0,
ISTATE_NEW_CMD = 1,
ISTATE_DEFERRED_CMD = 2,
ISTATE_UNSOLICITED_DATA = 3,
ISTATE_RECEIVE_DATAOUT = 4,
ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
ISTATE_RECEIVED_LAST_DATAOUT = 6,
ISTATE_WITHIN_DATAOUT_RECOVERY = 7,
ISTATE_IN_CONNECTION_RECOVERY = 8,
ISTATE_RECEIVED_TASKMGT = 9,
ISTATE_SEND_ASYNCMSG = 10,
ISTATE_SENT_ASYNCMSG = 11,
ISTATE_SEND_DATAIN = 12,
ISTATE_SEND_LAST_DATAIN = 13,
ISTATE_SENT_LAST_DATAIN = 14,
ISTATE_SEND_LOGOUTRSP = 15,
ISTATE_SENT_LOGOUTRSP = 16,
ISTATE_SEND_NOPIN = 17,
ISTATE_SENT_NOPIN = 18,
ISTATE_SEND_REJECT = 19,
ISTATE_SENT_REJECT = 20,
ISTATE_SEND_R2T = 21,
ISTATE_SENT_R2T = 22,
ISTATE_SEND_R2T_RECOVERY = 23,
ISTATE_SENT_R2T_RECOVERY = 24,
ISTATE_SEND_LAST_R2T = 25,
ISTATE_SENT_LAST_R2T = 26,
ISTATE_SEND_LAST_R2T_RECOVERY = 27,
ISTATE_SENT_LAST_R2T_RECOVERY = 28,
ISTATE_SEND_STATUS = 29,
ISTATE_SEND_STATUS_BROKEN_PC = 30,
ISTATE_SENT_STATUS = 31,
ISTATE_SEND_STATUS_RECOVERY = 32,
ISTATE_SENT_STATUS_RECOVERY = 33,
ISTATE_SEND_TASKMGTRSP = 34,
ISTATE_SENT_TASKMGTRSP = 35,
ISTATE_SEND_TEXTRSP = 36,
ISTATE_SENT_TEXTRSP = 37,
ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
ISTATE_SEND_NOPIN_NO_RESPONSE = 40,
ISTATE_REMOVE = 41,
ISTATE_FREE = 42,
};
/* Used for iscsi_recover_cmdsn() return values */
enum recover_cmdsn_ret_table {
CMDSN_ERROR_CANNOT_RECOVER = -1,
CMDSN_NORMAL_OPERATION = 0,
CMDSN_LOWER_THAN_EXP = 1,
CMDSN_HIGHER_THAN_EXP = 2,
};
/* Used for iscsi_handle_immediate_data() return values */
enum immedate_data_ret_table {
IMMEDIATE_DATA_CANNOT_RECOVER = -1,
IMMEDIATE_DATA_NORMAL_OPERATION = 0,
IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
};
/* Used for iscsi_decide_dataout_action() return values */
enum dataout_action_ret_table {
DATAOUT_CANNOT_RECOVER = -1,
DATAOUT_NORMAL = 0,
DATAOUT_SEND_R2T = 1,
DATAOUT_SEND_TO_TRANSPORT = 2,
DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
};
/* Used for struct iscsi_node_auth->naf_flags */
enum naf_flags_table {
NAF_USERID_SET = 0x01,
NAF_PASSWORD_SET = 0x02,
NAF_USERID_IN_SET = 0x04,
NAF_PASSWORD_IN_SET = 0x08,
};
/* Used by various struct timer_list to manage iSCSI specific state *
|