From nobody@FreeBSD.org  Mon Oct 28 15:50:10 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id A9AD650B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 28 Oct 2013 15:50:10 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 89DA828B1
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 28 Oct 2013 15:50:10 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r9SFoANL057739
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 28 Oct 2013 15:50:10 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r9SFoARR057727;
	Mon, 28 Oct 2013 15:50:10 GMT
	(envelope-from nobody)
Message-Id: <201310281550.r9SFoARR057727@oldred.freebsd.org>
Date: Mon, 28 Oct 2013 15:50:10 GMT
From: Abhishek Kumar <abhikumar163@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Routing restart returns non-zero exitcode in case of no extra routing parameter or missing atm/ipx
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         183407
>Category:       conf
>Synopsis:       [rc.d] [patch] Routing restart returns non-zero exitcode in case of no extra routing parameter or missing atm/ipx
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 28 16:00:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Sat Feb 22 17:10:00 UTC 2014
>Originator:     Abhishek Kumar
>Release:        FreeBSD 9.2.0, but sending patch for SVN Head
>Organization:
>Environment:
FreeBSD h4ck3r.freebsd.org 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013     root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
Current "/etc/rc.d/routing" script is as such it returns non-zero exitcode on restart in very common cases.

There are 2 issues in total...

Issue#1. It unsets a var and only in case any additional routing options of the provided communication channel (inet, inet6, atm, ipx) is to be turned on, it gets set. It fails for us as we don't have any extra routing options. For now I've patched it not to fail in case of no additional routing options.
Do check if any additional routing option is required or not.

Issue#2. There is also error in default case of routing start, where it tries to setroute for all (inet, inet6, atm, ipx) modes. Before that it checks if it's present or not and fails for atm and ipx not being present.

Since script is resilient enough, the required configuration gets applied. But the exitcode is erroneous which fails our configuration management tools by making them think the run failed itself.
>How-To-Repeat:
Shall happend for any install. But to be sure install it on a Virtualbox or any virtualization platform (have myself tried it on Xen and VirtualBox).

Perform
`/etc/rc.d/routing restart ; echo $?`

This will show a non-zero exitcode for routing service restart action.
>Fix:


Patch attached with submission follows:

--- routing-head	2013-10-28 21:06:15.434495241 +0530
+++ routing-head-patched	2013-10-28 21:10:14.807836000 +0530
@@ -21,12 +21,21 @@
 
 ROUTE_CMD="/sbin/route"
 
+get_communication_channels(){
+	for _a in inet inet6 atm ipx; do
+		if afexists $_a; then
+			comm_channel="${comm_channel} $_a"
+		fi
+	done
+}
+
 routing_start()
 {
 	local _cmd _af _if _a
 	_cmd=$1
 	_af=$2
 	_if=$3
+	get_communication_channels
 
 	case $_if in
 	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])	_if="" ;;
@@ -41,7 +50,7 @@
 		fi
 		;;
 	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])
-		for _a in inet inet6 ipx atm; do
+		for _a in $comm_channel; do
 			afexists $_a && setroutes $_cmd $_a $_if
 		done
 		;;
@@ -56,6 +65,7 @@
 	local _af _if _a
 	_af=$1
 	_if=$2
+	get_communication_channels
 
 	case $_if in
 	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])	_if="" ;;
@@ -74,7 +84,7 @@
 		fi
 		;;
 	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])
-		for _a in inet inet6 ipx atm; do
+		for _a in $comm_channel; do
 			afexists $_a || continue
 			eval static_${_a} delete $_if
 			# When $_if is specified, do not flush routes.
@@ -306,7 +316,9 @@
 options_inet()
 {
 	_ropts_initdone=
+	_all_false_checkyesno=true
 	if checkyesno icmp_bmcastecho; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' broadcast ping responses=YES'
 		${SYSCTL} net.inet.icmp.bmcastecho=1 > /dev/null
@@ -315,6 +327,7 @@
 	fi
 
 	if checkyesno icmp_drop_redirect; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' ignore ICMP redirect=YES'
 		${SYSCTL} net.inet.icmp.drop_redirect=1 > /dev/null
@@ -323,6 +336,7 @@
 	fi
 
 	if checkyesno icmp_log_redirect; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' log ICMP redirect=YES'
 		${SYSCTL} net.inet.icmp.log_redirect=1 > /dev/null
@@ -331,6 +345,7 @@
 	fi
 
 	if checkyesno gateway_enable; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' gateway=YES'
 		${SYSCTL} net.inet.ip.forwarding=1 > /dev/null
@@ -339,6 +354,7 @@
 	fi
 
 	if checkyesno forward_sourceroute; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' do source routing=YES'
 		${SYSCTL} net.inet.ip.sourceroute=1 > /dev/null
@@ -347,6 +363,7 @@
 	fi
 
 	if checkyesno accept_sourceroute; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' accept source routing=YES'
 		${SYSCTL} net.inet.ip.accept_sourceroute=1 > /dev/null
@@ -355,6 +372,7 @@
 	fi
 
 	if checkyesno arpproxy_all; then
+		_all_false_checkyesno=false
 		ropts_init inet
 		echo -n ' ARP proxyall=YES'
 		${SYSCTL} net.link.ether.inet.proxyall=1 > /dev/null
@@ -362,14 +380,16 @@
 		${SYSCTL} net.link.ether.inet.proxyall=0 > /dev/null
 	fi
 
-	[ -n "${_ropts_initdone}" ] && echo '.'
+	[ -n "${_ropts_initdone}" ] || $_all_false_checkyesno
 }
 
 options_inet6()
 {
 	_ropts_initdone=
+	_all_false_checkyesno=true
 
 	if checkyesno ipv6_gateway_enable; then
+		_all_false_checkyesno=false
 		ropts_init inet6
 		echo -n ' gateway=YES'
 		${SYSCTL} net.inet6.ip6.forwarding=1 > /dev/null
@@ -377,21 +397,24 @@
 		${SYSCTL} net.inet6.ip6.forwarding=0 > /dev/null
 	fi
 
-	[ -n "${_ropts_initdone}" ] && echo '.'
+	[ -n "${_ropts_initdone}" ] || $_all_false_checkyesno
 }
 
 options_atm()
 {
 	_ropts_initdone=
+	_all_false_checkyesno=true
 
-	[ -n "${_ropts_initdone}" ] && echo '.'
+	[ -n "${_ropts_initdone}" ] || $_all_false_checkyesno
 }
 
 options_ipx()
 {
 	_ropts_initdone=
+	_all_false_checkyesno=true
 
 	if checkyesno ipxgateway_enable; then
+		_all_false_checkyesno=false
 		ropts_init ipx
 		echo -n ' gateway=YES'
 		${SYSCTL} net.ipx.ipx.ipxforwarding=1 > /dev/null
@@ -399,7 +422,7 @@
 		${SYSCTL} net.ipx.ipx.ipxforwarding=0 > /dev/null
 	fi
 
-	[ -n "${_ropts_initdone}" ] && echo '.'
+	[ -n "${_ropts_initdone}" ] || $_all_false_checkyesno
 }
 
 load_rc_config $name


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Oct 29 19:38:37 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=183407 

From: "J.R. Oldroyd" <fbsd@opal.com>
To: bug-followup@FreeBSD.org, abhikumar163@gmail.com
Cc:  
Subject: Re: conf/183407: [rc.d] [patch] Routing restart returns non-zero
 exitcode in case of no extra routing parameter or missing atm/ipx
Date: Sat, 22 Feb 2014 12:07:10 -0500

 I've received bug reports for wifimgr(8) when it resets interfaces
 using "/etc/rc.d/netif restart ifname" which calls /etc/rc.d/routing
 which is returning an incorrect value of 1.
 
 The patch proposed here does indeed fix things.
>Unformatted:
