In bgpd_rtr_connect() do the setsockopt dance for IP_TOS and TCP_NODELAY
authorclaudio <claudio@openbsd.org>
Mon, 30 Sep 2024 09:42:24 +0000 (09:42 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 30 Sep 2024 09:42:24 +0000 (09:42 +0000)
before calling connect(). This way it happens for sure and on top the TOS
is already set on the initial SYN.
OK tb@

usr.sbin/bgpd/bgpd.c

index bb0e19d..572551c 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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);
 }