smartdns: bump copyright to 2023, and fix some typo

This commit is contained in:
Nick Peng
2023-01-20 00:05:14 +08:00
parent 1f40577ef0
commit 13d028df0d
70 changed files with 717 additions and 621 deletions

View File

@@ -1,5 +1,5 @@
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
# Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
#
# smartdns is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -889,7 +889,7 @@ int dns_add_SOA(struct dns_packet *packet, dns_rr_type type, const char *domain,
/*| mname |
*| rname |
*| serial |
*| refersh |
*| refresh |
*| retry |
*| expire |
*| minimum |
@@ -926,7 +926,7 @@ int dns_get_SOA(struct dns_rrs *rrs, char *domain, int maxsize, int *ttl, struct
/*| mname |
*| rname |
*| serial |
*| refersh |
*| refresh |
*| retry |
*| expire |
*| minimum |
@@ -1017,7 +1017,7 @@ int dns_get_OPT_ECS(struct dns_rrs *rrs, unsigned short *opt_code, unsigned shor
return 0;
}
int dns_add_OPT_TCP_KEEYALIVE(struct dns_packet *packet, unsigned short timeout)
int dns_add_OPT_TCP_KEEPALIVE(struct dns_packet *packet, unsigned short timeout)
{
unsigned short timeout_net = htons(timeout);
int data_len = 0;
@@ -1029,7 +1029,7 @@ int dns_add_OPT_TCP_KEEYALIVE(struct dns_packet *packet, unsigned short timeout)
return _dns_add_opt_RAW(packet, DNS_OPT_T_TCP_KEEPALIVE, &timeout_net, data_len);
}
int dns_get_OPT_TCP_KEEYALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
int dns_get_OPT_TCP_KEEPALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
unsigned short *timeout)
{
unsigned char opt_data[DNS_MAX_OPT_LEN];
@@ -1528,7 +1528,7 @@ static int _dns_encode_CNAME(struct dns_context *context, struct dns_rrs *rrs)
return -1;
}
/* when code domain, len must plus 1, because of length at the begining */
/* when code domain, len must plus 1, because of length at the beginning */
rr_len = 1;
ret = _dns_encode_rr_head(context, domain, qtype, qclass, ttl, rr_len, &rr_len_ptr);
if (ret < 0) {
@@ -1815,7 +1815,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
{
unsigned short opt_code = 0;
unsigned short opt_len = 0;
unsigned short ercode = (ttl >> 16) & 0xFFFF;
unsigned short errcode = (ttl >> 16) & 0xFFFF;
unsigned short ever = (ttl)&0xFFFF;
unsigned char *start = context->ptr;
struct dns_packet *packet = context->packet;
@@ -1858,7 +1858,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
return -1;
}
if (ercode != 0) {
if (errcode != 0) {
tlog(TLOG_ERROR, "extend rcode invalid.");
return -1;
}

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -81,7 +81,7 @@ typedef enum dns_opt_code {
} dns_opt_code_t;
/* https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https/11/ */
typedef enum dns_htts_svcparam {
typedef enum dns_https_svcparam {
DNS_HTTPS_T_MANDATORY = 0,
DNS_HTTPS_T_ALPN = 1,
DNS_HTTPS_T_NO_DEFAULT_ALPN = 2,
@@ -90,7 +90,7 @@ typedef enum dns_htts_svcparam {
DNS_HTTPS_T_ECH = 5,
DNS_HTTPS_T_IPV6HINT = 6,
DNS_HTTPS_T_ALL = 255
} dns_htts_svcparam_t;
} dns_https_svcparam_t;
typedef enum dns_opcode {
DNS_OP_QUERY = 0,
@@ -129,7 +129,7 @@ struct dns_head {
unsigned short qdcount; /* number of question entries */
unsigned short ancount; /* number of answer entries */
unsigned short nscount; /* number of authority entries */
unsigned short nrcount; /* number of addititional resource entries */
unsigned short nrcount; /* number of additional resource entries */
} __attribute__((packed, aligned(2)));
#define DNS_PACKET_DICT_SIZE 16
@@ -143,7 +143,7 @@ struct dns_packet_dict {
struct dns_packet_dict_item names[DNS_PACKET_DICT_SIZE];
};
/* packet haed */
/* packet head */
struct dns_packet {
struct dns_head head;
unsigned short questions;
@@ -272,8 +272,8 @@ int dns_get_OPT_payload_size(struct dns_packet *packet);
int dns_add_OPT_ECS(struct dns_packet *packet, struct dns_opt_ecs *ecs);
int dns_get_OPT_ECS(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len, struct dns_opt_ecs *ecs);
int dns_add_OPT_TCP_KEEYALIVE(struct dns_packet *packet, unsigned short timeout);
int dns_get_OPT_TCP_KEEYALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
int dns_add_OPT_TCP_KEEPALIVE(struct dns_packet *packet, unsigned short timeout);
int dns_get_OPT_TCP_KEEPALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
unsigned short *timeout);
int dns_add_HTTPS_start(struct dns_rr_nested *svcparam_buffer, struct dns_packet *packet,

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -199,7 +199,7 @@ struct dns_client {
struct dns_client_ecs ecs_ipv4;
struct dns_client_ecs ecs_ipv6;
/* query doman hash table, key: sid + domain */
/* query domain hash table, key: sid + domain */
pthread_mutex_t domain_map_lock;
DECLARE_HASHTABLE(domain_map, 6);
DECLARE_HASHTABLE(group, 4);
@@ -632,7 +632,7 @@ errout:
/* add server to group */
static int _dns_client_add_to_group_pending(const char *group_name, char *server_ip, int port,
dns_server_type_t server_type, int ispending)
dns_server_type_t server_type, int is_pending)
{
struct dns_server_info *server_info = NULL;
@@ -642,7 +642,7 @@ static int _dns_client_add_to_group_pending(const char *group_name, char *server
server_info = _dns_client_get_server(server_ip, port, server_type);
if (server_info == NULL) {
if (ispending == 0) {
if (is_pending == 0) {
tlog(TLOG_ERROR, "add server %s:%d to group %s failed", server_ip, port, group_name);
return -1;
}
@@ -1345,7 +1345,7 @@ errout:
}
static int _dns_client_add_server_pending(char *server_ip, char *server_host, int port, dns_server_type_t server_type,
struct client_dns_server_flags *flags, int ispending)
struct client_dns_server_flags *flags, int is_pending)
{
int ret = 0;
@@ -1354,7 +1354,7 @@ static int _dns_client_add_server_pending(char *server_ip, char *server_host, in
return -1;
}
if (check_is_ipaddr(server_ip) && ispending) {
if (check_is_ipaddr(server_ip) && is_pending) {
ret = _dns_client_server_pending(server_ip, port, server_type, flags);
if (ret == 0) {
tlog(TLOG_INFO, "add pending server %s", server_ip);
@@ -1414,7 +1414,7 @@ static void _dns_client_query_release(struct dns_query_struct *query)
/* notify caller query end */
if (query->callback) {
tlog(TLOG_DEBUG, "result: %s, qtype: %d, hasresult: %d, id %d", query->domain, query->qtype, query->has_result,
tlog(TLOG_DEBUG, "result: %s, qtype: %d, has-result: %d, id %d", query->domain, query->qtype, query->has_result,
query->sid);
query->callback(query->domain, DNS_QUERY_END, NULL, NULL, NULL, 0, query->user_ptr);
}
@@ -1611,7 +1611,7 @@ static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *
if (len != 0) {
char host_name[DNS_MAX_CNAME_LEN];
tlog(TLOG_INFO, "decode failed, packet len = %d, tc = %d, id = %d, from = %s\n", inpacket_len, packet->head.tc,
packet->head.id, gethost_by_addr(host_name, sizeof(host_name), from));
packet->head.id, get_host_by_addr(host_name, sizeof(host_name), from));
if (dns_save_fail_packet) {
dns_packet_save(dns_save_fail_packet_dir, "client", host_name, inpacket, inpacket_len);
}
@@ -1806,7 +1806,7 @@ static int _dns_client_create_socket_udp(struct dns_server_info *server_info)
setsockopt(server_info->fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
setsockopt(server_info->fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));
if (server_info->ai_family == AF_INET6) {
/* for recving ip ttl value */
/* for receiving ip ttl value */
setsockopt(server_info->fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, sizeof(on));
setsockopt(server_info->fd, IPPROTO_IPV6, IPV6_2292HOPLIMIT, &on, sizeof(on));
setsockopt(server_info->fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, sizeof(on));
@@ -2170,7 +2170,7 @@ static int _dns_client_process_udp_proxy(struct dns_server_info *server_info, st
}
tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d",
gethost_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len);
get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len);
/* update recv time */
time(&server_info->last_recv);
@@ -2249,7 +2249,7 @@ static int _dns_client_process_udp(struct dns_server_info *server_info, struct e
}
tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d, ttl: %d",
gethost_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, ttl);
get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, ttl);
/* update recv time */
time(&server_info->last_recv);
@@ -2483,7 +2483,7 @@ static int _dns_client_process_tcp_buff(struct dns_server_info *server_info)
}
if (len > server_info->recv_buff.len - 2) {
/* len is not expceded, wait and recv */
/* len is not expected, wait and recv */
ret = 0;
goto out;
}
@@ -2619,7 +2619,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
return 0;
}
/* clear epllout event */
/* clear epollout event */
struct epoll_event mod_event;
memset(&mod_event, 0, sizeof(mod_event));
mod_event.events = EPOLLIN;
@@ -2998,7 +2998,7 @@ static int _dns_client_process(struct dns_server_info *server_info, struct epoll
/* receive from tcp */
return _dns_client_process_tcp(server_info, event, now);
} else if (server_info->type == DNS_SERVER_TLS || server_info->type == DNS_SERVER_HTTPS) {
/* recive from tls */
/* receive from tls */
return _dns_client_process_tls(server_info, event, now);
} else {
return -1;
@@ -3291,7 +3291,7 @@ static int _dns_client_send_packet(struct dns_query_struct *query, void *packet,
send_err = errno;
break;
default:
/* unsupport query type */
/* unsupported query type */
ret = -1;
break;
}
@@ -3344,7 +3344,7 @@ static int _dns_client_dns_add_ecs(struct dns_query_struct *query, struct dns_pa
return dns_add_OPT_ECS(packet, &query->ecs.ecs);
}
static int _dns_client_send_query(struct dns_query_struct *query, const char *doamin)
static int _dns_client_send_query(struct dns_query_struct *query, const char *domain)
{
unsigned char packet_buff[DNS_PACKSIZE];
unsigned char inpacket[DNS_IN_PACKSIZE];
@@ -3368,13 +3368,13 @@ static int _dns_client_send_query(struct dns_query_struct *query, const char *do
}
/* add question */
if (dns_add_domain(packet, doamin, query->qtype, DNS_C_IN) != 0) {
if (dns_add_domain(packet, domain, query->qtype, DNS_C_IN) != 0) {
tlog(TLOG_ERROR, "add domain to packet failed.");
return -1;
}
dns_set_OPT_payload_size(packet, DNS_IN_PACKSIZE);
/* dns_add_OPT_TCP_KEEYALIVE(packet, 600); */
/* dns_add_OPT_TCP_KEEPALIVE(packet, 600); */
if (_dns_client_dns_add_ecs(query, packet) != 0) {
tlog(TLOG_ERROR, "add ecs failed.");
return -1;
@@ -3667,8 +3667,8 @@ static void _dns_client_remove_all_pending_servers(void)
list_for_each_entry_safe(pending, tmp, &remove_list, retry_list)
{
list_del_init(&pending->retry_list);
_dns_client_server_pending_release(pending);
_dns_client_server_pending_remove(pending);
_dns_client_server_pending_release(pending);
}
}
@@ -3676,14 +3676,14 @@ static void _dns_client_add_pending_servers(void)
{
struct dns_server_pending *pending = NULL;
struct dns_server_pending *tmp = NULL;
static int dely = 0;
static int delay = 0;
LIST_HEAD(retry_list);
/* add pending server after 3 seconds */
if (++dely < 3) {
if (++delay < 3) {
return;
}
dely = 0;
delay = 0;
pthread_mutex_lock(&pending_server_mutex);
if (list_empty(&pending_servers)) {
@@ -4011,7 +4011,7 @@ void dns_client_exit(void)
client.tid = 0;
}
/* free all resouces */
/* free all resources */
_dns_client_remove_all_pending_servers();
_dns_client_server_remove_all();
_dns_client_query_remove_all();

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -144,7 +144,7 @@ int dns_conf_ipset_timeout_enable;
int dns_conf_nftset_timeout_enable;
int dns_conf_nftset_debug_enable;
char dns_conf_user[DNS_CONF_USRNAME_LEN];
char dns_conf_user[DNS_CONF_USERNAME_LEN];
int dns_save_fail_packet;
char dns_save_fail_packet_dir[DNS_MAX_PATH];
@@ -216,7 +216,7 @@ static void _dns_rule_put(struct dns_rule *rule)
}
}
static int _get_domain(char *value, char *domain, int max_dmain_size, char **ptr_after_domain)
static int _get_domain(char *value, char *domain, int max_domain_size, char **ptr_after_domain)
{
char *begin = NULL;
char *end = NULL;
@@ -246,7 +246,7 @@ static int _get_domain(char *value, char *domain, int max_dmain_size, char **ptr
/* Get domain */
len = end - begin;
if (len >= max_dmain_size) {
if (len >= max_domain_size) {
tlog(TLOG_ERROR, "domain name %s too long", value);
goto errout;
}
@@ -469,7 +469,7 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
{"tls-host-verify", required_argument, NULL, 'V' }, /* verify tls hostname */
{"group", required_argument, NULL, 'g'}, /* add to group */
{"proxy", required_argument, NULL, 'P'}, /* proxy server */
{"exclude-default-group", no_argument, NULL, 'E'}, /* ecluse this from default group */
{"exclude-default-group", no_argument, NULL, 'E'}, /* exclude this from default group */
{"set-mark", required_argument, NULL, 254}, /* set mark */
{NULL, no_argument, NULL, 0}
};
@@ -703,12 +703,12 @@ static int _config_domain_set_rule_add_ext(const char *set_name, enum domain_rul
goto errout;
}
memset(set_rule_list, 0, sizeof(struct dns_domain_set_rule_list));
INIT_LIST_HEAD(&set_rule_list->domain_ruls_list);
INIT_LIST_HEAD(&set_rule_list->domain_rule_list);
safe_strncpy(set_rule_list->domain_set, set_name, DNS_MAX_CNAME_LEN);
hash_add(dns_domain_set_rule_table.rule_list, &set_rule_list->node, key);
}
list_add_tail(&set_rule->list, &set_rule_list->domain_ruls_list);
list_add_tail(&set_rule->list, &set_rule_list->domain_rule_list);
return 0;
errout:
if (set_rule) {
@@ -717,7 +717,7 @@ errout:
return -1;
}
static int _config_domian_set_rule_flags(const char *set_name, unsigned int flags, int is_clear_flag)
static int _config_domain_set_rule_flags(const char *set_name, unsigned int flags, int is_clear_flag)
{
return _config_domain_set_rule_add_ext(set_name, DOMAIN_RULE_FLAGS, NULL, flags, is_clear_flag);
}
@@ -790,7 +790,7 @@ errout:
free(add_domain_rule);
}
tlog(TLOG_ERROR, "add doamin %s rule failed", domain);
tlog(TLOG_ERROR, "add domain %s rule failed", domain);
return -1;
}
@@ -805,7 +805,7 @@ static int _config_domain_rule_flag_set(const char *domain, unsigned int flag, u
int len = 0;
if (strncmp(domain, "domain-set:", sizeof("domain-set:") - 1) == 0) {
return _config_domian_set_rule_flags(domain + sizeof("domain-set:") - 1, flag, is_clear);
return _config_domain_set_rule_flags(domain + sizeof("domain-set:") - 1, flag, is_clear);
}
len = strlen(domain);
@@ -858,7 +858,7 @@ errout:
free(add_domain_rule);
}
tlog(TLOG_ERROR, "add doamin %s rule failed", domain);
tlog(TLOG_ERROR, "add domain %s rule failed", domain);
return 0;
}
@@ -959,6 +959,7 @@ static int _conf_domain_rule_ipset(char *domain, const char *ipsetname)
goto errout;
}
_dns_rule_put(&ipset_rule->head);
ipset_rule = NULL;
}
goto clear;
@@ -1853,7 +1854,7 @@ static void _config_domain_set_rule_table_destroy(void)
hash_for_each_safe(dns_domain_set_rule_table.rule_list, i, tmp, set_rule_list, node)
{
hlist_del_init(&set_rule_list->node);
list_for_each_entry_safe(set_rule, tmp1, &set_rule_list->domain_ruls_list, list)
list_for_each_entry_safe(set_rule, tmp1, &set_rule_list->domain_rule_list, list)
{
list_del(&set_rule->list);
if (set_rule->rule) {
@@ -2678,7 +2679,7 @@ static struct config_item _config_item[] = {
CONF_YESNO("debug-save-fail-packet", &dns_save_fail_packet),
CONF_STRING("resolv-file", (char *)&dns_resolv_file, sizeof(dns_resolv_file)),
CONF_STRING("debug-save-fail-packet-dir", (char *)&dns_save_fail_packet_dir, sizeof(dns_save_fail_packet_dir)),
CONF_CUSTOM("conf-file", config_addtional_file, NULL),
CONF_CUSTOM("conf-file", config_additional_file, NULL),
CONF_END(),
};
@@ -2699,7 +2700,7 @@ static int _conf_printf(const char *file, int lineno, int ret)
return 0;
}
int config_addtional_file(void *data, int argc, char *argv[])
int config_additional_file(void *data, int argc, char *argv[])
{
char *conf_file = NULL;
char file_path[DNS_MAX_PATH];
@@ -2763,7 +2764,7 @@ static int _update_domain_set_from_list(const char *file, struct dns_domain_set_
continue;
}
list_for_each_entry(set_rule, &set_rule_list->domain_ruls_list, list)
list_for_each_entry(set_rule, &set_rule_list->domain_rule_list, list)
{
if (set_rule->type == DOMAIN_RULE_FLAGS) {
ret = _config_domain_rule_flag_set(domain, set_rule->flags, set_rule->is_clear_flag);
@@ -2900,7 +2901,7 @@ static int _dns_ping_cap_check(void)
has_ping = has_unprivileged_ping();
if (has_ping == 0) {
if (errno == EACCES && has_raw_cap == 0) {
tlog(TLOG_WARN, "unpriviledged ping is disabled, please enable by setting net.ipv4.ping_group_range");
tlog(TLOG_WARN, "unprivileged ping is disabled, please enable by setting net.ipv4.ping_group_range");
}
}

View File

@@ -49,7 +49,7 @@ extern "C" {
#define DNS_NAX_GROUP_NUMBER 16
#define DNS_MAX_IPLEN 64
#define DNS_PROXY_MAX_LEN 128
#define DNS_CONF_USRNAME_LEN 32
#define DNS_CONF_USERNAME_LEN 32
#define DNS_MAX_SPKI_LEN 64
#define DNS_MAX_URL_LEN 256
#define DNS_MAX_PATH 1024
@@ -120,7 +120,6 @@ typedef enum {
struct dns_rule {
atomic_t refcnt;
enum domain_rule rule;
char rule_data[];
};
struct dns_rule_flags {
@@ -332,7 +331,7 @@ struct dns_domain_set_rule {
struct dns_domain_set_rule_list {
struct hlist_node node;
char domain_set[DNS_MAX_CNAME_LEN];
struct list_head domain_ruls_list;
struct list_head domain_rule_list;
};
struct dns_domain_set_rule_table {
@@ -430,7 +429,7 @@ extern int dns_conf_local_ttl;
extern int dns_conf_force_no_cname;
extern char dns_conf_user[DNS_CONF_USRNAME_LEN];
extern char dns_conf_user[DNS_CONF_USERNAME_LEN];
extern struct dns_edns_client_subnet dns_conf_ipv4_ecs;
extern struct dns_edns_client_subnet dns_conf_ipv6_ecs;
@@ -449,7 +448,7 @@ int dns_server_check_update_hosts(void);
struct dns_proxy_names *dns_server_get_proxy_nams(const char *proxyname);
extern int config_addtional_file(void *data, int argc, char *argv[]);
extern int config_additional_file(void *data, int argc, char *argv[]);
#ifdef __cpluscplus
}
#endif

View File

@@ -60,7 +60,7 @@
#define SOCKET_IP_TOS (IPTOS_LOWDELAY | IPTOS_RELIABILITY)
#define SOCKET_PRIORITY (6)
#define CACHE_AUTO_ENABLE_SIZE (1024 * 1024 * 128)
#define EXPIRED_DOMAIN_PREFTCH_TIME (3600 * 8)
#define EXPIRED_DOMAIN_PREFETCH_TIME (3600 * 8)
#define DNS_MAX_DOMAIN_REFETCH_NUM 16
#define RECV_ERROR_AGAIN 1
@@ -279,10 +279,10 @@ static int _dns_server_get_answer(struct dns_server_post_context *context);
static void _dns_server_request_get(struct dns_request *request);
static void _dns_server_request_release(struct dns_request *request);
static void _dns_server_request_release_complete(struct dns_request *request, int do_complete);
static int _dns_server_reply_passthrouth(struct dns_server_post_context *context);
static int _dns_server_reply_passthrough(struct dns_server_post_context *context);
static int _dns_server_do_query(struct dns_request *request, int skip_notify_event);
static void _dns_server_wakup_thread(void)
static void _dns_server_wakeup_thread(void)
{
uint64_t u = 1;
int unused __attribute__((unused));
@@ -342,7 +342,7 @@ static void *_dns_server_get_dns_rule(struct dns_request *request, enum domain_r
return request->domain_rule.rules[rule];
}
static int _dns_server_is_dns_rule_extact_match(struct dns_request *request, enum domain_rule rule)
static int _dns_server_is_dns_rule_extract_match(struct dns_request *request, enum domain_rule rule)
{
if (rule >= DOMAIN_RULE_MAX || request == NULL) {
return 0;
@@ -604,7 +604,7 @@ static void _dns_server_audit_log(struct dns_server_post_context *context)
}
}
gethost_by_addr(req_host, sizeof(req_host), &request->addr);
get_host_by_addr(req_host, sizeof(req_host), &request->addr);
tlog_localtime(&tm);
if (req_host[0] == '\0') {
@@ -1595,7 +1595,7 @@ static int _dns_request_post(struct dns_server_post_context *context)
ret = _dns_reply_inpacket(request, context->inpacket, context->inpacket_len);
if (ret != 0) {
tlog(TLOG_WARN, "replay raw packet to client failed.");
tlog(TLOG_WARN, "reply raw packet to client failed.");
return -1;
}
@@ -1660,7 +1660,7 @@ static int _dns_server_reply_all_pending_list(struct dns_request *request, struc
context_pending.do_force_soa = context->do_force_soa;
context_pending.do_ipset = 0;
context_pending.reply_ttl = request->ip_ttl;
_dns_server_reply_passthrouth(&context_pending);
_dns_server_reply_passthrough(&context_pending);
req->request_pending_list = NULL;
list_del_init(&req->pending_list);
@@ -1707,7 +1707,7 @@ static int _dns_server_force_dualstack(struct dns_request *request)
}
/* if ipv4 is fasting than ipv6, add ipv4 to cache, and return SOA for AAAA request */
tlog(TLOG_INFO, "result: %s, qtype: %d, force %s perfered, id: %d, time1: %d, time2: %d", request->domain,
tlog(TLOG_INFO, "result: %s, qtype: %d, force %s preferred, id: %d, time1: %d, time2: %d", request->domain,
request->qtype, request->qtype == DNS_T_AAAA ? "IPv4" : "IPv6", request->id, request->ping_time,
request->dualstack_selection_ping_time);
request->dualstack_selection_force_soa = 1;
@@ -1718,7 +1718,7 @@ static int _dns_server_force_dualstack(struct dns_request *request)
static int _dns_server_request_complete_with_all_IPs(struct dns_request *request, int with_all_ips)
{
int ttl = 0;
int reply_ttl = ttl;
int reply_ttl = 0;
if (request->rcode == DNS_RC_SERVFAIL || request->rcode == DNS_RC_NXDOMAIN) {
ttl = DNS_SERVER_FAIL_TTL;
@@ -1838,7 +1838,7 @@ static int _dns_ip_address_check_add(struct dns_request *request, char *cname, u
addr_map = malloc(sizeof(*addr_map));
if (addr_map == NULL) {
pthread_mutex_unlock(&request->ip_map_lock);
tlog(TLOG_ERROR, "malloc addrmap failed");
tlog(TLOG_ERROR, "malloc addr map failed");
return -1;
}
memset(addr_map, 0, sizeof(*addr_map));
@@ -2389,7 +2389,7 @@ static int _dns_server_ip_rule_check(struct dns_request *request, unsigned char
goto rule_not_found;
}
/* bogux-nxdomain */
/* bogus-nxdomain */
rule = node->data;
if (rule->bogus) {
goto match;
@@ -2507,7 +2507,7 @@ static int _dns_server_process_answer_A(struct dns_rrs *rrs, struct dns_request
}
}
/* add this ip to reqeust */
/* add this ip to request */
if (_dns_ip_address_check_add(request, cname, addr, DNS_T_A) != 0) {
_dns_server_request_release(request);
return -1;
@@ -2584,7 +2584,7 @@ static int _dns_server_process_answer_AAAA(struct dns_rrs *rrs, struct dns_reque
}
}
/* add this ip to reqeust */
/* add this ip to request */
if (_dns_ip_address_check_add(request, cname, addr, DNS_T_AAAA) != 0) {
_dns_server_request_release(request);
return -1;
@@ -2871,7 +2871,7 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)
}
memcpy(request->ip_addr, addr, DNS_RR_A_LEN);
/* add this ip to reqeust */
/* add this ip to request */
request->ip_ttl = _dns_server_get_conf_ttl(ttl);
request->has_ip = 1;
request->rcode = packet->head.rcode;
@@ -2951,7 +2951,7 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)
return 0;
}
static int _dns_server_reply_passthrouth(struct dns_server_post_context *context)
static int _dns_server_reply_passthrough(struct dns_server_post_context *context)
{
struct dns_request *request = context->request;
@@ -3106,7 +3106,7 @@ static int dns_server_resolve_callback(const char *domain, dns_result_type rtype
context.do_reply = 1;
context.do_ipset = 1;
context.reply_ttl = ttl;
return _dns_server_reply_passthrouth(&context);
return _dns_server_reply_passthrough(&context);
}
if (request->prefetch == 0 && dns_conf_response_mode == DNS_RESPONSE_MODE_FASTEST_RESPONSE &&
@@ -3123,7 +3123,7 @@ static int dns_server_resolve_callback(const char *domain, dns_result_type rtype
context.reply_ttl = 2;
context.cache_ttl = 2;
context.no_check_add_ip = 1;
_dns_server_reply_passthrouth(&context);
_dns_server_reply_passthrough(&context);
request->cname[0] = 0;
request->has_ip = 0;
request->has_cname = 0;
@@ -3622,7 +3622,7 @@ static int _dns_server_pre_process_rule_flags(struct dns_request *request)
switch (request->qtype) {
case DNS_T_A:
if (flags & DOMAIN_FLAG_ADDR_IPV4_IGN) {
/* ignore this domain for A reqeust */
/* ignore this domain for A request */
goto out;
}
@@ -3633,7 +3633,7 @@ static int _dns_server_pre_process_rule_flags(struct dns_request *request)
break;
case DNS_T_AAAA:
if (flags & DOMAIN_FLAG_ADDR_IPV6_IGN) {
/* ignore this domain for A reqeust */
/* ignore this domain for A request */
goto out;
}
@@ -3840,7 +3840,7 @@ static int _dns_server_process_cache_packet(struct dns_request *request, struct
context.do_reply = 1;
context.reply_ttl = _dns_server_get_expired_ttl_reply(dns_cache);
return _dns_server_reply_passthrouth(&context);
return _dns_server_reply_passthrough(&context);
}
static int _dns_server_process_cache_data(struct dns_request *request, struct dns_cache *dns_cache)
@@ -3926,7 +3926,7 @@ static int _dns_server_process_cache(struct dns_request *request)
if ((dualstack_dns_cache->info.speed + (dns_conf_dualstack_ip_selection_threshold * 10)) <
dns_cache->info.speed ||
dns_cache->info.speed < 0) {
tlog(TLOG_DEBUG, "cache result: %s, qtype: %d, force %s perfered, id: %d, time1: %d, time2: %d",
tlog(TLOG_DEBUG, "cache result: %s, qtype: %d, force %s preferred, id: %d, time1: %d, time2: %d",
request->domain, request->qtype, request->qtype == DNS_T_AAAA ? "IPv4" : "IPv6", request->id,
dns_cache->info.speed, dualstack_dns_cache->info.speed);
ret = _dns_server_reply_SOA(DNS_RC_NOERROR, request);
@@ -4095,7 +4095,7 @@ static int _dns_server_process_smartdns_domain(struct dns_request *request)
return -1;
}
if (_dns_server_is_dns_rule_extact_match(request, DOMAIN_RULE_FLAGS) == 0) {
if (_dns_server_is_dns_rule_extract_match(request, DOMAIN_RULE_FLAGS) == 0) {
return -1;
}
@@ -4133,7 +4133,7 @@ static int _dns_server_process_special_query(struct dns_request *request)
break;
default:
tlog(TLOG_DEBUG, "unsupport qtype: %d, domain: %s", request->qtype, request->domain);
tlog(TLOG_DEBUG, "unsupported qtype: %d, domain: %s", request->qtype, request->domain);
request->passthrough = 1;
/* pass request to upstream server */
break;
@@ -4390,7 +4390,7 @@ static int _dns_server_do_query(struct dns_request *request, int skip_notify_eve
pthread_mutex_lock(&server.request_list_lock);
if (list_empty(&server.request_list) && skip_notify_event == 1) {
_dns_server_wakup_thread();
_dns_server_wakeup_thread();
}
list_add_tail(&request->list, &server.request_list);
pthread_mutex_unlock(&server.request_list_lock);
@@ -4501,7 +4501,7 @@ static int _dns_server_recv(struct dns_server_conn_head *conn, unsigned char *in
/* decode packet */
tlog(TLOG_DEBUG, "recv query packet from %s, len = %d, type = %d",
gethost_by_addr(name, sizeof(name), (struct sockaddr *)from), inpacket_len, conn->type);
get_host_by_addr(name, sizeof(name), (struct sockaddr *)from), inpacket_len, conn->type);
decode_len = dns_decode(packet, DNS_PACKSIZE, inpacket, inpacket_len);
if (decode_len < 0) {
tlog(TLOG_DEBUG, "decode failed.\n");
@@ -4535,7 +4535,7 @@ static int _dns_server_recv(struct dns_server_conn_head *conn, unsigned char *in
goto errout;
}
tlog(TLOG_INFO, "query server %s from %s, qtype = %d\n", request->domain, name, request->qtype);
tlog(TLOG_INFO, "query server %s from %s, qtype: %d\n", request->domain, name, request->qtype);
ret = _dns_server_do_query(request, 1);
if (ret != 0) {
@@ -4737,7 +4737,7 @@ static int _dns_server_tcp_accept(struct dns_server_conn_tcp_server *tcpserver,
return -1;
}
if (getsocknet_inet(tcpclient->head.fd, (struct sockaddr *)&tcpclient->localaddr, &tcpclient->localaddr_len) != 0) {
if (getsocket_inet(tcpclient->head.fd, (struct sockaddr *)&tcpclient->localaddr, &tcpclient->localaddr_len) != 0) {
tlog(TLOG_ERROR, "get local addr failed, %s", strerror(errno));
goto errout;
}
@@ -4952,13 +4952,13 @@ static int _dns_server_process(struct dns_server_conn_head *conn, struct epoll_e
if (ret != 0) {
char name[DNS_MAX_CNAME_LEN];
tlog(TLOG_DEBUG, "process TCP packet from %s failed.",
gethost_by_addr(name, sizeof(name), (struct sockaddr *)&tcpclient->addr));
get_host_by_addr(name, sizeof(name), (struct sockaddr *)&tcpclient->addr));
}
} else if (conn->type == DNS_CONN_TYPE_TLS_SERVER) {
tlog(TLOG_ERROR, "unsupport dns server type %d", conn->type);
tlog(TLOG_ERROR, "unsupported dns server type %d", conn->type);
ret = -1;
} else {
tlog(TLOG_ERROR, "unsupport dns server type %d", conn->type);
tlog(TLOG_ERROR, "unsupported dns server type %d", conn->type);
ret = -1;
}
_dns_server_conn_release(conn);
@@ -5104,8 +5104,8 @@ static void _dns_server_period_run_second(void)
if (prefetch_time == 0) {
prefetch_time = dns_conf_serve_expired_ttl / 2;
if (prefetch_time == 0 || prefetch_time > EXPIRED_DOMAIN_PREFTCH_TIME) {
prefetch_time = EXPIRED_DOMAIN_PREFTCH_TIME;
if (prefetch_time == 0 || prefetch_time > EXPIRED_DOMAIN_PREFETCH_TIME) {
prefetch_time = EXPIRED_DOMAIN_PREFETCH_TIME;
}
}
dns_cache_invalidate(NULL, 0, DNS_MAX_DOMAIN_REFETCH_NUM, _dns_server_prefetch_expired_domain,
@@ -5395,7 +5395,7 @@ static int _dns_create_socket(const char *host_ip, int type)
safe_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
ioctl(fd, SIOCGIFINDEX, &ifr);
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(struct ifreq)) < 0) {
tlog(TLOG_ERROR, "bind socket to device %s faild, %s\n", ifr.ifr_name, strerror(errno));
tlog(TLOG_ERROR, "bind socket to device %s failed, %s\n", ifr.ifr_name, strerror(errno));
goto errout;
}
}
@@ -5717,7 +5717,7 @@ errout:
void dns_server_stop(void)
{
atomic_set(&server.run, 0);
_dns_server_wakup_thread();
_dns_server_wakeup_thread();
}
void dns_server_exit(void)

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -63,8 +63,8 @@ struct ping_dns_head {
unsigned short flag;
unsigned short qdcount;
unsigned short ancount;
unsigned short aucount;
unsigned short adcount;
unsigned short nscount;
unsigned short nrcount;
char qd_name;
unsigned short q_qtype;
unsigned short q_qclass;
@@ -171,7 +171,7 @@ static int bool_print_log = 1;
static void _fast_ping_host_put(struct ping_host_struct *ping_host);
static void _fast_ping_wakup_thread(void)
static void _fast_ping_wakeup_thread(void)
{
uint64_t u = 1;
int unused __attribute__((unused));
@@ -534,7 +534,7 @@ static int _fast_ping_sendping_v6(struct ping_host_struct *ping_host)
char ping_host_name[PING_MAX_HOSTLEN];
tlog(TLOG_ERROR, "sendto %s, id %d, %s",
gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
ping_host->sid, strerror(err));
goto errout;
}
@@ -574,7 +574,7 @@ static int _fast_ping_sendping_v4(struct ping_host_struct *ping_host)
}
char ping_host_name[PING_MAX_HOSTLEN];
tlog(TLOG_ERROR, "sendto %s, id %d, %s",
gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
ping_host->sid, strerror(err));
goto errout;
}
@@ -626,7 +626,7 @@ static int _fast_ping_sendping_udp(struct ping_host_struct *ping_host)
}
char ping_host_name[PING_MAX_HOSTLEN];
tlog(TLOG_ERROR, "sendto %s, id %d, %s",
gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
ping_host->sid, strerror(err));
goto errout;
}
@@ -680,7 +680,7 @@ static int _fast_ping_sendping_tcp(struct ping_host_struct *ping_host)
}
tlog(TLOG_ERROR, "connect %s, id %d, %s",
gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
ping_host->sid, strerror(errno));
goto errout;
}
@@ -1205,7 +1205,7 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
pthread_mutex_lock(&ping.map_lock);
_fast_ping_host_get(ping_host);
if (hash_empty(ping.addrmap)) {
_fast_ping_wakup_thread();
_fast_ping_wakeup_thread();
}
hash_add(ping.addrmap, &ping_host->addr_node, addrkey);
ping_host->run = 1;
@@ -1326,7 +1326,7 @@ static struct fast_ping_packet *_fast_ping_icmp_packet(struct ping_host_struct *
if (ping.no_unprivileged_ping) {
if (ip->ip_p != IPPROTO_ICMP) {
tlog(TLOG_ERROR, "ip type faild, %d:%d", ip->ip_p, IPPROTO_ICMP);
tlog(TLOG_ERROR, "ip type failed, %d:%d", ip->ip_p, IPPROTO_ICMP);
return NULL;
}
@@ -1407,7 +1407,7 @@ static int _fast_ping_process_icmp(struct ping_host_struct *ping_host, struct ti
}
tlog(TLOG_DEBUG, "recv ping packet from %s failed.",
gethost_by_addr(name, sizeof(name), (struct sockaddr *)&from));
get_host_by_addr(name, sizeof(name), (struct sockaddr *)&from));
goto errout;
}
@@ -1899,7 +1899,7 @@ int fast_ping_init(void)
ret = pthread_create(&ping.notify_tid, &attr, _fast_ping_notify_worker, NULL);
if (ret != 0) {
tlog(TLOG_ERROR, "create ping notifyer work thread failed, %s\n", strerror(ret));
tlog(TLOG_ERROR, "create ping notifier work thread failed, %s\n", strerror(ret));
goto errout;
}
@@ -1923,7 +1923,7 @@ errout:
if (ping.tid) {
void *retval = NULL;
atomic_set(&ping.run, 0);
_fast_ping_wakup_thread();
_fast_ping_wakeup_thread();
pthread_join(ping.tid, &retval);
ping.tid = 0;
}
@@ -1982,7 +1982,7 @@ void fast_ping_exit(void)
if (ping.tid) {
void *ret = NULL;
atomic_set(&ping.run, 0);
_fast_ping_wakup_thread();
_fast_ping_wakeup_thread();
pthread_join(ping.tid, &ret);
ping.tid = 0;
}

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1090,7 +1090,7 @@ void art_substring_walk(const art_tree *t, const unsigned char *str, int str_len
// Check if the expanded path matches
if (!str_prefix_matches((art_leaf*)n, str, str_len)) {
found = (art_leaf*)n;
stop_search = func(found->key, found->key_len, found->key_len != (uint32_t)str_len, found->value, arg);
func(found->key, found->key_len, found->key_len != (uint32_t)str_len, found->value, arg);
}
break;
}

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
* find_next_and_bit. The differences are:
* - The "invert" argument, which is XORed with each fetched word before
* searching it for one bits.
* - The optional "addr2", which is anded with "addr1" if present.
* - The optional "addr2", which is addr2 with "addr1" if present.
*/
static inline unsigned long _find_next_bit(const unsigned long *addr1,
const unsigned long *addr2, unsigned long nbits,

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2022 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -89,7 +89,9 @@ static int _nftset_addattr(struct nlmsghdr *n, int maxlen, __u16 type, const voi
void *rta_data = RTA_DATA(attr);
memcpy(rta_data, data, alen);
if ((data != NULL) && (alen > 0)) {
memcpy(rta_data, data, alen);
}
memset((uint8_t *)rta_data + alen, 0, RTA_ALIGN(len) - len);
n->nlmsg_len = newlen;
@@ -202,7 +204,6 @@ static int _nftset_socket_request(void *msg, int msg_len, void *ret_msg, int ret
int ret = -1;
struct pollfd pfds;
int do_recv = 0;
int last_errno = 0;
int len = 0;
if (_nftset_socket_init() != 0) {
@@ -260,10 +261,6 @@ static int _nftset_socket_request(void *msg, int msg_len, void *ret_msg, int ret
break;
}
if (errno == EAGAIN && last_errno != 0) {
errno = last_errno;
}
return -1;
}
@@ -275,7 +272,6 @@ static int _nftset_socket_request(void *msg, int msg_len, void *ret_msg, int ret
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nlh);
if (err->error != 0) {
errno = -err->error;
last_errno = errno;
return -1;
}

View File

@@ -436,8 +436,10 @@ radix_node_t
node->parent = new_node;
} else {
if ((glue = malloc(sizeof(*glue))) == NULL)
if ((glue = malloc(sizeof(*glue))) == NULL) {
free(new_node);
return (NULL);
}
memset(glue, '\0', sizeof(*glue));
glue->bit = differ_bit;
glue->prefix = NULL;

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*************************************************************************
*
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -149,7 +149,7 @@ static struct addrinfo *_proxy_getaddr(const char *host, int port, int type, int
ret = getaddrinfo(host, port_str, &hints, &result);
if (ret != 0) {
tlog(TLOG_ERROR, "get addr info failed. %s\n", gai_strerror(ret));
tlog(TLOG_ERROR, "host = %s, port = %d, type = %d, protocol = %d", host, port, type, protocol);
tlog(TLOG_ERROR, "host: %s, port: %d, type: %d, protocol: %d", host, port, type, protocol);
goto errout;
}
@@ -391,7 +391,7 @@ static proxy_handshake_state _proxy_handshake_socks5_reply_connect_addr(struct p
int len = 0;
memset(buff, 0, sizeof(buff));
struct sockaddr_storage addr;
char *ptr = buff;
char *ptr = NULL;
socklen_t addr_len = sizeof(addr);
buff[0] = PROXY_SOCKS5_VERSION;
@@ -477,7 +477,7 @@ static proxy_handshake_state _proxy_handshake_socks5_send_auth(struct proxy_conn
offset += buff[offset] + 1;
len = send(proxy_conn->fd, buff, offset, MSG_NOSIGNAL);
if (len != offset) {
tlog(TLOG_ERROR, "send auth failed, len = %d, errno = %s", len, strerror(errno));
tlog(TLOG_ERROR, "send auth failed, len: %d, %s", len, strerror(errno));
return PROXY_HANDSHAKE_ERR;
}
@@ -499,7 +499,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
buff[3] = PROXY_SOCKS5_AUTH_USER_PASS;
len = send(proxy_conn->fd, buff, 4, MSG_NOSIGNAL);
if (len != 4) {
tlog(TLOG_ERROR, "init socks5 failed, errno = %s", strerror(errno));
tlog(TLOG_ERROR, "init socks5 failed, %s", strerror(errno));
return PROXY_HANDSHAKE_ERR;
}
@@ -514,7 +514,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
return PROXY_HANDSHAKE_WANT_READ;
}
tlog(TLOG_ERROR, "recv socks5 init ack failed, errno = %s", strerror(errno));
tlog(TLOG_ERROR, "recv socks5 init ack failed, %s", strerror(errno));
return PROXY_HANDSHAKE_ERR;
}
@@ -524,23 +524,23 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
}
if (proxy_conn->buffer.len > 2) {
tlog(TLOG_ERROR, "recv socks5 init ack failed, len = %d", len);
tlog(TLOG_ERROR, "recv socks5 init ack failed");
return PROXY_HANDSHAKE_ERR;
}
proxy_conn->buffer.len = 0;
if (proxy_conn->buffer.buffer[0] != PROXY_SOCKS5_VERSION) {
tlog(TLOG_ERROR, "Server not support socks5");
tlog(TLOG_ERROR, "server not support socks5");
return PROXY_HANDSHAKE_ERR;
}
if ((unsigned char)proxy_conn->buffer.buffer[1] == PROXY_SOCKS5_AUTH_NONE) {
tlog(TLOG_ERROR, "Server not support auth methods");
tlog(TLOG_ERROR, "server not support auth methods");
return PROXY_HANDSHAKE_ERR;
}
tlog(TLOG_INFO, "Server select auth method is %d", proxy_conn->buffer.buffer[1]);
tlog(TLOG_INFO, "server select auth method is %d", proxy_conn->buffer.buffer[1]);
if (proxy_conn->buffer.buffer[1] == PROXY_SOCKS5_AUTH_USER_PASS) {
return _proxy_handshake_socks5_send_auth(proxy_conn);
}
@@ -549,7 +549,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
return _proxy_handshake_socks5_reply_connect_addr(proxy_conn);
}
tlog(TLOG_ERROR, "Server select invalid auth method %d", proxy_conn->buffer.buffer[1]);
tlog(TLOG_ERROR, "server select invalid auth method %d", proxy_conn->buffer.buffer[1]);
return PROXY_HANDSHAKE_ERR;
break;
case PROXY_CONN_AUTH_ACK:
@@ -560,7 +560,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
return PROXY_HANDSHAKE_WANT_READ;
}
tlog(TLOG_ERROR, "recv socks5 auth ack failed, errno = %s", strerror(errno));
tlog(TLOG_ERROR, "recv socks5 auth ack failed, %s", strerror(errno));
return PROXY_HANDSHAKE_ERR;
}
@@ -570,23 +570,23 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
}
if (proxy_conn->buffer.len != 2) {
tlog(TLOG_ERROR, "recv socks5 auth ack failed, len = %d", len);
tlog(TLOG_ERROR, "recv socks5 auth ack failed");
return PROXY_HANDSHAKE_ERR;
}
proxy_conn->buffer.len = 0;
if (proxy_conn->buffer.buffer[0] != 0x1) {
tlog(TLOG_ERROR, "Server not support socks5");
tlog(TLOG_ERROR, "server not support socks5");
return PROXY_HANDSHAKE_ERR;
}
if (proxy_conn->buffer.buffer[1] != 0x0) {
tlog(TLOG_ERROR, "Server auth failed, code = %d", proxy_conn->buffer.buffer[1]);
tlog(TLOG_ERROR, "server auth failed, incorrect user or password, code: %d", proxy_conn->buffer.buffer[1]);
return PROXY_HANDSHAKE_ERR;
}
tlog(TLOG_INFO, "Server auth success");
tlog(TLOG_INFO, "server auth success");
proxy_conn->state = PROXY_CONN_CONNECTING;
return _proxy_handshake_socks5_reply_connect_addr(proxy_conn);
case PROXY_CONN_CONNECTING: {
@@ -603,7 +603,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
return PROXY_HANDSHAKE_WANT_READ;
}
tlog(TLOG_ERROR, "recv socks5 connect ack failed, errno = %s", strerror(errno));
tlog(TLOG_ERROR, "recv socks5 connect ack failed, %s", strerror(errno));
return PROXY_HANDSHAKE_ERR;
}
@@ -614,16 +614,16 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
recv_buff = proxy_conn->buffer.buffer;
if (recv_buff[0] != PROXY_SOCKS5_VERSION) {
tlog(TLOG_ERROR, "Server not support socks5");
tlog(TLOG_ERROR, "server not support socks5");
return PROXY_HANDSHAKE_ERR;
}
if (recv_buff[1] != 0) {
if ((unsigned char)recv_buff[1] <=
(sizeof(proxy_socks5_status_code) / sizeof(proxy_socks5_status_code[0]))) {
tlog(TLOG_ERROR, "Server replay failed, error code %s", proxy_socks5_status_code[(int)recv_buff[1]]);
tlog(TLOG_ERROR, "server reply failed, error-code: %s", proxy_socks5_status_code[(int)recv_buff[1]]);
} else {
tlog(TLOG_ERROR, "Server replay failed, error code %x", recv_buff[1]);
tlog(TLOG_ERROR, "server reply failed, error-code: %x", recv_buff[1]);
}
return PROXY_HANDSHAKE_ERR;
}
@@ -766,7 +766,7 @@ static int _proxy_handshake_http(struct proxy_conn *proxy_conn)
len = send(proxy_conn->fd, buff, msglen, MSG_NOSIGNAL);
if (len != msglen) {
tlog(TLOG_ERROR, "init https failed, len = %d, errno = %s", len, strerror(errno));
tlog(TLOG_ERROR, "init https failed, len: %d, %s", len, strerror(errno));
goto out;
}
@@ -786,7 +786,7 @@ static int _proxy_handshake_http(struct proxy_conn *proxy_conn)
if (len == 0) {
tlog(TLOG_ERROR, "remote server closed.");
} else {
tlog(TLOG_ERROR, "recv failed, errno = %s", strerror(errno));
tlog(TLOG_ERROR, "recv failed, %s", strerror(errno));
}
goto out;
}

View File

@@ -148,7 +148,7 @@ static void _help(void)
" -p [pid] pid file path, '-' means don't create pid file.\n"
" -S ignore segment fault signal.\n"
" -x verbose screen.\n"
" -v dispaly version.\n"
" -v display version.\n"
" -h show this help message.\n"
"Online help: http://pymumu.github.io/smartdns\n"

View File

@@ -1,6 +1,6 @@
/*
* tinylog
* Copyright (C) 2018-2020 Nick Peng <pymumu@gmail.com>
* Copyright (C) 2018-2023 Nick Peng <pymumu@gmail.com>
* https://github.com/pymumu/tinylog
*/
#ifndef _GNU_SOURCE
@@ -442,7 +442,7 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
log_len++;
}
if (tlog.root->segment_log) {
if (tlog.root->segment_log && log_head != NULL) {
if (len + 1 < maxlen - 1) {
*(buff + len) = '\0';
len++;
@@ -920,14 +920,14 @@ static void _tlog_wait_pid(struct tlog_log *log, int wait_hang)
log->zip_pid = -1;
char gzip_file[PATH_MAX * 2];
/* rename ziped file */
/* rename zipped file */
snprintf(gzip_file, sizeof(gzip_file), "%s/%s.pending.gz", log->logdir, log->logname);
if (_tlog_rename_logfile(log, gzip_file) != 0) {
_tlog_log_unlock(log);
return;
}
/* remove oldes file */
/* remove oldest file */
_tlog_remove_oldlog(log);
_tlog_log_unlock(log);
}
@@ -1090,7 +1090,7 @@ static int _tlog_archive_log_nocompress(struct tlog_log *log)
goto errout;
}
/* remove oldes file */
/* remove oldest file */
_tlog_remove_oldlog(log);
_tlog_log_unlock(log);
@@ -1437,7 +1437,7 @@ static void _tlog_work_write(struct tlog_log *log, int log_len, int log_extlen,
if (log_dropped > 0) {
/* if there is dropped log, record dropped log number */
char dropmsg[TLOG_TMP_LEN];
snprintf(dropmsg, sizeof(dropmsg), "[Totoal Dropped %d Messages]\n", log_dropped);
snprintf(dropmsg, sizeof(dropmsg), "[Total Dropped %d Messages]\n", log_dropped);
log->output_func(log, dropmsg, strnlen(dropmsg, sizeof(dropmsg)));
}
}
@@ -1845,7 +1845,7 @@ int tlog_init(const char *logfile, int maxlogsize, int maxlogcount, int buffsize
struct tlog_log *log = NULL;
if (tlog_format != NULL) {
fprintf(stderr, "tlog already initilized.\n");
fprintf(stderr, "tlog already initialized.\n");
return -1;
}

View File

@@ -52,7 +52,7 @@ struct tlog_time {
/*
multiwrite: enable multi process write mode.
NOTICE: maxlogsize in all prcesses must be same when enable this mode.
NOTICE: maxlogsize in all processes must be same when enable this mode.
*/
#define TLOG_MULTI_WRITE (1 << 2)
@@ -62,7 +62,7 @@ struct tlog_time {
/* enable log to screen */
#define TLOG_SCREEN (1 << 4)
/* enable suppport fork process */
/* enable support fork process */
#define TLOG_SUPPORT_FORK (1 << 5)
struct tlog_loginfo {
@@ -101,10 +101,10 @@ extern tlog_level tlog_getlevel(void);
/* set log file */
extern void tlog_set_logfile(const char *logfile);
/* enalbe log to screen */
/* enable log to screen */
extern void tlog_setlogscreen(int enable);
/* enalbe early log to screen */
/* enable early log to screen */
extern void tlog_set_early_printf(int enable);
/* Get log level in string */
@@ -184,7 +184,7 @@ va_list: args list
*/
extern int tlog_vprintf(tlog_log *log, const char *format, va_list ap);
/* enalbe log to screen */
/* enable log to screen */
extern void tlog_logscreen(tlog_log *log, int enable);
/* register output callback */

View File

@@ -109,7 +109,7 @@ unsigned long get_tick_count(void)
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}
char *gethost_by_addr(char *host, int maxsize, struct sockaddr *addr)
char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr)
{
struct sockaddr_storage *addr_store = (struct sockaddr_storage *)addr;
host[0] = 0;
@@ -173,7 +173,7 @@ errout:
return -1;
}
int getsocknet_inet(int fd, struct sockaddr *addr, socklen_t *addr_len)
int getsocket_inet(int fd, struct sockaddr *addr, socklen_t *addr_len)
{
struct sockaddr_storage addr_store;
socklen_t addr_store_len = sizeof(addr_store);
@@ -602,7 +602,7 @@ static int _ipset_support_timeout(void)
return -1;
}
static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int addr_len, unsigned long timeout,
static int _ipset_operate(const char *ipset_name, const unsigned char addr[], int addr_len, unsigned long timeout,
int operate)
{
struct nlmsghdr *netlink_head = NULL;
@@ -633,7 +633,7 @@ static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int
return -1;
}
if (strlen(ipsetname) >= IPSET_MAXNAMELEN) {
if (strlen(ipset_name) >= IPSET_MAXNAMELEN) {
errno = ENAMETOOLONG;
return -1;
}
@@ -653,7 +653,7 @@ static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int
proto = IPSET_PROTOCOL;
_ipset_add_attr(netlink_head, IPSET_ATTR_PROTOCOL, sizeof(proto), &proto);
_ipset_add_attr(netlink_head, IPSET_ATTR_SETNAME, strlen(ipsetname) + 1, ipsetname);
_ipset_add_attr(netlink_head, IPSET_ATTR_SETNAME, strlen(ipset_name) + 1, ipset_name);
nested[0] = (struct ipset_netlink_attr *)(buffer + NETLINK_ALIGN(netlink_head->nlmsg_len));
netlink_head->nlmsg_len += NETLINK_ALIGN(sizeof(struct ipset_netlink_attr));
@@ -692,14 +692,14 @@ static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int
return rc;
}
int ipset_add(const char *ipsetname, const unsigned char addr[], int addr_len, unsigned long timeout)
int ipset_add(const char *ipset_name, const unsigned char addr[], int addr_len, unsigned long timeout)
{
return _ipset_operate(ipsetname, addr, addr_len, timeout, IPSET_ADD);
return _ipset_operate(ipset_name, addr, addr_len, timeout, IPSET_ADD);
}
int ipset_del(const char *ipsetname, const unsigned char addr[], int addr_len)
int ipset_del(const char *ipset_name, const unsigned char addr[], int addr_len)
{
return _ipset_operate(ipsetname, addr, addr_len, 0, IPSET_DEL);
return _ipset_operate(ipset_name, addr, addr_len, 0, IPSET_DEL);
}
unsigned char *SSL_SHA256(const unsigned char *d, size_t n, unsigned char *md)
@@ -894,7 +894,7 @@ static int parse_extensions(const char *, size_t, char *, const char **);
static int parse_server_name_extension(const char *, size_t, char *, const char **);
/* Parse a TLS packet for the Server Name Indication extension in the client
* hello handshake, returning the first servername found (pointer to static
* hello handshake, returning the first server name found (pointer to static
* array)
*
* Returns:
@@ -1023,7 +1023,7 @@ static int parse_extensions(const char *data, size_t data_len, char *hostname, c
/* Check if it's a server name extension */
if (data[pos] == 0x00 && data[pos + 1] == 0x00) {
/* There can be only one extension of each type, so we break
* our state and move p to beinnging of the extension here */
* our state and move p to beginning of the extension here */
if (pos + 4 + len > data_len) {
return -5;
}
@@ -1276,27 +1276,27 @@ int dns_packet_save(const char *dir, const char *type, const char *from, const v
struct tm *ptm;
struct tm tm;
struct timeval tmval;
struct timeval tm_val;
struct stat sb;
if (stat(dir, &sb) != 0) {
mkdir(dir, 0750);
}
if (gettimeofday(&tmval, NULL) != 0) {
if (gettimeofday(&tm_val, NULL) != 0) {
return -1;
}
ptm = localtime_r(&tmval.tv_sec, &tm);
ptm = localtime_r(&tm_val.tv_sec, &tm);
if (ptm == NULL) {
return -1;
}
ret = snprintf(time_s, sizeof(time_s) - 1, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.3d", ptm->tm_year + 1900,
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tmval.tv_usec / 1000));
ret = snprintf(filename, sizeof(filename) - 1, "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%.1d.packet", dir, type,
ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
(int)(tmval.tv_usec / 100000));
snprintf(time_s, sizeof(time_s) - 1, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.3d", ptm->tm_year + 1900, ptm->tm_mon + 1,
ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tm_val.tv_usec / 1000));
snprintf(filename, sizeof(filename) - 1, "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%.1d.packet", dir, type,
ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
(int)(tm_val.tv_usec / 100000));
data = malloc(PACKET_BUF_SIZE);
if (data == NULL) {

View File

@@ -55,11 +55,11 @@ void bug_ext(const char *file, int line, const char *func, const char *errfmt, .
unsigned long get_tick_count(void);
char *gethost_by_addr(char *host, int maxsize, struct sockaddr *addr);
char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr);
int getaddr_by_host(const char *host, struct sockaddr *addr, socklen_t *addr_len);
int getsocknet_inet(int fd, struct sockaddr *addr, socklen_t *addr_len);
int getsocket_inet(int fd, struct sockaddr *addr, socklen_t *addr_len);
int fill_sockaddr_by_ip(unsigned char *ip, int ip_len, int port, struct sockaddr *addr, socklen_t *addr_len);
@@ -81,9 +81,9 @@ char *to_lower_case(char *output, const char *input, int len);
void print_stack(void);
int ipset_add(const char *ipsetname, const unsigned char addr[], int addr_len, unsigned long timeout);
int ipset_add(const char *ipset_name, const unsigned char addr[], int addr_len, unsigned long timeout);
int ipset_del(const char *ipsetname, const unsigned char addr[], int addr_len);
int ipset_del(const char *ipset_name, const unsigned char addr[], int addr_len);
void SSL_CRYPTO_thread_setup(void);
@@ -98,7 +98,7 @@ int SSL_base64_encode(const void *in, int in_len, char *out);
int create_pid_file(const char *pid_file);
/* Parse a TLS packet for the Server Name Indication extension in the client
* hello handshake, returning the first servername found (pointer to static
* hello handshake, returning the first server name found (pointer to static
* array)
*
* Returns: