looks fine to me, OK
On 2017 May 28 (Sun) at 19:12:34 +0200 (+0200), Sebastian Benoit wrote:
:Hi,
:
:testing hennigs diff i found having to specify the socket on the command
:line annoying:
:
: bgpctl -s /var/run/rdomain123.bgpd.sock sh rib
:
:srly?
:
:I figure when you are debuging things in rdomain <r>, you will want to route
:-T <r> exec ksh anyway, so this makes bgpd create /var/run/bgpd.sock.<r> when
run in rdomain
:<r>, and bgpctl to use /var/run/bgpd.sock.<r> when run in rdomain <r>.
:
:ok?
:
:(claudio suggested that we should do this in other routing daemons too - i
:will send diffs if this is acceptable).
:
:diff --git usr.sbin/bgpctl/bgpctl.8 usr.sbin/bgpctl/bgpctl.8
:index c17f4dcdd37..60e88f1f048 100644
:--- usr.sbin/bgpctl/bgpctl.8
:+++ usr.sbin/bgpctl/bgpctl.8
:@@ -44,10 +44,14 @@ Show neighbors' IP addresses instead of their description.
: .It Fl s Ar socket
: Use
: .Ar socket
:+to communicate with
:+.Xr bgpd 8
: instead of the default
: .Pa /var/run/bgpd.sock
:-to communicate with
:-.Xr bgpd 8 .
:+when run in routing domain 0, or
:+.Pa /var/run/bgpd.sock.<rdomain>
:+when run in routing domain
:+.Ar <rdomain> .
: .El
: .Pp
: The commands are as follows:
:diff --git usr.sbin/bgpctl/bgpctl.c usr.sbin/bgpctl/bgpctl.c
:index c1acceec05c..f30e20b73fa 100644
:--- usr.sbin/bgpctl/bgpctl.c
:+++ usr.sbin/bgpctl/bgpctl.c
:@@ -20,6 +20,7 @@
:
: #include <sys/types.h>
: #include <sys/socket.h>
:+#include <sys/stat.h>
: #include <sys/un.h>
: #include <net/if.h>
: #include <net/if_media.h>
:@@ -117,19 +118,27 @@ int
: main(int argc, char *argv[])
: {
: struct sockaddr_un sun;
:- int fd, n, done, ch, nodescr = 0, verbose = 0;
:+ int fd, n, done, ch, nodescr = 0, verbose = 0, r;
: struct imsg imsg;
: struct network_config net;
: struct parse_result *res;
: struct ctl_neighbor neighbor;
: struct ctl_show_rib_request ribreq;
:- char *sockname;
:+ struct stat sb;
:+ char *sockname, *sockname_r = NULL;
: enum imsg_type type;
:
:+ sockname = SOCKET_NAME;
:+ if ((r = getrtable()) > 0) {
:+ if (asprintf(&sockname_r, "%s.%d", SOCKET_NAME, r) == -1)
:+ err(1, "asprintf");
:+ if (stat(sockname_r, &sb) == 0)
:+ sockname = sockname_r;
:+ }
:+
: if (pledge("stdio rpath wpath cpath unix inet dns", NULL) == -1)
: err(1, "pledge");
:
:- sockname = SOCKET_NAME;
: while ((ch = getopt(argc, argv, "ns:")) != -1) {
: switch (ch) {
: case 'n':
:@@ -173,6 +182,7 @@ main(int argc, char *argv[])
: errx(1, "socket name too long");
: if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)
: err(1, "connect: %s", sockname);
:+ free(sockname_r);
:
: if (pledge("stdio rpath wpath", NULL) == -1)
: err(1, "pledge");
:diff --git usr.sbin/bgpd/bgpd.conf.5 usr.sbin/bgpd/bgpd.conf.5
:index 2baaf5e3897..c6b05dbef89 100644
:--- usr.sbin/bgpd/bgpd.conf.5
:+++ usr.sbin/bgpd/bgpd.conf.5
:@@ -413,7 +413,13 @@ If
: is specified a restricted control socket will be created.
: By default
: .Pa /var/run/bgpd.sock
:-is used and no restricted socket is created.
:+is used when
:+.Xr bgpd 8
:+is run in routing domain 0, and
:+.Pa /var/run/bgpd.sock.<rdomain>
:+when run in routing domain
:+.Ar <rdomain> .
:+By default, no restricted socket is created.
: .Pp
: .It Xo
: .Ic transparent-as
:diff --git usr.sbin/bgpd/config.c usr.sbin/bgpd/config.c
:index adbfaf380ee..33d89311677 100644
:--- usr.sbin/bgpd/config.c
:+++ usr.sbin/bgpd/config.c
:@@ -28,6 +28,7 @@
: #include <ifaddrs.h>
: #include <netdb.h>
: #include <stdlib.h>
:+#include <stdio.h>
: #include <string.h>
: #include <unistd.h>
:
:@@ -44,7 +45,8 @@ void free_rdomains(struct rdomain_head *);
: struct bgpd_config *
: new_config(void)
: {
:- struct bgpd_config *conf;
:+ struct bgpd_config *conf;
:+ int r;
:
: if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL)
: fatal(NULL);
:@@ -53,7 +55,10 @@ new_config(void)
: conf->bgpid = get_bgpid();
: conf->fib_priority = RTP_BGP;
:
:- if ((conf->csock = strdup(SOCKET_NAME)) == NULL)
:+ if ((r = getrtable()) > 0) {
:+ if (asprintf(&conf->csock, "%s.%d", SOCKET_NAME, r) == -1)
:+ fatal(NULL);
:+ } else if ((conf->csock = strdup(SOCKET_NAME)) == NULL)
: fatal(NULL);
:
: if ((conf->filters = calloc(1, sizeof(struct filter_head))) == NULL)
:
--
"The Schizophrenic: An Unauthorized Autobiography"