xref: /openbsd/usr.sbin/smtpd/limit.c (revision d3140113)
1 /*	$OpenBSD: limit.c,v 1.7 2021/06/14 17:58:15 eric Exp $	*/
2 
3 /*
4  * Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <string.h>
20 
21 #include "smtpd.h"
22 
23 void
limit_mta_set_defaults(struct mta_limits * limits)24 limit_mta_set_defaults(struct mta_limits *limits)
25 {
26 	limits->maxconn_per_host = 10;
27 	limits->maxconn_per_route = 5;
28 	limits->maxconn_per_source = 100;
29 	limits->maxconn_per_connector = 20;
30 	limits->maxconn_per_relay = 100;
31 	limits->maxconn_per_domain = 100;
32 
33 	limits->conndelay_host = 0;
34 	limits->conndelay_route = 5;
35 	limits->conndelay_source = 0;
36 	limits->conndelay_connector = 0;
37 	limits->conndelay_relay = 2;
38 	limits->conndelay_domain = 0;
39 
40 	limits->discdelay_route = 3;
41 
42 	limits->max_mail_per_session = 100;
43 	limits->sessdelay_transaction = 0;
44 	limits->sessdelay_keepalive = 10;
45 
46 	limits->max_failures_per_session = 25;
47 
48 	limits->family = AF_UNSPEC;
49 
50 	limits->task_hiwat = 50;
51 	limits->task_lowat = 30;
52 	limits->task_release = 10;
53 }
54 
55 int
limit_mta_set(struct mta_limits * limits,const char * key,int64_t value)56 limit_mta_set(struct mta_limits *limits, const char *key, int64_t value)
57 {
58 	if (!strcmp(key, "max-conn-per-host"))
59 		limits->maxconn_per_host = value;
60 	else if (!strcmp(key, "max-conn-per-route"))
61 		limits->maxconn_per_route = value;
62 	else if (!strcmp(key, "max-conn-per-source"))
63 		limits->maxconn_per_source = value;
64 	else if (!strcmp(key, "max-conn-per-connector"))
65 		limits->maxconn_per_connector = value;
66 	else if (!strcmp(key, "max-conn-per-relay"))
67 		limits->maxconn_per_relay = value;
68 	else if (!strcmp(key, "max-conn-per-domain"))
69 		limits->maxconn_per_domain = value;
70 
71 	else if (!strcmp(key, "conn-delay-host"))
72 		limits->conndelay_host = value;
73 	else if (!strcmp(key, "conn-delay-route"))
74 		limits->conndelay_route = value;
75 	else if (!strcmp(key, "conn-delay-source"))
76 		limits->conndelay_source = value;
77 	else if (!strcmp(key, "conn-delay-connector"))
78 		limits->conndelay_connector = value;
79 	else if (!strcmp(key, "conn-delay-relay"))
80 		limits->conndelay_relay = value;
81 	else if (!strcmp(key, "conn-delay-domain"))
82 		limits->conndelay_domain = value;
83 
84 	else if (!strcmp(key, "reconn-delay-route"))
85 		limits->discdelay_route = value;
86 
87 	else if (!strcmp(key, "session-mail-max"))
88 		limits->max_mail_per_session = value;
89 	else if (!strcmp(key, "session-transaction-delay"))
90 		limits->sessdelay_transaction = value;
91 	else if (!strcmp(key, "session-keepalive"))
92 		limits->sessdelay_keepalive = value;
93 
94 	else if (!strcmp(key, "max-failures-per-session"))
95 		limits->max_failures_per_session = value;
96 
97 	else if (!strcmp(key, "task-hiwat"))
98 		limits->task_hiwat = value;
99 	else if (!strcmp(key, "task-lowat"))
100 		limits->task_lowat = value;
101 	else if (!strcmp(key, "task-release"))
102 		limits->task_release = value;
103 
104 	else
105 		return (0);
106 
107 	return (1);
108 }
109