From: Martin Mares Date: Wed, 6 Sep 2017 20:58:54 +0000 (+0200) Subject: Server: Maximum packet size is now configurable X-Git-Tag: v0.9~20 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ccd1e7806f5abcf1477ceb5ae44e9bbc6f13de80;p=subauth.git Server: Maximum packet size is now configurable --- diff --git a/etc/subauthd b/etc/subauthd index b66b178..ea26479 100644 --- a/etc/subauthd +++ b/etc/subauthd @@ -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 diff --git a/server/subauthd.c b/server/subauthd.c index bdfe295..0df6ab9 100644 --- a/server/subauthd.c +++ b/server/subauthd.c @@ -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), diff --git a/server/subauthd.h b/server/subauthd.h index facaef6..6572500 100644 --- a/server/subauthd.h +++ b/server/subauthd.h @@ -14,7 +14,6 @@ #include #define SOCKET_TIMEOUT 60000 // in ms -#define MAX_PACKET_SIZE 16384 #define MAX_OOB_DATA_SIZE 4096 struct client {