summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2002-01-18 14:33:04 +0000
committerru <ru@FreeBSD.org>2002-01-18 14:33:04 +0000
commit7bbde3fb1fe2ff7b5efd1426bdbd435faa950f70 (patch)
tree868a544aec0071521723bf9f4a0985c76b46ad04
parentd254e724006714f3f20b2ea58624a58cc97d2874 (diff)
downloadFreeBSD-src-7bbde3fb1fe2ff7b5efd1426bdbd435faa950f70.zip
FreeBSD-src-7bbde3fb1fe2ff7b5efd1426bdbd435faa950f70.tar.gz
Introduce an interface announcement message for the routing
socket so that routing daemons and other interested parties know when an interface is attached/detached. PR: kern/33747 Obtained from: NetBSD MFC after: 2 weeks
-rw-r--r--sbin/route/route.c25
-rw-r--r--share/man/man4/route.419
-rw-r--r--sys/net/if.c6
-rw-r--r--sys/net/if.h15
-rw-r--r--sys/net/route.h2
-rw-r--r--sys/net/rtsock.c32
6 files changed, 96 insertions, 3 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index fcec843..ee6b924 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1335,6 +1335,7 @@ char *msgtypes[] = {
"RTM_IFINFO: iface status change",
"RTM_NEWMADDR: new multicast group membership on iface",
"RTM_DELMADDR: multicast group membership removed from iface",
+ "RTM_IFANNOUNCE: interface arrival/departure",
0,
};
@@ -1363,6 +1364,7 @@ print_rtmsg(rtm, msglen)
#ifdef RTM_NEWMADDR
struct ifma_msghdr *ifmam;
#endif
+ struct if_announcemsghdr *ifan;
if (verbose == 0)
return;
@@ -1371,7 +1373,11 @@ print_rtmsg(rtm, msglen)
rtm->rtm_version);
return;
}
- (void)printf("%s: len %d, ", msgtypes[rtm->rtm_type], rtm->rtm_msglen);
+ if (msgtypes[rtm->rtm_type] != NULL)
+ (void)printf("%s: ", msgtypes[rtm->rtm_type]);
+ else
+ (void)printf("#%d: ", rtm->rtm_type);
+ (void)printf("len %d, ", rtm->rtm_msglen);
switch (rtm->rtm_type) {
case RTM_IFINFO:
ifm = (struct if_msghdr *)rtm;
@@ -1393,6 +1399,23 @@ print_rtmsg(rtm, msglen)
pmsg_addrs((char *)(ifmam + 1), ifmam->ifmam_addrs);
break;
#endif
+ case RTM_IFANNOUNCE:
+ ifan = (struct if_announcemsghdr *)rtm;
+ (void) printf("if# %d, what: ", ifan->ifan_index);
+ switch (ifan->ifan_what) {
+ case IFAN_ARRIVAL:
+ printf("arrival");
+ break;
+ case IFAN_DEPARTURE:
+ printf("departure");
+ break;
+ default:
+ printf("#%d", ifan->ifan_what);
+ break;
+ }
+ printf("\n");
+ break;
+
default:
(void) printf("pid: %ld, seq %d, errno %d, flags:",
(long)rtm->rtm_pid, rtm->rtm_seq, rtm->rtm_errno);
diff --git a/share/man/man4/route.4 b/share/man/man4/route.4
index cc9df64..ef04cdb 100644
--- a/share/man/man4/route.4
+++ b/share/man/man4/route.4
@@ -32,7 +32,7 @@
.\" From: @(#)route.4 8.6 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd October 8, 1996
+.Dd January 18, 2002
.Dt ROUTE 4
.Os
.Sh NAME
@@ -198,6 +198,7 @@ Messages include:
#define RTM_IFINFO 0xe /* iface going up/down etc. */
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
+#define RTM_IFANNOUNCE 0x11 /* iface arrival/departure */
.Ed
.Pp
A message header consists of one of the following:
@@ -245,6 +246,15 @@ struct ifma_msghdr {
int ifmam_flags; /* value of ifa_flags */
u_short ifmam_index; /* index for associated ifp */
};
+
+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 */
+};
.Ed
.Pp
The
@@ -262,7 +272,12 @@ header, the
and
.Dv RTM_DELMADDR
messages use a
-.Ar ifma_msghdr ,
+.Vt ifma_msghdr
+header, the
+.Dv RTM_IFANNOUNCE
+message uses a
+.Vt if_announcemsghdr
+header,
and all other messages use the
.Ar rt_msghdr
header.
diff --git a/sys/net/if.c b/sys/net/if.c
index 7ffb296..8310190 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -430,6 +430,9 @@ if_attach(ifp)
TAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link);
}
ifp->if_broadcastaddr = 0; /* reliably crash if used uninitialized */
+
+ /* Announce the interface. */
+ rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
}
/*
@@ -511,6 +514,9 @@ if_detach(ifp)
(void) rnh->rnh_walktree(rnh, if_rtdel, ifp);
}
+ /* Announce that the interface is gone. */
+ rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
+
KNOTE(&ifp->if_klist, NOTE_EXIT);
TAILQ_REMOVE(&ifnet, ifp, if_link);
mtx_destroy(&ifp->if_snd.ifq_mtx);
diff --git a/sys/net/if.h b/sys/net/if.h
index 6cc5522..7370e12 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -197,6 +197,21 @@ struct ifma_msghdr {
};
/*
+ * 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
* definitions which begin with ifr_name. The
diff --git a/sys/net/route.h b/sys/net/route.h
index d4de208..838915b 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -207,6 +207,7 @@ struct rt_msghdr {
#define RTM_IFINFO 0xe /* iface going up/down etc. */
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
+#define RTM_IFANNOUNCE 0x11 /* iface arrival/departure */
/*
* Bitmask values for rtm_inits and rmx_locks.
@@ -277,6 +278,7 @@ struct ifmultiaddr;
void route_init __P((void));
int rt_getifa __P((struct rt_addrinfo *));
+void rt_ifannouncemsg __P((struct ifnet *, int));
void rt_ifmsg __P((struct ifnet *));
void rt_missmsg __P((int, struct rt_addrinfo *, int, int));
void rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *));
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index c55d765..88c9cc6 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -595,6 +595,10 @@ rt_msg1(type, rtinfo)
len = sizeof(struct if_msghdr);
break;
+ case RTM_IFANNOUNCE:
+ len = sizeof(struct if_announcemsghdr);
+ break;
+
default:
len = sizeof(struct rt_msghdr);
}
@@ -861,6 +865,34 @@ rt_newmaddrmsg(cmd, ifma)
}
/*
+ * 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((caddr_t)&info, sizeof(info));
+ m = rt_msg1(RTM_IFANNOUNCE, &info);
+ if (m == NULL)
+ return;
+ ifan = mtod(m, struct if_announcemsghdr *);
+ ifan->ifan_index = ifp->if_index;
+ snprintf(ifan->ifan_name, sizeof(ifan->ifan_name),
+ "%s%d", ifp->if_name, ifp->if_unit);
+ ifan->ifan_what = what;
+ route_proto.sp_protocol = 0;
+ raw_input(m, &route_proto, &route_src, &route_dst);
+ }
+
+/*
* This is used in dumping the kernel table via sysctl().
*/
int
OpenPOWER on IntegriCloud