在拉起dnsmasq进程时,可以根据需要使能option选项,这些option选项并不是随心所遇的字符串,而是在dnsmasq代码中已经定义好的一部分,因此如果你想增加新的option选项,必须修订dnsmasq的相关代码。
举个例子:当你执行dnsmasq --help时可以看到类似如下配置
root@iZbp1f4tnw2sehghtpe5zpZ:~# dnsmasq --help
Usage: dnsmasq [options]
Valid options are:
-a, --listen-address=<ipaddr> Specify local address(es) to listen on.
-A, --address=/<domain>/<ipaddr> Return ipaddr for all hosts in specified domains.
-b, --bogus-priv Fake reverse
...
而些信息则是通过dnsmasq工程中的:
option.c文件中的
一个静态函数:static void do_usage(void)
打印出来。
具体的结构体在如下位置:
static struct {
int opt;
unsigned int rept;
char * const flagdesc;
char * const desc;
char * const arg;
} usage[] = {
{ 'a', ARG_DUP, "<ipaddr>", gettext_noop("Specify local address(es) to listen on."), NULL },
{ 'A', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Return ipaddr for all hosts in specified domains."), NULL },
直接定义一个结构体数组,因此我们需要新增一个配置,可以仿照原先的逻辑在该数组新增一个结构体成员。
比如我新增一个nd代答的方法:
#define LOPT_ND_PROXY 357
新增
{ “nd-proxy”, 0, 0, LOPT_ND_PROXY },
在dnsmasq.h新增如下配置:
#define OPT_ND_PROXY 60
最后需要在one_opt(int option, char *arg, char *errstr, char *gen_err, int command_line, int servers_only)
新增一个关于该配置的case 选项
拉起进程:dnsmasq --no-hosts --no-resolv --strict-order --nd-proxy --except-interface=lo --dhcp-option-force=option:mtu,1500 --dhcp-lease-max=256 --domain=openstacklocal