changeset 4971:d050161827d1 draft

BSD: Ignore messages from ourself in privsep.
author Roy Marples <roy@marples.name>
date Thu, 16 Jan 2020 21:47:27 +0000
parents 64b25cbb621f
children c38657775fb4
files src/if-bsd.c
diffstat 1 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/if-bsd.c	Thu Jan 16 17:33:24 2020 +0000
+++ b/src/if-bsd.c	Thu Jan 16 21:47:27 2020 +0000
@@ -1245,12 +1245,15 @@
 	if (rtm->rtm_errno != 0)
 		return 0;
 
+	/* Ignore messages from ourself. */
 #ifdef PRIVSEP
-	/* Ignore messages from the route process.
-	 * We'll get the result of them regardless. */
-	if (rtm->rtm_pid == ctx->ps_root_pid)
-		return 0;
+	if (ctx->ps_root_pid != 0) {
+		if (rtm->rtm_pid == ctx->ps_root_pid)
+			return 0;
+	} else
 #endif
+		if (rtm->rtm_pid == getpid())
+			return 0;
 
 	if (if_copyrt(ctx, &rt, rtm) == -1)
 		return errno == ENOTSUP ? 0 : -1;
@@ -1292,6 +1295,21 @@
 		errno = EINVAL;
 		return -1;
 	}
+
+#ifdef HAVE_IFAM_PID
+#ifdef PRIVSEP
+	if (ctx->ps_root_pid != 0) {
+		if (ifam->ifam_pid == ctx->ps_root_pid)
+			return 0;
+	} else
+#endif
+		if (ifam->ifam_pid == getpid())
+			return 0;
+	pid = ifam->ifam_pid;
+#else
+	pid = 0;
+#endif
+
 	if (~ifam->ifam_addrs & RTA_IFA)
 		return 0;
 	if ((ifp = if_findindex(ctx->ifaces, ifam->ifam_index)) == NULL)
@@ -1301,12 +1319,6 @@
 		      ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
 		return -1;
 
-#ifdef HAVE_IFAM_PID
-	pid = ifam->ifam_pid;
-#else
-	pid = 0;
-#endif
-
 #ifdef HAVE_IFAM_ADDRFLAGS
 	addrflags = ifam->ifam_addrflags;
 #endif