Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
IP: rework support for ip v4 vs v6
Baptiste Daroussin committed 2 years ago
commit 288b4deeac3f4e95a96bb2b4f3a8d6488ebf7b03
parent e473264
4 files changed +29 -16
modified libpkg/fetch_libcurl.c
@@ -152,6 +152,10 @@ http_getmirrors(struct curl_repodata *cr)
	curl_easy_setopt(cl, CURLOPT_HEADERFUNCTION, curl_ph_cb);
	curl_easy_setopt(cl, CURLOPT_HEADERDATA, &data);
	curl_do_fetch(&data, cl, cr);
+
	if (ctx.ip == IPV4)
+
		curl_easy_setopt(cl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+
	if (ctx.ip == IPV6)
+
		curl_easy_setopt(cl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
	walk = buf;
	while ((line = strsep(&walk, "\n\r")) != NULL) {
		if (strncmp(line, "URL:", 4) != 0)
@@ -358,6 +362,10 @@ retry:
	} else {
		curl_easy_setopt(cl, CURLOPT_URL, fi->url);
	}
+
	if (repo->ip == IPV4)
+
		curl_easy_setopt(cl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+
	if (repo->ip == IPV6)
+
		curl_easy_setopt(cl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
	curl_easy_setopt(cl, CURLOPT_WRITEFUNCTION, curl_write_cb);
	curl_easy_setopt(cl, CURLOPT_WRITEDATA, &data);
	curl_easy_setopt(cl, CURLOPT_XFERINFOFUNCTION, curl_progress_cb);
modified libpkg/fetch_ssh.c
@@ -65,9 +65,9 @@ tcp_connect(struct pkg_repo *repo, struct yuarel *u)
	pkg_debug(1, "TCP> tcp_connect");
	memset(&hints, 0, sizeof(hints));
	hints.ai_family = PF_UNSPEC;
-
	if ((repo->flags & REPO_FLAGS_USE_IPV4) == REPO_FLAGS_USE_IPV4)
+
	if (repo->ip == IPV4)
		hints.ai_family = PF_INET;
-
	else if ((repo->flags & REPO_FLAGS_USE_IPV6) == REPO_FLAGS_USE_IPV6)
+
	else if (repo->ip == IPV6)
		hints.ai_family = PF_INET6;
	hints.ai_socktype = SOCK_STREAM;
	snprintf(srv, sizeof(srv), "%d", u->port);
@@ -167,9 +167,9 @@ ssh_connect(struct pkg_repo *repo, struct yuarel *u)
		ssh_args = pkg_object_string(pkg_config_get("PKG_SSH_ARGS"));
		if (ssh_args != NULL)
			fprintf(cmd->fp, "%s ", ssh_args);
-
		if ((repo->flags & REPO_FLAGS_USE_IPV4) == REPO_FLAGS_USE_IPV4)
+
		if (repo->ip == IPV4)
			fputs("-4 ", cmd->fp);
-
		else if ((repo->flags & REPO_FLAGS_USE_IPV6) == REPO_FLAGS_USE_IPV6)
+
		else if (repo->ip == IPV6)
			fputs("-6 ", cmd->fp);
		if (u->port > 0)
			fprintf(cmd->fp, "-p %d ", u->port);
modified libpkg/pkg_config.c
@@ -764,9 +764,9 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname, pkg_ini
		use_ipvx = pkg_object_int(pkg_config_get("IP_VERSION"));

	if (use_ipvx == 4)
-
		r->flags = REPO_FLAGS_USE_IPV4;
+
		r->ip = IPV4;
	else if (use_ipvx == 6)
-
		r->flags = REPO_FLAGS_USE_IPV6;
+
		r->ip = IPV6;

	if (env != NULL) {
		it = NULL;
@@ -1040,6 +1040,10 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
		err = EPKG_FATAL;
		goto out;
	}
+
	if ((flags & PKG_INIT_FLAG_USE_IPV4) == PKG_INIT_FLAG_USE_IPV4)
+
		ctx.ip = IPV4;
+
	if ((flags & PKG_INIT_FLAG_USE_IPV4) == PKG_INIT_FLAG_USE_IPV4)
+
		ctx.ip = IPV6;

	config = ucl_object_typed_new(UCL_OBJECT);

@@ -1607,12 +1611,11 @@ pkg_repo_priority(struct pkg_repo *r)
unsigned int
pkg_repo_ip_version(struct pkg_repo *r)
{
-
	if ((r->flags & PKG_INIT_FLAG_USE_IPV4) == PKG_INIT_FLAG_USE_IPV4)
+
	if (r->ip == IPV4)
		return 4;
-
	else if ((r->flags & PKG_INIT_FLAG_USE_IPV6) == PKG_INIT_FLAG_USE_IPV6)
+
	if (r->ip == IPV6)
		return 6;
-
	else
-
		return 0;
+
	return 0;
}

/* Locate the repo by the file basename / database name */
modified libpkg/private/pkg.h
@@ -131,6 +131,12 @@
typedef tll(struct pkg_kv *) kvlist_t;
typedef tll(char *) stringlist_t;

+
typedef enum {
+
	IPALL = 0,
+
	IPV4,
+
	IPV6,
+
} ip_version_t;
+

struct pkg_kvlist {
	kvlist_t *list;
};
@@ -172,6 +178,7 @@ struct pkg_ctx {
	pkghash *touched_dir_hash;
	bool defer_triggers;
	bool repo_accept_legacy_pkg;
+
	ip_version_t ip;
};

extern struct pkg_ctx ctx;
@@ -493,11 +500,6 @@ struct pkg_repo_ops {
		const char *destdir);
};

-
typedef enum _pkg_repo_flags {
-
	REPO_FLAGS_USE_IPV4 = (1U << 0),
-
	REPO_FLAGS_USE_IPV6 = (1U << 1)
-
} pkg_repo_flags;
-

struct pkg_repo {
	struct pkg_repo_ops *ops;

@@ -531,7 +533,7 @@ struct pkg_repo {

	unsigned int priority;

-
	pkg_repo_flags flags;
+
	ip_version_t ip;
	kvlist_t env;

	/* Opaque repository data */