From 9e4cf47ee831760d6651770c837993e0c32dda23 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Wed, 17 Feb 2016 20:26:32 +0000 Subject: [PATCH] Add --add-mac=text option. --- man/dnsmasq.8 | 4 ++-- src/dnsmasq.h | 3 ++- src/edns0.c | 17 +++++++++++------ src/option.c | 5 +++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/man/dnsmasq.8 b/man/dnsmasq.8 index 7183265..b782eaf 100644 --- a/man/dnsmasq.8 +++ b/man/dnsmasq.8 @@ -604,7 +604,7 @@ configured a zero is added in front of the label. ::1 becomes 0--1. The address range can be of the form , or / .TP -.B --add-mac[=base64] +.B --add-mac[=base64|text] Add the MAC address of the requestor to DNS queries which are forwarded upstream. This may be used to DNS filtering by the upstream server. The MAC address can only be added if the requestor is on the same @@ -613,7 +613,7 @@ is not yet standardised, so this should be considered experimental. Also note that exposing MAC addresses in this way may have security and privacy implications. The warning about caching given for --add-subnet applies to --add-mac too. An alternative encoding of the -MAC, as base64, is enabled by adding the "base64" parameter. +MAC, as base64, is enabled by adding the "base64" parameter and a human-readable encoding of hex-and-colons is enabled by added the "text" parameter. .TP .B --add-cpe-id= Add a arbitrary identifying string to o DNS queries which are diff --git a/src/dnsmasq.h b/src/dnsmasq.h index 549ef55..6d1c5ae 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -237,7 +237,8 @@ struct event_desc { #define OPT_TFTP_NO_FAIL 52 #define OPT_SCRIPT_ARP 53 #define OPT_MAC_B64 54 -#define OPT_LAST 55 +#define OPT_MAC_HEX 55 +#define OPT_LAST 56 /* extra flags for my_syslog, we use a couple of facilities since they are known not to occupy the same bits as priorities, no matter how syslog.h is set up. */ diff --git a/src/edns0.c b/src/edns0.c index b95005f..f1279df 100644 --- a/src/edns0.c +++ b/src/edns0.c @@ -223,14 +223,19 @@ static size_t add_dns_client(struct dns_header *header, size_t plen, unsigned ch { int maclen; unsigned char mac[DHCP_CHADDR_MAX]; - char encode[8]; /* handle 6 byte MACs */ + char encode[18]; /* handle 6 byte MACs */ if ((maclen = find_mac(l3, mac, 1, now)) == 6) { - encoder(mac, encode); - encoder(mac+3, encode+4); - - plen = add_pseudoheader(header, plen, limit, PACKETSZ, EDNS0_OPTION_NOMDEVICEID, (unsigned char *)encode, 8, 0); + if (option_bool(OPT_MAC_HEX)) + print_mac(encode, mac, maclen); + else + { + encoder(mac, encode); + encoder(mac+3, encode+4); + encode[8] = 0; + } + plen = add_pseudoheader(header, plen, limit, PACKETSZ, EDNS0_OPTION_NOMDEVICEID, (unsigned char *)encode, strlen(encode), 0); } return plen; @@ -377,7 +382,7 @@ size_t add_edns0_config(struct dns_header *header, size_t plen, unsigned char *l if (option_bool(OPT_ADD_MAC)) plen = add_mac(header, plen, limit, source, now); - if (option_bool(OPT_MAC_B64)) + if (option_bool(OPT_MAC_B64) || option_bool(OPT_MAC_HEX)) plen = add_dns_client(header, plen, limit, source, now); if (daemon->dns_client_id) diff --git a/src/option.c b/src/option.c index ac35e7c..724540d 100644 --- a/src/option.c +++ b/src/option.c @@ -2172,8 +2172,9 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma unhide_metas(arg); if (strcmp(arg, "base64") == 0) set_option_bool(OPT_MAC_B64); - else - ret_err(gen_err); + else if (strcmp(arg, "text") == 0) + set_option_bool(OPT_MAC_HEX); + ret_err(gen_err); } break;