summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2017-08-12 07:38:27 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2017-08-12 07:38:27 +0000
commit484b0a7aa00e74bc73a1ca5b99ba22487e859f69 (patch)
tree15006b7a632f17f7dd3a7a8305aaed528d2bafdc /usr.sbin
parent83a616a919315d240b3bcea9950d6f5fa81e8fa6 (diff)
No need to constantly re-open a socket. Just open it up front and keep
it around. OK jca
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rtadvd/if.c37
-rw-r--r--usr.sbin/rtadvd/rtadvd.c6
2 files changed, 18 insertions, 25 deletions
diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c
index 9c6acd0e049..cc1edb37059 100644
--- a/usr.sbin/rtadvd/if.c
+++ b/usr.sbin/rtadvd/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.45 2017/08/10 19:07:14 jca Exp $ */
+/* $OpenBSD: if.c,v 1.46 2017/08/12 07:38:26 florian Exp $ */
/* $KAME: if.c,v 1.17 2001/01/21 15:27:30 itojun Exp $ */
/*
@@ -65,6 +65,8 @@ static void get_iflist(char **buf, size_t *size);
static void parse_iflist(struct if_msghdr ***ifmlist_p, char *buf,
size_t bufsize);
+extern int ioctl_sock;
+
static void
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
{
@@ -111,23 +113,18 @@ if_nametosdl(char *name)
int
if_getmtu(char *name)
{
- int s, save_errno;
struct ifreq ifr;
u_long mtu = 0;
- if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) >= 0) {
- memset(&ifr, 0, sizeof(ifr));
- ifr.ifr_addr.sa_family = AF_INET6;
- if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >=
- sizeof(ifr.ifr_name))
- fatalx("strlcpy");
- if (ioctl(s, SIOCGIFMTU, (char *)&ifr) >= 0)
- mtu = ifr.ifr_mtu;
- save_errno = errno;
- close(s);
- errno = save_errno;
- }
-
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_addr.sa_family = AF_INET6;
+ if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >=
+ sizeof(ifr.ifr_name))
+ fatalx("strlcpy");
+ if (ioctl(ioctl_sock, SIOCGIFMTU, (char *)&ifr) >= 0)
+ mtu = ifr.ifr_mtu;
+ else
+ log_warn("s: %d", ioctl_sock);
return (mtu);
}
@@ -136,20 +133,12 @@ int
if_getflags(int ifindex, int oifflags)
{
struct ifreq ifr;
- int s;
-
- if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- log_warn("socket");
- return (oifflags & ~IFF_UP);
- }
if_indextoname(ifindex, ifr.ifr_name);
- if (ioctl(s, SIOCGIFFLAGS, (char *)&ifr) < 0) {
+ if (ioctl(ioctl_sock, SIOCGIFFLAGS, (char *)&ifr) < 0) {
log_warn("ioctl:SIOCGIFFLAGS: failed for %s", ifr.ifr_name);
- close(s);
return (oifflags & ~IFF_UP);
}
- close(s);
return (ifr.ifr_flags);
}
diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c
index 5214a8bb6ec..cabec6c5950 100644
--- a/usr.sbin/rtadvd/rtadvd.c
+++ b/usr.sbin/rtadvd/rtadvd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtadvd.c,v 1.88 2017/08/10 19:07:14 jca Exp $ */
+/* $OpenBSD: rtadvd.c,v 1.89 2017/08/12 07:38:26 florian Exp $ */
/* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */
/*
@@ -79,6 +79,7 @@ struct sockaddr_in6 from;
struct sockaddr_in6 sin6_allnodes = {sizeof(sin6_allnodes), AF_INET6};
int sock;
int rtsock = -1;
+int ioctl_sock;
int dflag = 0, sflag = 0;
u_char *conffile = NULL;
@@ -204,6 +205,9 @@ main(int argc, char *argv[])
if (conffile == NULL)
log_init(dflag);
+ if ((ioctl_sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+ fatal("socket");
+
while (argc--)
getconfig(*argv++);