Friday, 7 June 2013

Dnsmasq logging and options for the Quantum DHCP agent

Dnsmasq logs to syslog by default when the Quantum DHCP agent is configured to use it as the DHCP driver. This fills the syslog on the network node very quickly with dnsmasq messages - a request and reply line once per minute per instance when the lease time is the default 120 seconds. This post shows how to make dnsmasq log to a different file, give extra log detail and provide additional DHCP options for the clients.


Create a new file, e.g. /etc/quantum/dnsmasq.conf and add these lines to it

log-facility = /var/log/quantum/dnsmasq.log
log-dhcp


Then add this line to /etc/quantum/dhcp_agent.ini

dnsmasq_config_file = /etc/quantum/dnsmasq.conf


And restart the DHCP agent

netnode$ sudo service quantum-dhcp-agent restart


Now there should be a new /var/log/quantum/dnsmasq.log and no further dnsmasq messages in syslog. The log-dhcp option is useful for troubleshooting and can be commented out when extra detail is not needed.


DHCP options

Dnsmasq automatically sends the common DHCP options and can be configured to send additional ones too - it is well documented in the manpage. Say you need your instances to have some non-default MTU size, e.g. 1454 bytes, then just add this to the new dnsmasq.conf and restart the agent:

dhcp-option=26,1454


This configures dnsmasq to provide DHCP option 26. Now with the log-dhcp enabled you should see something like this when a request is made:

root@netnode:/# cat /var/log/quantum/dnsmasq.log

Jun  2 11:03:03 dnsmasq[17545]: started, version 2.59 cachesize 150
Jun  2 11:03:03 dnsmasq[17545]: compile time options: IPv6 GNU-getopt DBus i18n DHCP TFTP conntrack IDN
Jun  2 11:03:03 dnsmasq[17545]: warning: no upstream servers configured
Jun  2 11:03:03 dnsmasq-dhcp[17545]: DHCP, static leases only on 10.0.33.0, lease time 2m
Jun  2 11:03:03 dnsmasq[17545]: cleared cache
Jun  2 11:03:03 dnsmasq-dhcp[17545]: read /var/lib/quantum/dhcp/7a9ea3bd-77bd-4b99-ab7f-b1e200f07dd7/host
Jun  2 11:03:03 dnsmasq-dhcp[17545]: read /var/lib/quantum/dhcp/7a9ea3bd-77bd-4b99-ab7f-b1e200f07dd7/opts
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 available DHCP subnet: 10.0.33.0/255.255.255.0
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 vendor class: udhcp 1.18.5
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 DHCPDISCOVER(tapbec7a50d-b8) fa:16:3e:3d:05:84 
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 tags: tag0, known, tapbec7a50d-b8
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 DHCPOFFER(tapbec7a50d-b8) 10.0.33.2 fa:16:3e:3d:05:84 
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 requested options: 1:netmask, 3:router, 6:dns-server, 12:hostname, 
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 requested options: 15:domain-name, 26:mtu, 28:broadcast, 42:ntp-server
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 next server: 10.0.33.3
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  1 option: 53:message-type  02
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option: 54:server-identifier  10.0.33.3
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option: 51:lease-time  00:00:00:78
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option: 58:T1  00:00:00:3c
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option: 59:T2  00:00:00:69
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option:  1:netmask  255.255.255.0
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option: 28:broadcast  10.0.33.255
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size: 14 option: 15:domain-name  openstacklocal
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  9 option: 12:hostname  10-0-33-2
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  4 option:  3:router  10.0.33.1
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  8 option:  6:dns-server  8.8.4.4, 8.8.8.8
Jun  2 11:27:13 dnsmasq-dhcp[17545]: 108690537 sent size:  2 option: 26:mtu  05:ae


Here the client requested option 26 and dnsmasq sent back 1454 (0x05ae on the last line).

The instances need to be configured to request and use the options. The cirros test image does not have its DHCP client request the MTU by default, so it had to be rerun as follows:

# test from the vnc console and kill the original udhcpc process first
$ sudo udhcpc -R -n --timeout=60 -p /var/run/udhcpc.eth0.pid -i eth0 -O mtu


And this line was added to the end of /usr/share/udhcpc/default.script so the MTU received would actually get used:

[ -n "$mtu" ] && ip link set mtu $mtu dev $interface



Finally, care should be taken to avoid conflict with the options provided by the Quantum DHCP agent in /var/lib/quantum/dhcp/{{quantum-net-id}}/opts.