changeset 4421:1c0d24d49b16 draft

route: log which pid deletes routes
author Roy Marples <roy@marples.name>
date Tue, 02 Apr 2019 12:52:31 +0100
parents ab5d38241a7b
children 344851420e71
files src/if-bsd.c src/if-linux.c src/if-sun.c src/route.c src/route.h
diffstat 5 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/if-bsd.c	Wed Mar 27 17:33:03 2019 +0000
+++ b/src/if-bsd.c	Tue Apr 02 12:52:31 2019 +0100
@@ -688,7 +688,7 @@
 		rtm = (void *)p;
 		if (if_copyrt(ctx, &rt, rtm) == 0) {
 			rt.rt_dflags |= RTDF_INIT;
-			rt_recvrt(RTM_ADD, &rt);
+			rt_recvrt(RTM_ADD, &rt, rtm->rtm_pid);
 		}
 	}
 	free(buf);
@@ -1010,7 +1010,7 @@
 	}
 #endif
 
-	rt_recvrt(rtm->rtm_type, &rt);
+	rt_recvrt(rtm->rtm_type, &rt, rtm->rtm_pid);
 }
 
 static void
--- a/src/if-linux.c	Wed Mar 27 17:33:03 2019 +0000
+++ b/src/if-linux.c	Tue Apr 02 12:52:31 2019 +0100
@@ -550,7 +550,7 @@
 		return 0;
 
 	if (if_copyrt(ctx, &rt, nlm) == 0)
-		rt_recvrt(cmd, &rt);
+		rt_recvrt(cmd, &rt, (pid_t)nlm->nlmsg_pid);
 
 	return 0;
 }
@@ -1291,7 +1291,7 @@
 
 	if (if_copyrt(ctx, &rt, nlm) == 0) {
 		rt.rt_dflags |= RTDF_INIT;
-		rt_recvrt(RTM_ADD, &rt);
+		rt_recvrt(RTM_ADD, &rt, (pid_t)nlm->nlmsg_pid);
 	}
 	return 0;
 }
--- a/src/if-sun.c	Wed Mar 27 17:33:03 2019 +0000
+++ b/src/if-sun.c	Tue Apr 02 12:52:31 2019 +0100
@@ -582,7 +582,7 @@
 
 	if (if_copyrt(ctx, &rt, rtm) == 0) {
 		if_finishrt(&rt);
-		rt_recvrt(rtm->rtm_type, &rt);
+		rt_recvrt(rtm->rtm_type, &rt, rtm->rtm_pid);
 	}
 }
 
@@ -1104,7 +1104,7 @@
 		rt.rt_ifp = if_find(ctx->ifaces, ifname);
 		if (rt.rt_ifp != NULL) {
 			if_finishrt(&rt);
-			rt_recvrt(RTM_ADD, &rt);
+			rt_recvrt(RTM_ADD, &rt, 0);
 		}
 	} while (++re < e);
 	return 0;
@@ -1152,7 +1152,7 @@
 		rt.rt_ifp = if_find(ctx->ifaces, ifname);
 		if (rt.rt_ifp != NULL) {
 			if_finishrt(&rt);
-			rt_recvrt(RTM_ADD, &rt);
+			rt_recvrt(RTM_ADD, &rt, 0);
 		}
 	} while (++re < e);
 	return 0;
--- a/src/route.c	Wed Mar 27 17:33:03 2019 +0000
+++ b/src/route.c	Tue Apr 02 12:52:31 2019 +0100
@@ -272,7 +272,7 @@
 /* If something other than dhcpcd removes a route,
  * we need to remove it from our internal table. */
 void
-rt_recvrt(int cmd, const struct rt *rt)
+rt_recvrt(int cmd, const struct rt *rt, pid_t pid)
 {
 	struct dhcpcd_ctx *ctx;
 	struct rt *f;
@@ -288,8 +288,11 @@
 			rt_free(f);
 		}
 		if ((f = rt_find(&ctx->routes, rt)) != NULL) {
+			char buf[32];
+
 			TAILQ_REMOVE(&ctx->routes, f, rt_next);
-			rt_desc("deleted", f);
+			snprintf(buf, sizeof(buf), "pid %d deleted", pid);
+			rt_desc(buf, f);
 			rt_free(f);
 		}
 		break;
--- a/src/route.h	Wed Mar 27 17:33:03 2019 +0000
+++ b/src/route.h	Tue Apr 02 12:52:31 2019 +0100
@@ -92,7 +92,7 @@
 struct rt * rt_new0(struct dhcpcd_ctx *);
 void rt_setif(struct rt *, struct interface *);
 struct rt * rt_new(struct interface *);
-void rt_recvrt(int, const struct rt *);
+void rt_recvrt(int, const struct rt *, pid_t);
 void rt_build(struct dhcpcd_ctx *, int);
 
 #endif