]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Flock: shutdown command sends a reply
authorMaria Matejka <mq@ucw.cz>
Tue, 10 Sep 2024 10:04:44 +0000 (12:04 +0200)
committerMaria Matejka <mq@ucw.cz>
Sun, 23 Feb 2025 18:07:35 +0000 (19:07 +0100)
flock/ctl.c
flock/flock.h
flock/hypervisor.c

index ea34a7fe2a80e26a8a7bf1a0b8b3faab641c0237..1552993b0934e5c914ba2e8f6180de69bbdeec56 100644 (file)
@@ -1,4 +1,5 @@
 #include "lib/birdlib.h"
+#include "lib/cbor.h"
 #include "lib/string.h"
 #include "lib/io-loop.h"
 
@@ -19,6 +20,7 @@
 
 struct cbor_parser_context {
   linpool *lp;
+  sock *sock;
 
   PACKED enum {
     CPE_TYPE = 0,
@@ -58,12 +60,13 @@ struct cbor_parser_context {
 } while (0)
 
 struct cbor_parser_context *
-hcs_parser_init(pool *p)
+hcs_parser_init(sock *s)
 {
-  linpool *lp = lp_new(p);
+  linpool *lp = lp_new(s->pool);
   struct cbor_parser_context *ctx = lp_allocz(lp, sizeof *ctx);
 
   ctx->lp = lp;
+  ctx->sock = s;
 
   ctx->type = 0xff;
   ctx->stack_countdown[0] = 1;
@@ -154,7 +157,7 @@ hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size)
          case 1: /* inside toplevel mapping */
            if (ctx->type != 0)
              CBOR_PARSER_ERROR("Expected integer, got %u", ctx->type);
-           
+
            if (ctx->value >= 4)
              CBOR_PARSER_ERROR("Command key too high, got %lu", ctx->value);
 
@@ -167,6 +170,14 @@ hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size)
 
            log(L_INFO "Requested shutdown via CLI");
            ev_send_loop(&main_birdloop, &poweroff_event);
+           {
+             struct cbor_writer *cw = cbor_init(ctx->sock->tbuf, ctx->sock->tbsize, ctx->lp);
+             cbor_open_block_with_length(cw, 1);
+             cbor_add_int(cw, -1);
+             cbor_add_string(cw, "OK");
+             sk_send(ctx->sock, cw->pt);
+           }
+
            ctx->major_state = 1;
            break;
 
@@ -175,6 +186,7 @@ hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size)
              CBOR_PARSER_ERROR("Expected null, got %u-%u", ctx->type, ctx->value);
 
            log(L_INFO "Requested telnet open");
+
            ctx->major_state = 1;
            break;
 
index 2f83c5583017403be8c784459748a633fb13ae30..8cc334800b334168544d4e854b78a9ac4d138771 100644 (file)
@@ -6,6 +6,7 @@
 #include "lib/event.h"
 #include "lib/obstacle.h"
 #include "lib/resource.h"
+#include "lib/socket.h"
 
 void hypervisor_exposed_fork(void);
 void hypervisor_control_socket(void);
@@ -18,7 +19,7 @@ struct flock_config {
 
 extern struct flock_config flock_config;
 
-struct cbor_parser_context *hcs_parser_init(pool *p);
+struct cbor_parser_context *hcs_parser_init(sock *s);
 s64 hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size);
 void hcs_parser_cleanup(struct cbor_parser_context *ctx);
 const char *hcs_error(struct cbor_parser_context *ctx);
index 26d5e45552c83311d04fe6cbe486daa3088b279f..217eb5a7cbe7c375edd0d2187af7fdc2bb9d55e5 100644 (file)
@@ -39,7 +39,7 @@ hcs_rx(sock *s, uint size)
   /* TODO do something more */
 
   hcs_parser_cleanup(s->data);
-  s->data = hcs_parser_init(s->pool);
+  s->data = hcs_parser_init(s);
 
   if (sz == size)
     return 1;
@@ -63,7 +63,7 @@ hcs_connect(sock *s, uint size UNUSED)
 
   s->rx_hook = hcs_rx;
   s->err_hook = hcs_err;
-  s->data = hcs_parser_init(s->pool);
+  s->data = hcs_parser_init(s);
   return 1;
 }
 
@@ -103,6 +103,7 @@ hypervisor_control_socket(void)
   s->rx_hook = hcs_connect;
   s->err_hook = hcs_connect_err;
   s->rbsize = 1024;
+  s->tbsize = 1024;
 
   unlink(flock_config.control_socket_path);
   if (sk_open_unix(s, loop, flock_config.control_socket_path) < 0)