]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef CEPH_IPADDR_H |
2 | #define CEPH_IPADDR_H | |
3 | ||
11fdf7f2 | 4 | class entity_addr_t; |
7c673cae | 5 | |
11fdf7f2 | 6 | /* |
ec96510d | 7 | * Check if an IP address that is in the wanted subnet. |
7c673cae | 8 | */ |
ec96510d FG |
9 | bool matches_ipv4_in_subnet(const struct ifaddrs& addrs, |
10 | const struct sockaddr_in* net, | |
11 | unsigned int prefix_len); | |
12 | bool matches_ipv6_in_subnet(const struct ifaddrs& addrs, | |
13 | const struct sockaddr_in6* net, | |
14 | unsigned int prefix_len); | |
11fdf7f2 TL |
15 | |
16 | /* | |
17 | * Validate and parse IPv4 or IPv6 network | |
18 | * | |
19 | * Given a network (e.g. "192.168.0.0/24") and pointers to a sockaddr_storage | |
20 | * struct and an unsigned int: | |
21 | * | |
22 | * if the network string is valid, return true and populate sockaddr_storage | |
23 | * and prefix_len; | |
24 | * | |
25 | * if the network string is invalid, return false. | |
26 | */ | |
27 | bool parse_network(const char *s, | |
28 | struct sockaddr_storage *network, | |
29 | unsigned int *prefix_len); | |
30 | bool parse_network(const char *s, | |
31 | entity_addr_t *network, | |
32 | unsigned int *prefix_len); | |
33 | ||
34 | void netmask_ipv6(const struct in6_addr *addr, | |
35 | unsigned int prefix_len, | |
36 | struct in6_addr *out); | |
7c673cae | 37 | |
11fdf7f2 TL |
38 | void netmask_ipv4(const struct in_addr *addr, |
39 | unsigned int prefix_len, | |
40 | struct in_addr *out); | |
7c673cae | 41 | |
11fdf7f2 TL |
42 | bool network_contains( |
43 | const struct entity_addr_t& network, | |
44 | unsigned int prefix_len, | |
45 | const struct entity_addr_t& addr); | |
7c673cae FG |
46 | |
47 | #endif |