From: claudio Date: Mon, 30 Sep 2024 09:42:24 +0000 (+0000) Subject: In bgpd_rtr_connect() do the setsockopt dance for IP_TOS and TCP_NODELAY X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bc3692b580bc60c1139d13d2dd3ba44e2e37c01a;p=openbsd In bgpd_rtr_connect() do the setsockopt dance for IP_TOS and TCP_NODELAY before calling connect(). This way it happens for sure and on top the TOS is already set on the initial SYN. OK tb@ --- diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index bb0e19d01a8..572551ce4d8 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.267 2024/09/04 15:06:36 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.268 2024/09/30 09:42:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1381,6 +1381,29 @@ bgpd_rtr_connect(struct rtr_config *r) return; } + switch (r->remote_addr.aid) { + case AID_INET: + if (setsockopt(ce->fd, IPPROTO_IP, IP_TOS, &pre, sizeof(pre)) == + -1) { + log_warn("rtr %s: setsockopt IP_TOS", r->descr); + return; + } + break; + case AID_INET6: + if (setsockopt(ce->fd, IPPROTO_IPV6, IPV6_TCLASS, &pre, + sizeof(pre)) == -1) { + log_warn("rtr %s: setsockopt IP_TOS", r->descr); + return; + } + break; + } + + if (setsockopt(ce->fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, + sizeof(nodelay)) == -1) { + log_warn("rtr %s: setsockopt TCP_NODELAY", r->descr); + return; + } + if ((sa = addr2sa(&r->local_addr, 0, &len)) != NULL) { if (bind(ce->fd, sa, len) == -1) { log_warn("rtr %s: bind to %s", r->descr, @@ -1405,29 +1428,6 @@ bgpd_rtr_connect(struct rtr_config *r) return; } - switch (r->remote_addr.aid) { - case AID_INET: - if (setsockopt(ce->fd, IPPROTO_IP, IP_TOS, &pre, sizeof(pre)) == - -1) { - log_warn("rtr %s: setsockopt IP_TOS", r->descr); - return; - } - break; - case AID_INET6: - if (setsockopt(ce->fd, IPPROTO_IPV6, IPV6_TCLASS, &pre, - sizeof(pre)) == -1) { - log_warn("rtr %s: setsockopt IP_TOS", r->descr); - return; - } - break; - } - - if (setsockopt(ce->fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, - sizeof(nodelay)) == -1) { - log_warn("rtr %s: setsockopt TCP_NODELAY", r->descr); - return; - } - imsg_compose(ibuf_rtr, IMSG_SOCKET_CONN, ce->id, 0, ce->fd, NULL, 0); free(ce); }