summaryrefslogtreecommitdiff
path: root/usr.sbin/dhcpd
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/dhcpd')
-rw-r--r--usr.sbin/dhcpd/dhcp.c15
-rw-r--r--usr.sbin/dhcpd/dhcpd.h3
-rw-r--r--usr.sbin/dhcpd/memory.c28
-rw-r--r--usr.sbin/dhcpd/pfutils.c41
4 files changed, 49 insertions, 38 deletions
diff --git a/usr.sbin/dhcpd/dhcp.c b/usr.sbin/dhcpd/dhcp.c
index b6f04d044f4..0c37642828e 100644
--- a/usr.sbin/dhcpd/dhcp.c
+++ b/usr.sbin/dhcpd/dhcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.c,v 1.23 2006/05/31 02:43:15 ckuethe Exp $ */
+/* $OpenBSD: dhcp.c,v 1.24 2006/06/14 14:49:46 ckuethe Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -39,10 +39,6 @@
*/
#include "dhcpd.h"
-extern int pfpipe[2];
-extern int gotpipe;
-extern char *abandoned_tab;
-extern char *changedmac_tab;
int outstanding_pings;
@@ -85,7 +81,6 @@ dhcpdiscover(struct packet *packet)
{
struct lease *lease = find_lease(packet, packet->shared_network, 0);
struct host_decl *hp;
- struct pf_cmd cmd;
note("DHCPDISCOVER from %s via %s",
print_hw_addr(packet->raw->htype, packet->raw->hlen,
@@ -141,13 +136,7 @@ dhcpdiscover(struct packet *packet)
piaddr(lease->ip_addr));
lease->flags &= ~ABANDONED_LEASE;
- if (gotpipe && (abandoned_tab != NULL)){
- cmd.type = 'L';
- bcopy(lease->ip_addr.iabuf,
- &cmd.ip.s_addr, 4);
- (void)atomicio(vwrite, pfpipe[1],
- &cmd, sizeof(struct pf_cmd));
- }
+ pfmsg('L', lease); /* unabandon address */
}
}
diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h
index 1356597021c..317b7a0ee62 100644
--- a/usr.sbin/dhcpd/dhcpd.h
+++ b/usr.sbin/dhcpd/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.19 2006/05/31 02:43:15 ckuethe Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.20 2006/06/14 14:49:46 ckuethe Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -792,3 +792,4 @@ void pf_change_table(int , int , struct in_addr , char *);
void pf_kill_state(int , struct in_addr );
size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
#define vwrite (ssize_t (*)(int, void *, size_t))write
+void pfmsg(char, struct lease *);
diff --git a/usr.sbin/dhcpd/memory.c b/usr.sbin/dhcpd/memory.c
index 26366396bf9..a1f97ae4cde 100644
--- a/usr.sbin/dhcpd/memory.c
+++ b/usr.sbin/dhcpd/memory.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: memory.c,v 1.11 2006/05/31 02:43:15 ckuethe Exp $ */
+/* $OpenBSD: memory.c,v 1.12 2006/06/14 14:49:46 ckuethe Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
@@ -39,10 +39,6 @@
*/
#include "dhcpd.h"
-extern int pfpipe[2];
-extern int gotpipe;
-extern char *abandoned_tab;
-extern char *changedmac_tab;
static struct subnet *subnets;
static struct shared_network *shared_networks;
@@ -441,7 +437,6 @@ supersede_lease(struct lease *comp, struct lease *lease, int commit)
int enter_hwaddr = 0;
int do_pftable = 0;
struct lease *lp;
- struct pf_cmd cmd;
/* Static leases are not currently kept in the database... */
if (lease->flags & STATIC_LEASE)
@@ -604,17 +599,9 @@ supersede_lease(struct lease *comp, struct lease *lease, int commit)
comp->ends = lease->ends;
}
- if (gotpipe && (abandoned_tab != NULL)){
- cmd.type = 'L';
- bcopy(lease->ip_addr.iabuf, &cmd.ip.s_addr, 4);
- (void)atomicio(vwrite, pfpipe[1], &cmd, sizeof(struct pf_cmd));
- }
-
- if (gotpipe && do_pftable && (changedmac_tab != NULL)){
- cmd.type = 'C';
- bcopy(lease->ip_addr.iabuf, &cmd.ip.s_addr, 4);
- (void)atomicio(vwrite, pfpipe[1], &cmd, sizeof(struct pf_cmd));
- }
+ pfmsg('L', lease); /* address is leased. remove from purgatory */
+ if (do_pftable) /* address changed hwaddr. remove from overload */
+ pfmsg('C', lease);
/* Return zero if we didn't commit the lease to permanent storage;
nonzero if we did. */
@@ -647,7 +634,6 @@ void
abandon_lease(struct lease *lease, char *message)
{
struct lease lt;
- struct pf_cmd cmd;
time_t abtime;
abtime = lease->subnet->group->default_lease_time;
@@ -662,11 +648,7 @@ abandon_lease(struct lease *lease, char *message)
lt.uid_len = 0;
supersede_lease(lease, &lt, 1);
- if (gotpipe && abandoned_tab != NULL){
- cmd.type = 'A';
- bcopy(lease->ip_addr.iabuf, &cmd.ip.s_addr, 4);
- (void)atomicio(vwrite, pfpipe[1], &cmd, sizeof(struct pf_cmd));
- }
+ pfmsg('A', lease); /* address is abandoned. send to purgatory */
return;
}
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;
+ }
+}