Date: Thu, 27 Jul 2006 19:10:08 -0700 (PDT) From: Nick Barkas <snb@threerings.net> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/100956: [patch] support setting carp device state with ifconfig Message-ID: <20060728021008.9C20565E1@smtp.earth.threerings.net> Resent-Message-ID: <200607280210.k6S2AE06005422@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060728021008.9C20565E1>