From 9452375a6b2a46be7d62f6b4d59cd58c37afcd47 Mon Sep 17 00:00:00 2001 From: pelikan Date: Mon, 5 May 2014 18:27:57 +0000 Subject: [PATCH] Don't call the ICMP handler indirectly + clean up a bit. ok krw --- usr.sbin/dhcpd/dhcpd.c | 4 ++-- usr.sbin/dhcpd/dhcpd.h | 8 ++++---- usr.sbin/dhcpd/icmp.c | 18 ++++++------------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/usr.sbin/dhcpd/dhcpd.c b/usr.sbin/dhcpd/dhcpd.c index 43b6cde37f2..00134b8a943 100644 --- a/usr.sbin/dhcpd/dhcpd.c +++ b/usr.sbin/dhcpd/dhcpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.c,v 1.41 2010/12/15 14:34:17 claudio Exp $ */ +/* $OpenBSD: dhcpd.c,v 1.42 2014/05/05 18:27:57 pelikan Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -175,7 +175,7 @@ main(int argc, char *argv[]) if (setrtable(rdomain) == -1) error("setrtable (%m)"); - icmp_startup(1, lease_pinged); + icmp_startup(); if (syncsend || syncrecv) { syncfd = sync_init(sync_iface, sync_baddr, sync_port); diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h index 9c13aa803d8..be619607683 100644 --- a/usr.sbin/dhcpd/dhcpd.h +++ b/usr.sbin/dhcpd/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.47 2013/04/17 19:26:10 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.48 2014/05/05 18:27:57 pelikan Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998, 1999 @@ -687,9 +687,9 @@ u_int32_t checksum(unsigned char *, unsigned, u_int32_t); u_int32_t wrapsum(u_int32_t); /* icmp.c */ -void icmp_startup(int, void (*)(struct iaddr, u_int8_t *, int)); -int icmp_echorequest(struct iaddr *); -void icmp_echoreply(struct protocol *); +void icmp_startup(void); +int icmp_echorequest(struct iaddr *); +void icmp_echoreply(struct protocol *); /* pfutils.c */ __dead void pftable_handler(void); diff --git a/usr.sbin/dhcpd/icmp.c b/usr.sbin/dhcpd/icmp.c index d96fc6b324b..7f7a361df61 100644 --- a/usr.sbin/dhcpd/icmp.c +++ b/usr.sbin/dhcpd/icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp.c,v 1.10 2008/09/15 20:38:17 claudio Exp $ */ +/* $OpenBSD: icmp.c,v 1.11 2014/05/05 18:27:57 pelikan Exp $ */ /* * Copyright (c) 1997, 1998 The Internet Software Consortium. @@ -49,7 +49,7 @@ static int icmp_protocol_fd; /* Initialize the ICMP protocol. */ void -icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int)) +icmp_startup(void) { struct protoent *proto; int protocol = 1, state; @@ -73,7 +73,7 @@ icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int)) &state, sizeof(state)) == -1) error("Unable to disable SO_DONTROUTE on ICMP socket: %m"); - add_protocol("icmp", icmp_protocol_fd, icmp_echoreply, (void *)handler); + add_protocol("icmp", icmp_protocol_fd, icmp_echoreply, NULL); } int @@ -114,7 +114,6 @@ icmp_echorequest(struct iaddr *addr) void icmp_echoreply(struct protocol *protocol) { - void (*handler)(struct iaddr, u_int8_t *, int); struct sockaddr_in from; u_int8_t icbuf[1500]; struct icmp *icfrom; @@ -141,12 +140,7 @@ icmp_echoreply(struct protocol *protocol) if (icfrom->icmp_type != ICMP_ECHOREPLY) return; - /* If we were given a second-stage handler, call it. */ - if (protocol->local) { - handler = ((void (*)(struct iaddr, u_int8_t *, int)) - protocol->local); - memcpy(ia.iabuf, &from.sin_addr, sizeof from.sin_addr); - ia.len = sizeof from.sin_addr; - (*handler)(ia, icbuf, len); - } + memcpy(ia.iabuf, &from.sin_addr, sizeof from.sin_addr); + ia.len = sizeof from.sin_addr; + lease_pinged(ia, icbuf, len); } -- 2.20.1