summaryrefslogtreecommitdiffstats
path: root/src/include/ipaddr.h
blob: bf06cfc93642af2129a9ba354e2d9fd76826379d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef CEPH_IPADDR_H
#define CEPH_IPADDR_H

class entity_addr_t;

/*
 * Check if an IP address that is in the wanted subnet.
 */
bool matches_ipv4_in_subnet(const struct ifaddrs& addrs,
                            const struct sockaddr_in* net,
                            unsigned int prefix_len);
bool matches_ipv6_in_subnet(const struct ifaddrs& addrs,
                            const struct sockaddr_in6* net,
                            unsigned int prefix_len);

/*
 * Validate and parse IPv4 or IPv6 network
 *
 * Given a network (e.g. "192.168.0.0/24") and pointers to a sockaddr_storage
 * struct and an unsigned int:
 *
 * if the network string is valid, return true and populate sockaddr_storage
 * and prefix_len;
 *
 * if the network string is invalid, return false.
 */
bool parse_network(const char *s,
		   struct sockaddr_storage *network,
		   unsigned int *prefix_len);
bool parse_network(const char *s,
		   entity_addr_t *network,
		   unsigned int *prefix_len);

void netmask_ipv6(const struct in6_addr *addr,
		  unsigned int prefix_len,
		  struct in6_addr *out);

void netmask_ipv4(const struct in_addr *addr,
		  unsigned int prefix_len,
		  struct in_addr *out);

bool network_contains(
	const struct entity_addr_t& network,
	unsigned int prefix_len,
	const struct entity_addr_t& addr);

#endif