Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
835ad1b7
Commit
835ad1b7
authored
Jul 24, 2016
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
services: refactor lease handling and dns along with it
parent
6bbfe4e0
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
58 additions
and
78 deletions
+58
-78
interfaces.inc
src/etc/inc/interfaces.inc
+1
-0
services.inc
src/etc/inc/services.inc
+30
-6
system.inc
src/etc/inc/system.inc
+1
-40
legacy.inc
src/etc/inc/xmlrpc/legacy.inc
+6
-12
rc.bootup
src/etc/rc.bootup
+3
-4
rc.newwanip
src/etc/rc.newwanip
+1
-0
rc.reload_all
src/etc/rc.reload_all
+1
-0
services_dhcp.php
src/www/services_dhcp.php
+6
-7
services_dnsmasq.php
src/www/services_dnsmasq.php
+1
-0
system_advanced_admin.php
src/www/system_advanced_admin.php
+4
-7
system_general.php
src/www/system_general.php
+4
-2
No files found.
src/etc/inc/interfaces.inc
View file @
835ad1b7
...
...
@@ -2952,6 +2952,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
if
(
$interface
==
'lan'
)
{
/* make new hosts file */
system_hosts_generate
();
services_dhcpleases_configure
();
}
if
(
$reloadall
==
true
)
{
...
...
src/etc/inc/services.inc
View file @
835ad1b7
...
...
@@ -386,6 +386,31 @@ function services_dhcpdv6_leasesfile()
return
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
;
}
function
services_dhcpleases_configure
()
{
global
$config
,
$g
;
killbypid
(
'/var/run/dhcpleases.pid'
,
'TERM'
,
true
);
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
])
&&
isset
(
$config
[
'dnsmasq'
][
'regdhcp'
]))
{
mwexec
(
"/bin/mkdir -p
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db"
);
touch
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd.leases"
);
if
(
isvalidpid
(
'/var/run/dhcpleases.pid'
))
{
killbypid
(
'/var/run/dhcpleases.pid'
,
'HUP'
);
}
else
{
mwexecf
(
'/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s'
,
array
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd.leases"
,
$config
[
'system'
][
'domain'
],
'/var/run/dnsmasq.pid'
,
'/etc/hosts'
)
);
}
}
}
function
services_dhcpd_configure
(
$family
=
'all'
,
$blacklist
=
array
())
{
global
$g
;
...
...
@@ -1081,8 +1106,8 @@ function services_dhcpdv6_configure($blacklist = array())
global
$config
,
$g
;
/* kill any running dhcpd */
killbypid
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/run/dhcpdv6.pid"
);
killbypid
(
'/var/run/dhcpleases6.pid'
);
killbypid
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/run/dhcpdv6.pid"
,
'TERM'
,
true
);
killbypid
(
'/var/run/dhcpleases6.pid'
,
'TERM'
,
true
);
/* DHCP enabled on any interfaces? */
if
(
!
is_dhcpv6_server_enabled
())
{
...
...
@@ -1966,7 +1991,7 @@ function services_dnsmasq_configure($dhcp_reload = true)
/* run dnsmasq */
$cmd
=
"/usr/local/sbin/dnsmasq --all-servers
{
$dns_rebind
}
{
$args
}
"
;
mwexec_bg
(
$cmd
);
s
ystem
_dhcpleases_configure
();
s
ervices
_dhcpleases_configure
();
unset
(
$args
);
if
(
file_exists
(
"/var/run/booting"
))
{
...
...
@@ -1978,7 +2003,7 @@ function services_dnsmasq_configure($dhcp_reload = true)
* XXX this is overly convoluted, potentiall
* restarting all of dhcp up to three times ;)
*/
if
(
!
file_exists
(
"/var/run/booting"
)
&&
$dhcp_reload
)
{
if
(
$dhcp_reload
)
{
services_dhcpd_configure
();
}
}
...
...
@@ -1995,7 +2020,6 @@ function services_unbound_configure($dhcp_reload = true)
}
sync_unbound_service
();
system_dhcpleases_configure
();
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"done."
)
.
"
\n
"
;
...
...
@@ -2006,7 +2030,7 @@ function services_unbound_configure($dhcp_reload = true)
* XXX this is overly convoluted, potentially
* restarting all of dhcp up to three times ;)
*/
if
(
!
file_exists
(
"/var/run/booting"
)
&&
$dhcp_reload
)
{
if
(
$dhcp_reload
)
{
services_dhcpd_configure
();
}
}
...
...
src/etc/inc/system.inc
View file @
835ad1b7
...
...
@@ -412,7 +412,7 @@ function system_hosts_generate()
* Do not remove this because dhcpleases monitors with kqueue
* it needs to be * killed before writing to hosts files.
*/
killbypid
(
'/var/run/dhcpleases.pid'
);
killbypid
(
'/var/run/dhcpleases.pid'
,
'TERM'
,
true
);
$fd
=
fopen
(
'/etc/hosts'
,
'w'
);
if
(
!
$fd
)
{
...
...
@@ -426,48 +426,9 @@ function system_hosts_generate()
unbound_hosts_generate
();
}
system_dhcpleases_configure
();
return
0
;
}
function
system_dhcpleases_configure
()
{
global
$config
,
$g
;
/* Start the monitoring process for dynamic dhcpclients. */
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
])
&&
isset
(
$config
[
'dnsmasq'
][
'regdhcp'
]))
{
/* Make sure we do not error out */
mwexec
(
"/bin/mkdir -p
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db"
);
if
(
!
file_exists
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd.leases"
))
{
@
touch
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd.leases"
);
}
if
(
isvalidpid
(
'/var/run/dhcpleases.pid'
))
{
killbypid
(
'/var/run/dhcpleases.pid'
,
'HUP'
);
}
else
{
/* To ensure we do not start multiple instances of dhcpleases, perform some clean-up first. */
killbyname
(
'dhcpleases'
);
@
unlink
(
'/var/run/dhcpleases.pid'
);
if
(
isset
(
$config
[
'unbound'
][
'enable'
]))
{
$dns_pid
=
'unbound.pid'
;
}
else
{
$dns_pid
=
'dnsmasq.pid'
;
}
mwexecf
(
'/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s'
,
array
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd.leases"
,
$config
[
'system'
][
'domain'
],
"/var/run/
{
$dns_pid
}
"
,
'/etc/hosts'
)
);
}
}
else
{
killbypid
(
'/var/run/dhcpleases.pid'
);
}
}
function
system_hostname_configure
()
{
global
$config
;
...
...
src/etc/inc/xmlrpc/legacy.inc
View file @
835ad1b7
...
...
@@ -134,20 +134,14 @@ function filter_configure_xmlrpc()
filter_configure
();
system_routing_configure
();
setup_gateways_monitor
();
relayd_configure
();
openvpn_resync_all
();
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
services_dnsmasq_configure
();
}
elseif
(
isset
(
$config
[
'unbound'
][
'enable'
]))
{
services_unbound_configure
();
}
else
{
# Both calls above run services_dhcpd_configure(), then we just
# need to call it when them are not called to avoid restart dhcpd
# twice, as described on ticket #3797
services_dhcpd_configure
();
}
system_hosts_generate
();
services_dhcpleases_configure
();
local_sync_accounts
();
services_dnsmasq_configure
(
false
);
services_unbound_configure
(
false
);
services_dhcpd_configure
();
relayd_configure
();
openvpn_resync_all
();
return
true
;
}
...
...
src/etc/rc.bootup
View file @
835ad1b7
...
...
@@ -125,7 +125,6 @@ require_once("interfaces.inc");
echo
"."
;
require_once
(
"services.inc"
);
echo
"."
;
echo
"."
;
require_once
(
"system.inc"
);
echo
"."
;
require_once
(
"unbound.inc"
);
...
...
@@ -265,10 +264,10 @@ system_routing_configure();
system_routing_enable
();
/* start dnsmasq service */
services_dnsmasq_configure
();
services_dnsmasq_configure
(
false
);
/* start unbound service */
services_unbound_configure
();
services_unbound_configure
(
false
);
/* Do an initial time sync */
echo
"Starting NTP time client..."
;
...
...
@@ -282,7 +281,7 @@ relayd_configure();
services_dhcpd_configure
();
/* start dhcpleases dhpcp hosts leases program */
s
ystem
_dhcpleases_configure
();
s
ervices
_dhcpleases_configure
();
/* start DHCP relay */
services_dhcrelay_configure
();
...
...
src/etc/rc.newwanip
View file @
835ad1b7
...
...
@@ -141,6 +141,7 @@ if (!empty($bridgetmp)) {
/* make new hosts file */
system_hosts_generate
();
services_dhcpleases_configure
();
/* check tunneled IPv6 interface tracking */
if
(
isset
(
$config
[
'interfaces'
][
$interface
][
'ipaddrv6'
]))
{
...
...
src/etc/rc.reload_all
View file @
835ad1b7
...
...
@@ -49,6 +49,7 @@ system_timezone_configure();
system_firmware_configure
();
system_hostname_configure
();
system_hosts_generate
();
services_dhcpleases_configure
();
system_resolvconf_generate
();
system_routing_enable
();
interfaces_configure
();
...
...
src/www/services_dhcp.php
View file @
835ad1b7
...
...
@@ -110,17 +110,16 @@ function reconfigure_dhcpd()
killbyname
(
"dhcpd"
);
dhcp_clean_leases
();
system_hosts_generate
();
/* dnsmasq_configure calls dhcpd_configure */
/* no need to restart dhcpd twice */
services_dhcpleases_configure
();
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
])
&&
isset
(
$config
[
'dnsmasq'
][
'regdhcpstatic'
]))
{
services_dnsmasq_configure
();
services_dnsmasq_configure
(
false
);
clear_subsystem_dirty
(
'hosts'
);
}
elseif
(
isset
(
$config
[
'unbound'
][
'enable'
])
&&
isset
(
$config
[
'unbound'
][
'regdhcpstatic'
]))
{
services_unbound_configure
();
}
if
(
isset
(
$config
[
'unbound'
][
'enable'
])
&&
isset
(
$config
[
'unbound'
][
'regdhcpstatic'
]))
{
services_unbound_configure
(
false
);
clear_subsystem_dirty
(
'unbound'
);
}
else
{
services_dhcpd_configure
();
}
services_dhcpd_configure
();
clear_subsystem_dirty
(
'staticmaps'
);
}
...
...
src/www/services_dnsmasq.php
View file @
835ad1b7
...
...
@@ -118,6 +118,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
/* Update resolv.conf in case the interface bindings exclude localhost. */
system_resolvconf_generate
();
system_hosts_generate
();
services_dhcpleases_configure
();
services_dnsmasq_configure
();
clear_subsystem_dirty
(
'hosts'
);
header
(
"Location: services_dnsmasq.php"
);
...
...
src/www/system_advanced_admin.php
View file @
835ad1b7
...
...
@@ -232,13 +232,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
system_console_configure
();
system_hosts_generate
();
// Restart DNS in case dns rebinding toggled
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
services_dnsmasq_configure
();
}
elseif
(
isset
(
$config
[
'unbound'
][
'enable'
]))
{
services_unbound_configure
();
}
services_dhcpleases_configure
();
services_dnsmasq_configure
(
false
);
services_unbound_configure
(
false
);
services_dhcpd_configure
();
if
(
$restart_sshd
)
{
configd_run
(
'sshd restart'
,
true
);
...
...
src/www/system_general.php
View file @
835ad1b7
...
...
@@ -245,9 +245,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
prefer_ipv4_or_ipv6
();
system_hostname_configure
();
system_hosts_generate
();
services_dhcpleases_configure
();
system_resolvconf_generate
();
services_dnsmasq_configure
();
services_unbound_configure
();
services_dnsmasq_configure
(
false
);
services_unbound_configure
(
false
);
services_dhcpd_configure
();
system_timezone_configure
();
if
(
$olddnsallowoverride
!=
$config
[
'system'
][
'dnsallowoverride'
])
{
...
...
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