Merge pull request #1000 from freifunk-ffm/christf_dns-config
Add gluon-dns-config: a package that enables the node to be used as DNS cache
This commit is contained in:
		
						commit
						3e7434bca1
					
				
							
								
								
									
										30
									
								
								docs/features/dns-cache.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								docs/features/dns-cache.rst
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | DNS-Caching | ||||||
|  | =========== | ||||||
|  | User experience may be greatly improved when dns is accelerated. Also it | ||||||
|  | seems like a good idea to keep the number if packages being exchanged | ||||||
|  | between node and gateway as small as possible. In order to do this, a | ||||||
|  | dns-cache may be used on a node. The dnsmasq instance listening on port | ||||||
|  | 53 in the node will be re-configured to answer requests, use a list of | ||||||
|  | upstream servers and a specific cache size if the below options are | ||||||
|  | added to site.conf All settings are optional, though if no dns server is | ||||||
|  | set, the configuration will not be altered by gluon-core. | ||||||
|  | 
 | ||||||
|  | Besides caching dns requests from clients, the next_node-addresses are set to | ||||||
|  | resolve to a configurable name that may optionally be placed in next_node.name. | ||||||
|  | 
 | ||||||
|  | :: | ||||||
|  | 
 | ||||||
|  |   dns = { | ||||||
|  |     cacheentries = 5000, | ||||||
|  |     servers = { '2001:db8::1', }, | ||||||
|  |   }, | ||||||
|  |    | ||||||
|  |   next_node = { | ||||||
|  |     name = 'nextnode', | ||||||
|  |     ip6 = '2001:db8:8::1', | ||||||
|  |     ip4 = '198.51.100.1', | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | The cache will be initialized during startup. Each cache entry will use roughly | ||||||
|  | 90 Bytes of main memory. | ||||||
| @ -2,16 +2,16 @@ need_string 'site_code' | |||||||
| need_string 'site_name' | need_string 'site_name' | ||||||
| 
 | 
 | ||||||
| if need_table('opkg', nil, false) then | if need_table('opkg', nil, false) then | ||||||
|   need_string('opkg.lede', false) | 	need_string('opkg.lede', false) | ||||||
| 
 | 
 | ||||||
|   function check_repo(k, _) | 	function check_repo(k, _) | ||||||
|     -- this is not actually a uci name, but using the same naming rules here is fine | 		-- this is not actually a uci name, but using the same naming rules here is fine | ||||||
|     assert_uci_name(k) | 		assert_uci_name(k) | ||||||
| 
 | 
 | ||||||
|     need_string(string.format('opkg.extra[%q]', k)) | 		need_string(string.format('opkg.extra[%q]', k)) | ||||||
|   end | 	end | ||||||
| 
 | 
 | ||||||
|   need_table('opkg.extra', check_repo, false) | 	need_table('opkg.extra', check_repo, false) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| need_string('hostname_prefix', false) | need_string('hostname_prefix', false) | ||||||
| @ -23,19 +23,28 @@ need_string_match('prefix6', '^[%x:]+/%d+$') | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| for _, config in ipairs({'wifi24', 'wifi5'}) do | for _, config in ipairs({'wifi24', 'wifi5'}) do | ||||||
|   if need_table(config, nil, false) then | 	if need_table(config, nil, false) then | ||||||
|     need_string('regdom') -- regdom is only required when wifi24 or wifi5 is configured | 		need_string('regdom') -- regdom is only required when wifi24 or wifi5 is configured | ||||||
| 
 | 
 | ||||||
|     need_number(config .. '.channel') | 		need_number(config .. '.channel') | ||||||
| 
 | 
 | ||||||
|     local rates = {1000, 2000, 5500, 6000, 9000, 11000, 12000, 18000, 24000, 36000, 48000, 54000} | 		local rates = {1000, 2000, 5500, 6000, 9000, 11000, 12000, 18000, 24000, 36000, 48000, 54000} | ||||||
|     local supported_rates = need_array_of(config .. '.supported_rates', rates, false) | 		local supported_rates = need_array_of(config .. '.supported_rates', rates, false) | ||||||
|     if supported_rates then | 		if supported_rates then | ||||||
|       need_array_of(config .. '.basic_rate', supported_rates, true) | 			need_array_of(config .. '.basic_rate', supported_rates, true) | ||||||
|     else | 		else | ||||||
|       need_array_of(config .. '.basic_rate', rates, false) | 			need_array_of(config .. '.basic_rate', rates, false) | ||||||
|     end | 		end | ||||||
|   end | 	end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| need_boolean('poe_passthrough', false) | need_boolean('poe_passthrough', false) | ||||||
|  | if need_table('dns', nil, false) then | ||||||
|  | 	need_number('dns.cacheentries', false) | ||||||
|  | 	need_string_array('dns.servers', false) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | if need_table('next_node', nil, false) then | ||||||
|  | 	need_string_match('next_node.ip6', '^[%x:]+$', false) | ||||||
|  | 	need_string_match('next_node.ip4', '^%d+.%d+.%d+.%d+$', false) | ||||||
|  | end | ||||||
|  | |||||||
							
								
								
									
										40
									
								
								package/gluon-core/luasrc/lib/gluon/upgrade/820-dns-config
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										40
									
								
								package/gluon-core/luasrc/lib/gluon/upgrade/820-dns-config
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,40 @@ | |||||||
|  | #!/usr/bin/lua | ||||||
|  | local site = require 'gluon.site_config' | ||||||
|  | local uci = require('luci.model.uci').cursor() | ||||||
|  | 
 | ||||||
|  | dnsmasq=uci:get_first("dhcp", "dnsmasq") | ||||||
|  | 
 | ||||||
|  | uci:set('dhcp', dnsmasq, 'localise_queries', '1') | ||||||
|  | uci:set('dhcp', dnsmasq, 'localservice', '0') | ||||||
|  | 
 | ||||||
|  | if site.dns and site.dns.servers then | ||||||
|  | 	uci:set('dhcp', dnsmasq, 'server', site.dns.servers) | ||||||
|  | else | ||||||
|  | 	uci:delete('dhcp', dnsmasq, 'server') | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | if site.dns and site.dns.cacheentries then | ||||||
|  | 	uci:set('dhcp', dnsmasq, 'cachesize', site.dns.cacheentries) | ||||||
|  | else | ||||||
|  | 	uci:delete('dhcp', dnsmasq, 'cachesize') | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | if site.next_node and site.next_node.name and site.next_node.ip4 then | ||||||
|  | 	uci:section('dhcp','domain','nextnode4',{ | ||||||
|  | 		name=site.next_node.name, | ||||||
|  | 		ip=site.next_node.ip4, | ||||||
|  | 	}) | ||||||
|  | else | ||||||
|  | 	uci:delete('dhcp', 'domain', 'nextnode4') | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | if site.next_node and site.next_node.name and site.next_node.ip6 then | ||||||
|  | 	uci:section('dhcp','domain','nextnode6',{ | ||||||
|  | 		name=site.next_node.name, | ||||||
|  | 		ip=site.next_node.ip6, | ||||||
|  | 	}) | ||||||
|  | else | ||||||
|  | 	uci:delete('dhcp', 'domain', 'nextnode6') | ||||||
|  | end | ||||||
|  | uci:save('dhcp') | ||||||
|  | 
 | ||||||
| @ -29,6 +29,10 @@ uci:section('network', 'interface', 'local_node', | |||||||
| 	} | 	} | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | if site.dns and site.dns.servers then | ||||||
|  | 	uci:set('network', 'local-node', 'peerdns','0') | ||||||
|  | end | ||||||
|  | 
 | ||||||
| uci:delete('network', 'local_node_route6') | uci:delete('network', 'local_node_route6') | ||||||
| uci:section('network', 'route6', 'local_node_route6', | uci:section('network', 'route6', 'local_node_route6', | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user