Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get IDs of "Read Routing Gateway" #110

Closed
edenzv opened this issue Mar 21, 2021 · 5 comments · Fixed by #113
Closed

Cannot get IDs of "Read Routing Gateway" #110

edenzv opened this issue Mar 21, 2021 · 5 comments · Fixed by #113
Assignees
Labels
breaking change Requires changes that may breaking existing usage bug Something isn't working documentation Improvements or additions to documentation

Comments

@edenzv
Copy link

edenzv commented Mar 21, 2021

Hi,

I want to delete routing gateway but I cannot find the ID in the request of "Read Routing Gateway".

Thanks Eden

@jaredhendrickson13
Copy link
Owner

Hey!

This is because pfSense doesn't store object IDs, rather they use the configuration array index value of the object. This is outlined in the documentation here. Or you can refer to #90 for some examples and info on future plans for obtaining object IDs.

Let me know if you have any troubles.

Thanks!

@edenzv
Copy link
Author

edenzv commented Mar 22, 2021

Hey,

Thanks o the quick response, I also did your recommend before and tried it again, but I tried to remove by the ID and it remove other that I didn't meant to remove:

This is the gateways list in pfSense webgui:
image

This is the output of GET https://pfSense/api/v1/routing/gateway in postman:
image

I need to removed "WANCP1" and from the documentation this ID is 1 but it removed a different gateway (LANGW):
image

And after check the gateway list I found that it removed different gateway (WAN11):
image

I hope that you understood this use case.

Thanks Eden

@jaredhendrickson13
Copy link
Owner

Thanks for these details. Looking further into the code, I do see there is a discrepancy on this endpoint between the GET and DELETE requests. Typically, GET requests read the pfSense configuration directly but in this case the function it calls seems to return some detailed backend values for gateways that are not expected.

In the short term, I do see a workaround you can use today. Making a GET request to /api/v1/routing/gateway does seem to return the ID within the response data itself, more specifically the attribute field of the object is the ID. If the object does not contain a numeric value in the attribute field, it cannot be deleted as it's a system-defined gateway.

For example, GET requests to /api/v1/routing/gateway currently return this:

{
  "status": "ok",
  "code": 200,
  "return": 0,
  "message": "Success",
  "data": {
    "EXAMPLE_GW_1": {
      "interface": "em0",
      "gateway": "172.16.209.2",
      "name": "EXAMPLE_GW_1",
      "weight": "1",
      "ipprotocol": "inet",
      "descr": "",
      "monitor": "172.16.209.2",
      "friendlyiface": "wan",
      "friendlyifdescr": "WAN",
      "attribute": 0,    # <----- This object uses ID 0
      "tiername": ""
    },
    "EXAMPLE_GW_2": {
      "interface": "em0",
      "gateway": "172.16.209.12",
      "name": "EXAMPLE_GW_2",
      "weight": "1",
      "ipprotocol": "inet",
      "descr": "",
      "monitor": "172.16.209.12",
      "friendlyiface": "wan",
      "friendlyifdescr": "WAN",
      "attribute": 1,    # <----- This object uses ID 1
      "tiername": ""
    },
    "Null4": {
      "name": "Null4",
      "interface": "lo0",
      "ipprotocol": "inet",
      "gateway": "127.0.0.1",
      "attribute": "system",    # <----- This object cannot be deleted as it is a system gateway
      "tiername": ""
    }
  }
}

In the long term, this does express the need to move the current GET response to a different endpoint that can be used to retrieve these more detailed/non-configuration gateway values. Then in it's place, the GET response for this endpoint should be refactored to only return gateways as they appear in the configuration. Since this requires a breaking change, I will include the code change in the v1.3.0 workflow. For now, I will add a snippet to the documentation that details this discrepancy in the next release (v1.2.0). I'll keep this issue updated as these changes are implemented.

Thanks again for pointing this out. I appreciate it.

@jaredhendrickson13 jaredhendrickson13 self-assigned this Mar 22, 2021
@jaredhendrickson13 jaredhendrickson13 added breaking change Requires changes that may breaking existing usage bug Something isn't working documentation Improvements or additions to documentation labels Mar 22, 2021
@edenzv
Copy link
Author

edenzv commented Mar 24, 2021

Hey,

I'm very appreciate your advices.
I tried the workaround of remove the attribute, and I got response that it removed the right gateway but it removed a different gateway:

Need to removed "WANCP_Internet", and the attribute is 5:
image

Send delete request and got response that it removed:
image

I see the list of the existing gateways and see that "WANCP_Internet" is existing and "WANGW_2" has been removed:
image

I hope that you understood this use case.

Thanks Eden

@jaredhendrickson13
Copy link
Owner

Thanks for your patience.I spent some time yesterday looking deeper into this and I did find that in some scenarios the IDs become misaligned from the configuration, which seems to be what is causing this. I found I was able to reproduce this when either:

  1. the gateway order has been re-arranged within the UI
  2. gateways exist for multiple interfaces and were added out of order, or a gateway was deleted

I can actually reproduce the mismatched ID in the pfSense UI as well, however, it seems to work some magic to somehow map this magic ID back to it's actual ID which is something the API endpoint is missing. I'll work on a fix for this and have it included in the next patch. I'll update this issue when I have a pull request for the patch, which will include a test build so you can verify it fixes this issue for you.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Requires changes that may breaking existing usage bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants