Le Mon, May 03, 2021 at 03:01:13PM +0200, Claudio Jeker a écrit :
> The RTR connect code calls addr2sa() as an argument to connect() but also
> uses the len argument in both calls. It seems in some cases this is
> optimised the wrong way. I think it is better to write this code using two
> steps like it is done in other places.
>
> OK?
OK denis@
> --
> :wq Claudio
>
> Index: bgpd.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> retrieving revision 1.234
> diff -u -p -r1.234 bgpd.c
> --- bgpd.c16 Feb 2021 08:29:16 - 1.234
> +++ bgpd.c2 May 2021 14:57:58 -
> @@ -1261,6 +1261,7 @@ imsg_send_sockets(struct imsgbuf *se, st
> void
> bgpd_rtr_connect(struct rtr_config *r)
> {
> + struct sockaddr *sa;
> socklen_t len;
> int fd;
>
> @@ -1270,8 +1271,8 @@ bgpd_rtr_connect(struct rtr_config *r)
> log_warn("rtr %s", r->descr);
> return;
> }
> - if (r->local_addr.aid != AID_UNSPEC) {
> - if (bind(fd, addr2sa(>local_addr, 0, ), len) == -1) {
> + if ((sa = addr2sa(>local_addr, 0, )) != NULL) {
> + if (bind(fd, sa, len) == -1) {
> log_warn("rtr %s: bind to %s", r->descr,
> log_addr(>local_addr));
> close(fd);
> @@ -1279,8 +1280,8 @@ bgpd_rtr_connect(struct rtr_config *r)
> }
> }
>
> - if (connect(fd, addr2sa(>remote_addr, r->remote_port, ), len) ==
> - -1) {
> + sa = addr2sa(>remote_addr, r->remote_port, );
> + if (connect(fd, sa, len) == -1) {
> log_warn("rtr %s: connect to %s:%u", r->descr,
> log_addr(>remote_addr), r->remote_port);
> close(fd);
>