Index | Thread | Search

From:
Ralph Covelli <rcovelli@he.net>
Subject:
rtrd: Add SIGNAL_PDU to the controller protocol
To:
tech@openbsd.org
Date:
Sat, 14 Nov 2026 17:27:44 -0500

Download raw body.

Thread
  • Ralph Covelli:

    rtrd: Add SIGNAL_PDU to the controller protocol

Add "SIGNAL_PDU" (type 143) to the controller protocol (RTRx).

This PDU exposes rtrd's internal signaling system to the controller.

We will be adding /etc/rtrd.conf support soon.  This enables features 
like "rtrctl reload".

OK?

Index: RTRX.PROTOCOL
===================================================================
RCS file: /cvs/src/usr.sbin/rtrd/RTRX.PROTOCOL,v
diff -u -p -r1.1 RTRX.PROTOCOL
--- RTRX.PROTOCOL	16 Sep 2026 16:11:46 -0000	1.1
+++ RTRX.PROTOCOL	14 Nov 2026 05:34:57 -0000
@@ -35,6 +35,7 @@ GLOBAL_STATS            = 139
 CLIENT_STATS            = 140
 CACHE_FRAME_STATS       = 141
 END_OF_STATS            = 142
+SIGNAL_PDU              = 143
 
 RTRx PDU Structures
 ===================
@@ -45,6 +46,7 @@ RTRx PDU Structures
 
 #define CONTROLLER_FLAGS_IMPORTER	0x00000001
 #define CONTROLLER_FLAGS_STATS		0x00000002
+#define CONTROLLER_FLAGS_SIGNAL		0x00000004
 
 struct pdu_open_controller
 {
@@ -247,6 +249,22 @@ struct pdu_end_of_stats
         uint32_t length;
 } PACKED;
 
+#define SIGNAL_PDU_TERM 1
+#define SIGNAL_PDU_INT  2
+#define SIGNAL_PDU_QUIT 3
+#define SIGNAL_PDU_USR1 4
+#define SIGNAL_PDU_USR2 5
+#define SIGNAL_PDU_HUP  6
+
+struct pdu_signal
+{
+        uint8_t version;
+        uint8_t type;
+        uint16_t reserved;
+        uint32_t length;
+        uint32_t signal;
+} PACKED;
+
 Protocol Sequences
 ==================
 
@@ -328,5 +346,14 @@ Client: <-                  GLOBAL_STATS
 Client: <- (0 or more)      CLIENT_STATS :RTR Server
 Client: <- (0 or more) CACHE_FRAME_STATS :RTR Server
 Client: <-                  END_OF_STATS :RTR Server
+Client: CLOSE_CONTROLLER              -> :RTR Server
+Client *disconnects*
+
+Send a signal to the server
+---------------------------
+
+Client *connects*
+Client: OPEN_CONTROLLER               -> :RTR Server
+Client: SIGNAL_PDU                    -> :RTR Server
 Client: CLOSE_CONTROLLER              -> :RTR Server
 Client *disconnects*
Index: commands.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtrd/commands.c,v
diff -u -p -r1.5 commands.c
--- commands.c	4 Oct 2026 13:31:56 -0000	1.5
+++ commands.c	14 Nov 2026 05:34:57 -0000
@@ -1429,6 +1429,63 @@ m_end_of_stats(struct rtr_socket *s, str
 	return 0;
 }
 
+int
+m_signal_pdu(struct rtr_socket *s, struct pdu_header *ph)
+{
+	struct pdu_signal *pdu_sig;
+
+	assert(s);
+	assert(ph);
+
+	if (!TestSocketFlag(s, RTR_SOCKET_FLAG_INUSE))
+		return 0;
+	if (s->type != RTR_SOCKET_TYPE_CONTROLLER)
+		return 0;
+	if (TestSocketFlag(s, RTR_SOCKET_FLAG_CLOSED))
+		return 0;
+	if (!TestSocketFlag(s, RTR_SOCKET_FLAG_REGISTERED))
+		return 0;
+
+	if (ph->version != s->version) {
+		logx(0, "Illegal protocol version change from %d to %d",
+		    s->version, ph->version);
+		return 1;
+	}
+
+	if (ph->length != sizeof(struct pdu_signal)) {
+		logx(0, "Corrupt length (Signal)");
+		return 1;
+	}
+
+	pdu_sig = (struct pdu_signal *)ph;
+
+	logx(1, "Received SIGNAL_PDU from %s\n",
+	    s->name);
+
+	switch(pdu_sig->signal) {
+	case SIGNAL_PDU_TERM:
+		sigterm = 1;
+		break;
+	case SIGNAL_PDU_INT:
+		sigint = 1;
+		break;
+	case SIGNAL_PDU_QUIT:
+		sigquit = 1;
+		break;
+	case SIGNAL_PDU_USR1:
+		sigusr1 = 1;
+		break;
+	case SIGNAL_PDU_USR2:
+		sigusr2 = 1;
+		break;
+	case SIGNAL_PDU_HUP:
+		sighup = 1;
+		break;
+	}
+
+	return 0;
+}
+
 int (*command_table[])(struct rtr_socket *, struct pdu_header *) = {
 	m_serial_notify,	/*   0 */
 	m_serial_query,		/*   1 */
@@ -1459,7 +1516,8 @@ int (*rtrx_command_table[])(struct rtr_s
 	m_global_stats,		/* 139 */
 	m_client_stats,		/* 140 */
 	m_cache_frame_stats,	/* 141 */
-	m_end_of_stats		/* 142 */
+	m_end_of_stats,		/* 142 */
+	m_signal_pdu		/* 143 */
 };
 
 int (*command_lookup(uint8_t version, uint8_t type, int sock_type))
Index: packets.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtrd/packets.c,v
diff -u -p -r1.5 packets.c
--- packets.c	30 Sep 2026 17:08:29 -0000	1.5
+++ packets.c	14 Nov 2026 05:34:57 -0000
@@ -292,6 +292,7 @@ pdu_hton_controller(void *pdu)
 	struct pdu_client_stats *cs;
 	struct pdu_cache_frame_stats *cfs;
 	struct pdu_open_controller *oc;
+	struct pdu_signal *sig;
 	int provider_count;
 	int i;
 
@@ -425,6 +426,10 @@ pdu_hton_controller(void *pdu)
 		break;
 	/* case END_OF_STATS: */
 		/* break; */
+	case SIGNAL_PDU:
+		sig = pdu;
+		sig->signal = htobe32(sig->signal);
+		break;
 	}
 }
 
@@ -440,6 +445,7 @@ pdu_ntoh_controller(void *pdu)
 	struct pdu_client_stats *cs;
 	struct pdu_cache_frame_stats *cfs;
 	struct pdu_open_controller *oc;
+	struct pdu_signal *sig;
 	int provider_count;
 	int i;
 
@@ -573,6 +579,10 @@ pdu_ntoh_controller(void *pdu)
 		break;
 	/* case END_OF_STATS: */
 		/* break; */
+	case SIGNAL_PDU:
+		sig = pdu;
+		sig->signal = be32toh(sig->signal);
+		break;
 	}
 }
 
Index: rtrd.h
===================================================================
RCS file: /cvs/src/usr.sbin/rtrd/rtrd.h,v
diff -u -p -r1.5 rtrd.h
--- rtrd.h	30 Sep 2026 17:08:29 -0000	1.5
+++ rtrd.h	14 Nov 2026 05:34:57 -0000
@@ -256,6 +256,7 @@ enum pdu_type {
 	CLIENT_STATS		= 140,
 	CACHE_FRAME_STATS	= 141,
 	END_OF_STATS		= 142,
+	SIGNAL_PDU		= 143,
 	PDU_RTRX_MAX
 };
 
@@ -587,6 +588,21 @@ struct pdu_end_of_stats {
 	uint32_t length;
 } __packed;
 
+#define SIGNAL_PDU_TERM	1
+#define SIGNAL_PDU_INT	2
+#define SIGNAL_PDU_QUIT	3
+#define SIGNAL_PDU_USR1	4
+#define SIGNAL_PDU_USR2	5
+#define SIGNAL_PDU_HUP	6
+
+struct pdu_signal {
+	uint8_t version;
+	uint8_t type;
+	uint16_t reserved;
+	uint32_t length;
+	uint32_t signal;
+} __packed;
+
 /*
  * Cache
  */
@@ -818,6 +834,7 @@ extern int m_global_stats(struct rtr_soc
 extern int m_client_stats(struct rtr_socket *, struct pdu_header *);
 extern int m_cache_frame_stats(struct rtr_socket *, struct pdu_header *);
 extern int m_end_of_stats(struct rtr_socket *, struct pdu_header *);
+extern int m_signal_pdu(struct rtr_socket *, struct pdu_header *);
 
 extern int (*command_lookup(uint8_t, uint8_t, int))
     (struct rtr_socket *, struct pdu_header *);
@@ -908,12 +925,14 @@ extern void sendclientstatsto_one(struct
 extern void sendcacheframestatsto_one(struct rtr_socket *);
 extern ssize_t sendendofstatsto_one(struct rtr_socket *);
 
-#define sigflags (sigterm || sigint || sigquit || sigusr1 || sighup)
+#define sigflags (sigterm || sigint || sigquit || \
+    sigusr1 || sigusr2 || sighup)
 
 extern volatile sig_atomic_t sigterm;
 extern volatile sig_atomic_t sigint;
 extern volatile sig_atomic_t sigquit;
 extern volatile sig_atomic_t sigusr1;
+extern volatile sig_atomic_t sigusr2;
 extern volatile sig_atomic_t sighup;
 
 extern int init_signals(void);
Index: signals.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtrd/signals.c,v
diff -u -p -r1.6 signals.c
--- signals.c	30 Sep 2026 17:08:29 -0000	1.6
+++ signals.c	14 Nov 2026 05:34:57 -0000
@@ -29,6 +29,7 @@ volatile sig_atomic_t sigterm = 0;
 volatile sig_atomic_t sigint = 0;
 volatile sig_atomic_t sigquit = 0;
 volatile sig_atomic_t sigusr1 = 0;
+volatile sig_atomic_t sigusr2 = 0;
 volatile sig_atomic_t sighup = 0;
 
 /* 1 on fail */
@@ -40,6 +41,7 @@ init_signals(void)
 	sigint = 0;
 	sigquit = 0;
 	sigusr1 = 0;
+	sigusr2 = 0;
 	sighup = 0;
 
 	memset(&sa, 0, sizeof(sa));
@@ -52,8 +54,6 @@ init_signals(void)
 		return 1;
 	if (sigaction(SIGALRM, &sa, NULL) != 0)
 		return 1;
-	if (sigaction(SIGUSR2, &sa, NULL) != 0)
-		return 1;
 
 	sa.sa_handler = &signal_handler;
 	if (sigaction(SIGTERM, &sa, NULL) != 0)
@@ -64,6 +64,8 @@ init_signals(void)
 		return 1;
 	if (sigaction(SIGUSR1, &sa, NULL) != 0)
 		return 1;
+	if (sigaction(SIGUSR2, &sa, NULL) != 0)
+		return 1;
 	if (sigaction(SIGHUP,  &sa, NULL) != 0)
 		return 1;
 	return 0;
@@ -85,6 +87,9 @@ signal_handler(int sig)
 	case SIGUSR1:
 		sigusr1 = 1;
 		break;
+	case SIGUSR2:
+		sigusr2 = 1;
+		break;
 	case SIGHUP:
 		sighup = 1;
 		break;
@@ -113,6 +118,10 @@ signal_processor(void)
 		logx(0, "Received USR1 signal\n");
 		rtr_shutdown(1); /* restart */
 		sigusr1 = 0;
+	}
+	if (sigusr2) {
+		logx(0, "Received USR2 signal\n");
+		sigusr2 = 0;
 	}
 	if (sighup) {
 		logx(0, "Received HUP signal\n");