Bug 194292 - Patch for adding firewall_myservices_tcp and firewall_myservices_udp support to rc.conf
Summary: Patch for adding firewall_myservices_tcp and firewall_myservices_udp support ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Hiroki Sato
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-10 20:27 UTC by olivier
Modified: 2019-01-21 09:52 UTC (History)
6 users (show)

See Also:
bugmeister: mfc-stable10?
bugmeister: mfc-stable9?
bugmeister: mfc-stable8?


Attachments
patch for adding firewall_myservices_udp to rc.conf (1.90 KB, patch)
2014-10-10 20:27 UTC, olivier
no flags Details | Diff
patch for adding firewall_myservices_udp to rc.conf (1.90 KB, patch)
2014-10-11 07:40 UTC, olivier
no flags Details | Diff
Updated patch to support both protocols in one variable. (1.11 KB, patch)
2014-10-13 17:24 UTC, Hiroki Sato
no flags Details | Diff
Updated patch to support both protocols in one variable. (1.10 KB, patch)
2014-10-13 17:28 UTC, Hiroki Sato
no flags Details | Diff
Updated patch to support both protocols in one variable (1.23 KB, patch)
2014-10-13 19:34 UTC, Hiroki Sato
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description olivier 2014-10-10 20:27:23 UTC
Created attachment 148177 [details]
patch for adding firewall_myservices_udp to rc.conf

Settings firewall_myservices in etc/rc.conf permit to support only TCP services.
This patch propose to add UDP services by 2 changes:
1. firewall_myservices became a deprecated alias, the new is firewall_myservices_tcp
2. A new firewall_myservices_udp variable is added.
Patch to be apply to an up-to-date -current (tested on r272911).
Comment 1 Juan Ramón Molina Menor 2014-10-11 07:16:54 UTC
You seem to have a typo (double initial ff) in line 151 of /etc/defaults/rc.conf:
ffirewall_myservices_udp=""
Comment 2 olivier 2014-10-11 07:40:24 UTC
Created attachment 148185 [details]
patch for adding firewall_myservices_udp to rc.conf

fix the double "f" in etc/default/rc.conf
Comment 3 Hiroki Sato freebsd_committer freebsd_triage 2014-10-13 16:12:41 UTC
Take.
Comment 4 Scot Hetzel 2014-10-13 17:08:11 UTC
Instead of defining two new variables, we could expand firewall_myservices to:

firewall_myservices="20 80 443:tcp 3128:udp"

Then the code in rc.firewall would become:

for j in ${firewall_myservices}
	port=${j%:*}
	protocol=${j#*:}

	# Compatibility for when no protocol is specified, default to TCP 
	if [ "x${protocol}" = "x" ] {
		protocol="tcp"
		echo "Consider using ${port}:tcp in firewall_myservices"
	fi

	case ${protocol} in
		[Tt][Cc][Pp])
			;;
		[Uu][Dd][Pp])
			;;
		*)
			echo "Protocol ${port}:${protocol} not supported in firewall_myservices"
			protocol="unsupported"
			;;
	esac
	if [ "${protocol}" != "unsupported" ] {
		${fwcmd} add pass ${protocol} from $i to me ${port}
	}
done
Comment 5 Hiroki Sato freebsd_committer freebsd_triage 2014-10-13 17:24:00 UTC
Created attachment 148266 [details]
Updated patch to support both protocols in one variable.

(In reply to swhetzel from comment #4)
> Instead of defining two new variables, we could expand firewall_myservices
> to:
> 
> firewall_myservices="20 80 443:tcp 3128:udp"

I agree with this idea, but I prefer 443/tcp over 443:tcp.  How about the attached patch?
Comment 6 Scot Hetzel 2014-10-13 17:25:59 UTC
Comment on attachment 148266 [details]
Updated patch to support both protocols in one variable.

That looks good too.
Comment 7 Hiroki Sato freebsd_committer freebsd_triage 2014-10-13 17:28:54 UTC
Created attachment 148267 [details]
Updated patch to support both protocols in one variable.

A revised one.  The patch 148266 included a typo.
Comment 8 Hiroki Sato freebsd_committer freebsd_triage 2014-10-13 19:34:05 UTC
Created attachment 148278 [details]
Updated patch to support both protocols in one variable

Protocol number support has been added.  Now it supports the following:

 80 = 80/tcp (backward comaptibility)
 80/tcp = "allow tcp from $i to me dst-port 80"
 80/udp = "allow udp from $i to me dst-port 80"
 47/proto = "allow 47 from $i to me"

The port or protocol number can be specified in symbols defined in /etc/services and /etc/protocols.
Comment 9 olivier 2014-10-13 21:18:33 UTC
Wow… your improvements exceeded my expectations: Thanks guys !
Comment 10 Hiroki Sato freebsd_committer freebsd_triage 2014-10-14 03:23:16 UTC
I will commit the patch once I get a feedback from Adrian.
Comment 11 Adrian Chadd freebsd_committer freebsd_triage 2014-10-14 03:28:53 UTC
Looks great! Thanks!
Comment 12 Scot Hetzel 2014-10-15 16:40:27 UTC
Comment on attachment 148278 [details]
Updated patch to support both protocols in one variable

Just noticed that when the port is only specified, it is passing it as udp, should be tcp:

+	      echo "Consider using tcp/$j in firewall_myservices." > /dev/stderr
+	      ${fwcmd} add pass udp from $i to me $j

Also the error, message should say ..$j/tcp..

Otherwise it looks good to me.
Comment 13 commit-hook freebsd_committer freebsd_triage 2014-10-17 00:32:46 UTC
A commit references this bug:

Author: hrs
Date: Fri Oct 17 00:31:52 UTC 2014
New revision: 273201
URL: https://svnweb.freebsd.org/changeset/base/273201

Log:
  Add support of "/{udp,tcp,proto}" suffix into $firewall_myservices, which
  interpreted the listed items as port numbers of TCP services.

  A service with no suffix still works and recognized as a TCP service for
  backward compatibility.  It should be updated with /tcp suffix.

  PR:		194292
  MFC after:	1 week

Changes:
  head/etc/rc.firewall
Comment 14 Hiroki Sato freebsd_committer freebsd_triage 2014-10-17 00:43:23 UTC
(In reply to Scot Hetzel from comment #12)
> Comment on attachment 148278 [details]
> Updated patch to support both protocols in one variable
> 
> Just noticed that when the port is only specified, it is passing it as udp,
> should be tcp:
> 
> +	      echo "Consider using tcp/$j in firewall_myservices." > /dev/stderr
> +	      ${fwcmd} add pass udp from $i to me $j
> 
> Also the error, message should say ..$j/tcp..
> 
> Otherwise it looks good to me.

Thank you.  I fixed this and committed the patch in r273201.
Comment 15 Glen Barber freebsd_committer freebsd_triage 2015-07-08 18:02:25 UTC
Close PRs that have had a corresponding fix committed.
Comment 16 Hiroki Sato freebsd_committer freebsd_triage 2015-07-08 19:45:57 UTC
No, this has not been MFCed yet.  Please keep it open until it is done.
Comment 17 Hiren Panchasara freebsd_committer freebsd_triage 2016-12-22 19:47:42 UTC
hrs@, can this be closed now?
Comment 18 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-21 09:52:07 UTC
There is a commit referencing this PR, but it's still not closed and has been inactive for some time. Closing the PR as fixed but feel free to re-open it if the issue hasn't been completely resolved.

Thanks