summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEsben Norby <norby@cvs.openbsd.org>2006-02-19 18:52:07 +0000
committerEsben Norby <norby@cvs.openbsd.org>2006-02-19 18:52:07 +0000
commit2e6ac6d7457d700f5de16f5fbdda7a24903d06b4 (patch)
tree61920e5048e696dfeefd0cedb0d2de1cbadb1f2d /usr.sbin
parent46ba324f6859f405726b929bc7af473bfdd4e0be (diff)
Do not allocate a new chunk of memory every time we receive a packet.
This should have been fixed ages ago since it really improves the performance of ospfd. ok claudio@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ospfd/ospfe.c8
-rw-r--r--usr.sbin/ospfd/ospfe.h4
-rw-r--r--usr.sbin/ospfd/packet.c33
3 files changed, 22 insertions, 23 deletions
diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c
index 956d39953a9..37bbca7d7f2 100644
--- a/usr.sbin/ospfd/ospfe.c
+++ b/usr.sbin/ospfd/ospfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfe.c,v 1.38 2006/02/10 18:30:47 claudio Exp $ */
+/* $OpenBSD: ospfe.c,v 1.39 2006/02/19 18:52:06 norby Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -170,6 +170,9 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2],
TAILQ_INIT(&ctl_conns);
control_listen();
+ if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL)
+ fatal("ospfe");
+
/* start interfaces */
LIST_FOREACH(area, &oeconf->area_list, entry) {
LIST_FOREACH(iface, &area->iface_list, entry) {
@@ -216,6 +219,7 @@ ospfe_shutdown(void)
msgbuf_clear(&ibuf_main->w);
free(ibuf_main);
free(oeconf);
+ free(pkt_ptr);
log_info("ospf engine exiting");
_exit(0);
@@ -715,7 +719,7 @@ orig_rtr_lsa(struct area *area)
(iface->linkstate != LINK_STATE_UP &&
iface->media_type == IFT_CARP))
continue;
-
+
log_debug("orig_rtr_lsa: stub net, "
"interface %s", iface->name);
diff --git a/usr.sbin/ospfd/ospfe.h b/usr.sbin/ospfd/ospfe.h
index b15f090c567..de4cda12e86 100644
--- a/usr.sbin/ospfd/ospfe.h
+++ b/usr.sbin/ospfd/ospfe.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfe.h,v 1.21 2006/02/02 15:11:54 norby Exp $ */
+/* $OpenBSD: ospfe.h,v 1.22 2006/02/19 18:52:06 norby Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -294,4 +294,6 @@ int gen_ospf_hdr(struct buf *, struct iface *, u_int8_t);
int send_packet(struct iface *, char *, int, struct sockaddr_in *);
void recv_packet(int, short, void *);
+char *pkt_ptr; /* packet buffer */
+
#endif /* _OSPFE_H_ */
diff --git a/usr.sbin/ospfd/packet.c b/usr.sbin/ospfd/packet.c
index 647b50bfba2..b5bf87585e1 100644
--- a/usr.sbin/ospfd/packet.c
+++ b/usr.sbin/ospfd/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.18 2005/11/12 18:18:24 deraadt Exp $ */
+/* $OpenBSD: packet.c,v 1.19 2006/02/19 18:52:06 norby Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -86,7 +86,7 @@ recv_packet(int fd, short event, void *bula)
struct iface *iface;
struct nbr *nbr = NULL;
struct in_addr addr;
- char *buf, *ptr;
+ char *buf;
ssize_t r;
u_int16_t len;
int l;
@@ -94,18 +94,13 @@ recv_packet(int fd, short event, void *bula)
if (event != EV_READ)
return;
- /*
- * XXX I don't like to allocate a buffer for each packet received
- * and freeing that buffer at the end of the function. It would be
- * enough to allocate the buffer on startup.
- */
- if ((ptr = buf = calloc(1, READ_BUF_SIZE)) == NULL)
- fatal("recv_packet");
+ /* setup buffer */
+ buf = pkt_ptr;
if ((r = recvfrom(fd, buf, READ_BUF_SIZE, 0, NULL, NULL)) == -1) {
if (errno != EAGAIN && errno != EINTR)
log_debug("recv_packet: error receiving packet");
- goto done;
+ return;
}
len = (u_int16_t)r;
@@ -113,18 +108,18 @@ recv_packet(int fd, short event, void *bula)
/* IP header sanity checks */
if (len < sizeof(ip_hdr)) {
log_warnx("recv_packet: bad packet size");
- goto done;
+ return;
}
memcpy(&ip_hdr, buf, sizeof(ip_hdr));
if ((l = ip_hdr_sanity_check(&ip_hdr, len)) == -1)
- goto done;
+ return;
buf += l;
len -= l;
/* find a matching interface */
if ((iface = find_iface(xconf, ip_hdr.ip_src)) == NULL) {
log_debug("recv_packet: cannot find valid interface");
- goto done;
+ return;
}
/*
@@ -140,7 +135,7 @@ recv_packet(int fd, short event, void *bula)
log_debug("recv_packet: packet sent to wrong "
"address %s, interface %s",
inet_ntoa(ip_hdr.ip_dst), iface->name);
- goto done;
+ return;
}
}
}
@@ -148,23 +143,23 @@ recv_packet(int fd, short event, void *bula)
/* OSPF header sanity checks */
if (len < sizeof(*ospf_hdr)) {
log_warnx("recv_packet: bad packet size");
- goto done;
+ return;
}
ospf_hdr = (struct ospf_hdr *)buf;
if ((l = ospf_hdr_sanity_check(&ip_hdr, ospf_hdr, len, iface)) == -1)
- goto done;
+ return;
nbr = nbr_find_id(iface, ospf_hdr->rtr_id);
if (ospf_hdr->type != PACKET_TYPE_HELLO && nbr == NULL) {
log_debug("recv_packet: unknown neighbor ID");
- goto done;
+ return;
}
if (auth_validate(buf, len, iface, nbr)) {
log_warnx("recv_packet: authentication error, "
"interface %s", iface->name);
- goto done;
+ return;
}
buf += sizeof(*ospf_hdr);
@@ -198,8 +193,6 @@ recv_packet(int fd, short event, void *bula)
log_debug("recv_packet: unknown OSPF packet type, interface %s",
iface->name);
}
-done:
- free(ptr);
}
int