summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-01-27 16:49:54 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-01-27 16:49:54 +0000
commitb90dcea62391e72344b88933bec736cf5abe9f5f (patch)
tree2799dae7e243490fb377d28be332d25fa779a061 /usr.sbin
parente4e7fa53836f3e4df92922382229f61df1b0ac80 (diff)
use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support ok claudio@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/bgpd.h8
-rw-r--r--usr.sbin/bgpd/config.c4
-rw-r--r--usr.sbin/bgpd/log.c6
-rw-r--r--usr.sbin/bgpd/mrt.c12
-rw-r--r--usr.sbin/bgpd/parse.y19
-rw-r--r--usr.sbin/bgpd/rde.c10
-rw-r--r--usr.sbin/bgpd/rde_decide.c13
-rw-r--r--usr.sbin/bgpd/session.c65
8 files changed, 85 insertions, 52 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 7e85cffff5c..d33a0833e61 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.81 2004/01/27 14:09:36 markus Exp $ */
+/* $OpenBSD: bgpd.h,v 1.82 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -127,8 +127,8 @@ struct peer_config {
u_int32_t id;
char group[PEER_DESCR_LEN];
char descr[PEER_DESCR_LEN];
- struct sockaddr_in remote_addr;
- struct sockaddr_in local_addr;
+ struct bgpd_addr remote_addr;
+ struct bgpd_addr local_addr;
u_long max_prefix;
u_int16_t remote_as;
u_int8_t ebgp; /* 1 = ebgp, 0 = ibgp */
@@ -294,7 +294,7 @@ void fatal(const char *);
void fatalx(const char *);
void fatal_ensure(const char *, int, const char *);
char *log_ntoa(in_addr_t);
-char *log_addr(struct bgpd_addr *);
+char *log_addr(const struct bgpd_addr *);
/* parse.y */
int cmdline_symset(char *);
diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c
index e2eb48ddb0d..8201b56b776 100644
--- a/usr.sbin/bgpd/config.c
+++ b/usr.sbin/bgpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.21 2004/01/27 14:09:36 markus Exp $ */
+/* $OpenBSD: config.c,v 1.22 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -98,5 +98,5 @@ get_id(struct peer *p)
/*
* XXX this collides with multiviews and will need more clue later XXX
*/
- return (ntohl(p->conf.remote_addr.sin_addr.s_addr));
+ return (ntohl(p->conf.remote_addr.v4.s_addr));
}
diff --git a/usr.sbin/bgpd/log.c b/usr.sbin/bgpd/log.c
index da69ff0ce33..bbece753be9 100644
--- a/usr.sbin/bgpd/log.c
+++ b/usr.sbin/bgpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.22 2004/01/23 21:17:51 henning Exp $ */
+/* $OpenBSD: log.c,v 1.23 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -110,7 +110,7 @@ log_fmt_peer(const struct peer_config *peer)
char *ip;
char *pfmt;
- ip = inet_ntoa(peer->remote_addr.sin_addr);
+ ip = log_addr(&peer->remote_addr);
if (peer->descr[0]) {
if (asprintf(&pfmt, "neighbor %s (%s)", ip, peer->descr) ==
-1)
@@ -383,7 +383,7 @@ log_ntoa(in_addr_t ip)
}
char *
-log_addr(struct bgpd_addr *addr) {
+log_addr(const struct bgpd_addr *addr) {
switch (addr->af) {
case AF_INET:
return (inet_ntoa(addr->v4));
diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c
index 05b43c7953d..ed92279b596 100644
--- a/usr.sbin/bgpd/mrt.c
+++ b/usr.sbin/bgpd/mrt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.c,v 1.23 2004/01/22 20:34:56 henning Exp $ */
+/* $OpenBSD: mrt.c,v 1.24 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -123,8 +123,8 @@ mrt_dump_bgp_msg(struct mrt_config *mrt, void *pkg, u_int16_t pkglen, int type,
DUMP_SHORT(buf, peer->remote_as);
DUMP_SHORT(buf, /* ifindex */ 0);
DUMP_SHORT(buf, 4);
- DUMP_NLONG(buf, peer->local_addr.sin_addr.s_addr);
- DUMP_NLONG(buf, peer->remote_addr.sin_addr.s_addr);
+ DUMP_NLONG(buf, peer->local_addr.v4.s_addr);
+ DUMP_NLONG(buf, peer->remote_addr.v4.s_addr);
/* bgp header was chopped off so glue a new one together. */
if (type > 0) {
@@ -183,8 +183,8 @@ mrt_dump_state(struct mrt_config *mrt, u_int16_t old_state, u_int16_t new_state,
DUMP_SHORT(buf, peer->remote_as);
DUMP_SHORT(buf, /* ifindex */ 0);
DUMP_SHORT(buf, 4);
- DUMP_NLONG(buf, peer->local_addr.sin_addr.s_addr);
- DUMP_NLONG(buf, peer->remote_addr.sin_addr.s_addr);
+ DUMP_NLONG(buf, peer->local_addr.v4.s_addr);
+ DUMP_NLONG(buf, peer->remote_addr.v4.s_addr);
DUMP_SHORT(buf, old_state);
DUMP_SHORT(buf, new_state);
@@ -310,7 +310,7 @@ mrt_dump_entry(struct mrt_config *mrt, struct prefix *p, u_int16_t snum,
DUMP_BYTE(buf, p->prefix->prefixlen);
DUMP_BYTE(buf, 1); /* state */
DUMP_LONG(buf, p->lastchange); /* originated */
- DUMP_NLONG(buf, peer->remote_addr.sin_addr.s_addr);
+ DUMP_NLONG(buf, peer->remote_addr.v4.s_addr);
DUMP_SHORT(buf, peer->remote_as);
DUMP_SHORT(buf, attr_len);
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index 33c4024506b..e99e5d8bf9b 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.41 2004/01/26 21:08:18 henning Exp $ */
+/* $OpenBSD: parse.y,v 1.42 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -242,11 +242,8 @@ optnumber : /* empty */ { $$ = 0; }
neighbor : NEIGHBOR address optnl '{' optnl {
curpeer = new_peer();
- curpeer->conf.remote_addr.sin_len =
- sizeof(curpeer->conf.remote_addr);
- curpeer->conf.remote_addr.sin_family = AF_INET;
- curpeer->conf.remote_addr.sin_port = htons(BGP_PORT);
- curpeer->conf.remote_addr.sin_addr.s_addr = $2.s_addr;
+ curpeer->conf.remote_addr.af = AF_INET;
+ curpeer->conf.remote_addr.v4.s_addr = $2.s_addr;
}
peeropts_l '}' {
curpeer->next = peer_l;
@@ -302,10 +299,8 @@ peeropts : REMOTEAS number {
free($2);
}
| LOCALADDR address {
- curpeer->conf.local_addr.sin_len =
- sizeof(curpeer->conf.local_addr);
- curpeer->conf.local_addr.sin_family = AF_INET;
- curpeer->conf.local_addr.sin_addr.s_addr = $2.s_addr;
+ curpeer->conf.local_addr.af = AF_INET;
+ curpeer->conf.local_addr.v4.s_addr = $2.s_addr;
}
| MULTIHOP number {
if ($2 < 2 || $2 > 255) {
@@ -791,8 +786,6 @@ alloc_peer(void)
p->conf.distance = 1;
p->conf.announce_type = ANNOUNCE_SELF;
p->conf.max_prefix = ULONG_MAX;
- p->conf.local_addr.sin_len = sizeof(p->conf.local_addr);
- p->conf.local_addr.sin_family = AF_INET;
return (p);
}
@@ -818,8 +811,6 @@ new_peer(void)
p->conf.distance = 1;
p->conf.announce_type = ANNOUNCE_SELF;
p->conf.max_prefix = ULONG_MAX;
- p->conf.local_addr.sin_len = sizeof(p->conf.local_addr);
- p->conf.local_addr.sin_family = AF_INET;
return (p);
}
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index eb5a1a127c2..895e17c0b8f 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.67 2004/01/22 21:09:00 henning Exp $ */
+/* $OpenBSD: rde.c,v 1.68 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -562,28 +562,22 @@ rde_update_log(const char *message,
const struct rde_peer *peer, const struct attr_flags *attr,
const struct bgpd_addr *prefix, u_int8_t prefixlen)
{
- char *neighbor;
char *nexthop = NULL;
struct in_addr nh;
if (! (conf->log & BGPD_LOG_UPDATES))
return;
- neighbor = strdup(inet_ntoa(peer->conf.remote_addr.sin_addr));
- if (neighbor == NULL)
- return;
-
if (attr != NULL) {
nh.s_addr = attr->nexthop;
asprintf(&nexthop, " via %s", inet_ntoa(nh));
}
log_debug("neighbor %s (AS%u) %s %s/%u %s",
- neighbor, peer->conf.remote_as, message,
+ log_addr(&peer->conf.remote_addr), peer->conf.remote_as, message,
inet_ntoa(prefix->v4), prefixlen,
nexthop ? nexthop : "");
- free(neighbor);
free(nexthop);
}
diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c
index c685a2f7dc0..a52ba3eedd0 100644
--- a/usr.sbin/bgpd/rde_decide.c
+++ b/usr.sbin/bgpd/rde_decide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_decide.c,v 1.24 2004/01/22 20:34:56 henning Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.25 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -178,10 +178,13 @@ prefix_cmp(struct prefix *p1, struct prefix *p2)
return (p2->peer->remote_bgpid - p1->peer->remote_bgpid);
/* 9. lowest peer address wins */
- if ((p2->peer->conf.remote_addr.sin_addr.s_addr -
- p1->peer->conf.remote_addr.sin_addr.s_addr) != 0)
- return (p2->peer->conf.remote_addr.sin_addr.s_addr -
- p1->peer->conf.remote_addr.sin_addr.s_addr);
+ if (memcmp(&p1->peer->conf.remote_addr,
+ &p2->peer->conf.remote_addr,
+ sizeof(p1->peer->conf.remote_addr)) != 0)
+ return (memcmp(&p1->peer->conf.remote_addr,
+ &p2->peer->conf.remote_addr,
+ sizeof(p1->peer->conf.remote_addr)));
+
fatalx("Uh, oh a politician in the decision process");
/* NOTREACHED */
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index d560e2d1831..d7c7cdae958 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.94 2004/01/23 18:06:01 henning Exp $ */
+/* $OpenBSD: session.c,v 1.95 2004/01/27 16:49:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -79,7 +79,9 @@ void session_dispatch_imsg(struct imsgbuf *, int);
void session_up(struct peer *);
void session_down(struct peer *);
-struct peer *getpeerbyid(u_int32_t);
+struct peer *getpeerbyaddr(struct bgpd_addr *);
+struct peer *getpeerbyid(u_int32_t);
+static struct sockaddr *addr2sa(struct bgpd_addr *, u_int16_t);
struct bgpd_config *conf, *nconf = NULL;
struct peer *npeers;
@@ -722,7 +724,8 @@ session_accept(int listenfd)
int
session_connect(struct peer *peer)
{
- int n;
+ int n;
+ struct sockaddr *sa;
/*
* we do not need the overcomplicated collision detection rfc1771
@@ -732,7 +735,8 @@ session_connect(struct peer *peer)
if (peer->sock != -1)
return (-1);
- if ((peer->sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
+ if ((peer->sock = socket(peer->conf.remote_addr.af, SOCK_STREAM,
+ IPPROTO_TCP)) == -1) {
log_peer_warn(&peer->conf, "session_connect socket");
bgp_fsm(peer, EVNT_CON_OPENFAIL);
return (-1);
@@ -741,8 +745,8 @@ session_connect(struct peer *peer)
peer->wbuf.sock = peer->sock;
/* if update source is set we need to bind() */
- if (peer->conf.local_addr.sin_addr.s_addr)
- if (bind(peer->sock, (struct sockaddr *)&peer->conf.local_addr,
+ if (peer->conf.local_addr.af)
+ if (bind(peer->sock, addr2sa(&peer->conf.local_addr, 0),
sizeof(peer->conf.local_addr))) {
log_peer_warn(&peer->conf, "session_connect bind");
bgp_fsm(peer, EVNT_CON_OPENFAIL);
@@ -756,8 +760,8 @@ session_connect(struct peer *peer)
session_socket_blockmode(peer->sock, BM_NONBLOCK);
- if ((n = connect(peer->sock, (struct sockaddr *)&peer->conf.remote_addr,
- sizeof(peer->conf.remote_addr))) == -1)
+ sa = addr2sa(&peer->conf.remote_addr, BGP_PORT);
+ if ((n = connect(peer->sock, sa, sa->sa_len)) == -1)
if (errno != EINPROGRESS) {
log_peer_warn(&peer->conf, "connect");
bgp_fsm(peer, EVNT_CON_OPENFAIL);
@@ -1416,7 +1420,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx)
if (idx != PFD_PIPE_MAIN)
fatalx("reconf request not from parent");
pconf = imsg.data;
- p = getpeerbyip(pconf->remote_addr.sin_addr.s_addr);
+ p = getpeerbyaddr(&pconf->remote_addr);
if (p == NULL) {
if ((p = calloc(1, sizeof(struct peer))) ==
NULL)
@@ -1515,13 +1519,27 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx)
}
struct peer *
+getpeerbyaddr(struct bgpd_addr *addr)
+{
+ struct peer *p;
+
+ /* we might want a more effective way to find peers by IP */
+ for (p = peers; p != NULL &&
+ memcmp(&p->conf.remote_addr, addr, sizeof(p->conf.remote_addr));
+ p = p->next)
+ ; /* nothing */
+
+ return (p);
+}
+
+struct peer *
getpeerbyip(in_addr_t 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.sin_addr.s_addr != ip; p = p->next)
+ p->conf.remote_addr.v4.s_addr != ip; p = p->next)
; /* nothing */
return (p);
@@ -1580,3 +1598,30 @@ imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
{
return (imsg_compose_pid(&ibuf_main, type, pid, data, datalen));
}
+
+static struct sockaddr *
+addr2sa(struct bgpd_addr *addr, u_int16_t port)
+{
+ static struct sockaddr_storage ss;
+ struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss;
+ struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&ss;
+
+ bzero(&ss, sizeof(ss));
+ switch (addr->af) {
+ case AF_INET:
+ sa_in->sin_family = AF_INET;
+ sa_in->sin_len = sizeof(struct sockaddr_in);
+ sa_in->sin_addr.s_addr = addr->v4.s_addr;
+ sa_in->sin_port = htons(port);
+ break;
+ case AF_INET6:
+ sa_in6->sin6_family = AF_INET6;
+ sa_in6->sin6_len = sizeof(struct sockaddr_in6);
+ memcpy(&sa_in6->sin6_addr, &addr->v6,
+ sizeof(sa_in6->sin6_addr));
+ sa_in6->sin6_port = htons(port);
+ break;
+ }
+
+ return ((struct sockaddr *)&ss);
+}