- Add link status to if_data, so that routing daemons and other interested
parties can easily know the state of a link. - Define an interface announcement message for the routing socket so that routing daemons and other interested parties know when an interface is attached/detached.
This commit is contained in:
parent
8fb9de8e46
commit
0f5c059d1f
10
sys/net/if.c
10
sys/net/if.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if.c,v 1.56 2000/02/06 16:43:33 thorpej Exp $ */
|
||||
/* $NetBSD: if.c,v 1.57 2000/03/06 20:49:00 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
||||
@ -331,6 +331,11 @@ if_attach(ifp)
|
||||
if (ifp->if_snd.ifq_maxlen == 0)
|
||||
ifp->if_snd.ifq_maxlen = ifqmaxlen;
|
||||
ifp->if_broadcastaddr = 0; /* reliably crash if used uninitialized */
|
||||
|
||||
ifp->if_link_state = LINK_STATE_UNKNOWN;
|
||||
|
||||
/* Announce the interface. */
|
||||
rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -448,6 +453,9 @@ if_detach(ifp)
|
||||
IFAFREE(ifnet_addrs[ifp->if_index]);
|
||||
ifnet_addrs[ifp->if_index] = NULL;
|
||||
|
||||
/* Announce that the interface is gone. */
|
||||
rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
|
||||
|
||||
TAILQ_REMOVE(&ifnet, ifp, if_list);
|
||||
|
||||
splx(s);
|
||||
|
38
sys/net/if.h
38
sys/net/if.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if.h,v 1.45 2000/03/06 18:55:10 kleink Exp $ */
|
||||
/* $NetBSD: if.h,v 1.46 2000/03/06 20:49:00 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
||||
@ -119,11 +119,12 @@ struct ether_header;
|
||||
* Structure defining statistics and other data kept regarding a network
|
||||
* interface.
|
||||
*/
|
||||
struct if_data {
|
||||
struct if_data {
|
||||
/* generic interface information */
|
||||
u_char ifi_type; /* ethernet, tokenring, etc. */
|
||||
u_char ifi_addrlen; /* media address length */
|
||||
u_char ifi_hdrlen; /* media header length */
|
||||
int ifi_link_state; /* current link state */
|
||||
u_quad_t ifi_mtu; /* maximum transmission unit */
|
||||
u_quad_t ifi_metric; /* routing metric (external only) */
|
||||
u_quad_t ifi_baudrate; /* linespeed */
|
||||
@ -142,9 +143,16 @@ struct if_data {
|
||||
struct timeval ifi_lastchange; /* last updated */
|
||||
};
|
||||
|
||||
/*
|
||||
* Values for if_link_state.
|
||||
*/
|
||||
#define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
|
||||
#define LINK_STATE_DOWN 1 /* link is down */
|
||||
#define LINK_STATE_UP 2 /* link is up */
|
||||
|
||||
#if defined(_KERNEL) && defined(COMPAT_14)
|
||||
/* Pre-1.5 if_data struct */
|
||||
struct if_data14 {
|
||||
struct if_data14 {
|
||||
/* generic interface information */
|
||||
u_char ifi_type; /* ethernet, tokenring, etc. */
|
||||
u_char ifi_addrlen; /* media address length */
|
||||
@ -229,6 +237,7 @@ struct ifnet { /* and the entries */
|
||||
#define if_addrlen if_data.ifi_addrlen
|
||||
#define if_hdrlen if_data.ifi_hdrlen
|
||||
#define if_metric if_data.ifi_metric
|
||||
#define if_link_state if_data.ifi_link_state
|
||||
#define if_baudrate if_data.ifi_baudrate
|
||||
#define if_ipackets if_data.ifi_ipackets
|
||||
#define if_ierrors if_data.ifi_ierrors
|
||||
@ -265,6 +274,14 @@ struct ifnet { /* and the entries */
|
||||
(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
|
||||
IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
|
||||
|
||||
/*
|
||||
* Some convenience macros used for setting ifi_baudrate.
|
||||
* XXX 1000 vs. 1024? --thorpej@netbsd.org
|
||||
*/
|
||||
#define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */
|
||||
#define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */
|
||||
#define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */
|
||||
|
||||
/*
|
||||
* Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
|
||||
* input routines have queues of messages stored on ifqueue structures
|
||||
@ -388,6 +405,21 @@ struct ifa_msghdr {
|
||||
int ifam_metric; /* value of ifa_metric */
|
||||
};
|
||||
|
||||
/*
|
||||
* Message format announcing the arrival or departure of a network interface.
|
||||
*/
|
||||
struct if_announcemsghdr {
|
||||
u_short ifan_msglen; /* to skip over non-understood messages */
|
||||
u_char ifan_version; /* future binary compatibility */
|
||||
u_char ifan_type; /* message type */
|
||||
u_short ifan_index; /* index for associated ifp */
|
||||
char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
u_short ifan_what; /* what type of announcement */
|
||||
};
|
||||
|
||||
#define IFAN_ARRIVAL 0 /* interface arrival */
|
||||
#define IFAN_DEPARTURE 1 /* interface departure */
|
||||
|
||||
/*
|
||||
* Interface request structure used for socket
|
||||
* ioctl's. All interface ioctl's must have parameter
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: route.h,v 1.20 1999/11/19 10:41:42 bouyer Exp $ */
|
||||
/* $NetBSD: route.h,v 1.21 2000/03/06 20:49:00 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@ -186,7 +186,8 @@ struct rt_msghdr {
|
||||
#define RTM_NEWADDR 0xc /* address being added to iface */
|
||||
#define RTM_DELADDR 0xd /* address being removed from iface */
|
||||
#define RTM_OIFINFO 0xe /* Old (pre-1.5) RTM_IFINFO message */
|
||||
#define RTM_IFINFO 0xf /* iface going up/down etc. */
|
||||
#define RTM_IFINFO 0xf /* iface/link going up/down etc. */
|
||||
#define RTM_IFANNOUNCE 0x10 /* iface arrival/departure */
|
||||
|
||||
#define RTV_MTU 0x1 /* init or lock _mtu */
|
||||
#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
|
||||
@ -278,6 +279,7 @@ void route_init __P((void));
|
||||
int route_output __P((struct mbuf *, ...));
|
||||
int route_usrreq __P((struct socket *,
|
||||
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *));
|
||||
void rt_ifannouncemsg __P((struct ifnet *, int));
|
||||
void rt_ifmsg __P((struct ifnet *));
|
||||
void rt_maskedcopy __P((struct sockaddr *,
|
||||
struct sockaddr *, struct sockaddr *));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rtsock.c,v 1.35 2000/02/17 04:28:00 itojun Exp $ */
|
||||
/* $NetBSD: rtsock.c,v 1.36 2000/03/06 20:49:00 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -494,6 +494,10 @@ rt_msg1(type, rtinfo, data, datalen)
|
||||
len = sizeof(struct if_msghdr);
|
||||
break;
|
||||
|
||||
case RTM_IFANNOUNCE:
|
||||
len = sizeof(struct if_announcemsghdr);
|
||||
break;
|
||||
|
||||
default:
|
||||
len = sizeof(struct rt_msghdr);
|
||||
}
|
||||
@ -778,6 +782,33 @@ rt_newaddrmsg(cmd, ifa, error, rt)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called to generate routing socket messages indicating
|
||||
* network interface arrival and departure.
|
||||
*/
|
||||
void
|
||||
rt_ifannouncemsg(ifp, what)
|
||||
struct ifnet *ifp;
|
||||
int what;
|
||||
{
|
||||
struct if_announcemsghdr ifan;
|
||||
struct mbuf *m;
|
||||
struct rt_addrinfo info;
|
||||
|
||||
if (route_cb.any_count == 0)
|
||||
return;
|
||||
bzero(&info, sizeof(info));
|
||||
bzero(&ifan, sizeof(ifan));
|
||||
ifan.ifan_index = ifp->if_index;
|
||||
strcpy(ifan.ifan_name, ifp->if_xname);
|
||||
ifan.ifan_what = what;
|
||||
m = rt_msg1(RTM_IFANNOUNCE, &info, (caddr_t)&ifan, sizeof(ifan));
|
||||
if (m == 0)
|
||||
return;
|
||||
route_proto.sp_protocol = 0;
|
||||
raw_input(m, &route_proto, &route_src, &route_dst);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is used in dumping the kernel table via sysctl().
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user