summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ndp
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2017-04-15 11:58:51 +0000
committerbluhm <bluhm@openbsd.org>2017-04-15 11:58:51 +0000
commit2ab086da93d3955aa9ce409297533e4ad5b51dfe (patch)
tree3a4591e8c13f713ca8ebf38bbd9b1c3e1f314f5e /usr.sbin/ndp
parentName global variable for routing socket rtsock like in ndp(8). (diff)
downloadwireguard-openbsd-2ab086da93d3955aa9ce409297533e4ad5b51dfe.tar.xz
wireguard-openbsd-2ab086da93d3955aa9ce409297533e4ad5b51dfe.zip
Take implementation for getsocket() from arp(8). This brings
routing table filter and pledge(2) to ndp(8) modes -s and -d. OK florian@
Diffstat (limited to 'usr.sbin/ndp')
-rw-r--r--usr.sbin/ndp/ndp.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index f8269b19938..cd3f8989ea4 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ndp.c,v 1.80 2017/04/15 11:42:09 bluhm Exp $ */
+/* $OpenBSD: ndp.c,v 1.81 2017/04/15 11:58:51 bluhm Exp $ */
/* $KAME: ndp.c,v 1.101 2002/07/17 08:46:33 itojun Exp $ */
/*
@@ -334,13 +334,18 @@ file(char *name)
void
getsocket(void)
{
- if (rtsock < 0) {
- rtsock = socket(PF_ROUTE, SOCK_RAW, 0);
- if (rtsock < 0) {
- err(1, "socket");
- /* NOTREACHED */
- }
- }
+ socklen_t len = sizeof(rdomain);
+
+ if (rtsock >= 0)
+ return;
+ rtsock = socket(PF_ROUTE, SOCK_RAW, 0);
+ if (rtsock < 0)
+ err(1, "routing socket");
+ if (setsockopt(rtsock, PF_ROUTE, ROUTE_TABLEFILTER, &rdomain, len) < 0)
+ err(1, "ROUTE_TABLEFILTER");
+
+ if (pledge("stdio dns", NULL) == -1)
+ err(1, "pledge");
}
struct sockaddr_in6 so_mask = {sizeof(so_mask), AF_INET6 };