Bug 217939 - syslogd: -b doesn't work with IPv6 literal addresses after ^/head@r309933
Summary: syslogd: -b doesn't work with IPv6 literal addresses after ^/head@r309933
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Hiroki Sato
URL: https://reviews.freebsd.org/D10064
Keywords: regression
Depends on:
Blocks:
 
Reported: 2017-03-20 06:42 UTC by Enji Cooper
Modified: 2017-05-22 05:55 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer freebsd_triage 2017-03-20 06:42:38 UTC
syslogd no longer accepts `-b ::1` and `-b [::1]:syslog` after the refactoring done in r309933. Example:

Legacy format (`-b ::1`):

$ sudo env rc_debug=1 /etc/rc.d/syslogd restart
/etc/rc.d/syslogd: DEBUG: Sourcing /etc/defaults/rc.conf
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
syslogd not running? (check /var/run/syslog.pid).
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
/etc/rc.d/syslogd: DEBUG: run_rc_command: start_precmd: syslogd_precmd
Starting syslogd.
/etc/rc.d/syslogd: DEBUG: run_rc_command: doit:  limits -C daemon /usr/sbin/syslogd -b ::1 -b :syslog -b [::1]:syslog -b 127.0.0.1:syslog -d
syslogd: getaddrinfo failed for :1: servname not supported for ai_socktype: Bad file descriptor
logmsg: pri 53, flags 4, from , msg syslogd: getaddrinfo failed for :1: servname not supported for ai_socktype: Bad file descriptor
Logging to UNUSED
/etc/rc.d/syslogd: WARNING: failed to start syslogd

Square bracket format with service identifier (`-b [::1]:syslog`)

$ sudo env rc_debug=1 /etc/rc.d/syslogd restart
/etc/rc.d/syslogd: DEBUG: Sourcing /etc/defaults/rc.conf
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
syslogd not running? (check /var/run/syslog.pid).
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
/etc/rc.d/syslogd: DEBUG: run_rc_command: start_precmd: syslogd_precmd
Starting syslogd.
/etc/rc.d/syslogd: DEBUG: run_rc_command: doit:  limits -C daemon /usr/sbin/syslogd -b :syslog -b [::1]:syslog -b 127.0.0.1:syslog -b localhost -b localhost:syslog -d
new socket fd is 6
shutdown
sending on socket
new socket fd is 7
shutdown
sending on socket
Trying peer: [
syslogd: getaddrinfo failed for [:1]:syslog: servname not supported for ai_socktype: Bad file descriptor
logmsg: pri 53, flags 4, from , msg syslogd: getaddrinfo failed for [:1]:syslog: servname not supported for ai_socktype: Bad file descriptor
Logging to UNUSED
/etc/rc.d/syslogd: WARNING: failed to start syslog

Square bracket format without service identifier (`-b [::1]`)

$ sudo env rc_debug=1 /etc/rc.d/syslogd restart
/etc/rc.d/syslogd: DEBUG: Sourcing /etc/defaults/rc.conf
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
syslogd not running? (check /var/run/syslog.pid).
/etc/rc.d/syslogd: DEBUG: pid file (/var/run/syslog.pid): not readable.
/etc/rc.d/syslogd: DEBUG: checkyesno: syslogd_enable is set to YES.
/etc/rc.d/syslogd: DEBUG: run_rc_command: start_precmd: syslogd_precmd
Starting syslogd.
/etc/rc.d/syslogd: DEBUG: run_rc_command: doit:  limits -C daemon /usr/sbin/syslogd -b [::1] -b :syslog -b 127.0.0.1:syslog -d
Trying peer: [
syslogd: getaddrinfo failed for [:1]: servname not supported for ai_socktype: Bad file descriptor
logmsg: pri 53, flags 4, from , msg syslogd: getaddrinfo failed for [:1]: servname not supported for ai_socktype: Bad file descriptor
Logging to UNUSED
/etc/rc.d/syslogd: WARNING: failed to start syslogd
Comment 1 Andrey V. Elsukov freebsd_committer freebsd_triage 2017-03-20 10:27:51 UTC
I think the following patch should fix this:

Index: syslogd.c
===================================================================
--- syslogd.c	(revision 315478)
+++ syslogd.c	(working copy)
@@ -477,7 +477,8 @@ main(int argc, char *argv[])
 			break;
 		case 'b':
 			bflag = 1;
-			if ((p = strchr(optarg, ':')) == NULL) {
+			if ((p = strchr(optarg, ':')) == NULL ||
+			    strchr(p + 1, ':') != NULL) {
 				/* A hostname or filename only. */
 				addpeer(&(struct peer){
 					.pe_name = optarg,
Comment 2 Enji Cooper freebsd_committer freebsd_triage 2017-03-20 16:38:45 UTC
(In reply to Andrey V. Elsukov from comment #1)

I'm confirming that this works for the testcases that I have:

syslogd_flags="-b :syslog -b ::1 -b [::1]:syslog -b 127.0.0.1:syslog -b localhost -b localhost:syslog -d"
Comment 3 commit-hook freebsd_committer freebsd_triage 2017-03-20 17:46:58 UTC
A commit references this bug:

Author: hrs
Date: Mon Mar 20 17:46:33 UTC 2017
New revision: 315643
URL: https://svnweb.freebsd.org/changeset/base/315643

Log:
  Fix a regression which prevented an IPv6 address in a -b option from
  working.

  PR:	217939
  Differential Revision:	https://reviews.freebsd.org/D10064

Changes:
  head/usr.sbin/syslogd/syslogd.c
Comment 4 Hiroki Sato freebsd_committer freebsd_triage 2017-03-20 17:49:20 UTC
(In reply to commit-hook from comment #3)
Sorry for the breakage.  I fixed it just now.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2017-05-20 21:45:53 UTC
Over to committer for possible MFC before 11.1.
Comment 6 Enji Cooper freebsd_committer freebsd_triage 2017-05-22 05:55:11 UTC
This issue isn't present on ^/stable/11. Closing