Loading...
   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
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
/*
 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
 *
 * @APPLE_LICENSE_HEADER_START@
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Apple Public Source License
 * Version 2.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://www.opensource.apple.com/apsl/ and read it before using this
 * file.
 * 
 * The Original Code and all software distributed under the License are
 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 * Please see the License for the specific language governing rights and
 * limitations under the License.
 * 
 * @APPLE_LICENSE_HEADER_END@
 */
/*
 *	Copyright (c) 1988, 1989, 1993-1998 Apple Computer, Inc. 
 */

/* at_elap.c: 2.0, 1.29; 10/4/93; Apple Computer, Inc. */

/* This is the file which implements all the streams driver 
 * functionality required for EtherTalk.
 */

/* revision history 

 03-14-94  jjs 	Changed all functions which assumed only one port would
 		ever be used.  Added validate_msg_size, changed elap_online
		to work with the h/w name only (e.g. 'et2').

 Modified for MP, 1996 by Tuyen Nguyen
 Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.

*/

#define RESOLVE_DBG				/* for debug.h global resolution */
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <machine/spl.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/filedesc.h>
#include <sys/fcntl.h>
#include <sys/mbuf.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <sys/socketvar.h>
#include <sys/malloc.h>
#include <sys/domain.h>
#include <sys/sockio.h>
#include <vm/vm_kern.h>         /* for kernel_map */


#include <net/if.h>
#include <net/if_types.h>

#include <netat/sysglue.h>
#include <netat/appletalk.h>
#include <netat/at_var.h>
#include <netat/ddp.h>
#include <netat/lap.h>
#include <netat/routing_tables.h>     /* rtmp+zip table structs  */
#include <netat/zip.h>
#include <netat/nbp.h>
#include <netat/at_snmp.h>
#include <netat/at_pcb.h>
#include <netat/at_aarp.h>
#include <netat/asp.h>
#include <netat/atp.h>
#include <netat/debug.h>
#include <netat/adsp.h>
#include <netat/adsp_internal.h>

#include <sys/kern_event.h>

/* globals */

at_ifaddr_t at_interfaces[IF_TOTAL_MAX];
	/* index for at_interfaces is not important */
at_ifaddr_t  *ifID_table[IF_TOTAL_MAX];
	/* the table of ifID structures, one per interface 
	   (not just ethernet), 
	 * NOTE: for MH, entry 0 in this table is 
	 *       now defined to be the default I/F
	 */
at_ifaddr_t  *ifID_home;
	/* always ifID_table[IFID_HOME] for now, but will be used for
	   dynamic "home port" assignment, later */

at_state_t at_state;		/* global state of AT network */
snmpFlags_t snmpFlags;

int xpatcnt = 0;

/* snmp defines */
#define MAX_BUFSIZE	8192   
#define MAX_RTMP	(MAX_BUFSIZE/sizeof(RT_entry)-1)
#define MAX_NBP 		\
	((MAX_BUFSIZE - SNMP_NBP_HEADER_SIZE)/sizeof(snmpNbpEntry_t)-1)
#define MAX_NBP_BYTES	(MAX_NBP * sizeof(snmpNbpEntry_t))
#define MAX_ZIP		(MAX_BUFSIZE/sizeof(ZT_entry)-1)
#define MAX_RTMP_BYTES	(MAX_RTMP * sizeof(RT_entry))
#define MAX_ZIP_BYTES	(MAX_ZIP * sizeof(ZT_entry))

/* externs */
extern TAILQ_HEAD(name_registry, _nve_) name_registry;
extern snmpStats_t	snmpStats;
extern atlock_t ddpinp_lock;
extern atlock_t arpinp_lock;
extern short appletalk_inited;
extern int adspInited;
extern struct atpcb ddp_head;
extern gref_t *atp_inputQ[];
extern struct atp_state *atp_used_list;
extern asp_scb_t *asp_scbQ[];
extern asp_scb_t *scb_used_list;
extern CCB *adsp_inputQ[];
extern CCB *ccb_used_list;
extern at_ddp_stats_t at_ddp_stats;
extern lck_mtx_t * atalk_mutex;

/* protos */
extern snmpAarpEnt_t * getAarp(int *);
extern void nbp_shutdown(), routershutdown(), ddp_brt_shutdown();
extern void ddp_brt_init(), rtmp_init(), rtmp_input();
extern rtmp_router_start(at_kern_err_t *);
static void getIfNames(at_ifnames_t *);
static void add_route();
static int set_zones();
void elap_offline();
static int elap_online1(), re_aarp();
int at_reg_mcast(), at_unreg_mcast();
void  AARPwakeup(), ZIPwakeup();
static void elap_hangup();
static getSnmpCfg();

at_ifaddr_t *find_ifID(if_name)
	char	*if_name;
{
	int pat_id;
	  
	if (strlen(if_name))
		for (pat_id=0; pat_id < xpatcnt; pat_id++) {
			if (!strcmp(at_interfaces[pat_id].ifName, if_name))
				return(&at_interfaces[pat_id]);
		}

	return((at_ifaddr_t *)NULL);
}

static int validate_msg_size(m, gref, elapp)
	register gbuf_t *m;
	gref_t		*gref;
	at_ifaddr_t **elapp;

/* checks ioctl message type for minimum expected message size & 
   sends error back if size invalid
*/
{
	register ioc_t *iocbp;
	register at_if_cfg_t *cfgp;
	int i = 0, size = 1;
	
	*elapp = NULL;		
	iocbp = (ioc_t *) gbuf_rptr(m);

	dPrintf(D_M_ELAP, D_L_INFO, ("validate_msg_size: ioc_cmd = %d\n", 
				     iocbp->ioc_cmd));
	switch (iocbp->ioc_cmd) {
		case LAP_IOC_ADD_ROUTE:
			size = sizeof(RT_entry);
			break;
		case LAP_IOC_GET_ROUTE:
			size = sizeof(RT_entry);
			break;
		case LAP_IOC_GET_ZONE:
			size = sizeof(ZT_entryno);
			break;
		case LAP_IOC_SNMP_GET_CFG:
		case LAP_IOC_SNMP_GET_AARP:
		case LAP_IOC_SNMP_GET_ZIP:
		case LAP_IOC_SNMP_GET_RTMP:
		case LAP_IOC_SNMP_GET_NBP:
			size = sizeof(int);
			break;

		case ELAP_IOC_GET_STATS:
		case LAP_IOC_SNMP_GET_DDP:
			size = 0;
			break;

		default:
			dPrintf(D_M_ELAP, D_L_ERROR, ("validate_msg_size: unknown ioctl\n"));
			goto error;
	}

	if (size == 0) {				/* a non-data ioctl */
		return(0);
	}

	if (gbuf_cont(m) != NULL)
		i = gbuf_len(gbuf_cont(m));
	if (iocbp->ioc_count < size || (gbuf_cont(m) == NULL) || i < size) {
		dPrintf(D_M_ELAP, D_L_ERROR,
			("ioctl msg error:s:%d c:%d bcont:%c delta:%d\n",
			 size, iocbp->ioc_count,
			 gbuf_cont(m)? 'Y' : 'N', i));
		goto error;
	}
	else
		return(0);
error:
	ioc_ack(EMSGSIZE, m, gref);
	return (EMSGSIZE);
} /* validate_msg_size */

int lap_online(elapp, cfgp)
     at_ifaddr_t *elapp;
     at_if_cfg_t *cfgp;
{
	int error;

	if (elapp->ifState != LAP_OFFLINE) {
		return(EALREADY);
	}

	elapp->flags = 0;
	if (cfgp->flags & ELAP_CFG_HOME) {
		if (ifID_home)  {
			/* only 1 home allowed! */
			return(EEXIST);
		}
		dPrintf(D_M_ELAP, D_L_STARTUP, 
			("elap_wput home I/F:%s\n", cfgp->ifr_name));
		elapp->flags |= ELAP_CFG_HOME;
	}

	if (MULTIPORT_MODE) {
		elapp->flags |= ELAP_CFG_ZONELESS;
		if (ROUTING_MODE && cfgp->netStart)
			elapp->flags |= ELAP_CFG_SEED;
	}

	if (!DEFAULT_ZONE(&cfgp->zonename) &&
	    (elapp->flags & ELAP_CFG_HOME) || MULTIHOME_MODE) {
		elapp->startup_zone = cfgp->zonename;
	}

	if (elapp->flags & ELAP_CFG_SEED) {
		dPrintf(D_M_ELAP, D_L_STARTUP_INFO,
			("elap_wput: found to be seed\n"));
		elapp->ifThisCableStart = cfgp->netStart;
		elapp->ifThisCableEnd   = cfgp->netEnd;
	}
	else {
		dPrintf(D_M_ELAP,D_L_ERROR, 
			("elap_wput: we believe we're not seed\n"));
		/* from ELAP_IOC_SET_CFG */
		if (ATALK_VALUE(cfgp->node)) {
			u_short	initial_net;
			u_char	initial_node;

			initial_node = cfgp->node.s_node;
			initial_net = cfgp->node.s_net;
			if ((initial_node<0xfe) && (initial_node>0) &&
			    !((initial_net == 0) ||
			      ((initial_net >= DDP_STARTUP_LOW)&&
			       (initial_net <= DDP_STARTUP_HIGH)))) {

				elapp->initial_addr = cfgp->node;
			}
		}
	}

	elapp->startup_error = 0;
	elapp->startup_inprogress = FALSE;
	if ((error = elap_online1(elapp)))
		ddp_rem_if(elapp);
	else 
		if (!(MULTIPORT_MODE) &&
		    elapp->ifZoneName.len == 1 &&
		    elapp->ifZoneName.str[0] == '*' &&
		    !DEFAULT_ZONE(&cfgp->zonename)) {
			nbp_add_multicast(&cfgp->zonename, elapp);
		}
	return(error);
} /* lap_online */

/***********************************************************************
 * elap_wput()
 *
 **********************************************************************/
int elap_wput(gref, m)
     gref_t *gref;
     register gbuf_t	*m;
{
	at_ifaddr_t 	*elapp;
	register ioc_t		*iocbp;
	register at_if_cfg_t	*cfgp;
	at_elap_stats_t		*statsp;
	int 		i;
	int			(*func)();
	gbuf_t		*tmpm;
	at_ifaddr_t *patp;


	switch (gbuf_type(m)) {
	case MSG_DATA:
		gbuf_freem(m);
		dPrintf(D_M_ELAP,D_L_ERROR,
	       		("Output data to control channel is ignored\n"));
	break;

	case MSG_IOCTL:
		iocbp = (ioc_t *) gbuf_rptr(m);

	        if (validate_msg_size(m, gref, &elapp))
			break;	

		if (elapp)
			cfgp = (at_if_cfg_t*) gbuf_rptr(gbuf_cont(m));

		if (LAP_IOC_MYIOCTL(iocbp->ioc_cmd) || 
		    ELAP_IOC_MYIOCTL(iocbp->ioc_cmd)) {

			switch (iocbp->ioc_cmd) {
			case ELAP_IOC_GET_STATS:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_GET_STATS\n");
#endif
				if ( (gbuf_cont(m) == NULL)
				     || (elapp = find_ifID(gbuf_rptr(gbuf_cont(m)))) == NULL) {
					ioc_ack(EINVAL, m, gref);
					break;
				}
				gbuf_freem(gbuf_cont(m));
				if ((gbuf_cont(m) =gbuf_alloc(sizeof(at_elap_stats_t), 
			    		PRI_MED)) == NULL) {
					ioc_ack(ENOBUFS, m, gref);
					break;
				}
				statsp = ((at_elap_stats_t *)gbuf_rptr(gbuf_cont(m)));
				*statsp = elapp->stats;
				gbuf_wset(gbuf_cont(m),sizeof(at_elap_stats_t));
				iocbp->ioc_count = sizeof(at_elap_stats_t);
				ioc_ack(0, m, gref);
				break;

			case LAP_IOC_ADD_ROUTE:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_ADD_ROUTE\n");
#endif
				add_route((RT_entry *)gbuf_rptr(gbuf_cont(m)));
				ioc_ack(0, m, gref);
				break;

			case LAP_IOC_GET_ZONE:
#ifdef APPLETALK_DEBUG
			  kprintf("LAP_IOC_GET_ZONE\n");
#endif
			  /* return next ZT_entryno from ZT_table 
			     a pointer to the struct ZT_entryno is passed down from
			     user space and the first byte is cast to a int, if
			     this int is non-zero, then the first ZT_entry is
			     returned and subsequent calls with a zero value
			     will return the next entry in the table. The next
			     read after the last valid entry will return EINVAL
			  */
			{
				ZT_entryno *pZTe;

				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;

				pZTe = zt_getNextZone(i);
				if (pZTe) {
					if ((gbuf_cont(m) = gbuf_alloc(sizeof(ZT_entryno), PRI_MED)) == NULL) {
						ioc_ack(ENOBUFS, m, gref);
						break;
					}	
					*(ZT_entryno *)gbuf_rptr(gbuf_cont(m)) = *pZTe;
					gbuf_wset(gbuf_cont(m),sizeof(ZT_entryno));
					iocbp->ioc_count = sizeof(ZT_entryno);
					ioc_ack(0, m, gref);
				}
				else
					ioc_ack(EINVAL, m, gref);
			}
				break;

			case LAP_IOC_GET_ROUTE:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_GET_ROUTE\n");
#endif
				/* return next RT_entry from RT_table 
				 * a pointer to the struct RT_entry is
				 * passed down from user space and the first
				 * byte is cast to a int, if this int is
				 * non-zero, then the first RT_entry is
				 * returned and subsequent calls with a
				 * zero value will return the next entry in
				 * the table. The next read after the last
				 * valid entry will return EINVAL
				 */
			{
				RT_entry *pRT;

				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;

				pRT = rt_getNextRoute(i);
				if (pRT) {
					if ((gbuf_cont(m) = gbuf_alloc(sizeof(RT_entry), PRI_MED)) == NULL) {
						ioc_ack(ENOBUFS, m, gref);
						break;
					}	
					*(RT_entry *)gbuf_rptr(gbuf_cont(m)) = *pRT;
					gbuf_wset(gbuf_cont(m),sizeof(RT_entry));
					iocbp->ioc_count = sizeof(RT_entry);
					ioc_ack(0, m, gref);
				}
				else
					ioc_ack(EINVAL, m, gref);
			}
				break;
			
			case LAP_IOC_SNMP_GET_DDP:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_SNMP_GET_DDP\n");
#endif
				if (!(at_state.flags & AT_ST_STARTED)) {
					ioc_ack(ENOTREADY, m, gref);
					break;
				}
				if ((gbuf_cont(m) = gbuf_alloc(sizeof(snmpStats_t), 
						PRI_MED)) == NULL) {
					ioc_ack(ENOBUFS, m, gref);
					break;
				}
				
				*(snmpStats_t *)gbuf_rptr(gbuf_cont(m)) = snmpStats;
				gbuf_wset(gbuf_cont(m),sizeof(snmpStats));
				iocbp->ioc_count = sizeof(snmpStats);
				ioc_ack(0, m, gref);
				break;
			case LAP_IOC_SNMP_GET_CFG:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_SNMP_GET_CFG\n");
#endif
			{
				int i,size;
				snmpCfg_t 	snmp;

				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;
				if (!(at_state.flags & AT_ST_STARTED)) {
					/* if stack down */
					iocbp->ioc_count = 0;
					ioc_ack(ENOTREADY, m, gref);
					dPrintf(D_M_ELAP_LOW, D_L_INFO,
						("elap_wput: cfg req, stack down\n"));
					break;
				}
				if (i == UPDATE_IF_CHANGED && 
					!(at_state.flags & AT_ST_IF_CHANGED)) {
					iocbp->ioc_count = 0;
					ioc_ack(0, m, gref);
					dPrintf(D_M_ELAP_LOW, D_L_INFO,
						("elap_wput: cfg req, unchanged\n"));
					break;
				}
				dPrintf(D_M_ELAP_LOW, D_L_INFO,
					("elap_wput: cfg req, changed\n"));

				if (getSnmpCfg(&snmp)) {
					dPrintf(D_M_ELAP,D_L_ERROR,
						("elap_wput:SNMP_GET_CFG error\n"));
					ioc_ack(EOPNOTSUPP, m, gref);
					break;
				}
					/* send up only used part of table */
				size = sizeof(snmp) - 
					   sizeof(snmpIfCfg_t) * (MAX_IFS - snmp.cfg_ifCnt);

				if ((gbuf_cont(m) = gbuf_alloc(size, PRI_MED)) == NULL) {
					ioc_ack(ENOBUFS, m, gref);
					break;
				}
				bcopy(&snmp,gbuf_rptr(gbuf_cont(m)),size);
				gbuf_wset(gbuf_cont(m),size);
				iocbp->ioc_count = size;
				at_state.flags &= ~AT_ST_IF_CHANGED;
				ioc_ack(0, m, gref);
			}
			break;

			case LAP_IOC_SNMP_GET_AARP:
			{
				snmpAarpEnt_t *snmpp;
				int bytes;
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_SNMP_GET_AARP\n");
#endif
				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;
				dPrintf(D_M_ELAP,D_L_INFO,
					("elap_wput:calling getarp,i=%d\n", i));
				snmpp = getAarp(&i); 
				bytes = i * sizeof(snmpAarpEnt_t);
				dPrintf(D_M_ELAP,D_L_INFO,
					("elap_wput:getarp returned, i=%d,bytes=%d\n", 
					i, bytes));
				if (snmpp) {
					if ((gbuf_cont(m) = gbuf_alloc(bytes, PRI_MED)) == NULL) {
						ioc_ack(ENOBUFS, m, gref);
						break;
					}	
					bcopy(snmpp, gbuf_rptr(gbuf_cont(m)), bytes);
					gbuf_wset(gbuf_cont(m),bytes);
					iocbp->ioc_count = bytes;
					ioc_ack(0, m, gref);
				}
				else
					ioc_ack(EOPNOTSUPP, m, gref);
			}
			break;

			case LAP_IOC_SNMP_GET_ZIP:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_SNMP_GET_ZIP\n");
#endif
			{ /* matching brace NOT in this case */
				register int i,j;
				register int size, total, tabsize;
				gbuf_t	*mn;		/* new gbuf */
				gbuf_t	*mo;		/* old gbuf */
				gbuf_t	*mt;		/* temp */
				snmpNbpTable_t		*nbp;

				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;
				if (!(at_state.flags & AT_ST_STARTED)) {
					ioc_ack(ENOTREADY, m, gref);
					break;
				}
				if (i == UPDATE_IF_CHANGED && 
					!(at_state.flags & AT_ST_ZT_CHANGED)) {
					iocbp->ioc_count = 0;
					ioc_ack(0, m, gref);
					break;
				}
				mo=(gbuf_t*)NULL;
				tabsize = getZipTableSize();

					/* retrieve table into multiple gbufs */
				for (i =0; i<tabsize;  i+=j) {
					j = tabsize - i > 
						MAX_ZIP ? MAX_ZIP : tabsize - i;
					size = j < MAX_ZIP ? sizeof(ZT_entry)*j : MAX_ZIP_BYTES;
					if ((mn = gbuf_alloc(size, PRI_MED)) == NULL) {
						if (gbuf_cont(m))
							gbuf_freem(gbuf_cont(m));
						ioc_ack(ENOBUFS, m, gref);
						break;
					}
					if (!mo)	{ 		/* if first new one */
						mt = mn;
						total = size;
					}
					else {
						gbuf_cont(mo) = mn;
						total += size;
					}
					mo = mn;
					getZipTable((ZT_entry*)gbuf_rptr(mn),i,j); 
					gbuf_wset(mn,size);
				}
				if ((gbuf_cont(m) = gbuf_alloc(sizeof(int), PRI_MED)) == NULL) {
					if (mt)
						gbuf_freem(mt);
					iocbp->ioc_count = 0;
					ioc_ack(ENOBUFS, m, gref);
					break;
				}
				if (!tabsize) {
					dPrintf(D_M_ELAP,D_L_WARNING,
						("elap_wput:snmp: empty zip table\n"));
					total = 0;
				}
				*(int*)gbuf_rptr(gbuf_cont(m)) = total; 	/* return table size */
				gbuf_wset(gbuf_cont(m),sizeof(int));
				iocbp->ioc_count = sizeof(int);
				ioc_ack(0, m, gref);
				if (tabsize)
					atalk_putnext(gref,mt);		/* send up table */
				at_state.flags &= ~AT_ST_ZT_CHANGED;
				break;

			case LAP_IOC_SNMP_GET_RTMP:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_SNMP_GET_RTMP\n");
#endif
				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;
				if (!(at_state.flags & AT_ST_STARTED)) {
					ioc_ack(ENOTREADY, m, gref);
					break;
				}
				if (i == UPDATE_IF_CHANGED && 
				    !(at_state.flags & AT_ST_RT_CHANGED)) {
					iocbp->ioc_count = 0;
					ioc_ack(0, m, gref);
					break;
				}

				mo=(gbuf_t*)NULL;
				tabsize = getRtmpTableSize();

					/* retrieve table into multiple gbufs */
				for (i =0; i<tabsize;  i+=j) {
					j = tabsize - i > 
						MAX_RTMP ? MAX_RTMP : tabsize - i;
					size = j < MAX_RTMP ? sizeof(RT_entry)*j : MAX_RTMP_BYTES;
					if ((mn = gbuf_alloc(size, PRI_MED)) == NULL) {
						if (gbuf_cont(m))
							gbuf_freem(gbuf_cont(m));
						ioc_ack(ENOBUFS, m, gref);
						break;
					}
					if (!mo)	{ 		/* if first new one */
						mt = mn;
						total = size;
					}
					else {
						gbuf_cont(mo) = mn;
						total += size;
					}
					mo = mn;
					getRtmpTable((RT_entry*)gbuf_rptr(mn),i,j); 
					gbuf_wset(mn,size);
				}
				if ((gbuf_cont(m) = gbuf_alloc(sizeof(int), PRI_MED)) == NULL) {
					if (mt)
						gbuf_freem(mt);
					iocbp->ioc_count = 0;
					ioc_ack(ENOBUFS, m, gref);
					break;
				}
				if (!tabsize)
					total = 0;
				*(int*)gbuf_rptr(gbuf_cont(m)) = total;	/* return table size */
				gbuf_wset(gbuf_cont(m),sizeof(int));
				iocbp->ioc_count = sizeof(int);
				ioc_ack(0, m, gref);
				if (tabsize)
					atalk_putnext(gref,mt);		/* send up table */
				at_state.flags &= ~AT_ST_RT_CHANGED;
				break;

			case LAP_IOC_SNMP_GET_NBP:
#ifdef APPLETALK_DEBUG
				kprintf("LAP_IOC_SNMP_GET_NBP\n");
#endif
				i =  *(int *)gbuf_rptr(gbuf_cont(m));
				gbuf_freem(gbuf_cont(m));
				gbuf_cont(m) = NULL;
				if (!(at_state.flags & AT_ST_STARTED)) {
					ioc_ack(ENOTREADY, m, gref);
					break;
				}
				if (i == UPDATE_IF_CHANGED && 
				    !(at_state.flags & AT_ST_NBP_CHANGED)) {
					iocbp->ioc_count = 0;
					ioc_ack(0, m, gref);
					dPrintf(D_M_ELAP_LOW, D_L_INFO,
						("elap_wput: nbp req denied, no change\n"));
					break;
				}

				mo=(gbuf_t*)NULL;
				tabsize = getNbpTableSize();

					/* retrieve table into multiple gbufs */
				for (i =0; i<tabsize;  i+=j) {
					j = tabsize - i > 
						MAX_NBP ? MAX_NBP : tabsize - i;
					size = j < MAX_NBP ? sizeof(snmpNbpEntry_t)*j : MAX_NBP_BYTES;
					if (!i)
						size += SNMP_NBP_HEADER_SIZE;
					if ((mn = gbuf_alloc(size, PRI_MED)) == NULL) {
						if (gbuf_cont(m))
							gbuf_freem(gbuf_cont(m));
						ioc_ack(ENOBUFS, m, gref);
						break;
					}
					if (!mo)	{ 		/* if first new one */
						mt = mn;
						total = size;
						nbp = (snmpNbpTable_t*)gbuf_rptr(mn);
						nbp->nbpt_entries = tabsize;
						nbp->nbpt_zone = ifID_home->ifZoneName;
						getNbpTable(nbp->nbpt_table,i,j); 
					}
					else {
						gbuf_cont(mo) = mn;
						total += size;
						getNbpTable((snmpNbpEntry_t *)gbuf_rptr(mn),i,j); 
					}
					mo = mn;
					gbuf_wset(mn,size);
				}
				if ((gbuf_cont(m) = gbuf_alloc(sizeof(int), PRI_MED)) == NULL) {
					if (mt)
						gbuf_freem(mt);
					iocbp->ioc_count = 0;
					ioc_ack(ENOBUFS, m, gref);
					break;
				}
				if (!tabsize)
					total = 0;
				*(int*)gbuf_rptr(gbuf_cont(m)) = total;	/* return table size */
				gbuf_wset(gbuf_cont(m),sizeof(int));
				iocbp->ioc_count = sizeof(int);
				ioc_ack(0, m, gref);
				if (tabsize)
					atalk_putnext(gref,mt);		/* send up table */
				at_state.flags &= ~AT_ST_NBP_CHANGED;
				break;
			}
				
			default:
#ifdef APPLETALK_DEBUG
				kprintf("unknown ioctl %d\n", iocbp->ioc_cmd);
#endif
				ioc_ack(ENOTTY, m, gref);
				dPrintf(D_M_ELAP, D_L_WARNING,
					("elap_wput: unknown ioctl (%d)\n", iocbp->ioc_cmd));

				if (elapp)
					elapp->stats.unknown_mblks++;
				break;
			}
		}
		break;

	default:
		gbuf_freem(m);
		break;
	}

	return 0;
} /* elap_wput */


/* Called directly by ddp/zip.
 */
elap_dataput(m, elapp, addr_flag, addr)
     register	gbuf_t	*m;
     register at_ifaddr_t *elapp;
     u_char	addr_flag;
     char *addr;
{
	register int		size;
	int			error = 0;
	extern	int		zip_type_packet();
	struct	etalk_addr	dest_addr;
	struct	atalk_addr	dest_at_addr;
	extern	gbuf_t		*growmsg();
	int			loop = TRUE;
				/* flag to aarp to loopback (default) */

	/* the incoming frame is of the form {flag, address, ddp...}
	 * where "flag" indicates whether the address is an 802.3
	 * (link) address, or an appletalk address.  If it's an
	 * 802.3 address, the packet can just go out to the network
	 * through PAT, if it's an appletalk address, AT->802.3 address
	 * resolution needs to be done.
	 * If 802.3 address is known, strip off the flag and 802.3
	 * address, and prepend 802.2 and 802.3 headers.
	 */
	
	if (addr == NULL) {
		addr_flag = *(u_char *)gbuf_rptr(m);
		gbuf_rinc(m,1);
	}
	
	switch (addr_flag) {
	case AT_ADDR_NO_LOOP :
		loop = FALSE;
		/* pass thru */
	case AT_ADDR :
	if (addr == NULL) {
	    dest_at_addr = *(struct atalk_addr *)gbuf_rptr(m);
	    gbuf_rinc(m,sizeof(struct atalk_addr));
	} else
	    dest_at_addr = *(struct atalk_addr *)addr;
	    break;
	case ET_ADDR :
	if (addr == NULL) {
	    dest_addr = *(struct etalk_addr *)gbuf_rptr(m);
	    gbuf_rinc(m,sizeof(struct etalk_addr));
	} else
	    dest_addr = *(struct etalk_addr *)addr;
	    break;
	default :
	    gbuf_freel(m);		/* unknown address type, chuck it */
	    return(EINVAL);
        }

	m = gbuf_strip(m);

	/* At this point, rptr points to ddp header for sure */
	if (elapp->ifState == LAP_OFFLINE) {
	    gbuf_freel(m);
		return(ENETDOWN);
	}

	if (elapp->ifState == LAP_ONLINE_FOR_ZIP) {
		/* see if this is a ZIP packet that we need
		 * to let through even though network is
		 * not yet alive!!
		 */
		if (zip_type_packet(m) == 0) {
		    	gbuf_freel(m);
			return(ENETDOWN);
		}
	}
	
	elapp->stats.xmit_packets++;
	size = gbuf_msgsize(m);
	elapp->stats.xmit_bytes += size;
	snmpStats.dd_outLong++;
	
	switch (addr_flag) {
	case AT_ADDR_NO_LOOP :
	case AT_ADDR :
	    /*
	     * we don't want elap to be looking into ddp header, so
	     * it doesn't know net#, consequently can't do 
	     * AMT_LOOKUP.  That task left to aarp now.
	     */
	    error = aarp_send_data(m,elapp,&dest_at_addr, loop);
	    break;
	case ET_ADDR :
	    error = pat_output(elapp, m, &dest_addr, 0);
	    break;
        }
	return (error);
} /* elap_dataput */

/************************************************************************
 * elap_online()
 *
 ************************************************************************/

static int elap_online1(elapp)
     at_ifaddr_t *elapp;
{
	int errno;

	dPrintf(D_M_ELAP, D_L_STARTUP_INFO, ("elap_online:%s elapp:0x%x\n",
		(elapp->ifName) ? &elapp->ifName[0] : "NULL interface", (u_int) elapp));
	if (elapp->ifState != LAP_OFFLINE || elapp->startup_inprogress == TRUE)
	        return (EALREADY);
	
	at_state.flags |= AT_ST_IF_CHANGED;

	if (elapp->flags & ELAP_CFG_HOME) /* tell ddp_add_if if this is home */
		elapp->ifFlags |= AT_IFF_DEFAULT;
		
	/* Get DDP started */
	if ((errno = ddp_add_if(elapp)))
		return(errno);
	
	// check if we still have an interface - can be lost when
	// ddp_add_if calls malloc
	// need to make check here after ddp_add_if completes because 
	// lap_online will call ddp_rem_if if we fail here
	if (elapp->aa_ifp == 0)
		return ENOENT;
		
	/* set up multicast address for cable-wide broadcasts */
	(void)at_reg_mcast(elapp, (caddr_t)&elapp->cable_multicast_addr);

        // need to check again if interface is present
        // can be lost in at_reg_mcast
	if (elapp->aa_ifp == 0)
		return ENOENT;

	elapp->startup_inprogress = TRUE;
	if (! (elapp->startup_error = re_aarp(elapp))) {
		lck_mtx_assert(atalk_mutex, LCK_MTX_ASSERT_OWNED);
		(void)msleep(&elapp->startup_inprogress, atalk_mutex, PSOCK | PCATCH, 
			     "elap_online1", 0);
	}

	/* then later, after some timeouts AARPwakeup() is called */

	return(elapp->startup_error);
} /* elap_online1 */

static int re_aarp(elapp)
     at_ifaddr_t *elapp;
{
	int errno;

	/* We now call aarp_init() to assign an appletalk node addr */
	errno = aarp_init1(elapp);
			/* aarp_init1() returns either -1 or ENOTREADY */
	if (errno == ENOTREADY)
		return(0);
	else {
		dPrintf(D_M_ELAP, D_L_STATE_CHG, 
			("elap_online aarp_init for %s\n", elapp->ifName));
		(void)at_unreg_mcast(elapp, (caddr_t)&elapp->cable_multicast_addr);
		ddp_rem_if(elapp);
		elapp->ifState = LAP_OFFLINE;
		return(EADDRNOTAVAIL);
	}
}

/* called from AARPwakeup */
static void elap_online2(elapp)
     at_ifaddr_t *elapp;
{
	if (MULTIPORT_MODE) {
		dPrintf(D_M_ELAP,D_L_STARTUP_INFO, 
			("elap_online: re_aarp, we know it's a router...\n"));

		if (elapp->flags & ELAP_CFG_SEED) {
			/* add route table entry (zones to be added later) */
			dPrintf(D_M_ELAP, D_L_STARTUP_INFO,
				("elap_online: rt_insert Cable %d-%d port =%d as SEED\n",
				elapp->ifThisCableStart, elapp->ifThisCableEnd, elapp->ifPort));
			rt_insert(elapp->ifThisCableEnd,
				  elapp->ifThisCableStart,
				  0,0,0,
				  elapp->ifPort,
				  RTE_STATE_PERMANENT | RTE_STATE_ZKNOWN | RTE_STATE_GOOD
					 );
			/* LD 081694: set the RTR_SEED_PORT flag for seed ports */
			elapp->ifFlags |= RTR_SEED_PORT;
		}
		else 
			dPrintf(D_M_ELAP,D_L_STARTUP_INFO,
				("elap_online: it's a router, but non seed\n"));
	}

	if (elapp->flags & ELAP_CFG_ZONELESS) {
		/* ELAP_CFG_ZONELESS tells us that it is a router or in
		       multihome mode, so we don't want to do the GetNetInfo
		       exchange with the router.  */

		elapp->ifState = LAP_ONLINE_ZONELESS;
		elapp->startup_inprogress = FALSE;
		wakeup(&elapp->startup_inprogress);
		dPrintf(D_M_ELAP, D_L_STARTUP_INFO, ("elap_online: ack 3\n"));
		return;
	}

	/* if we don't already have a zone and a multicast address */
	if (*(int *)&elapp->ZoneMcastAddr == 0 || elapp->ifZoneName.len == 0) {
		/* hzonehash is a global containing the nbp hash for the startup_zone */
		sethzonehash(elapp);

		/* Get ZIP rolling to get zone multicast address, etc. */
		elapp->ifState = LAP_ONLINE_FOR_ZIP;
		(void)zip_control(elapp, ZIP_ONLINE);
		/* zip_control (w. control == ZIP_ONLINE) always returns ENOTREADY */

		/* later, after some timeouts ZIPwakeup() is called. */
	} else {
		/* otherwise, we have the zone and the multicast already,
		   so don't bother with another ZIP GetNetInfo request */
		ZIPwakeup(elapp, 0);
	}
} /* elap_online2 */

/* called from rtmp_router_start */
int elap_online3(elapp)
     at_ifaddr_t	*elapp;
{
	elapp->startup_inprogress = TRUE;

	/* just reset the net range */
	elapp->initial_addr.s_net = 0;
	elapp->initial_addr.s_node = 0;
	dPrintf(D_M_ELAP_LOW, D_L_STARTUP_INFO,
		("elap_online: goto re_aarp port=%d\n", elapp->ifPort));

	if ((elapp->startup_error = re_aarp(elapp)))
		return(elapp->startup_error);

	/* then later, after some timeouts AARPwakeup() is called */

	lck_mtx_assert(atalk_mutex, LCK_MTX_ASSERT_OWNED);
	(void)msleep(&elapp->startup_inprogress, atalk_mutex, PSOCK | PCATCH, 
		     "elap_online3", 0);
	return(elapp->startup_error);
} /* elap_online3 */

/****************************************************************************
 * elap_offline()
 *
 ****************************************************************************/

void elap_offline(elapp)
     register at_ifaddr_t *elapp;

{
	void	zip_sched_getnetinfo(); /* forward reference */
	int	errno;
	int s;

	dPrintf(D_M_ELAP, D_L_SHUTDN_INFO, ("elap_offline:%s\n", elapp->ifName));
	if (elapp->ifState != LAP_OFFLINE) {

		/* Since AppleTalk is going away, remove the cable
		 * multicast address  and turn the interface off so that all 
		 * AppleTalk packets are dropped in the driver itself.
		 * Get rid of the zone multicast address prior to going Offline.
		 */
		(void)at_unreg_mcast(elapp, (caddr_t)&elapp->ZoneMcastAddr);
		(void)at_unreg_mcast(elapp, (caddr_t)&elapp->cable_multicast_addr);
		elapp->ifState = LAP_OFFLINE;

		ATDISABLE(s, ddpinp_lock);
		if (MULTIPORT_MODE)
			RT_DELETE(elapp->ifThisCableEnd,
				  elapp->ifThisCableStart);
		ATENABLE(s, ddpinp_lock);

		/* make sure no zip timeouts are left running */
		elapp->ifGNIScheduled = 0;
		untimeout(zip_sched_getnetinfo, elapp);
	}
	ddp_rem_if(elapp);
} /* elap_offline */


static void add_route(rt)
RT_entry 	*rt;

/* support ioctl to manually add routes to table. 
   this is really only for testing
*/
{
	rt_insert( 	rt->NetStop, rt->NetStart, rt->NextIRNet, 
			 	rt->NextIRNode, rt->NetDist, rt->NetPort, 
			 	rt->EntryState);
	dPrintf(D_M_ELAP, D_L_STARTUP_INFO, ("adding route: %ud:%ud dist:%ud\n",
		rt->NetStart, rt->NetStop,rt->NetDist));
}

/*
 * ddp_start()
 *
 * Initialization that takes place each time AppleTalk is restarted.
 *
 */
void ddp_start()
{
	TAILQ_INIT(&at_ifQueueHd);
	TAILQ_INIT(&name_registry);
	bzero(at_interfaces, sizeof(at_interfaces));
	bzero(ifID_table, sizeof(ifID_table));
	bzero(&at_ddp_stats, sizeof(at_ddp_stats_t));
	rtmp_init(); /* initialize trackedrouters */

	add_ddp_handler(RTMP_SOCKET, rtmp_input);
	ifID_home = (at_ifaddr_t *)NULL;
	xpatcnt = 0;
}

int ddp_shutdown(count_only)
     int count_only;
{
	at_ifaddr_t *ifID;
	asp_scb_t *scb, *scb_next;
	struct atp_state *atp, *atp_next;
	CCB *sp, *sp_next;
	gref_t *gref;
	vm_offset_t temp_rcb_data, temp_state_data;
	int i, s, active_skts = 0;	/* count of active pids for non-socketized
				   AppleTalk protocols */

	/* Network is shutting down... send error messages up on each open
	 * socket.
	 *** For now, for ASP, ATP and ADSP, attempt to notify open 
	     sockets, but return EBUSY and don't complete shutdown. *** 
	 */

	s = splimp();	/* *** previously contained mismatched locking 
			   that was ifdef'ed to splimp() *** */
	if (!count_only)
		nbp_shutdown();	/* clear all known NVE */

	/* ASP */
	for (scb = scb_used_list; scb; ) {
	    scb_next = scb->next_scb;
	    active_skts++;
	    if (!count_only) {
		dPrintf(D_M_ASP, D_L_TRACE, ("asp pid=%d\n", scb->pid));
	        atalk_notify(scb->gref, ESHUTDOWN);
	    }
	    scb = scb_next; 
	}
	for (i = 0; i < 256 ; i++) {
	    if ((scb = asp_scbQ[i]))
		do {
		    scb_next = scb->next_scb;
		    active_skts++;
		    if (!count_only) {
			dPrintf(D_M_ASP, D_L_TRACE, 
				("asp pid=%d\n", scb->pid));
		        atalk_notify(scb->gref, ESHUTDOWN);
		    }
		    scb = scb_next;
		} while (scb);
	}

	/* ATP */
	for (atp = atp_used_list; atp; ) {
	    atp_next = atp->atp_trans_waiting;
	    active_skts++;
	    if (!count_only) {
		dPrintf(D_M_ATP, D_L_TRACE, ("atp pid=%d\n", atp->atp_pid));
	        atalk_notify(atp->atp_gref, ESHUTDOWN);
	    }
	    atp = atp_next;
	}
	for (i = 0; i < 256; i++) {
	  if ((gref = atp_inputQ[i]) && (gref != (gref_t *)1)) {
		atp = (struct atp_state *)gref->info;	
		if (!atp->dflag) {
		    active_skts++;
		    if (!count_only) {
			dPrintf(D_M_ATP, D_L_TRACE, 
				("atp pid=%d\n", atp->atp_pid));
		        atalk_notify(atp->atp_gref, ESHUTDOWN);
		    }
		}
	  }
	}
	
	/* ADSP */
	for (sp = ccb_used_list; sp ; ) {
	    sp_next = sp->otccbLink;
	    active_skts++;
	    if (!count_only) {
		dPrintf(D_M_ADSP, D_L_TRACE, ("adsp pid=%d\n", sp->pid));
		atalk_notify(sp->gref, ESHUTDOWN);
	    }
	    sp = sp_next;
	}
	for (i = 0; i < 256 ; i++) {
	    if ((sp = adsp_inputQ[i]))
		do {
		    sp_next = sp->otccbLink;
		    active_skts++;
		    if (!count_only) {
			dPrintf(D_M_ADSP, D_L_TRACE, 
				("adsp pid=%d\n", sp->pid));
			atalk_notify(sp->gref, ESHUTDOWN);
		    }
		    sp = sp_next;
		} while (sp);
	}

	/* DDP */
	for (gref = ddp_head.atpcb_next; gref != &ddp_head; 
	     gref = gref->atpcb_next) {
	    if (count_only) {
		active_skts++;
	    } else {
		dPrintf(D_M_DDP,D_L_TRACE, ("ddp pid=%d\n", gref->pid));
		atalk_notify(gref, ESHUTDOWN);
	    }
	}
	if (count_only || active_skts) {
		splx(s);
		return(active_skts);

	}
	/* if there are no interfaces in the process of going online, continue shutting down DDP */
	for (i = 0; i < IF_TOTAL_MAX; i++) {
		if (at_interfaces[i].startup_inprogress == TRUE)
		        return(1);
	}
	if (MULTIPORT_MODE) {
                rtmp_shutdown();
                /* free memory allocated for the rtmp/zip tables */
		if (ZT_table) {
			FREE(ZT_table, M_RTABLE);
			ZT_table = (ZT_entry *)NULL;
		}
		if (RT_table) {
			FREE(RT_table, M_RTABLE);
			RT_table = (RT_entry *)NULL;
		}
	}          

	at_state.flags = 0;     /* make sure inits are done on restart */
	
	wakeup(&ifID_home->startup_inprogress);	/* if rtmp_router_start still starting up */

	/* from original ddp_shutdown() */
	routershutdown();
	ddp_brt_shutdown();

	if (adspInited) {
		CleanupGlobals();
		adspInited = 0;
	}
	
	 
	dPrintf(D_M_DDP, D_L_VERBOSE, ("DDP shutdown completed"));

	/*
	 * make sure we don't have a probe timeout hanging around
	 * it's going to try and make use of an entry in at_interfaces
	 * which is going to be zero'd out by the call to ddp_start a
	 * little further down
	 */
	untimeout(aarp_sched_probe, 0);

	/* *** after an SIOCSIFADDR and before an AIOCSIFADDR,
	       this is the only place to find the ifID *** */
	for (i = 0; i < IF_TOTAL_MAX; i++) {
		ifID = &at_interfaces[i];
		/* do LAP_IOC_OFFLINE processing */
		elap_offline(ifID);
	}
	ddp_start();
	
	splx(s);
	return(0);
} /* ddp_shutdown */

int routerStart(keP)
     at_kern_err_t *keP;
{
	register at_ifaddr_t *ifID;
	int error;
	struct timespec ts;

	if (! ifID_home)
		return(EINVAL);

	/*
	 * this will cause the ports to glean from the net the relevant
	 * information before forwarding
	 */
	TAILQ_FOREACH(ifID, &at_ifQueueHd, aa_link) {
		dPrintf(D_M_ELAP, D_L_STARTUP_INFO, 
			("routerStart Port %d (%s) set to activating\n",
			 ifID->ifPort, ifID->ifName));
		ifID->ifRoutingState = PORT_ACTIVATING;
		ifID->ifFlags |= RTR_XNET_PORT;
	}

	/*
	 * The next step is to check the information for each port before
	 * declaring the ports up and forwarding
	 */
	dPrintf(D_M_ELAP, D_L_STARTUP_INFO,
		("router_start: waiting 20 sec before starting up\n"));

	lck_mtx_assert(atalk_mutex, LCK_MTX_ASSERT_OWNED);
	/* sleep for 20 seconds */

	/* the vaue of 10n terms of hz is 100ms */
	ts.tv_sec = 20;
	ts.tv_nsec = 0;
	
	if ((error = 
	     /* *** eventually this will be the ifID for the interface
		being brought up in router mode *** */
		msleep(&ifID_home->startup_inprogress, atalk_mutex,
		    PSOCK | PCATCH, "routerStart", &ts))
	    != EWOULDBLOCK) {
/*
		if (!error)
			panic("routerStart: spurious interrupt");
*/
		return(error);
	}

	return(rtmp_router_start(keP));
	/* was timeout(rtmp_router_start, 0, 20 * SYS_HZ);  */
} /* routerStart */

void ZIPwakeup(elapp, ZipError)
     at_ifaddr_t *elapp;
     int ZipError;
{
	int s, error = ZipError;

	ATDISABLE(s, ddpinp_lock);
	if ( (elapp != NULL) && elapp->startup_inprogress) {
		ATENABLE(s, ddpinp_lock);

		/* was ZIPContinue */
		/* was elapp_online() with jump to ZIP_sleep */

		/* instead of the goto ZIP_sleep ... */
		switch (ZipError) {
			case 0 : /* success */
			    elapp->ifState = LAP_ONLINE;

				/* Send event with zone info. */
				atalk_post_msg(elapp->aa_ifp, KEV_ATALK_ZONEUPDATED, 0, &(elapp->ifZoneName));
				
			    break;
			case ZIP_RE_AARP :
			    /* instead of goto re_aarp; */
			    /* We now call aarp_init() to assign an 
			       appletalk node addr */
			    if ((elapp->startup_error = re_aarp(elapp))) {
				elapp->startup_inprogress = FALSE;
				wakeup(&elapp->startup_inprogress);
				dPrintf(D_M_ELAP, D_L_STARTUP_INFO, 
					("elap_online: ack 2\n"));
			    }
			    break;
			default :
			    break;
		}
		if (ZipError != ZIP_RE_AARP) {
			elapp->startup_error = error;
			elapp->startup_inprogress = FALSE;
			wakeup(&elapp->startup_inprogress);
			dPrintf(D_M_ELAP, D_L_STARTUP_INFO,
				("elap_online: ifZipError=%d\n", error));
		}
	} else
		ATENABLE(s, ddpinp_lock);
} /* ZIPwakeup */

void AARPwakeup(probe_cb)
     aarp_amt_t *probe_cb;
{
	int s;
	int errno;
	at_ifaddr_t *elapp;

	ATDISABLE(s, arpinp_lock);
	elapp = probe_cb->elapp;
	if ( (elapp != NULL) && elapp->startup_inprogress && elapp->aa_ifp != 0) {
		ATENABLE(s, arpinp_lock);

		/* was AARPContinue */
		errno = aarp_init2(elapp);
		/* aarp_init2() returns either -1 or 0 */
		if (errno != 0) {
			dPrintf(D_M_ELAP, D_L_STATE_CHG, 
				("elap_online aarp_init for %s\n",
				 elapp->ifName));
			(void)at_unreg_mcast(elapp, (caddr_t)&elapp->ZoneMcastAddr);
			(void)at_unreg_mcast(elapp, (caddr_t)&elapp->cable_multicast_addr);
			elapp->ifState = LAP_OFFLINE;
			ddp_rem_if(elapp);
			elapp->startup_error = EADDRNOTAVAIL;
			elapp->startup_inprogress = FALSE;
			wakeup(&elapp->startup_inprogress);
			dPrintf(D_M_ELAP, D_L_STARTUP_INFO, ("elap_online: ack 2\n"));
		} else {
			dPrintf(D_M_ELAP,D_L_STARTUP_INFO,
				("elap_online: aarp_init returns zero\n"));
			elap_online2(elapp);
		}
	} else
		ATENABLE(s, arpinp_lock);
} /* AARPwakeup */

void ddp_bit_reverse(addr)
	unsigned char *addr;
{
static unsigned char reverse_data[] = {
	0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
	0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
	0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
	0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
	0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
	0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
	0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
	0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
	0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
	0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
	0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
	0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
	0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
	0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
	0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
	0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
	0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
	0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
	0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
	0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
	0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
	0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
	0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
	0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
	0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
	0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
	0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
	0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
	0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
	0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
	0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
	0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
	};

	unsigned char k;

	for (k=0; k < 6; k++)
		addr[k] = reverse_data[addr[k]];
}

static int elap_trackMcast(patp, func, addr)
	at_ifaddr_t    *patp;
	int func;
	caddr_t addr;
{
	int i, loc=-1;
	u_char c;
	switch(patp->aa_ifp->if_type) {
	case IFT_ETHER: 
	case IFT_FDDI:
	case IFT_L2VLAN:
	case IFT_IEEE8023ADLAG: /* bonded ethernet */
		/* set addr to point to unique part of addr */
		c = addr[5];

		/* first try to find match */
		/* *** save just one byte of the multicast address? *** */
		for (i=0; i< MAX_MCASTS; i++) 
			if (c == patp->mcast[i]) {
				loc = i;
				break;
			}
				
		switch (func) {
		case MCAST_TRACK_DELETE:
			if (loc >= 0) 
				patp->mcast[loc] = 0;

			break;
		case MCAST_TRACK_ADD:
			dPrintf(D_M_PAT_LOW, D_L_USR2, ("mctrack:add loc:%d\n", i));
			if (loc >= 0) {
				dPrintf(D_M_PAT_LOW, D_L_USR2, ("mctrack:add, addr was there\n"));
				return(1);
				break;			/* already there */
			}		
			for (i=0; i< MAX_MCASTS; i++) 
				if (patp->mcast[i] == 0) {
					loc = i;
					break;
				}
			dPrintf(D_M_PAT_LOW, D_L_USR2, ("mctrack:add1 loc:%d\n", i));
			if (loc >= 0) {
				patp->mcast[loc] = c;
				dPrintf(D_M_PAT_LOW, D_L_USR2, ("mctrack:add, adding(%x)\n",
					(*(int*)addr)&0xffffff));
			}
			else {
				/*errno = ENOMEM; */ /*LD 5/7/97 nobody is using that */
				return(-1);
			}
			break;	
		case MCAST_TRACK_CHECK:
			if (loc >= 0) {
				dPrintf(D_M_PAT_LOW, D_L_USR2, ("mctrack:check, addr was there\n"));
				return(0);
			}
			else {
				dPrintf(D_M_PAT_LOW, D_L_USR2, ("mctrack:add, addr was NOT there\n"));
				return(-1);
			}
			
		default:
			/*errno = EINVAL;*/ /*LD 5/7/97 nobody is using that */
			return(-1);
		}

	case IFT_ISO88025: /* token ring */
		/* we would use the lowest byte of the addr argument as a value
		   to shift left a 1 to form the mcast mask for TR. We'll do this
		   when the time comes
		 */
	default:
		;
	}
	return(0);
}


static getSnmpCfg(snmp)
	snmpCfg_t *snmp;
{
	int i;
	at_ifaddr_t 	*elapp;
	snmpIfCfg_t	*ifc;

	snmp->cfg_ifCnt = 0;
	
	bzero(snmp,sizeof(snmpCfg_t));
	for (i=0, elapp=at_interfaces,ifc=snmp->cfg_ifCfg; 
		 i<IF_TOTAL_MAX; i++, elapp++, ifc++) {
		if (elapp->ifState != LAP_OFFLINE) {
			snmp->cfg_ifCnt++;
			strncpy(ifc->ifc_name,elapp->ifName, sizeof(ifc->ifc_name));
			ifc->ifc_aarpSize = getAarpTableSize(i);
			ifc->ifc_addrSize = getPhysAddrSize(i);
			switch (elapp->aa_ifp->if_type) {
				case IFT_ETHER:
                                case IFT_L2VLAN:
				case IFT_IEEE8023ADLAG: /* bonded ethernet */
					ifc->ifc_type = SNMP_TYPE_ETHER2;
					break;
				case IFT_ISO88025: /* token ring */
					ifc->ifc_type = SNMP_TYPE_TOKEN;
					break;
				case IFT_FDDI:
				default:
					ifc->ifc_type = SNMP_TYPE_OTHER;
					break;
			}
			ifc->ifc_start 	= elapp->ifThisCableStart;
			ifc->ifc_end	= elapp->ifThisCableEnd;
			ifc->ifc_ddpAddr= elapp->ifThisNode;
			ifc->ifc_status	= elapp->ifState == LAP_ONLINE ? 1 : 2;
			ifc->ifc_zoneName.len = 0;
			if (elapp->ifZoneName.len != 0) {
				ifc->ifc_zoneName = elapp->ifZoneName;
			}
			else if (elapp->ifDefZone) {
				ifc->ifc_zoneName = ZT_table[elapp->ifDefZone-1].Zone;
			}
			else	/* temp, debug only */
				ifc->ifc_zoneName = ZT_table[0].Zone;
			if (ROUTING_MODE) {
				if (elapp->ifFlags & RTR_SEED_PORT) {
					ifc->ifc_netCfg  = SNMP_CFG_CONFIGURED;
					ifc->ifc_zoneCfg = SNMP_CFG_CONFIGURED;
				}
				else {
					ifc->ifc_netCfg  = SNMP_CFG_GARNERED;
					ifc->ifc_zoneCfg = SNMP_CFG_GARNERED;
				}
			}
			else  { 	/* single-port mode */
				if (elapp->ifRouterState == ROUTER_AROUND) {
					ifc->ifc_netCfg = SNMP_CFG_GARNERED;
				}
				else {
					ifc->ifc_netCfg = SNMP_CFG_GUESSED;
					ifc->ifc_zoneCfg = SNMP_CFG_UNCONFIG;
				}
			}
		}
	} 
	snmp->cfg_flags = at_state.flags;

		
	return(0);
}	

int at_reg_mcast(ifID, data)
     at_ifaddr_t *ifID;
     caddr_t data;
{
	struct ifnet *nddp = ifID->aa_ifp;
	struct sockaddr_dl sdl;

	if (*(int *)data) {
		if (!nddp) {
			dPrintf(D_M_PAT, D_L_STARTUP, ("pat_mcast: BAD ndpp\n"));
			return(-1);
		}

		if (elap_trackMcast(ifID, MCAST_TRACK_ADD, data) == 1)
			return(0);

		/* this is for ether_output */
		bzero(&sdl, sizeof(sdl));
		sdl.sdl_family = AF_LINK;
		sdl.sdl_alen = sizeof(struct etalk_addr);
		sdl.sdl_len = offsetof(struct sockaddr_dl, sdl_data) 
		    + sizeof(struct etalk_addr);
		bcopy(data, sdl.sdl_data, sizeof(struct etalk_addr));
		/* these next two lines should not really be needed XXX */
		sdl.sdl_index = nddp->if_index;
		sdl.sdl_type = IFT_ETHER;

		dPrintf(D_M_PAT, D_L_STARTUP,
			("pat_mcast: adding multicast %08x%04x ifID:0x%x\n",
			 *(unsigned*)data, (*(unsigned *)(data+2))&0x0000ffff, 
			 (unsigned)ifID));

		if (if_addmulti(nddp, &sdl, 0))
			return -1;
	}
	return 0;

}

int at_unreg_mcast(ifID, data)
     at_ifaddr_t *ifID;
     caddr_t data;
{
	struct ifnet *nddp = ifID->aa_ifp;
	struct sockaddr_dl sdl;

	if (*(int *)data) {
		if (!nddp) {
			dPrintf(D_M_PAT, D_L_STARTUP, ("pat_mcast: BAD ndpp\n"));
			return(-1);
		}

		elap_trackMcast(ifID, MCAST_TRACK_DELETE, data);

		/* this is for ether_output */
		bzero(&sdl, sizeof(sdl));
		sdl.sdl_family = AF_LINK;
		sdl.sdl_alen = sizeof(struct etalk_addr);
		sdl.sdl_len = offsetof(struct sockaddr_dl, sdl_data) 
		    + sizeof(struct etalk_addr);
		bcopy(data, sdl.sdl_data, sizeof(struct etalk_addr));
		/* these next two lines should not really be needed XXX */
		sdl.sdl_index = nddp->if_index;
		sdl.sdl_type = IFT_ETHER;

		dPrintf(D_M_PAT, D_L_STARTUP,
			("pat_mcast: deleting multicast %08x%04x ifID:0x%x\n",
			 *(unsigned*)data, (*(unsigned *)(data+2))&0x0000ffff, 
			 (unsigned)ifID));
		bzero(data, sizeof(struct etalk_addr));

		if (if_delmulti(nddp, &sdl))
			return -1;
	}
	return 0;
}
#ifdef NOT_YET
/* *** at_reg_mcast() and at_unreg_mcast() should be replaced as soon as the
       new code to allow an AF_LINK address family multicast to be (un)registered
       using the SIOCADDMULTI / SIOCDELMULTI ioctls has been completed.

       The issue is that the "struct sockaddr_dl" needed for the AF_LINK does not 
       fit in the "struct ifreq" that is used for these ioctls, and we do not want
       Blue/Classic, which currently uses AF_UNSPEC, to use a different address 
       family multicast address than Mac OS X uses.
   *** */

int at_reg_mcast(ifID, data)
     at_ifaddr_t *ifID;
     caddr_t data;
{
	struct ifnet *nddp = ifID->aa_ifp;
	struct sockaddr_dl sdl;

	if (*(int *)data) {
		if (!nddp) {
			dPrintf(D_M_PAT, D_L_STARTUP, ("pat_mcast: BAD ndpp\n"));
			return(-1);
		}
		if (elap_trackMcast(ifID, MCAST_TRACK_ADD, data) == 1)
			return(0);

		sdl.sdl_len = sizeof(struct sockaddr_dl);
		sdl.sdl_family = AF_LINK;
		sdl.sdl_index = 0;
		sdl.sdl_type = nddp->if_type;
		sdl.sdl_alen = nddp->if_addrlen;
		sdl.sdl_slen = 0;
		sdl.sdl_nlen = sprintf(sdl.sdl_data, "%s%d", 
				       nddp->if_name , nddp->if_unit);
		bcopy(data, LLADDR(&sdl), sdl.sdl_alen);

		dPrintf(D_M_PAT, D_L_STARTUP,
			("pat_mcast: adding multicast %08x%04x ifID:0x%x\n",
			 *(unsigned*)data, (*(unsigned *)(data+2))&0x0000ffff, 
			 (unsigned)ifID));

		if (if_addmulti(nddp, (struct sockaddr *)&sdl, 0))
			return -1;
	}

	return 0;
}

int at_unreg_mcast(ifID, data)
     at_ifaddr_t *ifID;
     caddr_t data;
{
	struct ifnet *nddp = ifID->aa_ifp;
	struct sockaddr_dl sdl;

	if (*(int *)data) {
		if (!nddp) {
			dPrintf(D_M_PAT, D_L_STARTUP, ("pat_mcast: BAD ndpp\n"));
			return(-1);
		}

		elap_trackMcast(ifID, MCAST_TRACK_DELETE, data);

		sdl.sdl_len = sizeof(struct sockaddr_dl);
		sdl.sdl_family = AF_LINK;
		sdl.sdl_index = 0;
		sdl.sdl_type = nddp->if_type;
		sdl.sdl_alen = nddp->if_addrlen;
		sdl.sdl_slen = 0;
		sdl.sdl_nlen = sprintf(sdl.sdl_data, "%s%d", 
				       nddp->if_name , nddp->if_unit);

		dPrintf(D_M_PAT, D_L_STARTUP,
			("pat_mcast: deleting multicast %08x%04x ifID:0x%x\n",
			 *(unsigned*)data, (*(unsigned *)(data+2))&0x0000ffff, 
			 (unsigned)ifID));
		bzero(data, ETHERNET_ADDR_LEN);	

		if (if_delmulti(nddp, (struct sockaddr *)&sdl))
			return(-1);
	}

	return 0;
}

#endif