From owner-svn-ports-all@freebsd.org Tue Jul 21 19:00:40 2020 Return-Path: Delivered-To: svn-ports-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 76E59364BEB; Tue, 21 Jul 2020 19:00:40 +0000 (UTC) (envelope-from tijl@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BB7GJ2clLz45PR; Tue, 21 Jul 2020 19:00:40 +0000 (UTC) (envelope-from tijl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 22FA722EDD; Tue, 21 Jul 2020 19:00:40 +0000 (UTC) (envelope-from tijl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06LJ0dw3086207; Tue, 21 Jul 2020 19:00:39 GMT (envelope-from tijl@FreeBSD.org) Received: (from tijl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06LJ0dbx086075; Tue, 21 Jul 2020 19:00:39 GMT (envelope-from tijl@FreeBSD.org) Message-Id: <202007211900.06LJ0dbx086075@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tijl set sender to tijl@FreeBSD.org using -f From: Tijl Coosemans Date: Tue, 21 Jul 2020 19:00:39 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r542780 - in head/print/hplip: . files X-SVN-Group: ports-head X-SVN-Commit-Author: tijl X-SVN-Commit-Paths: in head/print/hplip: . files X-SVN-Commit-Revision: 542780 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 19:00:40 -0000 Author: tijl Date: Tue Jul 21 19:00:39 2020 New Revision: 542780 URL: https://svnweb.freebsd.org/changeset/ports/542780 Log: Fix mDNS support for network printers. At least on FreeBSD 13, SO_REUSEPORT is no longer sufficient when Avahi already uses port 5353. It seems that port reuse is only allowed for processes from the same user now. But even if Avahi is not running and port 5353 is available my printer still failed to be detected. According to RFC 6762 only fully compliant queriers should be using that port which HPLIP isn't. I suspect the printer is sending responses that HPLIP can't parse. Patch HPLIP to use a simple socket (dynamically allocated port) which is enough for the one-shot mDNS queries it performs. Now my printer is detected by "hp-probe --method=mdns" and xsane can find the scanner part using the hpaio plugin. PR: 247723 Approved by: maintainer timeout (19 days) Modified: head/print/hplip/Makefile head/print/hplip/files/patch-protocol_discovery_mdns.c Modified: head/print/hplip/Makefile ============================================================================== --- head/print/hplip/Makefile Tue Jul 21 18:52:06 2020 (r542779) +++ head/print/hplip/Makefile Tue Jul 21 19:00:39 2020 (r542780) @@ -3,7 +3,7 @@ PORTNAME= hplip PORTVERSION= 3.20.3 -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= print MASTER_SITES= SF Modified: head/print/hplip/files/patch-protocol_discovery_mdns.c ============================================================================== --- head/print/hplip/files/patch-protocol_discovery_mdns.c Tue Jul 21 18:52:06 2020 (r542779) +++ head/print/hplip/files/patch-protocol_discovery_mdns.c Tue Jul 21 19:00:39 2020 (r542780) @@ -1,4 +1,16 @@ ---- protocol/discovery/mdns.c.orig 2019-10-22 06:18:12 UTC +Use a dynamically allocated port instead of binding port 5353. The bind(2) +call fails when Avahi has already claimed port 5353. On top of that, HPLIP +only performs one-shot queries and those shouldn't be using port 5353 according +to RFC 6762. + +Don't disable loop-back. It's harmless. + +Use default TTL of 1. RFC 6762 requires 255 for responses, not for queries. + +There's no need to join the multicast group for one-shot queries. Responses +are sent to the unicast address. + +--- protocol/discovery/mdns.c.orig 2020-07-01 14:48:56 UTC +++ protocol/discovery/mdns.c @@ -24,7 +24,11 @@ Author: Sanjay Kumar @@ -13,15 +25,62 @@ #include #include #include -@@ -85,6 +89,11 @@ static int mdns_open_socket(int *psocket) +@@ -70,57 +74,13 @@ static int mdns_convert_name_to_dns(const char *name, + static int mdns_open_socket(int *psocket) + { + int stat = MDNS_STATUS_ERROR; +- int udp_socket = -1, yes = 1; +- char loop = 0, ttl = 255; +- struct sockaddr_in recv_addr , addr; +- struct ip_mreq mreq; ++ int udp_socket; - /* Get rid of "address already in use" error message. */ - if (setsockopt(udp_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) -+ { -+ BUG("unable to setsockopt: %m\n"); -+ goto bugout; -+ } -+ if (setsockopt(udp_socket, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) == -1) + DBG("mdns_open_socket entry.\n"); + + if ((udp_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - BUG("unable to setsockopt: %m\n"); + BUG("unable to create udp socket: %m\n"); +- goto bugout; +- } +- +- /* Get rid of "address already in use" error message. */ +- if (setsockopt(udp_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) +- { +- BUG("unable to setsockopt: %m\n"); +- goto bugout; +- } +- +- /* Bind the socket to port and IP equal to INADDR_ANY. */ +- bzero(&recv_addr, sizeof(recv_addr)); +- recv_addr.sin_family = AF_INET; +- recv_addr.sin_addr.s_addr = htonl(INADDR_ANY); +- recv_addr.sin_port = htons(5353); +- if (bind(udp_socket, (struct sockaddr *) &recv_addr, sizeof(recv_addr)) == -1) +- { +- BUG("unable to bind udp socket: %m\n"); +- goto bugout; +- } +- +- /* Set multicast loopback off. */ +- if (setsockopt(udp_socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) == -1) +- { +- BUG("unable to setsockopt: %m\n"); +- goto bugout; +- } +- +- /* Set ttl to 255. Required by mdns. */ +- if (setsockopt(udp_socket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl))== -1) +- { +- BUG("unable to setsockopt: %m\n"); +- goto bugout; +- } +- +- /* Join the .local multicast group */ +- mreq.imr_multiaddr.s_addr = inet_addr("224.0.0.251"); +- mreq.imr_interface.s_addr = htonl(INADDR_ANY); +- if (setsockopt(udp_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(struct ip_mreq)) == -1) { +- BUG("unable to add to multicast group: %m\n"); +- close(udp_socket); goto bugout; + } +