Skip to content

Commit

Permalink
Extend 204/404 logic to /dhcp/leases/{ip}
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Jan 7, 2024
1 parent 85e3d4d commit 1d83e39
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/api/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ int api_dhcp_leases_DELETE(struct ftl_conn *api)
// Send empty reply with code 204 No Content
return send_json_error(api,
400,
"bad_request",
"bad_request",
"The provided IPv4 address is invalid",
api->item);
api->item);
}

// Delete lease
log_debug(DEBUG_API, "Deleting DHCP lease for address %s", api->item);
FTL_unlink_DHCP_lease(api->item);
const bool found = FTL_unlink_DHCP_lease(api->item);

// Send empty reply with code 204 No Content
// Send empty reply with codes:
// - 204 No Content (if a lease was deleted)
// - 404 Not Found (if no lease was found)
cJSON *json = JSON_NEW_OBJECT();
JSON_SEND_OBJECT_CODE(json, 204);
JSON_SEND_OBJECT_CODE(json, found ? 204 : 404);
}
6 changes: 6 additions & 0 deletions src/api/docs/content/specs/dhcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ components:
responses:
'204':
description: Item deleted
'404':
description: Item not found
content:
application/json:
schema:
$ref: 'common.yaml#/components/schemas/took'
'400':
description: Bad request
content:
Expand Down
1 change: 1 addition & 0 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3263,6 +3263,7 @@ bool FTL_unlink_DHCP_lease(const char *ipaddr)
#endif
else
{
// Invalid IP address or no lease found
return false;
}

Expand Down

0 comments on commit 1d83e39

Please sign in to comment.