From f7421e07365e171296702da2023be51730de3d50 Mon Sep 17 00:00:00 2001 From: job Date: Wed, 15 May 2024 09:09:38 +0000 Subject: [PATCH] Mark RTR and IPv6 BGP packets with DSCP CS6 (network control) 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 | 29 ++++++++++++++++++++++++++++- usr.sbin/bgpd/session.c | 9 ++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index b4df9efaa8d..5987713052c 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -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 @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -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); } diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 559e41c1bd2..df990438254 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -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 @@ -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 -- 2.20.1