summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2003-12-23 01:06:22 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2003-12-23 01:06:22 +0000
commitd7fd4a13c62ac2d16ea4e2646be3b76940fef497 (patch)
tree33ac21b74746caafd79dbc0db730bff597079b47
parentef5c8e75746e73e2fb914ff36b40cd079cb9f3a5 (diff)
allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy
-rw-r--r--usr.sbin/bgpd/bgpd.h3
-rw-r--r--usr.sbin/bgpd/config.c6
-rw-r--r--usr.sbin/bgpd/parse.y15
-rw-r--r--usr.sbin/bgpd/session.c15
4 files changed, 25 insertions, 14 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index bc3d22f26c7..5502ddb6762 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.13 2003/12/22 15:22:13 henning Exp $ */
+/* $OpenBSD: bgpd.h,v 1.14 2003/12/23 01:06:21 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -99,6 +99,7 @@ struct bgpd_config {
u_int32_t bgpid;
u_int16_t holdtime;
u_int16_t min_holdtime;
+ struct sockaddr_in listen_addr;
struct peer *peers;
};
diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c
index 2e008b19fc3..dc2d26d0c2d 100644
--- a/usr.sbin/bgpd/config.c
+++ b/usr.sbin/bgpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.2 2003/12/19 14:23:28 henning Exp $ */
+/* $OpenBSD: config.c,v 1.3 2003/12/23 01:06:21 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -23,6 +23,7 @@
#include <errno.h>
#include <ifaddrs.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "bgpd.h"
@@ -66,6 +67,9 @@ merge_config(struct bgpd_config *xconf, struct bgpd_config *conf)
if (!xconf->min_holdtime)
xconf->min_holdtime = conf->min_holdtime = MIN_HOLDTIME;
+ memcpy(&xconf->listen_addr, &conf->listen_addr,
+ sizeof(xconf->listen_addr));
+
/*
* as we cannot get the negotiated holdtime in the main process,
* the session engine needs to check it against the possibly new values
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index 0083b374a74..0b7939e08f5 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.8 2003/12/22 19:43:36 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.9 2003/12/23 01:06:21 henning Exp $ */
/*
* Copyright (c) 2002, 2003 Henning Brauer <henning@openbsd.org>
@@ -81,7 +81,8 @@ typedef struct {
%}
-%token SET AS BGPID HOLDTIME HOLDTIME_MIN
+%token SET
+%token AS BGPID HOLDTIME HOLDTIME_MIN LISTEN ON
%token GROUP NEIGHBOR
%token REMOTEAS DESCR LOCALADDR MULTIHOP
%token ERROR
@@ -151,6 +152,9 @@ conf_main : AS number {
}
conf->min_holdtime = $2;
}
+ | LISTEN ON address {
+ conf->listen_addr.sin_addr.s_addr = $3.s_addr;
+ }
/*
* XXX this is bad.
* a) number should be optional
@@ -300,10 +304,12 @@ lookup(char *s)
{ "group", GROUP},
{ "holdtime", HOLDTIME},
{ "holdtime_min", HOLDTIME_MIN},
+ { "listen", LISTEN},
{ "local-address", LOCALADDR},
{ "mrtdump", MRTDUMP},
{ "multihop", MULTIHOP},
{ "neighbor", NEIGHBOR},
+ { "on", ON},
{ "remote-as", REMOTEAS},
{ "set", SET},
};
@@ -528,6 +534,11 @@ parse_config(char *filename, struct bgpd_config *xconf,
lineno = 1;
errors = 0;
+ conf->listen_addr.sin_len = sizeof(conf->listen_addr);
+ conf->listen_addr.sin_family = AF_INET;
+ conf->listen_addr.sin_addr.s_addr = INADDR_ANY;
+ conf->listen_addr.sin_port = htons(BGP_PORT);
+
if (strcmp(filename, "-") == 0) {
fin = stdin;
infile = "stdin";
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index 6e2f068a7f3..929132360ff 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.27 2003/12/21 23:28:39 henning Exp $ */
+/* $OpenBSD: session.c,v 1.28 2003/12/23 01:06:21 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -97,8 +97,7 @@ session_sighdlr(int sig)
int
setup_listener(void)
{
- int fd, opt;
- struct sockaddr_in addr;
+ int fd, opt;
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
return (fd);
@@ -106,12 +105,8 @@ setup_listener(void)
opt = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt));
- bzero(&addr, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- addr.sin_port = htons(BGP_PORT);
-
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr))) {
+ if (bind(fd, (struct sockaddr *)&conf->listen_addr,
+ sizeof(conf->listen_addr))) {
close(fd);
return (-1);
}
@@ -123,7 +118,7 @@ setup_listener(void)
close(fd);
return (-1);
}
-
+
return (fd);
}