Module Name: src
Committed By: plunky
Date: Tue May 12 21:21:23 UTC 2009
Modified Files:
src/usr.sbin/btpand: tap.c
Log Message:
add an exit hook at the tap so that on the way out (for whatever reason),
btpand will mark down the interface.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btpand/tap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/btpand/tap.c
diff -u src/usr.sbin/btpand/tap.c:1.4 src/usr.sbin/btpand/tap.c:1.5
--- src/usr.sbin/btpand/tap.c:1.4 Tue May 12 21:08:30 2009
+++ src/usr.sbin/btpand/tap.c Tue May 12 21:21:23 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: tap.c,v 1.4 2009/05/12 21:08:30 plunky Exp $ */
+/* $NetBSD: tap.c,v 1.5 2009/05/12 21:21:23 plunky Exp $ */
/*-
* Copyright (c) 2008 Iain Hibbert
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: tap.c,v 1.4 2009/05/12 21:08:30 plunky Exp $");
+__RCSID("$NetBSD: tap.c,v 1.5 2009/05/12 21:21:23 plunky Exp $");
#include <sys/ioctl.h>
#include <sys/uio.h>
@@ -40,6 +40,7 @@
#include "btpand.h"
+static void tap_exit(void);
static bool tap_send(channel_t *, packet_t *);
static bool tap_recv(packet_t *);
static void tap_down(channel_t *);
@@ -64,6 +65,8 @@
log_err("Could not get interface name: %m");
exit(EXIT_FAILURE);
}
+ interface_name = strndup(ifr.ifr_name, IFNAMSIZ);
+ atexit(tap_exit);
s = socket(PF_LINK, SOCK_DGRAM, 0);
if (s == -1) {
@@ -123,6 +126,35 @@
log_err("pidfile not made");
}
+static void
+tap_exit(void)
+{
+ struct ifreq ifr;
+ int s;
+
+ s = socket(PF_LINK, SOCK_DGRAM, 0);
+ if (s == -1) {
+ log_err("Could not open PF_LINK socket: %m");
+ return;
+ }
+
+ strncpy(ifr.ifr_name, interface_name, IFNAMSIZ);
+ if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
+ log_err("Could not get interface flags: %m");
+ return;
+ }
+
+ if ((ifr.ifr_flags & IFF_UP)) {
+ ifr.ifr_flags &= ~IFF_UP;
+ if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) {
+ log_err("Could not clear IFF_UP: %m");
+ return;
+ }
+ }
+
+ close(s);
+}
+
static bool
tap_send(channel_t *chan, packet_t *pkt)
{