Skip to content

Commit

Permalink
add service ip to the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kamarya committed Sep 1, 2020
1 parent fe0ab2a commit 99bd533
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dnsd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
# https_proxy=<IP>:<PORT>

# The default server URL is set below.
server_url = https://dns.google.com/
server_url = https://dns.google.com

# The local service port
# The local service ip and port
service_port = 53
service_ip = 127.0.0.1

# EDNS ECS support default is disabled (0)
# to enable change the following line to "enable_edns_ecs=true"
Expand Down
5 changes: 4 additions & 1 deletion inc/dnssec.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Behrooz Kamary Aliabadi
* Copyright (C) 2016 Behrooz Kamary
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -68,6 +68,8 @@
#define OPT_ENABLE_EDNS "enable_edns_ecs"
#define OPT_DEFAULT_URL "https://dns.google.com"
#define OPT_SERVICE_PORT "service_port"
#define OPT_SERVICE_IP "service_ip"
#define OPT_SERVICE_IP_LEN INET6_ADDRSTRLEN
#define OPT_ENABLE_TRUE "true"
#define OPT_ENABLE_FALSE "false"

Expand All @@ -91,6 +93,7 @@ struct func_options
char https_proxy[OPT_HTTPS_PROXY_LEN];
char server_url[OPT_SERVER_URL_LEN];
char server_ip_list[OPT_SERVER_IP_LEN];
char service_ip[OPT_SERVICE_IP_LEN];
uint16_t server_timeout;
uint16_t service_port;
uint8_t enable_debug;
Expand Down
23 changes: 22 additions & 1 deletion src/dnssec.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,19 @@ int server()
server_add.sin_port = htons(options.service_port);
server_add.sin_addr.s_addr = htonl(INADDR_ANY);

LOG_DEBUG("local port (%d)", options.service_port);
if (options.service_ip[0] != '\0')
{
if (inet_pton(AF_INET, options.service_ip, &(server_add.sin_addr)) == 1)
{
LOG_INFO("service ip (%s)", options.service_ip);
}
else
{
LOG_ERROR("invalid service ip (%s)", options.service_ip);
}
}

LOG_DEBUG("service port (%d)", options.service_port);

sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0)
Expand Down Expand Up @@ -811,6 +823,11 @@ int parse_options()
size_t len = 0;
ssize_t read = 0;

options.https_proxy[0] = 0;
options.server_url[0] = 0;
options.server_ip_list[0] = 0;
options.service_ip[0] = 0;

fp = fopen(options.config_file, "r");
if (fp == NULL) return EXIT_FAILURE;

Expand Down Expand Up @@ -845,6 +862,10 @@ int parse_options()
{
options.service_port = atoi(line + sizeof(OPT_SERVICE_PORT));
}
else if (strstr(line, OPT_SERVICE_IP) != NULL)
{
strncpy(options.service_ip, line + sizeof(OPT_SERVICE_IP), OPT_SERVICE_IP_LEN);
}
else if (strstr(line, OPT_ENABLE_EDNS) != NULL)
{
if (strcasestr(line, OPT_ENABLE_TRUE) != NULL) options.enable_edns = 1;
Expand Down

0 comments on commit 99bd533

Please sign in to comment.