]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/ddp.c
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / netat / ddp.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31 * Copyright (c) 1987, 1988, 1989 Apple Computer, Inc.
32 *
33 *
34 * Modified for MP, 1996 by Tuyen Nguyen
35 * Added AURP support, April 8, 1996 by Tuyen Nguyen
36 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
37 */
38
39#define RESOLVE_DBG /* define debug globals in debug.h */
40
41#include <sys/errno.h>
42#include <sys/types.h>
43#include <sys/param.h>
44#include <machine/spl.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>
47#include <sys/proc.h>
48#include <sys/filedesc.h>
49#include <sys/fcntl.h>
50#include <sys/mbuf.h>
51#include <sys/ioctl.h>
52#include <sys/malloc.h>
53#include <sys/socket.h>
54#include <sys/socketvar.h>
55#include <sys/protosw.h>
56
57#include <net/if.h>
58#include <net/dlil.h>
59
60#include <netat/sysglue.h>
61#include <netat/appletalk.h>
62#include <netat/at_var.h>
63#include <netat/ddp.h>
64#include <netat/ep.h>
65#include <netat/nbp.h>
66#include <netat/rtmp.h>
67#include <netat/zip.h>
68#include <netat/at_pcb.h>
69#include <netat/routing_tables.h>
70#include <netat/at_snmp.h>
71#include <netat/aurp.h>
72#include <netat/debug.h>
73#include <netat/at_ddp_brt.h>
74#include <netat/at_aarp.h>
75#include <netat/adsp.h>
76#include <netat/adsp_internal.h>
77
78/* globals */
79
80/* Queue of LAP interfaces which have registered themselves with DDP */
81struct at_ifQueueHd at_ifQueueHd;
82
83extern at_state_t at_state;
84extern TAILQ_HEAD(name_registry, _nve_) name_registry;
85
86snmpStats_t snmpStats; /* snmp ddp & echo stats */
87
88extern at_ddp_stats_t at_ddp_stats; /* DDP statistics */
89extern struct atpcb ddp_head;
90extern at_ifaddr_t *ifID_home, *ifID_table[];
91extern aarp_amt_array *aarp_table[];
92extern at_ifaddr_t at_interfaces[];
93
94/* routing mode special */
95void (*ddp_AURPsendx)();
96at_ifaddr_t *aurp_ifID = 0;
97extern pktsIn,pktsOut;
98int pktsDropped,pktsHome;
1c79356b
A
99
100extern int *atp_pidM;
101extern int *adsp_pidM;
102extern struct atpcb *atp_inputQ[];
103extern CCB *adsp_inputQ[];
104
105at_ifaddr_t *forUs(at_ddp_t *);
106
107void ddp_input(), ddp_notify_nbp();
108
109extern void routing_needed();
110extern void ddp_brt_sweep();
111
112struct {
113 void (*func)();
114} ddp_handler[256];
115
116void init_ddp_handler()
117{
118 bzero(ddp_handler, sizeof(ddp_handler));
119}
120
121void add_ddp_handler(ddp_socket, input_func)
122 u_char ddp_socket;
123 void (*input_func)();
124{
125 ddp_handler[ddp_socket].func = input_func;
126}
127
128void
129ddp_slowtimo()
130{
131 ddp_brt_sweep();
132}
133
134/*
135 * Raw DDP socket option processing.
136 */
137int ddp_ctloutput(so, sopt)
138 struct socket *so;
139 struct sockopt *sopt;
140{
141 struct atpcb *at_pcb = sotoatpcb(so);
142 int optval, error = 0;
143
144 if (sopt->sopt_level != ATPROTO_NONE)
145 return (EINVAL);
146
147 switch (sopt->sopt_dir) {
148
149 case SOPT_GET:
150 switch (sopt->sopt_name) {
151 case DDP_HDRINCL:
152 optval = at_pcb->ddp_flags & DDPFLG_HDRINCL;
153 error = sooptcopyout(sopt, &optval, sizeof optval);
154 break;
155 case DDP_CHKSUM_ON:
156 optval = at_pcb->ddp_flags & DDPFLG_CHKSUM;
157 error = sooptcopyout(sopt, &optval, sizeof optval);
158 break;
159 case DDP_STRIPHDR:
160 optval = at_pcb->ddp_flags & DDPFLG_STRIPHDR;
161 error = sooptcopyout(sopt, &optval, sizeof optval);
162 break;
163 case DDP_SLFSND_ON:
164 optval = at_pcb->ddp_flags & DDPFLG_SLFSND;
165 error = sooptcopyout(sopt, &optval, sizeof optval);
166 break;
167 case DDP_GETSOCKNAME:
168 {
169 ddp_addr_t addr;
170 addr.inet.net = at_pcb->laddr.s_net;
171 addr.inet.node = at_pcb->laddr.s_node;
172 addr.inet.socket = at_pcb->lport;
173 addr.ddptype = at_pcb->ddptype;
174 error = sooptcopyout(sopt, &addr, sizeof addr);
175 }
176 break;
177 default:
178 error = ENOPROTOOPT;
179 break;
180 }
181 break;
182 case SOPT_SET:
183 switch (sopt->sopt_name) {
184 case DDP_HDRINCL:
185 error = sooptcopyin(sopt, &optval, sizeof optval,
186 sizeof optval);
187 if (error)
188 break;
189 if (optval)
190 at_pcb->ddp_flags |= DDPFLG_HDRINCL;
191 else
192 at_pcb->ddp_flags &= ~DDPFLG_HDRINCL;
193 break;
194 case DDP_CHKSUM_ON:
195 error = sooptcopyin(sopt, &optval, sizeof optval,
196 sizeof optval);
197 if (error)
198 break;
199 if (optval)
200 at_pcb->ddp_flags |= DDPFLG_CHKSUM;
201 else
202 at_pcb->ddp_flags &= ~DDPFLG_CHKSUM;
203 break;
204 case DDP_STRIPHDR:
205 error = sooptcopyin(sopt, &optval, sizeof optval,
206 sizeof optval);
207 if (error)
208 break;
209 if (optval)
210 at_pcb->ddp_flags |= DDPFLG_STRIPHDR;
211 else
212 at_pcb->ddp_flags &= ~DDPFLG_STRIPHDR;
213 break;
214 case DDP_SLFSND_ON:
215 error = sooptcopyin(sopt, &optval, sizeof optval,
216 sizeof optval);
217 if (error)
218 break;
219 if (optval)
220 at_pcb->ddp_flags |= DDPFLG_SLFSND;
221 else
222 at_pcb->ddp_flags &= ~DDPFLG_SLFSND;
223 break;
224 default:
225 error = ENOPROTOOPT;
226 break;
227 }
228 break;
229 }
230
231 return(error);
232} /* ddp_cloutput */
233
234/****************************************************************/
235/* */
236/* */
237/* Support Routines */
238/* */
239/* */
240/****************************************************************/
241
242/*
243 * Name:
244 * ddp_checksum
245 *
246 * Description:
247 * This procedure determines the checksum of an extended DDP datagram.
248 * Add the unsigned bytes into an unsigned 16-bit accumulator.
249 * After each add, rotate the sign bit into the low order bit of
250 * the accumulator. When done, if the checksum is 0, changed into 0xFFFF.
251 *
252 * Calling sequence:
253 * checksum = ddp_checksum(mp, offset)
254 *
255 * Parameters:
256 * mp pointer to the datagram gbuf_t
257 * offset offset to start at in first gbuf_t block
258 *
259 * Return value:
260 * The DDP checksum.
261 *
262 */
263
264u_short ddp_checksum(mp, offset)
265 register gbuf_t *mp;
266 register int offset;
267{
268 register u_char *data;
269 register int length;
270 register u_short checksum;
271
272 checksum = 0;
273
274 do {
275 if (offset >= gbuf_len(mp))
276 offset -= gbuf_len(mp);
277 else {
278 data = ((unsigned char *) gbuf_rptr(mp)) + offset;
279 length = gbuf_len(mp) - offset;
280 offset = 0;
281 /* Portable checksum from 3.0 */
282 while (length--) {
283 checksum += *data++;
284 checksum = (checksum & 0x8000) ?
285 ((checksum << 1) | 1) : (checksum << 1);
286 }
287 }
288 } while ( (mp = gbuf_cont(mp)) );
289
290 if (checksum == 0)
291 checksum = 0xffff;
292
293 return(checksum);
294}
295
296/*
297 * ddp_add_if()
298 *
299 * Description:
300 * This procedure is called by each LAP interface when it wants to place
301 * itself online. The LAP interfaces passes in a pointer to its at_if
302 * struct, which is added to DDP's list of active interfaces (at_ifQueueHd).
303 * When DDP wants to transmit a packet, it searches this list for the
304 * interface to use.
305 *
306 * If AT_IFF_DEFAULT is set, then this interface is to be brought online
307 * as the interface DDP socket addresses are tied to. Of course there can
308 * be only one default interface; we return an error if it's already set.
309 *
310 * Calling Sequence:
311 * ret_status = ddp_add_if(ifID)
312 *
313 * Formal Parameters:
314 * ifID pointer to LAP interface's at_if struct.
315 *
316 * Completion Status:
317 * 0 Procedure successfully completed.
318 * EALREADY This interface is already online, or there is
319 * already a default interface.
320 * ENOBUFS Cannot allocate input queue
321 *
322 */
323int ddp_add_if(ifID)
324register at_ifaddr_t *ifID;
325{
326 int port = -1;
327
328 dPrintf(D_M_DDP, D_L_STARTUP,
329 ("ddp_add_if: called, ifID:0x%x\n", (u_int) ifID));
330
331 if (ifID->ifFlags & AT_IFF_DEFAULT) {
332 if (ifID_home)
333 return(EEXIST); /* home port already set */
334 else {
335 port = IFID_HOME;
336 ifID_home = ifID;
337 }
338 } else {
339 for (port=IFID_HOME+1; port<IF_TOTAL_MAX; port++)
340 if (!ifID_table[port]) {
341 break;
342 }
343 if (port == IF_TOTAL_MAX) /* no space left */
344 return(ENOMEM);
345 }
346
347 /* allocate an et_aarp_amt structure */
348 if ((aarp_table[port] =
349 (aarp_amt_array *)_MALLOC(sizeof(aarp_amt_array),
350 M_RTABLE, M_WAITOK)) == NULL)
351 return(ENOMEM);
352
353 dPrintf(D_M_DDP, D_L_STARTUP, ("ddp:adding ifID_table[%d]\n", port));
354
355 /* add i/f to port list */
356 ifID_table[port] = ifID;
357 ifID->ifPort = port; /* set ddp port # in ifID */
358
359 /* Add this interface to the list of online interfaces */
360 TAILQ_INSERT_TAIL(&at_ifQueueHd, ifID, aa_link);
361
362 return (0);
363} /* ddp_add_if */
364
365/*
366 * ddp_rem_if()
367 *
368 * Description:
369 * This procedure is called by each LAP interface when it wants to take
370 * itself offline. The LAP interfaces passes in a pointer to its at_if
371 * struct; DDP's list of active interfaces (at_ifQueueHd) is searched and
372 * this interface is removed from the list. DDP can still transmit
373 * packets as long as this interface is not the default interface; the
374 * sender will just get ENETUNREACH errors when it tries to send to an
375 * interface that went offline. However, if the default interface is
376 * taken offline, we no longer have a node ID to use as a source address
377 * and DDP must return ENETDOWN when a caller tries to send a packet.
378 *
379 * Formal Parameters:
380 * ifID pointer to LAP interface's at_if struct.
381 */
382
383void ddp_rem_if(ifID)
384 register at_ifaddr_t *ifID;
385{
386 struct ifaddr *ifa = &ifID->aa_ifa;
387
388 /* un-do processing done in SIOCSIFADDR */
389 if (ifa->ifa_addr) {
91447636
A
390 ifnet_lock_exclusive(ifID->aa_ifp);
391 if_detach_ifa(ifID->aa_ifp, ifa);
1c79356b 392 ifa->ifa_addr = NULL;
91447636 393 ifnet_lock_done(ifID->aa_ifp);
1c79356b
A
394 }
395 if (ifID->at_dl_tag) {
396/* dlil_detach_protocol(ifID->at_dl_tag); */
397 ether_detach_at(ifID->aa_ifp);
398 ifID->at_dl_tag = 0;
399 }
400
401 /* un-do processing done in ddp_add_if() */
402 if (ifID->ifPort) {
403 if (aarp_table[ifID->ifPort]) {
404 FREE(aarp_table[ifID->ifPort], M_RTABLE);
405 aarp_table[ifID->ifPort] = NULL;
406 }
407
408 at_state.flags |= AT_ST_IF_CHANGED;
409 ifID->aa_ifp = NULL;
410
411 trackrouter_rem_if(ifID);
412 TAILQ_REMOVE(&at_ifQueueHd, ifID, aa_link);
413 ifID_table[ifID->ifPort] = NULL;
414 ifID->ifName[0] = '\0';
415 ifID->ifPort = 0;
416 }
417
418 /* *** deallocate ifID, eventually *** */
419} /* ddp_rem_if */
420
421/*
422 * The user may have registered an NVE with the NBP on a socket. When the
423 * socket is closed, the NVE should be deleted from NBP's name table. The
424 * user should delete the NVE before the socket is shut down, but there
425 * may be circumstances when he can't. So, whenever a DDP socket is closed,
426 * this routine is used to notify NBP of the socket closure. This would
427 * help NBP get rid of all NVE's registered on the socket.
428 */
429
430/* *** Do we still need to do this? *** */
431int ot_ddp_check_socket(socket, pid)
432 unsigned char socket;
433 int pid;
434{
435 int cnt = 0;
436 gref_t *gref;
437
438 dPrintf(D_M_DDP, D_L_INFO, ("ot_ddp_check_socket: %d\n", socket));
439 for (gref = ddp_head.atpcb_next; gref != &ddp_head; gref = gref->atpcb_next)
440 if (gref->lport == socket && gref->pid == pid)
441 cnt++;
442 if ((atp_inputQ[socket] != NULL) && (atp_inputQ[socket] != (gref_t *)1)
443 && (atp_pidM[socket] == pid))
444 cnt++;
445 if ((adsp_inputQ[socket] != NULL) && (adsp_pidM[socket] == pid))
446 cnt++;
447
448 return(cnt);
449}
450
451void ddp_notify_nbp(socket, pid, ddptype)
452 unsigned char socket;
453 int pid;
454 unsigned char ddptype; /* not used */
455{
456 extern int nve_lock;
0b4e3aa0 457 nve_entry_t *nve_entry, *nve_next;
1c79356b
A
458
459 if (at_state.flags & AT_ST_STARTED) {
460 /* *** NBP_CLOSE_NOTE processing (from ddp_nbp.c) *** */
0b4e3aa0
A
461 for ((nve_entry = TAILQ_FIRST(&name_registry)); nve_entry; nve_entry = nve_next) {
462 nve_next = TAILQ_NEXT(nve_entry, nve_link);
1c79356b
A
463 if ((at_socket)socket == nve_entry->address.socket &&
464 /* *** check complete address and ddptype here *** */
465 pid == nve_entry->pid &&
466 ot_ddp_check_socket(nve_entry->address.socket,
467 nve_entry->pid) < 2) {
0b4e3aa0 468 /* NB: nbp_delete_entry calls TAILQ_REMOVE */
1c79356b
A
469 nbp_delete_entry(nve_entry);
470 }
471 }
1c79356b
A
472 }
473} /* ddp_notify_nbp */
474
475static void fillin_pkt_chain(m)
476 gbuf_t *m;
477{
478 gbuf_t *tmp_m = m;
479 register at_ddp_t
480 *ddp = (at_ddp_t *)gbuf_rptr(m),
481 *tmp_ddp;
482 u_short tmp;
483
484 if (UAS_VALUE(ddp->checksum)) {
485 tmp = ddp_checksum(m, 4);
5d5c5d0d 486 UAS_ASSIGN_HTON(ddp->checksum, tmp);
1c79356b
A
487 }
488
489 for (tmp_m=gbuf_next(tmp_m); tmp_m; tmp_m=gbuf_next(tmp_m)) {
490 tmp_ddp = (at_ddp_t *)gbuf_rptr(tmp_m);
5d5c5d0d 491 DDPLEN_ASSIGN(tmp_ddp, gbuf_msgsize(tmp_m));
1c79356b
A
492 tmp_ddp->hopcount =
493 tmp_ddp->unused = 0;
494 NET_NET(tmp_ddp->src_net, ddp->src_net);
495 tmp_ddp->src_node = ddp->src_node;
496 tmp_ddp->src_socket = ddp->src_socket;
497 if (UAS_VALUE(tmp_ddp->checksum)) {
498 tmp = ddp_checksum(tmp_m, 4);
5d5c5d0d 499 UAS_ASSIGN_HTON(ddp->checksum, tmp);
1c79356b
A
500 }
501 }
502}
503
504/* There are various ways a packet may go out.... it may be sent out
505 * directly to destination node, or sent to a random router or sent
506 * to a router whose entry exists in Best Router Cache. Following are
507 * constants used WITHIN this routine to keep track of choice of destination
508 */
509#define DIRECT_ADDR 1
510#define BRT_ENTRY 2
511#define BRIDGE_ADDR 3
512
513/*
514 * ddp_output()
515 *
516 * Remarks :
517 * Called to queue a atp/ddp data packet on the network interface.
518 * It returns 0 normally, and an errno in case of error.
519 * The mbuf chain pointed to by *mp is consumed on success, and
520 * freed in case of error.
521 *
522 */
523int ddp_output(mp, src_socket, src_addr_included)
524 register gbuf_t **mp;
525 at_socket src_socket;
526 int src_addr_included;
527{
528 register at_ifaddr_t *ifID = ifID_home, *ifIDTmp = NULL;
529 register at_ddp_t *ddp;
530 register ddp_brt_t *brt;
531 register at_net_al dst_net;
532 register int len;
533 struct atalk_addr at_dest;
534 at_ifaddr_t *ARouterIf = NULL;
535 int loop = 0;
536 int error = 0;
537 int addr_type;
538 u_char addr_flag;
539 char *addr = NULL;
540 register gbuf_t *m;
541
542 KERNEL_DEBUG(DBG_AT_DDP_OUTPUT | DBG_FUNC_START, 0,
543 0,0,0,0);
544
545 snmpStats.dd_outReq++;
546
547 m = *mp;
548 ddp = (at_ddp_t *)gbuf_rptr(m);
9bccf70c
A
549
550 if (!ifID) {
551 /* Device/Interface not configured */
552 dPrintf(D_M_DDP, D_L_ERROR, ("Device/Interface not configured"));
553 error = ENXIO;
554 gbuf_freel(*mp);
555 goto exit_ddp_output;
556 }
1c79356b
A
557
558 if ((ddp->dst_socket > (unsigned) (DDP_SOCKET_LAST + 1)) ||
559 (ddp->dst_socket < DDP_SOCKET_1st_RESERVED)) {
560 dPrintf(D_M_DDP, D_L_ERROR,
561 ("Illegal destination socket on outgoing packet (0x%x)",
562 ddp->dst_socket));
563 at_ddp_stats.xmit_bad_addr++;
564 error = ENOTSOCK;
565 gbuf_freel(*mp);
566 goto exit_ddp_output;
567 }
568 if ((len = gbuf_msgsize(*mp)) > DDP_DATAGRAM_SIZE) {
569 /* the packet is too large */
570 dPrintf(D_M_DDP, D_L_ERROR,
571 ("Outgoing packet too long (len=%d bytes)", len));
572 at_ddp_stats.xmit_bad_length++;
573 error = EMSGSIZE;
574 gbuf_freel(*mp);
575 goto exit_ddp_output;
576 }
577 at_ddp_stats.xmit_bytes += len;
578 at_ddp_stats.xmit_packets++;
579
5d5c5d0d 580 DDPLEN_ASSIGN(ddp, len);
1c79356b
A
581 ddp->hopcount =
582 ddp->unused = 0;
583
584 /* If this packet is for the same node, loop it back
585 * up... Note that for LocalTalk, dst_net zero means "THIS_NET", so
586 * address 0.nn is eligible for loopback. For Extended EtherTalk,
587 * dst_net 0 can be used only for cable-wide or zone-wide
588 * broadcasts (0.ff) and as such, address of the form 0.nn is NOT
589 * eligible for loopback.
590 */
591 dst_net = NET_VALUE(ddp->dst_net);
592
593 /* If our packet is destined for the 'virtual' bridge
594 * address of NODE==0xFE, replace that address with a
595 * real bridge address.
596 */
597 if ((ddp->dst_node == 0xfe) &&
598 ((dst_net == ATADDR_ANYNET) ||
599 (dst_net >= ifID_home->ifThisCableStart &&
600 dst_net <= ifID_home->ifThisCableEnd))) {
601 /* if there's a router that's not us, it's in ifID_home */
602 NET_ASSIGN(ddp->dst_net, ifID_home->ifARouter.s_net);
603 dst_net = ifID_home->ifARouter.s_net;
604 ddp->dst_node = ifID_home->ifARouter.s_node;
605 }
606
607 if (MULTIHOME_MODE && (ifIDTmp = forUs(ddp))) {
608 ifID = ifIDTmp;
609 loop = TRUE;
610 dPrintf(D_M_DDP_LOW, D_L_USR1,
611 ("ddp_out: for us if:%s\n", ifIDTmp->ifName));
612 }
613
614 if (!loop)
615 loop = ((ddp->dst_node == ifID->ifThisNode.s_node) &&
616 (dst_net == ifID->ifThisNode.s_net)
617 );
618 if (loop) {
619 gbuf_t *mdata, *mdata_next;
620
621 if (!MULTIHOME_MODE || !src_addr_included) {
622 NET_ASSIGN(ddp->src_net, ifID->ifThisNode.s_net);
623 ddp->src_node = ifID->ifThisNode.s_node;
624 }
625 ddp->src_socket = src_socket;
626
627 dPrintf(D_M_DDP_LOW, D_L_OUTPUT,
628 ("ddp_output: loop to %d:%d port=%d\n",
629 NET_VALUE(ddp->dst_net),
630 ddp->dst_node,
631 ifID->ifPort));
632
633 fillin_pkt_chain(*mp);
634
635 dPrintf(D_M_DDP, D_L_VERBOSE,
636 ("Looping back packet from skt 0x%x to skt 0x%x\n",
637 ddp->src_socket, ddp->dst_socket));
638
639 for (mdata = *mp; mdata; mdata = mdata_next) {
640 mdata_next = gbuf_next(mdata);
641 gbuf_next(mdata) = 0;
642 ddp_input(mdata, ifID);
643 }
644 goto exit_ddp_output;
645 }
646 if ((ddp->dst_socket == ZIP_SOCKET) &&
647 (zip_type_packet(*mp) == ZIP_GETMYZONE)) {
648 ddp->src_socket = src_socket;
649 error = zip_handle_getmyzone(ifID, *mp);
650 gbuf_freel(*mp);
651 goto exit_ddp_output;
652 }
653 /*
654 * find out the interface on which the packet should go out
655 */
656 TAILQ_FOREACH(ifID, &at_ifQueueHd, aa_link) {
657 if ((ifID->ifThisNode.s_net == dst_net) || (dst_net == 0))
658 /* the message is either going out (i) on the same
659 * NETWORK in case of LocalTalk, or (ii) on the same
660 * CABLE in case of Extended AppleTalk (EtherTalk).
661 */
662 break;
663
664 if ((ifID->ifThisCableStart <= dst_net) &&
665 (ifID->ifThisCableEnd >= dst_net)
666 )
667 /* We're on EtherTalk and the message is going out to
668 * some other network on the same cable.
669 */
670 break;
671
672 if (ARouterIf == NULL && ATALK_VALUE(ifID->ifARouter))
673 ARouterIf = ifID;
674 }
675 dPrintf(D_M_DDP_LOW, D_L_USR1,
676 ("ddp_output: after search ifid:0x%x %s ifID_home:0x%x\n",
677 (u_int)ifID, ifID ? ifID->ifName : "",
678 (u_int)ifID_home));
679
680 if (ifID) {
681 /* located the interface where the packet should
682 * go.... the "first-hop" destination address
683 * must be the same as real destination address.
684 */
685 addr_type = DIRECT_ADDR;
686 } else {
687 /* no, the destination network number does
688 * not match known network numbers. If we have
689 * heard from this network recently, BRT table
690 * may have address of a router we could use!
691 */
692 if (!MULTIPORT_MODE) {
693 BRT_LOOK (brt, dst_net);
694 if (brt) {
695 /* Bingo... BRT has an entry for this network.
696 * Use the link address as is.
697 */
698 dPrintf(D_M_DDP, D_L_VERBOSE,
699 ("Found BRT entry to send to net 0x%x", dst_net));
700 at_ddp_stats.xmit_BRT_used++;
701 addr_type = BRT_ENTRY;
702 ifID = brt->ifID;
703 } else {
704 /* No BRT entry available for dest network... do we
705 * know of any router at all??
706 */
707 if ((ifID = ARouterIf) != NULL)
708 addr_type = BRIDGE_ADDR;
709 else {
710 dPrintf(D_M_DDP, D_L_WARNING,
711 ("Found no interface to send pkt"));
712 at_ddp_stats.xmit_bad_addr++;
713 error = ENETUNREACH;
714 gbuf_freel(*mp);
715 goto exit_ddp_output;
716 }
717 }
718 }
719 else { /* We are in multiport mode, so we can bypass all the rest
720 * and directly ask for the routing of the packet
721 */
722 at_ddp_stats.xmit_BRT_used++;
723
724 ifID = ifID_home;
725 if (!src_addr_included) {
726 ddp->src_node = ifID->ifThisNode.s_node;
727 NET_ASSIGN(ddp->src_net, ifID->ifThisNode.s_net);
728 }
729 ddp->src_socket = src_socket;
730 routing_needed(*mp, ifID, TRUE);
731
732 goto exit_ddp_output;
733 }
734 }
735 /* by the time we land here, we know the interface on
736 * which this packet is going out.... ifID.
737 */
738 if (ifID->ifState == LAP_OFFLINE) {
739 gbuf_freel(*mp);
740 goto exit_ddp_output;
741 }
742
743 switch (addr_type) {
744 case DIRECT_ADDR :
745/*
746 at_dest.atalk_unused = 0;
747*/
748 NET_ASSIGN(at_dest.atalk_net, dst_net);
749 at_dest.atalk_node = ddp->dst_node;
750 addr_flag = AT_ADDR;
751 addr = (char *)&at_dest;
752 break;
753 case BRT_ENTRY :
754 addr_flag = ET_ADDR;
755 addr = (char *)&brt->et_addr;
756 break;
757 case BRIDGE_ADDR :
758 NET_ASSIGN(at_dest.atalk_net, ifID->ifARouter.s_net);
759 at_dest.atalk_node = ifID->ifARouter.s_node;
760 addr_flag = AT_ADDR;
761 addr = (char *)&at_dest;
762 break;
763
764 }
765 /* Irrespective of the interface on which
766 * the packet is going out, we always put the
767 * same source address on the packet (unless multihoming mode).
768 */
769 if (MULTIHOME_MODE) {
770 if (!src_addr_included) {
771 ddp->src_node = ifID->ifThisNode.s_node;
772 NET_ASSIGN(ddp->src_net, ifID->ifThisNode.s_net);
773 }
774 }
775 else {
776 ddp->src_node = ifID_home->ifThisNode.s_node;
777 NET_ASSIGN(ddp->src_net, ifID_home->ifThisNode.s_net);
778 }
779 ddp->src_socket = src_socket;
780
781 dPrintf(D_M_DDP_LOW, D_L_OUTPUT,
782 ("ddp_output: going out to %d:%d skt%d on %s\n",
783 dst_net, ddp->dst_node, ddp->dst_socket, ifID->ifName));
784
785 fillin_pkt_chain(*mp);
786
787 { /* begin block */
788 struct etalk_addr dest_addr;
789 struct atalk_addr dest_at_addr;
790 int loop = TRUE; /* flag to aarp to loopback (default) */
791
792 m = *mp;
793
794 /* the incoming frame is of the form {flag, address, ddp...}
795 * where "flag" indicates whether the address is an 802.3
796 * (link) address, or an appletalk address. If it's an
797 * 802.3 address, the packet can just go out to the network
798 * through PAT, if it's an appletalk address, AT->802.3 address
799 * resolution needs to be done.
800 * If 802.3 address is known, strip off the flag and 802.3
801 * address, and prepend 802.2 and 802.3 headers.
802 */
803
804 if (addr == NULL) {
805 addr_flag = *(u_char *)gbuf_rptr(m);
806 gbuf_rinc(m,1);
807 }
808
809 switch (addr_flag) {
810 case AT_ADDR_NO_LOOP :
811 loop = FALSE;
812 /* pass thru */
813 case AT_ADDR :
814 if (addr == NULL) {
815 dest_at_addr = *(struct atalk_addr *)gbuf_rptr(m);
816 gbuf_rinc(m,sizeof(struct atalk_addr));
817 } else
818 dest_at_addr = *(struct atalk_addr *)addr;
819 break;
820 case ET_ADDR :
821 if (addr == NULL) {
822 dest_addr = *(struct etalk_addr *)gbuf_rptr(m);
823 gbuf_rinc(m,sizeof(struct etalk_addr));
824 } else
825 dest_addr = *(struct etalk_addr *)addr;
826 break;
827 default :
828 dPrintf(D_M_DDP_LOW,D_L_ERROR,
829 ("ddp_output: Unknown addr_flag = 0x%x\n", addr_flag));
830 gbuf_freel(m); /* unknown address type, chuck it */
831 goto exit_ddp_output;
832 }
833
834 m = gbuf_strip(m);
835
836 /* At this point, rptr points to ddp header for sure */
837 if (ifID->ifState == LAP_ONLINE_FOR_ZIP) {
838 /* see if this is a ZIP packet that we need
839 * to let through even though network is
840 * not yet alive!!
841 */
842 if (zip_type_packet(m) == 0) {
843 gbuf_freel(m);
844 goto exit_ddp_output;
845 }
846 }
847
848 ifID->stats.xmit_packets++;
849 ifID->stats.xmit_bytes += gbuf_msgsize(m);
850 snmpStats.dd_outLong++;
851
852 switch (addr_flag) {
853 case AT_ADDR_NO_LOOP :
854 case AT_ADDR :
855 /*
856 * we don't want elap to be looking into ddp header, so
857 * it doesn't know net#, consequently can't do
858 * AMT_LOOKUP. That task left to aarp now.
859 */
5d5c5d0d 860 aarp_send_data(m,ifID, &dest_at_addr, loop);
1c79356b
A
861 break;
862 case ET_ADDR :
863 pat_output(ifID, m, &dest_addr, 0);
864 break;
865 }
866 } /* end block */
867 exit_ddp_output:
868 KERNEL_DEBUG(DBG_AT_DDP_OUTPUT | DBG_FUNC_END, 0,
869 error, 0, 0, 0);
870 return(error);
871} /* ddp_output */
872
873void ddp_input(mp, ifID)
874 register gbuf_t *mp;
875 register at_ifaddr_t *ifID;
876{
877 register at_ddp_t *ddp; /* DDP header */
878 register int msgsize;
879 register at_socket socket;
880 register int len;
881 register at_net_al dst_net;
882
883 KERNEL_DEBUG(DBG_AT_DDP_INPUT | DBG_FUNC_START, 0,
884 ifID, mp, gbuf_len(mp),0);
885
886 /* Makes sure we know the default interface before starting to
887 * accept incomming packets. If we don't we may end up with a
888 * null ifID_table[0] and have impredicable results (specially
889 * in router mode. This is a transitory state (because we can
890 * begin to receive packet while we're not completly set up yet.
891 */
892
893 if (ifID_home == (at_ifaddr_t *)NULL) {
894 dPrintf(D_M_DDP, D_L_ERROR,
895 ("dropped incoming packet ifID_home not set yet\n"));
896 gbuf_freem(mp);
897 goto out; /* return */
898 }
899
900 /*
901 * if a DDP packet has been broadcast, we're going to get a copy of
902 * it here; if it originated at user level via a write on a DDP
903 * socket; when it gets here, the first block in the chain will be
904 * empty since it only contained the lap level header which will be
905 * stripped in the lap level immediately below ddp
906 */
907
908 if ((mp = (gbuf_t *)ddp_compress_msg(mp)) == NULL) {
909 dPrintf(D_M_DDP, D_L_ERROR,
910 ("dropped short incoming ET packet (len %d)", 0));
911 snmpStats.dd_inTotal++;
912 at_ddp_stats.rcv_bad_length++;
913 goto out; /* return; */
914 }
915 msgsize = gbuf_msgsize(mp);
916
917 at_ddp_stats.rcv_bytes += msgsize;
918 at_ddp_stats.rcv_packets++;
919
920 /* if the interface pointer is 0, the packet has been
921 * looped back by 'write' half of DDP. It is of the
922 * form {extended ddp,...}. The packet is meant to go
923 * up to some socket on the same node.
924 */
925 if (!ifID) /* if loop back is specified */
926 ifID = ifID_home; /* that means the home port */
927
928 /* the incoming datagram has extended DDP header and is of
929 * the form {ddp,...}.
930 */
931 if (msgsize < DDP_X_HDR_SIZE) {
932 dPrintf(D_M_DDP, D_L_ERROR,
933 ("dropped short incoming ET packet (len %d)", msgsize));
934 at_ddp_stats.rcv_bad_length++;
935 gbuf_freem(mp);
936 goto out; /* return; */
937 }
938 /*
939 * At this point, the message is always of the form
940 * {extended ddp, ... }.
941 */
942 ddp = (at_ddp_t *)gbuf_rptr(mp);
5d5c5d0d 943 len = DDPLEN_VALUE(ddp);
1c79356b
A
944
945 if (msgsize != len) {
946 if ((unsigned) msgsize > len) {
947 if (len < DDP_X_HDR_SIZE) {
948 dPrintf(D_M_DDP, D_L_ERROR,
949 ("Length problems, ddp length %d, buffer length %d",
950 len, msgsize));
951 snmpStats.dd_tooLong++;
952 at_ddp_stats.rcv_bad_length++;
953 gbuf_freem(mp);
954 goto out; /* return; */
955 }
956 /*
957 * shave off the extra bytes from the end of message
958 */
959 mp = ddp_adjmsg(mp, -(msgsize - len)) ? mp : 0;
960 if (mp == 0)
961 goto out; /* return; */
962 } else {
963 dPrintf(D_M_DDP, D_L_ERROR,
964 ("Length problems, ddp length %d, buffer length %d",
965 len, msgsize));
966 snmpStats.dd_tooShort++;
967 at_ddp_stats.rcv_bad_length++;
968 gbuf_freem(mp);
969 goto out; /* return; */
970 }
971 }
972 socket = ddp->dst_socket;
973
974 /*
975 * We want everything in router mode, specially socket 254 for nbp so we need
976 * to bypass this test when we are a router.
977 */
978
979 if (!MULTIPORT_MODE && (socket > DDP_SOCKET_LAST ||
980 socket < DDP_SOCKET_1st_RESERVED)) {
981 dPrintf(D_M_DDP, D_L_WARNING,
982 ("Bad dst socket on incoming packet (0x%x)",
983 ddp->dst_socket));
984 at_ddp_stats.rcv_bad_socket++;
985 gbuf_freem(mp);
986 goto out; /* return; */
987 }
988 /*
989 * if the checksum is true, then upstream wants us to calc
990 */
991 if (UAS_VALUE(ddp->checksum) &&
5d5c5d0d 992 (UAS_VALUE_NTOH(ddp->checksum) != ddp_checksum(mp, 4))) {
1c79356b
A
993 dPrintf(D_M_DDP, D_L_WARNING,
994 ("Checksum error on incoming pkt, calc 0x%x, exp 0x%x",
5d5c5d0d 995 ddp_checksum(mp, 4), UAS_VALUE_NTOH(ddp->checksum)));
1c79356b
A
996 snmpStats.dd_checkSum++;
997 at_ddp_stats.rcv_bad_checksum++;
998 gbuf_freem(mp);
999 goto out; /* return; */
1000 }
1001
1002/*############### routing input checking */
1003
1004/* Router mode special: we send "up-stack" packets for this node or coming from any
1005 * other ports, but for the reserved atalk sockets (RTMP, ZIP, NBP [and EP])
1006 * BTW, the way we know it's for the router and not the home port is that the
1007 * MAC (ethernet) address is always the one of the interface we're on, but
1008 * the AppleTalk address must be the one of the home port. If it's a multicast
1009 * or another AppleTalk address, this is the router job's to figure out where it's
1010 * going to go.
1011 */
1012 /* *** a duplicate should be sent to any other client that is listening
1013 for packets of this type on a raw DDP socket *** */
1014 if (ddp_handler[socket].func) {
1015 dPrintf(D_M_DDP,D_L_INPUT,
1016 ("ddp_input: skt %d hdnlr:0x%x\n",
1017 (u_int) socket, ddp_handler[socket].func));
1018 pktsHome++;
1019 snmpStats.dd_inLocal++;
1020
1021 (*ddp_handler[socket].func)(mp, ifID);
1022 goto out; /* return; */
1023 }
1024 dst_net = NET_VALUE(ddp->dst_net);
1025 if (
1026 /* exact match */
1027 forUs(ddp) ||
1028 /* any node, wildcard or matching net */
1029 ((ddp->dst_node == 255) &&
1030 (((dst_net >= ifID_home->ifThisCableStart) &&
1031 (dst_net <= ifID_home->ifThisCableEnd)) ||
1032 dst_net == 0)) ||
1033 /* this node is not online yet(?) */
1034 (ifID->ifRoutingState < PORT_ONLINE)
1035 ) {
1036 gref_t *gref;
1037 pktsHome++;
1038 snmpStats.dd_inLocal++;
1039
1040 if (ddp->type == DDP_ATP) {
1041 if (atp_inputQ[socket] && (atp_inputQ[socket] != (gref_t *)1)) {
1042 /* if there's an ATP pcb */
1043 atp_input(mp);
1044 goto out; /* return; */
1045 }
1046 } else if (ddp->type == DDP_ADSP) {
1047 if (adsp_inputQ[socket]) {
1048 /* if there's an ADSP pcb */
1049 adsp_input(mp);
1050 goto out; /* return; */
1051 }
1052 }
1053
1054 /* otherwise look for a DDP pcb;
1055 ATP / raw-DDP and ADSP / raw-DDP are possible */
1056 for (gref = ddp_head.atpcb_next; gref != &ddp_head;
1057 gref = gref->atpcb_next)
0b4e3aa0
A
1058 if (gref->lport == socket &&
1059 (gref->ddptype == 0 || gref->ddptype == ddp->type)) {
1060 dPrintf(D_M_DDP, D_L_INPUT,
1061 ("ddp_input: streamq, skt %d\n", socket));
1c79356b
A
1062 if (gref->atpcb_socket) {
1063 struct sockaddr_at ddp_in;
1064 ddp_in.sat_len = sizeof(ddp_in);
1065 ddp_in.sat_family = AF_APPLETALK;
1066 ddp_in.sat_addr.s_net = NET_VALUE(ddp->src_net);
1067 ddp_in.sat_addr.s_node = ddp->src_node;
1068 ddp_in.sat_port = ddp->src_socket;
1069
1070 /* strip off DDP header if so indicated by
1071 sockopt */
1072 if (gref->ddp_flags & DDPFLG_STRIPHDR) {
1073 mp = m_pullup((struct mbuf *)mp,
1074 DDP_X_HDR_SIZE);
1075 if (mp) {
1076 gbuf_rinc(mp, DDP_X_HDR_SIZE);
1077 } else {
1078 /* this should never happen because
1079 msgsize was checked earlier */
1080 at_ddp_stats.rcv_bad_length++;
1081 goto out; /* return */
1082 }
1083 }
1084
1085 if (sbappendaddr(&((gref->atpcb_socket)->so_rcv),
1086 (struct sockaddr *)&ddp_in,
91447636 1087 mp, 0, NULL) != 0) {
1c79356b 1088 sorwakeup(gref->atpcb_socket);
91447636 1089 }
1c79356b
A
1090 } else {
1091 atalk_putnext(gref, mp);
1092 }
1093 goto out; /* return */
1094 }
1095
1096 at_ddp_stats.rcv_bad_socket++;
1097 gbuf_freem(mp);
1098 snmpStats.dd_noHandler++;
1099 dPrintf(D_M_DDP, D_L_WARNING,
1100 ("ddp_input: dropped pkt for socket %d\n", socket));
1101 } else {
1102 dPrintf(D_M_DDP, D_L_ROUTING,
1103 ("ddp_input: routing_needed from port=%d sock=%d\n",
1104 ifID->ifPort, ddp->dst_socket));
1105
1106 snmpStats.dd_fwdReq++;
1107 if (((pktsIn-pktsHome+200) >= RouterMix) && ((++pktsDropped % 5) == 0)) {
1108 at_ddp_stats.rcv_dropped_nobuf++;
1109 gbuf_freem(mp);
1110 }
1111 else {
1112 routing_needed(mp, ifID, FALSE);
1113 }
1114 }
1115out:
1116 KERNEL_DEBUG(DBG_AT_DDP_INPUT | DBG_FUNC_END, 0,0,0,0,0);
1117} /* ddp_input */
1118
1119
1120/*
1121 * ddp_router_output()
1122 *
1123 * Remarks :
1124 * This is a modified version of ddp_output for router use.
1125 * The main difference is that the interface on which the packet needs
1126 * to be sent is specified and a *destination* AppleTalk address is passed
1127 * as an argument, this address may or may not be the same as the destination
1128 * address found in the ddp packet... This is the trick about routing, the
1129 * AppleTalk destination of the packet may not be the same as the Enet address
1130 * we send the packet too (ie, we may pass the baby to another router).
1131 *
1132 */
1133int ddp_router_output(mp, ifID, addr_type, router_net, router_node, enet_addr)
1134 gbuf_t *mp;
1135 at_ifaddr_t *ifID;
1136 int addr_type;
1137 at_net_al router_net;
1138 at_node router_node;
1139 etalk_addr_t *enet_addr;
1140{
1141 register at_ddp_t *ddp;
1142 struct atalk_addr at_dest;
1143 int addr_flag;
1144 char *addr = NULL;
1145 register gbuf_t *m;
1146
1147 if (!ifID) {
1148 dPrintf(D_M_DDP, D_L_WARNING, ("BAD BAD ifID\n"));
1149 gbuf_freel(mp);
1150 return(EPROTOTYPE);
1151 }
1152 ddp = (at_ddp_t *)gbuf_rptr(mp);
1153
5d5c5d0d 1154#ifdef AURP_SUPPORT
1c79356b
A
1155 if (ifID->ifFlags & AT_IFF_AURP) { /* AURP link? */
1156 if (ddp_AURPsendx) {
1157 fillin_pkt_chain(mp);
1158 if (router_node == 255)
1159 router_node = 0;
1160 ddp_AURPsendx(AURPCODE_DATAPKT, mp, router_node);
1161 return 0;
1162 } else {
1163 gbuf_freel(mp);
1164 return EPROTOTYPE;
1165 }
1166 }
5d5c5d0d 1167#endif
1c79356b
A
1168
1169 /* keep some of the tests for now ####### */
1170
1171 if (gbuf_msgsize(mp) > DDP_DATAGRAM_SIZE) {
1172 /* the packet is too large */
1173 dPrintf(D_M_DDP, D_L_WARNING,
1174 ("ddp_router_output: Packet too large size=%d\n",
1175 gbuf_msgsize(mp)));
1176 gbuf_freel(mp);
1177 return (EMSGSIZE);
1178 }
1179
1180 switch (addr_type) {
1181
1182 case AT_ADDR :
1183
1184 /*
1185 * Check for packet destined to the home stack
1186 */
1187
1188 if ((ddp->dst_node == ifID->ifThisNode.s_node) &&
1189 (NET_VALUE(ddp->dst_net) == ifID->ifThisNode.s_net)) {
1190 dPrintf(D_M_DDP_LOW, D_L_ROUTING,
1191 ("ddp_r_output: sending back home from port=%d socket=%d\n",
1192 ifID->ifPort, ddp->dst_socket));
1193
1194 UAS_ASSIGN(ddp->checksum, 0);
1195 ddp_input(mp, ifID);
1196 return(0);
1197 }
1198
1199 NET_ASSIGN(at_dest.atalk_net, router_net);
1200 at_dest.atalk_node = router_node;
1201
1202 addr_flag = AT_ADDR_NO_LOOP;
1203 addr = (char *)&at_dest;
1204 dPrintf(D_M_DDP_LOW, D_L_ROUTING_AT,
1205 ("ddp_r_output: AT_ADDR out port=%d net %d:%d via rte %d:%d",
1206 ifID->ifPort, NET_VALUE(ddp->dst_net), ddp->dst_node, router_net,
1207 router_node));
1208 break;
1209
1210 case ET_ADDR :
1211 addr_flag = ET_ADDR;
1212 addr = (char *)enet_addr;
1213 dPrintf(D_M_DDP_LOW, D_L_ROUTING,
1214 ("ddp_r_output: ET_ADDR out port=%d net %d:%d\n",
1215 ifID->ifPort, NET_VALUE(ddp->dst_net), ddp->dst_node));
1216 break;
1217 }
1218
1219 if (ifID->ifState == LAP_OFFLINE) {
1220 gbuf_freel(mp);
1221 return 0;
1222 }
1223
1224 fillin_pkt_chain(mp);
1225
1226 { /* begin block */
1227 struct etalk_addr dest_addr;
1228 struct atalk_addr dest_at_addr;
1229 int loop = TRUE; /* flag to aarp to loopback (default) */
1230
1231 m = mp;
1232
1233 /* the incoming frame is of the form {flag, address, ddp...}
1234 * where "flag" indicates whether the address is an 802.3
1235 * (link) address, or an appletalk address. If it's an
1236 * 802.3 address, the packet can just go out to the network
1237 * through PAT, if it's an appletalk address, AT->802.3 address
1238 * resolution needs to be done.
1239 * If 802.3 address is known, strip off the flag and 802.3
1240 * address, and prepend 802.2 and 802.3 headers.
1241 */
1242
1243 if (addr == NULL) {
1244 addr_flag = *(u_char *)gbuf_rptr(m);
1245 gbuf_rinc(m,1);
1246 }
1247
1248 switch (addr_flag) {
1249 case AT_ADDR_NO_LOOP :
1250 loop = FALSE;
1251 /* pass thru */
1252 case AT_ADDR :
1253 if (addr == NULL) {
1254 dest_at_addr = *(struct atalk_addr *)gbuf_rptr(m);
1255 gbuf_rinc(m,sizeof(struct atalk_addr));
1256 } else
1257 dest_at_addr = *(struct atalk_addr *)addr;
1258 break;
1259 case ET_ADDR :
1260 if (addr == NULL) {
1261 dest_addr = *(struct etalk_addr *)gbuf_rptr(m);
1262 gbuf_rinc(m,sizeof(struct etalk_addr));
1263 } else
1264 dest_addr = *(struct etalk_addr *)addr;
1265 break;
1266 default :
1267 dPrintf(D_M_DDP_LOW,D_L_ERROR,
1268 ("ddp_router_output: Unknown addr_flag = 0x%x\n", addr_flag));
1269
1270 gbuf_freel(m); /* unknown address type, chuck it */
1271 return 0;
1272 }
1273
1274 m = gbuf_strip(m);
1275
1276 /* At this point, rptr points to ddp header for sure */
1277 if (ifID->ifState == LAP_ONLINE_FOR_ZIP) {
1278 /* see if this is a ZIP packet that we need
1279 * to let through even though network is
1280 * not yet alive!!
1281 */
1282 if (zip_type_packet(m) == 0) {
1283 gbuf_freel(m);
1284 return 0;
1285 }
1286 }
1287
1288 ifID->stats.xmit_packets++;
1289 ifID->stats.xmit_bytes += gbuf_msgsize(m);
1290 snmpStats.dd_outLong++;
1291
1292 switch (addr_flag) {
1293 case AT_ADDR_NO_LOOP :
1294 case AT_ADDR :
1295 /*
1296 * we don't want elap to be looking into ddp header, so
1297 * it doesn't know net#, consequently can't do
1298 * AMT_LOOKUP. That task left to aarp now.
1299 */
1300 aarp_send_data(m,ifID,&dest_at_addr, loop);
1301 break;
1302 case ET_ADDR :
1303 pat_output(ifID, m, &dest_addr, 0);
1304 break;
1305 }
1306 } /* end block */
1307
1308 return(0);
1309} /* ddp_router_output */
1310
1311/*****************************************/
1312
1313void rt_delete(NetStop, NetStart)
1314 unsigned short NetStop;
1315 unsigned short NetStart;
1316{
1317 RT_entry *found;
1318 int s;
1319
1c79356b
A
1320 if ((found = rt_bdelete(NetStop, NetStart)) != 0) {
1321 bzero(found, sizeof(RT_entry));
1322 found->right = RT_table_freelist;
1323 RT_table_freelist = found;
1324 }
1c79356b
A
1325}
1326
5d5c5d0d 1327#ifdef AURP_SUPPORT
1c79356b
A
1328int ddp_AURPfuncx(code, param, node)
1329 int code;
1330 void *param;
1331 unsigned char node;
1332{
1333 extern void rtmp_timeout();
1334 extern void rtmp_send_port();
1335 at_ifaddr_t *ifID;
1336 int k;
1337
1338 switch (code) {
1339 case AURPCODE_DATAPKT: /* data packet */
1340 if (aurp_ifID) {
1341 dPrintf(D_M_DDP, D_L_TRACE, ("ddp_AURPfuncx: data, 0x%x, %d\n",
1342 (u_int) aurp_ifID, node));
1343
1344 ddp_input((gbuf_t *)param, aurp_ifID);
1345 } else
1346 gbuf_freem((gbuf_t *)param);
1347 break;
1348
1349 case AURPCODE_REG: /* register/deregister */
1350 if (!ROUTING_MODE)
1351 return -1;
1352 ddp_AURPsendx = (void(*)())param;
1353
1354 if (param) {
1355 /* register AURP callback function */
1356 if (aurp_ifID)
1357 return 0;
1358 for (k=(IFID_HOME+1); k < IF_TOTAL_MAX; k++) {
1359 if (ifID_table[k] == 0) {
1360 aurp_ifID = &at_interfaces[k];
1361 aurp_ifID->ifFlags = RTR_XNET_PORT;
1362 ddp_add_if(aurp_ifID);
1363 aurp_ifID->ifState = LAP_ONLINE;
1364 aurp_ifID->ifRoutingState = PORT_ONLINE;
1365 dPrintf(D_M_DDP, D_L_TRACE,
1366 ("ddp_AURPfuncx: on, 0x%x\n",
1367 (u_int) aurp_ifID));
1368
1369 ddp_AURPsendx(AURPCODE_DEBUGINFO,
1370 &dbgBits, aurp_ifID->ifPort);
1371 return 0;
1372 }
1373 }
1374 return -1;
1375
1376 } else {
1377 /* deregister AURP callback function */
1378 if (aurp_ifID) {
1379 rtmp_purge(aurp_ifID);
1380 ddp_rem_if(aurp_ifID);
1381 aurp_ifID->ifState = LAP_OFFLINE;
1382 aurp_ifID->ifRoutingState = PORT_OFFLINE;
1383 dPrintf(D_M_DDP, D_L_TRACE,
1384 ("ddp_AURPfuncx: off, 0x%x\n", (u_int) aurp_ifID));
1385 aurp_ifID = 0;
1386 }
1387 }
1388 break;
1389
1390 case AURPCODE_AURPPROTO: /* proto type - AURP */
1391 if (aurp_ifID) {
1392 aurp_ifID->ifFlags |= AT_IFF_AURP;
1393 }
1394 break;
1395 }
1396
1397 return 0;
1398}
5d5c5d0d 1399#endif
1c79356b
A
1400
1401/* checks to see if address of packet is for one of our interfaces
1402 returns *ifID if it's for us, NULL if not
1403*/
1404at_ifaddr_t *forUs(ddp)
1405 register at_ddp_t *ddp;
1406{
1407 at_ifaddr_t *ifID;
1408
1409 TAILQ_FOREACH(ifID, &at_ifQueueHd, aa_link) {
1410 if ((ddp->dst_node == ifID->ifThisNode.s_node) &&
1411 (NET_VALUE(ddp->dst_net) == ifID->ifThisNode.s_net)
1412 ) {
1413 dPrintf(D_M_DDP_LOW, D_L_ROUTING,
1414 ("pkt was for port %d\n", ifID->ifPort));
1415
1416 return(ifID);
1417 }
1418 }
1419
1420 return((at_ifaddr_t *)NULL);
1421} /* forUs */