opnsense / core

OPNsense GUI, API and systems backend
https://opnsense.org/
BSD 2-Clause "Simplified" License
3.26k stars 725 forks source link

Fail to save static gateway for wan interface when choosing from existed interface items #5165

Closed lifesboy closed 2 years ago

lifesboy commented 3 years ago

Important notices

Describe the bug

Choose an existed static gateway for wan interface then click on save. It's saving old gateway, not new gateway.

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'Interfaces > [WAN]'
  2. Click on 'IPv4 Upstream Gateway'
  3. Select another existed gateway item.(ex: current selected is: 'WAN_GWv46', select new gateway is 'WAN_GWv4')
  4. Click on 'Save'
  5. Check last saved backup file in: '/conf/backup/'
  6. Verify key: ...<interfaces><wan><gateway>{saved_value}</gateway></wan>... saved_value is old: 'WAN_GWv46'

Expected behavior saved_value should be new gateway: 'WAN_GWv4'

Describe alternatives you considered in src/www/interfaces.php#L1341, it's updating $a_interfaces[$if] = $new_config but write_config() is saving global $config, which is not updated with $new_config. https://github.com/opnsense/core/blob/41a0a938f844f96450bc13dc35a9102016e650fd/src/www/interfaces.php#L1341

Screenshots

image image

Relevant log files

<interfaces>
    <wan>
      <if>eno1</if>
      <descr>WAN</descr>
      <enable>1</enable>
      <spoofmac/>
      <blockpriv>1</blockpriv>
      <blockbogons>1</blockbogons>
      <ipaddr>192.168.1.18</ipaddr>
      <subnet>24</subnet>
      <gateway>WAN_GWv46</gateway>
    </wan>
...
fichtner commented 2 years ago

I cannot reproduce this. $a_interfaces is a reference to $config[interfaces]:

https://github.com/opnsense/core/blob/ea7709e2683f2754b7fb2150679020fef9964b80/src/www/interfaces.php#L310

Cheers, Franco

lifesboy commented 2 years ago

After use latest from master branch, this issue has been fixed. Thank you for your support!