diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-04-16 04:52:27 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-04-16 04:52:27 +0000 |
commit | a2f6fe900ddac44ca32793c95d6e7c78431c0805 (patch) | |
tree | c6afa4cfa324a99da6ed26861a9a9953cdf32f4e /usr.sbin/bgpd/session.c | |
parent | 3ce5c575dda9cc5c74cc2315778a6a2d0ea07dff (diff) |
let getpeerbyip work for both v4 and v6
Diffstat (limited to 'usr.sbin/bgpd/session.c')
-rw-r--r-- | usr.sbin/bgpd/session.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index af4bceaab25..11fcf1c4d48 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.141 2004/04/16 04:47:19 henning Exp $ */ +/* $OpenBSD: session.c,v 1.142 2004/04/16 04:52:26 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -79,7 +79,7 @@ void session_dispatch_imsg(struct imsgbuf *, int); void session_up(struct peer *); void session_down(struct peer *); -struct peer *getpeerbyaddr(struct bgpd_addr *); +struct peer *getpeerbyip(struct sockaddr *); struct peer *getpeerbyid(u_int32_t); static struct sockaddr *addr2sa(struct bgpd_addr *, u_int16_t); @@ -753,7 +753,7 @@ session_accept(int listenfd) int connfd; int opt; socklen_t len; - struct sockaddr_in cliaddr; + struct sockaddr_storage cliaddr; struct peer *p = NULL; len = sizeof(cliaddr); @@ -765,7 +765,7 @@ session_accept(int listenfd) log_warn("accept"); } - p = getpeerbyip(cliaddr.sin_addr.s_addr); + p = getpeerbyip((struct sockaddr *)&cliaddr); if (p != NULL && (p->state == STATE_CONNECT || p->state == STATE_ACTIVE)) { @@ -1851,16 +1851,25 @@ getpeerbyaddr(struct bgpd_addr *addr) } struct peer * -getpeerbyip(in_addr_t ip) +getpeerbyip(struct sockaddr *ip) { struct peer *p; /* we might want a more effective way to find peers by IP */ - for (p = peers; p != NULL && - p->conf.remote_addr.v4.s_addr != ip; p = p->next) - ; /* nothing */ + for (p = peers; p != NULL; p = p->next) + if (p->conf.remote_addr.af == ip->sa_family) { + if (p->conf.remote_addr.af == AF_INET && + p->conf.remote_addr.v4.s_addr == + ((struct sockaddr_in *)ip)->sin_addr.s_addr) + return (p); + if (p->conf.remote_addr.af == AF_INET6 && + !bcmp(&p->conf.remote_addr.v6, + &((struct sockaddr_in6 *)ip)->sin6_addr, + sizeof(p->conf.remote_addr.v6))) + return (p); + } - return (p); + return (NULL); } struct peer * |