Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Nov 2013 17:30:14 +0000 (UTC)
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r334333 - in head/ports-mgmt/pkg: . files
Message-ID:  <201311191730.rAJHUEfq002230@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bdrewery
Date: Tue Nov 19 17:30:14 2013
New Revision: 334333
URL: http://svnweb.freebsd.org/changeset/ports/334333

Log:
  - Update to 1.1.4_10 ahead of 1.2 update with critical fixes
  
  Changes:
   * When using SRV mirrors, order the mirrors by the advertised
     priority and weight. This should fix 'pkg update' using mirror
     A while 'pkg upgrade' and 'pkg fetch' end up using mirrors
     A, B and C, resulting in checksum errors due to not all mirrors
     being updated at the same time.
   * Add support for 'pkg+http://' URL scheme and deprecate
     'http://' when using SRV mirroring. This is only a cosmetic change
     that encourages users to not try loading the PACKAGESITE into
     a browser to view it.
  
  Discussed with:	bapt
  With hat:	portmgr
  Obtained from:	upstream git

Added:
  head/ports-mgmt/pkg/files/patch-libpkg__dns_utils.c   (contents, props changed)
  head/ports-mgmt/pkg/files/patch-libpkg__fetch.c   (contents, props changed)
  head/ports-mgmt/pkg/files/patch-libpkg__private__utils.h   (contents, props changed)
Modified:
  head/ports-mgmt/pkg/Makefile

Modified: head/ports-mgmt/pkg/Makefile
==============================================================================
--- head/ports-mgmt/pkg/Makefile	Tue Nov 19 17:13:22 2013	(r334332)
+++ head/ports-mgmt/pkg/Makefile	Tue Nov 19 17:30:14 2013	(r334333)
@@ -2,7 +2,7 @@
 
 PORTNAME=	pkg
 DISTVERSION=	1.1.4
-PORTREVISION=	9
+PORTREVISION=	10
 CATEGORIES=	ports-mgmt
 MASTER_SITES=	http://files.etoilebsd.net/pkg/ \
 		http://mirror.shatow.net/freebsd/${PORTNAME}/ \

Added: head/ports-mgmt/pkg/files/patch-libpkg__dns_utils.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/ports-mgmt/pkg/files/patch-libpkg__dns_utils.c	Tue Nov 19 17:30:14 2013	(r334333)
@@ -0,0 +1,108 @@
+--- ./libpkg/dns_utils.c.orig	2013-07-06 05:48:19.000000000 -0500
++++ ./libpkg/dns_utils.c	2013-11-19 11:13:45.349130754 -0600
+@@ -40,6 +40,65 @@
+ 	unsigned char buf[1024];
+ } query_t;
+ 
++static int
++srv_priority_cmp(const void *a, const void *b)
++{
++	const struct dns_srvinfo *da, *db;
++	
++	da = *(struct dns_srvinfo * const *)a;
++	db = *(struct dns_srvinfo * const *)b;
++
++	return ((da->priority > db->priority) - (da->priority < db->priority));
++}
++
++static int
++srv_final_cmp(const void *a, const void *b)
++{
++	const struct dns_srvinfo *da, *db;
++	int res;
++	
++	da = *(struct dns_srvinfo * const *)a;
++	db = *(struct dns_srvinfo * const *)b;
++
++	res = ((da->priority > db->priority) - (da->priority < db->priority));
++	if (res == 0)
++		res = ((db->finalweight > da->finalweight) - (db->finalweight < da->finalweight));
++
++	return (res);
++}
++
++static void
++compute_weight(struct dns_srvinfo **d, int first, int last)
++{
++	int i, j;
++	int totalweight = 0;
++	int *chosen;
++
++	for (i = 0; i <= last; i++)
++		totalweight += d[i]->weight;
++
++	if (totalweight == 0)
++		return;
++
++	chosen = malloc(sizeof(int) * (last - first + 1));
++
++	for (i = 0; i <= last; i++) {
++		for (;;) {
++			chosen[i] = random() % (d[i]->weight * 100 / totalweight);
++			for (j = 0; j < i; j++) {
++				if (chosen[i] == chosen[j])
++					break;
++			}
++			if (j == i) {
++				d[i]->finalweight = chosen[i];
++				break;
++			}
++		}
++	}
++
++	free(chosen);
++}
++
+ struct dns_srvinfo *
+ dns_getsrvinfo(const char *zone)
+ {
+@@ -49,6 +108,7 @@
+ 	struct dns_srvinfo **res, *first;
+ 	unsigned char *end, *p;
+ 	unsigned int type, class, ttl, priority, weight, port;
++	int f, l;
+ 
+ 	if ((len = res_query(zone, C_IN, T_SRV, q.buf, sizeof(q.buf))) == -1 ||
+ 	    len < (int)sizeof(HEADER))
+@@ -120,12 +180,31 @@
+ 		res[n]->weight = weight;
+ 		res[n]->port = port;
+ 		res[n]->next = NULL;
++		res[n]->finalweight = 0;
+ 		strlcpy(res[n]->host, host, MAXHOSTNAMELEN);
+ 
+ 		p += len;
+ 		n++;
+ 	}
+ 
++	/* order by priority */
++	qsort(res, n, sizeof(res[0]), srv_priority_cmp);
++
++	priority = 0;
++	f = 0;
++	l = 0;
++	for (i = 0; i < n; i++) {
++		if (res[i]->priority != priority) {
++			if (f != l)
++				compute_weight(res, f, l);
++			f = i;
++			priority = res[i]->priority;
++		}
++		l = i;
++	}
++
++	qsort(res, n, sizeof(res[0]), srv_final_cmp);
++
+ 	for (i = 0; i < n - 1; i++)
+ 		res[i]->next = res[i + 1];
+ 

Added: head/ports-mgmt/pkg/files/patch-libpkg__fetch.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/ports-mgmt/pkg/files/patch-libpkg__fetch.c	Tue Nov 19 17:30:14 2013	(r334333)
@@ -0,0 +1,88 @@
+--- ./libpkg/fetch.c.orig	2013-07-06 05:48:19.000000000 -0500
++++ ./libpkg/fetch.c	2013-11-19 11:13:45.352130038 -0600
+@@ -179,6 +179,8 @@
+ 	return (EPKG_FATAL);
+ }
+ 
++#define URL_SCHEME_PREFIX	"pkg+"
++
+ int
+ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t)
+ {
+@@ -204,6 +206,7 @@
+ 	int kq = -1, flags = 0;
+ 	struct kevent e, ev;
+ 	struct timespec ts;
++	bool pkg_url_scheme = false;
+ 
+ 	if (pkg_config_int64(PKG_CONFIG_FETCH_RETRY, &max_retry) == EPKG_FATAL)
+ 		max_retry = 3;
+@@ -215,6 +218,34 @@
+ 
+ 	retry = max_retry;
+ 
++	/* A URL of the form http://host.example.com/ where
++	 * host.example.com does not resolve as a simple A record is
++	 * not valid according to RFC 2616 Section 3.2.2.  Our usage
++	 * with SRV records is incorrect.  However it is encoded into
++	 * /usr/sbin/pkg in various releases so we can't just drop it.
++         *
++         * Instead, introduce new pkg+http://, pkg+https://,
++	 * pkg+ssh://, pkg+ftp://, pkg+file:// to support the
++	 * SRV-style server discovery, and also to allow eg. Firefox
++	 * to run pkg-related stuff given a pkg+foo:// URL.
++	 *
++	 * Warn if using plain http://, https:// etc with SRV
++	 */
++
++	if (strncmp(URL_SCHEME_PREFIX, url, strlen(URL_SCHEME_PREFIX)) == 0) {
++		if (repo->mirror_type != SRV) {
++			pkg_emit_error("packagesite URL error for %s -- "
++				       URL_SCHEME_PREFIX
++				       ":// implies SRV mirror type", url);
++
++			/* Too early for there to be anything to cleanup */
++			return(EPKG_FATAL);
++		}
++
++		url += strlen(URL_SCHEME_PREFIX);
++		pkg_url_scheme = true;
++	}
++
+ 	u = fetchParseURL(url);
+ 	if (t != NULL)
+ 		u->ims_time = *t;
+@@ -253,6 +284,12 @@
+ 			if (repo != NULL && repo->mirror_type == SRV &&
+ 			    (strncmp(u->scheme, "http", 4) == 0
+ 			     || strcmp(u->scheme, "ftp") == 0)) {
++
++				if (!pkg_url_scheme)
++					pkg_emit_notice(
++     "Warning: use of %s:// URL scheme with SRV records is deprecated: "
++     "switch to pkg+%s://", u->scheme, u->scheme);
++
+ 				snprintf(zone, sizeof(zone),
+ 				    "_%s._tcp.%s", u->scheme, u->host);
+ 				if (repo->srv == NULL)
+@@ -268,8 +305,10 @@
+ 			}
+ 		}
+ 
+-		if (repo != NULL && repo->mirror_type == SRV && repo->srv != NULL)
++		if (repo != NULL && repo->mirror_type == SRV && repo->srv != NULL) {
+ 			strlcpy(u->host, srv_current->host, sizeof(u->host));
++			u->port = srv_current->port;
++		}
+ 		else if (repo != NULL && repo->mirror_type == HTTP && repo->http != NULL) {
+ 			strlcpy(u->scheme, http_current->url->scheme, sizeof(u->scheme));
+ 			strlcpy(u->host, http_current->url->host, sizeof(u->host));
+@@ -366,7 +405,7 @@
+ 
+ 	cleanup:
+ 
+-	if (strcmp(u->scheme, "ssh") != 0) {
++	if (u != NULL && strcmp(u->scheme, "ssh") != 0) {
+ 		if (remote != NULL)
+ 			fclose(remote);
+ 	} else {

Added: head/ports-mgmt/pkg/files/patch-libpkg__private__utils.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/ports-mgmt/pkg/files/patch-libpkg__private__utils.h	Tue Nov 19 17:30:14 2013	(r334333)
@@ -0,0 +1,10 @@
+--- ./libpkg/private/utils.h.orig	2013-07-06 05:48:19.000000000 -0500
++++ ./libpkg/private/utils.h	2013-11-19 11:13:45.354131958 -0600
+@@ -60,6 +60,7 @@
+ 	unsigned int priority;
+ 	unsigned int weight;
+ 	unsigned int port;
++	unsigned int finalweight;
+ 	char host[MAXHOSTNAMELEN];
+ 	struct dns_srvinfo *next;
+ };



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311191730.rAJHUEfq002230>