From fb09a1e4e436e8c963d6ecee7c044855f7ed76f1 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Thu, 10 Jan 2019 14:49:08 +0000 Subject: "AF_* values are *almost* always the correct choice, particularly with POSIX APIs". Also sprach guenther@. So switch PF_ROUTE to AF_ROUTE in socket() and setsockopt() calls. Keep PF_ROUTE in sysctl(2) uses. adding a comment for future visitors, Also replace PF_UNSPEC with 0 in socketpair(), as socketpair(2) points out this is the only sensible value. Cluebat from and ok guenther@ --- sbin/dhclient/dhclient.c | 26 +++++++++++++------------- sbin/dhclient/kroute.c | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'sbin/dhclient') diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index ca7ba5f367c..656609cd661 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.600 2019/01/09 16:48:36 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.601 2019/01/10 14:49:07 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -565,8 +565,8 @@ main(int argc, char *argv[]) exit(0); } - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, - PF_UNSPEC, socket_fd) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, + socket_fd) == -1) fatal("socketpair"); if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) @@ -638,17 +638,17 @@ main(int argc, char *argv[]) close(ioctlfd); ioctlfd = -1; - if ((routefd = socket(PF_ROUTE, SOCK_RAW, AF_INET)) == -1) - fatal("socket(PF_ROUTE, SOCK_RAW)"); + if ((routefd = socket(AF_ROUTE, SOCK_RAW, AF_INET)) == -1) + fatal("socket(AF_ROUTE, SOCK_RAW)"); rtfilter = ROUTE_FILTER(RTM_PROPOSAL) | ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_NEWADDR) | ROUTE_FILTER(RTM_DELADDR) | ROUTE_FILTER(RTM_IFANNOUNCE) | ROUTE_FILTER(RTM_80211INFO); - if (setsockopt(routefd, PF_ROUTE, ROUTE_MSGFILTER, + if (setsockopt(routefd, AF_ROUTE, ROUTE_MSGFILTER, &rtfilter, sizeof(rtfilter)) == -1) fatal("setsockopt(ROUTE_MSGFILTER)"); - if (setsockopt(routefd, PF_ROUTE, ROUTE_TABLEFILTER, &ifi->rdomain, + if (setsockopt(routefd, AF_ROUTE, ROUTE_TABLEFILTER, &ifi->rdomain, sizeof(ifi->rdomain)) == -1) fatal("setsockopt(ROUTE_TABLEFILTER)"); @@ -2257,8 +2257,8 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) if ((ioctlfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) fatal("socket(AF_INET, SOCK_DGRAM)"); - if ((routefd = socket(PF_ROUTE, SOCK_RAW, 0)) == -1) - fatal("socket(PF_ROUTE, SOCK_RAW)"); + if ((routefd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) + fatal("socket(AF_ROUTE, SOCK_RAW)"); while (quit == 0) { pfd[0].fd = priv_ibuf->fd; @@ -2887,15 +2887,15 @@ propose_release(struct interface_info *ifi) if (time(&start_time) == -1) fatal("time"); - if ((routefd = socket(PF_ROUTE, SOCK_RAW, AF_INET)) == -1) - fatal("socket(PF_ROUTE, SOCK_RAW)"); + if ((routefd = socket(AF_ROUTE, SOCK_RAW, AF_INET)) == -1) + fatal("socket(AF_ROUTE, SOCK_RAW)"); rtfilter = ROUTE_FILTER(RTM_PROPOSAL); - if (setsockopt(routefd, PF_ROUTE, ROUTE_MSGFILTER, + if (setsockopt(routefd, AF_ROUTE, ROUTE_MSGFILTER, &rtfilter, sizeof(rtfilter)) == -1) fatal("setsockopt(ROUTE_MSGFILTER)"); - if (setsockopt(routefd, PF_ROUTE, ROUTE_TABLEFILTER, &ifi->rdomain, + if (setsockopt(routefd, AF_ROUTE, ROUTE_TABLEFILTER, &ifi->rdomain, sizeof(ifi->rdomain)) == -1) fatal("setsockopt(ROUTE_TABLEFILTER)"); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 228b1a77bb3..023af022117 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.156 2018/06/13 01:37:54 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.157 2019/01/10 14:49:07 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -66,7 +66,7 @@ get_routes(int rdomain, size_t *len) size_t needed; mib[0] = CTL_NET; - mib[1] = PF_ROUTE; + mib[1] = PF_ROUTE; /* PF_ROUTE (not AF_ROUTE) for sysctl(2)! */ mib[2] = 0; mib[3] = AF_INET; mib[4] = NET_RT_FLAGS; -- cgit v1.2.3