mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
- ip_freebind: yesno option in unbound.conf sets IP_FREEBIND for
binding to an IP address while the interface or address is down. git-svn-id: file:///svn/unbound/trunk@3673 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
197a50ea96
commit
9f8b2bb468
12 changed files with 2162 additions and 2088 deletions
|
|
@ -389,7 +389,7 @@ add_open(const char* ip, int nr, struct listen_port** list, int noproto_is_err,
|
|||
|
||||
/* open fd */
|
||||
fd = create_tcp_accept_sock(res, 1, &noproto, 0,
|
||||
cfg->ip_transparent, 0);
|
||||
cfg->ip_transparent, 0, cfg->ip_freebind);
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
15 March 2016: Wouter
|
||||
- ip_freebind: yesno option in unbound.conf sets IP_FREEBIND for
|
||||
binding to an IP address while the interface or address is down.
|
||||
|
||||
14 March 2016: Wouter
|
||||
- Fix warnings in ifdef corner case, older or unknown libevent.
|
||||
- Fix compile for ub_event code with older libev.
|
||||
|
|
|
|||
|
|
@ -96,10 +96,11 @@ verbose_print_addr(struct addrinfo *addr)
|
|||
int
|
||||
create_udp_sock(int family, int socktype, struct sockaddr* addr,
|
||||
socklen_t addrlen, int v6only, int* inuse, int* noproto,
|
||||
int rcv, int snd, int listen, int* reuseport, int transparent)
|
||||
int rcv, int snd, int listen, int* reuseport, int transparent,
|
||||
int freebind)
|
||||
{
|
||||
int s;
|
||||
#if defined(SO_REUSEADDR) || defined(SO_REUSEPORT) || defined(IPV6_USE_MIN_MTU) || defined(IP_TRANSPARENT) || defined(IP_BINDANY)
|
||||
#if defined(SO_REUSEADDR) || defined(SO_REUSEPORT) || defined(IPV6_USE_MIN_MTU) || defined(IP_TRANSPARENT) || defined(IP_BINDANY) || defined(IP_FREEBIND)
|
||||
int on=1;
|
||||
#endif
|
||||
#ifdef IPV6_MTU
|
||||
|
|
@ -116,6 +117,9 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr,
|
|||
#endif
|
||||
#if !defined(IP_TRANSPARENT) && !defined(IP_BINDANY)
|
||||
(void)transparent;
|
||||
#endif
|
||||
#if !defined(IP_FREEBIND)
|
||||
(void)freebind;
|
||||
#endif
|
||||
if((s = socket(family, socktype, 0)) == -1) {
|
||||
*inuse = 0;
|
||||
|
|
@ -180,6 +184,14 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr,
|
|||
#else
|
||||
(void)reuseport;
|
||||
#endif /* defined(SO_REUSEPORT) */
|
||||
#ifdef IP_FREEBIND
|
||||
if (freebind &&
|
||||
setsockopt(s, IPPROTO_IP, IP_FREEBIND, (void*)&on,
|
||||
(socklen_t)sizeof(on)) < 0) {
|
||||
log_warn("setsockopt(.. IP_FREEBIND ..) failed: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
#endif /* IP_FREEBIND */
|
||||
#ifdef IP_TRANSPARENT
|
||||
if (transparent &&
|
||||
setsockopt(s, IPPROTO_IP, IP_TRANSPARENT, (void*)&on,
|
||||
|
|
@ -490,14 +502,17 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr,
|
|||
|
||||
int
|
||||
create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto,
|
||||
int* reuseport, int transparent, int mss)
|
||||
int* reuseport, int transparent, int mss, int freebind)
|
||||
{
|
||||
int s;
|
||||
#if defined(SO_REUSEADDR) || defined(SO_REUSEPORT) || defined(IPV6_V6ONLY) || defined(IP_TRANSPARENT)
|
||||
#if defined(SO_REUSEADDR) || defined(SO_REUSEPORT) || defined(IPV6_V6ONLY) || defined(IP_TRANSPARENT) || defined(IP_FREEBIND)
|
||||
int on = 1;
|
||||
#endif
|
||||
#ifndef IP_TRANSPARENT
|
||||
(void)transparent;
|
||||
#endif
|
||||
#if !defined(IP_FREEBIND)
|
||||
(void)freebind;
|
||||
#endif
|
||||
verbose_print_addr(addr);
|
||||
*noproto = 0;
|
||||
|
|
@ -553,6 +568,13 @@ create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto,
|
|||
return -1;
|
||||
}
|
||||
#endif /* SO_REUSEADDR */
|
||||
#ifdef IP_FREEBIND
|
||||
if (freebind && setsockopt(s, IPPROTO_IP, IP_FREEBIND, (void*)&on,
|
||||
(socklen_t)sizeof(on)) < 0) {
|
||||
log_warn("setsockopt(.. IP_FREEBIND ..) failed: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
#endif /* IP_FREEBIND */
|
||||
#ifdef SO_REUSEPORT
|
||||
/* try to set SO_REUSEPORT so that incoming
|
||||
* connections are distributed evenly among the receiving threads.
|
||||
|
|
@ -704,7 +726,7 @@ create_local_accept_sock(const char *path, int* noproto)
|
|||
static int
|
||||
make_sock(int stype, const char* ifname, const char* port,
|
||||
struct addrinfo *hints, int v6only, int* noip6, size_t rcv, size_t snd,
|
||||
int* reuseport, int transparent, int tcp_mss)
|
||||
int* reuseport, int transparent, int tcp_mss, int freebind)
|
||||
{
|
||||
struct addrinfo *res = NULL;
|
||||
int r, s, inuse, noproto;
|
||||
|
|
@ -732,7 +754,7 @@ make_sock(int stype, const char* ifname, const char* port,
|
|||
s = create_udp_sock(res->ai_family, res->ai_socktype,
|
||||
(struct sockaddr*)res->ai_addr, res->ai_addrlen,
|
||||
v6only, &inuse, &noproto, (int)rcv, (int)snd, 1,
|
||||
reuseport, transparent);
|
||||
reuseport, transparent, freebind);
|
||||
if(s == -1 && inuse) {
|
||||
log_err("bind: address already in use");
|
||||
} else if(s == -1 && noproto && hints->ai_family == AF_INET6){
|
||||
|
|
@ -740,7 +762,7 @@ make_sock(int stype, const char* ifname, const char* port,
|
|||
}
|
||||
} else {
|
||||
s = create_tcp_accept_sock(res, v6only, &noproto, reuseport,
|
||||
transparent, tcp_mss);
|
||||
transparent, tcp_mss, freebind);
|
||||
if(s == -1 && noproto && hints->ai_family == AF_INET6){
|
||||
*noip6 = 1;
|
||||
}
|
||||
|
|
@ -753,7 +775,7 @@ make_sock(int stype, const char* ifname, const char* port,
|
|||
static int
|
||||
make_sock_port(int stype, const char* ifname, const char* port,
|
||||
struct addrinfo *hints, int v6only, int* noip6, size_t rcv, size_t snd,
|
||||
int* reuseport, int transparent, int tcp_mss)
|
||||
int* reuseport, int transparent, int tcp_mss, int freebind)
|
||||
{
|
||||
char* s = strchr(ifname, '@');
|
||||
if(s) {
|
||||
|
|
@ -775,10 +797,10 @@ make_sock_port(int stype, const char* ifname, const char* port,
|
|||
(void)strlcpy(p, s+1, sizeof(p));
|
||||
p[strlen(s+1)]=0;
|
||||
return make_sock(stype, newif, p, hints, v6only, noip6,
|
||||
rcv, snd, reuseport, transparent, tcp_mss);
|
||||
rcv, snd, reuseport, transparent, tcp_mss, freebind);
|
||||
}
|
||||
return make_sock(stype, ifname, port, hints, v6only, noip6, rcv, snd,
|
||||
reuseport, transparent, tcp_mss);
|
||||
reuseport, transparent, tcp_mss, freebind);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -874,13 +896,14 @@ set_recvpktinfo(int s, int family)
|
|||
* set to false on exit if reuseport failed due to no kernel support.
|
||||
* @param transparent: set IP_TRANSPARENT socket option.
|
||||
* @param tcp_mss: maximum segment size of tcp socket. default if zero.
|
||||
* @param freebind: set IP_FREEBIND socket option.
|
||||
* @return: returns false on error.
|
||||
*/
|
||||
static int
|
||||
ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
|
||||
struct addrinfo *hints, const char* port, struct listen_port** list,
|
||||
size_t rcv, size_t snd, int ssl_port, int* reuseport, int transparent,
|
||||
int tcp_mss)
|
||||
int tcp_mss, int freebind)
|
||||
{
|
||||
int s, noip6=0;
|
||||
if(!do_udp && !do_tcp)
|
||||
|
|
@ -888,7 +911,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
|
|||
if(do_auto) {
|
||||
if((s = make_sock_port(SOCK_DGRAM, ifname, port, hints, 1,
|
||||
&noip6, rcv, snd, reuseport, transparent,
|
||||
tcp_mss)) == -1) {
|
||||
tcp_mss, freebind)) == -1) {
|
||||
if(noip6) {
|
||||
log_warn("IPv6 protocol not available");
|
||||
return 1;
|
||||
|
|
@ -916,7 +939,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
|
|||
/* regular udp socket */
|
||||
if((s = make_sock_port(SOCK_DGRAM, ifname, port, hints, 1,
|
||||
&noip6, rcv, snd, reuseport, transparent,
|
||||
tcp_mss)) == -1) {
|
||||
tcp_mss, freebind)) == -1) {
|
||||
if(noip6) {
|
||||
log_warn("IPv6 protocol not available");
|
||||
return 1;
|
||||
|
|
@ -937,7 +960,8 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
|
|||
atoi(strchr(ifname, '@')+1) == ssl_port) ||
|
||||
(!strchr(ifname, '@') && atoi(port) == ssl_port));
|
||||
if((s = make_sock_port(SOCK_STREAM, ifname, port, hints, 1,
|
||||
&noip6, 0, 0, reuseport, transparent, tcp_mss)) == -1) {
|
||||
&noip6, 0, 0, reuseport, transparent, tcp_mss,
|
||||
freebind)) == -1) {
|
||||
if(noip6) {
|
||||
/*log_warn("IPv6 protocol not available");*/
|
||||
return 1;
|
||||
|
|
@ -1095,7 +1119,7 @@ listening_ports_open(struct config_file* cfg, int* reuseport)
|
|||
cfg->so_rcvbuf, cfg->so_sndbuf,
|
||||
cfg->ssl_port, reuseport,
|
||||
cfg->ip_transparent,
|
||||
cfg->tcp_mss)) {
|
||||
cfg->tcp_mss, cfg->ip_freebind)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1108,7 +1132,7 @@ listening_ports_open(struct config_file* cfg, int* reuseport)
|
|||
cfg->so_rcvbuf, cfg->so_sndbuf,
|
||||
cfg->ssl_port, reuseport,
|
||||
cfg->ip_transparent,
|
||||
cfg->tcp_mss)) {
|
||||
cfg->tcp_mss, cfg->ip_freebind)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1123,7 +1147,7 @@ listening_ports_open(struct config_file* cfg, int* reuseport)
|
|||
cfg->so_rcvbuf, cfg->so_sndbuf,
|
||||
cfg->ssl_port, reuseport,
|
||||
cfg->ip_transparent,
|
||||
cfg->tcp_mss)) {
|
||||
cfg->tcp_mss, cfg->ip_freebind)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1136,7 +1160,7 @@ listening_ports_open(struct config_file* cfg, int* reuseport)
|
|||
cfg->so_rcvbuf, cfg->so_sndbuf,
|
||||
cfg->ssl_port, reuseport,
|
||||
cfg->ip_transparent,
|
||||
cfg->tcp_mss)) {
|
||||
cfg->tcp_mss, cfg->ip_freebind)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,11 +190,12 @@ void listen_start_accept(struct listen_dnsport* listen);
|
|||
* @param reuseport: if nonNULL and true, try to set SO_REUSEPORT on
|
||||
* listening UDP port. Set to false on return if it failed to do so.
|
||||
* @param transparent: set IP_TRANSPARENT socket option.
|
||||
* @param freebind: set IP_FREEBIND socket option.
|
||||
* @return: the socket. -1 on error.
|
||||
*/
|
||||
int create_udp_sock(int family, int socktype, struct sockaddr* addr,
|
||||
socklen_t addrlen, int v6only, int* inuse, int* noproto, int rcv,
|
||||
int snd, int listen, int* reuseport, int transparent);
|
||||
int snd, int listen, int* reuseport, int transparent, int freebind);
|
||||
|
||||
/**
|
||||
* Create and bind TCP listening socket
|
||||
|
|
@ -205,10 +206,11 @@ int create_udp_sock(int family, int socktype, struct sockaddr* addr,
|
|||
* listening UDP port. Set to false on return if it failed to do so.
|
||||
* @param transparent: set IP_TRANSPARENT socket option.
|
||||
* @param mss: maximum segment size of the socket. if zero, leaves the default.
|
||||
* @param freebind: set IP_FREEBIND socket option.
|
||||
* @return: the socket. -1 on error.
|
||||
*/
|
||||
int create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto,
|
||||
int* reuseport, int transparent, int mss);
|
||||
int* reuseport, int transparent, int mss, int freebind);
|
||||
|
||||
/**
|
||||
* Create and bind local listening socket
|
||||
|
|
|
|||
|
|
@ -909,13 +909,13 @@ udp_sockport(struct sockaddr_storage* addr, socklen_t addrlen, int port,
|
|||
sa->sin6_port = (in_port_t)htons((uint16_t)port);
|
||||
fd = create_udp_sock(AF_INET6, SOCK_DGRAM,
|
||||
(struct sockaddr*)addr, addrlen, 1, inuse, &noproto,
|
||||
0, 0, 0, NULL, 0);
|
||||
0, 0, 0, NULL, 0, 0);
|
||||
} else {
|
||||
struct sockaddr_in* sa = (struct sockaddr_in*)addr;
|
||||
sa->sin_port = (in_port_t)htons((uint16_t)port);
|
||||
fd = create_udp_sock(AF_INET, SOCK_DGRAM,
|
||||
(struct sockaddr*)addr, addrlen, 1, inuse, &noproto,
|
||||
0, 0, 0, NULL, 0);
|
||||
0, 0, 0, NULL, 0, 0);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ config_create(void)
|
|||
cfg->so_sndbuf = 0;
|
||||
cfg->so_reuseport = 0;
|
||||
cfg->ip_transparent = 0;
|
||||
cfg->ip_freebind = 0;
|
||||
cfg->num_ifs = 0;
|
||||
cfg->ifs = NULL;
|
||||
cfg->num_out_ifs = 0;
|
||||
|
|
@ -393,6 +394,7 @@ int config_set_option(struct config_file* cfg, const char* opt,
|
|||
else S_MEMSIZE("so-sndbuf:", so_sndbuf)
|
||||
else S_YNO("so-reuseport:", so_reuseport)
|
||||
else S_YNO("ip-transparent:", ip_transparent)
|
||||
else S_YNO("ip-freebind:", ip_freebind)
|
||||
else S_MEMSIZE("rrset-cache-size:", rrset_cache_size)
|
||||
else S_POW2("rrset-cache-slabs:", rrset_cache_slabs)
|
||||
else S_YNO("prefetch:", prefetch)
|
||||
|
|
@ -664,6 +666,7 @@ config_get_option(struct config_file* cfg, const char* opt,
|
|||
else O_MEM(opt, "so-sndbuf", so_sndbuf)
|
||||
else O_YNO(opt, "so-reuseport", so_reuseport)
|
||||
else O_YNO(opt, "ip-transparent", ip_transparent)
|
||||
else O_YNO(opt, "ip-freebind", ip_freebind)
|
||||
else O_MEM(opt, "rrset-cache-size", rrset_cache_size)
|
||||
else O_DEC(opt, "rrset-cache-slabs", rrset_cache_slabs)
|
||||
else O_YNO(opt, "prefetch-key", prefetch_key)
|
||||
|
|
|
|||
|
|
@ -142,6 +142,8 @@ struct config_file {
|
|||
int so_reuseport;
|
||||
/** IP_TRANSPARENT socket option requested on port 53 sockets */
|
||||
int ip_transparent;
|
||||
/** IP_FREEBIND socket option request on port 53 sockets */
|
||||
int ip_freebind;
|
||||
|
||||
/** number of interfaces to open. If 0 default all interfaces. */
|
||||
int num_ifs;
|
||||
|
|
|
|||
2778
util/configlexer.c
2778
util/configlexer.c
File diff suppressed because it is too large
Load diff
|
|
@ -234,6 +234,7 @@ so-rcvbuf{COLON} { YDVAR(1, VAR_SO_RCVBUF) }
|
|||
so-sndbuf{COLON} { YDVAR(1, VAR_SO_SNDBUF) }
|
||||
so-reuseport{COLON} { YDVAR(1, VAR_SO_REUSEPORT) }
|
||||
ip-transparent{COLON} { YDVAR(1, VAR_IP_TRANSPARENT) }
|
||||
ip-freebind{COLON} { YDVAR(1, VAR_IP_FREEBIND) }
|
||||
chroot{COLON} { YDVAR(1, VAR_CHROOT) }
|
||||
username{COLON} { YDVAR(1, VAR_USERNAME) }
|
||||
directory{COLON} { YDVAR(1, VAR_DIRECTORY) }
|
||||
|
|
|
|||
1369
util/configparser.c
1369
util/configparser.c
File diff suppressed because it is too large
Load diff
|
|
@ -207,7 +207,8 @@ extern int yydebug;
|
|||
VAR_CAPS_WHITELIST = 417,
|
||||
VAR_CACHE_MAX_NEGATIVE_TTL = 418,
|
||||
VAR_PERMIT_SMALL_HOLDDOWN = 419,
|
||||
VAR_QNAME_MINIMISATION = 420
|
||||
VAR_QNAME_MINIMISATION = 420,
|
||||
VAR_IP_FREEBIND = 421
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
|
|
@ -374,6 +375,7 @@ extern int yydebug;
|
|||
#define VAR_CACHE_MAX_NEGATIVE_TTL 418
|
||||
#define VAR_PERMIT_SMALL_HOLDDOWN 419
|
||||
#define VAR_QNAME_MINIMISATION 420
|
||||
#define VAR_IP_FREEBIND 421
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
|
|
@ -384,7 +386,7 @@ union YYSTYPE
|
|||
|
||||
char* str;
|
||||
|
||||
#line 388 "util/configparser.h" /* yacc.c:1909 */
|
||||
#line 390 "util/configparser.h" /* yacc.c:1909 */
|
||||
};
|
||||
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ extern struct config_parser_state* cfg_parser;
|
|||
%token VAR_RATELIMIT VAR_RATELIMIT_SLABS VAR_RATELIMIT_SIZE
|
||||
%token VAR_RATELIMIT_FOR_DOMAIN VAR_RATELIMIT_BELOW_DOMAIN VAR_RATELIMIT_FACTOR
|
||||
%token VAR_CAPS_WHITELIST VAR_CACHE_MAX_NEGATIVE_TTL VAR_PERMIT_SMALL_HOLDDOWN
|
||||
%token VAR_QNAME_MINIMISATION
|
||||
%token VAR_QNAME_MINIMISATION VAR_IP_FREEBIND
|
||||
|
||||
%%
|
||||
toplevelvars: /* empty */ | toplevelvars toplevelvar ;
|
||||
|
|
@ -191,7 +191,8 @@ content_server: server_num_threads | server_verbosity | server_port |
|
|||
server_ratelimit_size | server_ratelimit_for_domain |
|
||||
server_ratelimit_below_domain | server_ratelimit_factor |
|
||||
server_caps_whitelist | server_cache_max_negative_ttl |
|
||||
server_permit_small_holddown | server_qname_minimisation
|
||||
server_permit_small_holddown | server_qname_minimisation |
|
||||
server_ip_freebind
|
||||
;
|
||||
stubstart: VAR_STUB_ZONE
|
||||
{
|
||||
|
|
@ -662,6 +663,16 @@ server_ip_transparent: VAR_IP_TRANSPARENT STRING_ARG
|
|||
free($2);
|
||||
}
|
||||
;
|
||||
server_ip_freebind: VAR_IP_FREEBIND STRING_ARG
|
||||
{
|
||||
OUTYY(("P(server_ip_freebind:%s)\n", $2));
|
||||
if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0)
|
||||
yyerror("expected yes or no.");
|
||||
else cfg_parser->cfg->ip_freebind =
|
||||
(strcmp($2, "yes")==0);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_edns_buffer_size: VAR_EDNS_BUFFER_SIZE STRING_ARG
|
||||
{
|
||||
OUTYY(("P(server_edns_buffer_size:%s)\n", $2));
|
||||
|
|
|
|||
Loading…
Reference in a new issue