commit:     b833afd6410c2e7dde0cae40ac20d218a5ae425e
Author:     Patrick McLean <chutzpah <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 10 06:01:15 2016 +0000
Commit:     Patrick McLean <chutzpah <AT> gentoo <DOT> org>
CommitDate: Sat Dec 10 06:01:15 2016 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b833afd6

net-dns/dnsmasq: Revision bump, add patch to fix caching of bound sockets

This also adds gentoo prefix support.

Gentoo-Bug: 601920

Package-Manager: portage-2.3.3

 net-dns/dnsmasq/dnsmasq-2.76-r1.ebuild             | 193 +++++++++++++++++++++
 ...-binding-upstream-servers-to-an-interface.patch | 135 ++++++++++++++
 2 files changed, 328 insertions(+)

diff --git a/net-dns/dnsmasq/dnsmasq-2.76-r1.ebuild 
b/net-dns/dnsmasq/dnsmasq-2.76-r1.ebuild
new file mode 100644
index 00000000..8a754fc
--- /dev/null
+++ b/net-dns/dnsmasq/dnsmasq-2.76-r1.ebuild
@@ -0,0 +1,193 @@
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI=6
+
+inherit eutils toolchain-funcs flag-o-matic user systemd
+
+DESCRIPTION="Small forwarding DNS server"
+HOMEPAGE="http://www.thekelleys.org.uk/dnsmasq/doc.html";
+SRC_URI="http://www.thekelleys.org.uk/dnsmasq/${P}.tar.xz";
+
+LICENSE="|| ( GPL-2 GPL-3 )"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh 
~sparc ~x86 ~sparc-fbsd ~x86-fbsd"
+IUSE="auth-dns conntrack dbus +dhcp dhcp-tools dnssec idn +inotify ipv6 lua 
nls script selinux static tftp"
+DM_LINGUAS="de es fi fr id it no pl pt_BR ro"
+for dm_lingua in ${DM_LINGUAS}; do
+       IUSE+=" linguas_${dm_lingua}"
+done
+
+CDEPEND="dbus? ( sys-apps/dbus )
+       idn? ( net-dns/libidn )
+       lua? ( dev-lang/lua:* )
+       conntrack? ( net-libs/libnetfilter_conntrack )
+       nls? (
+               sys-devel/gettext
+               net-dns/libidn
+       )
+"
+
+DEPEND="${CDEPEND}
+       app-arch/xz-utils
+       dnssec? (
+               dev-libs/nettle[gmp]
+               static? (
+                       dev-libs/nettle[static-libs(+)]
+               )
+       )
+       virtual/pkgconfig"
+
+RDEPEND="${CDEPEND}
+       dnssec? (
+               !static? (
+                       dev-libs/nettle[gmp]
+               )
+       )
+       selinux? ( sec-policy/selinux-dnsmasq )
+"
+
+REQUIRED_USE="dhcp-tools? ( dhcp )
+       lua? ( script )"
+
+PATCHES=(
+       "${FILESDIR}/${P}-handle-binding-upstream-servers-to-an-interface.patch"
+)
+
+use_have() {
+       local useflag no_only uword
+       if [[ $1 == '-n' ]]; then
+               no_only=1
+               shift
+       fi
+       useflag="${1}"
+       shift
+
+       uword="${1:-${useflag}}"
+       shift
+
+       while [[ ${uword} ]]; do
+               uword="${uword^^}"
+
+               if ! use "${useflag}"; then
+                       printf " -DNO_%s" "${uword}"
+               elif [[ -z "${no_only}" ]]; then
+                       printf " -DHAVE_%s" "${uword}"
+               fi
+               uword="${1}"
+               shift
+       done
+}
+
+pkg_pretend() {
+       if use static; then
+               einfo "Only sys-libs/gmp and dev-libs/nettle are statically 
linked."
+               use dnssec || einfo "Thus, ${P}[!dnssec,static] makes no sense; 
the static USE flag is ignored."
+       fi
+}
+
+pkg_setup() {
+       enewgroup dnsmasq
+       enewuser dnsmasq -1 -1 /dev/null dnsmasq
+}
+
+src_prepare() {
+       default
+
+       sed -i -r 's:lua5.[0-9]+:lua:' Makefile
+       sed -i "s:%%PREFIX%%:${EPREFIX}/usr:" dnsmasq.conf.example
+}
+
+src_configure() {
+       COPTS="$(use_have -n auth-dns auth)"
+       COPTS+="$(use_have conntrack)"
+       COPTS+="$(use_have dbus)"
+       COPTS+="$(use_have idn)"
+       COPTS+="$(use_have -n inotify)"
+       COPTS+="$(use_have -n dhcp dhcp dhcp6)"
+       COPTS+="$(use_have -n ipv6 ipv6 dhcp6)"
+       COPTS+="$(use_have lua luascript)"
+       COPTS+="$(use_have -n script)"
+       COPTS+="$(use_have -n tftp)"
+       COPTS+="$(use_have dnssec)"
+       COPTS+="$(use_have static dnssec_static)"
+}
+
+src_compile() {
+       emake \
+               PREFIX="${EPREFIX}/usr" \
+               MANDIR="${EPREFIX}/usr/share/man" \
+               CC="$(tc-getCC)" \
+               PKG_CONFIG="$(tc-getPKG_CONFIG)" \
+               CFLAGS="${CFLAGS}" \
+               LDFLAGS="${LDFLAGS}" \
+               COPTS="${COPTS}" \
+               CONFFILE="${EPREFIX}/etc/${PN}.conf" \
+               all$(use nls && echo "-i18n")
+
+       use dhcp-tools && emake -C contrib/lease-tools \
+               PREFIX="${EPREFIX}/usr" \
+               MANDIR="${EPREFIX}/usr/share/man" \
+               CC="$(tc-getCC)" \
+               PKG_CONFIG="$(tc-getPKG_CONFIG)" \
+               CFLAGS="${CFLAGS}" \
+               LDFLAGS="${LDFLAGS}" \
+               all
+}
+
+src_install() {
+       local lingua puid
+       emake \
+               PREFIX=/usr \
+               MANDIR=/usr/share/man \
+               COPTS="${COPTS}" \
+               DESTDIR="${ED}" \
+               install$(use nls && echo "-i18n")
+
+       for lingua in ${DM_LINGUAS}; do
+               use linguas_${lingua} || rm -rf 
"${D}"/usr/share/locale/${lingua}
+       done
+       [[ -d "${ED}"/usr/share/locale/ ]] && rmdir --ignore-fail-on-non-empty 
"${ED}"/usr/share/locale/
+
+       dodoc CHANGELOG CHANGELOG.archive FAQ dnsmasq.conf.example
+       dodoc -r logo
+
+       docinto html/
+       dodoc *.html
+
+       newinitd "${FILESDIR}"/dnsmasq-init-r2 ${PN}
+       newconfd "${FILESDIR}"/dnsmasq.confd-r1 ${PN}
+
+       insinto /etc
+       newins dnsmasq.conf.example dnsmasq.conf
+
+       insinto /usr/share/dnsmasq
+       doins trust-anchors.conf
+
+       if use dhcp; then
+               dodir /var/lib/misc
+               newinitd "${FILESDIR}"/dnsmasq-init-dhcp-r1 ${PN}
+       fi
+       if use dbus; then
+               insinto /etc/dbus-1/system.d
+               doins dbus/dnsmasq.conf
+       fi
+
+       if use dhcp-tools; then
+               dosbin contrib/lease-tools/{dhcp_release,dhcp_lease_time}
+               doman contrib/lease-tools/{dhcp_release,dhcp_lease_time}.1
+       fi
+
+       systemd_newunit "${FILESDIR}"/${PN}.service-r1 ${PN}.service
+}
+
+pkg_preinst() {
+       # temporary workaround to (hopefully) prevent leases file from being 
removed
+       [[ -f /var/lib/misc/dnsmasq.leases ]] && cp 
/var/lib/misc/dnsmasq.leases "${T}"
+}
+
+pkg_postinst() {
+       # temporary workaround to (hopefully) prevent leases file from being 
removed
+       [[ -f "${T}"/dnsmasq.leases ]] && cp "${T}"/dnsmasq.leases 
/var/lib/misc/dnsmasq.leases
+}

diff --git 
a/net-dns/dnsmasq/files/dnsmasq-2.76-handle-binding-upstream-servers-to-an-interface.patch
 
b/net-dns/dnsmasq/files/dnsmasq-2.76-handle-binding-upstream-servers-to-an-interface.patch
new file mode 100644
index 00000000..463c935
--- /dev/null
+++ 
b/net-dns/dnsmasq/files/dnsmasq-2.76-handle-binding-upstream-servers-to-an-interface.patch
@@ -0,0 +1,135 @@
+From 2675f2061525bc954be14988d64384b74aa7bf8b Mon Sep 17 00:00:00 2001
+From: Beniamino Galvani <[email protected]>
+Date: Sun, 28 Aug 2016 20:44:05 +0100
+Subject: [PATCH] Handle binding upstream servers to an interface
+ (--server=1.2.3.4@eth0) when the named interface is
+ destroyed and recreated in the kernel.
+
+---
+ CHANGELOG     |    5 +++++
+ src/dnsmasq.h |    1 +
+ src/network.c |   31 +++++++++++++++++++++++++++++--
+ 3 files changed, 35 insertions(+), 2 deletions(-)
+
+diff --git a/CHANGELOG b/CHANGELOG
+index 2731cc4..5bcce38 100644
+--- a/CHANGELOG
++++ b/CHANGELOG
+@@ -30,6 +30,11 @@ version 2.77
+           and are now converted to names like
+           <prefix>--ffff-1-2-3-4.<domain>
+ 
++          Handle binding upstream servers to an interface 
++          (--server=1.2.3.4@eth0) when the named interface
++          is destroyed and recreated in the kernel. Thanks to 
++          Beniamino Galvani for the patch.
++
+ 
+ version 2.76
+             Include 0.0.0.0/8 in DNS rebind checks. This range 
+diff --git a/src/dnsmasq.h b/src/dnsmasq.h
+index 27385a9..f239ce5 100644
+--- a/src/dnsmasq.h
++++ b/src/dnsmasq.h
+@@ -488,6 +488,7 @@ struct serverfd {
+   int fd;
+   union mysockaddr source_addr;
+   char interface[IF_NAMESIZE+1];
++  unsigned int ifindex, used;
+   struct serverfd *next;
+ };
+ 
+diff --git a/src/network.c b/src/network.c
+index e7722fd..ddf8d31 100644
+--- a/src/network.c
++++ b/src/network.c
+@@ -1204,6 +1204,7 @@ int local_bind(int fd, union mysockaddr *addr, char 
*intname, int is_tcp)
+ static struct serverfd *allocate_sfd(union mysockaddr *addr, char *intname)
+ {
+   struct serverfd *sfd;
++  unsigned int ifindex = 0;
+   int errsave;
+ 
+   /* when using random ports, servers which would otherwise use
+@@ -1224,11 +1225,15 @@ static struct serverfd *allocate_sfd(union mysockaddr 
*addr, char *intname)
+       return NULL;
+ #endif
+     }
++
++  if (intname && strlen(intname) != 0)
++    ifindex = if_nametoindex(intname); /* index == 0 when not binding to an 
interface */
+       
+   /* may have a suitable one already */
+   for (sfd = daemon->sfds; sfd; sfd = sfd->next )
+     if (sockaddr_isequal(&sfd->source_addr, addr) &&
+-      strcmp(intname, sfd->interface) == 0)
++      strcmp(intname, sfd->interface) == 0 &&
++      ifindex == sfd->ifindex) 
+       return sfd;
+   
+   /* need to make a new one. */
+@@ -1250,11 +1255,13 @@ static struct serverfd *allocate_sfd(union mysockaddr 
*addr, char *intname)
+       errno = errsave;
+       return NULL;
+     }
+-    
++
+   strcpy(sfd->interface, intname); 
+   sfd->source_addr = *addr;
+   sfd->next = daemon->sfds;
++  sfd->ifindex = ifindex;
+   daemon->sfds = sfd;
++
+   return sfd; 
+ }
+ 
+@@ -1429,12 +1436,16 @@ void check_servers(void)
+ {
+   struct irec *iface;
+   struct server *serv;
++  struct serverfd *sfd, *tmp, **up;
+   int port = 0, count;
+ 
+   /* interface may be new since startup */
+   if (!option_bool(OPT_NOWILD))
+     enumerate_interfaces(0);
+   
++  for (sfd = daemon->sfds; sfd; sfd = sfd->next)
++    sfd->used = 0;
++
+ #ifdef HAVE_DNSSEC
+  /* Disable DNSSEC validation when using server=/domain/.... servers
+     unless there's a configured trust anchor. */
+@@ -1505,6 +1516,8 @@ void check_servers(void)
+             serv->flags |= SERV_MARK;
+             continue;
+           }
++
++        serv->sfd->used = 1;
+       }
+       
+       if (!(serv->flags & SERV_NO_REBIND) && !(serv->flags & 
SERV_LITERAL_ADDRESS))
+@@ -1547,6 +1560,20 @@ void check_servers(void)
+   if (count - 1 > SERVERS_LOGGED)
+     my_syslog(LOG_INFO, _("using %d more nameservers"), count - 
SERVERS_LOGGED - 1);
+ 
++  /* Remove unused sfds */
++  for (sfd = daemon->sfds, up = &daemon->sfds; sfd; sfd = tmp)
++    {
++       tmp = sfd->next;
++       if (!sfd->used) 
++      {
++        *up = sfd->next;
++        close(sfd->fd);
++        free(sfd);
++      } 
++      else
++      up = &sfd->next;
++    }
++  
+   cleanup_servers();
+ }
+ 
+-- 
+1.7.10.4
+

Reply via email to