Bug 273640

Summary: route delete fails when specifying -iface
Product: Base System Reporter: mmendoza
Component: kernAssignee: freebsd-net (Nobody) <net>
Status: Closed FIXED    
Severity: Affects Some People CC: freebsd, rcm, zlei
Priority: ---    
Version: 14.0-CURRENT   
Hardware: Any   
OS: Any   

Description mmendoza 2023-09-08 19:08:30 UTC
route(8) fails to delete routes when the interface is specified.

Example route:
# route show -inet default
   route to: default
destination: default
       mask: default
    gateway: 10.0.5.1
        fib: 0
  interface: vmx0
      flags: <UP,GATEWAY,DONE,STATIC>
 recvpipe  sendpipe  ssthresh  rtt,msec    mtu       weight    expire
       0         0         0         0      1500        0         0

On FreeBSD 12.3-STABLE:
# route del -inet default -iface vmx0
del net default: gateway vmx0

On FreeBSD 14.0-CURRENT:
# route del -inet default -iface vmx0
route: route has not been found
del net default: gateway vmx0 fib 0: not in table
Comment 1 Mina Galić freebsd_triage 2023-09-08 19:17:40 UTC
is this with or without netlink?
Comment 2 mmendoza 2023-09-08 20:04:52 UTC
In the 12.3 test, without netlink; in the 14.0 test, with netlink.

Further tests indicate that it's only an issue with combining both "-inet" and "-iface" (IPv6 works), and only when the CIDR size is omitted. This works:
# route del -inet 192.168.1.0/24 -iface vmx0
Comment 3 Mina Galić freebsd_triage 2023-09-08 20:09:03 UTC
i seem to have figured most of that out, too, when writing this code

https://github.com/canonical/cloud-init/blob/main/cloudinit/net/netops/bsd_netops.py#L35

(contrast the Linux Code here, it's based on: https://github.com/canonical/cloud-init/blob/main/cloudinit/net/netops/iproute2.py#L51 )
Comment 4 Zhenlei Huang freebsd_committer freebsd_triage 2023-09-09 10:26:38 UTC
(In reply to mmendoza from comment #0)

> Example route:
> # route show -inet default
>    route to: default
> destination: default
>        mask: default
>     gateway: 10.0.5.1
>         fib: 0
>   interface: vmx0
>       flags: <UP,GATEWAY,DONE,STATIC>
>  recvpipe  sendpipe  ssthresh  rtt,msec    mtu       weight    expire
       0         0         0         0      1500        0         0

Option `-iface` of route(8) is for directly connected route. In the above example, the `default` or `0.0.0.0/0` is not directly connected. It does not make sense if you try to delete it with option `-iface`.


(In reply to mmendoza from comment #2)
> Further tests indicate that it's only an issue with combining both "-inet" and
> "-iface" (IPv6 works), and only when the CIDR size is omitted. This works:
> # route del -inet 192.168.1.0/24 -iface vmx0

I bet your route `192.168.1.0/24` is directly connected. It may looks like:
```
   route to: 192.168.1.0
destination: 192.168.1.0
       mask: 255.255.255.0
        fib: 0
  interface: vmx0
      flags: <UP,DONE,PINNED>
 recvpipe  sendpipe  ssthresh  rtt,msec    mtu       weight    expire
       0         0         0         0      1500        1         0
```
Comment 5 mmendoza 2023-09-09 14:46:18 UTC
It fails either way.
Comment 6 Zhenlei Huang freebsd_committer freebsd_triage 2023-09-10 04:49:28 UTC
(In reply to mmendoza from comment #5)
Can you share your route table ?
Comment 7 mmendoza 2023-09-12 00:15:48 UTC
(In reply to Zhenlei Huang from comment #6)
The test was on a system with a single interface where "10.0.5.1" is the connected network and "192.168.1.0/24" is a manually-added static route. I can recreate the test and pull the output if needed.
Comment 8 mmendoza 2023-09-13 17:22:50 UTC
Closing this as fixed - I am not able to reproduce it on more recent 14.0-ALPHA builds. For reference, it seems to have been fixed between src commits 680ad06f and b23dbabb.