| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "basic-forward.h" |
| 5 |
#include "strv.h" |
| 6 |
|
| 7 |
/* HOST_NAME_MAX should be 64 on linux, but musl uses the one by POSIX (255). */ |
| 8 |
#define LINUX_HOST_NAME_MAX CONST_MIN((size_t) HOST_NAME_MAX, (size_t) 64) |
| 9 |
|
| 10 |
char* get_default_hostname_raw(void); |
| 11 |
|
| 12 |
bool valid_ldh_char(char c) _const_; |
| 13 |
|
| 14 |
typedef enum ValidHostnameFlags { |
| 15 |
VALID_HOSTNAME_TRAILING_DOT = 1 << 0, /* Accept trailing dot on multi-label names */ |
| 16 |
VALID_HOSTNAME_DOT_HOST = 1 << 1, /* Accept ".host" as valid hostname */ |
| 17 |
VALID_HOSTNAME_QUESTION_MARK = 1 << 2, /* Accept "?" as place holder for hashed machine ID value */ |
| 18 |
} ValidHostnameFlags; |
| 19 |
|
| 20 |
bool hostname_is_valid(const char *s, ValidHostnameFlags flags) _pure_; |
| 21 |
char* hostname_cleanup(char *s); |
| 22 |
|
| 23 |
bool is_localhost(const char *hostname); |
| 24 |
|
| 25 |
static inline bool is_gateway_hostname(const char *hostname) { |
| 26 |
/* This tries to identify the valid syntaxes for the our synthetic "gateway" host. */ |
| 27 |
return STRCASE_IN_SET(hostname, "_gateway", "_gateway."); |
| 28 |
} |
| 29 |
|
| 30 |
static inline bool is_outbound_hostname(const char *hostname) { |
| 31 |
/* This tries to identify the valid syntaxes for the our synthetic "outbound" host. */ |
| 32 |
return STRCASE_IN_SET(hostname, "_outbound", "_outbound."); |
| 33 |
} |
| 34 |
|
| 35 |
static inline bool is_dns_stub_hostname(const char *hostname) { |
| 36 |
return STRCASE_IN_SET(hostname, "_localdnsstub", "_localdnsstub."); |
| 37 |
} |
| 38 |
|
| 39 |
static inline bool is_dns_proxy_stub_hostname(const char *hostname) { |
| 40 |
return STRCASE_IN_SET(hostname, "_localdnsproxy", "_localdnsproxy."); |
| 41 |
} |
| 42 |
|
| 43 |
const char* etc_hostname(void); |
| 44 |
const char* etc_machine_info(void); |
| 45 |
|
| 46 |
int get_pretty_hostname(char **ret); |
| 47 |
|
| 48 |
int machine_spec_valid(const char *s); |
| 49 |
int split_user_at_host(const char *s, char **ret_user, char **ret_host); |
| 50 |
|
| 51 |
#define MACHINE_TAGS_MAX 1024U |
| 52 |
|
| 53 |
bool machine_tag_is_valid(const char *s); |
| 54 |
bool machine_tag_list_is_valid(char **l); |
| 55 |
int machine_tags_from_string(const char *s, bool graceful, char ***ret); |