From: Roy Marples Date: Mon, 25 Apr 2016 13:03:52 +0000 (+0000) Subject: We can only check rtm_pid for the correct pid - other messages X-Git-Tag: v6.11.0~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff3431567b6d858ed7696125315fd39b31083b96;p=thirdparty%2Fdhcpcd.git We can only check rtm_pid for the correct pid - other messages do not have this sadly. --- diff --git a/if-bsd.c b/if-bsd.c index 7ce4001c..4283e36c 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -1246,26 +1246,6 @@ if_managelink(struct dhcpcd_ctx *ctx) e = msg + bytes; for (p = msg; p < e; p += rtm->rtm_msglen) { rtm = (void *)p; - if (rtm->rtm_type == RTM_MISS) - continue; - /* Ignore messages generated by us */ - if (rtm->rtm_pid == getpid()) { - ctx->options &= ~DHCPCD_RTM_PPID; - continue; - } - /* Ignore messages sent by the parent process after forking */ - if ((ctx->options & (DHCPCD_RTM_PPID | DHCPCD_DAEMONISED)) == - (DHCPCD_RTM_PPID | DHCPCD_DAEMONISED) && - rtm->rtm_pid == ctx->ppid) - { - /* If this is the last successful message sent clear - * the check flag as it's possible another process could - * re-use the same pid and also manipulate the kernel - * routing table. */ - if (rtm->rtm_seq == ctx->pseq) - ctx->options &= ~DHCPCD_RTM_PPID; - continue; - } switch(rtm->rtm_type) { #ifdef RTM_IFANNOUNCE case RTM_IFANNOUNCE: @@ -1311,6 +1291,25 @@ if_managelink(struct dhcpcd_ctx *ctx) case RTM_ADD: case RTM_CHANGE: case RTM_DELETE: + /* Ignore messages generated by us */ + if (rtm->rtm_pid == getpid()) { + ctx->options &= ~DHCPCD_RTM_PPID; + continue; + } + /* Ignore messages sent by the parent after forking */ + if ((ctx->options & + (DHCPCD_RTM_PPID | DHCPCD_DAEMONISED)) == + (DHCPCD_RTM_PPID | DHCPCD_DAEMONISED) && + rtm->rtm_pid == ctx->ppid) + { + /* If this is the last successful message sent, + * clear the check flag as it's possible another + * process could re-use the same pid and also + * manipulate therouting table. */ + if (rtm->rtm_seq == ctx->pseq) + ctx->options &= ~DHCPCD_RTM_PPID; + continue; + } cp = (void *)(rtm + 1); sa = (void *)cp; switch (sa->sa_family) { @@ -1360,6 +1359,9 @@ if_managelink(struct dhcpcd_ctx *ctx) #endif case RTM_DELADDR: /* FALLTHROUGH */ case RTM_NEWADDR: + /* XXX We have no way of knowing who generated these + * messages wich truely sucks because we want to + * avoid listening to our own delete messages. */ ifam = (void *)p; ifp = if_findindex(ctx->ifaces, ifam->ifam_index); if (ifp == NULL)