]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Merge commit 'a95fff37' into thread-merge-2.16
authorMaria Matejka <mq@ucw.cz>
Thu, 28 Nov 2024 09:57:37 +0000 (10:57 +0100)
committerMaria Matejka <mq@ucw.cz>
Thu, 28 Nov 2024 09:57:37 +0000 (10:57 +0100)
1  2 
conf/conf.h
nest/cli.h
sysdep/unix/config.Y
sysdep/unix/io.c
sysdep/unix/main.c
sysdep/unix/unix.h

diff --cc conf/conf.h
index 9a06ad4df45003e86de01e65dbab69c2bcb667c9,dd2966520578289de2a3081d8c71d3474b1a7a2b..03ef4ef823e2b0c5f8b6b3f3fbe1923bdca3f800
@@@ -13,8 -13,8 +13,9 @@@
  #include "lib/ip.h"
  #include "lib/hash.h"
  #include "lib/resource.h"
 +#include "lib/obstacle.h"
  #include "lib/timer.h"
+ #include "lib/tlists.h"
  
  /* Configuration structure */
  struct config {
    list logfiles;                      /* Configured log files (sysdep) */
    list tests;                         /* Configured unit tests (f_bt_test_suite) */
    list symbols;                               /* Configured symbols in config order */
+   TLIST_STRUCT_DEF(cli_config, struct cli_config) cli; /* Configured CLI sockets */
  
 -  int mrtdump_file;                   /* Configured MRTDump file (sysdep, fd in unix) */
 +  struct rfile *mrtdump_file;         /* Configured MRTDump file */
    const char *syslog_name;            /* Name used for syslog (NULL -> no syslog) */
 -  struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */
 +  struct symbol *def_tables[NET_MAX]; /* Default routing tables for each network */
    struct iface_patt *router_id_from;  /* Configured list of router ID iface patterns */
  
    u32 router_id;                      /* Our Router ID */
diff --cc nest/cli.h
index bcc64dc055e43c53f9dee4e67bd25952e31393a6,a9848a89dca1b9cb337e047bd8803e51f87b9f09..37943a1b9aa05b19ac7d67b187efdecbf27b5a36
  #define _BIRD_CLI_H_
  
  #include "lib/resource.h"
 +#include "lib/lists.h"
  #include "lib/event.h"
+ #include "lib/tlists.h"
+ #include "conf/conf.h"
  
  #define CLI_RX_BUF_SIZE 4096
  #define CLI_TX_BUF_SIZE 4096
index 46365c85051157b3d6bd115708d6bf5e165fac91,24d1ae5d288e343350547f18e9b2637a02f6b878..6df86c2f6a9a3eb12df88b2a58cbd5eae039c209
@@@ -17,12 -17,11 +17,12 @@@ static struct log_config *this_log
  
  CF_DECLS
  
- CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR, SOFT, UDP, PORT)
 -CF_KEYWORDS(LOG, SYSLOG, NAME, STDERR, UDP, PORT, CLI)
 -CF_KEYWORDS(ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG)
 -CF_KEYWORDS(DEBUG, LATENCY, LIMIT, WATCHDOG, WARNING, TIMEOUT, THREADS)
++CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR, SOFT, UDP, PORT, CLI)
 +CF_KEYWORDS(NAME, CONFIRM, UNDO, CHECK, TIMEOUT, DEBUG, LATENCY, LIMIT, WATCHDOG, WARNING, STATUS)
 +CF_KEYWORDS(PING, WAKEUP, SOCKETS, SCHEDULING, EVENTS, TIMERS, ALLOCATOR)
 +CF_KEYWORDS(GRACEFUL, RESTART, FIXED)
  
 -%type <i> log_mask log_mask_list log_cat cfg_timeout
 +%type <i> log_mask log_mask_list log_cat cfg_timeout debug_unix latency_debug_mask latency_debug_flag latency_debug_list
  %type <t> cfg_name
  %type <tf> timeformat_which
  %type <t> syslog_name
@@@ -122,13 -123,6 +122,12 @@@ mrtdump_base
     }
   ;
  
 +conf: THREADS expr {
 +    if ($2 < 1) cf_error("Number of threads must be at least one.");
 +    new_config->thread_count = $2;
 +}
 +
 +
  conf: debug_unix ;
  
  debug_unix:
index 7f7676e9deec225bf0a36790ae0995bb69733772,5a0dde8e3b567febc64367f877755ab81a95a664..9d120258e96505af94a33f6c47658158836debc0
@@@ -1684,7 -1531,7 +1684,7 @@@ err
  }
  
  int
- sk_open_unix(sock *s, struct birdloop *loop, char *name)
 -sk_open_unix(sock *s, const char *name)
++sk_open_unix(sock *s, struct birdloop *loop, const char *name)
  {
    struct sockaddr_un sa;
    int fd;
index 254690b1ba9d6b65c988b7dfb4af088b8081b8ae,c712aee482f5e084601bf1367f594e6a4a6e3e50..38b96fe5b8498f87c296473b61d98ba40968c2cd
@@@ -545,19 -536,51 +548,51 @@@ cli_listener(struct cli_config *cf
    s->fast_rx = 1;
  
    /* Return value intentionally ignored */
-   unlink(path_control_socket);
+   unlink(cf->name);
  
-   if (sk_open_unix(s, &main_birdloop, path_control_socket) < 0)
-     die("Cannot create control socket %s: %m", path_control_socket);
 -  if (sk_open_unix(s, cf->name) < 0)
++  if (sk_open_unix(s, &main_birdloop, cf->name) < 0)
+   {
+     log(L_ERR "Cannot create control socket %s: %m", cf->name);
+     return NULL;
+   }
  
-   if (use_uid || use_gid)
-     if (chown(path_control_socket, use_uid, use_gid) < 0)
-       die("chown: %m");
+   if (cf->uid || cf->gid)
+     if (chown(cf->name, cf->uid, cf->gid) < 0)
+     {
+       log(L_ERR "Cannot chown control socket %s: %m", cf->name);
+       return NULL;
+     }
  
-   if (chmod(path_control_socket, 0660) < 0)
-     die("chmod: %m");
+   if (chmod(cf->name, cf->mode) < 0)
+   {
+     log(L_ERR "Cannot chmod control socket %s: %m", cf->name);
+     return NULL;
+   }
+   return l;
+ }
+ static void
+ cli_init_unix(uid_t use_uid, gid_t use_gid)
+ {
+   ASSERT_DIE(main_control_socket_config == NULL);
+   main_control_socket_config = mb_alloc(&root_pool, sizeof *main_control_socket_config);
+   *main_control_socket_config = (struct cli_config) {
+     .name = path_control_socket,
+     .uid = use_uid,
+     .gid = use_gid,
+     .mode = 0660,
+   };
+   ASSERT_DIE(main_control_socket == NULL);
+   cli_init();
+   main_control_socket = cli_listener(main_control_socket_config);
+   if (!main_control_socket)
+     die("Won't run without control socket");
  }
  
  /*
   *    PID file
   */
index e7c4c143649b0eb8ca56f9d1a3e7c9e2e7636487,7c15e30d46a29e67b9b5b3925d48c3603bf521c0..e9b8758d748d08504c7a0b645058c8e01a61a387
@@@ -114,22 -107,11 +114,22 @@@ extern volatile sig_atomic_t async_shut
  void io_init(void);
  void io_loop(void);
  void io_log_dump(void);
- int sk_open_unix(struct birdsock *s, struct birdloop *, char *name);
 -int sk_open_unix(struct birdsock *s, const char *name);
 -struct rfile *rf_open(struct pool *, const char *name, const char *mode);
 -struct rfile *rf_fdopen(pool *p, int fd, const char *mode);
 -void *rf_file(struct rfile *f);
++int sk_open_unix(struct birdsock *s, struct birdloop *, const char *name);
 +
 +enum rf_mode {
 +  RF_APPEND = 1,
 +  RF_FIXED,
 +};
 +
 +struct rfile *rf_open(struct pool *, const char *name, enum rf_mode mode, off_t limit);
 +off_t rf_size(struct rfile *);
 +int rf_same(struct rfile *, struct rfile *);
 +int rf_writev(struct rfile *, struct iovec *, int);
 +void rf_write_crude(struct rfile *, const char *, int);
  int rf_fileno(struct rfile *f);
 +
 +extern struct rfile rf_stderr;
 +
  void test_old_bird(char *path);
  ip_addr resolve_hostname(const char *host, int type, const char **err_msg);