Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freebsd-pkg: add mirror_type: "none" #264

Merged
merged 1 commit into from
Sep 14, 2024
Merged

freebsd-pkg: add mirror_type: "none" #264

merged 1 commit into from
Sep 14, 2024

Conversation

CismonX
Copy link
Contributor

@CismonX CismonX commented Sep 13, 2024

Since currently there is no SRV record on either _http._tcp.mirrors.ustc.edu.cn or _https._tcp.mirrors.ustc.edu.cn, the mirror_type field in /etc/pkg/FreeBSD.conf should be overridden to none, otherwise pkg(8) may produce warnings like:

pkg: No SRV record found for the repo 'FreeBSD'

See also: pkg.conf(5), #90665, #90716

@taoky
Copy link
Member

taoky commented Sep 14, 2024

In pkg.conf(5), it says:

		MIRROR_TYPE: string  MIRROR_TYPE  for  this  repository	 only.
				     Default:  NONE.   Any  of	HTTP or	SRV or
				     NONE.

And:

       For a MIRROR_TYPE of NONE, any of the following URL  schemes:  http://,
       https://,  file://,  ssh://,  tcp://.   Where  MIRROR_TYPE  is SRV, you
       should use a pkg+http://	or pkg+https://	(etc.) URL scheme.   Using  an
       http:// URL implies that	the hostname part is a simple hostname accord-
       ing to RFC 2616,	and is no longer accepted.

I'm curious that if it's really necessary to explicitly declare mirror_type as none.

@CismonX
Copy link
Contributor Author

CismonX commented Sep 14, 2024

In pkg.conf(5):

Repository configuration files are searched for in order of the
directories listed in the REPOS_DIR array, which defaults to
/etc/pkg/ and /usr/local/etc/pkg/repos/.

Also:

Reusing the repository tag will cause those items defined in
configuration files later on the REPOS_DIR search path to
overwrite the equivalent settings for the same tag
earlier on the search path.

Since the default configuration in /etc/pkg/FreeBSD.conf already declares mirror_type as srv, that value will be used by pkg(8) unless explicitly overridden.

In freebsd/pkg/libpkg/fetch_libcurl.c:

// ...
if (repo->mirror_type == SRV && repo->srv == NULL) {
    int urloff = 0;
    cr->url = curl_url();
    if (strncasecmp(repo->url, "pkg+", 4) == 0)
        urloff = 4;
    CURLUcode c = curl_url_set(cr->url, CURLUPART_URL, repo->url + urloff, 0);
    if (c) {
        pkg_emit_error("impossible to parse url: '%s'", repo->url);
        return (EPKG_FATAL);
    }

    char *zone;
    char *host = NULL, *scheme = NULL;
    curl_url_get(cr->url, CURLUPART_HOST, &host, 0);
    curl_url_get(cr->url, CURLUPART_SCHEME, &scheme, 0);
    xasprintf(&zone, "_%s._tcp.%s", scheme, host);
    repo->srv = dns_getsrvinfo(zone);
    free(zone);
    free(host);
    free(scheme);
    if (repo->srv == NULL) {
        pkg_emit_error("No SRV record found for the "
            "repo '%s'", repo->name);
        repo->mirror_type = NOMIRROR;
    }
}
// ...

When mirror_type is srv, pkg(8) attempts to resolve the SRV record even if the URL is not prefixed with pkg+, leading to the aforementioned warning message.

This behavior is introduced in commit #f06399ce03, and continues to exist in all releases since 1.20.0. That explains why users never encountered this problem until recently...

@taoky taoky merged commit 3a9afe3 into ustclug:master Sep 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants