[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bgpd listener fix



Hey bgpd users,

this diff needs your attention.

There is a major bug in the fd passing code that resulted in duplicate
listener fds passed to the SE. The result was normaly a CLOSED listener
and bgpd no longer accepting connections.

Here is a diff that solves that issue that needs to be tested ASAP by as
many people as possible.

To test you need to add/remove "listen on <IP>" statements from the config
and issue a "bgpctl reload". Then have a look at the netstat -an output
for any strange bgpd sockets.

-- 
:wq Claudio

Index: buffer.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/buffer.c,v
retrieving revision 1.27
diff -u -p -r1.27 buffer.c
--- buffer.c	14 Mar 2005 11:59:13 -0000	1.27
+++ buffer.c	17 Mar 2005 17:48:28 -0000
@@ -151,8 +151,6 @@ msgbuf_write(struct msgbuf *msgbuf)
 	TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
 		if (i >= IOV_MAX)
 			break;
-		if (i != 0 && buf->fd != -1)	/* fds on their own */
-			break;
 		iov[i].iov_base = buf->buf + buf->rpos;
 		iov[i].iov_len = buf->size - buf->rpos;
 		i++;
@@ -185,6 +183,15 @@ msgbuf_write(struct msgbuf *msgbuf)
 		return (-2);
 	}
 
+	/*
+	 * assumption: fd got sent if sendmsg sent anything
+	 * this works because fds are passed one at a time
+	 */
+	if (buf != NULL && buf->fd != -1) {
+		close(buf->fd);
+		buf->fd = -1;
+	}
+	
 	for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
 	    buf = next) {
 		next = TAILQ_NEXT(buf, entry);
@@ -194,11 +201,6 @@ msgbuf_write(struct msgbuf *msgbuf)
 		} else {
 			buf->rpos += n;
 			n = 0;
-			/* assumption: fd got sent if sendmsg sent anything */
-			if (buf->fd != -1) {
-				close(buf->fd);
-				buf->fd = -1;
-			}
 		}
 	}



Visit your host, monkey.org