summaryrefslogtreecommitdiff
path: root/usr.sbin/ldpd/packet.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2011-01-10 12:28:26 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2011-01-10 12:28:26 +0000
commit8dd53ac18f0cdb713d66285fd5bf778cfdc47c7b (patch)
tree194eecb1d2682613ac07e22ed306f7c87bd4bbef /usr.sbin/ldpd/packet.c
parentf41871bceda51d5e9a1475ff8a8d358b2317b1ba (diff)
Fix a bad heritage from ospfd. Make neighbors independent of interfaces.
They are not bound as strongly as in ospf and causes problems when the TCP connection is established from an not connected IP (e.g. a loopback). Use three RB trees to sort the neighbor list by id, addr and peerid. More cleanup is needed but this makes ldpd work against peers using loopback IPs. Problem found, reported and fix tested again by Marcel Wiget.
Diffstat (limited to 'usr.sbin/ldpd/packet.c')
-rw-r--r--usr.sbin/ldpd/packet.c43
1 files changed, 5 insertions, 38 deletions
diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c
index 932e1daad3e..80c42a09637 100644
--- a/usr.sbin/ldpd/packet.c
+++ b/usr.sbin/ldpd/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.13 2010/11/04 09:52:16 claudio Exp $ */
+/* $OpenBSD: packet.c,v 1.14 2011/01/10 12:28:25 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -42,7 +42,6 @@
int ldp_hdr_sanity_check(struct ldp_hdr *, u_int16_t,
const struct iface *);
struct iface *find_iface(struct ldpd_conf *, unsigned int, struct in_addr);
-struct iface *session_find_iface(struct ldpd_conf *, struct in_addr);
ssize_t session_get_pdu(struct ibuf_read *, char **);
static int msgcnt = 0;
@@ -60,7 +59,8 @@ gen_ldp_hdr(struct ibuf *buf, struct iface *iface, u_int16_t size)
ldp_hdr.length = htons(size);
ldp_hdr.lsr_id = ldpe_router_id();
- ldp_hdr.lspace_id = iface->lspace_id;
+ if (iface)
+ ldp_hdr.lspace_id = iface->lspace_id;
return (ibuf_add(buf, &ldp_hdr, LDP_HDR_SIZE));
}
@@ -253,8 +253,6 @@ void
session_accept(int fd, short event, void *bula)
{
struct sockaddr_in src;
- struct ldpd_conf *xconf = bula;
- struct iface *iface;
struct nbr *nbr = NULL;
int newfd;
socklen_t len = sizeof(src);
@@ -271,18 +269,12 @@ session_accept(int fd, short event, void *bula)
session_socket_blockmode(newfd, BM_NONBLOCK);
- if ((iface = session_find_iface(xconf, src.sin_addr)) == NULL) {
- log_debug("sess_recv_packet: cannot find a matching interface");
- close(newfd);
- return;
- }
-
- nbr = nbr_find_ip(iface, src.sin_addr.s_addr);
+ nbr = nbr_find_ip(src.sin_addr.s_addr);
if (nbr == NULL) {
struct ibuf *buf;
/* If there is no neighbor matching there is no
Hello adjacency: try to send notification */
- buf = send_notification(S_NO_HELLO, iface, 0, 0);
+ buf = send_notification(S_NO_HELLO, NULL, 0, 0);
write(newfd, buf->buf, buf->wpos);
ibuf_free(buf);
close(newfd);
@@ -462,31 +454,6 @@ session_close(struct nbr *nbr)
close(nbr->fd);
}
-struct iface *
-session_find_iface(struct ldpd_conf *xconf, struct in_addr src)
-{
- struct iface *iface = NULL;
-
- /* returned interface needs to be active */
- LIST_FOREACH(iface, &xconf->iface_list, entry) {
- switch (iface->type) {
- case IF_TYPE_POINTOPOINT:
- if (iface->dst.s_addr == src.s_addr &&
- !iface->passive)
- return (iface);
- break;
- default:
- if ((iface->addr.s_addr & iface->mask.s_addr) ==
- (src.s_addr & iface->mask.s_addr) &&
- !iface->passive)
- return (iface);
- break;
- }
- }
-
- return (NULL);
-}
-
ssize_t
session_get_pdu(struct ibuf_read *r, char **b)
{