From patchwork Sun May 6 04:21:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [OpenWrt-Devel,1/1] dnsmasq: add support for set: and tag: pairs Date: Sun, 06 May 2012 03:21:23 -0000 From: Philip Prindeville X-Patchwork-Id: 2161 Message-Id: <4FA5FC43.5050209@redfish-solutions.com> To: OpenWrt Development List On my network, I have a variety of machines and appliances, some of which need different configuration issues than the default options. For example: config host option name 'client' option mac '00:01:02:03:04:05' option ip '192.168.1.20' option tag 'acme' config tag option name 'acme' option force '1' list dhcp_option 'option:router,192.168.1.253' list dhcp_option 'option:domain-name,acme.com' list dhcp_option 'option:domain-search,acme.com,redfish-solutions.com' which allows me to override the default router for my client's host, as well as its domain-name, and its domain-search. this causes the following config lines: dhcp-host=00:01:02:03:04:05,set:acme,192.168.1.20,client dhcp-option-force=tag:acme,option:router,192.168.1.253,option:domain-name,acme.com,option:domain-search:acme.com,redfish-solutions.com This could be useful elsewhere, for instance, if you have an IP CCTV that you don't want to have a default-route, etc. Index: trunk/package/dnsmasq/files/dnsmasq.init =================================================================== --- trunk/package/dnsmasq/files/dnsmasq.init (revision 31572) +++ trunk/package/dnsmasq/files/dnsmasq.init (working copy) @@ -224,16 +224,37 @@ config_get name "$cfg" name config_get ip "$cfg" ip - [ -n "$ip" ] || [ -n "$name" ] || return 0 + [ -n "$ip" -o -n "$name" ] || return 0 macs="" config_get mac "$cfg" mac for m in $mac; do append macs "$m" ","; done [ -n "$macs" ] || return 0 - xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${ip:+,$ip}${name:+,$name}" + config_get tag "$cfg" tag + + xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}" } +append_option() { + append options "$1" "," +} + +dhcp_tag_add() { + local cfg="$1" + + config_get tag "$cfg" name + [ -n "$tag" ] || return 0 + + options="" + config_list_foreach "$cfg" "dhcp_option" append_option + + config_get force "$cfg" force 0 + [ "$force" = "0" ] && force= + + xappend "--dhcp-option${force:+-force}=tag:$tag,$options" +} + dhcp_mac_add() { local cfg="$1" @@ -435,6 +456,7 @@ echo >> $CONFIGFILE config_foreach dhcp_boot_add boot config_foreach dhcp_mac_add mac + config_foreach dhcp_tag_add tag config_foreach dhcp_vendorclass_add vendorclass config_foreach dhcp_userclass_add userclass config_foreach dhcp_circuitid_add circuitid