Blame bin/tests/system/feature-test.c

Packit 5ce601
/*
Packit 5ce601
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit 5ce601
 *
Packit 5ce601
 * This Source Code Form is subject to the terms of the Mozilla Public
Packit 5ce601
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service 704ed8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
Packit 5ce601
 *
Packit 5ce601
 * See the COPYRIGHT file distributed with this work for additional
Packit 5ce601
 * information regarding copyright ownership.
Packit 5ce601
 */
Packit 5ce601
Packit 5ce601
#include <config.h>
Packit 5ce601
Packit 5ce601
#include <unistd.h>
Packit 5ce601
#include <stdio.h>
Packit 5ce601
#include <stdlib.h>
Packit 5ce601
#include <string.h>
Packit 5ce601
Packit 5ce601
#include <isc/print.h>
Packit 5ce601
#include <isc/util.h>
Packit 5ce601
#include <isc/net.h>
Packit 5ce601
#include <dns/edns.h>
Packit 5ce601
Packit 5ce601
#ifdef WIN32
Packit 5ce601
#include <Winsock2.h>
Packit 5ce601
#endif
Packit 5ce601
Packit 5ce601
#ifndef MAXHOSTNAMELEN
Packit 5ce601
#ifdef HOST_NAME_MAX
Packit 5ce601
#define MAXHOSTNAMELEN HOST_NAME_MAX
Packit 5ce601
#else
Packit 5ce601
#define MAXHOSTNAMELEN 256
Packit 5ce601
#endif
Packit 5ce601
#endif
Packit 5ce601
Packit 5ce601
static void
Packit 5ce601
usage() {
Packit 5ce601
	fprintf(stderr, "usage: feature-test <arg>\n");
Packit 5ce601
	fprintf(stderr, "args:\n");
Packit Service 704ed8
	fprintf(stderr, "\t--edns-version\n");
Packit Service 704ed8
	fprintf(stderr, "\t--enable-filter-aaaa\n");
Packit Service 704ed8
	fprintf(stderr, "\t--gethostname\n");
Packit Service 704ed8
	fprintf(stderr, "\t--gssapi\n");
Packit Service 704ed8
	fprintf(stderr, "\t--have-aes\n");
Packit Service 704ed8
	fprintf(stderr, "\t--have-dlopen\n");
Packit Service 704ed8
	fprintf(stderr, "\t--have-geoip2\n");
Packit Service 704ed8
	fprintf(stderr, "\t--have-geoip\n");
Packit Service 704ed8
	fprintf(stderr, "\t--have-libxml2\n");
Packit Service 704ed8
	fprintf(stderr, "\t--ipv6only=no\n");
Packit Service 704ed8
	fprintf(stderr, "\t--rpz-log-qtype-qclass\n");
Packit Service 704ed8
	fprintf(stderr, "\t--rpz-nsdname\n");
Packit Service 704ed8
	fprintf(stderr, "\t--rpz-nsip\n");
Packit Service 704ed8
	fprintf(stderr, "\t--tsan\n");
Packit Service 704ed8
	fprintf(stderr, "\t--with-dlz-filesystem\n");
Packit Service 704ed8
	fprintf(stderr, "\t--with-idn\n");
Packit Service 704ed8
	fprintf(stderr, "\t--with-lmdb\n");
Packit 5ce601
}
Packit 5ce601
Packit 5ce601
int
Packit 5ce601
main(int argc, char **argv) {
Packit 5ce601
	if (argc != 2) {
Packit 5ce601
		usage();
Packit 5ce601
		return (1);
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--edns-version") == 0) {
Packit 5ce601
#ifdef DNS_EDNS_VERSION
Packit 5ce601
		printf("%d\n", DNS_EDNS_VERSION);
Packit 5ce601
#else
Packit 5ce601
		printf("0\n");
Packit 5ce601
#endif
Packit 5ce601
		return (0);
Packit 5ce601
	}
Packit 5ce601
Packit Service 704ed8
	if (strcmp(argv[1], "--enable-filter-aaaa") == 0) {
Packit Service 704ed8
#ifdef ALLOW_FILTER_AAAA
Packit Service 704ed8
		return (0);
Packit Service 704ed8
#else
Packit Service 704ed8
		return (1);
Packit Service 704ed8
#endif
Packit Service 704ed8
	}
Packit Service 704ed8
Packit 5ce601
	if (strcmp(argv[1], "--gethostname") == 0) {
Packit 5ce601
		char hostname[MAXHOSTNAMELEN];
Packit 5ce601
		int n;
Packit 5ce601
#ifdef WIN32
Packit 5ce601
		/* From lwres InitSocket() */
Packit 5ce601
		WORD wVersionRequested;
Packit 5ce601
		WSADATA wsaData;
Packit 5ce601
		int err;
Packit 5ce601
Packit 5ce601
		wVersionRequested = MAKEWORD(2, 0);
Packit 5ce601
		err = WSAStartup( wVersionRequested, &wsaData );
Packit 5ce601
		if (err != 0) {
Packit 5ce601
			fprintf(stderr, "WSAStartup() failed: %d\n", err);
Packit 5ce601
			exit(1);
Packit 5ce601
		}
Packit 5ce601
#endif
Packit 5ce601
Packit 5ce601
		n = gethostname(hostname, sizeof(hostname));
Packit 5ce601
		if (n == -1) {
Packit 5ce601
			perror("gethostname");
Packit 5ce601
			return(1);
Packit 5ce601
		}
Packit 5ce601
		fprintf(stdout, "%s\n", hostname);
Packit 5ce601
#ifdef WIN32
Packit 5ce601
		WSACleanup();
Packit 5ce601
#endif
Packit 5ce601
		return (0);
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--gssapi") == 0) {
Packit 5ce601
#if defined(GSSAPI)
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--have-aes") == 0) {
Packit 5ce601
#if defined(HAVE_OPENSSL_AES) || defined(HAVE_OPENSSL_EVP_AES)
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--have-dlopen") == 0) {
Packit 5ce601
#if defined(HAVE_DLOPEN) && defined(ISC_DLZ_DLOPEN)
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--have-geoip") == 0) {
Packit 5ce601
#ifdef HAVE_GEOIP
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--have-geoip2") == 0) {
Packit 5ce601
#ifdef HAVE_GEOIP2
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--have-libxml2") == 0) {
Packit 5ce601
#ifdef HAVE_LIBXML2
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit Service 704ed8
	if (strcmp(argv[1], "--ipv6only=no") == 0) {
Packit Service 704ed8
#ifdef WIN32
Packit Service 704ed8
		return (0);
Packit Service 704ed8
#elif defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
Packit Service 704ed8
		int s;
Packit Service 704ed8
		int n = -1;
Packit Service 704ed8
		int v6only = -1;
Packit Service 704ed8
		ISC_SOCKADDR_LEN_T len = sizeof(v6only);
Packit Service 704ed8
Packit Service 704ed8
		s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
Packit Service 704ed8
		if (s >= 0) {
Packit Service 704ed8
			n = getsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
Packit Service 704ed8
				       (void *)&v6only, &len;;
Packit Service 704ed8
			close(s);
Packit Service 704ed8
		}
Packit Service 704ed8
		return ((n == 0 && v6only == 0) ? 0 : 1);
Packit Service 704ed8
#else
Packit Service 704ed8
		return (1);
Packit Service 704ed8
#endif
Packit Service 704ed8
	}
Packit Service 704ed8
Packit Service 704ed8
	if (strcmp(argv[1], "--rpz-log-qtype-qclass") == 0) {
Packit Service 704ed8
#ifdef RPZ_LOG_QTYPE_QCLASS
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--rpz-nsdname") == 0) {
Packit 5ce601
#ifdef ENABLE_RPZ_NSDNAME
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit Service 704ed8
	if (strcmp(argv[1], "--rpz-nsip") == 0) {
Packit Service 704ed8
#ifdef ENABLE_RPZ_NSIP
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit Service 704ed8
	if (strcmp(argv[1], "--tsan") == 0) {
Packit Service 704ed8
#if defined(__has_feature)
Packit Service 704ed8
#if __has_feature(thread_sanitizer)
Packit Service 704ed8
		return (0);
Packit Service 704ed8
#endif
Packit Service 704ed8
#endif
Packit Service 704ed8
#if __SANITIZE_THREAD__
Packit 5ce601
		return (0);
Packit 5ce601
#else
Packit 5ce601
		return (1);
Packit 5ce601
#endif
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	if (strcmp(argv[1], "--with-dlz-filesystem") == 0) {
Packit 5ce601
#ifdef DLZ_FILESYSTEM
Packit 5ce601
		return (0);
Packit Service 704ed8
#else  /* ifdef DLZ_FILESYSTEM */
Packit 5ce601
		return (1);
Packit Service 704ed8
#endif /* ifdef DLZ_FILESYSTEM */
Packit 5ce601
	}
Packit 5ce601
Packit Service 704ed8
	if (strcmp(argv[1], "--with-idn") == 0) {
Packit Service 704ed8
#ifdef HAVE_LIBIDN2
Packit 5ce601
		return (0);
Packit Service 704ed8
#else  /* ifdef HAVE_LIBIDN2 */
Packit 5ce601
		return (1);
Packit Service 704ed8
#endif /* ifdef HAVE_LIBIDN2 */
Packit 5ce601
	}
Packit 5ce601
Packit Service 704ed8
	if (strcmp(argv[1], "--with-lmdb") == 0) {
Packit Service 704ed8
#ifdef HAVE_LMDB
Packit 5ce601
		return (0);
Packit Service 704ed8
#else  /* ifdef HAVE_LMDB */
Packit 5ce601
		return (1);
Packit Service 704ed8
#endif /* ifdef HAVE_LMDB */
Packit 5ce601
	}
Packit 5ce601
Packit 5ce601
	fprintf(stderr, "unknown arg: %s\n", argv[1]);
Packit 5ce601
	usage();
Packit 5ce601
	return (1);
Packit 5ce601
}