1 /* $OpenBSD: limit.c,v 1.3 2014/02/04 14:56:03 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 <sys/types.h> 20 #include <sys/queue.h> 21 #include <sys/tree.h> 22 #include <sys/socket.h> 23 24 #include <ctype.h> 25 #include <err.h> 26 #include <event.h> 27 #include <fcntl.h> 28 #include <imsg.h> 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <string.h> 32 33 #include "smtpd.h" 34 #include "log.h" 35 36 void 37 limit_mta_set_defaults(struct mta_limits *limits) 38 { 39 limits->maxconn_per_host = 10; 40 limits->maxconn_per_route = 5; 41 limits->maxconn_per_source = 50; 42 limits->maxconn_per_connector = 20; 43 limits->maxconn_per_relay = 100; 44 limits->maxconn_per_domain = 100; 45 46 limits->conndelay_host = 0; 47 limits->conndelay_route = 5; 48 limits->conndelay_source = 0; 49 limits->conndelay_connector = 0; 50 limits->conndelay_relay = 2; 51 limits->conndelay_domain = 0; 52 53 limits->discdelay_route = 3; 54 55 limits->max_mail_per_session = 100; 56 limits->sessdelay_transaction = 1; 57 limits->sessdelay_keepalive = 10; 58 59 limits->max_failures_per_session = 25; 60 61 limits->family = AF_UNSPEC; 62 63 limits->task_hiwat = 50; 64 limits->task_lowat = 30; 65 limits->task_release = 10; 66 } 67 68 int 69 limit_mta_set(struct mta_limits *limits, const char *key, int64_t value) 70 { 71 if (!strcmp(key, "max-conn-per-host")) 72 limits->maxconn_per_host = value; 73 else if (!strcmp(key, "max-conn-per-route")) 74 limits->maxconn_per_route = value; 75 else if (!strcmp(key, "max-conn-per-source")) 76 limits->maxconn_per_source = value; 77 else if (!strcmp(key, "max-conn-per-connector")) 78 limits->maxconn_per_connector = value; 79 else if (!strcmp(key, "max-conn-per-relay")) 80 limits->maxconn_per_relay = value; 81 else if (!strcmp(key, "max-conn-per-domain")) 82 limits->maxconn_per_domain = value; 83 84 else if (!strcmp(key, "conn-delay-host")) 85 limits->conndelay_host = value; 86 else if (!strcmp(key, "conn-delay-route")) 87 limits->conndelay_route = value; 88 else if (!strcmp(key, "conn-delay-source")) 89 limits->conndelay_source = value; 90 else if (!strcmp(key, "conn-delay-connector")) 91 limits->conndelay_connector = value; 92 else if (!strcmp(key, "conn-delay-relay")) 93 limits->conndelay_relay = value; 94 else if (!strcmp(key, "conn-delay-domain")) 95 limits->conndelay_domain = value; 96 97 else if (!strcmp(key, "reconn-delay-route")) 98 limits->discdelay_route = value; 99 100 else if (!strcmp(key, "session-mail-max")) 101 limits->max_mail_per_session = value; 102 else if (!strcmp(key, "session-transaction-delay")) 103 limits->sessdelay_transaction = value; 104 else if (!strcmp(key, "session-keepalive")) 105 limits->sessdelay_keepalive = value; 106 107 else if (!strcmp(key, "max-failures-per-session")) 108 limits->max_failures_per_session = value; 109 110 else if (!strcmp(key, "task-hiwat")) 111 limits->task_hiwat = value; 112 else if (!strcmp(key, "task-lowat")) 113 limits->task_lowat = value; 114 else if (!strcmp(key, "task-release")) 115 limits->task_release = value; 116 117 else 118 return (0); 119 120 return (1); 121 } 122