172 lines
4.8 KiB
Plaintext
172 lines
4.8 KiB
Plaintext
$OpenBSD: patch-arpd_c,v 1.4 2010/04/21 21:41:26 alek Exp $
|
|
--- arpd.c.orig Sun Feb 9 05:20:40 2003
|
|
+++ arpd.c Sat Apr 30 14:45:52 2005
|
|
@@ -22,10 +22,6 @@
|
|
#include <syslog.h>
|
|
#include <unistd.h>
|
|
|
|
-/* XXX - libevent */
|
|
-#undef timeout_pending
|
|
-#undef timeout_initialized
|
|
-
|
|
#include <event.h>
|
|
#include <dnet.h>
|
|
#include "tree.h"
|
|
@@ -61,11 +57,12 @@ SPLAY_PROTOTYPE(tree, arp_req, next, compare);
|
|
|
|
SPLAY_GENERATE(tree, arp_req, next, compare);
|
|
|
|
+static struct event arpd_sigint;
|
|
+static struct event arpd_sigterm;
|
|
static pcap_t *arpd_pcap;
|
|
static arp_t *arpd_arp;
|
|
static eth_t *arpd_eth;
|
|
static struct intf_entry arpd_ifent;
|
|
-static int arpd_sig;
|
|
|
|
static void
|
|
usage(void)
|
|
@@ -265,7 +262,7 @@ arpd_send(eth_t *eth, int op,
|
|
spa->addr_ip, tha->addr_eth, tpa->addr_ip);
|
|
|
|
if (op == ARP_OP_REQUEST) {
|
|
- syslog(LOG_DEBUG, __FUNCTION__ ": who-has %s tell %s",
|
|
+ syslog(LOG_DEBUG, "%s: who-has %s tell %s", __FUNCTION__,
|
|
addr_ntoa(tpa), addr_ntoa(spa));
|
|
} else if (op == ARP_OP_REPLY) {
|
|
syslog(LOG_INFO, "arp reply %s is-at %s",
|
|
@@ -282,7 +278,7 @@ arpd_lookup(struct addr *addr)
|
|
int error;
|
|
|
|
if (addr_cmp(addr, &arpd_ifent.intf_addr) == 0) {
|
|
- syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
|
|
+ syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
|
|
addr_ntoa(addr), addr_ntoa(&arpd_ifent.intf_link_addr));
|
|
return (0);
|
|
}
|
|
@@ -291,10 +287,10 @@ arpd_lookup(struct addr *addr)
|
|
error = arp_get(arpd_arp, &arpent);
|
|
|
|
if (error == -1) {
|
|
- syslog(LOG_DEBUG, __FUNCTION__ ": no entry for %s",
|
|
+ syslog(LOG_DEBUG, "%s: no entry for %s", __FUNCTION__,
|
|
addr_ntoa(addr));
|
|
} else {
|
|
- syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
|
|
+ syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
|
|
addr_ntoa(addr), addr_ntoa(&arpent.arp_ha));
|
|
}
|
|
return (error);
|
|
@@ -303,9 +299,9 @@ arpd_lookup(struct addr *addr)
|
|
static void
|
|
arpd_free(struct arp_req *req)
|
|
{
|
|
- timeout_del(&req->active);
|
|
- timeout_del(&req->inactive);
|
|
- timeout_del(&req->discover);
|
|
+ evtimer_del(&req->active);
|
|
+ evtimer_del(&req->inactive);
|
|
+ evtimer_del(&req->discover);
|
|
free(req);
|
|
}
|
|
|
|
@@ -331,7 +327,7 @@ arpd_discover(struct arp_req *req, struc
|
|
arpd_send(arpd_eth, ARP_OP_REQUEST,
|
|
&arpd_ifent.intf_link_addr,
|
|
&arpd_ifent.intf_addr, &req->ha, &req->pa);
|
|
- timeout_add(&req->discover, &tv);
|
|
+ evtimer_add(&req->discover, &tv);
|
|
}
|
|
req->cnt++;
|
|
}
|
|
@@ -378,13 +374,13 @@ arpd_recv_cb(u_char *u, const struct pca
|
|
}
|
|
memcpy(&req->pa, &tmp.pa, sizeof(tmp.pa));
|
|
|
|
- timeout_set(&req->active, arpd_timeout, req);
|
|
- timeout_set(&req->inactive, arpd_timeout, req);
|
|
- timeout_set(&req->discover, arpd_discovercb, req);
|
|
+ evtimer_set(&req->active, arpd_timeout, req);
|
|
+ evtimer_set(&req->inactive, arpd_timeout, req);
|
|
+ evtimer_set(&req->discover, arpd_discovercb, req);
|
|
|
|
timerclear(&tv);
|
|
tv.tv_sec = ARPD_MAX_ACTIVE;
|
|
- timeout_add(&req->active, &tv);
|
|
+ evtimer_add(&req->active, &tv);
|
|
|
|
SPLAY_INSERT(tree, &arpd_reqs, req);
|
|
|
|
@@ -396,7 +392,7 @@ arpd_recv_cb(u_char *u, const struct pca
|
|
} else {
|
|
timerclear(&tv);
|
|
tv.tv_sec = ARPD_MAX_INACTIVE;
|
|
- timeout_add(&req->inactive, &tv);
|
|
+ evtimer_add(&req->inactive, &tv);
|
|
|
|
if (req->negative) {
|
|
syslog(LOG_DEBUG, "%s: %s is allocated",
|
|
@@ -423,7 +419,7 @@ arpd_recv_cb(u_char *u, const struct pca
|
|
if ((req = SPLAY_FIND(tree, &arpd_reqs, &tmp)) != NULL) {
|
|
addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
|
|
ethip->ar_sha, ETH_ADDR_LEN);
|
|
- syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
|
|
+ syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
|
|
addr_ntoa(&req->pa), addr_ntoa(&src.arp_ha));
|
|
|
|
/* This address is claimed */
|
|
@@ -441,30 +438,18 @@ arpd_recv(int fd, short type, void *ev)
|
|
if (pcap_dispatch(arpd_pcap, -1, arpd_recv_cb, NULL) < 0)
|
|
syslog(LOG_ERR, "pcap_dispatch: %s", pcap_geterr(arpd_pcap));
|
|
}
|
|
-
|
|
+
|
|
void
|
|
-terminate_handler(int sig)
|
|
+arpd_signal(int sig, short events, void *data)
|
|
{
|
|
- extern int event_gotsig;
|
|
-
|
|
- event_gotsig = 1;
|
|
- arpd_sig = sig;
|
|
-}
|
|
-
|
|
-int
|
|
-arpd_signal(void)
|
|
-{
|
|
- syslog(LOG_INFO, "exiting on signal %d", arpd_sig);
|
|
+ syslog(LOG_INFO, "exiting on signal %d", sig);
|
|
arpd_exit(0);
|
|
- /* NOTREACHED */
|
|
- return (-1);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
struct event recv_ev;
|
|
- extern int (*event_sigcb)(void);
|
|
char *dev;
|
|
int c, debug;
|
|
FILE *fp;
|
|
@@ -516,15 +501,10 @@ main(int argc, char *argv[])
|
|
event_add(&recv_ev, NULL);
|
|
|
|
/* Setup signal handler */
|
|
- if (signal(SIGINT, terminate_handler) == SIG_ERR) {
|
|
- perror("signal");
|
|
- return (-1);
|
|
- }
|
|
- if (signal(SIGTERM, terminate_handler) == SIG_ERR) {
|
|
- perror("signal");
|
|
- return (-1);
|
|
- }
|
|
- event_sigcb = arpd_signal;
|
|
+ signal_set(&arpd_sigint, SIGINT, arpd_signal, NULL);
|
|
+ signal_add(&arpd_sigint, NULL);
|
|
+ signal_set(&arpd_sigterm, SIGTERM, arpd_signal, NULL);
|
|
+ signal_add(&arpd_sigterm, NULL);
|
|
|
|
event_dispatch();
|
|
|