dhcp-server: Add "authoritative" mode
PATCH 1/8 dhcp-server: Add "authoritative" mode
An authoritative DHCP server basically assumes that there are no other DHCP servers on the network and replies to DHCPREQUEST messages requesting IPs from outside of its subnet or with a wrong server ID value. This speeds up connections from clients who try to use IP leases they have cached from other networks and who start their IP configuration by trying DHCPREQUESTs for those leases.
The term is not defined in the DHCP standard but is used by various implementations. Default to authoritative being true. When set to false, handle a DHCPREQUEST message directed at other servers by taking it as meaning the client is declining our own lease offer as mandated by RFC 2131 on page 16.
Refactor the checks in DHCPREQUEST handling quoting parts of the RFC. The new checks are stricter and I'm not preserving some of the checks that didn't seem justified, for example in the
"if (server_id_opt || !lease) ... send_nak()" block it didn't seem to make sense to only reply to clients who have no lease (offered or active) and ignore those who do have a lease with a different IP address, the opposite would make more sense.
--- ell/dhcp-server.c | 109 ++++++++++++++++++++++++++++++++++++++++------ ell/dhcp.h | 2 + ell/ell.sym | 1 + 3 files changed, 98 insertions(+), 14 deletions(-)
ell/dhcp-server.c +95 -14
@@ -87,6 +87,8 @@ struct l_dhcp_server {struct dhcp_transport *transport;struct l_acd *acd; + + bool authoritative : 1; };#define MAC "%02x:%02x:%02x:%02x:%02x:%02x"
@@ -615,9 +617,6 @@ static void listener_event(const void *data, size_t len, void *user_data)if (l ==4 ) server_id_opt =l_get_u32 (v); -if (server->address != server_id_opt) -return ; -break ;case L_DHCP_OPTION_REQUESTED_IP_ADDRESS :if (l ==4 )
@@ -640,6 +639,9 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received DISCOVER, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); +if (server_id_opt && server_id_opt != server->address) +break ; +send_offer (server, message, lease, requested_ip_opt);break ;
@@ -647,27 +649,92 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received REQUEST, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); -if (requested_ip_opt ==0 ) { - requested_ip_opt = message->ciaddr; -if (requested_ip_opt ==0 ) +/* +* RFC2131 Section 3.5: "Those servers not selected by the +* DHCPREQUEST message use the message as notification that +* the client has declined that server's offer." +*/ +if (server_id_opt && server_id_opt != server->address) { +if (server->authoritative) { +send_nak (server, message);break ; - } + } -if (lease && requested_ip_opt == lease->address) { -send_ack (server, message, lease->address); +if (!lease || !lease->offering) +break ; + +remove_lease (server, lease);break ; } -if (server_id_opt || !lease) { -send_nak (server, message); +/* +* RFC2131 Section 3.5: "If the selected server is unable to +* satisfy the DHCPREQUEST message (...), the server SHOULD +* respond with a DHCPNAK message." +* +* But: +* 4.3.2: "If the DHCP server has no record of this client, +* then it MUST remain silent (...)" +*/ +if (!lease) { +if (server_id_opt == server->address || + server->authoritative) +send_nak (server, message); +break ; } + +/* +* 4.3.2: "If the DHCPREQUEST message contains a 'server +* identifier' option, the message is in response to a +* DHCPOFFER message. Otherwise, the message is a request +* to verify or extend an existing lease." +*/ +if (server_id_opt == server->address) { +/* +* Allow either no 'requested IP address' option or +* a value identical with the one we offered because +* the spec is unclear on whether it is to be +* included: +* +* Section 4.3.2: "DHCPREQUEST generated during +* SELECTING state: (...) 'requested IP address' MUST +* be filled in with the yiaddr value from the chosen +* DHCPOFFER." +* +* but section 3.5 suggests only in the INIT-REBOOT +* state: "The 'requested IP address' option is to be +* filled in only in a DHCPREQUEST message when the +* client is verifying network parameters obtained +* previously." +*/ +if (!lease->offering || + (requested_ip_opt && + requested_ip_opt != lease->address)) { +send_nak (server, message); +break ; + } + }else { +/* +* 3.5: "If a server receives a DHCPREQUEST message +* with an invalid 'requested IP address', the server +* SHOULD respond to the client with a DHCPNAK message" +*/ +if (lease->offering || + (requested_ip_opt && + requested_ip_opt != lease->address)) { +send_nak (server, message); +break ; + } + } + +send_ack (server, message, lease->address);break ;case DHCP_MESSAGE_TYPE_DECLINE :SERVER_DEBUG ("Received DECLINE" ); -if (!server_id_opt || !requested_ip_opt || !lease || - !lease->offering) +if (server_id_opt != server->address || !requested_ip_opt || + !lease || !lease->offering)break ;if (requested_ip_opt == lease->address)
@@ -677,7 +744,8 @@ static void listener_event(const void *data, size_t len, void *user_data)case DHCP_MESSAGE_TYPE_RELEASE :SERVER_DEBUG ("Received RELEASE" ); -if (!server_id_opt || !lease || lease->offering) +if (server_id_opt != server->address || !lease || + lease->offering)break ;if (message->ciaddr == lease->address)
@@ -687,6 +755,9 @@ static void listener_event(const void *data, size_t len, void *user_data)case DHCP_MESSAGE_TYPE_INFORM :SERVER_DEBUG ("Received INFORM" ); +if (server_id_opt && server_id_opt != server->address) +break ; +send_inform (server, message);break ; }
@@ -732,6 +803,7 @@ LIB_EXPORT struct l_dhcp_server *l_dhcp_server_new(int ifindex) server->expired_list =l_queue_new (); server->started = false; + server->authoritative = true; server->lease_seconds =DEFAULT_DHCP_LEASE_SEC ; server->max_expired =MAX_EXPIRED_LEASES ;
@@ -1053,6 +1125,15 @@ failed:return false; } +LIB_EXPORT void l_dhcp_server_set_authoritative(struct l_dhcp_server *server, +bool authoritative) +{ +if (unlikely (!server)) +return ; + + server->authoritative = authoritative; +} + LIB_EXPORT struct l_dhcp_lease *l_dhcp_server_discover( struct l_dhcp_server *server, uint32_t requested_ip_opt,
ell/dhcp.h +2 -0
@@ -141,6 +141,8 @@ bool l_dhcp_server_set_ip_address(struct l_dhcp_server *server,bool l_dhcp_server_set_netmask (struct l_dhcp_server *server,const char *mask);bool l_dhcp_server_set_gateway (struct l_dhcp_server *server,const char *ip);bool l_dhcp_server_set_dns (struct l_dhcp_server *server,char **dns); +void l_dhcp_server_set_authoritative (struct l_dhcp_server *server, +bool authoritative); struct l_dhcp_lease *l_dhcp_server_discover(struct l_dhcp_server *server, uint32_t requested_ip_opt,
ell/ell.sym +1 -0
@@ -259,6 +259,7 @@ global: l_dhcp_server_set_netmask; l_dhcp_server_set_gateway; l_dhcp_server_set_dns; + l_dhcp_server_set_authoritative; l_dhcp_server_discover; l_dhcp_server_request; l_dhcp_server_decline;
Signature · 1 line
2.30.2
PATCH 2/8 dhcp-server: Handle DHCPDECLINE for active leases
RFC2131 Section 3.1 mentions a scenario where the client is supposed to drop its lease using DHCPDECLINE after sending the DHCPREQUEST and receiving the DHCPACK meaning that lease is no longer in the offering state:
"5. The client receives the DHCPACK message with configuration
parameters. The client SHOULD perform a final check on the parameters [...]. If the client detects that the address is already in use (e.g., through the use of ARP), the client MUST send a DHCPDECLINE message..."
--- ell/dhcp-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/dhcp-server.c +1 -1
@@ -734,7 +734,7 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received DECLINE" );if (server_id_opt != server->address || !requested_ip_opt || - !lease || !lease->offering) + !lease)break ;if (requested_ip_opt == lease->address)
Signature · 1 line
2.30.2
PATCH 3/8 dhcp-server: Respect client's broadcast flag
In reply to Andrew ZaborowskiFollow notes in RFC2131 4.1, 4.3.2 and 4.4.4 when deciding whether we can use unicast for a given message. We want to prefer unicast when possible but we should follow the spec on the broadcast flag and the destination address.
--- ell/dhcp-private.h | 3 ++ ell/dhcp-server.c | 90 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 21 deletions(-)
ell/dhcp-private.h +3 -0
@@ -66,6 +66,9 @@ enum dhcp_option_overload {#define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57/* Section 9.10 */ #define DHCP_OPTION_CLIENT_IDENTIFIER 61/* Section 9.14 */ +/* RFC 2131, Figure 2 */ +#define DHCP_FLAG_BROADCAST (1 << 15) +/* RFC 2131, Figure 1 */ struct dhcp_message {uint8_t op;
ell/dhcp-server.c +69 -21
121 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH 3/8] dhcp-server: Respect client's broadcast flag
Hi Andrew,
Quoted 113 lines · Andrew Zaborowski
Follow notes in RFC2131 4.1, 4.3.2 and 4.4.4 when deciding whether we can use unicast for a given message. We want to prefer unicast when possible but we should follow the spec on the broadcast flag and the destination address.
--- ell/dhcp-private.h | 3 ++ ell/dhcp-server.c | 90 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 21 deletions(-)ell/dhcp-private.h +3
-0@@ -66,6 +66,9 @@ enum dhcp_option_overload {#define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57/* Section 9.10 */ #define DHCP_OPTION_CLIENT_IDENTIFIER 61/* Section 9.14 */ +/* RFC 2131, Figure 2 */ +#define DHCP_FLAG_BROADCAST (1 << 15) +/* RFC 2131, Figure 1 */ struct dhcp_message {uint8_t op;ell/dhcp-server.c +66
-5@@ -420,6 +420,71 @@ static void server_message_init(struct l_dhcp_server *server, reply->ciaddr = client_msg->ciaddr; } +static bool server_message_send (struct l_dhcp_server *server, +struct dhcp_message *reply,size_t len, +uint8_t type) +{ +uint32_t daddr; +uint16_t dport; +const uint8_t *dest_mac; + +/* +* RFC2131 Section 4.1: "If the 'giaddr' field in a DHCP message from +* a client is non-zero, the server sends any return messages to the +* 'DHCP server' port on the BOOTP relay agent whose address appears +* in 'giaddr'. If the 'giaddr' field is zero and the 'ciaddr' field +* is nonzero, then the server unicasts DHCPOFFER and DHCPACK messages +* to the address in 'ciaddr'. If 'giaddr' is zero and 'ciaddr' is +* zero, and the broadcast bit is set, then the server broadcasts +* DHCPOFFER and DHCPACK messages to 0xffffffff. If the broadcast bit +* is not set and 'giaddr' is zero and 'ciaddr' is zero, then the +* server unicasts DHCPOFFER and DHCPACK messages to the client's +* hardware address and 'yiaddr' address. In all cases, when 'giaddr' +* is zero, the server broadcasts any DHCPNAK messages to 0xffffffff." +* +* 4.3.2: "If 'giaddr' is set in the DHCPREQUEST message, the client +* is on a different subnet. The server MUST set the broadcast bit in +* the DHCPNAK, so that the relay agent will broadcast the DHCPNAK to +* the client, because the client may not have a correct network +* address or subnet mask, and the client may not be answering ARP +* requests." +*/ +if (reply->giaddr) { + dport =DHCP_PORT_SERVER ; + daddr = reply->giaddr; + dest_mac = reply->chaddr; + +if (type ==DHCP_MESSAGE_TYPE_NAK ) + reply->flags |=L_CPU_TO_BE16 (DHCP_FLAG_BROADCAST ); + }else { + dport =DHCP_PORT_CLIENT ; + +if (type ==DHCP_MESSAGE_TYPE_NAK ) { + daddr =0xffffffff ; + dest_mac =MAC_BCAST_ADDR ; + }else if (reply->ciaddr) { + daddr = reply->ciaddr; + dest_mac = reply->chaddr; + }else if (L_BE16_TO_CPU (reply->flags) &DHCP_FLAG_BROADCAST ) { + daddr =0xffffffff ; + dest_mac =MAC_BCAST_ADDR ; + }else { + daddr = reply->yiaddr; + dest_mac = reply->chaddr; + } + } + +if (server->transport->l2_send (server->transport, server->address, +DHCP_PORT_SERVER , daddr, dport, + dest_mac, reply, len) <0 ) { +SERVER_DEBUG ("Failed to send %s" , +_dhcp_message_type_to_string (type)); +return false; + } + +return true; +} +static void add_server_options (struct l_dhcp_server *server,struct dhcp_message_builder *builder) {@@ -491,11 +556,7 @@ static void send_offer(struct l_dhcp_server *server,SERVER_DEBUG ("Sending OFFER of " NIPQUAD_FMT " to " MAC ,NIPQUAD (reply->yiaddr),MAC_STR (reply->chaddr)); -if (server->transport->l2_send (server->transport, server->address, -DHCP_PORT_SERVER , - reply->ciaddr,DHCP_PORT_CLIENT , - reply->chaddr, reply, len) <0 ) -SERVER_DEBUG ("Failed to send OFFER" ); +server_message_send (server, reply, len,DHCP_MESSAGE_TYPE_OFFER ); } static void send_inform(struct l_dhcp_server *server,
ell/dhcp-server.c static void send_inform(struct l_dhcp_server *server, · line 579
Quoted 9 lines
ell/dhcp-server.c +1
-5@@ -515,11 +576,7 @@ static void send_inform(struct l_dhcp_server *server,_dhcp_message_builder_finalize (&builder, &len); -if (server->transport->l2_send (server->transport, server->address, -DHCP_PORT_SERVER , reply->ciaddr, -DHCP_PORT_CLIENT , reply->chaddr, - reply, len) <0 ) -SERVER_DEBUG ("Failed to send INFORM" ); +server_message_send (server, reply, len,DHCP_MESSAGE_TYPE_ACK );
Inform?
Quoted 22 lines
ell/dhcp-server.c +1
-6} static void send_nak(struct l_dhcp_server *server,@@ -537,11 +594,7 @@ static void send_nak(struct l_dhcp_server *server,_dhcp_message_builder_finalize (&builder, &len); -if (server->transport->l2_send (server->transport, server->address, -DHCP_PORT_SERVER , reply->ciaddr, -DHCP_PORT_CLIENT ,MAC_BCAST_ADDR , - reply, len) <0 ) -SERVER_DEBUG ("Failed to send NACK" ); +server_message_send (server, reply, len,DHCP_MESSAGE_TYPE_NAK ); } static void send_ack(struct l_dhcp_server *server,@@ -574,13 +627,8 @@ static void send_ack(struct l_dhcp_server *server,SERVER_DEBUG ("Sending ACK to " NIPQUAD_FMT ,NIPQUAD (reply->yiaddr)); - if (server->transport->l2_send(server->transport, server->address,
ell/dhcp-server.c static void send_ack(struct l_dhcp_server *server, · line 634
Quoted 10 lines
ell/dhcp-server.c +1
-5- DHCP_PORT_SERVER, reply->ciaddr, - DHCP_PORT_CLIENT, - reply->chaddr, reply, len) < 0) { -SERVER_DEBUG ("Failed to send ACK" ); +if (!server_message_send (server, reply, len,DHCP_MESSAGE_TYPE_ACK ))return ; - } lease =add_lease (server, false, reply->chaddr, reply->yiaddr);
Regards,
-Denis
Re: [PATCH 3/8] dhcp-server: Respect client's broadcast flag
Quoted 6 lines · Denis Kenzior
Quoted 5 lines · Andrew Zaborowski
static void send_inform(struct
l_dhcp_server*server,ell/dhcp-server.c +0
-0@@ -515,11 +576,7 @@ static void send_inform(struct l_dhcp_server *server,_dhcp_message_builder_finalize (&builder, &len);
Quoted 8 lines
ell/dhcp-server.c static void send_inform(struct l_dhcp_server *server, · line 579
Quoted 6 lines
ell/dhcp-server.c +1
-5-if (server->transport->l2_send (server->transport, server->address, -DHCP_PORT_SERVER , reply->ciaddr, -DHCP_PORT_CLIENT , reply->chaddr, - reply, len) <0 ) -SERVER_DEBUG ("Failed to send INFORM" ); +server_message_send (server, reply, len,DHCP_MESSAGE_TYPE_ACK );Inform?
Yep, right.
Best regards
PATCH 4/8 dhcp-lease: Check duplicate options in _dhcp_lease_parse_options
In reply to Andrew ZaborowskiGuard against leaks if some of the options are duplicated in the message being parsed in _dhcp_lease_parse_options.
--- ell/dhcp-lease.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
ell/dhcp-lease.c +4 -1
@@ -90,6 +90,9 @@ struct l_dhcp_lease *_dhcp_lease_parse_options(struct dhcp_message_iter *iter) lease->broadcast =l_get_u32 (v);break ;case L_DHCP_OPTION_DOMAIN_NAME_SERVER : +if (lease->dns) + goto error; +if (l >=4 && !(l %4 )) {unsigned i =0 ;
@@ -105,7 +108,7 @@ struct l_dhcp_lease *_dhcp_lease_parse_options(struct dhcp_message_iter *iter) }break ;case L_DHCP_OPTION_DOMAIN_NAME : -if (l <1 || l >253 ) +if (l <1 || l >253 || lease->domain_name) goto error;/* Disallow embedded NUL bytes. */
Signature · 1 line
2.30.2
Denis Kenzior
AppliedRe: [PATCH 4/8] dhcp-lease: Check duplicate options in _dhcp_lease_parse_options
Hi Andrew,
Quoted 6 lines · Andrew Zaborowski
Guard against leaks if some of the options are duplicated in the message being parsed in
_dhcp_lease_parse_options.--- ell/dhcp-lease.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Applied, thanks.
Regards,
-Denis
PATCH 5/8 dhcp-server: Look up leases by client identifier option
In reply to Andrew ZaborowskiIf the client identifier option is present in the client message, that should be used for lease lookups, overriding the MAC value, according to RFC2131. Parse that option and save the value for lookups.
--- ell/dhcp-lease.c | 9 ++++++ ell/dhcp-private.h | 1 + ell/dhcp-server.c | 72 ++++++++++++++++++++++++++++++++-------------- ell/dhcp.h | 1 + 4 files changed, 62 insertions(+), 21 deletions(-)
ell/dhcp-lease.c +9 -0
@@ -49,6 +49,7 @@ void _dhcp_lease_free(struct l_dhcp_lease *lease)l_free (lease->dns);l_free (lease->domain_name); +l_free (lease->client_id);l_free (lease); }
@@ -137,6 +138,14 @@ struct l_dhcp_lease *_dhcp_lease_parse_options(struct dhcp_message_iter *iter)if (l_net_hostname_is_localhost (lease->domain_name)) goto error; +break ; +case DHCP_OPTION_CLIENT_IDENTIFIER : +if (l <1 || l >253 || lease->client_id) + goto error; + + lease->client_id =l_malloc (l +1 ); + lease->client_id[0 ] = l; +memcpy (lease->client_id +1 , v, l);break ;default :break ;
ell/dhcp-private.h +1 -0
@@ -167,6 +167,7 @@ struct l_dhcp_lease {char *domain_name;/* for server */ uint8_t mac[6 ]; +uint8_t *client_id;/* set for an offered lease, but not ACK'ed */ bool offering : 1;
ell/dhcp-server.c +51 -21
208 lines not on this page · raw message
ell/dhcp.h +1 -0
@@ -146,6 +146,7 @@ void l_dhcp_server_set_authoritative(struct l_dhcp_server *server,struct l_dhcp_lease *l_dhcp_server_discover (struct l_dhcp_server *server,uint32_t requested_ip_opt, +const uint8_t *client_id,const uint8_t *mac);bool l_dhcp_server_request (struct l_dhcp_server *server,struct l_dhcp_lease *lease);
Signature · 1 line
2.30.2
PATCH 6/8 dhcp-server: Copy client identifier from the client message
In reply to Andrew ZaborowskiAs mandated by RFC 6842 copy the client identifier option from the client message we're replying to into the reply message.
--- ell/dhcp-server.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
ell/dhcp-server.c +23 -8
@@ -524,6 +524,16 @@ static void add_server_options(struct l_dhcp_server *server, } } +/* Copy the client identifier option from the client message per RFC6842 */ +static void copy_client_id (struct dhcp_message_builder *builder, +const uint8_t *client_id) +{ +if (client_id) +_dhcp_message_builder_append (builder, +DHCP_OPTION_CLIENT_IDENTIFIER , + client_id[0 ], client_id +1 ); +} + static void send_offer(struct l_dhcp_server *server, const struct dhcp_message *client_msg, struct l_dhcp_lease *lease, uint32_t requested_ip,
@@ -569,6 +579,7 @@ static void send_offer(struct l_dhcp_server *server, 4, &server->address);add_server_options (server, &builder); +copy_client_id (&builder, client_id);_dhcp_message_builder_finalize (&builder, &len);
@@ -579,7 +590,8 @@ static void send_offer(struct l_dhcp_server *server, }static void send_inform (struct l_dhcp_server *server, -const struct dhcp_message *client_msg) +const struct dhcp_message *client_msg, +const uint8_t *client_id) {struct dhcp_message_builder builder;size_t len =sizeof (struct dhcp_message ) +DHCP_MIN_OPTIONS_SIZE ;
@@ -592,6 +604,7 @@ static void send_inform(struct l_dhcp_server *server,_dhcp_message_builder_init (&builder, reply, len,DHCP_MESSAGE_TYPE_ACK );add_server_options (server, &builder); +copy_client_id (&builder, client_id);_dhcp_message_builder_finalize (&builder, &len);
@@ -599,7 +612,8 @@ static void send_inform(struct l_dhcp_server *server, }static void send_nak (struct l_dhcp_server *server, -const struct dhcp_message *client_msg) +const struct dhcp_message *client_msg, +const uint8_t *client_id) {struct dhcp_message_builder builder;size_t len =sizeof (struct dhcp_message ) +DHCP_MIN_OPTIONS_SIZE ;
@@ -610,7 +624,7 @@ static void send_nak(struct l_dhcp_server *server,server_message_init (server, client_msg, reply);_dhcp_message_builder_init (&builder, reply, len,DHCP_MESSAGE_TYPE_NAK ); - +copy_client_id (&builder, client_id);_dhcp_message_builder_finalize (&builder, &len);server_message_send (server, reply, len,DHCP_MESSAGE_TYPE_NAK );
@@ -638,6 +652,7 @@ static void send_ack(struct l_dhcp_server *server, 4, &lease_time);add_server_options (server, &builder); +copy_client_id (&builder, lease->client_id);_dhcp_message_builder_append (&builder,L_DHCP_OPTION_SERVER_IDENTIFIER ,4 , &server->address);
@@ -733,7 +748,7 @@ static void listener_event(const void *data, size_t len, void *user_data)*/ if (server_id_opt && server_id_opt != server->address) {if (server->authoritative) { -send_nak (server, message); +send_nak (server, message, client_id_opt);break ; }
@@ -756,7 +771,7 @@ static void listener_event(const void *data, size_t len, void *user_data)if (!lease) {if (server_id_opt == server->address || server->authoritative) -send_nak (server, message); +send_nak (server, message, client_id_opt);break ; }
@@ -788,7 +803,7 @@ static void listener_event(const void *data, size_t len, void *user_data)if (!lease->offering || (requested_ip_opt && requested_ip_opt != lease->address)) { -send_nak (server, message); +send_nak (server, message, client_id_opt);break ; } }else {
@@ -800,7 +815,7 @@ static void listener_event(const void *data, size_t len, void *user_data)if (lease->offering || (requested_ip_opt && requested_ip_opt != lease->address)) { -send_nak (server, message); +send_nak (server, message, client_id_opt);break ; } }
@@ -835,7 +850,7 @@ static void listener_event(const void *data, size_t len, void *user_data)if (server_id_opt && server_id_opt != server->address)break ; -send_inform (server, message); +send_inform (server, message, client_id_opt);break ; } }
Signature · 1 line
2.30.2
PATCH 7/8 dhcp-server: Support RFC4039 Rapid Commit
In reply to Andrew ZaborowskiHandle the RFC4039 Rapid Commit option in a DHCPDISCOVERY by directly creating an active lease and replying with a DHCPACK, i.e. skipping the DHCPOFFER and DHCPREQUEST roundtrip.
Currently enabled unconditionally, the support can be made optional if needed in the future.
--- ell/dhcp-private.h | 1 + ell/dhcp-server.c | 26 ++++++++++++++++++++++++-- ell/dhcp-util.c | 4 +++- 3 files changed, 28 insertions(+), 3 deletions(-)
ell/dhcp-private.h +1 -0
@@ -65,6 +65,7 @@ enum dhcp_option_overload {#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55/* Section 9.8 */ #define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57/* Section 9.10 */ #define DHCP_OPTION_CLIENT_IDENTIFIER 61/* Section 9.14 */ +#define DHCP_OPTION_RAPID_COMMIT 80/* RFC 4039 Section 4 */ /* RFC 2131, Figure 2 */ #define DHCP_FLAG_BROADCAST (1 << 15)
ell/dhcp-server.c +24 -2
@@ -632,7 +632,8 @@ static void send_nak(struct l_dhcp_server *server,static void send_ack (struct l_dhcp_server *server,const struct dhcp_message *client_msg, -const struct l_dhcp_lease *lease) +const struct l_dhcp_lease *lease, +bool rapid_commit) {struct dhcp_message_builder builder;size_t len =sizeof (struct dhcp_message ) +DHCP_MIN_OPTIONS_SIZE ;
@@ -657,6 +658,10 @@ static void send_ack(struct l_dhcp_server *server,_dhcp_message_builder_append (&builder,L_DHCP_OPTION_SERVER_IDENTIFIER ,4 , &server->address); +if (rapid_commit) +_dhcp_message_builder_append (&builder,DHCP_OPTION_RAPID_COMMIT , +0 ,"" ); +_dhcp_message_builder_finalize (&builder, &len);SERVER_DEBUG ("Sending ACK to " NIPQUAD_FMT ,NIPQUAD (reply->yiaddr));
@@ -684,6 +689,7 @@ static void listener_event(const void *data, size_t len, void *user_data)uint32_t server_id_opt =0 ;uint32_t requested_ip_opt =0 ; L_AUTO_FREE_VAR(uint8_t *, client_id_opt) = NULL; +bool rapid_commit_opt = false;SERVER_DEBUG ("" );
@@ -715,6 +721,9 @@ static void listener_event(const void *data, size_t len, void *user_data) client_id_opt[0 ] = l;memcpy (client_id_opt +1 , v, l);break ; +case DHCP_OPTION_RAPID_COMMIT : + rapid_commit_opt = true; +break ; } }
@@ -734,6 +743,19 @@ static void listener_event(const void *data, size_t len, void *user_data)if (server_id_opt && server_id_opt != server->address)break ; +if (rapid_commit_opt) { + lease =l_dhcp_server_discover (server, requested_ip_opt, + client_id_opt, + message->chaddr); +if (!lease) { +send_nak (server, message, client_id_opt); +break ; + } + +send_ack (server, message, lease, rapid_commit_opt); +break ; + } +send_offer (server, message, lease, requested_ip_opt, client_id_opt);break ;
@@ -820,7 +842,7 @@ static void listener_event(const void *data, size_t len, void *user_data) } } -send_ack (server, message, lease); +send_ack (server, message, lease, false);break ;case DHCP_MESSAGE_TYPE_DECLINE :SERVER_DEBUG ("Received DECLINE" );
ell/dhcp-util.c +3 -1
@@ -73,7 +73,9 @@ bool _dhcp_message_builder_append(struct dhcp_message_builder *builder, builder->pos[0 ] = code; builder->pos[1 ] = optlen; -memcpy (builder->pos +2 , optval, optlen); + +if (optlen) +memcpy (builder->pos +2 , optval, optlen); builder->pos += optlen +2 ;break ;
Signature · 1 line
2.30.2
PATCH 8/8 dhcp: Support RFC4039 Rapid Commit
In reply to Andrew ZaborowskiUse the RFC4039 Rapid Commit option in the DHCPDISCOVERY to attempt to get the server to directly reply with a DHCPACK, i.e. skipping the DHCPOFFER and DHCPREQUEST roundtrip.
Currently enabled unconditionally, the support can be made optional if needed in the future.
--- ell/dhcp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
ell/dhcp.c +14 -0
@@ -361,6 +361,8 @@ static int dhcp_client_send_discover(struct l_dhcp_client *client) client->hostname))return -EINVAL ; +_dhcp_message_builder_append (&builder,DHCP_OPTION_RAPID_COMMIT , +0 ,"" );_dhcp_message_builder_finalize (&builder, &len); return client->transport->l2_send(client->transport,
@@ -815,6 +817,17 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata)case DHCP_STATE_INIT :return ;case DHCP_STATE_SELECTING : +if (msg_type ==DHCP_MESSAGE_TYPE_ACK ) { +_dhcp_message_iter_init (&iter, message, len); + +while (_dhcp_message_iter_next (&iter, &t, &l, &v)) +if (t ==DHCP_OPTION_RAPID_COMMIT ) { +CLIENT_ENTER_STATE ( +DHCP_STATE_REQUESTING ); + goto receive_rapid_commit; + } + } +if (msg_type !=DHCP_MESSAGE_TYPE_OFFER )return ;
@@ -835,6 +848,7 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata)case DHCP_STATE_REQUESTING :case DHCP_STATE_RENEWING :case DHCP_STATE_REBINDING : + receive_rapid_commit:if (msg_type ==DHCP_MESSAGE_TYPE_NAK ) {CLIENT_DEBUG ("Received NAK, Stopping..." );l_dhcp_client_stop (client);
Signature · 1 line
2.30.2
Hi Andrew,
Quoted 13 lines · Andrew Zaborowski
An authoritative DHCP server basically assumes that there are no other DHCP servers on the network and replies to DHCPREQUEST messages requesting IPs from outside of its subnet or with a wrong server ID value. This speeds up connections from clients who try to use IP leases they have cached from other networks and who start their IP configuration by trying DHCPREQUESTs for those leases.
The term is not defined in the DHCP standard but is used by various implementations. Default to authoritative being true. When set to false, handle a DHCPREQUEST message directed at other servers by taking it as meaning the client is declining our own lease offer as mandated by RFC 2131 on page 16.
Quoted 7 lines
Refactor the checks in DHCPREQUEST handling quoting parts of the RFC. The new checks are stricter and I'm not preserving some of the checks that didn't seem justified, for example in the
"if (server_id_opt|| !lease) ...send_nak()" block it didn't seem to make sense to only reply to clients who have no lease (offered or active) and ignore those who do have a lease with a different IP address, the opposite would make more sense.
It seems like this is supposed to be handling the init-reboot, bound, renewing, rebinding states where server_id isn't present...?
Quoted 30 lines
--- ell/dhcp-server.c | 109 ++++++++++++++++++++++++++++++++++++++++------ ell/dhcp.h | 2 + ell/ell.sym | 1 + 3 files changed, 98 insertions(+), 14 deletions(-)ell/dhcp-server.c +2
-3@@ -87,6 +87,8 @@ struct l_dhcp_server {struct dhcp_transport *transport;struct l_acd *acd; + + bool authoritative : 1; };#define MAC "%02x:%02x:%02x:%02x:%02x:%02x"@@ -615,9 +617,6 @@ static void listener_event(const void *data, size_t len, void *user_data)if (l ==4 ) server_id_opt =l_get_u32 (v); -if (server->address != server_id_opt) -return ; -break ;case L_DHCP_OPTION_REQUESTED_IP_ADDRESS :if (l ==4 )
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 644
Quoted 6 lines
ell/dhcp-server.c +3
-0@@ -640,6 +639,9 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received DISCOVER, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); +if (server_id_opt && server_id_opt != server->address) +break ; +
So strictly speaking, according to DHCPDISCOVER from the client shouldn't even have this option...
Quoted 9 lines
ell/dhcp-server.c +0
-2send_offer (server, message, lease, requested_ip_opt);break ;@@ -647,27 +649,92 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received REQUEST, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); -if (requested_ip_opt ==0 ) { - requested_ip_opt = message->ciaddr;
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 660
Quoted 10 lines
ell/dhcp-server.c +8
-1-if (requested_ip_opt ==0 ) +/* +* RFC2131 Section 3.5: "Those servers not selected by the +* DHCPREQUEST message use the message as notification that +* the client has declined that server's offer." +*/ +if (server_id_opt && server_id_opt != server->address) { +if (server->authoritative) { +send_nak (server, message);break ;
So you send a NAK here if server_id_opt is provided and doesn't match...
Quoted 16 lines
ell/dhcp-server.c +7
-5- } + } -if (lease && requested_ip_opt == lease->address) { -send_ack (server, message, lease->address); +if (!lease || !lease->offering) +break ; + +remove_lease (server, lease);break ; } -if (server_id_opt || !lease) { -send_nak (server, message); +/* +* RFC2131 Section 3.5: "If the selected server is unable to
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 681
Quoted 10 lines
ell/dhcp-server.c +10
-0+* satisfy the DHCPREQUEST message (...), the server SHOULD +* respond with a DHCPNAK message." +* +* But: +* 4.3.2: "If the DHCP server has no record of this client, +* then it MUST remain silent (...)" +*/ +if (!lease) { +if (server_id_opt == server->address || + server->authoritative)
So why check server->authoritative here? It seems like you can only get to this point if the server_id_opt is provided and matches, or not provided at all. The 'server_id_opt ==' part also seems unsafe for those cases where server_id isn't provided at all...?
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 693
Quoted 12 lines
ell/dhcp-server.c +10
-0+send_nak (server, message); +break ; } + +/* +* 4.3.2: "If the DHCPREQUEST message contains a 'server +* identifier' option, the message is in response to a +* DHCPOFFER message. Otherwise, the message is a request +* to verify or extend an existing lease." +*/ +if (server_id_opt == server->address) {
Same here, checking server_id_opt seems unsafe?
Quoted 36 lines
ell/dhcp-server.c +36
-0+/* +* Allow either no 'requested IP address' option or +* a value identical with the one we offered because +* the spec is unclear on whether it is to be +* included: +* +* Section 4.3.2: "DHCPREQUEST generated during +* SELECTING state: (...) 'requested IP address' MUST +* be filled in with the yiaddr value from the chosen +* DHCPOFFER." +* +* but section 3.5 suggests only in the INIT-REBOOT +* state: "The 'requested IP address' option is to be +* filled in only in a DHCPREQUEST message when the +* client is verifying network parameters obtained +* previously." +*/ +if (!lease->offering || + (requested_ip_opt && + requested_ip_opt != lease->address)) { +send_nak (server, message); +break ; + } + }else { +/* +* 3.5: "If a server receives a DHCPREQUEST message +* with an invalid 'requested IP address', the server +* SHOULD respond to the client with a DHCPNAK message" +*/ +if (lease->offering || + (requested_ip_opt && + requested_ip_opt != lease->address)) { +send_nak (server, message); +break ; + } + }
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 737
Quoted 10 lines
ell/dhcp-server.c +4
-2+ +send_ack (server, message, lease->address);break ;case DHCP_MESSAGE_TYPE_DECLINE :SERVER_DEBUG ("Received DECLINE" ); -if (!server_id_opt || !requested_ip_opt || !lease || - !lease->offering) +if (server_id_opt != server->address || !requested_ip_opt || + !lease || !lease->offering)
This also seems unsafe? server_id must be present, but you're not checking this here?
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 748
Quoted 10 lines
ell/dhcp-server.c +2
-1break ;if (requested_ip_opt == lease->address)@@ -677,7 +744,8 @@ static void listener_event(const void *data, size_t len, void *user_data)case DHCP_MESSAGE_TYPE_RELEASE :SERVER_DEBUG ("Received RELEASE" ); -if (!server_id_opt || !lease || lease->offering) +if (server_id_opt != server->address || !lease || + lease->offering)
Or here?
Quoted 56 lines
ell/dhcp-server.c +13
-0break ;if (message->ciaddr == lease->address)@@ -687,6 +755,9 @@ static void listener_event(const void *data, size_t len, void *user_data)case DHCP_MESSAGE_TYPE_INFORM :SERVER_DEBUG ("Received INFORM" ); +if (server_id_opt && server_id_opt != server->address) +break ; +send_inform (server, message);break ; }@@ -732,6 +803,7 @@ LIB_EXPORT struct l_dhcp_server *l_dhcp_server_new(int ifindex) server->expired_list =l_queue_new (); server->started = false; + server->authoritative = true; server->lease_seconds =DEFAULT_DHCP_LEASE_SEC ; server->max_expired =MAX_EXPIRED_LEASES ;@@ -1053,6 +1125,15 @@ failed:return false; } +LIB_EXPORT void l_dhcp_server_set_authoritative(struct l_dhcp_server *server, +bool authoritative) +{ +if (unlikely (!server)) +return ; + + server->authoritative = authoritative; +} + LIB_EXPORT struct l_dhcp_lease *l_dhcp_server_discover( struct l_dhcp_server *server, uint32_t requested_ip_opt,ell/dhcp.h +2
-0@@ -141,6 +141,8 @@ bool l_dhcp_server_set_ip_address(struct l_dhcp_server *server,bool l_dhcp_server_set_netmask (struct l_dhcp_server *server,const char *mask);bool l_dhcp_server_set_gateway (struct l_dhcp_server *server,const char *ip);bool l_dhcp_server_set_dns (struct l_dhcp_server *server,char **dns); +void l_dhcp_server_set_authoritative (struct l_dhcp_server *server, +bool authoritative); struct l_dhcp_lease *l_dhcp_server_discover(struct l_dhcp_server *server, uint32_t requested_ip_opt,ell/ell.sym +0
-0
ell/ell.sym global: · line 265
Quoted 7 lines
ell/ell.sym +1
-0@@ -259,6 +259,7 @@ global: l_dhcp_server_set_netmask; l_dhcp_server_set_gateway; l_dhcp_server_set_dns; + l_dhcp_server_set_authoritative; l_dhcp_server_discover; l_dhcp_server_request; l_dhcp_server_decline;
Regards,
-Denis
Hi Denis,
Quoted 22 lines · Denis Kenzior
Quoted 13 lines · Andrew Zaborowski
An authoritative DHCP server basically assumes that there are no other DHCP servers on the network and replies to DHCPREQUEST messages requesting IPs from outside of its subnet or with a wrong server ID value. This speeds up connections from clients who try to use IP leases they have cached from other networks and who start their IP configuration by trying DHCPREQUESTs for those leases.
The term is not defined in the DHCP standard but is used by various implementations. Default to authoritative being true. When set to false, handle a DHCPREQUEST message directed at other servers by taking it as meaning the client is declining our own lease offer as mandated by RFC 2131 on page 16.
Quoted 7 lines
Refactor the checks in DHCPREQUEST handling quoting parts of the RFC. The new checks are stricter and I'm not preserving some of the checks that didn't seem justified, for example in the
"if (server_id_opt|| !lease) ...send_nak()" block it didn't seem to make sense to only reply to clients who have no lease (offered or active) and ignore those who do have a lease with a different IP address, the opposite would make more sense.
Quoted 2 lines
It seems like this is supposed to be handling the init-reboot, bound, renewing, rebinding states where
server_idisn't present...?
We were checking the opposite, i.e. we were sending a NAK if it *was* present.
However I was referring to the "!lease" part which seemed to be the opposite of what was desired because we were supposed to remain silent if we had no previous knowledge of the client.
Quoted 34 lines
Quoted 34 lines
--- ell/dhcp-server.c | 109 ++++++++++++++++++++++++++++++++++++++++------ ell/dhcp.h | 2 + ell/ell.sym | 1 + 3 files changed, 98 insertions(+), 14 deletions(-)ell/dhcp-server.c +2
-3@@ -87,6 +87,8 @@ struct l_dhcp_server {struct dhcp_transport *transport;struct l_acd *acd; + + bool authoritative : 1; };#define MAC "%02x:%02x:%02x:%02x:%02x:%02x"@@ -615,9 +617,6 @@ static void listener_event(const void *data, size_t len, void *user_data)if (l ==4 ) server_id_opt =l_get_u32 (v); -if (server->address != server_id_opt) -return ; -break ;case L_DHCP_OPTION_REQUESTED_IP_ADDRESS :if (l ==4 )@@ -640,6 +639,9 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received DISCOVER, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt));
Quoted 6 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 644
Quoted 3 lines
ell/dhcp-server.c +3
-0+if (server_id_opt && server_id_opt != server->address) +break ; +So strictly speaking, according to DHCPDISCOVER from the client shouldn't even have this option...
Ok, I can make this check stricter here. I preserved the original logic where we would ignore the whole message if (erver_id_opt != server->address) but otherwise we weren't checking whether the server_id was correct or absent.
Quoted 50 lines
Quoted 10 lines
ell/dhcp-server.c +0
-2send_offer (server, message, lease, requested_ip_opt);break ;@@ -647,27 +649,92 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received REQUEST, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); -if (requested_ip_opt ==0 ) { - requested_ip_opt = message->ciaddr;ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 660
Quoted 10 lines
ell/dhcp-server.c +8
-1-if (requested_ip_opt ==0 ) +/* +* RFC2131 Section 3.5: "Those servers not selected by the +* DHCPREQUEST message use the message as notification that +* the client has declined that server's offer." +*/ +if (server_id_opt && server_id_opt != server->address) { +if (server->authoritative) { +send_nak (server, message);break ;So you send a NAK here if
server_id_optis provided and doesn't match...Quoted 16 lines
ell/dhcp-server.c +7
-5- } + } -if (lease && requested_ip_opt == lease->address) { -send_ack (server, message, lease->address); +if (!lease || !lease->offering) +break ; + +remove_lease (server, lease);break ; } -if (server_id_opt || !lease) { -send_nak (server, message); +/* +* RFC2131 Section 3.5: "If the selected server is unable to ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 681
Quoted 10 lines
ell/dhcp-server.c +10
-0+* satisfy the DHCPREQUEST message (...), the server SHOULD +* respond with a DHCPNAK message." +* +* But: +* 4.3.2: "If the DHCP server has no record of this client, +* then it MUST remain silent (...)" +*/ +if (!lease) { +if (server_id_opt == server->address || + server->authoritative)
Quoted 2 lines
So why check
server->authoritativehere? It seems like you can only get to this point if theserver_id_optis provided and matches, or not provided at all.
Right, I guess I could have simply written (server_id_opt || server->authoritative) beause as you noted, we've already checked that if server_id was present, it was correct.
The server->authoritative part is so that we send a NAK if no server_id was provided and we know we're the only server on the network.
Quoted 3 lines
The
'server_id_opt==' part also seems unsafe for those cases whereserver_idisn't provided at all...?
server_id_opt would be 0 in that case, so if (server_id_opt == server->address) we know that it was present in the message and correct, i.e. addressed at us.
Quoted 15 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 693
Quoted 13 lines
ell/dhcp-server.c +10
-0+send_nak (server, message); +break ; } + +/* +* 4.3.2: "If the DHCPREQUEST message contains a 'server +* identifier' option, the message is in response to a +* DHCPOFFER message. Otherwise, the message is a request +* to verify or extend an existing lease." +*/ +if (server_id_opt == server->address) {Same here, checking
server_id_optseems unsafe?
Same comment as above.
Quoted 43 lines
Quoted 43 lines
ell/dhcp-server.c +38
-0+/* +* Allow either no 'requested IP address' option or +* a value identical with the one we offered because +* the spec is unclear on whether it is to be +* included: +* +* Section 4.3.2: "DHCPREQUEST generated during +* SELECTING state: (...) 'requested IP address' MUST +* be filled in with the yiaddr value from the chosen +* DHCPOFFER." +* +* but section 3.5 suggests only in the INIT-REBOOT +* state: "The 'requested IP address' option is to be +* filled in only in a DHCPREQUEST message when the +* client is verifying network parameters obtained +* previously." +*/ +if (!lease->offering || + (requested_ip_opt && + requested_ip_opt != lease->address)) { +send_nak (server, message); +break ; + } + }else { +/* +* 3.5: "If a server receives a DHCPREQUEST message +* with an invalid 'requested IP address', the server +* SHOULD respond to the client with a DHCPNAK message" +*/ +if (lease->offering || + (requested_ip_opt && + requested_ip_opt != lease->address)) { +send_nak (server, message); +break ; + } + } + +send_ack (server, message, lease->address);break ;case DHCP_MESSAGE_TYPE_DECLINE :SERVER_DEBUG ("Received DECLINE" );
Quoted 7 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 737
Quoted 4 lines
ell/dhcp-server.c +2
-2-if (!server_id_opt || !requested_ip_opt || !lease || - !lease->offering) +if (server_id_opt != server->address || !requested_ip_opt || + !lease || !lease->offering)This also seems unsafe?
server_idmust be present, but you're not checking this here?
Here we bail out if the server_id was absent (server_id_opt == 0) or incorrect (server_id_opt != 0 && server_id_opt != server->address), i.e. preserving the old logic.
Quoted 8 lines
Quoted 8 lines
ell/dhcp-server.c +0
-0break ;if (requested_ip_opt == lease->address)@@ -677,7 +744,8 @@ static void listener_event(const void *data, size_t len, void *user_data)case DHCP_MESSAGE_TYPE_RELEASE :SERVER_DEBUG ("Received RELEASE" );
Quoted 5 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 748
Quoted 3 lines
ell/dhcp-server.c +2
-1-if (!server_id_opt || !lease || lease->offering) +if (server_id_opt != server->address || !lease || + lease->offering)Or here?
Same as above.
Best regards
Hi Andrew,
Quoted 5 lines
We were checking the opposite, i.e. we were sending a NAK if it *was* present.
However I was referring to the "!lease" part which seemed to be the opposite of what was desired because we were supposed to remain silent if we had no previous knowledge of the client.
Okay, yep, it looks like the original logic got this wrong.
Quoted 11 lines
Quoted 10 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 644
Quoted 7 lines
ell/dhcp-server.c +3
-0@@ -640,6 +639,9 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received DISCOVER, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); +if (server_id_opt && server_id_opt != server->address) +break ; +So strictly speaking, according to DHCPDISCOVER from the client shouldn't even have this option...
Quoted 5 lines
Ok, I can make this check stricter here. I preserved the original logic where we would ignore the whole message if (
erver_id_opt!=server->address) but otherwise we weren't checking whether theserver_idwas correct or absent.
Well, the thing is that you've introduced a small ambiguity. Maybe it doesn't matter... but...
The prior logic looked at the server_id option if present and compared to our own server id. So the only way you get past the pre-check is if the server_id matched or was omitted entirely.
But now, you can have server_id option from the client that is equal to '0', and we treat both the same. So ideally this should be tightened up a bit.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
ell/dhcp-server.c +0
-0send_offer (server, message, lease, requested_ip_opt);break ;@@ -647,27 +649,92 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received REQUEST, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt));
Quoted 9 lines
Quoted 9 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 657
Quoted 9 lines
ell/dhcp-server.c +6
-3-if (requested_ip_opt ==0 ) { - requested_ip_opt = message->ciaddr; -if (requested_ip_opt ==0 ) +/* +* RFC2131 Section 3.5: "Those servers not selected by the +* DHCPREQUEST message use the message as notification that +* the client has declined that server's offer." +*/ +if (server_id_opt && server_id_opt != server->address) {
This is inconsistent with how you do the server_id_opt checks later on. I should have checked the original and not just the diff, but from the diff it seemed like server_id_opt was meant to be a pointer. Not sure why my brain didn't register that there was no dereference. So you can ignore some of my comments based on the above.
Quoted 36 lines
Quoted 33 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 660
Quoted 3 lines
ell/dhcp-server.c +2
-0+if (server->authoritative) { +send_nak (server, message);break ;So you send a NAK here if
server_id_optis provided and doesn't match...Quoted 16 lines
ell/dhcp-server.c +7
-5- } + } -if (lease && requested_ip_opt == lease->address) { -send_ack (server, message, lease->address); +if (!lease || !lease->offering) +break ; + +remove_lease (server, lease);break ; } -if (server_id_opt || !lease) { -send_nak (server, message); +/* +* RFC2131 Section 3.5: "If the selected server is unable to ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 681
Quoted 10 lines
ell/dhcp-server.c +10
-0+* satisfy the DHCPREQUEST message (...), the server SHOULD +* respond with a DHCPNAK message." +* +* But: +* 4.3.2: "If the DHCP server has no record of this client, +* then it MUST remain silent (...)" +*/ +if (!lease) { +if (server_id_opt == server->address || + server->authoritative)Quoted 2 lines
So why check
server->authoritativehere? It seems like you can only get to this point if theserver_id_optis provided and matches, or not provided at all.
Quoted 7 lines
Right, I guess I could have simply written (
server_id_opt||server->authoritative) beause as you noted, we've already checked that ifserver_idwas present, it was correct.The
server->authoritativepart is so that we send a NAK if noserver_idwas provided and we know we're the only server on the network.
Okay, makes sense.
Regards,
-Denis
Quoted 20 lines · Denis Kenzior
Quoted 11 lines
Quoted 10 lines
ell/dhcp-server.c static void listener_event(const void *data, size_t len, void *user_data) · line 644
Quoted 7 lines
ell/dhcp-server.c +3
-0@@ -640,6 +639,9 @@ static void listener_event(const void *data, size_t len, void *user_data)SERVER_DEBUG ("Received DISCOVER, requested IP " NIPQUAD_FMT ,NIPQUAD (requested_ip_opt)); +if (server_id_opt && server_id_opt != server->address) +break ; +So strictly speaking, according to DHCPDISCOVER from the client shouldn't even have this option...
Quoted 5 lines
Ok, I can make this check stricter here. I preserved the original logic where we would ignore the whole message if (
erver_id_opt!=server->address) but otherwise we weren't checking whether theserver_idwas correct or absent.Well, the thing is that you've introduced a small ambiguity. Maybe it doesn't matter... but...
Quoted 6 lines
The prior logic looked at the
server_idoption if present and compared to our own server id. So the only way you get past the pre-check is if theserver_idmatched or was omitted entirely.But now, you can have
server_idoption from the client that is equal to '0', and we treat both the same. So ideally this should be tightened up a bit.
True, if the client includes a 0 server_id we'd treat it as if the option was omitted. Let me replace uint32_t server_id_opt with a bool server_id_opt and a bool server_id_match.
Best regards