Mark RTR and IPv6 BGP packets with DSCP CS6 (network control)
authorjob <job@openbsd.org>
Wed, 15 May 2024 09:09:38 +0000 (09:09 +0000)
committerjob <job@openbsd.org>
Wed, 15 May 2024 09:09:38 +0000 (09:09 +0000)
Additionally, set TCP_NODELAY on the RTR socket, there is no need to
queue up messages towards the RTR server.

OK claudio@

usr.sbin/bgpd/bgpd.c
usr.sbin/bgpd/session.c

index b4df9ef..5987713 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpd.c,v 1.263 2024/04/09 12:05:07 claudio Exp $ */
+/*     $OpenBSD: bgpd.c,v 1.264 2024/05/15 09:09:38 job Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -20,6 +20,8 @@
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <err.h>
 #include <errno.h>
@@ -1342,6 +1344,8 @@ bgpd_rtr_connect(struct rtr_config *r)
        struct connect_elm *ce;
        struct sockaddr *sa;
        socklen_t len;
+       int nodelay = 1;
+       int pre = IPTOS_PREC_INTERNETCONTROL;
 
        if (connect_cnt >= MAX_CONNECT_CNT) {
                log_warnx("rtr %s: too many concurrent connection requests",
@@ -1387,6 +1391,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;
+       }
+
        imsg_compose(ibuf_rtr, IMSG_SOCKET_CONN, ce->id, 0, ce->fd, NULL, 0);
        free(ce);
 }
index 559e41c..df99043 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: session.c,v 1.474 2024/04/24 10:41:34 claudio Exp $ */
+/*     $OpenBSD: session.c,v 1.475 2024/05/15 09:09:38 job Exp $ */
 
 /*
  * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -1168,6 +1168,13 @@ session_setup_socket(struct peer *p)
                }
                break;
        case AID_INET6:
+               if (setsockopt(p->fd, IPPROTO_IPV6, IPV6_TCLASS, &pre,
+                   sizeof(pre)) == -1) {
+                       log_peer_warn(&p->conf, "session_setup_socket "
+                           "setsockopt TCLASS");
+                       return (-1);
+               }
+
                if (p->conf.ebgp) {
                        /*
                         * set hoplimit to foreign router's distance