From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 28 02:10:16 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2EA4416A4DA for ; Fri, 28 Jul 2006 02:10:16 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 59D2A43D5D for ; Fri, 28 Jul 2006 02:10:14 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k6S2AEUg005423 for ; Fri, 28 Jul 2006 02:10:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k6S2AE06005422; Fri, 28 Jul 2006 02:10:14 GMT (envelope-from gnats) Resent-Date: Fri, 28 Jul 2006 02:10:14 GMT Resent-Message-Id: <200607280210.k6S2AE06005422@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Nick Barkas Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0437016A4DE for ; Fri, 28 Jul 2006 02:10:09 +0000 (UTC) (envelope-from snb@smtp.earth.threerings.net) Received: from smtp.earth.threerings.net (mail.threerings.net [64.127.109.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9114043D5A for ; Fri, 28 Jul 2006 02:10:09 +0000 (GMT) (envelope-from snb@smtp.earth.threerings.net) Received: by smtp.earth.threerings.net (Postfix, from userid 1004) id 9C20565E1; Thu, 27 Jul 2006 19:10:08 -0700 (PDT) Message-Id: <20060728021008.9C20565E1@smtp.earth.threerings.net> Date: Thu, 27 Jul 2006 19:10:08 -0700 (PDT) From: Nick Barkas To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/100956: [patch] support setting carp device state with ifconfig X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Nick Barkas List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jul 2006 02:10:16 -0000 >Number: 100956 >Category: bin >Synopsis: [patch] support setting carp device state with ifconfig >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Jul 28 02:10:13 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Nick Barkas >Release: FreeBSD 7.0-CURRENT i386 >Organization: >Environment: FreeBSD freebsd-current.sea.earth.threerings.net 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Thu Jul 27 13:01:44 PDT 2006 root@freebsd61.sea.earth.threerings.net:/usr/obj/usr/src/sys/TEST i386 >Description: carp(4) devices expose an ioctl allowing their states to be set to MASTER or BACKUP explicitly from userland. However, ifconfig does not have any option to do this. Attached is a patch based on OpenBSD's ifconfig which allows a state option to be given to carp interfaces, and a patch to the ifconfig man page. >How-To-Repeat: ifconfig carpN state foo does not currently work. >Fix: --- src/sbin/ifconfig/ifcarp.c.orig Tue Feb 22 06:07:47 2005 +++ src/sbin/ifconfig/ifcarp.c Thu Jul 27 16:15:12 2006 @@ -57,6 +57,7 @@ void setcarp_advskew(const char *, int, int, const struct afswtch *rafp); void setcarp_passwd(const char *, int, int, const struct afswtch *rafp); void setcarp_vhid(const char *, int, int, const struct afswtch *rafp); +void setcarp_state(const char *, int, int, const struct afswtch *rafp); void carp_status(int s) @@ -174,11 +175,34 @@ return; } +void setcarp_state(const char *val, int d, int s, const struct afswtch *afp) +{ + struct carpreq carpr; + int i; + + bzero((char *)&carpr, sizeof(struct carpreq)); + ifr.ifr_data = (caddr_t)&carpr; + + if (ioctl(s, SIOCGVH, (caddr_t)&ifr) == -1) + err(1, "SIOCGVH"); + + for (i = 0; i <= CARP_MAXSTATE; i++) { + if (!strcasecmp(val, carp_states[i])) { + carpr.carpr_state = i; + break; + } + } + + if (ioctl(s, SIOCSVH, (caddr_t)&ifr) == -1) + err(1, "SIOCSVH"); +} + static struct cmd carp_cmds[] = { DEF_CMD_ARG("advbase", setcarp_advbase), DEF_CMD_ARG("advskew", setcarp_advskew), DEF_CMD_ARG("pass", setcarp_passwd), DEF_CMD_ARG("vhid", setcarp_vhid), + DEF_CMD_ARG("state", setcarp_state), }; static struct afswtch af_carp = { .af_name = "af_carp", --- src/sbin/ifconfig/ifconfig.8.orig Tue Jul 25 20:08:45 2006 +++ src/sbin/ifconfig/ifconfig.8 Thu Jul 27 19:02:50 2006 @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD: /repoman/r/ncvs/src/sbin/ifconfig/ifconfig.8,v 1.119 2006/07/26 03:08:45 sam Exp $ .\" -.Dd July 25, 2006 +.Dd July 27, 2006 .Dt IFCONFIG 8 .Os .Sh NAME @@ -1405,6 +1405,13 @@ Set the virtual host ID. This is a required setting. Acceptable values are 1 to 255. +.It Cm state Ar state +Force the interface into state +.Ar state . +Valid states are INIT, BACKUP, and MASTER. Note that manually setting the state +to INIT is ignored by +.Xr carp 4 . +This state is set automatically when the underlying interface is down. .El .Pp The >Release-Note: >Audit-Trail: >Unformatted: