Bug 248647

Summary: net/fping: Fails to run inside a FreeBSD jail with "allow.raw_sockets": Can't assign requested address
Product: Ports & Packages Reporter: Dirk Meyer <dinoex>
Component: Individual Port(s)Assignee: Dirk Meyer <dinoex>
Status: Closed FIXED    
Severity: Affects Only Me CC: james, jharris
Priority: --- Keywords: needs-patch, needs-qa, regression
Version: LatestFlags: jharris: maintainer-feedback+
dinoex: merge-quarterly-
Hardware: Any   
OS: Any   
Attachments:
Description Flags
patch none

Description Dirk Meyer freebsd_committer freebsd_triage 2020-08-13 17:57:35 UTC
After update from 4.2 to 4.4wuth 
"fping" and "fping6" now fails inside a FreeBSD jail with "allow.raw_sockets".

$ fping 127.0.0.44
fping: cannot bind source address : Can't assign requested address

truss fping6:
socket(PF_INET6,SOCK_RAW,IPPROTO_ICMPV6)         = 4 (0x4)
fcntl(4,F_GETFL,)                                = 2 (0x2)
fcntl(4,F_SETFL,O_RDWR|O_NONBLOCK)               = 0 (0x0)
getuid()                                         = 0 (0x0)
getpid()                                         = 29446 (0x7306)
setsockopt(3,SOL_SOCKET,SO_TIMESTAMP,0x7fffffffe930,4) = 0 (0x0)
setsockopt(4,SOL_SOCKET,SO_TIMESTAMP,0x7fffffffe930,4) = 0 (0x0)
bind(3,{ AF_INET 0.0.0.0:0 },16)                 ERR#49 'Can't assign requested address'

reverting to 4.2 fixes the problem.
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2020-08-14 02:19:11 UTC
@Dirk Was this a regression against a prior port/package version, or on a particular FreeBSD version/branch?
Comment 2 James French 2020-08-14 14:30:57 UTC
This works when the jail is set to ip4 = inherit

$ fping 127.0.0.1
127.0.0.1 is alive

$ fping --version
fping: Version 4.4
fping: comments to david@schweikert.ch

I can confirm it's broken when the jail is given an IP address.
Comment 3 Dirk Meyer freebsd_committer freebsd_triage 2020-08-17 18:02:22 UTC
(In reply to Kubilay Kocak from comment #1)

Same FreeBSD version.

broken package:
10 Aug. 07:36 /usr/ports/packages12-amd64/All/fping-4.4.txz

working package_
13 Juli 16:36 /usr/ports/packages12-amd64/Old/fping-4.2.txz
Comment 4 jharris 2020-08-18 22:40:28 UTC
Please see if ping 5.0 fixes this issue:

  https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=248744

Thanks.
Comment 5 Dirk Meyer freebsd_committer freebsd_triage 2020-08-19 21:09:20 UTC
(In reply to jharris from comment #4)

Sorry, but fping 5.0 fails as well with the same error.
Comment 6 James French 2020-08-20 04:44:28 UTC
(In reply to Dirk Meyer from comment #5)

The issue is a commit somewhere between v4.2 and v4.3 (which is also broken). I'm currently tracking down the commit in question with a git-bisect and will report back when I find it (hopefully with a patch).
Comment 7 Dirk Meyer freebsd_committer freebsd_triage 2020-08-20 06:01:24 UTC
As seen in the truss output

fping6 tries to bind to an IPv4, AF_INET
fping tries to bind to an IPV4 and IPv6.

I got fping to work if I force both Source.Addresses.

Looking at the diffs I see that
src_addr_set and src_addr6_set is set but not used.

Revering the conditions in fping.c resolves the problems for me.

I propose the following patch to fix the port.
Comment 8 Dirk Meyer freebsd_committer freebsd_triage 2020-08-20 06:02:08 UTC
Created attachment 217361 [details]
patch
Comment 9 Dirk Meyer freebsd_committer freebsd_triage 2020-08-20 06:06:54 UTC
merger-quaterly is not needed, as quarterly has still 4.2

https://www.freshports.org/net/fping/
Comment 10 Dirk Meyer freebsd_committer freebsd_triage 2020-08-20 06:18:30 UTC
Reported the issue upstream at
https://github.com/schweikert/fping/pull/198
Comment 11 James French 2020-08-20 06:44:13 UTC
(In reply to Dirk Meyer from comment #10)

Bisect finished (had to break to do something else), the offending commit is this one:

https://github.com/schweikert/fping/commit/1486bf209baa49724c7f776463d2ba5858fa0ff4

I will add it to your issue report.
Comment 12 Dirk Meyer freebsd_committer freebsd_triage 2020-08-20 11:21:29 UTC
(In reply to James French from comment #11)

This matches my finding.

Both flags have been removed in the conditionals:

968/974 if (src_addr_set && socket4 >= 0) {
972/978 if (src_addr6_set && socket6 >= 0) {
Comment 13 Dirk Meyer freebsd_committer freebsd_triage 2020-08-20 11:29:29 UTC
(In reply to jharris from comment #4)

Do you approve the suggested patch for you port?
Comment 14 jharris 2020-08-20 22:00:02 UTC
(In reply to Dirk Meyer from comment #13)

Yes, albeit without personally testing.  Thanks!
Comment 15 commit-hook freebsd_committer freebsd_triage 2020-08-22 12:37:19 UTC
A commit references this bug:

Author: dinoex
Date: Sat Aug 22 12:36:18 UTC 2020
New revision: 545762
URL: https://svnweb.freebsd.org/changeset/ports/545762

Log:
  - fix Can't assign requested address
  PR:		248647
  Approved by:	 J Harris

Changes:
  head/net/fping/Makefile
  head/net/fping/files/
  head/net/fping/files/patch-fping.c