2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * $DragonFly: src/sys/netproto/atalk/at_control.c,v 1.12 2006/12/22 23:57:53 swildner Exp $
11 #include <sys/sockio.h>
12 #include <sys/malloc.h>
13 #include <sys/kernel.h>
14 #include <sys/socket.h>
15 #include <sys/thread2.h>
17 #include <net/route.h>
18 #include <netinet/in.h>
20 #include <netinet/if_ether.h>
24 #include "at_extern.h"
26 struct at_ifaddr
*at_ifaddr
;
28 static int aa_dorangeroute(struct ifaddr
*ifa
,
29 u_int first
, u_int last
, int cmd
);
30 static int aa_addsingleroute(struct ifaddr
*ifa
,
31 struct at_addr
*addr
, struct at_addr
*mask
);
32 static int aa_delsingleroute(struct ifaddr
*ifa
,
33 struct at_addr
*addr
, struct at_addr
*mask
);
34 static int aa_dosingleroute(struct ifaddr
*ifa
, struct at_addr
*addr
,
35 struct at_addr
*mask
, int cmd
, int flags
);
36 static int at_scrub( struct ifnet
*ifp
, struct at_ifaddr
*aa
);
37 static int at_ifinit( struct ifnet
*ifp
, struct at_ifaddr
*aa
,
38 struct sockaddr_at
*sat
);
39 static int aa_claim_addr(struct ifaddr
*ifa
, struct sockaddr
*gw
);
41 # define sateqaddr(a,b) ((a)->sat_len == (b)->sat_len && \
42 (a)->sat_family == (b)->sat_family && \
43 (a)->sat_addr.s_net == (b)->sat_addr.s_net && \
44 (a)->sat_addr.s_node == (b)->sat_addr.s_node )
47 at_control(struct socket
*so
, u_long cmd
, caddr_t data
,
48 struct ifnet
*ifp
, struct thread
*td
)
50 struct ifreq
*ifr
= (struct ifreq
*)data
;
51 struct sockaddr_at
*sat
;
53 struct at_aliasreq
*ifra
= (struct at_aliasreq
*)data
;
54 struct at_ifaddr
*aa0
;
55 struct at_ifaddr
*aa
= 0;
56 struct ifaddr
*ifa
, *ifa0
;
60 * If we have an ifp, then find the matching at_ifaddr if it exists
63 for ( aa
= at_ifaddr
; aa
; aa
= aa
->aa_next
) {
64 if ( aa
->aa_ifp
== ifp
) break;
69 * In this first switch table we are basically getting ready for
70 * the second one, by getting the atalk-specific things set up
71 * so that they start to look more similar to other protocols etc.
78 * If we have an appletalk sockaddr, scan forward of where
79 * we are now on the at_ifaddr list to find one with a matching
80 * address on this interface.
81 * This may leave aa pointing to the first address on the
84 if ( ifra
->ifra_addr
.sat_family
== AF_APPLETALK
) {
85 for ( ; aa
; aa
= aa
->aa_next
) {
86 if ( aa
->aa_ifp
== ifp
&&
87 sateqaddr( &aa
->aa_addr
, &ifra
->ifra_addr
)) {
93 * If we a retrying to delete an addres but didn't find such,
94 * then rewurn with an error
96 if ( cmd
== SIOCDIFADDR
&& aa
== 0 ) {
97 return( EADDRNOTAVAIL
);
103 * If we are not superuser, then we don't get to do these ops.
108 sat
= satosat( &ifr
->ifr_addr
);
109 nr
= (struct netrange
*)sat
->sat_zero
;
110 if ( nr
->nr_phase
== 1 ) {
112 * Look for a phase 1 address on this interface.
113 * This may leave aa pointing to the first address on the
116 for ( ; aa
; aa
= aa
->aa_next
) {
117 if ( aa
->aa_ifp
== ifp
&&
118 ( aa
->aa_flags
& AFA_PHASE2
) == 0 ) {
122 } else { /* default to phase 2 */
124 * Look for a phase 2 address on this interface.
125 * This may leave aa pointing to the first address on the
128 for ( ; aa
; aa
= aa
->aa_next
) {
129 if ( aa
->aa_ifp
== ifp
&& ( aa
->aa_flags
& AFA_PHASE2
)) {
136 panic( "at_control" );
139 * If we failed to find an existing at_ifaddr entry, then we
140 * allocate a fresh one.
142 if ( aa
== (struct at_ifaddr
*) 0 ) {
143 aa0
= kmalloc(sizeof(struct at_ifaddr
), M_IFADDR
, M_WAITOK
| M_ZERO
);
144 callout_init(&aa0
->aa_ch
);
145 if (( aa
= at_ifaddr
) != NULL
) {
147 * Don't let the loopback be first, since the first
148 * address is the machine's default address for
150 * If it is, stick ourself in front, otherwise
151 * go to the back of the list.
153 if ( at_ifaddr
->aa_ifp
->if_flags
& IFF_LOOPBACK
) {
155 aa
->aa_next
= at_ifaddr
;
158 for ( ; aa
->aa_next
; aa
= aa
->aa_next
)
166 * Don't Add a reference for the aa itself!
167 * I fell into this trap. IFAFREE tests for <=0
168 * not <= 1 like RTFREE
170 /* aa->aa_ifa.ifa_refcnt++; DON'T DO THIS!! */
174 * Find the end of the interface's addresses
175 * and link our new one on the end
177 ifa
= (struct ifaddr
*)aa
;
178 TAILQ_INSERT_TAIL(&ifp
->if_addrhead
, ifa
, ifa_link
);
181 * Add a reference for the linking into the ifp_if_addrlist.
186 * As the at_ifaddr contains the actual sockaddrs,
187 * and the ifaddr itself, link them al together correctly.
189 ifa
->ifa_addr
= (struct sockaddr
*)&aa
->aa_addr
;
190 ifa
->ifa_dstaddr
= (struct sockaddr
*)&aa
->aa_addr
;
191 ifa
->ifa_netmask
= (struct sockaddr
*)&aa
->aa_netmask
;
194 * Set/clear the phase 2 bit.
196 if ( nr
->nr_phase
== 1 ) {
197 aa
->aa_flags
&= ~AFA_PHASE2
;
199 aa
->aa_flags
|= AFA_PHASE2
;
203 * and link it all together
208 * If we DID find one then we clobber any routes dependent on it..
215 sat
= satosat( &ifr
->ifr_addr
);
216 nr
= (struct netrange
*)sat
->sat_zero
;
217 if ( nr
->nr_phase
== 1 ) {
219 * If the request is specifying phase 1, then
220 * only look at a phase one address
222 for ( ; aa
; aa
= aa
->aa_next
) {
223 if ( aa
->aa_ifp
== ifp
&&
224 ( aa
->aa_flags
& AFA_PHASE2
) == 0 ) {
232 for ( ; aa
; aa
= aa
->aa_next
) {
233 if ( aa
->aa_ifp
== ifp
&& ( aa
->aa_flags
& AFA_PHASE2
)) {
239 if ( aa
== (struct at_ifaddr
*) 0 )
240 return( EADDRNOTAVAIL
);
245 * By the time this switch is run we should be able to assume that
246 * the "aa" pointer is valid when needed.
252 * copy the contents of the sockaddr blindly.
254 sat
= (struct sockaddr_at
*)&ifr
->ifr_addr
;
258 * and do some cleanups
260 ((struct netrange
*)&sat
->sat_zero
)->nr_phase
261 = (aa
->aa_flags
& AFA_PHASE2
) ? 2 : 1;
262 ((struct netrange
*)&sat
->sat_zero
)->nr_firstnet
= aa
->aa_firstnet
;
263 ((struct netrange
*)&sat
->sat_zero
)->nr_lastnet
= aa
->aa_lastnet
;
267 return( at_ifinit( ifp
, aa
, (struct sockaddr_at
*)&ifr
->ifr_addr
));
270 if ( sateqaddr( &ifra
->ifra_addr
, &aa
->aa_addr
)) {
273 return( at_ifinit( ifp
, aa
, (struct sockaddr_at
*)&ifr
->ifr_addr
));
277 * scrub all routes.. didn't we just DO this? XXX yes, del it
282 * remove the ifaddr from the interface
284 ifa0
= (struct ifaddr
*)aa
;
285 TAILQ_REMOVE(&ifp
->if_addrhead
, ifa0
, ifa_link
);
288 * refs goes from 1->0 if no external refs. note..
289 * This will not free it ... looks for -1.
294 * Now remove the at_ifaddr from the parallel structure
295 * as well, or we'd be in deep trouble
298 if ( aa0
== ( aa
= at_ifaddr
)) {
299 at_ifaddr
= aa
->aa_next
;
301 while ( aa
->aa_next
&& ( aa
->aa_next
!= aa0
)) {
306 * if we found it, remove it, otherwise we screwed up.
309 aa
->aa_next
= aa0
->aa_next
;
311 panic( "at_control" );
316 * Now dump the memory we were using.
317 * Decrement the reference count.
318 * This should probably be the last reference
319 * as the count will go from 0 to -1.
320 * (unless there is still a route referencing this)
326 if ( ifp
== 0 || ifp
->if_ioctl
== 0 )
327 return( EOPNOTSUPP
);
328 lwkt_serialize_enter(ifp
->if_serializer
);
329 error
= ifp
->if_ioctl(ifp
, cmd
, data
, td
->td_proc
->p_ucred
);
330 lwkt_serialize_exit(ifp
->if_serializer
);
337 * Given an interface and an at_ifaddr (supposedly on that interface)
338 * remove any routes that depend on this.
339 * Why ifp is needed I'm not sure,
340 * as aa->at_ifaddr.ifa_ifp should be the same.
343 at_scrub(struct ifnet
*ifp
, struct at_ifaddr
*aa
)
347 if ( aa
->aa_flags
& AFA_ROUTE
) {
348 if (ifp
->if_flags
& IFF_LOOPBACK
) {
349 if ((error
= aa_delsingleroute(&aa
->aa_ifa
,
350 &aa
->aa_addr
.sat_addr
,
351 &aa
->aa_netmask
.sat_addr
)) != 0) {
354 } else if (ifp
->if_flags
& IFF_POINTOPOINT
) {
355 if ((error
= rtinit( &aa
->aa_ifa
, RTM_DELETE
, RTF_HOST
)) != 0)
357 } else if (ifp
->if_flags
& IFF_BROADCAST
) {
358 error
= aa_dorangeroute(&aa
->aa_ifa
,
359 ntohs(aa
->aa_firstnet
),
360 ntohs(aa
->aa_lastnet
),
363 aa
->aa_ifa
.ifa_flags
&= ~IFA_ROUTE
;
364 aa
->aa_flags
&= ~AFA_ROUTE
;
370 * given an at_ifaddr,a sockaddr_at and an ifp,
371 * bang them all together at high speed and see what happens
374 at_ifinit(struct ifnet
*ifp
, struct at_ifaddr
*aa
, struct sockaddr_at
*sat
)
376 struct netrange nr
, onr
;
377 struct sockaddr_at oldaddr
;
379 int netinc
, nodeinc
, nnets
;
385 * save the old addresses in the at_ifaddr just in case we need them.
387 oldaddr
= aa
->aa_addr
;
388 onr
.nr_firstnet
= aa
->aa_firstnet
;
389 onr
.nr_lastnet
= aa
->aa_lastnet
;
392 * take the address supplied as an argument, and add it to the
393 * at_ifnet (also given). Remember ing to update
394 * those parts of the at_ifaddr that need special processing
396 bzero( AA_SAT( aa
), sizeof( struct sockaddr_at
));
397 bcopy( sat
->sat_zero
, &nr
, sizeof( struct netrange
));
398 bcopy( sat
->sat_zero
, AA_SAT( aa
)->sat_zero
, sizeof( struct netrange
));
399 nnets
= ntohs( nr
.nr_lastnet
) - ntohs( nr
.nr_firstnet
) + 1;
400 aa
->aa_firstnet
= nr
.nr_firstnet
;
401 aa
->aa_lastnet
= nr
.nr_lastnet
;
405 kprintf("at_ifinit: %s: %u.%u range %u-%u phase %d\n",
407 ntohs(sat
->sat_addr
.s_net
), sat
->sat_addr
.s_node
,
408 ntohs(aa
->aa_firstnet
), ntohs(aa
->aa_lastnet
),
409 (aa
->aa_flags
& AFA_PHASE2
) ? 2 : 1);
413 * We could eliminate the need for a second phase 1 probe (post
414 * autoconf) if we check whether we're resetting the node. Note
415 * that phase 1 probes use only nodes, not net.node pairs. Under
416 * phase 2, both the net and node must be the same.
418 if ( ifp
->if_flags
& IFF_LOOPBACK
) {
419 AA_SAT( aa
)->sat_len
= sat
->sat_len
;
420 AA_SAT( aa
)->sat_family
= AF_APPLETALK
;
421 AA_SAT( aa
)->sat_addr
.s_net
= sat
->sat_addr
.s_net
;
422 AA_SAT( aa
)->sat_addr
.s_node
= sat
->sat_addr
.s_node
;
424 } else if ( fp
->if_flags
& IFF_POINTOPOINT
) {
427 * we'd have to copy the dstaddr field over from the sat
428 * but it's not clear that it would contain the right info..
433 * We are a normal (probably ethernet) interface.
434 * apply the new address to the interface structures etc.
435 * We will probe this address on the net first, before
436 * applying it to ensure that it is free.. If it is not, then
437 * we will try a number of other randomly generated addresses
438 * in this net and then increment the net. etc.etc. until
439 * we find an unused address.
441 aa
->aa_flags
|= AFA_PROBING
; /* if not loopback we Must probe? */
442 AA_SAT( aa
)->sat_len
= sizeof(struct sockaddr_at
);
443 AA_SAT( aa
)->sat_family
= AF_APPLETALK
;
444 if ( aa
->aa_flags
& AFA_PHASE2
) {
445 if ( sat
->sat_addr
.s_net
== ATADDR_ANYNET
) {
447 * If we are phase 2, and the net was not specified
448 * then we select a random net within the supplied netrange.
449 * XXX use /dev/random?
452 net
= ntohs( nr
.nr_firstnet
) + time_second
% ( nnets
- 1 );
454 net
= ntohs( nr
.nr_firstnet
);
458 * if a net was supplied, then check that it is within
459 * the netrange. If it is not then replace the old values
460 * and return an error
462 if ( ntohs( sat
->sat_addr
.s_net
) < ntohs( nr
.nr_firstnet
) ||
463 ntohs( sat
->sat_addr
.s_net
) > ntohs( nr
.nr_lastnet
)) {
464 aa
->aa_addr
= oldaddr
;
465 aa
->aa_firstnet
= onr
.nr_firstnet
;
466 aa
->aa_lastnet
= onr
.nr_lastnet
;
471 * otherwise just use the new net number..
473 net
= ntohs( sat
->sat_addr
.s_net
);
477 * we must be phase one, so just use whatever we were given.
478 * I guess it really isn't going to be used... RIGHT?
480 net
= ntohs( sat
->sat_addr
.s_net
);
484 * set the node part of the address into the ifaddr.
485 * If it's not specified, be random about it...
486 * XXX use /dev/random?
488 if ( sat
->sat_addr
.s_node
== ATADDR_ANYNODE
) {
489 AA_SAT( aa
)->sat_addr
.s_node
= time_second
;
491 AA_SAT( aa
)->sat_addr
.s_node
= sat
->sat_addr
.s_node
;
497 AA_SAT( aa
)->sat_range
.r_netrange
.nr_phase
498 = ((aa
->aa_flags
& AFA_PHASE2
) ? 2:1);
501 * step through the nets in the range
502 * starting at the (possibly random) start point.
504 for ( i
= nnets
, netinc
= 1; i
> 0; net
= ntohs( nr
.nr_firstnet
) +
505 (( net
- ntohs( nr
.nr_firstnet
) + netinc
) % nnets
), i
-- ) {
506 AA_SAT( aa
)->sat_addr
.s_net
= htons( net
);
509 * using a rather strange stepping method,
510 * stagger through the possible node addresses
511 * Once again, starting at the (possibly random)
512 * initial node address.
514 for ( j
= 0, nodeinc
= time_second
| 1; j
< 256;
515 j
++, AA_SAT( aa
)->sat_addr
.s_node
+= nodeinc
) {
516 if ( AA_SAT( aa
)->sat_addr
.s_node
> 253 ||
517 AA_SAT( aa
)->sat_addr
.s_node
< 1 ) {
523 * start off the probes as an asynchronous activity.
524 * though why wait 200mSec?
526 callout_reset(&aa
->aa_ch
, hz
/ 5, aarpprobe
, ifp
);
527 if ( tsleep( aa
, PCATCH
, "at_ifinit", 0 )) {
529 * theoretically we shouldn't time out here
530 * so if we returned with an error..
532 kprintf( "at_ifinit: why did this happen?!\n" );
533 aa
->aa_addr
= oldaddr
;
534 aa
->aa_firstnet
= onr
.nr_firstnet
;
535 aa
->aa_lastnet
= onr
.nr_lastnet
;
541 * The async activity should have woken us up.
542 * We need to see if it was successful in finding
543 * a free spot, or if we need to iterate to the next
546 if (( aa
->aa_flags
& AFA_PROBING
) == 0 ) {
552 * of course we need to break out through two loops...
554 if (( aa
->aa_flags
& AFA_PROBING
) == 0 ) {
557 /* reset node for next network */
558 AA_SAT( aa
)->sat_addr
.s_node
= time_second
;
562 * if we are still trying to probe, then we have finished all
563 * the possible addresses, so we need to give up
566 if ( aa
->aa_flags
& AFA_PROBING
) {
567 aa
->aa_addr
= oldaddr
;
568 aa
->aa_firstnet
= onr
.nr_firstnet
;
569 aa
->aa_lastnet
= onr
.nr_lastnet
;
571 return( EADDRINUSE
);
576 * Now that we have selected an address, we need to tell the interface
577 * about it, just in case it needs to adjust something.
579 lwkt_serialize_enter(ifp
->if_serializer
);
581 (error
= ifp
->if_ioctl(ifp
, SIOCSIFADDR
, (caddr_t
)aa
, NULL
))
584 * of course this could mean that it objects violently
585 * so if it does, we back out again..
587 aa
->aa_addr
= oldaddr
;
588 aa
->aa_firstnet
= onr
.nr_firstnet
;
589 aa
->aa_lastnet
= onr
.nr_lastnet
;
590 lwkt_serialize_exit(ifp
->if_serializer
);
594 lwkt_serialize_exit(ifp
->if_serializer
);
597 * set up the netmask part of the at_ifaddr
598 * and point the appropriate pointer in the ifaddr to it.
599 * probably pointless, but what the heck.. XXX
601 bzero(&aa
->aa_netmask
, sizeof(aa
->aa_netmask
));
602 aa
->aa_netmask
.sat_len
= sizeof(struct sockaddr_at
);
603 aa
->aa_netmask
.sat_family
= AF_APPLETALK
;
604 aa
->aa_netmask
.sat_addr
.s_net
= 0xffff;
605 aa
->aa_netmask
.sat_addr
.s_node
= 0;
606 aa
->aa_ifa
.ifa_netmask
=(struct sockaddr
*) &(aa
->aa_netmask
); /* XXX */
609 * Initialize broadcast (or remote p2p) address
611 bzero(&aa
->aa_broadaddr
, sizeof(aa
->aa_broadaddr
));
612 aa
->aa_broadaddr
.sat_len
= sizeof(struct sockaddr_at
);
613 aa
->aa_broadaddr
.sat_family
= AF_APPLETALK
;
615 aa
->aa_ifa
.ifa_metric
= ifp
->if_metric
;
616 if (ifp
->if_flags
& IFF_BROADCAST
) {
617 aa
->aa_broadaddr
.sat_addr
.s_net
= htons(0);
618 aa
->aa_broadaddr
.sat_addr
.s_node
= 0xff;
619 aa
->aa_ifa
.ifa_broadaddr
= (struct sockaddr
*) &aa
->aa_broadaddr
;
620 /* add the range of routes needed */
621 error
= aa_dorangeroute(&aa
->aa_ifa
,
622 ntohs(aa
->aa_firstnet
), ntohs(aa
->aa_lastnet
), RTM_ADD
);
624 else if (ifp
->if_flags
& IFF_POINTOPOINT
) {
625 struct at_addr rtaddr
, rtmask
;
627 bzero(&rtaddr
, sizeof(rtaddr
));
628 bzero(&rtmask
, sizeof(rtmask
));
629 /* fill in the far end if we know it here XXX */
630 aa
->aa_ifa
.ifa_dstaddr
= (struct sockaddr
*) &aa
->aa_dstaddr
;
631 error
= aa_addsingleroute(&aa
->aa_ifa
, &rtaddr
, &rtmask
);
633 else if ( ifp
->if_flags
& IFF_LOOPBACK
) {
634 struct at_addr rtaddr
, rtmask
;
636 bzero(&rtaddr
, sizeof(rtaddr
));
637 bzero(&rtmask
, sizeof(rtmask
));
638 rtaddr
.s_net
= AA_SAT( aa
)->sat_addr
.s_net
;
639 rtaddr
.s_node
= AA_SAT( aa
)->sat_addr
.s_node
;
640 rtmask
.s_net
= 0xffff;
641 rtmask
.s_node
= 0x0; /* XXX should not be so.. should be HOST route */
642 error
= aa_addsingleroute(&aa
->aa_ifa
, &rtaddr
, &rtmask
);
647 * set the address of our "check if this addr is ours" routine.
649 aa
->aa_ifa
.ifa_claim_addr
= aa_claim_addr
;
652 * of course if we can't add these routes we back out, but it's getting
657 aa
->aa_addr
= oldaddr
;
658 aa
->aa_firstnet
= onr
.nr_firstnet
;
659 aa
->aa_lastnet
= onr
.nr_lastnet
;
665 * note that the address has a route associated with it....
667 aa
->aa_ifa
.ifa_flags
|= IFA_ROUTE
;
668 aa
->aa_flags
|= AFA_ROUTE
;
674 * check whether a given address is a broadcast address for us..
677 at_broadcast(struct sockaddr_at
*sat
)
679 struct at_ifaddr
*aa
;
682 * If the node is not right, it can't be a broadcast
684 if ( sat
->sat_addr
.s_node
!= ATADDR_BCAST
) {
689 * If the node was right then if the net is right, it's a broadcast
691 if ( sat
->sat_addr
.s_net
== ATADDR_ANYNET
) {
696 * failing that, if the net is one we have, it's a broadcast as well.
698 for ( aa
= at_ifaddr
; aa
; aa
= aa
->aa_next
) {
699 if (( aa
->aa_ifp
->if_flags
& IFF_BROADCAST
)
700 && ( ntohs( sat
->sat_addr
.s_net
) >= ntohs( aa
->aa_firstnet
)
701 && ntohs( sat
->sat_addr
.s_net
) <= ntohs( aa
->aa_lastnet
))) {
711 * Add a route for a range of networks from bot to top - 1.
714 * Split the range into two subranges such that the middle
715 * of the two ranges is the point where the highest bit of difference
716 * between the two addresses makes its transition.
717 * Each of the upper and lower ranges might not exist, or might be
718 * representable by 1 or more netmasks. In addition, if both
719 * ranges can be represented by the same netmask, then they can be merged
720 * by using the next higher netmask..
724 aa_dorangeroute(struct ifaddr
*ifa
, u_int bot
, u_int top
, int cmd
)
732 * slight sanity check
734 if (bot
> top
) return (EINVAL
);
739 * just start out with the lowest boundary
740 * and keep extending the mask till it's too big.
745 while ((( bot
& ~mask1
) >= bot
)
746 && (( bot
| mask1
) <= top
)) {
751 mask
.s_net
= htons(~mask1
);
752 addr
.s_net
= htons(bot
);
754 error
= aa_addsingleroute(ifa
,&addr
,&mask
);
760 error
= aa_delsingleroute(ifa
,&addr
,&mask
);
762 bot
= (bot
| mask1
) + 1;
768 aa_addsingleroute(struct ifaddr
*ifa
,
769 struct at_addr
*addr
, struct at_addr
*mask
)
774 kprintf("aa_addsingleroute: %x.%x mask %x.%x ...\n",
775 ntohs(addr
->s_net
), addr
->s_node
,
776 ntohs(mask
->s_net
), mask
->s_node
);
779 error
= aa_dosingleroute(ifa
, addr
, mask
, RTM_ADD
, RTF_UP
);
781 kprintf("aa_addsingleroute: error %d\n", error
);
786 aa_delsingleroute(struct ifaddr
*ifa
,
787 struct at_addr
*addr
, struct at_addr
*mask
)
791 error
= aa_dosingleroute(ifa
, addr
, mask
, RTM_DELETE
, 0);
793 kprintf("aa_delsingleroute: error %d\n", error
);
798 aa_dosingleroute(struct ifaddr
*ifa
,
799 struct at_addr
*at_addr
, struct at_addr
*at_mask
, int cmd
, int flags
)
801 struct sockaddr_at addr
, mask
;
803 bzero(&addr
, sizeof(addr
));
804 bzero(&mask
, sizeof(mask
));
805 addr
.sat_family
= AF_APPLETALK
;
806 addr
.sat_len
= sizeof(struct sockaddr_at
);
807 addr
.sat_addr
.s_net
= at_addr
->s_net
;
808 addr
.sat_addr
.s_node
= at_addr
->s_node
;
809 mask
.sat_family
= AF_APPLETALK
;
810 mask
.sat_len
= sizeof(struct sockaddr_at
);
811 mask
.sat_addr
.s_net
= at_mask
->s_net
;
812 mask
.sat_addr
.s_node
= at_mask
->s_node
;
815 return(rtrequest(cmd
, (struct sockaddr
*) &addr
,
816 (flags
& RTF_HOST
)?(ifa
->ifa_dstaddr
):(ifa
->ifa_addr
),
817 (struct sockaddr
*) &mask
, flags
, NULL
));
825 struct at_ifaddr
*aa
;
829 while ( aa
= at_ifaddr
) {
832 at_ifaddr
= aa
->aa_next
;
833 if (( ifa
= ifp
->if_addrlist
) == (struct ifaddr
*)aa
) {
834 ifp
->if_addrlist
= ifa
->ifa_next
;
836 while ( ifa
->ifa_next
&&
837 ( ifa
->ifa_next
!= (struct ifaddr
*)aa
)) {
840 if ( ifa
->ifa_next
) {
841 ifa
->ifa_next
= ((struct ifaddr
*)aa
)->ifa_next
;
852 aa_claim_addr(struct ifaddr
*ifa
, struct sockaddr
*gw0
)
854 struct sockaddr_at
*addr
= (struct sockaddr_at
*)ifa
->ifa_addr
;
855 struct sockaddr_at
*gw
= (struct sockaddr_at
*)gw0
;
857 switch (gw
->sat_range
.r_netrange
.nr_phase
) {
859 if(addr
->sat_range
.r_netrange
.nr_phase
== 1)
864 * if it's our net (including 0),
865 * or netranges are valid, and we are in the range,
868 if ((addr
->sat_addr
.s_net
== gw
->sat_addr
.s_net
)
869 || ((addr
->sat_range
.r_netrange
.nr_lastnet
)
870 && (ntohs(gw
->sat_addr
.s_net
)
871 >= ntohs(addr
->sat_range
.r_netrange
.nr_firstnet
))
872 && (ntohs(gw
->sat_addr
.s_net
)
873 <= ntohs(addr
->sat_range
.r_netrange
.nr_lastnet
)))) {
878 kprintf("atalk: bad phase\n");