2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
9 #include <sys/sockio.h>
10 #include <sys/malloc.h>
11 #include <sys/kernel.h>
12 #include <sys/socket.h>
14 #include <net/route.h>
15 #include <netinet/in.h>
17 #include <netinet/if_ether.h>
19 #include <netatalk/at.h>
20 #include <netatalk/at_var.h>
21 #include <netatalk/at_extern.h>
23 struct at_ifaddr *at_ifaddr;
25 static int aa_dorangeroute(struct ifaddr *ifa,
26 u_int first, u_int last, int cmd);
27 static int aa_addsingleroute(struct ifaddr *ifa,
28 struct at_addr *addr, struct at_addr *mask);
29 static int aa_delsingleroute(struct ifaddr *ifa,
30 struct at_addr *addr, struct at_addr *mask);
31 static int aa_dosingleroute(struct ifaddr *ifa, struct at_addr *addr,
32 struct at_addr *mask, int cmd, int flags);
33 static int at_scrub( struct ifnet *ifp, struct at_ifaddr *aa );
34 static int at_ifinit( struct ifnet *ifp, struct at_ifaddr *aa,
35 struct sockaddr_at *sat );
36 static int aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw);
38 # define sateqaddr(a,b) ((a)->sat_len == (b)->sat_len && \
39 (a)->sat_family == (b)->sat_family && \
40 (a)->sat_addr.s_net == (b)->sat_addr.s_net && \
41 (a)->sat_addr.s_node == (b)->sat_addr.s_node )
44 at_control(struct socket *so, u_long cmd, caddr_t data,
45 struct ifnet *ifp, struct proc *p )
47 struct ifreq *ifr = (struct ifreq *)data;
48 struct sockaddr_at *sat;
50 struct at_aliasreq *ifra = (struct at_aliasreq *)data;
51 struct at_ifaddr *aa0;
52 struct at_ifaddr *aa = 0;
53 struct ifaddr *ifa, *ifa0;
56 * If we have an ifp, then find the matching at_ifaddr if it exists
59 for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
60 if ( aa->aa_ifp == ifp ) break;
65 * In this first switch table we are basically getting ready for
66 * the second one, by getting the atalk-specific things set up
67 * so that they start to look more similar to other protocols etc.
74 * If we have an appletalk sockaddr, scan forward of where
75 * we are now on the at_ifaddr list to find one with a matching
76 * address on this interface.
77 * This may leave aa pointing to the first address on the
80 if ( ifra->ifra_addr.sat_family == AF_APPLETALK ) {
81 for ( ; aa; aa = aa->aa_next ) {
82 if ( aa->aa_ifp == ifp &&
83 sateqaddr( &aa->aa_addr, &ifra->ifra_addr )) {
89 * If we a retrying to delete an addres but didn't find such,
90 * then rewurn with an error
92 if ( cmd == SIOCDIFADDR && aa == 0 ) {
93 return( EADDRNOTAVAIL );
99 * If we are not superuser, then we don't get to do these ops.
104 sat = satosat( &ifr->ifr_addr );
105 nr = (struct netrange *)sat->sat_zero;
106 if ( nr->nr_phase == 1 ) {
108 * Look for a phase 1 address on this interface.
109 * This may leave aa pointing to the first address on the
112 for ( ; aa; aa = aa->aa_next ) {
113 if ( aa->aa_ifp == ifp &&
114 ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
118 } else { /* default to phase 2 */
120 * Look for a phase 2 address on this interface.
121 * This may leave aa pointing to the first address on the
124 for ( ; aa; aa = aa->aa_next ) {
125 if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) {
132 panic( "at_control" );
135 * If we failed to find an existing at_ifaddr entry, then we
136 * allocate a fresh one.
138 if ( aa == (struct at_ifaddr *) 0 ) {
139 aa0 = malloc(sizeof(struct at_ifaddr), M_IFADDR, M_WAITOK);
140 bzero(aa0, sizeof(struct at_ifaddr));
141 if (( aa = at_ifaddr ) != NULL ) {
143 * Don't let the loopback be first, since the first
144 * address is the machine's default address for
146 * If it is, stick ourself in front, otherwise
147 * go to the back of the list.
149 if ( at_ifaddr->aa_ifp->if_flags & IFF_LOOPBACK ) {
151 aa->aa_next = at_ifaddr;
154 for ( ; aa->aa_next; aa = aa->aa_next )
162 * Don't Add a reference for the aa itself!
163 * I fell into this trap. IFAFREE tests for <=0
164 * not <= 1 like RTFREE
166 /* aa->aa_ifa.ifa_refcnt++; DON'T DO THIS!! */
170 * Find the end of the interface's addresses
171 * and link our new one on the end
173 ifa = (struct ifaddr *)aa;
174 TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
177 * Add a reference for the linking into the ifp_if_addrlist.
182 * As the at_ifaddr contains the actual sockaddrs,
183 * and the ifaddr itself, link them al together correctly.
185 ifa->ifa_addr = (struct sockaddr *)&aa->aa_addr;
186 ifa->ifa_dstaddr = (struct sockaddr *)&aa->aa_addr;
187 ifa->ifa_netmask = (struct sockaddr *)&aa->aa_netmask;
190 * Set/clear the phase 2 bit.
192 if ( nr->nr_phase == 1 ) {
193 aa->aa_flags &= ~AFA_PHASE2;
195 aa->aa_flags |= AFA_PHASE2;
199 * and link it all together
204 * If we DID find one then we clobber any routes dependent on it..
211 sat = satosat( &ifr->ifr_addr );
212 nr = (struct netrange *)sat->sat_zero;
213 if ( nr->nr_phase == 1 ) {
215 * If the request is specifying phase 1, then
216 * only look at a phase one address
218 for ( ; aa; aa = aa->aa_next ) {
219 if ( aa->aa_ifp == ifp &&
220 ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
228 for ( ; aa; aa = aa->aa_next ) {
229 if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) {
235 if ( aa == (struct at_ifaddr *) 0 )
236 return( EADDRNOTAVAIL );
241 * By the time this switch is run we should be able to assume that
242 * the "aa" pointer is valid when needed.
248 * copy the contents of the sockaddr blindly.
250 sat = (struct sockaddr_at *)&ifr->ifr_addr;
254 * and do some cleanups
256 ((struct netrange *)&sat->sat_zero)->nr_phase
257 = (aa->aa_flags & AFA_PHASE2) ? 2 : 1;
258 ((struct netrange *)&sat->sat_zero)->nr_firstnet = aa->aa_firstnet;
259 ((struct netrange *)&sat->sat_zero)->nr_lastnet = aa->aa_lastnet;
263 return( at_ifinit( ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr ));
266 if ( sateqaddr( &ifra->ifra_addr, &aa->aa_addr )) {
269 return( at_ifinit( ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr ));
273 * scrub all routes.. didn't we just DO this? XXX yes, del it
278 * remove the ifaddr from the interface
280 ifa0 = (struct ifaddr *)aa;
281 TAILQ_REMOVE(&ifp->if_addrhead, ifa0, ifa_link);
284 * refs goes from 1->0 if no external refs. note..
285 * This will not free it ... looks for -1.
290 * Now remove the at_ifaddr from the parallel structure
291 * as well, or we'd be in deep trouble
294 if ( aa0 == ( aa = at_ifaddr )) {
295 at_ifaddr = aa->aa_next;
297 while ( aa->aa_next && ( aa->aa_next != aa0 )) {
302 * if we found it, remove it, otherwise we screwed up.
305 aa->aa_next = aa0->aa_next;
307 panic( "at_control" );
312 * Now dump the memory we were using.
313 * Decrement the reference count.
314 * This should probably be the last reference
315 * as the count will go from 0 to -1.
316 * (unless there is still a route referencing this)
322 if ( ifp == 0 || ifp->if_ioctl == 0 )
323 return( EOPNOTSUPP );
324 return( (*ifp->if_ioctl)( ifp, cmd, data ));
330 * Given an interface and an at_ifaddr (supposedly on that interface)
331 * remove any routes that depend on this.
332 * Why ifp is needed I'm not sure,
333 * as aa->at_ifaddr.ifa_ifp should be the same.
338 struct at_ifaddr *aa;
342 if ( aa->aa_flags & AFA_ROUTE ) {
343 if (ifp->if_flags & IFF_LOOPBACK) {
344 if ((error = aa_delsingleroute(&aa->aa_ifa,
345 &aa->aa_addr.sat_addr,
346 &aa->aa_netmask.sat_addr)) != 0) {
349 } else if (ifp->if_flags & IFF_POINTOPOINT) {
350 if ((error = rtinit( &aa->aa_ifa, RTM_DELETE, RTF_HOST)) != 0)
352 } else if (ifp->if_flags & IFF_BROADCAST) {
353 error = aa_dorangeroute(&aa->aa_ifa,
354 ntohs(aa->aa_firstnet),
355 ntohs(aa->aa_lastnet),
358 aa->aa_ifa.ifa_flags &= ~IFA_ROUTE;
359 aa->aa_flags &= ~AFA_ROUTE;
365 * given an at_ifaddr,a sockaddr_at and an ifp,
366 * bang them all together at high speed and see what happens
369 at_ifinit( ifp, aa, sat )
371 struct at_ifaddr *aa;
372 struct sockaddr_at *sat;
374 struct netrange nr, onr;
375 struct sockaddr_at oldaddr;
376 int s = splimp(), error = 0, i, j;
377 int netinc, nodeinc, nnets;
381 * save the old addresses in the at_ifaddr just in case we need them.
383 oldaddr = aa->aa_addr;
384 onr.nr_firstnet = aa->aa_firstnet;
385 onr.nr_lastnet = aa->aa_lastnet;
388 * take the address supplied as an argument, and add it to the
389 * at_ifnet (also given). Remember ing to update
390 * those parts of the at_ifaddr that need special processing
392 bzero( AA_SAT( aa ), sizeof( struct sockaddr_at ));
393 bcopy( sat->sat_zero, &nr, sizeof( struct netrange ));
394 bcopy( sat->sat_zero, AA_SAT( aa )->sat_zero, sizeof( struct netrange ));
395 nnets = ntohs( nr.nr_lastnet ) - ntohs( nr.nr_firstnet ) + 1;
396 aa->aa_firstnet = nr.nr_firstnet;
397 aa->aa_lastnet = nr.nr_lastnet;
401 printf("at_ifinit: %s: %u.%u range %u-%u phase %d\n",
403 ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
404 ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet),
405 (aa->aa_flags & AFA_PHASE2) ? 2 : 1);
409 * We could eliminate the need for a second phase 1 probe (post
410 * autoconf) if we check whether we're resetting the node. Note
411 * that phase 1 probes use only nodes, not net.node pairs. Under
412 * phase 2, both the net and node must be the same.
414 if ( ifp->if_flags & IFF_LOOPBACK ) {
415 AA_SAT( aa )->sat_len = sat->sat_len;
416 AA_SAT( aa )->sat_family = AF_APPLETALK;
417 AA_SAT( aa )->sat_addr.s_net = sat->sat_addr.s_net;
418 AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node;
420 } else if ( fp->if_flags & IFF_POINTOPOINT) {
423 * we'd have to copy the dstaddr field over from the sat
424 * but it's not clear that it would contain the right info..
429 * We are a normal (probably ethernet) interface.
430 * apply the new address to the interface structures etc.
431 * We will probe this address on the net first, before
432 * applying it to ensure that it is free.. If it is not, then
433 * we will try a number of other randomly generated addresses
434 * in this net and then increment the net. etc.etc. until
435 * we find an unused address.
437 aa->aa_flags |= AFA_PROBING; /* if not loopback we Must probe? */
438 AA_SAT( aa )->sat_len = sizeof(struct sockaddr_at);
439 AA_SAT( aa )->sat_family = AF_APPLETALK;
440 if ( aa->aa_flags & AFA_PHASE2 ) {
441 if ( sat->sat_addr.s_net == ATADDR_ANYNET ) {
443 * If we are phase 2, and the net was not specified
444 * then we select a random net within the supplied netrange.
445 * XXX use /dev/random?
448 net = ntohs( nr.nr_firstnet ) + time_second % ( nnets - 1 );
450 net = ntohs( nr.nr_firstnet );
454 * if a net was supplied, then check that it is within
455 * the netrange. If it is not then replace the old values
456 * and return an error
458 if ( ntohs( sat->sat_addr.s_net ) < ntohs( nr.nr_firstnet ) ||
459 ntohs( sat->sat_addr.s_net ) > ntohs( nr.nr_lastnet )) {
460 aa->aa_addr = oldaddr;
461 aa->aa_firstnet = onr.nr_firstnet;
462 aa->aa_lastnet = onr.nr_lastnet;
467 * otherwise just use the new net number..
469 net = ntohs( sat->sat_addr.s_net );
473 * we must be phase one, so just use whatever we were given.
474 * I guess it really isn't going to be used... RIGHT?
476 net = ntohs( sat->sat_addr.s_net );
480 * set the node part of the address into the ifaddr.
481 * If it's not specified, be random about it...
482 * XXX use /dev/random?
484 if ( sat->sat_addr.s_node == ATADDR_ANYNODE ) {
485 AA_SAT( aa )->sat_addr.s_node = time_second;
487 AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node;
493 AA_SAT( aa )->sat_range.r_netrange.nr_phase
494 = ((aa->aa_flags & AFA_PHASE2) ? 2:1);
497 * step through the nets in the range
498 * starting at the (possibly random) start point.
500 for ( i = nnets, netinc = 1; i > 0; net = ntohs( nr.nr_firstnet ) +
501 (( net - ntohs( nr.nr_firstnet ) + netinc ) % nnets ), i-- ) {
502 AA_SAT( aa )->sat_addr.s_net = htons( net );
505 * using a rather strange stepping method,
506 * stagger through the possible node addresses
507 * Once again, starting at the (possibly random)
508 * initial node address.
510 for ( j = 0, nodeinc = time_second | 1; j < 256;
511 j++, AA_SAT( aa )->sat_addr.s_node += nodeinc ) {
512 if ( AA_SAT( aa )->sat_addr.s_node > 253 ||
513 AA_SAT( aa )->sat_addr.s_node < 1 ) {
519 * start off the probes as an asynchronous activity.
520 * though why wait 200mSec?
522 aa->aa_ch = timeout( aarpprobe, (caddr_t)ifp, hz / 5 );
523 if ( tsleep( aa, PPAUSE|PCATCH, "at_ifinit", 0 )) {
525 * theoretically we shouldn't time out here
526 * so if we returned with an error..
528 printf( "at_ifinit: why did this happen?!\n" );
529 aa->aa_addr = oldaddr;
530 aa->aa_firstnet = onr.nr_firstnet;
531 aa->aa_lastnet = onr.nr_lastnet;
537 * The async activity should have woken us up.
538 * We need to see if it was successful in finding
539 * a free spot, or if we need to iterate to the next
542 if (( aa->aa_flags & AFA_PROBING ) == 0 ) {
548 * of course we need to break out through two loops...
550 if (( aa->aa_flags & AFA_PROBING ) == 0 ) {
553 /* reset node for next network */
554 AA_SAT( aa )->sat_addr.s_node = time_second;
558 * if we are still trying to probe, then we have finished all
559 * the possible addresses, so we need to give up
562 if ( aa->aa_flags & AFA_PROBING ) {
563 aa->aa_addr = oldaddr;
564 aa->aa_firstnet = onr.nr_firstnet;
565 aa->aa_lastnet = onr.nr_lastnet;
567 return( EADDRINUSE );
572 * Now that we have selected an address, we need to tell the interface
573 * about it, just in case it needs to adjust something.
575 if ( ifp->if_ioctl &&
576 ( error = (*ifp->if_ioctl)( ifp, SIOCSIFADDR, (caddr_t)aa ))) {
578 * of course this could mean that it objects violently
579 * so if it does, we back out again..
581 aa->aa_addr = oldaddr;
582 aa->aa_firstnet = onr.nr_firstnet;
583 aa->aa_lastnet = onr.nr_lastnet;
589 * set up the netmask part of the at_ifaddr
590 * and point the appropriate pointer in the ifaddr to it.
591 * probably pointless, but what the heck.. XXX
593 bzero(&aa->aa_netmask, sizeof(aa->aa_netmask));
594 aa->aa_netmask.sat_len = sizeof(struct sockaddr_at);
595 aa->aa_netmask.sat_family = AF_APPLETALK;
596 aa->aa_netmask.sat_addr.s_net = 0xffff;
597 aa->aa_netmask.sat_addr.s_node = 0;
598 aa->aa_ifa.ifa_netmask =(struct sockaddr *) &(aa->aa_netmask); /* XXX */
601 * Initialize broadcast (or remote p2p) address
603 bzero(&aa->aa_broadaddr, sizeof(aa->aa_broadaddr));
604 aa->aa_broadaddr.sat_len = sizeof(struct sockaddr_at);
605 aa->aa_broadaddr.sat_family = AF_APPLETALK;
607 aa->aa_ifa.ifa_metric = ifp->if_metric;
608 if (ifp->if_flags & IFF_BROADCAST) {
609 aa->aa_broadaddr.sat_addr.s_net = htons(0);
610 aa->aa_broadaddr.sat_addr.s_node = 0xff;
611 aa->aa_ifa.ifa_broadaddr = (struct sockaddr *) &aa->aa_broadaddr;
612 /* add the range of routes needed */
613 error = aa_dorangeroute(&aa->aa_ifa,
614 ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet), RTM_ADD );
616 else if (ifp->if_flags & IFF_POINTOPOINT) {
617 struct at_addr rtaddr, rtmask;
619 bzero(&rtaddr, sizeof(rtaddr));
620 bzero(&rtmask, sizeof(rtmask));
621 /* fill in the far end if we know it here XXX */
622 aa->aa_ifa.ifa_dstaddr = (struct sockaddr *) &aa->aa_dstaddr;
623 error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask);
625 else if ( ifp->if_flags & IFF_LOOPBACK ) {
626 struct at_addr rtaddr, rtmask;
628 bzero(&rtaddr, sizeof(rtaddr));
629 bzero(&rtmask, sizeof(rtmask));
630 rtaddr.s_net = AA_SAT( aa )->sat_addr.s_net;
631 rtaddr.s_node = AA_SAT( aa )->sat_addr.s_node;
632 rtmask.s_net = 0xffff;
633 rtmask.s_node = 0x0; /* XXX should not be so.. should be HOST route */
634 error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask);
639 * set the address of our "check if this addr is ours" routine.
641 aa->aa_ifa.ifa_claim_addr = aa_claim_addr;
644 * of course if we can't add these routes we back out, but it's getting
649 aa->aa_addr = oldaddr;
650 aa->aa_firstnet = onr.nr_firstnet;
651 aa->aa_lastnet = onr.nr_lastnet;
657 * note that the address has a route associated with it....
659 aa->aa_ifa.ifa_flags |= IFA_ROUTE;
660 aa->aa_flags |= AFA_ROUTE;
666 * check whether a given address is a broadcast address for us..
670 struct sockaddr_at *sat;
672 struct at_ifaddr *aa;
675 * If the node is not right, it can't be a broadcast
677 if ( sat->sat_addr.s_node != ATADDR_BCAST ) {
682 * If the node was right then if the net is right, it's a broadcast
684 if ( sat->sat_addr.s_net == ATADDR_ANYNET ) {
689 * failing that, if the net is one we have, it's a broadcast as well.
691 for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
692 if (( aa->aa_ifp->if_flags & IFF_BROADCAST )
693 && ( ntohs( sat->sat_addr.s_net ) >= ntohs( aa->aa_firstnet )
694 && ntohs( sat->sat_addr.s_net ) <= ntohs( aa->aa_lastnet ))) {
704 * Add a route for a range of networks from bot to top - 1.
707 * Split the range into two subranges such that the middle
708 * of the two ranges is the point where the highest bit of difference
709 * between the two addresses makes its transition.
710 * Each of the upper and lower ranges might not exist, or might be
711 * representable by 1 or more netmasks. In addition, if both
712 * ranges can be represented by the same netmask, then they can be merged
713 * by using the next higher netmask..
717 aa_dorangeroute(struct ifaddr *ifa, u_int bot, u_int top, int cmd)
725 * slight sanity check
727 if (bot > top) return (EINVAL);
732 * just start out with the lowest boundary
733 * and keep extending the mask till it's too big.
738 while ((( bot & ~mask1) >= bot)
739 && (( bot | mask1) <= top)) {
744 mask.s_net = htons(~mask1);
745 addr.s_net = htons(bot);
747 error = aa_addsingleroute(ifa,&addr,&mask);
753 error = aa_delsingleroute(ifa,&addr,&mask);
755 bot = (bot | mask1) + 1;
761 aa_addsingleroute(struct ifaddr *ifa,
762 struct at_addr *addr, struct at_addr *mask)
767 printf("aa_addsingleroute: %x.%x mask %x.%x ...\n",
768 ntohs(addr->s_net), addr->s_node,
769 ntohs(mask->s_net), mask->s_node);
772 error = aa_dosingleroute(ifa, addr, mask, RTM_ADD, RTF_UP);
774 printf("aa_addsingleroute: error %d\n", error);
779 aa_delsingleroute(struct ifaddr *ifa,
780 struct at_addr *addr, struct at_addr *mask)
784 error = aa_dosingleroute(ifa, addr, mask, RTM_DELETE, 0);
786 printf("aa_delsingleroute: error %d\n", error);
791 aa_dosingleroute(struct ifaddr *ifa,
792 struct at_addr *at_addr, struct at_addr *at_mask, int cmd, int flags)
794 struct sockaddr_at addr, mask;
796 bzero(&addr, sizeof(addr));
797 bzero(&mask, sizeof(mask));
798 addr.sat_family = AF_APPLETALK;
799 addr.sat_len = sizeof(struct sockaddr_at);
800 addr.sat_addr.s_net = at_addr->s_net;
801 addr.sat_addr.s_node = at_addr->s_node;
802 mask.sat_family = AF_APPLETALK;
803 mask.sat_len = sizeof(struct sockaddr_at);
804 mask.sat_addr.s_net = at_mask->s_net;
805 mask.sat_addr.s_node = at_mask->s_node;
808 return(rtrequest(cmd, (struct sockaddr *) &addr,
809 (flags & RTF_HOST)?(ifa->ifa_dstaddr):(ifa->ifa_addr),
810 (struct sockaddr *) &mask, flags, NULL));
818 struct at_ifaddr *aa;
822 while ( aa = at_ifaddr ) {
825 at_ifaddr = aa->aa_next;
826 if (( ifa = ifp->if_addrlist ) == (struct ifaddr *)aa ) {
827 ifp->if_addrlist = ifa->ifa_next;
829 while ( ifa->ifa_next &&
830 ( ifa->ifa_next != (struct ifaddr *)aa )) {
833 if ( ifa->ifa_next ) {
834 ifa->ifa_next = ((struct ifaddr *)aa)->ifa_next;
845 aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw0)
847 struct sockaddr_at *addr = (struct sockaddr_at *)ifa->ifa_addr;
848 struct sockaddr_at *gw = (struct sockaddr_at *)gw0;
850 switch (gw->sat_range.r_netrange.nr_phase) {
852 if(addr->sat_range.r_netrange.nr_phase == 1)
857 * if it's our net (including 0),
858 * or netranges are valid, and we are in the range,
861 if ((addr->sat_addr.s_net == gw->sat_addr.s_net)
862 || ((addr->sat_range.r_netrange.nr_lastnet)
863 && (ntohs(gw->sat_addr.s_net)
864 >= ntohs(addr->sat_range.r_netrange.nr_firstnet ))
865 && (ntohs(gw->sat_addr.s_net)
866 <= ntohs(addr->sat_range.r_netrange.nr_lastnet )))) {
871 printf("atalk: bad phase\n");