diff options
author | 2010-05-14 13:49:09 +0000 | |
---|---|---|
committer | 2010-05-14 13:49:09 +0000 | |
commit | deb01a47f3116531e30ca2713f7660f1c183f460 (patch) | |
tree | 8b76bf6a4282b44c2005dd7a019aea8165ba02fc | |
parent | Defer installing signal handlers until echo is disabled so that we (diff) | |
download | wireguard-openbsd-deb01a47f3116531e30ca2713f7660f1c183f460.tar.xz wireguard-openbsd-deb01a47f3116531e30ca2713f7660f1c183f460.zip |
Do not send notifications directly onto the wire. Decide in the caller how
to send the notification. On accept use write() else queue message and try
to send the queued messages out via msgbuf_write(). This may still fail but
is better then the code beforehands.
OK michele@
-rw-r--r-- | usr.sbin/ldpd/ldpe.h | 6 | ||||
-rw-r--r-- | usr.sbin/ldpd/notification.c | 18 | ||||
-rw-r--r-- | usr.sbin/ldpd/packet.c | 15 |
3 files changed, 21 insertions, 18 deletions
diff --git a/usr.sbin/ldpd/ldpe.h b/usr.sbin/ldpd/ldpe.h index fd2eb3d330c..6772ee7bffc 100644 --- a/usr.sbin/ldpd/ldpe.h +++ b/usr.sbin/ldpd/ldpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.h,v 1.7 2010/04/15 15:04:23 claudio Exp $ */ +/* $OpenBSD: ldpe.h,v 1.8 2010/05/14 13:49:09 claudio Exp $ */ /* * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org> @@ -88,9 +88,9 @@ void send_keepalive(struct nbr *); int recv_keepalive(struct nbr *, char *, u_int16_t); /* notification.c */ -void send_notification(u_int32_t, struct iface *, int, u_int32_t, - u_int32_t); void send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t); +struct buf *send_notification(u_int32_t, struct iface *, u_int32_t, + u_int32_t); int recv_notification(struct nbr *, char *, u_int16_t); /* address.c */ diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c index 286acd1df17..0708a6027a1 100644 --- a/usr.sbin/ldpd/notification.c +++ b/usr.sbin/ldpd/notification.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notification.c,v 1.5 2010/05/12 13:31:35 claudio Exp $ */ +/* $OpenBSD: notification.c,v 1.6 2010/05/14 13:49:09 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -43,17 +43,18 @@ void send_notification_nbr(struct nbr *nbr, u_int32_t status, u_int32_t msgid, u_int32_t type) { + struct buf *buf; + if (nbr->iface->passive) return; - log_debug("send_notification: neighbor ID %s", inet_ntoa(nbr->id)); - - send_notification(status, nbr->iface, nbr->fd, msgid, type); + buf = send_notification(status, nbr->iface, msgid, type); + evbuf_enqueue(&nbr->wbuf, buf); } -void -send_notification(u_int32_t status, struct iface *iface, int fd, - u_int32_t msgid, u_int32_t type) +struct buf * +send_notification(u_int32_t status, struct iface *iface, u_int32_t msgid, + u_int32_t type) { struct buf *buf; u_int16_t size; @@ -73,8 +74,7 @@ send_notification(u_int32_t status, struct iface *iface, int fd, gen_status_tlv(buf, status, msgid, type); - write(fd, buf->buf, buf->wpos); - buf_free(buf); + return (buf); } int diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index c6dafe327fe..df224545a4d 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.10 2010/05/01 12:22:33 jsg Exp $ */ +/* $OpenBSD: packet.c,v 1.11 2010/05/14 13:49:09 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -276,12 +276,14 @@ session_accept(int fd, short event, void *bula) return; } - /* XXX */ nbr = nbr_find_ip(iface, src.sin_addr.s_addr); if (nbr == NULL) { + struct buf *buf; /* If there is no neighbor matching there is no - Hello adjacency: send notification */ - send_notification(S_NO_HELLO, iface, newfd, 0, 0); + Hello adjacency: try to send notification */ + buf = send_notification(S_NO_HELLO, iface, 0, 0); + write(newfd, buf->buf, buf->wpos); + buf_free(buf); close(newfd); return; } @@ -437,8 +439,9 @@ session_shutdown(struct nbr *nbr, u_int32_t status, u_int32_t msgid, inet_ntoa(nbr->id), status); send_notification_nbr(nbr, status, msgid, type); - if (status != S_SHUTDOWN) - send_notification_nbr(nbr, S_SHUTDOWN, msgid, type); + + /* try to flush write buffer, if it fails tough shit */ + msgbuf_write(&nbr->wbuf.wbuf); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); } |