|
Packit Service |
dff8e4 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
Packit Service |
dff8e4 |
#pragma once
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
#include <netinet/in.h>
|
|
Packit Service |
dff8e4 |
#include <stddef.h>
|
|
Packit Service |
dff8e4 |
#include <sys/socket.h>
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
#include "hash-funcs.h"
|
|
Packit Service |
dff8e4 |
#include "macro.h"
|
|
Packit Service |
dff8e4 |
#include "util.h"
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
union in_addr_union {
|
|
Packit Service |
dff8e4 |
struct in_addr in;
|
|
Packit Service |
dff8e4 |
struct in6_addr in6;
|
|
Packit Service |
dff8e4 |
uint8_t bytes[CONST_MAX(sizeof(struct in_addr), sizeof(struct in6_addr))];
|
|
Packit Service |
dff8e4 |
};
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
struct in_addr_data {
|
|
Packit Service |
dff8e4 |
int family;
|
|
Packit Service |
dff8e4 |
union in_addr_union address;
|
|
Packit Service |
dff8e4 |
};
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
bool in4_addr_is_null(const struct in_addr *a);
|
|
Packit Bot |
c44df3 |
static inline bool in4_addr_is_set(const struct in_addr *a) {
|
|
Packit Bot |
c44df3 |
return !in4_addr_is_null(a);
|
|
Packit Bot |
c44df3 |
}
|
|
Packit Bot |
c44df3 |
bool in6_addr_is_null(const struct in6_addr *a);
|
|
Packit Bot |
c44df3 |
static inline bool in6_addr_is_set(const struct in6_addr *a) {
|
|
Packit Bot |
c44df3 |
return !in6_addr_is_null(a);
|
|
Packit Bot |
c44df3 |
}
|
|
Packit Service |
dff8e4 |
int in_addr_is_null(int family, const union in_addr_union *u);
|
|
Packit Bot |
c44df3 |
static inline bool in_addr_is_set(int family, const union in_addr_union *u) {
|
|
Packit Bot |
c44df3 |
return in_addr_is_null(family, u) == 0;
|
|
Packit Bot |
c44df3 |
}
|
|
Packit Bot |
c44df3 |
static inline int in_addr_data_is_null(const struct in_addr_data *a) {
|
|
Packit Bot |
c44df3 |
assert(a);
|
|
Packit Bot |
c44df3 |
return in_addr_is_null(a->family, &a->address);
|
|
Packit Bot |
c44df3 |
}
|
|
Packit Bot |
c44df3 |
static inline bool in_addr_data_is_set(const struct in_addr_data *a) {
|
|
Packit Bot |
c44df3 |
return in_addr_data_is_null(a);
|
|
Packit Bot |
c44df3 |
}
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
int in_addr_is_multicast(int family, const union in_addr_union *u);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
bool in4_addr_is_link_local(const struct in_addr *a);
|
|
Packit Bot |
c44df3 |
bool in6_addr_is_link_local(const struct in6_addr *a);
|
|
Packit Service |
dff8e4 |
int in_addr_is_link_local(int family, const union in_addr_union *u);
|
|
Packit Service |
dff8e4 |
bool in6_addr_is_link_local_all_nodes(const struct in6_addr *a);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
bool in4_addr_is_localhost(const struct in_addr *a);
|
|
Packit Service |
dff8e4 |
int in_addr_is_localhost(int family, const union in_addr_union *u);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
bool in4_addr_is_local_multicast(const struct in_addr *a);
|
|
Packit Service |
dff8e4 |
bool in4_addr_is_non_local(const struct in_addr *a);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
bool in4_addr_equal(const struct in_addr *a, const struct in_addr *b);
|
|
Packit Bot |
c44df3 |
bool in6_addr_equal(const struct in6_addr *a, const struct in6_addr *b);
|
|
Packit Service |
dff8e4 |
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b);
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen);
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_nth(int family, union in_addr_union *u, unsigned prefixlen, uint64_t nth);
|
|
Packit Service |
dff8e4 |
int in_addr_random_prefix(int family, union in_addr_union *u, unsigned prefixlen_fixed_part, unsigned prefixlen);
|
|
Packit Bot |
c44df3 |
int in_addr_prefix_range(
|
|
Packit Bot |
c44df3 |
int family,
|
|
Packit Bot |
c44df3 |
const union in_addr_union *in,
|
|
Packit Bot |
c44df3 |
unsigned prefixlen,
|
|
Packit Bot |
c44df3 |
union in_addr_union *ret_start,
|
|
Packit Bot |
c44df3 |
union in_addr_union *ret_end);
|
|
Packit Service |
dff8e4 |
int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **ret);
|
|
Packit Service |
dff8e4 |
int in_addr_port_ifindex_name_to_string(int family, const union in_addr_union *u, uint16_t port, int ifindex, const char *server_name, char **ret);
|
|
Packit Service |
dff8e4 |
static inline int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) {
|
|
Packit Service |
dff8e4 |
return in_addr_port_ifindex_name_to_string(family, u, 0, ifindex, NULL, ret);
|
|
Packit Service |
dff8e4 |
}
|
|
Packit Service |
dff8e4 |
static inline int in_addr_port_to_string(int family, const union in_addr_union *u, uint16_t port, char **ret) {
|
|
Packit Service |
dff8e4 |
return in_addr_port_ifindex_name_to_string(family, u, port, 0, NULL, ret);
|
|
Packit Service |
dff8e4 |
}
|
|
Packit Service |
dff8e4 |
int in_addr_from_string(int family, const char *s, union in_addr_union *ret);
|
|
Packit Service |
dff8e4 |
int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union *ret);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
unsigned char in4_addr_netmask_to_prefixlen(const struct in_addr *addr);
|
|
Packit Service |
dff8e4 |
struct in_addr* in4_addr_prefixlen_to_netmask(struct in_addr *addr, unsigned char prefixlen);
|
|
Packit Service |
dff8e4 |
int in4_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen);
|
|
Packit Service |
dff8e4 |
int in4_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mask);
|
|
Packit Service |
dff8e4 |
int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen);
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_covers(int family, const union in_addr_union *prefix, unsigned char prefixlen, const union in_addr_union *address);
|
|
Packit Service |
dff8e4 |
int in_addr_parse_prefixlen(int family, const char *p, unsigned char *ret);
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_from_string(const char *p, int family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
typedef enum InAddrPrefixLenMode {
|
|
Packit Service |
dff8e4 |
PREFIXLEN_FULL, /* Default to prefixlen of address size, 32 for IPv4 or 128 for IPv6, if not specified. */
|
|
Packit Service |
dff8e4 |
PREFIXLEN_REFUSE, /* Fail with -ENOANO if prefixlen is not specified. */
|
|
Packit Service |
dff8e4 |
PREFIXLEN_LEGACY, /* Default to legacy default prefixlen calculation from address if not specified. */
|
|
Packit Service |
dff8e4 |
} InAddrPrefixLenMode;
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
int in_addr_prefix_from_string_auto_internal(const char *p, InAddrPrefixLenMode mode, int *ret_family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen);
|
|
Packit Service |
dff8e4 |
static inline int in_addr_prefix_from_string_auto(const char *p, int *ret_family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen) {
|
|
Packit Service |
dff8e4 |
return in_addr_prefix_from_string_auto_internal(p, PREFIXLEN_FULL, ret_family, ret_prefix, ret_prefixlen);
|
|
Packit Service |
dff8e4 |
}
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
static inline size_t FAMILY_ADDRESS_SIZE(int family) {
|
|
Packit Service |
dff8e4 |
assert(IN_SET(family, AF_INET, AF_INET6));
|
|
Packit Service |
dff8e4 |
return family == AF_INET6 ? 16 : 4;
|
|
Packit Service |
dff8e4 |
}
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
/* Workaround for clang, explicitly specify the maximum-size element here.
|
|
Packit Service |
dff8e4 |
* See also oss-fuzz#11344. */
|
|
Packit Service |
dff8e4 |
#define IN_ADDR_NULL ((union in_addr_union) { .in6 = {} })
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
void in6_addr_hash_func(const struct in6_addr *addr, struct siphash *state);
|
|
Packit Service |
dff8e4 |
int in6_addr_compare_func(const struct in6_addr *a, const struct in6_addr *b);
|
|
Packit Service |
dff8e4 |
|
|
Packit Service |
dff8e4 |
extern const struct hash_ops in_addr_data_hash_ops;
|
|
Packit Service |
dff8e4 |
extern const struct hash_ops in6_addr_hash_ops;
|