@@ -62,6 +62,7 @@ struct sd_dhcp_client {
6262 uint8_t * req_opts ;
6363 size_t req_opts_allocated ;
6464 size_t req_opts_size ;
65+ bool anonymize ;
6566 be32_t last_addr ;
6667 uint8_t mac_addr [MAX_MAC_ADDR_LEN ];
6768 size_t mac_addr_len ;
@@ -116,6 +117,32 @@ static const uint8_t default_req_opts[] = {
116117 SD_DHCP_OPTION_DOMAIN_NAME_SERVER ,
117118};
118119
120+ /* RFC7844 section 3:
121+ MAY contain the Parameter Request List option.
122+ RFC7844 section 3.6:
123+ The client intending to protect its privacy SHOULD only request a
124+ minimal number of options in the PRL and SHOULD also randomly shuffle
125+ the ordering of option codes in the PRL. If this random ordering
126+ cannot be implemented, the client MAY order the option codes in the
127+ PRL by option code number (lowest to highest).
128+ */
129+ /* NOTE: using PRL options that Windows 10 RFC7844 implementation uses */
130+ static const uint8_t default_req_opts_anonymize [] = {
131+ SD_DHCP_OPTION_SUBNET_MASK , /* 1 */
132+ SD_DHCP_OPTION_ROUTER , /* 3 */
133+ SD_DHCP_OPTION_DOMAIN_NAME_SERVER , /* 6 */
134+ SD_DHCP_OPTION_DOMAIN_NAME , /* 15 */
135+ SD_DHCP_OPTION_ROUTER_DISCOVER , /* 31 */
136+ SD_DHCP_OPTION_STATIC_ROUTE , /* 33 */
137+ SD_DHCP_OPTION_VENDOR_SPECIFIC , /* 43 */
138+ SD_DHCP_OPTION_NETBIOS_NAMESERVER , /* 44 */
139+ SD_DHCP_OPTION_NETBIOS_NODETYPE , /* 46 */
140+ SD_DHCP_OPTION_NETBIOS_SCOPE , /* 47 */
141+ SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE , /* 121 */
142+ SD_DHCP_OPTION_PRIVATE_CLASSLESS_STATIC_ROUTE , /* 249 */
143+ SD_DHCP_OPTION_PRIVATE_PROXY_AUTODISCOVERY , /* 252 */
144+ };
145+
119146static int client_receive_message_raw (
120147 sd_event_source * s ,
121148 int fd ,
@@ -588,11 +615,18 @@ static int client_message_init(
588615 it MUST include that list in any subsequent DHCPREQUEST
589616 messages.
590617 */
591- r = dhcp_option_append (& packet -> dhcp , optlen , & optoffset , 0 ,
592- SD_DHCP_OPTION_PARAMETER_REQUEST_LIST ,
593- client -> req_opts_size , client -> req_opts );
594- if (r < 0 )
595- return r ;
618+
619+ /* RFC7844 section 3:
620+ MAY contain the Parameter Request List option. */
621+ /* NOTE: in case that there would be an option to do not send
622+ * any PRL at all, the size should be checked before sending */
623+ if (client -> req_opts_size > 0 ) {
624+ r = dhcp_option_append (& packet -> dhcp , optlen , & optoffset , 0 ,
625+ SD_DHCP_OPTION_PARAMETER_REQUEST_LIST ,
626+ client -> req_opts_size , client -> req_opts );
627+ if (r < 0 )
628+ return r ;
629+ }
596630
597631 /* RFC2131 section 3.5:
598632 The client SHOULD include the ’maximum DHCP message size’ option to
@@ -616,12 +650,16 @@ static int client_message_init(
616650 Maximum DHCP Message Size option is the total maximum packet size,
617651 including IP and UDP headers.)
618652 */
619- max_size = htobe16 (size );
620- r = dhcp_option_append (& packet -> dhcp , client -> mtu , & optoffset , 0 ,
621- SD_DHCP_OPTION_MAXIMUM_MESSAGE_SIZE ,
622- 2 , & max_size );
623- if (r < 0 )
624- return r ;
653+ /* RFC7844 section 3:
654+ SHOULD NOT contain any other option. */
655+ if (!client -> anonymize ) {
656+ max_size = htobe16 (size );
657+ r = dhcp_option_append (& packet -> dhcp , client -> mtu , & optoffset , 0 ,
658+ SD_DHCP_OPTION_MAXIMUM_MESSAGE_SIZE ,
659+ 2 , & max_size );
660+ if (r < 0 )
661+ return r ;
662+ }
625663
626664 * _optlen = optlen ;
627665 * _optoffset = optoffset ;
@@ -1783,7 +1821,14 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
17831821 if (r < 0 )
17841822 return r ;
17851823
1786- if (client -> last_addr )
1824+ /* RFC7844 section 3.3:
1825+ SHOULD perform a complete four-way handshake, starting with a
1826+ DHCPDISCOVER, to obtain a new address lease. If the client can
1827+ ascertain that this is exactly the same network to which it was
1828+ previously connected, and if the link-layer address did not change,
1829+ the client MAY issue a DHCPREQUEST to try to reclaim the current
1830+ address. */
1831+ if (client -> last_addr && !client -> anonymize )
17871832 client -> state = DHCP_STATE_INIT_REBOOT ;
17881833
17891834 r = client_start (client );
@@ -1875,7 +1920,7 @@ sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client) {
18751920 return mfree (client );
18761921}
18771922
1878- int sd_dhcp_client_new (sd_dhcp_client * * ret ) {
1923+ int sd_dhcp_client_new (sd_dhcp_client * * ret , int anonymize ) {
18791924 _cleanup_ (sd_dhcp_client_unrefp ) sd_dhcp_client * client = NULL ;
18801925
18811926 assert_return (ret , - EINVAL );
@@ -1892,8 +1937,15 @@ int sd_dhcp_client_new(sd_dhcp_client **ret) {
18921937 client -> mtu = DHCP_DEFAULT_MIN_SIZE ;
18931938 client -> port = DHCP_PORT_CLIENT ;
18941939
1895- client -> req_opts_size = ELEMENTSOF (default_req_opts );
1896- client -> req_opts = memdup (default_req_opts , client -> req_opts_size );
1940+ client -> anonymize = !!anonymize ;
1941+ /* NOTE: this could be moved to a function. */
1942+ if (anonymize ) {
1943+ client -> req_opts_size = ELEMENTSOF (default_req_opts_anonymize );
1944+ client -> req_opts = memdup (default_req_opts_anonymize , client -> req_opts_size );
1945+ } else {
1946+ client -> req_opts_size = ELEMENTSOF (default_req_opts );
1947+ client -> req_opts = memdup (default_req_opts , client -> req_opts_size );
1948+ }
18971949 if (!client -> req_opts )
18981950 return - ENOMEM ;
18991951
0 commit comments