-
Notifications
You must be signed in to change notification settings - Fork 7
/
SCTP.c
executable file
·645 lines (619 loc) · 28.3 KB
/
SCTP.c
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
/*
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/sysctl.h>
#include <netinet/in.h>
#include <sys/protosw.h>
#include <netinet/ip.h>
#include <sys/lock.h>
#include <sys/domain.h>
#include <net/route.h>
#include <sys/socketvar.h>
#include <netinet/in_pcb.h>
#include <netinet/sctp_os.h>
#include <netinet/sctp_pcb.h>
#include <netinet/sctp_var.h>
#include <netinet/sctp_timer.h>
#ifdef INET6
#include <netinet6/sctp6_var.h>
#endif
#include <netinet/sctp.h>
#if defined(APPLE_LEOPARD)
#include <netinet/udp.h>
#include <netinet/udp_var.h>
extern struct pr_usrreqs udp_usrreqs;
#ifdef INET6
extern struct pr_usrreqs udp6_usrreqs;
#endif
extern struct inpcbinfo udbinfo;
#endif
SYSCTL_DECL(_net_inet);
#ifdef INET6
SYSCTL_DECL(_net_inet6);
#endif
SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP")
#ifdef INET6
SYSCTL_NODE(_net_inet6, IPPROTO_SCTP, sctp6, CTLFLAG_RW, 0, "SCTP6")
#endif
extern struct sysctl_oid sysctl__net_inet_sctp_sendspace;
extern struct sysctl_oid sysctl__net_inet_sctp_recvspace;
extern struct sysctl_oid sysctl__net_inet_sctp_auto_asconf;
extern struct sysctl_oid sysctl__net_inet_sctp_ecn_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_pr_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_auth_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_asconf_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_reconfig_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_nrsack_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_pktdrop_enable;
extern struct sysctl_oid sysctl__net_inet_sctp_fr_maxburst;
extern struct sysctl_oid sysctl__net_inet_sctp_loopback_nocsum;
extern struct sysctl_oid sysctl__net_inet_sctp_peer_chkoh;
extern struct sysctl_oid sysctl__net_inet_sctp_maxburst;
extern struct sysctl_oid sysctl__net_inet_sctp_maxchunks;
extern struct sysctl_oid sysctl__net_inet_sctp_delayed_sack_time;
extern struct sysctl_oid sysctl__net_inet_sctp_sack_freq;
extern struct sysctl_oid sysctl__net_inet_sctp_heartbeat_interval;
extern struct sysctl_oid sysctl__net_inet_sctp_pmtu_raise_time;
extern struct sysctl_oid sysctl__net_inet_sctp_shutdown_guard_time;
extern struct sysctl_oid sysctl__net_inet_sctp_secret_lifetime;
extern struct sysctl_oid sysctl__net_inet_sctp_rto_max;
extern struct sysctl_oid sysctl__net_inet_sctp_rto_min;
extern struct sysctl_oid sysctl__net_inet_sctp_rto_initial;
extern struct sysctl_oid sysctl__net_inet_sctp_init_rto_max;
extern struct sysctl_oid sysctl__net_inet_sctp_valid_cookie_life;
extern struct sysctl_oid sysctl__net_inet_sctp_init_rtx_max;
extern struct sysctl_oid sysctl__net_inet_sctp_assoc_rtx_max;
extern struct sysctl_oid sysctl__net_inet_sctp_path_rtx_max;
extern struct sysctl_oid sysctl__net_inet_sctp_path_pf_threshold;
extern struct sysctl_oid sysctl__net_inet_sctp_incoming_streams;
extern struct sysctl_oid sysctl__net_inet_sctp_outgoing_streams;
extern struct sysctl_oid sysctl__net_inet_sctp_cmt_on_off;
extern struct sysctl_oid sysctl__net_inet_sctp_cmt_use_dac;
extern struct sysctl_oid sysctl__net_inet_sctp_cwnd_maxburst;
extern struct sysctl_oid sysctl__net_inet_sctp_nat_friendly;
extern struct sysctl_oid sysctl__net_inet_sctp_abc_l_var;
extern struct sysctl_oid sysctl__net_inet_sctp_max_chained_mbufs;
extern struct sysctl_oid sysctl__net_inet_sctp_do_sctp_drain;
extern struct sysctl_oid sysctl__net_inet_sctp_hb_max_burst;
extern struct sysctl_oid sysctl__net_inet_sctp_abort_at_limit;
extern struct sysctl_oid sysctl__net_inet_sctp_min_residual;
extern struct sysctl_oid sysctl__net_inet_sctp_max_retran_chunk;
extern struct sysctl_oid sysctl__net_inet_sctp_log_level;
extern struct sysctl_oid sysctl__net_inet_sctp_default_cc_module;
extern struct sysctl_oid sysctl__net_inet_sctp_default_ss_module;
extern struct sysctl_oid sysctl__net_inet_sctp_default_frag_interleave;
extern struct sysctl_oid sysctl__net_inet_sctp_mobility_base;
extern struct sysctl_oid sysctl__net_inet_sctp_mobility_fasthandoff;
#if defined(SCTP_LOCAL_TRACE_BUF)
extern struct sysctl_oid sysctl__net_inet_sctp_log;
extern struct sysctl_oid sysctl__net_inet_sctp_clear_trace;
#endif
extern struct sysctl_oid sysctl__net_inet_sctp_udp_tunneling_port;
extern struct sysctl_oid sysctl__net_inet_sctp_enable_sack_immediately;
extern struct sysctl_oid sysctl__net_inet_sctp_nat_friendly_init;
extern struct sysctl_oid sysctl__net_inet_sctp_vtag_time_wait;
extern struct sysctl_oid sysctl__net_inet_sctp_buffer_splitting;
extern struct sysctl_oid sysctl__net_inet_sctp_initial_cwnd;
extern struct sysctl_oid sysctl__net_inet_sctp_rttvar_bw;
extern struct sysctl_oid sysctl__net_inet_sctp_rttvar_rtt;
extern struct sysctl_oid sysctl__net_inet_sctp_rttvar_eqret;
extern struct sysctl_oid sysctl__net_inet_sctp_rttvar_steady_step;
extern struct sysctl_oid sysctl__net_inet_sctp_use_dcccecn;
extern struct sysctl_oid sysctl__net_inet_sctp_blackhole;
extern struct sysctl_oid sysctl__net_inet_sctp_sendall_limit;
extern struct sysctl_oid sysctl__net_inet_sctp_diag_info_code;
#if defined(SCTP_DEBUG)
extern struct sysctl_oid sysctl__net_inet_sctp_debug;
#endif
extern struct sysctl_oid sysctl__net_inet_sctp_stats;
extern struct sysctl_oid sysctl__net_inet_sctp_assoclist;
extern struct sysctl_oid sysctl__net_inet_sctp_main_timer;
extern struct sysctl_oid sysctl__net_inet_sctp_ignore_vmware_interfaces;
extern struct sysctl_oid sysctl__net_inet_sctp_output_unlocked;
extern struct sysctl_oid sysctl__net_inet_sctp_addr_watchdog_limit;
extern struct sysctl_oid sysctl__net_inet_sctp_vtag_watchdog_limit;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
extern struct domain inetdomain;
#ifdef INET6
extern struct domain inet6domain;
#endif
#else
extern struct domain *inetdomain;
#ifdef INET6
extern struct domain *inet6domain;
#endif
#endif
extern struct protosw *ip_protox[];
#ifdef INET6
extern struct protosw *ip6_protox[];
#endif
extern struct sctp_epinfo sctppcinfo;
struct protosw sctp4_seqpacket;
struct protosw sctp4_stream;
#ifdef INET6
struct protosw sctp6_seqpacket;
struct protosw sctp6_stream;
#endif
struct protosw *old_pr4;
#ifdef INET6
struct protosw *old_pr6;
#endif
#if defined(APPLE_LEOPARD)
static int
soreceive_fix(struct socket *so, struct sockaddr **psa, struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
{
if ((controlp) && (*controlp)) {
m_freem(*controlp);
}
return (soreceive(so, psa, uio, mp0, controlp, flagsp));
}
#endif
kern_return_t
SCTP_start(kmod_info_t * ki __attribute__((unused)), void * d __attribute__((unused)))
{
int err;
#if !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)
domain_guard_t guard;
#endif
old_pr4 = ip_protox [IPPROTO_SCTP];
#ifdef INET6
old_pr6 = ip6_protox[IPPROTO_SCTP];
#endif
memset(&sctp4_seqpacket, 0, sizeof(struct protosw));
memset(&sctp4_stream, 0, sizeof(struct protosw));
#ifdef INET6
memset(&sctp6_seqpacket, 0, sizeof(struct protosw));
memset(&sctp6_stream, 0, sizeof(struct protosw));
#endif
sctp4_seqpacket.pr_type = SOCK_SEQPACKET;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp4_seqpacket.pr_domain = &inetdomain;
#endif
sctp4_seqpacket.pr_protocol = IPPROTO_SCTP;
sctp4_seqpacket.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_PCBLOCK|PR_PROTOLOCK;
sctp4_seqpacket.pr_input = sctp_input;
sctp4_seqpacket.pr_output = NULL;
sctp4_seqpacket.pr_ctlinput = sctp_ctlinput;
sctp4_seqpacket.pr_ctloutput = sctp_ctloutput;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp4_seqpacket.pr_ousrreq = NULL;
#endif
sctp4_seqpacket.pr_init = sctp_init;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)
sctp4_seqpacket.pr_fasttimo = NULL;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp4_seqpacket.pr_slowtimo = sctp_slowtimo;
#endif
sctp4_seqpacket.pr_drain = sctp_drain;
sctp4_seqpacket.pr_sysctl = NULL;
sctp4_seqpacket.pr_usrreqs = &sctp_usrreqs;
sctp4_seqpacket.pr_lock = sctp_lock;
sctp4_seqpacket.pr_unlock = sctp_unlock;
sctp4_seqpacket.pr_getlock = sctp_getlock;
sctp4_stream.pr_type = SOCK_STREAM;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp4_stream.pr_domain = &inetdomain;
#endif
sctp4_stream.pr_protocol = IPPROTO_SCTP;
sctp4_stream.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_PCBLOCK|PR_PROTOLOCK;
sctp4_stream.pr_input = sctp_input;
sctp4_stream.pr_output = NULL;
sctp4_stream.pr_ctlinput = sctp_ctlinput;
sctp4_stream.pr_ctloutput = sctp_ctloutput;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp4_stream.pr_ousrreq = NULL;
sctp4_stream.pr_init = NULL;
#else
sctp4_stream.pr_init = sctp_init;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)
sctp4_stream.pr_fasttimo = NULL;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp4_stream.pr_slowtimo = NULL;
#endif
sctp4_stream.pr_drain = sctp_drain;
sctp4_stream.pr_sysctl = NULL;
sctp4_stream.pr_usrreqs = &sctp_usrreqs;
sctp4_stream.pr_lock = sctp_lock;
sctp4_stream.pr_unlock = sctp_unlock;
sctp4_stream.pr_getlock = sctp_getlock;
#ifdef INET6
sctp6_seqpacket.pr_type = SOCK_SEQPACKET;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp6_seqpacket.pr_domain = &inet6domain;
#endif
sctp6_seqpacket.pr_protocol = IPPROTO_SCTP;
sctp6_seqpacket.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_PCBLOCK|PR_PROTOLOCK;
sctp6_seqpacket.pr_input = (void (*) (struct mbuf *, int)) sctp6_input;
sctp6_seqpacket.pr_output = NULL;
sctp6_seqpacket.pr_ctlinput = sctp6_ctlinput;
sctp6_seqpacket.pr_ctloutput = sctp_ctloutput;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp6_seqpacket.pr_ousrreq = NULL;
sctp6_seqpacket.pr_init = NULL;
#else
sctp6_seqpacket.pr_init = sctp_init;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)
sctp6_seqpacket.pr_fasttimo = NULL;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp6_seqpacket.pr_slowtimo = NULL;
#endif
sctp6_seqpacket.pr_drain = sctp_drain;
sctp6_seqpacket.pr_sysctl = NULL;
sctp6_seqpacket.pr_usrreqs = &sctp6_usrreqs;
sctp6_seqpacket.pr_lock = sctp_lock;
sctp6_seqpacket.pr_unlock = sctp_unlock;
sctp6_seqpacket.pr_getlock = sctp_getlock;
sctp6_stream.pr_type = SOCK_STREAM;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp6_stream.pr_domain = &inet6domain;
#endif
sctp6_stream.pr_protocol = IPPROTO_SCTP;
sctp6_stream.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_PCBLOCK|PR_PROTOLOCK;
sctp6_stream.pr_input = (void (*) (struct mbuf *, int)) sctp6_input;
sctp6_stream.pr_output = NULL;
sctp6_stream.pr_ctlinput = sctp6_ctlinput;
sctp6_stream.pr_ctloutput = sctp_ctloutput;
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp6_stream.pr_ousrreq = NULL;
sctp6_stream.pr_init = NULL;
#else
sctp6_stream.pr_init = sctp_init;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)
sctp6_stream.pr_fasttimo = NULL;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
sctp6_stream.pr_slowtimo = NULL;
#endif
sctp6_stream.pr_drain = sctp_drain;
sctp6_stream.pr_sysctl = NULL;
sctp6_stream.pr_usrreqs = &sctp6_usrreqs;
sctp6_stream.pr_lock = sctp_lock;
sctp6_stream.pr_unlock = sctp_unlock;
sctp6_stream.pr_getlock = sctp_getlock;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
lck_mtx_lock(inetdomain.dom_mtx);
#ifdef INET6
lck_mtx_lock(inet6domain.dom_mtx);
#endif
#else
guard = domain_guard_deploy();
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
err = net_add_proto(&sctp4_seqpacket, &inetdomain);
err |= net_add_proto(&sctp4_stream, &inetdomain);
#ifdef INET6
err |= net_add_proto(&sctp6_seqpacket, &inet6domain);
err |= net_add_proto(&sctp6_stream, &inet6domain);
#endif
#else
err = net_add_proto(&sctp4_seqpacket, inetdomain, 1);
err |= net_add_proto(&sctp4_stream, inetdomain, 0);
#ifdef INET6
err |= net_add_proto(&sctp6_seqpacket, inet6domain, 0);
err |= net_add_proto(&sctp6_stream, inet6domain, 0);
#endif
#endif
if (err) {
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
#ifdef INET6
lck_mtx_unlock(inet6domain.dom_mtx);
#endif
lck_mtx_unlock(inetdomain.dom_mtx);
#else
domain_guard_release(guard);
#endif
SCTP_PRINTF("SCTP NKE: Not all protocol handlers could be installed.\n");
return (KERN_FAILURE);
}
ip_protox[IPPROTO_SCTP] = &sctp4_seqpacket;
#ifdef INET6
ip6_protox[IPPROTO_SCTP] = &sctp6_seqpacket;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
#ifdef INET6
lck_mtx_unlock(inet6domain.dom_mtx);
#endif
lck_mtx_unlock(inetdomain.dom_mtx);
#else
domain_guard_release(guard);
#endif
sysctl_register_oid(&sysctl__net_inet_sctp);
sysctl_register_oid(&sysctl__net_inet_sctp_sendspace);
sysctl_register_oid(&sysctl__net_inet_sctp_recvspace);
sysctl_register_oid(&sysctl__net_inet_sctp_auto_asconf);
sysctl_register_oid(&sysctl__net_inet_sctp_ecn_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_pr_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_auth_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_asconf_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_reconfig_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_nrsack_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_pktdrop_enable);
sysctl_register_oid(&sysctl__net_inet_sctp_fr_maxburst);
sysctl_register_oid(&sysctl__net_inet_sctp_loopback_nocsum);
sysctl_register_oid(&sysctl__net_inet_sctp_peer_chkoh);
sysctl_register_oid(&sysctl__net_inet_sctp_maxburst);
sysctl_register_oid(&sysctl__net_inet_sctp_maxchunks);
sysctl_register_oid(&sysctl__net_inet_sctp_delayed_sack_time);
sysctl_register_oid(&sysctl__net_inet_sctp_sack_freq);
sysctl_register_oid(&sysctl__net_inet_sctp_heartbeat_interval);
sysctl_register_oid(&sysctl__net_inet_sctp_pmtu_raise_time);
sysctl_register_oid(&sysctl__net_inet_sctp_shutdown_guard_time);
sysctl_register_oid(&sysctl__net_inet_sctp_secret_lifetime);
sysctl_register_oid(&sysctl__net_inet_sctp_rto_max);
sysctl_register_oid(&sysctl__net_inet_sctp_rto_min);
sysctl_register_oid(&sysctl__net_inet_sctp_rto_initial);
sysctl_register_oid(&sysctl__net_inet_sctp_init_rto_max);
sysctl_register_oid(&sysctl__net_inet_sctp_valid_cookie_life);
sysctl_register_oid(&sysctl__net_inet_sctp_init_rtx_max);
sysctl_register_oid(&sysctl__net_inet_sctp_assoc_rtx_max);
sysctl_register_oid(&sysctl__net_inet_sctp_path_rtx_max);
sysctl_register_oid(&sysctl__net_inet_sctp_path_pf_threshold);
sysctl_register_oid(&sysctl__net_inet_sctp_incoming_streams);
sysctl_register_oid(&sysctl__net_inet_sctp_outgoing_streams);
sysctl_register_oid(&sysctl__net_inet_sctp_cmt_on_off);
sysctl_register_oid(&sysctl__net_inet_sctp_cmt_use_dac);
sysctl_register_oid(&sysctl__net_inet_sctp_cwnd_maxburst);
sysctl_register_oid(&sysctl__net_inet_sctp_nat_friendly);
sysctl_register_oid(&sysctl__net_inet_sctp_abc_l_var);
sysctl_register_oid(&sysctl__net_inet_sctp_max_chained_mbufs);
sysctl_register_oid(&sysctl__net_inet_sctp_do_sctp_drain);
sysctl_register_oid(&sysctl__net_inet_sctp_hb_max_burst);
sysctl_register_oid(&sysctl__net_inet_sctp_abort_at_limit);
sysctl_register_oid(&sysctl__net_inet_sctp_min_residual);
sysctl_register_oid(&sysctl__net_inet_sctp_max_retran_chunk);
sysctl_register_oid(&sysctl__net_inet_sctp_log_level);
sysctl_register_oid(&sysctl__net_inet_sctp_default_cc_module);
sysctl_register_oid(&sysctl__net_inet_sctp_default_ss_module);
sysctl_register_oid(&sysctl__net_inet_sctp_default_frag_interleave);
sysctl_register_oid(&sysctl__net_inet_sctp_mobility_base);
sysctl_register_oid(&sysctl__net_inet_sctp_mobility_fasthandoff);
#if defined(SCTP_LOCAL_TRACE_BUF)
sysctl_register_oid(&sysctl__net_inet_sctp_log);
sysctl_register_oid(&sysctl__net_inet_sctp_clear_trace);
#endif
sysctl_register_oid(&sysctl__net_inet_sctp_udp_tunneling_port);
sysctl_register_oid(&sysctl__net_inet_sctp_enable_sack_immediately);
sysctl_register_oid(&sysctl__net_inet_sctp_nat_friendly_init);
sysctl_register_oid(&sysctl__net_inet_sctp_vtag_time_wait);
sysctl_register_oid(&sysctl__net_inet_sctp_buffer_splitting);
sysctl_register_oid(&sysctl__net_inet_sctp_initial_cwnd);
sysctl_register_oid(&sysctl__net_inet_sctp_rttvar_bw);
sysctl_register_oid(&sysctl__net_inet_sctp_rttvar_rtt);
sysctl_register_oid(&sysctl__net_inet_sctp_rttvar_eqret);
sysctl_register_oid(&sysctl__net_inet_sctp_rttvar_steady_step);
sysctl_register_oid(&sysctl__net_inet_sctp_use_dcccecn);
sysctl_register_oid(&sysctl__net_inet_sctp_blackhole);
sysctl_register_oid(&sysctl__net_inet_sctp_sendall_limit);
sysctl_register_oid(&sysctl__net_inet_sctp_diag_info_code);
#ifdef SCTP_DEBUG
sysctl_register_oid(&sysctl__net_inet_sctp_debug);
#endif
sysctl_register_oid(&sysctl__net_inet_sctp_stats);
sysctl_register_oid(&sysctl__net_inet_sctp_assoclist);
sysctl_register_oid(&sysctl__net_inet_sctp_main_timer);
sysctl_register_oid(&sysctl__net_inet_sctp_ignore_vmware_interfaces);
sysctl_register_oid(&sysctl__net_inet_sctp_output_unlocked);
sysctl_register_oid(&sysctl__net_inet_sctp_addr_watchdog_limit);
sysctl_register_oid(&sysctl__net_inet_sctp_vtag_watchdog_limit);
#if defined(APPLE_LEOPARD)
lck_rw_lock_exclusive(udbinfo.mtx);
udp_usrreqs.pru_soreceive = soreceive_fix;
#ifdef INET6
udp6_usrreqs.pru_soreceive = soreceive_fix;
#endif
lck_rw_done(udbinfo.mtx);
#endif
SCTP_PRINTF("SCTP NKE: NKE loaded.\n");
return (KERN_SUCCESS);
}
kern_return_t
SCTP_stop(kmod_info_t * ki __attribute__((unused)), void * d __attribute__((unused)))
{
struct inpcb *inp;
int err;
#if !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)
domain_guard_t guard;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
if (!lck_rw_try_lock_exclusive(SCTP_BASE_INFO(sctbinfo).mtx)) {
#else
if (!lck_rw_try_lock_exclusive(SCTP_BASE_INFO(sctbinfo).ipi_lock)) {
#endif
SCTP_PRINTF("SCTP NKE: Someone else holds the lock\n");
return (KERN_FAILURE);
}
if (!LIST_EMPTY(&SCTP_BASE_INFO(listhead))) {
SCTP_PRINTF("SCTP NKE: There are still SCTP endpoints. NKE not unloaded\n");
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
lck_rw_unlock_exclusive(SCTP_BASE_INFO(sctbinfo).mtx);
#else
lck_rw_unlock_exclusive(SCTP_BASE_INFO(sctbinfo).ipi_lock);
#endif
return (KERN_FAILURE);
}
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
if (!LIST_EMPTY(SCTP_BASE_INFO(sctbinfo).listhead)) {
#else
if (!LIST_EMPTY(SCTP_BASE_INFO(sctbinfo).ipi_listhead)) {
#endif
SCTP_PRINTF("SCTP NKE: There are still not deleted SCTP endpoints. NKE not unloaded\n");
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
LIST_FOREACH(inp, SCTP_BASE_INFO(sctbinfo).listhead, inp_list) {
#else
LIST_FOREACH(inp, SCTP_BASE_INFO(sctbinfo).ipi_listhead, inp_list) {
#endif
SCTP_PRINTF("inp = %p: inp_wantcnt = %d, inp_state = %d, inp_socket->so_usecount = %d\n", inp, inp->inp_wantcnt, inp->inp_state, inp->inp_socket->so_usecount);
}
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
lck_rw_unlock_exclusive(SCTP_BASE_INFO(sctbinfo).mtx);
#else
lck_rw_unlock_exclusive(SCTP_BASE_INFO(sctbinfo).ipi_lock);
#endif
return (KERN_FAILURE);
}
#if defined(APPLE_LEOPARD)
lck_rw_lock_exclusive(udbinfo.mtx);
udp_usrreqs.pru_soreceive = soreceive;
#ifdef INET6
udp6_usrreqs.pru_soreceive = soreceive;
#endif
lck_rw_done(udbinfo.mtx);
#endif
sysctl_unregister_oid(&sysctl__net_inet_sctp_sendspace);
sysctl_unregister_oid(&sysctl__net_inet_sctp_recvspace);
sysctl_unregister_oid(&sysctl__net_inet_sctp_auto_asconf);
sysctl_unregister_oid(&sysctl__net_inet_sctp_ecn_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_pr_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_auth_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_asconf_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_reconfig_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_nrsack_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_pktdrop_enable);
sysctl_unregister_oid(&sysctl__net_inet_sctp_fr_maxburst);
sysctl_unregister_oid(&sysctl__net_inet_sctp_loopback_nocsum);
sysctl_unregister_oid(&sysctl__net_inet_sctp_peer_chkoh);
sysctl_unregister_oid(&sysctl__net_inet_sctp_maxburst);
sysctl_unregister_oid(&sysctl__net_inet_sctp_maxchunks);
sysctl_unregister_oid(&sysctl__net_inet_sctp_delayed_sack_time);
sysctl_unregister_oid(&sysctl__net_inet_sctp_sack_freq);
sysctl_unregister_oid(&sysctl__net_inet_sctp_heartbeat_interval);
sysctl_unregister_oid(&sysctl__net_inet_sctp_pmtu_raise_time);
sysctl_unregister_oid(&sysctl__net_inet_sctp_shutdown_guard_time);
sysctl_unregister_oid(&sysctl__net_inet_sctp_secret_lifetime);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rto_max);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rto_min);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rto_initial);
sysctl_unregister_oid(&sysctl__net_inet_sctp_init_rto_max);
sysctl_unregister_oid(&sysctl__net_inet_sctp_valid_cookie_life);
sysctl_unregister_oid(&sysctl__net_inet_sctp_init_rtx_max);
sysctl_unregister_oid(&sysctl__net_inet_sctp_assoc_rtx_max);
sysctl_unregister_oid(&sysctl__net_inet_sctp_path_rtx_max);
sysctl_unregister_oid(&sysctl__net_inet_sctp_path_pf_threshold);
sysctl_unregister_oid(&sysctl__net_inet_sctp_incoming_streams);
sysctl_unregister_oid(&sysctl__net_inet_sctp_outgoing_streams);
sysctl_unregister_oid(&sysctl__net_inet_sctp_cmt_on_off);
sysctl_unregister_oid(&sysctl__net_inet_sctp_cmt_use_dac);
sysctl_unregister_oid(&sysctl__net_inet_sctp_cwnd_maxburst);
sysctl_unregister_oid(&sysctl__net_inet_sctp_nat_friendly);
sysctl_unregister_oid(&sysctl__net_inet_sctp_abc_l_var);
sysctl_unregister_oid(&sysctl__net_inet_sctp_max_chained_mbufs);
sysctl_unregister_oid(&sysctl__net_inet_sctp_do_sctp_drain);
sysctl_unregister_oid(&sysctl__net_inet_sctp_hb_max_burst);
sysctl_unregister_oid(&sysctl__net_inet_sctp_abort_at_limit);
sysctl_unregister_oid(&sysctl__net_inet_sctp_min_residual);
sysctl_unregister_oid(&sysctl__net_inet_sctp_max_retran_chunk);
sysctl_unregister_oid(&sysctl__net_inet_sctp_log_level);
sysctl_unregister_oid(&sysctl__net_inet_sctp_default_cc_module);
sysctl_unregister_oid(&sysctl__net_inet_sctp_default_ss_module);
sysctl_unregister_oid(&sysctl__net_inet_sctp_default_frag_interleave);
sysctl_unregister_oid(&sysctl__net_inet_sctp_mobility_base);
sysctl_unregister_oid(&sysctl__net_inet_sctp_mobility_fasthandoff);
#if defined(SCTP_LOCAL_TRACE_BUF)
sysctl_unregister_oid(&sysctl__net_inet_sctp_log);
sysctl_unregister_oid(&sysctl__net_inet_sctp_clear_trace);
#endif
sysctl_unregister_oid(&sysctl__net_inet_sctp_udp_tunneling_port);
sysctl_unregister_oid(&sysctl__net_inet_sctp_enable_sack_immediately);
sysctl_unregister_oid(&sysctl__net_inet_sctp_nat_friendly_init);
sysctl_unregister_oid(&sysctl__net_inet_sctp_vtag_time_wait);
sysctl_unregister_oid(&sysctl__net_inet_sctp_buffer_splitting);
sysctl_unregister_oid(&sysctl__net_inet_sctp_initial_cwnd);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rttvar_bw);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rttvar_rtt);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rttvar_eqret);
sysctl_unregister_oid(&sysctl__net_inet_sctp_rttvar_steady_step);
sysctl_unregister_oid(&sysctl__net_inet_sctp_use_dcccecn);
sysctl_unregister_oid(&sysctl__net_inet_sctp_blackhole);
sysctl_unregister_oid(&sysctl__net_inet_sctp_sendall_limit);
sysctl_unregister_oid(&sysctl__net_inet_sctp_diag_info_code);
#ifdef SCTP_DEBUG
sysctl_unregister_oid(&sysctl__net_inet_sctp_debug);
#endif
sysctl_unregister_oid(&sysctl__net_inet_sctp_stats);
sysctl_unregister_oid(&sysctl__net_inet_sctp_assoclist);
sysctl_unregister_oid(&sysctl__net_inet_sctp_main_timer);
sysctl_unregister_oid(&sysctl__net_inet_sctp_ignore_vmware_interfaces);
sysctl_unregister_oid(&sysctl__net_inet_sctp_output_unlocked);
sysctl_unregister_oid(&sysctl__net_inet_sctp_addr_watchdog_limit);
sysctl_unregister_oid(&sysctl__net_inet_sctp_vtag_watchdog_limit);
sysctl_unregister_oid(&sysctl__net_inet_sctp);
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
lck_mtx_lock(inetdomain.dom_mtx);
#ifdef INET6
lck_mtx_lock(inet6domain.dom_mtx);
#endif
#else
guard = domain_guard_deploy();
#endif
ip_protox[IPPROTO_SCTP] = old_pr4;
#ifdef INET6
ip6_protox[IPPROTO_SCTP] = old_pr6;
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
err = net_del_proto(sctp4_seqpacket.pr_type, sctp4_seqpacket.pr_protocol, &inetdomain);
err |= net_del_proto(sctp4_stream.pr_type, sctp4_stream.pr_protocol, &inetdomain);
#ifdef INET6
err |= net_del_proto(sctp6_seqpacket.pr_type, sctp6_seqpacket.pr_protocol, &inet6domain);
err |= net_del_proto(sctp6_stream.pr_type, sctp6_stream.pr_protocol, &inet6domain);
#endif
#else
err = net_del_proto(sctp4_seqpacket.pr_type, sctp4_seqpacket.pr_protocol, inetdomain);
err |= net_del_proto(sctp4_stream.pr_type, sctp4_stream.pr_protocol, inetdomain);
#ifdef INET6
err |= net_del_proto(sctp6_seqpacket.pr_type, sctp6_seqpacket.pr_protocol, inet6domain);
err |= net_del_proto(sctp6_stream.pr_type, sctp6_stream.pr_protocol, inet6domain);
#endif
#endif
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
lck_rw_unlock_exclusive(SCTP_BASE_INFO(sctbinfo).mtx);
#else
lck_rw_unlock_exclusive(SCTP_BASE_INFO(sctbinfo).ipi_lock);
#endif
sctp_finish();
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
#ifdef INET6
lck_mtx_unlock(inet6domain.dom_mtx);
#endif
lck_mtx_unlock(inetdomain.dom_mtx);
#else
domain_guard_release(guard);
#endif
if (err) {
SCTP_PRINTF("SCTP NKE: Not all protocol handlers could be removed.\n");
return (KERN_FAILURE);
} else {
SCTP_PRINTF("SCTP NKE: NKE unloaded.\n");
return (KERN_SUCCESS);
}
}