ethernet: Fix premature gateway clearing on static IP validation fail

When a PATCH request contains invalid IPv4 static addresses, the
gateway was being incorrectly cleared even though the static IP
configuration failed validation. This occurred because
HandleDHCPPatch function would clear the gateway based on the current
DHCP state without validating the static addresses first.
```
Problem:
- handleDHCPPatch() runs before handleIPv4StaticPatch()
- If DHCP was currently active, gateway got cleared immediately
- When static IP validation later failed, gateway remained cleared
- This caused working DHCP configurations to lose their gateway

Example scenario:
1. System has working DHCP: IP=10.0.2.15, Gateway=10.0.2.2
2. User sends PATCH with invalid static IP: Gateway="10.3.36"
3. handleDHCPPatch() clears gateway because DHCP is currently active
4. handleIPv4StaticPatch() fails validation and returns early
5. Result: Gateway lost (shows as 0.0.0.0), network potentially
   broken
  "IPv4Addresses": [
    {
      "Address": "10.0.2.15",
      "AddressOrigin": "DHCP",
      "Gateway": "0.0.0.0",
      "SubnetMask": "255.255.255.0"
    }
  ]

Solution:
- Add pre-validation of IPv4 static addresses before
  handleDHCPPatch()
- Only clear gateway when DHCP is currently active AND IPv4 static
  addresses are valid
- This handles the implicit DHCP→Static transition correctly
- Preserve existing gateway when static IP validation fails
- Ensure failed requests don't have side effects on working config

Logic:
- If system uses DHCP AND user provides valid static addresses:
  Clear DHCP gateway to prepare for clean transition to static
- If static addresses are invalid: Preserve existing DHCP gateway
- If system already uses static config: No gateway clearing needed

Changes:
- Modified handleDHCPPatch() to accept hasValidIPv4StaticAddresses
  parameter
- Added pre-validation step in main PATCH handler using
  parseAddresses()
- Changed gateway clearing condition from dhcpBeingEnabled to
  ipv4Active
- Added safety check to prevent clearing gateway on validation
  failures

Testing:
- PATCH with invalid static IPs no longer affects working DHCP
  gateway
- PATCH with valid static IPs on DHCP system properly clears
  gateway for clean transition
- Mixed requests handle validation failures gracefully
- Static-to-static updates work without unnecessary gateway
  clearing

~$ curl -k -N -X GET https://root:0penBmc@127.0.0.1:2443/redfish/v1/Managers/bmc/EthernetInterfaces/eth0
{
  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
  "@odata.type": "#EthernetInterface.v1_9_0.EthernetInterface",
  "DHCPv4": {
    "DHCPEnabled": true,
    "UseDNSServers": true,
    "UseDomainName": true,
    "UseNTPServers": true
  },
  "DHCPv6": {
    "OperatingMode": "Enabled",
    "UseDNSServers": true,
    "UseDomainName": true,
    "UseNTPServers": true
  },
  "Description": "Management Network Interface",
  "EthernetInterfaceType": "Physical",
  "FQDN": "gb200nvl-bmc",
  "HostName": "gb200nvl-bmc",
  "IPv4Addresses": [
    {
      "Address": "10.0.2.15",
      "AddressOrigin": "DHCP",
      "Gateway": "10.0.2.2",
      "SubnetMask": "255.255.255.0"
    }
  ],
  "IPv4StaticAddresses": [],
  "IPv6AddressPolicyTable": [],
  "IPv6Addresses": [
    {
      "Address": "fe80::86:6cff:feb4:1b3b",
      "AddressOrigin": "LinkLocal",
      "PrefixLength": 64
    },
    {
      "Address": "fec0::86:6cff:feb4:1b3b",
      "AddressOrigin": "DHCPv6",
      "PrefixLength": 64
    }
  ],
  "IPv6DefaultGateway": "fe80::2",
  "IPv6StaticAddresses": [],
  "IPv6StaticDefaultGateways": [],
  "Id": "eth0",
  "InterfaceEnabled": true,
  "LinkStatus": "LinkUp",
  "MACAddress": "02:86:6c:b4:1b:3b",
  "MTUSize": 1500,
  "Name": "Manager Ethernet Interface",
  "NameServers": [
    "10.0.2.3"
  ],
  "SpeedMbps": 100,
  "StatelessAddressAutoConfig": {
    "IPv6AutoConfigEnabled": true
  },
  "StaticNameServers": [],
  "Status": {
    "Health": "OK",
    "State": "Enabled"
  }
}
~$ curl -k -N -X PATCH https://root:0penBmc@127.0.0.1:2443/redfish/v1/Managers/bmc/EthernetInterfaces/eth0 -H "Content-Type: application/json"  -d '{"IPv4StaticAddresses": [{"Address": "10.7.7.7", "SubnetMask": "255.255.0.0", "Gateway": "10.3.36"}]}' -v
< HTTP/1.1 400 Bad Request
< Allow: DELETE, GET, PATCH
< OData-Version: 4.0
< Strict-Transport-Security: max-age=31536000; includeSubdomains
< Pragma: no-cache
< Cache-Control: no-store, max-age=0
< X-Content-Type-Options: nosniff
< Content-Type: application/json
< Date: Wed, 06 Aug 2025 17:50:08 GMT
< Content-Length: 1138
<
{
  "IPv4StaticAddresses/0/Address@Message.ExtendedInfo": [
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The value '\"\"' for the property IPv4StaticAddresses/0/Address is not a format that the property can accept.",
      "MessageArgs": [
        "\"\"",
        "IPv4StaticAddresses/0/Address"
      ],
      "MessageId": "Base.1.19.PropertyValueFormatError",
      "MessageSeverity": "Warning",
      "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed."
    }
  ],
  "IPv4StaticAddresses/0/Gateway@Message.ExtendedInfo": [
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The value '\"10.3.36\"' for the property IPv4StaticAddresses/0/Gateway is not a format that the property can accept.",
      "MessageArgs": [
        "\"10.3.36\"",
        "IPv4StaticAddresses/0/Gateway"
      ],
      "MessageId": "Base.1.19.PropertyValueFormatError",
      "MessageSeverity": "Warning",
      "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed."
    }
  ]
}
$ curl -k -N -X GET https://root:0penBmc@127.0.0.1:2443/redfish/v1/Managers/bmc/EthernetInterfaces/eth0
{
  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
  "@odata.type": "#EthernetInterface.v1_9_0.EthernetInterface",
  "DHCPv4": {
    "DHCPEnabled": true,
    "UseDNSServers": true,
    "UseDomainName": true,
    "UseNTPServers": true
  },
  "DHCPv6": {
    "OperatingMode": "Enabled",
    "UseDNSServers": true,
    "UseDomainName": true,
    "UseNTPServers": true
  },
  "Description": "Management Network Interface",
  "EthernetInterfaceType": "Physical",
  "FQDN": "gb200nvl-bmc",
  "HostName": "gb200nvl-bmc",
  "IPv4Addresses": [
    {
      "Address": "10.0.2.15",
      "AddressOrigin": "DHCP",
      "Gateway": "10.0.2.2",
      "SubnetMask": "255.255.255.0"
    }
  ],
  "IPv4StaticAddresses": [],
  "IPv6AddressPolicyTable": [],
  "IPv6Addresses": [
    {
      "Address": "fe80::86:6cff:feb4:1b3b",
      "AddressOrigin": "LinkLocal",
      "PrefixLength": 64
    },
    {
      "Address": "fec0::86:6cff:feb4:1b3b",
      "AddressOrigin": "DHCPv6",
      "PrefixLength": 64
    }
  ],
  "IPv6DefaultGateway": "fe80::2",
  "IPv6StaticAddresses": [],
  "IPv6StaticDefaultGateways": [],
  "Id": "eth0",
  "InterfaceEnabled": true,
  "LinkStatus": "LinkUp",
  "MACAddress": "02:86:6c:b4:1b:3b",
  "MTUSize": 1500,
  "Name": "Manager Ethernet Interface",
  "NameServers": [
    "10.0.2.3"
  ],
  "SpeedMbps": 100,
  "StatelessAddressAutoConfig": {
    "IPv6AutoConfigEnabled": true
  },
  "StaticNameServers": [],
  "Status": {
    "Health": "OK",
    "State": "Enabled"
  }
}

```

Change-Id: Ic841344051681896bb6a0d3f8552ea9dfd92de9f
Signed-off-by: Chandramohan Harkude <chandramohan.harkude@gmail.com>
1 file changed
tree: 16c8c807964208d369807e96c7ef0f89701171c3
  1. .github/
  2. config/
  3. docs/
  4. features/
  5. http/
  6. include/
  7. redfish-core/
  8. scripts/
  9. src/
  10. static/
  11. subprojects/
  12. test/
  13. .clang-format
  14. .clang-tidy
  15. .codespell-ignore
  16. .dockerignore
  17. .eslintignore
  18. .gitignore
  19. .markdownlint.yaml
  20. .openbmc-enforce-gitlint
  21. .prettierignore
  22. .shellcheck
  23. DEVELOPING.md
  24. LICENSE
  25. meson.build
  26. meson.options
  27. OWNERS
  28. README.md
  29. run-ci
README.md

OpenBMC webserver

This component attempts to be a "do everything" embedded webserver for OpenBMC.

Features

The webserver implements a few distinct interfaces:

  • DBus event websocket. Allows registering on changes to specific dbus paths, properties, and will send an event from the websocket if those filters match.
  • OpenBMC DBus REST api. Allows direct, low interference, high fidelity access to dbus and the objects it represents.
  • Serial: A serial websocket for interacting with the host serial console through websockets.
  • Redfish: A protocol compliant, DBus to Redfish translator.
  • KVM: A websocket based implementation of the RFB (VNC) frame buffer protocol intended to mate to webui-vue to provide a complete KVM implementation.

Protocols

bmcweb at a protocol level supports http and https. TLS is supported through OpenSSL. Http1 and http2 are supported using ALPN registration for TLS connections and h2c upgrade header for http connections.

AuthX

Authentication

Bmcweb supports multiple authentication protocols:

  • Basic authentication per RFC7617
  • Cookie based authentication for authenticating against webui-vue
  • Mutual TLS authentication based on OpenSSL
  • Session authentication through webui-vue
  • XToken based authentication conformant to Redfish DSP0266

Each of these types of authentication is able to be enabled or disabled both via runtime policy changes (through the relevant Redfish APIs) or via configure time options. All authentication mechanisms supporting username/password are routed to libpam, to allow for customization in authentication implementations.

Authorization

All authorization in bmcweb is determined at routing time, and per route, and conform to the Redfish PrivilegeRegistry.

*Note: Non-Redfish functions are mapped to the closest equivalent Redfish privilege level.

Configuration

bmcweb is configured per the meson build files. Available options are documented in meson_options.txt

Compile bmcweb with default options

meson setup builddir
ninja -C builddir

If any of the dependencies are not found on the host system during configuration, meson will automatically download them via its wrap dependencies mentioned in bmcweb/subprojects.

Use of persistent data

bmcweb relies on some on-system data for storage of persistent data that is internal to the process. Details on the exact data stored and when it is read/written can seen from the persistent_data namespace.

TLS certificate generation

When SSL support is enabled and a usable certificate is not found, bmcweb will generate a self-signed a certificate before launching the server. Please see the bmcweb source code for details on the parameters this certificate is built with.

Compression

bmcweb supports various forms of http compression, including zstd and gzip. Client headers are observed to determine whether compressed payloads are supported.

Redfish Aggregation

bmcweb is capable of aggregating resources from satellite BMCs. Refer to AGGREGATION.md for more information on how to enable and use this feature.