+static int
+sysctl_mld_v2enable SYSCTL_HANDLER_ARGS
+{
+#pragma unused(arg1, arg2)
+ int error;
+ int i;
+ struct mld_ifinfo *mli;
+ struct mld_tparams mtp = { 0, 0, 0, 0 };
+
+ MLD_LOCK();
+
+ i = mld_v2enable;
+
+ error = sysctl_handle_int(oidp, &i, 0, req);
+ if (error || !req->newptr)
+ goto out_locked;
+
+ if (i < 0 || i > 1) {
+ error = EINVAL;
+ goto out_locked;
+ }
+
+ mld_v2enable = i;
+ /*
+ * If we enabled v2, the state transition will take care of upgrading
+ * the MLD version back to v2. Otherwise, we have to explicitly
+ * downgrade. Note that this functionality is to be used for debugging.
+ */
+ if (mld_v2enable == 1)
+ goto out_locked;
+
+ LIST_FOREACH(mli, &mli_head, mli_link) {
+ MLI_LOCK(mli);
+ if (mld_set_version(mli, MLD_VERSION_1) > 0)
+ mtp.qpt = 1;
+ MLI_UNLOCK(mli);
+ }
+
+out_locked:
+ MLD_UNLOCK();
+
+ mld_set_timeout(&mtp);
+
+ return (error);
+}
+