]> mj.ucw.cz Git - subauth.git/commitdiff
Server: Maximum packet size is now configurable
authorMartin Mares <mj@ucw.cz>
Wed, 6 Sep 2017 20:58:54 +0000 (22:58 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 6 Sep 2017 20:58:54 +0000 (22:58 +0200)
etc/subauthd
server/subauthd.c
server/subauthd.h

index b66b17827bdcf2f5dc21602ce0af4d913f8449f8..ea26479228bb7abb2afe2768dfb6d5383a7d8f3b 100644 (file)
@@ -13,6 +13,9 @@ SubauthD {
        # Maximum number of simultaneous client connections
        MaxConnections  1000
 
+       # Maximum packet size (default: 16k)
+       MaxPacketSize   16k
+
 #ifndef CONFIG_LOCAL
        # Log to a given stream (configured below)
        LogStream       syslog
index bdfe295930a57373f8df8d9452166bbd51c61476..0df6ab954c0aa6bd04209481bbd01fdd020d99f9 100644 (file)
@@ -28,11 +28,12 @@ clist zone_list;
 char *database_name = "subauthd.db";
 char *temp_key_file;
 char *log_stream_name;
+static uint max_packet_size = 16384;
 
 static struct main_file listen_socket;
 static uint num_connections;
 
-static byte packet_buffer[MAX_PACKET_SIZE];
+static byte *packet_buffer;
 static byte oob_data_buffer[MAX_OOB_DATA_SIZE];
 
 static int socket_read_handler(struct main_file *fi);
@@ -63,7 +64,7 @@ static void try_send_reply(struct client *c)
   TRANS_TRY
     {
       struct fastbuf fb;
-      fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE);
+      fbbuf_init_write(&fb, packet_buffer, max_packet_size);
       fb_tie(&fb);
       json_write(c->json, &fb, c->reply);
       len = fbbuf_count_written(&fb);
@@ -72,7 +73,7 @@ static void try_send_reply(struct client *c)
     {
       msg(L_ERROR, "Unable to construct reply, it is probably too long");
       struct fastbuf fb2;
-      fbbuf_init_write(&fb2, packet_buffer, MAX_PACKET_SIZE);
+      fbbuf_init_write(&fb2, packet_buffer, max_packet_size);
       bputs(&fb2, "{ \"error\": \"Reply too long\" }\n");
       len = fbbuf_count_written(&fb2);
     }
@@ -144,7 +145,7 @@ static int socket_read_handler(struct main_file *fi)
 
   struct iovec iov = {
     .iov_base = packet_buffer,
-    .iov_len = MAX_PACKET_SIZE,
+    .iov_len = max_packet_size,
   };
 
   struct msghdr mh = {
@@ -252,6 +253,8 @@ static int listen_read_handler(struct main_file *fi)
 
 static void init_socket(void)
 {
+  packet_buffer = xmalloc(max_packet_size);
+
   int sk = socket(PF_UNIX, SOCK_SEQPACKET, 0);
   if (sk < 0)
     die("socket(PF_UNIX, SOCK_SEQPACKET): %m");
@@ -314,6 +317,7 @@ static struct cf_section daemon_config = {
   CF_ITEMS {
     CF_STRING("SocketPath", &socket_path),
     CF_UINT("MaxConnections", &max_connections),
+    CF_UINT("MaxPacketSize", &max_packet_size),
     CF_LIST("Zone", &zone_list, &zone_config),
     CF_STRING("Database", &database_name),
     CF_STRING("TempKeyFile", &temp_key_file),
index facaef65f2af5f247c05a44b8cda8d499c99bca4..657250075e2ba25374adf979283b0da42522c5df 100644 (file)
@@ -14,7 +14,6 @@
 #include <ucw-json/json.h>
 
 #define SOCKET_TIMEOUT 60000           // in ms
-#define MAX_PACKET_SIZE 16384
 #define MAX_OOB_DATA_SIZE 4096
 
 struct client {