]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/pick_address.h
1faf60dbd75bcf65f183311df305d7f2cbcc377e
[ceph.git] / ceph / src / common / pick_address.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_PICK_ADDRESS_H
4 #define CEPH_PICK_ADDRESS_H
5
6 #include <string>
7 #include <list>
8
9 #include "include/common_fwd.h"
10
11 struct entity_addr_t;
12 class entity_addrvec_t;
13
14
15 #define CEPH_PICK_ADDRESS_PUBLIC 0x01
16 #define CEPH_PICK_ADDRESS_CLUSTER 0x02
17 #define CEPH_PICK_ADDRESS_MSGR1 0x04
18 #define CEPH_PICK_ADDRESS_MSGR2 0x08
19 #define CEPH_PICK_ADDRESS_IPV4 0x10
20 #define CEPH_PICK_ADDRESS_IPV6 0x20
21 #define CEPH_PICK_ADDRESS_PREFER_IPV4 0x40
22 #define CEPH_PICK_ADDRESS_DEFAULT_MON_PORTS 0x80
23
24 #ifndef WITH_SEASTAR
25 /*
26 Pick addresses based on subnets if needed.
27
28 If an address is not explicitly given, and a list of subnets is
29 given, find an assigned IP address in the subnets and set that.
30
31 cluster_addr is set based on cluster_network, public_addr is set
32 based on public_network.
33
34 cluster_network and public_network are a list of ip/prefix pairs.
35
36 All IP addresses assigned to all local network interfaces are
37 potential matches.
38
39 If multiple IP addresses match the subnet, one of them will be
40 picked, effectively randomly.
41
42 This function will exit on error.
43 */
44 void pick_addresses(CephContext *cct, int needs);
45
46 #endif // !WITH_SEASTAR
47
48 int pick_addresses(CephContext *cct, unsigned flags, entity_addrvec_t *addrs,
49 int preferred_numa_node = -1);
50 int pick_addresses(CephContext *cct, unsigned flags, struct ifaddrs *ifa,
51 entity_addrvec_t *addrs,
52 int preferred_numa_node = -1);
53
54 /**
55 * Find a network interface whose address matches the address/netmask
56 * in `network`.
57 */
58 std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network);
59
60 /**
61 * check for a locally configured address
62 *
63 * check if any of the listed addresses is configured on the local host.
64 *
65 * @param cct context
66 * @param ls list of addresses
67 * @param match [out] pointer to match, if an item in @a ls is found configured locally.
68 */
69 bool have_local_addr(CephContext *cct, const std::list<entity_addr_t>& ls, entity_addr_t *match);
70
71 /**
72 * filter the addresses in @c ifa with specified interfaces, networks and IPv
73 *
74 * @param cct
75 * @param ifa a list of network interface addresses to be filtered
76 * @param ipv bitmask of CEPH_PICK_ADDRESS_IPV4 and CEPH_PICK_ADDRESS_IPV6.
77 * it is used to filter the @c networks
78 * @param networks a comma separated list of networks as the allow list. only
79 * the addresses in the specified networks are allowed. all addresses
80 * are accepted if it is empty.
81 * @param interfaces a comma separated list of interfaces for the allow list.
82 * all addresses are accepted if it is empty
83 * @param exclude_lo_iface filter out network interface named "lo"
84 */
85 const struct sockaddr *find_ip_in_subnet_list(
86 CephContext *cct,
87 const struct ifaddrs *ifa,
88 unsigned ipv,
89 const std::string &networks,
90 const std::string &interfaces,
91 int numa_node=-1);
92
93 int get_iface_numa_node(
94 const std::string& iface,
95 int *node);
96
97 #endif