summaryrefslogtreecommitdiffstats
path: root/usr.sbin/dhcpd/pfutils.c
diff options
context:
space:
mode:
authorckuethe <ckuethe@openbsd.org>2006-06-14 14:49:46 +0000
committerckuethe <ckuethe@openbsd.org>2006-06-14 14:49:46 +0000
commitdfafa18493d4f3f777c538be97961f5b4cc32c25 (patch)
tree6989eeb4f39e6e65a4e91dfad392df9a4c9f04f6 /usr.sbin/dhcpd/pfutils.c
parentAvoid changing pf tables when table name is NULL (diff)
downloadwireguard-openbsd-dfafa18493d4f3f777c538be97961f5b4cc32c25.tar.xz
wireguard-openbsd-dfafa18493d4f3f777c538be97961f5b4cc32c25.zip
Move the transmission of privsep messages into its own function. Wherever
we might have conditionally sent a message, we now just call the pfmsg() function, and let it figure out whether the message should be sent or not. ok henning
Diffstat (limited to 'usr.sbin/dhcpd/pfutils.c')
-rw-r--r--usr.sbin/dhcpd/pfutils.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/usr.sbin/dhcpd/pfutils.c b/usr.sbin/dhcpd/pfutils.c
index d1fea6cdfdc..15b06c8138c 100644
--- a/usr.sbin/dhcpd/pfutils.c
+++ b/usr.sbin/dhcpd/pfutils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfutils.c,v 1.3 2006/06/14 14:44:39 ckuethe Exp $ */
+/* $OpenBSD: pfutils.c,v 1.4 2006/06/14 14:49:46 ckuethe Exp $ */
/*
* Copyright (c) 2006 Chris Kuethe <ckuethe@openbsd.org>
*
@@ -40,6 +40,7 @@
extern struct passwd *pw;
extern int pfpipe[2];
+extern int gotpipe;
extern char *abandoned_tab;
extern char *changedmac_tab;
@@ -184,3 +185,41 @@ atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
}
return (pos);
}
+
+/*
+ * This function sends commands to the pf table handler. It will safely and
+ * silently return if the handler is unconfigured, therefore it can be called
+ * on all interesting lease events, whether or not the user actually wants to
+ * use the pf table feature.
+ */
+void
+pfmsg(char c, struct lease *lp)
+{
+ struct pf_cmd cmd;
+
+ if (gotpipe == 0)
+ return;
+
+ cmd.type = c;
+ bcopy(lp->ip_addr.iabuf, &cmd.ip.s_addr, 4);
+
+ switch(c){
+ case 'A': /* address is being abandoned */
+ if (abandoned_tab != NULL)
+ (void)atomicio(vwrite, pfpipe[1], &cmd,
+ sizeof(struct pf_cmd));
+ break;
+ case 'C': /* IP moved to different ethernet address */
+ if (changedmac_tab != NULL)
+ (void)atomicio(vwrite, pfpipe[1], &cmd,
+ sizeof(struct pf_cmd));
+ break;
+ case 'L': /* Address is being leased (unabandoned) */
+ if (abandoned_tab != NULL)
+ (void)atomicio(vwrite, pfpipe[1], &cmd,
+ sizeof(struct pf_cmd));
+ break;
+ default: /* silently ignore unknown commands */
+ break;
+ }
+}