Bug 194672 - [carp] Changing advskew to 0 from another value doesn't work
Summary: [carp] Changing advskew to 0 from another value doesn't work
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.1-RC2
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-net (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-28 22:09 UTC by cmb
Modified: 2015-02-06 17:16 UTC (History)
2 users (show)

See Also:


Attachments
Fix set advskew back to 0 (397 bytes, patch)
2014-12-29 21:59 UTC, Renato Botelho
no flags Details | Diff
2nd attempt, fix also advbase check (1.56 KB, patch)
2014-12-30 15:45 UTC, Renato Botelho
no flags Details | Diff
3rd version - Fix advskew and advbase checks, set default advbase for new entries (1.44 KB, patch)
2014-12-30 18:58 UTC, Renato Botelho
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description cmb 2014-10-28 22:09:31 UTC
When you configure advskew in CARP to be something other than 0, then try to change it back to 0, FreeBSD refuses to do so. It can be changed to any value other than 0, but never back to 0. This is a semi-common scenario, as it's how people would generally demote a system from master to backup for maintenance or other purposes, and would generally want to set it back to 0 afterwards. 

Initially setting it to 0 works fine. 

Tested on 10.0 release and 10.1-RC3, both behave the same. The following shows the issue and how to replicate. 

# ifconfig em0 vhid 55 advskew 0 pass PASSWORD alias 192.168.124.222/24
# ifconfig em0 
em0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
        ether 00:0c:29:11:5e:be
        inet 192.168.124.132 netmask 0xffffff00 broadcast 192.168.124.255
        inet 192.168.124.222 netmask 0xffffff00 broadcast 192.168.124.255 vhid 55
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
        carp: MASTER vhid 55 advbase 1 advskew 0

Change it, it'll work. 
# ifconfig em0 vhid 55 advskew 100
# ifconfig em0 | grep carp:
        carp: MASTER vhid 55 advbase 1 advskew 100

Try changing it back to 0, and it won't. 
# ifconfig em0 vhid 55 advskew 0
# ifconfig em0 | grep carp:
        carp: MASTER vhid 55 advbase 1 advskew 100

But can change it to 1 or other values. 
# ifconfig em0 vhid 55 advskew 1
# ifconfig em0 | grep carp:
        carp: MASTER vhid 55 advbase 1 advskew 1
Comment 1 Renato Botelho freebsd_committer freebsd_triage 2014-12-29 21:48:21 UTC
Looking into sys/netinet/ip_carp.c at line 1706:

		if (carpr.carpr_advskew > 0) {
			if (carpr.carpr_advskew >= 255) {
				error = EINVAL;
				break;
			}
			sc->sc_advskew = carpr.carpr_advskew;
		}

It silently accepts 0 as a good value (no error returned) but it doesn't set sc->sc_advskew. Is it expected to work this way?
Comment 2 Renato Botelho freebsd_committer freebsd_triage 2014-12-29 21:59:59 UTC
Created attachment 151093 [details]
Fix set advskew back to 0

The attached patch make it possible to set advskew back to 0
Comment 3 Renato Botelho freebsd_committer freebsd_triage 2014-12-30 15:45:31 UTC
Created attachment 151123 [details]
2nd attempt, fix also advbase check

There is one more issue, advbase should be >= 1 and <= 255, it makes proper check and also fix default advbase value on ifconfig to 1
Comment 4 Renato Botelho freebsd_committer freebsd_triage 2014-12-30 17:39:09 UTC
Please ignore second patch, it has issues, will send a new one shortly
Comment 5 Renato Botelho freebsd_committer freebsd_triage 2014-12-30 18:58:47 UTC
Created attachment 151128 [details]
3rd version - Fix advskew and advbase checks, set default advbase for new entries

This version changes ifconfig to set default advbase to 1 on new entries, and because of that make advbase and advskew checks correct on kernel side
Comment 6 commit-hook freebsd_committer freebsd_triage 2015-01-06 13:08:02 UTC
A commit references this bug:

Author: loos
Date: Tue Jan  6 13:07:14 UTC 2015
New revision: 276751
URL: https://svnweb.freebsd.org/changeset/base/276751

Log:
  Remove the check that prevent carp(4) advskew to be set to '0'.

  CARP devices are created with advskew set to '0' and once you set it to
  any other value in the valid range (0..254) you can't set it back to zero.

  The code in question is also used to prevent that zeroed values overwrite
  the CARP defaults when a new CARP device is created.  Since advskew already
  defaults to '0' for newly created devices and the new value is guaranteed
  to be within the valid range, it is safe to overwrite it here.

  PR:		194672
  Reported by:	cmb@pfsense.org
  In collaboration with:	garga
  Tested by:	garga
  MFC after:	2 weeks

Changes:
  head/sys/netinet/ip_carp.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2015-02-02 11:42:42 UTC
A commit references this bug:

Author: loos
Date: Mon Feb  2 11:42:36 UTC 2015
New revision: 278075
URL: https://svnweb.freebsd.org/changeset/base/278075

Log:
  MFC r276751:

  Remove the check that prevent carp(4) advskew to be set to '0'.

  CARP devices are created with advskew set to '0' and once you set it to
  any other value in the valid range (0..254) you can't set it back to zero.

  The code in question is also used to prevent that zeroed values overwrite
  the CARP defaults when a new CARP device is created.  Since advskew already
  defaults to '0' for newly created devices and the new value is guaranteed
  to be within the valid range, it is safe to overwrite it here.

  PR:		194672
  Reported by:	cmb@pfsense.org

Changes:
_U  stable/10/
  stable/10/sys/netinet/ip_carp.c
Comment 8 Luiz Otavio O Souza,+55 (14) 99772-1255 freebsd_committer freebsd_triage 2015-02-06 17:16:29 UTC
The fix was committed to -head and 10-stable.

Thanks!