A follow-up to my report: the diff I sent only seems to cover part of
the problem.  For your consideration, a different diff is below.

The diff I sent refuses the move only when the loopback already lives
in a non-default rdomain ("loifp->if_rdomain != 0").  Moving it from
rdomain 0 still skips the teardown, for the same reason as before:
if_createrdomain() sets loifp->if_rdomain = N, so if_setrdomain() then
sees no change and skips if_down/rti_delete/in_ifdetach/in6_ifdetach.
The connected route stays in table 0 and outlives the interface:

    ifconfig lo206 create
    ifconfig lo206 inet 192.0.2.6/24
    ifconfig lo206 rdomain 206         # moved, teardown skipped
    ifconfig lo206 destroy
    route -n show -inet | grep 192.0.2.6     # route still in table 0
    route -n delete 192.0.2.6                # "not in table"

No panic here (table 0 is never removed), but the route is left in
table 0 after the interface is gone and cannot be deleted.

The diff below tries to address the cause instead of refusing the
move: when the interface being moved is the loopback itself,
if_createrdomain() leaves its if_rdomain alone, so if_setrdomain()
does the normal teardown and then moves it.  In my tests both cases
behave correctly with it, and "ifconfig loN rdomain N" keeps working
(with the diff I sent, moving a loopback out of a non-default rdomain
returned EBUSY).  It also removes a write of if_rdomain that
if_createrdomain() did without NET_LOCK; no lock is added.

Please consider this diff instead of the previous diff as a proposal
for discussion

Index: sys/net/if.c
===================================================================
--- sys/net/if.c
+++ sys/net/if.c
@@ -2043,7 +2043,14 @@ if_createrdomain(struct ifnet *ifp, unsi
                return (error);
        }
 
-       loifp->if_rdomain = rdomain;
+       /*
+        * If the loopback is the interface being moved, leave its
+        * rdomain alone: if_setrdomain() tears down its old rdomain
+        * state and then moves it.  Setting it here would make
+        * if_setrdomain() skip that teardown.
+        */
+       if (loifp != ifp)
+               loifp->if_rdomain = rdomain;
        rtable_l2set(rdomain, rdomain, loifp->if_index);
        if_put(loifp);
 

Tested on master afb08c4d5 GENERIC.MP, amd64, built without warnings
from one clean tree: unpatched md5 eaeed0ca, patched md5 5c885129, my
earlier diff md5 3d89d1fc.  Fresh boot before every run, 2 vcpus:

                        unpatched     earlier diff     this diff
  original report       3/3 panic     move refused     3/3 ok
  (inet, 204 -> 206)                  (EBUSY)
  same with inet6       3/3 panic     -                3/3 ok
  from rdomain 0        3/3 route     1/1 route        3/3 ok
  (above)               left behind   left behind

"ok" means: the move is accepted, no route for the old address is left
in the old table, and destroying both loopbacks works.  Normal use on
the patched kernel, 3 runs, 11 checks each, all as expected (one run
on the unpatched kernel, same result): creating an rdomain through
"ifconfig vetherN rdomain N" creates loN; ping 127.0.0.1 and an own
address in that rdomain; an rdomain's own loopback still cannot leave
it (EPERM); "ifconfig loN rdomain N" on a fresh loopback, then
127.0.0.1 on it, and another interface joining that rdomain, with its
route in "route -T N show"; lo0 untouched; destroying everything.

Reply via email to