Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
Dnsmasq
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Dnsmasq
Commits
22ce550e
Commit
22ce550e
authored
Jan 22, 2013
by
Simon Kelley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct behaviour for TCP queries to allowed address via banned interface.
parent
30393100
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
20 deletions
+125
-20
CHANGELOG
CHANGELOG
+10
-1
src/dnsmasq.c
src/dnsmasq.c
+43
-19
src/dnsmasq.h
src/dnsmasq.h
+1
-0
src/network.c
src/network.c
+71
-0
No files found.
CHANGELOG
View file @
22ce550e
...
@@ -16,7 +16,16 @@ version 2.66
...
@@ -16,7 +16,16 @@ version 2.66
this idea.
this idea.
Fix crash on startup on Solaris 11. Regression probably
Fix crash on startup on Solaris 11. Regression probably
introduced in 2.61. Thanks to Geoff Johnstone for the patch.
introduced in 2.61. Thanks to Geoff Johnstone for the
patch.
Add code to make behaviour for TCP DNS requests that same
as for UDP requests, when a request arrives for an allowed
address, but via a banned interface. This change is only
active on Linux, since the relevant API is missing (AFAIK)
on other platforms. Many thanks to Tomas Hozza for
spotting the problem, and doing invaluable discovery of
the obscure and undocumented API required for the solution.
version 2.65
version 2.65
...
...
src/dnsmasq.c
View file @
22ce550e
...
@@ -1337,7 +1337,7 @@ static void check_dns_listeners(fd_set *set, time_t now)
...
@@ -1337,7 +1337,7 @@ static void check_dns_listeners(fd_set *set, time_t now)
if
(
listener
->
tcpfd
!=
-
1
&&
FD_ISSET
(
listener
->
tcpfd
,
set
))
if
(
listener
->
tcpfd
!=
-
1
&&
FD_ISSET
(
listener
->
tcpfd
,
set
))
{
{
int
confd
;
int
confd
,
client_ok
=
1
;
struct
irec
*
iface
=
NULL
;
struct
irec
*
iface
=
NULL
;
pid_t
p
;
pid_t
p
;
union
mysockaddr
tcp_addr
;
union
mysockaddr
tcp_addr
;
...
@@ -1348,25 +1348,49 @@ static void check_dns_listeners(fd_set *set, time_t now)
...
@@ -1348,25 +1348,49 @@ static void check_dns_listeners(fd_set *set, time_t now)
if
(
confd
==
-
1
||
if
(
confd
==
-
1
||
getsockname
(
confd
,
(
struct
sockaddr
*
)
&
tcp_addr
,
&
tcp_len
)
==
-
1
)
getsockname
(
confd
,
(
struct
sockaddr
*
)
&
tcp_addr
,
&
tcp_len
)
==
-
1
)
continue
;
continue
;
if
(
option_bool
(
OPT_NOWILD
)
||
option_bool
(
OPT_CLEVERBIN
D
))
if
(
option_bool
(
OPT_NOWIL
D
))
iface
=
listener
->
iface
;
/* May be NULL */
iface
=
listener
->
iface
;
/* May be NULL */
else
else
{
{
/* Check for allowed interfaces when binding the wildcard address:
int
if_index
;
we do this by looking for an interface with the same address as
the local address of the TCP connection, then looking to see if that's
/* In full wildcard mode, need to refresh interface list.
an allowed interface. As a side effect, we get the netmask of the
This happens automagically in CLEVERBIND */
interface too, for localisation. */
if
(
!
option_bool
(
OPT_CLEVERBIND
))
enumerate_interfaces
();
/* interface may be new since startup */
if
(
enumerate_interfaces
())
/* if we can find the arrival interface, check it's one that's allowed */
for
(
iface
=
daemon
->
interfaces
;
iface
;
iface
=
iface
->
next
)
if
((
if_index
=
tcp_interface
(
confd
,
tcp_addr
.
sa
.
sa_family
))
!=
0
)
if
(
sockaddr_isequal
(
&
iface
->
addr
,
&
tcp_addr
))
{
break
;
for
(
iface
=
daemon
->
interfaces
;
iface
;
iface
=
iface
->
next
)
}
if
(
iface
->
index
==
if_index
)
break
;
if
(
!
iface
&&
!
(
option_bool
(
OPT_NOWILD
)
||
option_bool
(
OPT_CLEVERBIND
)))
if
(
!
iface
)
client_ok
=
0
;
}
if
(
option_bool
(
OPT_CLEVERBIND
))
iface
=
listener
->
iface
;
/* May be NULL */
else
{
/* Check for allowed interfaces when binding the wildcard address:
we do this by looking for an interface with the same address as
the local address of the TCP connection, then looking to see if that's
an allowed interface. As a side effect, we get the netmask of the
interface too, for localisation. */
for
(
iface
=
daemon
->
interfaces
;
iface
;
iface
=
iface
->
next
)
if
(
sockaddr_isequal
(
&
iface
->
addr
,
&
tcp_addr
))
break
;
if
(
!
iface
)
client_ok
=
0
;
}
}
if
(
!
client_ok
)
{
{
shutdown
(
confd
,
SHUT_RDWR
);
shutdown
(
confd
,
SHUT_RDWR
);
close
(
confd
);
close
(
confd
);
...
...
src/dnsmasq.h
View file @
22ce550e
...
@@ -1003,6 +1003,7 @@ void create_bound_listeners(int die);
...
@@ -1003,6 +1003,7 @@ void create_bound_listeners(int die);
int
is_dad_listeners
(
void
);
int
is_dad_listeners
(
void
);
int
iface_check
(
int
family
,
struct
all_addr
*
addr
,
char
*
name
,
int
*
auth_dns
);
int
iface_check
(
int
family
,
struct
all_addr
*
addr
,
char
*
name
,
int
*
auth_dns
);
int
fix_fd
(
int
fd
);
int
fix_fd
(
int
fd
);
int
tcp_interface
(
int
fd
,
int
af
);
struct
in_addr
get_ifaddr
(
char
*
intr
);
struct
in_addr
get_ifaddr
(
char
*
intr
);
#ifdef HAVE_IPV6
#ifdef HAVE_IPV6
int
set_ipv6pktinfo
(
int
fd
);
int
set_ipv6pktinfo
(
int
fd
);
...
...
src/network.c
View file @
22ce550e
...
@@ -459,6 +459,77 @@ int set_ipv6pktinfo(int fd)
...
@@ -459,6 +459,77 @@ int set_ipv6pktinfo(int fd)
return
0
;
return
0
;
}
}
#endif
#endif
/* Find the interface on which a TCP connection arrived, if possible, or zero otherwise. */
int
tcp_interface
(
int
fd
,
int
af
)
{
int
if_index
=
0
;
#ifdef HAVE_LINUX_NETWORK
int
opt
=
1
;
struct
cmsghdr
*
cmptr
;
struct
msghdr
msg
;
/* use mshdr do that the CMSDG_* macros are available */
msg
.
msg_control
=
daemon
->
packet
;
msg
.
msg_controllen
=
daemon
->
packet_buff_sz
;
/* we overwrote the buffer... */
daemon
->
srv_save
=
NULL
;
if
(
af
==
AF_INET
)
{
if
(
setsockopt
(
fd
,
IPPROTO_IP
,
IP_PKTINFO
,
&
opt
,
sizeof
(
opt
))
!=
-
1
&&
getsockopt
(
fd
,
IPPROTO_IP
,
IP_PKTOPTIONS
,
msg
.
msg_control
,
(
socklen_t
*
)
&
msg
.
msg_controllen
)
!=
-
1
)
for
(
cmptr
=
CMSG_FIRSTHDR
(
&
msg
);
cmptr
;
cmptr
=
CMSG_NXTHDR
(
&
msg
,
cmptr
))
if
(
cmptr
->
cmsg_level
==
IPPROTO_IP
&&
cmptr
->
cmsg_type
==
IP_PKTINFO
)
{
union
{
unsigned
char
*
c
;
struct
in_pktinfo
*
p
;
}
p
;
p
.
c
=
CMSG_DATA
(
cmptr
);
if_index
=
p
.
p
->
ipi_ifindex
;
}
}
#ifdef HAVE_IPV6
else
{
/* Only the RFC-2292 API has the ability to find the interface for TCP connections,
it was removed in RFC-3542 !!!!
Fortunately, Linux kept the 2292 ABI when it moved to 3542. The following code always
uses the old ABI, and should work with pre- and post-3542 kernel headers */
#ifdef IPV6_2292PKTOPTIONS
# define PKTOPTIONS IPV6_2292PKTOPTIONS
#else
# define PKTOPTIONS IPV6_PKTOPTIONS
#endif
if
(
set_ipv6pktinfo
(
fd
)
&&
getsockopt
(
fd
,
IPPROTO_IPV6
,
PKTOPTIONS
,
msg
.
msg_control
,
(
socklen_t
*
)
&
msg
.
msg_controllen
)
!=
-
1
)
{
for
(
cmptr
=
CMSG_FIRSTHDR
(
&
msg
);
cmptr
;
cmptr
=
CMSG_NXTHDR
(
&
msg
,
cmptr
))
if
(
cmptr
->
cmsg_level
==
IPPROTO_IPV6
&&
cmptr
->
cmsg_type
==
daemon
->
v6pktinfo
)
{
union
{
unsigned
char
*
c
;
struct
in6_pktinfo
*
p
;
}
p
;
p
.
c
=
CMSG_DATA
(
cmptr
);
if_index
=
p
.
p
->
ipi6_ifindex
;
}
}
}
#endif
/* IPV6 */
#endif
/* Linux */
return
if_index
;
}
static
struct
listener
*
create_listeners
(
union
mysockaddr
*
addr
,
int
do_tftp
,
int
dienow
)
static
struct
listener
*
create_listeners
(
union
mysockaddr
*
addr
,
int
do_tftp
,
int
dienow
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment