jaredhendrickson13 / pfsense-api

The missing REST and GraphQL API package for pfSense
https://pfrest.org/
Apache License 2.0
690 stars 106 forks source link

Cannot PATCH LAN interface without gateway field specified #564

Closed digitalm8 closed 2 months ago

digitalm8 commented 2 months ago

Describe the bug I've got the error while updating an assigned LAN interface.

Before update it looks like:

Array
(
    [id] => lan
    [if] => ixl2.1
    [enable] => 1
    [descr] => LAN
    [spoofmac] =>
    [mtu] =>
    [mss] =>
    [media] =>
    [mediaopt] =>
    [blockpriv] =>
    [blockbogons] =>
    [typev4] => static
    [ipaddr] => 192.168.4.189
    [subnet] => 22
    [gateway] =>
    [dhcphostname] =>
    [alias_address] =>
    [alias_subnet] =>
    [dhcprejectfrom] =>
    [adv_dhcp_config_advanced] =>
    [adv_dhcp_pt_values] =>
    [adv_dhcp_pt_timeout] =>
    [adv_dhcp_pt_retry] =>
    [adv_dhcp_pt_select_timeout] =>
    [adv_dhcp_pt_reboot] =>
    [adv_dhcp_pt_backoff_cutoff] =>
    [adv_dhcp_pt_initial_interval] =>
    [adv_dhcp_send_options] =>
    [adv_dhcp_request_options] =>
    [adv_dhcp_required_options] =>
    [adv_dhcp_option_modifiers] =>
    [adv_dhcp_config_file_override] =>
    [adv_dhcp_config_file_override_path] =>
    [typev6] => none
    [ipaddrv6] =>
    [subnetv6] =>
    [gatewayv6] =>
    [ipv6usev4iface] =>
    [slaacusev4iface] =>
    [prefix_6rd] =>
    [gateway_6rd] =>
    [prefix_6rd_v4plen] =>
    [track6_interface] => wan
    [track6_prefix_id_hex] =>
)

The response is:

URL: https://192.168.4.189/api/v2/interface
PATCH REQUEST: {"id":"lan","if":"ixl2.1","enable":true,"descr":"A","typev4":"static","ipaddr":"192.168.4.1","subnet":22,"dhcphostname":"host-a","typev6":"none"}
Array
(
    [code] => 400
    [status] => bad request
    [response_id] => FIELD_EMPTY_NOT_ALLOWED
    [message] => Field `gateway` cannot be empty.
    [data] => Array
        (
        )
)

Expected behavior I can create (POST) any LAN interface without gateway specified. But why API requires gateway on update (PATCH)?

pfSense Version & Package Version:

Affected Endpoints: PATCH /api/v2/interface

digitalm8 commented 2 months ago

Cannot reproduce the error. This LAN interface was initially created on installation procedure. After editing the interface in the UI, everything started working.

jaredhendrickson13 commented 2 months ago

This would be expected for the default LAN interface since it is created with the gateway field as an empty string instead of null. pfSense often treats null and empty values the same. But the REST API enforces a strict schema that does not treat these values the same. In the case of the gateway field, it is nullable. Including {"gateway": null} should nullify the empty string and allow the PATCH to go through.

digitalm8 commented 2 months ago

Thank you very much for your reply. I will definitely take this into account when forming requests.