summaryrefslogtreecommitdiffstats
path: root/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2016-09-02 08:09:47 +0000
committerRoy Marples <roy@marples.name>2016-09-02 08:09:47 +0000
commitc62f687eb8edf0eafca1aeed8c9241ee4a3f4797 (patch)
treea358b0dcd749864b4a4dc1aee33b34a783e2c997 /if-bsd.c
parent92b920ad2c781cc96e182ae557d953b1298b6685 (diff)
downloaddhcpcd-c62f687eb8edf0eafca1aeed8c9241ee4a3f4797.tar.xz
Rework the recvmsg_realloc function to handle flags.
Commit also includes mistakenly added ifam_pid patch for BSD. It does no harm being here, even though no BSD supports this yet.
Diffstat (limited to 'if-bsd.c')
-rw-r--r--if-bsd.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/if-bsd.c b/if-bsd.c
index fbcb5172..7bc54e09 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -1312,32 +1312,43 @@ if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm)
(unsigned int)ifm->ifm_flags, ifp->name);
}
-static void
-if_rtm(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
+static int
+if_ownmsgpid(struct dhcpcd_ctx *ctx, pid_t pid, int seq)
{
- const struct sockaddr *sa;
/* Ignore messages generated by us */
- if (rtm->rtm_pid == getpid()) {
+ if (getpid() == pid) {
ctx->options &= ~DHCPCD_RTM_PPID;
- return;
+ return 1;
}
/* 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)
+ ctx->ppid == pid)
{
/* 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)
+ * manipulate the routing table. */
+ if (ctx->pseq == seq)
ctx->options &= ~DHCPCD_RTM_PPID;
- return;
+ return 1;
}
+ /* Not a message we made. */
+ return 0;
+}
+
+static void
+if_rtm(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
+{
+ const struct sockaddr *sa;
+
+ if (if_ownmsgpid(ctx, rtm->rtm_pid, rtm->rtm_seq))
+ return;
+
sa = (const void *)(rtm + 1);
switch (sa->sa_family) {
#ifdef INET
@@ -1395,9 +1406,11 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
struct interface *ifp;
const struct sockaddr *rti_info[RTAX_MAX];
- /* 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. */
+#ifdef HAVE_IFAM_PID
+ if (if_ownmsgpid(ctx, ifam->ifam_pid, 0))
+ return;
+#endif
+
if ((ifp = if_findindex(ctx->ifaces, ifam->ifam_index)) == NULL)
return;
get_addrs(ifam->ifam_addrs, ifam + 1, rti_info);
@@ -1521,8 +1534,9 @@ if_handlelink(struct dhcpcd_ctx *ctx)
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &ctx->iov;
+ msg.msg_iovlen = 1;
- if ((bytes = recvmsg_alloc(ctx->link_fd, &msg)) == -1)
+ if ((bytes = recvmsg_realloc(ctx->link_fd, &msg, 0)) == -1)
return -1;
if_dispatch(ctx, ctx->iov.iov_base);
return 0;