if_slowtimo timeout driven
[unix-history] / usr / src / sys / net / if.c
/* if.c 4.19 82/09/12 */
#include "../h/param.h"
#include "../h/systm.h"
#include "../h/socket.h"
#include "../h/protosw.h"
#include "../net/in.h"
#include "../net/in_systm.h"
#include "../net/if.h"
#include "../net/af.h"
int ifqmaxlen = IFQ_MAXLEN;
/*
* Network interface utility routines.
*
* Routines with if_ifwith* names take sockaddr *'s as
* parameters. Other routines take value parameters,
* e.g. if_ifwithnet takes the network number.
*/
ifinit()
{
register struct ifnet *ifp;
for (ifp = ifnet; ifp; ifp = ifp->if_next)
if (ifp->if_init) {
(*ifp->if_init)(ifp->if_unit);
if (ifp->if_snd.ifq_maxlen == 0)
ifp->if_snd.ifq_maxlen = ifqmaxlen;
}
if_slowtimo();
}
/*
* Call each interface on a Unibus reset.
*/
ifubareset(uban)
int uban;
{
register struct ifnet *ifp;
for (ifp = ifnet; ifp; ifp = ifp->if_next)
if (ifp->if_ubareset)
(*ifp->if_ubareset)(uban);
}
/*
* Attach an interface to the
* list of "active" interfaces.
*/
if_attach(ifp)
struct ifnet *ifp;
{
register struct ifnet **p = &ifnet;
while (*p)
p = &((*p)->if_next);
*p = ifp;
}
/*
* Locate an interface based on a complete address.
*/
/*ARGSUSED*/
struct ifnet *
if_ifwithaddr(addr)
struct sockaddr *addr;
{
register struct ifnet *ifp;
#define equal(a1, a2) \
(bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0)
for (ifp = ifnet; ifp; ifp = ifp->if_next) {
if (ifp->if_addr.sa_family != addr->sa_family)
continue;
if (equal(&ifp->if_addr, addr))
break;
if ((ifp->if_flags & IFF_BROADCAST) &&
equal(&ifp->if_broadaddr, addr))
break;
}
return (ifp);
}
/*
* Find an interface on a specific network. If many, choice
* is first found.
*/
struct ifnet *
if_ifwithnet(addr)
register struct sockaddr *addr;
{
register struct ifnet *ifp;
register int af = addr->sa_family;
register int (*netmatch)();
if (af >= AF_MAX)
return (0);
netmatch = afswitch[af].af_netmatch;
for (ifp = ifnet; ifp; ifp = ifp->if_next) {
if (af != ifp->if_addr.sa_family)
continue;
if ((*netmatch)(addr, &ifp->if_addr))
break;
}
return (ifp);
}
/*
* As above, but parameter is network number.
*/
struct ifnet *
if_ifonnetof(net)
register int net;
{
register struct ifnet *ifp;
for (ifp = ifnet; ifp; ifp = ifp->if_next)
if (ifp->if_net == net)
break;
return (ifp);
}
/*
* Find an interface using a specific address family
*/
struct ifnet *
if_ifwithaf(af)
register int af;
{
register struct ifnet *ifp;
for (ifp = ifnet; ifp; ifp = ifp->if_next)
if (ifp->if_addr.sa_family == af)
break;
return (ifp);
}
/*
* Mark an interface down and notify protocols of
* the transition.
*/
if_down(ifp)
register struct ifnet *ifp;
{
ifp->if_flags &= ~IFF_UP;
pfctlinput(PRC_IFDOWN, (caddr_t)&ifp->if_addr);
}
/*
* Handle interface watchdog timer routines. Called
* from softclock, we decrement timers (if set) and
* call the appropriate interface routine on expiration.
*/
if_slowtimo()
{
register struct ifnet *ifp;
for (ifp = ifnet; ifp; ifp = ifp->if_next)
if (ifp->if_timer && --ifp->if_timer == 0) {
if (ifp->if_watchdog == 0) {
printf("%s%d: no watchdog routine\n",
ifp->if_name, ifp->if_unit);
continue;
}
(*ifp->if_watchdog)(ifp->if_unit);
}
timeout(if_slowtimo, 0, hz / IFNET_SLOWHZ);
}