Home | History | Annotate | Line # | Download | only in netatalk
at_control.c revision 1.21
      1  1.21    dyoung /*	$NetBSD: at_control.c,v 1.21 2007/12/05 01:16:02 dyoung Exp $	 */
      2   1.1  christos 
      3   1.1  christos /*
      4   1.1  christos  * Copyright (c) 1990,1994 Regents of The University of Michigan.
      5   1.1  christos  * All Rights Reserved.
      6   1.1  christos  *
      7   1.1  christos  * Permission to use, copy, modify, and distribute this software and
      8   1.1  christos  * its documentation for any purpose and without fee is hereby granted,
      9   1.1  christos  * provided that the above copyright notice appears in all copies and
     10   1.1  christos  * that both that copyright notice and this permission notice appear
     11   1.1  christos  * in supporting documentation, and that the name of The University
     12   1.1  christos  * of Michigan not be used in advertising or publicity pertaining to
     13   1.1  christos  * distribution of the software without specific, written prior
     14   1.1  christos  * permission. This software is supplied as is without expressed or
     15   1.1  christos  * implied warranties of any kind.
     16   1.1  christos  *
     17   1.1  christos  * This product includes software developed by the University of
     18   1.1  christos  * California, Berkeley and its contributors.
     19   1.1  christos  *
     20   1.1  christos  *	Research Systems Unix Group
     21   1.1  christos  *	The University of Michigan
     22   1.1  christos  *	c/o Wesley Craig
     23   1.1  christos  *	535 W. William Street
     24   1.1  christos  *	Ann Arbor, Michigan
     25   1.1  christos  *	+1-313-764-2278
     26   1.1  christos  *	netatalk (at) umich.edu
     27   1.1  christos  */
     28   1.6     lukem 
     29   1.6     lukem #include <sys/cdefs.h>
     30  1.21    dyoung __KERNEL_RCSID(0, "$NetBSD: at_control.c,v 1.21 2007/12/05 01:16:02 dyoung Exp $");
     31   1.1  christos 
     32   1.1  christos #include <sys/param.h>
     33   1.1  christos #include <sys/systm.h>
     34   1.1  christos #include <sys/proc.h>
     35   1.1  christos #include <sys/errno.h>
     36   1.1  christos #include <sys/ioctl.h>
     37   1.1  christos #include <sys/mbuf.h>
     38   1.1  christos #include <sys/kernel.h>
     39   1.1  christos #include <sys/socket.h>
     40   1.1  christos #include <sys/socketvar.h>
     41  1.13      elad #include <sys/kauth.h>
     42   1.1  christos #include <net/if.h>
     43   1.1  christos #include <net/route.h>
     44   1.1  christos #include <net/if_ether.h>
     45   1.1  christos #include <netinet/in.h>
     46   1.1  christos #undef s_net
     47   1.1  christos 
     48   1.1  christos #include <netatalk/at.h>
     49   1.1  christos #include <netatalk/at_var.h>
     50   1.1  christos #include <netatalk/aarp.h>
     51   1.1  christos #include <netatalk/phase2.h>
     52   1.1  christos #include <netatalk/at_extern.h>
     53   1.1  christos 
     54  1.20    dyoung static int aa_dorangeroute(struct ifaddr * ifa,
     55  1.20    dyoung     u_int first, u_int last, int cmd);
     56  1.20    dyoung static int aa_addsingleroute(struct ifaddr * ifa,
     57  1.20    dyoung     struct at_addr * addr, struct at_addr * mask);
     58  1.20    dyoung static int aa_delsingleroute(struct ifaddr * ifa,
     59  1.20    dyoung     struct at_addr * addr, struct at_addr * mask);
     60  1.20    dyoung static int aa_dosingleroute(struct ifaddr * ifa, struct at_addr * addr,
     61  1.20    dyoung     struct at_addr * mask, int cmd, int flags);
     62  1.20    dyoung static int at_scrub(struct ifnet * ifp, struct at_ifaddr * aa);
     63  1.20    dyoung static int at_ifinit(struct ifnet *, struct at_ifaddr *,
     64  1.20    dyoung     const struct sockaddr_at *);
     65   1.1  christos #if 0
     66  1.20    dyoung static void aa_clean(void);
     67   1.1  christos #endif
     68   1.1  christos 
     69   1.1  christos #define sateqaddr(a,b)	((a)->sat_len == (b)->sat_len && \
     70   1.1  christos 			 (a)->sat_family == (b)->sat_family && \
     71   1.1  christos 			 (a)->sat_addr.s_net == (b)->sat_addr.s_net && \
     72   1.1  christos 			 (a)->sat_addr.s_node == (b)->sat_addr.s_node )
     73   1.1  christos 
     74   1.1  christos int
     75  1.15        ad at_control(cmd, data, ifp, l)
     76   1.1  christos 	u_long          cmd;
     77  1.18  christos 	void *        data;
     78   1.1  christos 	struct ifnet   *ifp;
     79  1.15        ad 	struct lwp     *l;
     80   1.1  christos {
     81   1.1  christos 	struct ifreq   *ifr = (struct ifreq *) data;
     82  1.20    dyoung 	const struct sockaddr_at *csat;
     83   1.1  christos 	struct netrange *nr;
     84  1.20    dyoung 	const struct netrange *cnr;
     85   1.1  christos 	struct at_aliasreq *ifra = (struct at_aliasreq *) data;
     86   1.1  christos 	struct at_ifaddr *aa0;
     87   1.1  christos 	struct at_ifaddr *aa = 0;
     88   1.1  christos 
     89   1.1  christos 	/*
     90   1.1  christos          * If we have an ifp, then find the matching at_ifaddr if it exists
     91   1.1  christos          */
     92   1.1  christos 	if (ifp)
     93   1.1  christos 		for (aa = at_ifaddr.tqh_first; aa; aa = aa->aa_list.tqe_next)
     94   1.1  christos 			if (aa->aa_ifp == ifp)
     95   1.1  christos 				break;
     96   1.1  christos 
     97   1.1  christos 	/*
     98   1.1  christos          * In this first switch table we are basically getting ready for
     99   1.1  christos          * the second one, by getting the atalk-specific things set up
    100   1.1  christos          * so that they start to look more similar to other protocols etc.
    101   1.1  christos          */
    102   1.1  christos 
    103   1.1  christos 	switch (cmd) {
    104   1.1  christos 	case SIOCAIFADDR:
    105   1.1  christos 	case SIOCDIFADDR:
    106   1.1  christos 		/*
    107   1.1  christos 		 * If we have an appletalk sockaddr, scan forward of where
    108   1.1  christos 		 * we are now on the at_ifaddr list to find one with a matching
    109   1.1  christos 		 * address on this interface.
    110   1.1  christos 		 * This may leave aa pointing to the first address on the
    111   1.1  christos 		 * NEXT interface!
    112   1.1  christos 		 */
    113   1.1  christos 		if (ifra->ifra_addr.sat_family == AF_APPLETALK) {
    114   1.1  christos 			for (; aa; aa = aa->aa_list.tqe_next)
    115   1.1  christos 				if (aa->aa_ifp == ifp &&
    116   1.1  christos 				    sateqaddr(&aa->aa_addr, &ifra->ifra_addr))
    117   1.1  christos 					break;
    118   1.1  christos 		}
    119   1.1  christos 		/*
    120   1.1  christos 		 * If we a retrying to delete an addres but didn't find such,
    121   1.1  christos 		 * then return with an error
    122   1.1  christos 		 */
    123   1.1  christos 		if (cmd == SIOCDIFADDR && aa == 0)
    124   1.1  christos 			return (EADDRNOTAVAIL);
    125   1.1  christos 		/* FALLTHROUGH */
    126   1.1  christos 
    127   1.1  christos 	case SIOCSIFADDR:
    128   1.1  christos 		/*
    129   1.1  christos 		 * If we are not superuser, then we don't get to do these
    130   1.1  christos 		 * ops.
    131   1.1  christos 		 */
    132  1.16      elad 		if (l && kauth_authorize_network(l->l_cred,
    133  1.16      elad 		    KAUTH_NETWORK_INTERFACE,
    134  1.16      elad 		    KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
    135  1.16      elad 		    NULL) != 0)
    136   1.1  christos 			return (EPERM);
    137   1.1  christos 
    138  1.20    dyoung 		csat = satocsat(ifreq_getaddr(cmd, ifr));
    139  1.20    dyoung 		cnr = (const struct netrange *)csat->sat_zero;
    140  1.20    dyoung 		if (cnr->nr_phase == 1) {
    141   1.1  christos 			/*
    142   1.1  christos 		         * Look for a phase 1 address on this interface.
    143   1.1  christos 		         * This may leave aa pointing to the first address on
    144   1.1  christos 			 * the NEXT interface!
    145   1.1  christos 		         */
    146   1.1  christos 			for (; aa; aa = aa->aa_list.tqe_next) {
    147   1.1  christos 				if (aa->aa_ifp == ifp &&
    148   1.1  christos 				    (aa->aa_flags & AFA_PHASE2) == 0)
    149   1.1  christos 					break;
    150   1.1  christos 			}
    151   1.1  christos 		} else {	/* default to phase 2 */
    152   1.1  christos 			/*
    153   1.1  christos 		         * Look for a phase 2 address on this interface.
    154   1.1  christos 		         * This may leave aa pointing to the first address on
    155   1.1  christos 			 * the NEXT interface!
    156   1.1  christos 		         */
    157   1.1  christos 			for (; aa; aa = aa->aa_list.tqe_next) {
    158   1.1  christos 				if (aa->aa_ifp == ifp &&
    159   1.1  christos 				    (aa->aa_flags & AFA_PHASE2))
    160   1.1  christos 					break;
    161   1.1  christos 			}
    162   1.1  christos 		}
    163   1.1  christos 
    164   1.1  christos 		if (ifp == 0)
    165   1.1  christos 			panic("at_control");
    166   1.1  christos 
    167   1.1  christos 		/*
    168   1.1  christos 		 * If we failed to find an existing at_ifaddr entry, then we
    169   1.1  christos 		 * allocate a fresh one.
    170   1.1  christos 		 * XXX change this to use malloc
    171   1.1  christos 		 */
    172   1.1  christos 		if (aa == (struct at_ifaddr *) 0) {
    173   1.1  christos 			aa = (struct at_ifaddr *)
    174  1.10     perry 			    malloc(sizeof(struct at_ifaddr), M_IFADDR,
    175   1.9      matt 			    M_WAITOK|M_ZERO);
    176   1.1  christos 
    177   1.1  christos 			if (aa == NULL)
    178   1.1  christos 				return (ENOBUFS);
    179   1.1  christos 
    180  1.19        ad 			callout_init(&aa->aa_probe_ch, 0);
    181   1.1  christos 
    182   1.1  christos 			if ((aa0 = at_ifaddr.tqh_first) != NULL) {
    183   1.1  christos 				/*
    184   1.1  christos 				 * Don't let the loopback be first, since the
    185   1.1  christos 				 * first address is the machine's default
    186   1.1  christos 				 * address for binding.
    187   1.1  christos 				 * If it is, stick ourself in front, otherwise
    188   1.1  christos 				 * go to the back of the list.
    189   1.1  christos 				 */
    190   1.1  christos 				if (aa0->aa_ifp->if_flags & IFF_LOOPBACK) {
    191   1.1  christos 					TAILQ_INSERT_HEAD(&at_ifaddr, aa,
    192   1.1  christos 					    aa_list);
    193   1.1  christos 				} else {
    194   1.1  christos 					TAILQ_INSERT_TAIL(&at_ifaddr, aa,
    195   1.1  christos 					    aa_list);
    196   1.1  christos 				}
    197   1.1  christos 			} else {
    198   1.1  christos 				TAILQ_INSERT_TAIL(&at_ifaddr, aa, aa_list);
    199   1.1  christos 			}
    200   1.2   thorpej 			IFAREF(&aa->aa_ifa);
    201   1.1  christos 
    202   1.1  christos 			/*
    203   1.1  christos 		         * Find the end of the interface's addresses
    204   1.1  christos 		         * and link our new one on the end
    205   1.1  christos 		         */
    206   1.1  christos 			TAILQ_INSERT_TAIL(&ifp->if_addrlist,
    207   1.1  christos 			    (struct ifaddr *) aa, ifa_list);
    208   1.2   thorpej 			IFAREF(&aa->aa_ifa);
    209   1.1  christos 
    210   1.1  christos 			/*
    211   1.1  christos 		         * As the at_ifaddr contains the actual sockaddrs,
    212   1.1  christos 		         * and the ifaddr itself, link them al together
    213   1.1  christos 			 * correctly.
    214   1.1  christos 		         */
    215   1.1  christos 			aa->aa_ifa.ifa_addr =
    216   1.1  christos 			    (struct sockaddr *) &aa->aa_addr;
    217   1.1  christos 			aa->aa_ifa.ifa_dstaddr =
    218   1.1  christos 			    (struct sockaddr *) &aa->aa_addr;
    219   1.1  christos 			aa->aa_ifa.ifa_netmask =
    220   1.1  christos 			    (struct sockaddr *) &aa->aa_netmask;
    221   1.1  christos 
    222   1.1  christos 			/*
    223   1.1  christos 		         * Set/clear the phase 2 bit.
    224   1.1  christos 		         */
    225  1.20    dyoung 			if (cnr->nr_phase == 1)
    226   1.1  christos 				aa->aa_flags &= ~AFA_PHASE2;
    227   1.1  christos 			else
    228   1.1  christos 				aa->aa_flags |= AFA_PHASE2;
    229   1.1  christos 
    230   1.1  christos 			/*
    231   1.1  christos 		         * and link it all together
    232   1.1  christos 		         */
    233   1.1  christos 			aa->aa_ifp = ifp;
    234   1.1  christos 		} else {
    235   1.1  christos 			/*
    236   1.1  christos 		         * If we DID find one then we clobber any routes
    237   1.1  christos 			 * dependent on it..
    238   1.1  christos 		         */
    239   1.1  christos 			at_scrub(ifp, aa);
    240   1.1  christos 		}
    241   1.1  christos 		break;
    242   1.1  christos 
    243   1.1  christos 	case SIOCGIFADDR:
    244  1.20    dyoung 		csat = satocsat(ifreq_getaddr(cmd, ifr));
    245  1.20    dyoung 		cnr = (const struct netrange *)csat->sat_zero;
    246  1.20    dyoung 		if (cnr->nr_phase == 1) {
    247   1.1  christos 			/*
    248   1.1  christos 		         * If the request is specifying phase 1, then
    249   1.1  christos 		         * only look at a phase one address
    250   1.1  christos 		         */
    251   1.1  christos 			for (; aa; aa = aa->aa_list.tqe_next) {
    252   1.1  christos 				if (aa->aa_ifp == ifp &&
    253   1.1  christos 				    (aa->aa_flags & AFA_PHASE2) == 0)
    254   1.1  christos 					break;
    255   1.1  christos 			}
    256  1.20    dyoung 		} else if (cnr->nr_phase == 2) {
    257   1.1  christos 			/*
    258   1.8        is 		         * If the request is specifying phase 2, then
    259   1.8        is 		         * only look at a phase two address
    260   1.1  christos 		         */
    261   1.1  christos 			for (; aa; aa = aa->aa_list.tqe_next) {
    262   1.1  christos 				if (aa->aa_ifp == ifp &&
    263   1.1  christos 				    (aa->aa_flags & AFA_PHASE2))
    264   1.8        is 					break;
    265   1.8        is 			}
    266   1.8        is 		} else {
    267   1.8        is 			/*
    268   1.8        is 		         * default to everything
    269   1.8        is 		         */
    270   1.8        is 			for (; aa; aa = aa->aa_list.tqe_next) {
    271   1.8        is 				if (aa->aa_ifp == ifp)
    272   1.1  christos 					break;
    273   1.1  christos 			}
    274   1.1  christos 		}
    275   1.1  christos 
    276   1.1  christos 		if (aa == (struct at_ifaddr *) 0)
    277   1.1  christos 			return (EADDRNOTAVAIL);
    278   1.1  christos 		break;
    279   1.1  christos 	}
    280   1.1  christos 
    281   1.1  christos 	/*
    282   1.1  christos          * By the time this switch is run we should be able to assume that
    283   1.1  christos          * the "aa" pointer is valid when needed.
    284   1.1  christos          */
    285   1.1  christos 	switch (cmd) {
    286  1.20    dyoung 	case SIOCGIFADDR: {
    287  1.20    dyoung 		union {
    288  1.20    dyoung 			struct sockaddr sa;
    289  1.20    dyoung 			struct sockaddr_at sat;
    290  1.20    dyoung 		} u;
    291   1.1  christos 
    292   1.1  christos 		/*
    293   1.1  christos 		 * copy the contents of the sockaddr blindly.
    294   1.1  christos 		 */
    295  1.20    dyoung 		sockaddr_copy(&u.sa, sizeof(u),
    296  1.20    dyoung 		    (const struct sockaddr *)&aa->aa_addr);
    297   1.1  christos 		/*
    298   1.1  christos 		 * and do some cleanups
    299   1.1  christos 		 */
    300  1.20    dyoung 		nr = (struct netrange *)&u.sat.sat_zero;
    301  1.20    dyoung 		nr->nr_phase = (aa->aa_flags & AFA_PHASE2) ? 2 : 1;
    302  1.20    dyoung 		nr->nr_firstnet = aa->aa_firstnet;
    303  1.20    dyoung 		nr->nr_lastnet = aa->aa_lastnet;
    304  1.20    dyoung 		ifreq_setaddr(cmd, ifr, &u.sa);
    305   1.1  christos 		break;
    306  1.20    dyoung 	}
    307   1.1  christos 
    308   1.1  christos 	case SIOCSIFADDR:
    309  1.20    dyoung 		return at_ifinit(ifp, aa,
    310  1.20    dyoung 		    (const struct sockaddr_at *)ifreq_getaddr(cmd, ifr));
    311   1.1  christos 
    312   1.1  christos 	case SIOCAIFADDR:
    313   1.1  christos 		if (sateqaddr(&ifra->ifra_addr, &aa->aa_addr))
    314   1.1  christos 			return 0;
    315  1.20    dyoung 		return at_ifinit(ifp, aa,
    316  1.20    dyoung 		    (const struct sockaddr_at *)ifreq_getaddr(cmd, ifr));
    317   1.1  christos 
    318   1.1  christos 	case SIOCDIFADDR:
    319   1.2   thorpej 		at_purgeaddr((struct ifaddr *) aa, ifp);
    320   1.1  christos 		break;
    321   1.1  christos 
    322   1.1  christos 	default:
    323   1.1  christos 		if (ifp == 0 || ifp->if_ioctl == 0)
    324   1.1  christos 			return (EOPNOTSUPP);
    325   1.1  christos 		return ((*ifp->if_ioctl) (ifp, cmd, data));
    326   1.1  christos 	}
    327   1.1  christos 	return (0);
    328   1.2   thorpej }
    329   1.2   thorpej 
    330   1.2   thorpej void
    331   1.2   thorpej at_purgeaddr(ifa, ifp)
    332   1.2   thorpej 	struct ifaddr *ifa;
    333   1.2   thorpej 	struct ifnet *ifp;
    334   1.2   thorpej {
    335   1.2   thorpej 	struct at_ifaddr *aa = (void *) ifa;
    336   1.2   thorpej 
    337   1.2   thorpej 	/*
    338   1.2   thorpej 	 * scrub all routes.. didn't we just DO this? XXX yes, del it
    339   1.2   thorpej 	 * XXX above XXX not necessarily true anymore
    340   1.2   thorpej 	 */
    341   1.2   thorpej 	at_scrub(ifp, aa);
    342   1.2   thorpej 
    343   1.2   thorpej 	/*
    344   1.2   thorpej 	 * remove the ifaddr from the interface
    345   1.2   thorpej 	 */
    346   1.2   thorpej 	TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *) aa, ifa_list);
    347   1.2   thorpej 	IFAFREE(&aa->aa_ifa);
    348   1.2   thorpej 	TAILQ_REMOVE(&at_ifaddr, aa, aa_list);
    349   1.2   thorpej 	IFAFREE(&aa->aa_ifa);
    350   1.3   thorpej }
    351   1.3   thorpej 
    352   1.3   thorpej void
    353   1.3   thorpej at_purgeif(ifp)
    354   1.3   thorpej 	struct ifnet *ifp;
    355   1.3   thorpej {
    356   1.3   thorpej 	struct ifaddr *ifa, *nifa;
    357   1.3   thorpej 
    358   1.3   thorpej 	for (ifa = TAILQ_FIRST(&ifp->if_addrlist); ifa != NULL; ifa = nifa) {
    359   1.3   thorpej 		nifa = TAILQ_NEXT(ifa, ifa_list);
    360   1.3   thorpej 		if (ifa->ifa_addr->sa_family != AF_APPLETALK)
    361   1.3   thorpej 			continue;
    362   1.3   thorpej 		at_purgeaddr(ifa, ifp);
    363   1.3   thorpej 	}
    364   1.1  christos }
    365   1.1  christos 
    366   1.1  christos /*
    367   1.1  christos  * Given an interface and an at_ifaddr (supposedly on that interface) remove
    368   1.1  christos  * any routes that depend on this. Why ifp is needed I'm not sure, as
    369   1.1  christos  * aa->at_ifaddr.ifa_ifp should be the same.
    370   1.1  christos  */
    371   1.1  christos static int
    372   1.1  christos at_scrub(ifp, aa)
    373   1.1  christos 	struct ifnet   *ifp;
    374   1.1  christos 	struct at_ifaddr *aa;
    375   1.1  christos {
    376   1.1  christos 	int error = 0;
    377   1.1  christos 
    378   1.1  christos 	if (aa->aa_flags & AFA_ROUTE) {
    379   1.1  christos 		if (ifp->if_flags & IFF_LOOPBACK)
    380   1.1  christos 			error = aa_delsingleroute(&aa->aa_ifa,
    381   1.1  christos 			    &aa->aa_addr.sat_addr, &aa->aa_netmask.sat_addr);
    382   1.1  christos 		else if (ifp->if_flags & IFF_POINTOPOINT)
    383   1.1  christos 			error = rtinit(&aa->aa_ifa, RTM_DELETE, RTF_HOST);
    384   1.1  christos 		else if (ifp->if_flags & IFF_BROADCAST)
    385   1.1  christos 			error = aa_dorangeroute(&aa->aa_ifa,
    386   1.1  christos 			    ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet),
    387   1.1  christos 			    RTM_DELETE);
    388   1.1  christos 
    389   1.1  christos 		aa->aa_ifa.ifa_flags &= ~IFA_ROUTE;
    390   1.1  christos 		aa->aa_flags &= ~AFA_ROUTE;
    391   1.1  christos 	}
    392   1.1  christos 	return error;
    393   1.1  christos }
    394   1.1  christos 
    395   1.1  christos /*
    396   1.1  christos  * given an at_ifaddr,a sockaddr_at and an ifp,
    397   1.1  christos  * bang them all together at high speed and see what happens
    398   1.1  christos  */
    399   1.1  christos static int
    400   1.1  christos at_ifinit(ifp, aa, sat)
    401   1.1  christos 	struct ifnet   *ifp;
    402   1.1  christos 	struct at_ifaddr *aa;
    403  1.20    dyoung 	const struct sockaddr_at *sat;
    404   1.1  christos {
    405   1.1  christos 	struct netrange nr, onr;
    406   1.1  christos 	struct sockaddr_at oldaddr;
    407   1.5   thorpej 	int             s = splnet(), error = 0, i, j;
    408   1.1  christos 	int             netinc, nodeinc, nnets;
    409   1.1  christos 	u_short         net;
    410   1.1  christos 
    411   1.1  christos 	/*
    412   1.1  christos 	 * save the old addresses in the at_ifaddr just in case we need them.
    413   1.1  christos 	 */
    414   1.1  christos 	oldaddr = aa->aa_addr;
    415   1.1  christos 	onr.nr_firstnet = aa->aa_firstnet;
    416   1.1  christos 	onr.nr_lastnet = aa->aa_lastnet;
    417   1.1  christos 
    418   1.1  christos 	/*
    419   1.1  christos          * take the address supplied as an argument, and add it to the
    420   1.1  christos          * at_ifnet (also given). Remember ing to update
    421   1.1  christos          * those parts of the at_ifaddr that need special processing
    422   1.1  christos          */
    423   1.1  christos 	bzero(AA_SAT(aa), sizeof(struct sockaddr_at));
    424   1.1  christos 	bcopy(sat->sat_zero, &nr, sizeof(struct netrange));
    425   1.1  christos 	bcopy(sat->sat_zero, AA_SAT(aa)->sat_zero, sizeof(struct netrange));
    426   1.1  christos 	nnets = ntohs(nr.nr_lastnet) - ntohs(nr.nr_firstnet) + 1;
    427   1.1  christos 	aa->aa_firstnet = nr.nr_firstnet;
    428   1.1  christos 	aa->aa_lastnet = nr.nr_lastnet;
    429   1.1  christos 
    430   1.1  christos #ifdef NETATALKDEBUG
    431   1.1  christos 	printf("at_ifinit: %s: %u.%u range %u-%u phase %d\n",
    432   1.1  christos 	    ifp->if_xname,
    433   1.1  christos 	    ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
    434   1.1  christos 	    ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet),
    435   1.1  christos 	    (aa->aa_flags & AFA_PHASE2) ? 2 : 1);
    436   1.1  christos #endif
    437   1.1  christos 
    438   1.1  christos 	/*
    439   1.1  christos          * We could eliminate the need for a second phase 1 probe (post
    440   1.1  christos          * autoconf) if we check whether we're resetting the node. Note
    441   1.1  christos          * that phase 1 probes use only nodes, not net.node pairs.  Under
    442   1.1  christos          * phase 2, both the net and node must be the same.
    443   1.1  christos          */
    444   1.1  christos 	AA_SAT(aa)->sat_len = sat->sat_len;
    445   1.1  christos 	AA_SAT(aa)->sat_family = AF_APPLETALK;
    446   1.1  christos 	if (ifp->if_flags & IFF_LOOPBACK) {
    447   1.1  christos 		AA_SAT(aa)->sat_addr.s_net = sat->sat_addr.s_net;
    448   1.1  christos 		AA_SAT(aa)->sat_addr.s_node = sat->sat_addr.s_node;
    449   1.1  christos #if 0
    450   1.1  christos 	} else if (fp->if_flags & IFF_POINTOPOINT) {
    451   1.1  christos 		/* unimplemented */
    452   1.1  christos 		/*
    453   1.1  christos 		 * we'd have to copy the dstaddr field over from the sat
    454   1.1  christos 		 * but it's not clear that it would contain the right info..
    455   1.1  christos 		 */
    456   1.1  christos #endif
    457   1.1  christos 	} else {
    458   1.1  christos 		/*
    459   1.1  christos 		 * We are a normal (probably ethernet) interface.
    460   1.1  christos 		 * apply the new address to the interface structures etc.
    461   1.1  christos 		 * We will probe this address on the net first, before
    462   1.1  christos 		 * applying it to ensure that it is free.. If it is not, then
    463   1.1  christos 		 * we will try a number of other randomly generated addresses
    464   1.1  christos 		 * in this net and then increment the net.  etc.etc. until
    465   1.1  christos 		 * we find an unused address.
    466   1.1  christos 		 */
    467   1.1  christos 		aa->aa_flags |= AFA_PROBING;	/* if not loopback we Must
    468   1.1  christos 						 * probe? */
    469   1.1  christos 		if (aa->aa_flags & AFA_PHASE2) {
    470   1.1  christos 			if (sat->sat_addr.s_net == ATADDR_ANYNET) {
    471   1.1  christos 				/*
    472   1.1  christos 				 * If we are phase 2, and the net was not
    473   1.1  christos 				 * specified * then we select a random net
    474   1.1  christos 				 * within the supplied netrange.
    475   1.1  christos 				 * XXX use /dev/random?
    476   1.1  christos 				 */
    477   1.1  christos 				if (nnets != 1) {
    478   1.1  christos 					net = ntohs(nr.nr_firstnet) +
    479  1.14    kardel 					    time_second % (nnets - 1);
    480   1.1  christos 				} else {
    481   1.1  christos 					net = ntohs(nr.nr_firstnet);
    482   1.1  christos 				}
    483   1.1  christos 			} else {
    484   1.1  christos 				/*
    485   1.1  christos 				 * if a net was supplied, then check that it
    486   1.1  christos 				 * is within the netrange. If it is not then
    487   1.1  christos 				 * replace the old values and return an error
    488   1.1  christos 				 */
    489   1.1  christos 				if (ntohs(sat->sat_addr.s_net) <
    490   1.1  christos 				    ntohs(nr.nr_firstnet) ||
    491   1.1  christos 				    ntohs(sat->sat_addr.s_net) >
    492   1.1  christos 				    ntohs(nr.nr_lastnet)) {
    493   1.1  christos 					aa->aa_addr = oldaddr;
    494   1.1  christos 					aa->aa_firstnet = onr.nr_firstnet;
    495   1.1  christos 					aa->aa_lastnet = onr.nr_lastnet;
    496   1.1  christos 					splx(s);
    497   1.1  christos 					return (EINVAL);
    498   1.1  christos 				}
    499   1.1  christos 				/*
    500   1.1  christos 				 * otherwise just use the new net number..
    501   1.1  christos 				 */
    502   1.1  christos 				net = ntohs(sat->sat_addr.s_net);
    503   1.1  christos 			}
    504   1.1  christos 		} else {
    505   1.1  christos 			/*
    506   1.1  christos 		         * we must be phase one, so just use whatever we were
    507   1.1  christos 			 * given. I guess it really isn't going to be used...
    508   1.1  christos 			 * RIGHT?
    509   1.1  christos 		         */
    510   1.1  christos 			net = ntohs(sat->sat_addr.s_net);
    511   1.1  christos 		}
    512   1.1  christos 
    513   1.1  christos 		/*
    514   1.1  christos 		 * set the node part of the address into the ifaddr. If it's
    515   1.1  christos 		 * not specified, be random about it... XXX use /dev/random?
    516   1.1  christos 		 */
    517   1.1  christos 		if (sat->sat_addr.s_node == ATADDR_ANYNODE) {
    518  1.14    kardel 			AA_SAT(aa)->sat_addr.s_node = time_second;
    519   1.1  christos 		} else {
    520   1.1  christos 			AA_SAT(aa)->sat_addr.s_node = sat->sat_addr.s_node;
    521   1.1  christos 		}
    522   1.1  christos 
    523   1.1  christos 		/*
    524   1.1  christos 		 * step through the nets in the range starting at the
    525   1.1  christos 		 * (possibly random) start point.
    526   1.1  christos 		 */
    527   1.1  christos 		for (i = nnets, netinc = 1; i > 0; net = ntohs(nr.nr_firstnet) +
    528   1.1  christos 		     ((net - ntohs(nr.nr_firstnet) + netinc) % nnets), i--) {
    529   1.1  christos 			AA_SAT(aa)->sat_addr.s_net = htons(net);
    530   1.1  christos 
    531   1.1  christos 			/*
    532   1.1  christos 		         * using a rather strange stepping method,
    533   1.1  christos 		         * stagger through the possible node addresses
    534   1.1  christos 		         * Once again, starting at the (possibly random)
    535   1.1  christos 		         * initial node address.
    536   1.1  christos 		         */
    537  1.14    kardel 			for (j = 0, nodeinc = time_second | 1; j < 256;
    538   1.1  christos 			     j++, AA_SAT(aa)->sat_addr.s_node += nodeinc) {
    539   1.1  christos 				if (AA_SAT(aa)->sat_addr.s_node > 253 ||
    540   1.1  christos 				    AA_SAT(aa)->sat_addr.s_node < 1) {
    541   1.1  christos 					continue;
    542   1.1  christos 				}
    543   1.1  christos 				aa->aa_probcnt = 10;
    544   1.1  christos 
    545   1.1  christos 				/*
    546   1.1  christos 				 * start off the probes as an asynchronous
    547   1.1  christos 				 * activity. though why wait 200mSec?
    548   1.1  christos 				 */
    549   1.4   thorpej 				callout_reset(&aa->aa_probe_ch, hz / 5,
    550   1.4   thorpej 				    aarpprobe, ifp);
    551   1.1  christos 				if (tsleep(aa, PPAUSE | PCATCH, "at_ifinit",
    552   1.1  christos 				    0)) {
    553   1.1  christos 					/*
    554   1.1  christos 				         * theoretically we shouldn't time out
    555   1.1  christos 					 * here so if we returned with an error.
    556   1.1  christos 				         */
    557   1.1  christos 					printf("at_ifinit: timeout?!\n");
    558   1.1  christos 					aa->aa_addr = oldaddr;
    559   1.1  christos 					aa->aa_firstnet = onr.nr_firstnet;
    560   1.1  christos 					aa->aa_lastnet = onr.nr_lastnet;
    561   1.1  christos 					splx(s);
    562   1.1  christos 					return (EINTR);
    563   1.1  christos 				}
    564   1.1  christos 				/*
    565   1.1  christos 				 * The async activity should have woken us
    566   1.1  christos 				 * up. We need to see if it was successful in
    567   1.1  christos 				 * finding a free spot, or if we need to
    568   1.1  christos 				 * iterate to the next address to try.
    569   1.1  christos 				 */
    570   1.1  christos 				if ((aa->aa_flags & AFA_PROBING) == 0)
    571   1.1  christos 					break;
    572   1.1  christos 			}
    573   1.1  christos 
    574   1.1  christos 			/*
    575   1.1  christos 		         * of course we need to break out through two loops...
    576   1.1  christos 		         */
    577   1.1  christos 			if ((aa->aa_flags & AFA_PROBING) == 0)
    578   1.1  christos 				break;
    579   1.1  christos 
    580   1.1  christos 			/* reset node for next network */
    581  1.14    kardel 			AA_SAT(aa)->sat_addr.s_node = time_second;
    582   1.1  christos 		}
    583   1.1  christos 
    584   1.1  christos 		/*
    585   1.1  christos 		 * if we are still trying to probe, then we have finished all
    586   1.1  christos 		 * the possible addresses, so we need to give up
    587   1.1  christos 		 */
    588   1.1  christos 		if (aa->aa_flags & AFA_PROBING) {
    589   1.1  christos 			aa->aa_addr = oldaddr;
    590   1.1  christos 			aa->aa_firstnet = onr.nr_firstnet;
    591   1.1  christos 			aa->aa_lastnet = onr.nr_lastnet;
    592   1.1  christos 			splx(s);
    593   1.1  christos 			return (EADDRINUSE);
    594   1.1  christos 		}
    595   1.1  christos 	}
    596   1.1  christos 
    597   1.1  christos 	/*
    598   1.1  christos 	 * Now that we have selected an address, we need to tell the
    599   1.1  christos 	 * interface about it, just in case it needs to adjust something.
    600   1.1  christos 	 */
    601   1.1  christos 	if (ifp->if_ioctl &&
    602  1.18  christos 	    (error = (*ifp->if_ioctl) (ifp, SIOCSIFADDR, (void *) aa))) {
    603   1.1  christos 		/*
    604   1.1  christos 		 * of course this could mean that it objects violently
    605   1.1  christos 		 * so if it does, we back out again..
    606   1.1  christos 		 */
    607   1.1  christos 		aa->aa_addr = oldaddr;
    608   1.1  christos 		aa->aa_firstnet = onr.nr_firstnet;
    609   1.1  christos 		aa->aa_lastnet = onr.nr_lastnet;
    610   1.1  christos 		splx(s);
    611   1.1  christos 		return (error);
    612   1.1  christos 	}
    613   1.1  christos 	/*
    614   1.1  christos 	 * set up the netmask part of the at_ifaddr and point the appropriate
    615   1.1  christos 	 * pointer in the ifaddr to it. probably pointless, but what the
    616   1.1  christos 	 * heck.. XXX
    617   1.1  christos 	 */
    618   1.1  christos 	bzero(&aa->aa_netmask, sizeof(aa->aa_netmask));
    619   1.1  christos 	aa->aa_netmask.sat_len = sizeof(struct sockaddr_at);
    620   1.1  christos 	aa->aa_netmask.sat_family = AF_APPLETALK;
    621   1.1  christos 	aa->aa_netmask.sat_addr.s_net = 0xffff;
    622   1.1  christos 	aa->aa_netmask.sat_addr.s_node = 0;
    623   1.1  christos #if 0
    624   1.1  christos 	aa->aa_ifa.ifa_netmask = (struct sockaddr *) &(aa->aa_netmask);/* XXX */
    625   1.1  christos #endif
    626   1.1  christos 
    627   1.1  christos 	/*
    628   1.1  christos          * Initialize broadcast (or remote p2p) address
    629   1.1  christos          */
    630   1.1  christos 	bzero(&aa->aa_broadaddr, sizeof(aa->aa_broadaddr));
    631   1.1  christos 	aa->aa_broadaddr.sat_len = sizeof(struct sockaddr_at);
    632   1.1  christos 	aa->aa_broadaddr.sat_family = AF_APPLETALK;
    633   1.1  christos 
    634   1.1  christos 	aa->aa_ifa.ifa_metric = ifp->if_metric;
    635   1.1  christos 	if (ifp->if_flags & IFF_BROADCAST) {
    636   1.1  christos 		aa->aa_broadaddr.sat_addr.s_net = htons(0);
    637   1.1  christos 		aa->aa_broadaddr.sat_addr.s_node = 0xff;
    638   1.1  christos 		aa->aa_ifa.ifa_broadaddr =
    639   1.1  christos 		    (struct sockaddr *) &aa->aa_broadaddr;
    640   1.1  christos 		/* add the range of routes needed */
    641   1.1  christos 		error = aa_dorangeroute(&aa->aa_ifa,
    642   1.1  christos 		    ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet), RTM_ADD);
    643   1.1  christos 	} else if (ifp->if_flags & IFF_POINTOPOINT) {
    644   1.1  christos 		struct at_addr  rtaddr, rtmask;
    645   1.1  christos 
    646   1.1  christos 		bzero(&rtaddr, sizeof(rtaddr));
    647   1.1  christos 		bzero(&rtmask, sizeof(rtmask));
    648   1.1  christos 		/* fill in the far end if we know it here XXX */
    649   1.1  christos 		aa->aa_ifa.ifa_dstaddr = (struct sockaddr *) & aa->aa_dstaddr;
    650   1.1  christos 		error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask);
    651   1.1  christos 	} else if (ifp->if_flags & IFF_LOOPBACK) {
    652   1.1  christos 		struct at_addr  rtaddr, rtmask;
    653   1.1  christos 
    654   1.1  christos 		bzero(&rtaddr, sizeof(rtaddr));
    655   1.1  christos 		bzero(&rtmask, sizeof(rtmask));
    656   1.1  christos 		rtaddr.s_net = AA_SAT(aa)->sat_addr.s_net;
    657   1.1  christos 		rtaddr.s_node = AA_SAT(aa)->sat_addr.s_node;
    658   1.1  christos 		rtmask.s_net = 0xffff;
    659   1.1  christos 		rtmask.s_node = 0x0;
    660   1.1  christos 		error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask);
    661   1.1  christos 	}
    662   1.1  christos 	/*
    663   1.1  christos          * of course if we can't add these routes we back out, but it's getting
    664   1.1  christos          * risky by now XXX
    665   1.1  christos          */
    666   1.1  christos 	if (error) {
    667   1.1  christos 		at_scrub(ifp, aa);
    668   1.1  christos 		aa->aa_addr = oldaddr;
    669   1.1  christos 		aa->aa_firstnet = onr.nr_firstnet;
    670   1.1  christos 		aa->aa_lastnet = onr.nr_lastnet;
    671   1.1  christos 		splx(s);
    672   1.1  christos 		return (error);
    673   1.1  christos 	}
    674   1.1  christos 	/*
    675   1.1  christos          * note that the address has a route associated with it....
    676   1.1  christos          */
    677   1.1  christos 	aa->aa_ifa.ifa_flags |= IFA_ROUTE;
    678   1.1  christos 	aa->aa_flags |= AFA_ROUTE;
    679   1.1  christos 	splx(s);
    680   1.1  christos 	return (0);
    681   1.1  christos }
    682   1.1  christos 
    683   1.1  christos /*
    684   1.1  christos  * check whether a given address is a broadcast address for us..
    685   1.1  christos  */
    686   1.1  christos int
    687  1.17    dyoung at_broadcast(const struct sockaddr_at *sat)
    688   1.1  christos {
    689   1.1  christos 	struct at_ifaddr *aa;
    690   1.1  christos 
    691   1.1  christos 	/*
    692   1.1  christos          * If the node is not right, it can't be a broadcast
    693   1.1  christos          */
    694   1.1  christos 	if (sat->sat_addr.s_node != ATADDR_BCAST)
    695   1.1  christos 		return 0;
    696   1.1  christos 
    697   1.1  christos 	/*
    698   1.1  christos          * If the node was right then if the net is right, it's a broadcast
    699   1.1  christos          */
    700   1.1  christos 	if (sat->sat_addr.s_net == ATADDR_ANYNET)
    701   1.1  christos 		return 1;
    702   1.1  christos 
    703   1.1  christos 	/*
    704   1.1  christos          * failing that, if the net is one we have, it's a broadcast as well.
    705   1.1  christos          */
    706   1.1  christos 	for (aa = at_ifaddr.tqh_first; aa; aa = aa->aa_list.tqe_next) {
    707   1.1  christos 		if ((aa->aa_ifp->if_flags & IFF_BROADCAST)
    708   1.1  christos 		    && (ntohs(sat->sat_addr.s_net) >= ntohs(aa->aa_firstnet)
    709   1.1  christos 		  && ntohs(sat->sat_addr.s_net) <= ntohs(aa->aa_lastnet)))
    710   1.1  christos 			return 1;
    711   1.1  christos 	}
    712   1.1  christos 	return 0;
    713   1.1  christos }
    714   1.1  christos 
    715   1.1  christos 
    716   1.1  christos /*
    717   1.1  christos  * aa_dorangeroute()
    718   1.1  christos  *
    719   1.1  christos  * Add a route for a range of networks from bot to top - 1.
    720   1.1  christos  * Algorithm:
    721   1.1  christos  *
    722   1.1  christos  * Split the range into two subranges such that the middle
    723   1.1  christos  * of the two ranges is the point where the highest bit of difference
    724   1.1  christos  * between the two addresses, makes it's transition
    725   1.1  christos  * Each of the upper and lower ranges might not exist, or might be
    726   1.1  christos  * representable by 1 or more netmasks. In addition, if both
    727   1.1  christos  * ranges can be represented by the same netmask, then teh can be merged
    728   1.1  christos  * by using the next higher netmask..
    729   1.1  christos  */
    730   1.1  christos 
    731   1.1  christos static int
    732   1.1  christos aa_dorangeroute(ifa, bot, top, cmd)
    733   1.1  christos 	struct ifaddr *ifa;
    734   1.1  christos 	u_int bot;
    735   1.1  christos 	u_int top;
    736   1.1  christos 	int cmd;
    737   1.1  christos {
    738   1.1  christos 	u_int           mask1;
    739   1.1  christos 	struct at_addr  addr;
    740   1.1  christos 	struct at_addr  mask;
    741   1.1  christos 	int             error;
    742   1.1  christos 
    743   1.1  christos 	/*
    744   1.1  christos 	 * slight sanity check
    745   1.1  christos 	 */
    746   1.1  christos 	if (bot > top)
    747   1.1  christos 		return (EINVAL);
    748   1.1  christos 
    749   1.1  christos 	addr.s_node = 0;
    750   1.1  christos 	mask.s_node = 0;
    751   1.1  christos 	/*
    752   1.1  christos 	 * just start out with the lowest boundary
    753   1.1  christos 	 * and keep extending the mask till it's too big.
    754   1.1  christos 	 */
    755   1.1  christos 
    756   1.1  christos 	while (bot <= top) {
    757   1.1  christos 		mask1 = 1;
    758   1.1  christos 		while (((bot & ~mask1) >= bot)
    759   1.1  christos 		       && ((bot | mask1) <= top)) {
    760   1.1  christos 			mask1 <<= 1;
    761   1.1  christos 			mask1 |= 1;
    762   1.1  christos 		}
    763   1.1  christos 		mask1 >>= 1;
    764   1.1  christos 		mask.s_net = htons(~mask1);
    765   1.1  christos 		addr.s_net = htons(bot);
    766   1.1  christos 		if (cmd == RTM_ADD) {
    767   1.1  christos 			error = aa_addsingleroute(ifa, &addr, &mask);
    768   1.1  christos 			if (error) {
    769   1.1  christos 				/* XXX clean up? */
    770   1.1  christos 				return (error);
    771   1.1  christos 			}
    772   1.1  christos 		} else {
    773   1.1  christos 			error = aa_delsingleroute(ifa, &addr, &mask);
    774   1.1  christos 		}
    775   1.1  christos 		bot = (bot | mask1) + 1;
    776   1.1  christos 	}
    777   1.1  christos 	return 0;
    778   1.1  christos }
    779   1.1  christos 
    780   1.1  christos static int
    781   1.1  christos aa_addsingleroute(ifa, addr, mask)
    782   1.1  christos 	struct ifaddr *ifa;
    783   1.1  christos 	struct at_addr *addr;
    784   1.1  christos 	struct at_addr *mask;
    785   1.1  christos {
    786   1.1  christos 	int error;
    787   1.1  christos 
    788   1.1  christos #ifdef NETATALKDEBUG
    789   1.1  christos 	printf("aa_addsingleroute: %x.%x mask %x.%x ...",
    790   1.1  christos 	       ntohs(addr->s_net), addr->s_node,
    791   1.1  christos 	       ntohs(mask->s_net), mask->s_node);
    792   1.1  christos #endif
    793   1.1  christos 
    794   1.1  christos 	error = aa_dosingleroute(ifa, addr, mask, RTM_ADD, RTF_UP);
    795   1.1  christos #ifdef NETATALKDEBUG
    796   1.1  christos 	if (error)
    797   1.1  christos 		printf("aa_addsingleroute: error %d\n", error);
    798   1.1  christos #endif
    799   1.1  christos 	return (error);
    800   1.1  christos }
    801   1.1  christos 
    802   1.1  christos static int
    803   1.1  christos aa_delsingleroute(ifa, addr, mask)
    804   1.1  christos 	struct ifaddr *ifa;
    805   1.1  christos 	struct at_addr *addr;
    806   1.1  christos 	struct at_addr *mask;
    807   1.1  christos {
    808   1.1  christos 	int error;
    809   1.1  christos 
    810   1.1  christos #ifdef NETATALKDEBUG
    811   1.1  christos 	printf("aa_delsingleroute: %x.%x mask %x.%x ...",
    812   1.1  christos 	       ntohs(addr->s_net), addr->s_node,
    813   1.1  christos 	       ntohs(mask->s_net), mask->s_node);
    814   1.1  christos #endif
    815   1.1  christos 
    816   1.1  christos 	error = aa_dosingleroute(ifa, addr, mask, RTM_DELETE, 0);
    817   1.1  christos #ifdef NETATALKDEBUG
    818   1.1  christos 	if (error)
    819   1.1  christos 		printf("aa_delsingleroute: error %d\n", error);
    820   1.1  christos #endif
    821   1.1  christos 	return (error);
    822   1.1  christos }
    823   1.1  christos 
    824   1.1  christos static int
    825   1.1  christos aa_dosingleroute(ifa, at_addr, at_mask, cmd, flags)
    826   1.1  christos 	struct ifaddr *ifa;
    827   1.1  christos 	struct at_addr *at_addr;
    828   1.1  christos 	struct at_addr *at_mask;
    829   1.1  christos 	int cmd;
    830   1.1  christos 	int flags;
    831   1.1  christos {
    832   1.1  christos 	struct sockaddr_at addr, mask, *gate;
    833   1.1  christos 
    834   1.1  christos 	bzero(&addr, sizeof(addr));
    835   1.1  christos 	bzero(&mask, sizeof(mask));
    836   1.1  christos 	addr.sat_family = AF_APPLETALK;
    837   1.1  christos 	addr.sat_len = sizeof(struct sockaddr_at);
    838   1.1  christos 	addr.sat_addr.s_net = at_addr->s_net;
    839   1.1  christos 	addr.sat_addr.s_node = at_addr->s_node;
    840   1.1  christos 	mask.sat_family = AF_APPLETALK;
    841   1.1  christos 	mask.sat_len = sizeof(struct sockaddr_at);
    842   1.1  christos 	mask.sat_addr.s_net = at_mask->s_net;
    843   1.1  christos 	mask.sat_addr.s_node = at_mask->s_node;
    844   1.1  christos 
    845   1.1  christos 	if (at_mask->s_node) {
    846   1.1  christos 		gate = satosat(ifa->ifa_dstaddr);
    847   1.1  christos 		flags |= RTF_HOST;
    848   1.1  christos 	} else {
    849   1.1  christos 		gate = satosat(ifa->ifa_addr);
    850   1.1  christos 	}
    851   1.1  christos 
    852   1.1  christos #ifdef NETATALKDEBUG
    853   1.1  christos 	printf("on %s %x.%x\n", (flags & RTF_HOST) ? "host" : "net",
    854   1.1  christos 	       ntohs(gate->sat_addr.s_net), gate->sat_addr.s_node);
    855   1.1  christos #endif
    856   1.1  christos 	return (rtrequest(cmd, (struct sockaddr *) &addr,
    857   1.1  christos 	    (struct sockaddr *) gate, (struct sockaddr *) &mask, flags, NULL));
    858   1.1  christos }
    859   1.1  christos 
    860   1.1  christos #if 0
    861   1.1  christos static void
    862   1.1  christos aa_clean()
    863   1.1  christos {
    864   1.1  christos 	struct at_ifaddr *aa;
    865   1.1  christos 	struct ifaddr  *ifa;
    866   1.1  christos 	struct ifnet   *ifp;
    867   1.1  christos 
    868  1.21    dyoung 	while ((aa = TAILQ_FIRST(&at_ifaddr)) != NULL) {
    869  1.21    dyoung 		TAILQ_REMOVE(&at_ifaddr, aa, aa_list);
    870   1.1  christos 		ifp = aa->aa_ifp;
    871   1.1  christos 		at_scrub(ifp, aa);
    872  1.21    dyoung 		IFADDR_FOREACH(ifa, ifp) {
    873  1.21    dyoung 			if (ifa == &aa->aa_ifa)
    874  1.21    dyoung 				break;
    875   1.1  christos 		}
    876  1.21    dyoung 		if (ifa == NULL)
    877  1.21    dyoung 			panic("aa not present");
    878  1.21    dyoung 		else
    879  1.21    dyoung 			TAILQ_REMOVE(&ifp->if_addrlist, ifa, ifa_list);
    880   1.1  christos 	}
    881   1.1  christos }
    882   1.1  christos #endif
    883