Remove IP addresses by position, ID or address

2 days ago

When you ask the server to remove an IP address, RouterOS lets you point at it three ways. By its position in the printed list, by its internal ID, or by the address itself. This pull request makes both the IPv4 and the IPv6 remove tools accept all three. Before, only the internal ID and the address value worked, and a plain position number quietly failed.

Ask about this presentation

Chapters

  1. 0:00The change
  2. 0:25The bug
  3. 0:50The fix
  4. 1:16Evidence and review
Show transcript
  1. When you ask the server to remove an IP address, RouterOS lets you point at it three ways. By its position in the printed list, by its internal ID, or by the address itself. This pull request makes both the IPv4 and the IPv6 remove tools accept all three. Before, only the internal ID and the address value worked, and a plain position number quietly failed.

    Slide text

    Removing an IP address now works by position, ID, or address.

    remove_ip_address and remove_ipv6_address

  2. Here's what went wrong. The old tool counted matches with a where clause on the internal ID. Give it a position like zero, and RouterOS finds no item with that ID, so the count comes back zero. The tool then tried the address value lookup, found nothing there either, and told you the address didn't exist. The address was sitting right there. This is the problem reported in issues 154 and 109.

    Slide text

    A position number matched nothing.

    The old check compared the position to the internal ID.

    before
    print count-only where .id="0"
    => 0, so "not found"
  3. The fix reuses two helpers that already exist in the selectors module, resolve item ID and item count. A number is turned into a real internal ID by asking RouterOS for the item at that position. A star prefixed ID passes straight through. If neither resolves, the tool falls back to matching the address value, as it did before. The IPv6 tool gets the same treatment.

    Slide text

    Resolve the item first, then fall back to the address.

    1. Position resolves to an internal ID
    2. Internal ID is used as given
    3. Otherwise, look up by address value
  4. The change comes with a new unit test file for IPv4 removal and an extended one for IPv6. The author lists the lint checks, the unit tests and the API coverage check as passing. Jeff Nasseri approved it and it has merged. If you review anything, look at the fallback order. A value that looks like an ID or a number is tried as a selector first, and only then as an address.

    Slide text

    Tests cover the new selectors for both address families.

    • New unit tests for IPv4 removal
    • IPv6 tests extended
    • Approved, then merged

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York