luci: add server flags option and suppress some log

This commit is contained in:
Nick Peng
2023-05-05 22:36:09 +08:00
parent c9f7dad42f
commit 7bca0ee98f
14 changed files with 186 additions and 72 deletions

View File

@@ -913,6 +913,11 @@ int dns_add_SOA(struct dns_packet *packet, dns_rr_type type, const char *domain,
unsigned char data[sizeof(*soa)];
unsigned char *ptr = data;
int len = 0;
if (soa == NULL || domain == NULL || packet == NULL) {
return -1;
}
safe_strncpy((char *)ptr, soa->mname, DNS_MAX_CNAME_LEN);
ptr += strnlen(soa->mname, DNS_MAX_CNAME_LEN - 1) + 1;
safe_strncpy((char *)ptr, soa->rname, DNS_MAX_CNAME_LEN);

View File

@@ -56,7 +56,7 @@
#include <unistd.h>
#define DNS_MAX_HOSTNAME 256
#define DNS_MAX_EVENTS 64
#define DNS_MAX_EVENTS 256
#define DNS_HOSTNAME_LEN 128
#define DNS_TCP_BUFFER (32 * 1024)
#define DNS_TCP_IDLE_TIMEOUT (60 * 10)

View File

@@ -3308,18 +3308,20 @@ static int _config_log_level(void *data, int argc, char *argv[])
/* read log level and set */
char *value = argv[1];
if (strncmp("debug", value, MAX_LINE_LEN) == 0) {
if (strncasecmp("debug", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_DEBUG;
} else if (strncmp("info", value, MAX_LINE_LEN) == 0) {
} else if (strncasecmp("info", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_INFO;
} else if (strncmp("notice", value, MAX_LINE_LEN) == 0) {
} else if (strncasecmp("notice", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_NOTICE;
} else if (strncmp("warn", value, MAX_LINE_LEN) == 0) {
} else if (strncasecmp("warn", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_WARN;
} else if (strncmp("error", value, MAX_LINE_LEN) == 0) {
} else if (strncasecmp("error", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_ERROR;
} else if (strncmp("fatal", value, MAX_LINE_LEN) == 0) {
} else if (strncasecmp("fatal", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_FATAL;
} else if (strncasecmp("off", value, MAX_LINE_LEN) == 0) {
dns_conf_log_level = TLOG_OFF;
} else {
return -1;
}

View File

@@ -1122,6 +1122,11 @@ static int _dns_server_reply_tcp(struct dns_request *request, struct dns_server_
unsigned char inpacket_data[DNS_IN_PACKSIZE];
unsigned char *inpacket = inpacket_data;
if (len > sizeof(inpacket_data) - 2) {
tlog(TLOG_ERROR, "packet size is invalid.");
return -1;
}
/* TCP query format
* | len (short) | dns query data |
*/
@@ -6361,6 +6366,7 @@ static void _dns_server_save_cache_to_file(void)
close(i);
}
tlog_setlevel(TLOG_OFF);
_dns_server_cache_save(1);
_exit(0);
} else if (pid < 0) {

View File

@@ -542,7 +542,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
return PROXY_HANDSHAKE_ERR;
}
tlog(TLOG_INFO, "server %s select auth method is %d", proxy_conn->server_info->proxy_name,
tlog(TLOG_DEBUG, "server %s select auth method is %d", proxy_conn->server_info->proxy_name,
proxy_conn->buffer.buffer[1]);
if (proxy_conn->buffer.buffer[1] == PROXY_SOCKS5_AUTH_USER_PASS) {
return _proxy_handshake_socks5_send_auth(proxy_conn);
@@ -592,7 +592,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
return PROXY_HANDSHAKE_ERR;
}
tlog(TLOG_INFO, "server %s auth success", proxy_conn->server_info->proxy_name);
tlog(TLOG_DEBUG, "server %s auth success", proxy_conn->server_info->proxy_name);
proxy_conn->state = PROXY_CONN_CONNECTING;
return _proxy_handshake_socks5_reply_connect_addr(proxy_conn);
case PROXY_CONN_CONNECTING: {
@@ -720,7 +720,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
}
proxy_conn->state = PROXY_CONN_CONNECTED;
tlog(TLOG_INFO, "success connect to socks5 proxy server %s", proxy_conn->server_info->proxy_name);
tlog(TLOG_DEBUG, "success connect to socks5 proxy server %s", proxy_conn->server_info->proxy_name);
return PROXY_HANDSHAKE_CONNECTED;
} break;
default:
@@ -838,7 +838,7 @@ static int _proxy_handshake_http(struct proxy_conn *proxy_conn)
if (proxy_conn->buffer.len < 0) {
proxy_conn->buffer.len = 0;
}
tlog(TLOG_INFO, "success connect to http proxy server %s", proxy_conn->server_info->proxy_name);
tlog(TLOG_DEBUG, "success connect to http proxy server %s", proxy_conn->server_info->proxy_name);
proxy_conn->state = PROXY_CONN_CONNECTED;
ret = PROXY_HANDSHAKE_CONNECTED;
goto out;
@@ -929,6 +929,11 @@ int proxy_conn_sendto(struct proxy_conn *proxy_conn, const void *buf, size_t len
return -1;
}
if (sizeof(buffer) - buffer_len <= len) {
errno = ENOSPC;
return -1;
}
memcpy(buffer + buffer_len, buf, len);
buffer_len += len;

View File

@@ -26,7 +26,8 @@ typedef enum {
TLOG_WARN = 3,
TLOG_ERROR = 4,
TLOG_FATAL = 5,
TLOG_END = 6
TLOG_OFF = 6,
TLOG_END = 7
} tlog_level;
struct tlog_time {