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
|
/*
*
* ===================================
* HARP | Host ATM Research Platform
* ===================================
*
*
* This Host ATM Research Platform ("HARP") file (the "Software") is
* made available by Network Computing Services, Inc. ("NetworkCS")
* "AS IS". NetworkCS does not provide maintenance, improvements or
* support of any kind.
*
* NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
* INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
* SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
* In no event shall NetworkCS be responsible for any damages, including
* but not limited to consequential damages, arising from or relating to
* any use of the Software or related support.
*
* Copyright 1994-1998 Network Computing Services, Inc.
*
* Copies of this Software may be made, however, the above copyright
* notice must be reproduced on all copies.
*
* @(#) $FreeBSD$
*
*/
/*
* IP Over ATM Support
* -------------------
*
* Support for running as a loadable kernel module
*
*/
#ifndef ATM_IP_MODULE
#include "opt_atm.h"
#endif
#include <netatm/kern_include.h>
#include <netatm/ipatm/ipatm.h>
#include <netatm/ipatm/ipatm_var.h>
#ifndef lint
__RCSID("@(#) $FreeBSD$");
#endif
/*
* Global variables
*/
int ipatm_vccnt = 0;
int ipatm_vcidle = IPATM_VCIDLE;
int ipatm_print = 0;
u_long last_map_ipdst = 0;
struct ipvcc* last_map_ipvcc = NULL;
struct ip_nif *ipatm_nif_head = NULL;
struct ipatm_stat ipatm_stat = {0};
struct atm_time ipatm_itimer = {0, 0}; /* VCC idle timer */
Atm_endpoint ipatm_endpt = {
NULL,
ENDPT_IP,
ipatm_ioctl,
ipatm_getname,
ipatm_connected,
ipatm_cleared,
ipatm_incoming,
NULL,
NULL,
NULL,
ipatm_cpcs_data,
NULL,
NULL,
NULL,
NULL
};
struct sp_info ipatm_vcpool = {
"ipatm vcc pool", /* si_name */
sizeof(struct ipvcc), /* si_blksiz */
10, /* si_blkcnt */
100 /* si_maxallow */
};
struct sp_info ipatm_nifpool = {
"ipatm nif pool", /* si_name */
sizeof(struct ip_nif), /* si_blksiz */
5, /* si_blkcnt */
52 /* si_maxallow */
};
/*
* Local functions
*/
static int ipatm_start __P((void));
static int ipatm_stop __P((void));
/*
* Local variables
*/
static struct atm_ncm ipatm_ncm = {
NULL,
AF_INET,
ipatm_ifoutput,
ipatm_nifstat
};
static struct ipatm_listener {
Atm_attributes attr;
Atm_connection *conn;
} ipatm_listeners[] = {
{
{ NULL, /* nif */
CMAPI_CPCS, /* api */
0, /* api_init */
0, /* headin */
0, /* headout */
{ /* aal */
T_ATM_PRESENT,
ATM_AAL5
},
{ /* traffic */
T_ATM_PRESENT,
{
{
T_ATM_ABSENT,
0,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_NO
},
{
T_ATM_ABSENT,
0,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_NO
},
T_YES
},
},
{ /* bearer */
T_ATM_ANY
},
{ /* bhli */
T_ATM_ABSENT
},
{ /* blli */
T_ATM_PRESENT,
T_ATM_ABSENT,
{
{
T_ATM_SIMPLE_ID,
},
{
T_ATM_ABSENT
}
}
},
{ /* llc */
T_ATM_PRESENT,
{
T_ATM_LLC_SHARING,
IPATM_LLC_LEN,
IPATM_LLC_HDR
}
},
{ /* called */
T_ATM_ANY
},
{ /* calling */
T_ATM_ANY
},
{ /* qos */
T_ATM_PRESENT,
{
T_ATM_NETWORK_CODING,
{
T_ATM_QOS_CLASS_0,
},
{
T_ATM_QOS_CLASS_0
}
}
},
{ /* transit */
T_ATM_ANY
},
{ /* cause */
T_ATM_ABSENT
},
},
NULL
},
{
{ NULL, /* nif */
CMAPI_CPCS, /* api */
0, /* api_init */
0, /* headin */
0, /* headout */
{ /* aal */
T_ATM_PRESENT,
ATM_AAL5
},
{ /* traffic */
T_ATM_PRESENT,
{
{
T_ATM_ABSENT,
0,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_NO
},
{
T_ATM_ABSENT,
0,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_NO
},
T_YES
},
},
{ /* bearer */
T_ATM_ANY
},
{ /* bhli */
T_ATM_ABSENT
},
{ /* blli */
T_ATM_ABSENT,
T_ATM_ABSENT
},
{ /* llc */
T_ATM_ABSENT
},
{ /* called */
T_ATM_ANY
},
{ /* calling */
T_ATM_ANY
},
{ /* qos */
T_ATM_PRESENT,
{
T_ATM_NETWORK_CODING,
{
T_ATM_QOS_CLASS_0,
},
{
T_ATM_QOS_CLASS_0
}
}
},
{ /* transit */
T_ATM_ANY
},
{ /* cause */
T_ATM_ABSENT
},
},
NULL
},
{
{ NULL, /* nif */
CMAPI_CPCS, /* api */
0, /* api_init */
0, /* headin */
0, /* headout */
{ /* aal */
T_ATM_PRESENT,
ATM_AAL3_4
},
{ /* traffic */
T_ATM_PRESENT,
{
{
T_ATM_ABSENT,
0,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_NO
},
{
T_ATM_ABSENT,
0,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_ATM_ABSENT,
T_NO
},
T_YES
},
},
{ /* bearer */
T_ATM_ANY
},
{ /* bhli */
T_ATM_ABSENT
},
{ /* blli */
T_ATM_ABSENT,
T_ATM_ABSENT
},
{ /* llc */
T_ATM_ABSENT
},
{ /* called */
T_ATM_ANY
},
{ /* calling */
T_ATM_ANY
},
{ /* qos */
T_ATM_PRESENT,
{
T_ATM_NETWORK_CODING,
{
T_ATM_QOS_CLASS_0,
},
{
T_ATM_QOS_CLASS_0
}
}
},
{ /* transit */
T_ATM_ANY
},
{ /* cause */
T_ATM_ABSENT
},
},
NULL
},
};
static struct t_atm_cause ipatm_cause = {
T_ATM_ITU_CODING,
T_ATM_LOC_USER,
T_ATM_CAUSE_UNSPECIFIED_NORMAL,
{0, 0, 0, 0}
};
/*
* Initialize ipatm processing
*
* This will be called during module loading. We'll just register
* ourselves and wait for the packets to start flying.
*
* Arguments:
* none
*
* Returns:
* 0 startup was successful
* errno startup failed - reason indicated
*
*/
static int
ipatm_start()
{
struct atm_pif *pip;
struct atm_nif *nip;
int err, s, i;
/*
* Verify software version
*/
if (atm_version != ATM_VERSION) {
log(LOG_ERR, "version mismatch: ipatm=%d.%d kernel=%d.%d\n",
ATM_VERS_MAJ(ATM_VERSION), ATM_VERS_MIN(ATM_VERSION),
ATM_VERS_MAJ(atm_version), ATM_VERS_MIN(atm_version));
return (EINVAL);
}
/*
* Register ourselves as a network convergence module
*/
err = atm_netconv_register(&ipatm_ncm);
if (err)
goto done;
/*
* Register ourselves as an ATM endpoint
*/
err = atm_endpoint_register(&ipatm_endpt);
if (err)
goto done;
/*
* Get current system configuration
*/
s = splnet();
for (pip = atm_interface_head; pip; pip = pip->pif_next) {
/*
* Process each network interface
*/
for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
struct ifnet *ifp = (struct ifnet *)nip;
struct in_ifaddr *ia;
/*
* Attach interface
*/
err = ipatm_nifstat(NCM_ATTACH, nip, 0);
if (err) {
(void) splx(s);
goto done;
}
/*
* If IP address has been set, register it
*/
TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) {
if (ia->ia_ifp == ifp)
break;
}
if (ia) {
err = ipatm_nifstat(NCM_SETADDR, nip, (int)ia);
if (err) {
(void) splx(s);
goto done;
}
}
}
}
(void) splx(s);
/*
* Fill in union fields
*/
ipatm_aal5llc.aal.v.aal5.forward_max_SDU_size =
ATM_NIF_MTU + IPATM_LLC_LEN;
ipatm_aal5llc.aal.v.aal5.backward_max_SDU_size =
ATM_NIF_MTU + IPATM_LLC_LEN;
ipatm_aal5llc.aal.v.aal5.SSCS_type = T_ATM_NULL;
ipatm_aal5llc.blli.v.layer_2_protocol.ID.simple_ID = T_ATM_BLLI2_I8802;
ipatm_aal5null.aal.v.aal5.forward_max_SDU_size = ATM_NIF_MTU;
ipatm_aal5null.aal.v.aal5.backward_max_SDU_size = ATM_NIF_MTU;
ipatm_aal5null.aal.v.aal5.SSCS_type = T_ATM_NULL;
ipatm_aal4null.aal.v.aal4.forward_max_SDU_size = ATM_NIF_MTU;
ipatm_aal4null.aal.v.aal4.backward_max_SDU_size = ATM_NIF_MTU;
ipatm_aal4null.aal.v.aal4.SSCS_type = T_ATM_NULL;
ipatm_aal4null.aal.v.aal4.mid_low = 0;
ipatm_aal4null.aal.v.aal4.mid_high = 1023;
/*
* Listen for incoming calls
*/
for (i = 0;
i < (sizeof(ipatm_listeners) / sizeof(struct ipatm_listener));
i++) {
struct attr_aal *aalp = &ipatm_listeners[i].attr.aal;
int maxsdu = ATM_NIF_MTU;
/*
* Fill in union fields
*/
if (ipatm_listeners[i].attr.blli.tag_l2 == T_ATM_PRESENT) {
struct t_atm_blli *bp = &ipatm_listeners[i].attr.blli.v;
bp->layer_2_protocol.ID.simple_ID = T_ATM_BLLI2_I8802;
maxsdu += IPATM_LLC_LEN;
}
if (aalp->type == ATM_AAL5) {
aalp->v.aal5.forward_max_SDU_size = maxsdu;
aalp->v.aal5.backward_max_SDU_size = maxsdu;
aalp->v.aal5.SSCS_type = T_ATM_NULL;
} else {
aalp->v.aal4.forward_max_SDU_size = maxsdu;
aalp->v.aal4.backward_max_SDU_size = maxsdu;
aalp->v.aal4.SSCS_type = T_ATM_NULL;
aalp->v.aal4.mid_low = 0;
aalp->v.aal4.mid_high = 1023;
}
/*
* Now start listening
*/
if ((err = atm_cm_listen(&ipatm_endpt, (void *)i,
&ipatm_listeners[i].attr,
&ipatm_listeners[i].conn)) != 0)
goto done;
}
/*
* Start background VCC idle timer
*/
atm_timeout(&ipatm_itimer, IPATM_IDLE_TIME, ipatm_itimeout);
done:
return (err);
}
/*
* Halt ipatm processing
*
* This will be called just prior to unloading the module from
* memory. All IP VCCs must be terminated before the protocol can
* be shutdown.
*
* Arguments:
* none
*
* Returns:
* 0 shutdown was successful
* errno shutdown failed - reason indicated
*
*/
static int
ipatm_stop()
{
struct ip_nif *inp;
int err = 0, i;
int s = splnet();
/*
* Any VCCs still open??
*/
if (ipatm_vccnt) {
/* Yes, can't stop now */
err = EBUSY;
goto done;
}
/*
* Kill VCC idle timer
*/
(void) atm_untimeout(&ipatm_itimer);
/*
* Stop listening for incoming calls
*/
for (i = 0;
i < (sizeof(ipatm_listeners) / sizeof(struct ipatm_listener));
i++) {
if (ipatm_listeners[i].conn != NULL) {
(void) atm_cm_release(ipatm_listeners[i].conn,
&ipatm_cause);
}
}
/*
* Detach all our interfaces
*/
while ((inp = ipatm_nif_head) != NULL) {
(void) ipatm_nifstat(NCM_DETACH, inp->inf_nif, 0);
}
/*
* De-register from system
*/
(void) atm_netconv_deregister(&ipatm_ncm);
(void) atm_endpoint_deregister(&ipatm_endpt);
/*
* Free up our storage pools
*/
atm_release_pool(&ipatm_vcpool);
atm_release_pool(&ipatm_nifpool);
done:
(void) splx(s);
return (err);
}
#ifdef ATM_IP_MODULE
/*
*******************************************************************
*
* Loadable Module Support
*
*******************************************************************
*/
static int ipatm_doload __P((void));
static int ipatm_dounload __P((void));
/*
* Generic module load processing
*
* This function is called by an OS-specific function when this
* module is being loaded.
*
* Arguments:
* none
*
* Returns:
* 0 load was successful
* errno load failed - reason indicated
*
*/
static int
ipatm_doload()
{
int err = 0;
/*
* Start us up
*/
err = ipatm_start();
if (err)
/* Problems, clean up */
(void)ipatm_stop();
return (err);
}
/*
* Generic module unload processing
*
* This function is called by an OS-specific function when this
* module is being unloaded.
*
* Arguments:
* none
*
* Returns:
* 0 unload was successful
* errno unload failed - reason indicated
*
*/
static int
ipatm_dounload()
{
int err = 0;
/*
* OK, try to clean up our mess
*/
err = ipatm_stop();
return (err);
}
#include <sys/exec.h>
#include <sys/sysent.h>
#include <sys/lkm.h>
/*
* Loadable miscellaneous module description
*/
MOD_MISC(ipatm);
/*
* Loadable module support "load" entry point
*
* This is the routine called by the lkm driver whenever the
* modload(1) command is issued for this module.
*
* Arguments:
* lkmtp pointer to lkm drivers's structure
* cmd lkm command code
*
* Returns:
* 0 command was successful
* errno command failed - reason indicated
*
*/
static int
ipatm_load(lkmtp, cmd)
struct lkm_table *lkmtp;
int cmd;
{
return(ipatm_doload());
}
/*
* Loadable module support "unload" entry point
*
* This is the routine called by the lkm driver whenever the
* modunload(1) command is issued for this module.
*
* Arguments:
* lkmtp pointer to lkm drivers's structure
* cmd lkm command code
*
* Returns:
* 0 command was successful
* errno command failed - reason indicated
*
*/
static int
ipatm_unload(lkmtp, cmd)
struct lkm_table *lkmtp;
int cmd;
{
return(ipatm_dounload());
}
/*
* Loadable module support entry point
*
* This is the routine called by the lkm driver for all loadable module
* functions for this driver. This routine name must be specified
* on the modload(1) command. This routine will be called whenever the
* modload(1), modunload(1) or modstat(1) commands are issued for this
* module.
*
* Arguments:
* lkmtp pointer to lkm drivers's structure
* cmd lkm command code
* ver lkm version
*
* Returns:
* 0 command was successful
* errno command failed - reason indicated
*
*/
int
ipatm_mod(lkmtp, cmd, ver)
struct lkm_table *lkmtp;
int cmd;
int ver;
{
MOD_DISPATCH(ipatm, lkmtp, cmd, ver,
ipatm_load, ipatm_unload, lkm_nullcmd);
}
#else /* !ATM_IP_MODULE */
/*
*******************************************************************
*
* Kernel Compiled Module Support
*
*******************************************************************
*/
static void ipatm_doload __P((void *));
SYSINIT(atmipatm, SI_SUB_PROTO_END, SI_ORDER_ANY, ipatm_doload, NULL)
/*
* Kernel initialization
*
* Arguments:
* arg Not used
*
* Returns:
* none
*
*/
static void
ipatm_doload(void *arg)
{
int err = 0;
/*
* Start us up
*/
err = ipatm_start();
if (err) {
/* Problems, clean up */
(void)ipatm_stop();
log(LOG_ERR, "IP over ATM unable to initialize (%d)!!\n", err);
}
return;
}
#endif /* ATM_IP_MODULE */
|