代码拉取完成,页面将自动刷新
From 0e549bc94256119334a5f949cff2fef28b6d14f7 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 11 Jul 2024 11:59:27 -0400
Subject: [PATCH 5/5] Refactor: Remove global booth_conf variable in
find_myself...
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
...as well as functions that call it. Also, mark _find_myself as static
and remove the unnecessary function prototype for it.
Co-authored-by: Jan Pokorný <jpokorny@redhat.com>
---
src/main.c | 6 +++---
src/transport.c | 37 ++++++++++++++++++++-----------------
src/transport.h | 14 +++++++++++++-
3 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/src/main.c b/src/main.c
index 609dcdf..c6f6bb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -399,9 +399,9 @@ static int setup_config(struct booth_config **conf, int type)
return -EINVAL;
}
local->local = 1;
- } else
- find_myself(NULL, type == CLIENT || type == GEOSTORE);
-
+ } else {
+ find_myself(booth_conf, NULL, type == CLIENT || type == GEOSTORE);
+ }
rv = check_config(booth_conf, type);
if (rv < 0)
diff --git a/src/transport.c b/src/transport.c
index 56e5108..791029c 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -78,11 +78,12 @@ enum match_type {
EXACT_MATCH,
};
-static int find_address(unsigned char ipaddr[BOOTH_IPADDR_LEN],
- int family, int prefixlen,
- int fuzzy_allowed,
- struct booth_site **me,
- int *address_bits_matched)
+static int find_address(struct booth_config *conf,
+ unsigned char ipaddr[BOOTH_IPADDR_LEN],
+ int family, int prefixlen,
+ int fuzzy_allowed,
+ struct booth_site **me,
+ int *address_bits_matched)
{
int i;
struct booth_site *node;
@@ -92,13 +93,14 @@ static int find_address(unsigned char ipaddr[BOOTH_IPADDR_LEN],
int matched;
enum match_type did_match = NO_MATCH;
+ assert(conf != NULL);
bytes = prefixlen / 8;
bits_left = prefixlen % 8;
/* One bit left to check means ignore 7 lowest bits. */
mask = ~( (1 << (8 - bits_left)) -1);
- _FOREACH_NODE(i, node) {
+ FOREACH_NODE(conf, i, node) {
if (family != node->family)
continue;
n_a = node_to_addr_pointer(node);
@@ -140,8 +142,8 @@ static int find_address(unsigned char ipaddr[BOOTH_IPADDR_LEN],
}
-int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed);
-int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed)
+static int _find_myself(struct booth_config *conf, int family,
+ struct booth_site **mep, int fuzzy_allowed)
{
int fd;
struct sockaddr_nl nladdr;
@@ -247,9 +249,9 @@ int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed)
* the function find_address will try to return another, most similar
* address (with the longest possible number of same bytes). */
if (ifa->ifa_prefixlen > address_bits_matched) {
- find_address(ipaddr,
- ifa->ifa_family, ifa->ifa_prefixlen,
- fuzzy_allowed, &me, &address_bits_matched);
+ find_address(conf, ipaddr,
+ ifa->ifa_family, ifa->ifa_prefixlen,
+ fuzzy_allowed, &me, &address_bits_matched);
if (me) {
log_debug("found myself at %s (%d bits matched)",
@@ -263,9 +265,9 @@ int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed)
* call the function find_address with disabled searching of
* similar addresses (fuzzy_allowed == 0) */
else if (ifa->ifa_prefixlen == address_bits_matched) {
- find_address(ipaddr,
- ifa->ifa_family, ifa->ifa_prefixlen,
- 0 /* fuzzy_allowed */, &me, &address_bits_matched);
+ find_address(conf, ipaddr,
+ ifa->ifa_family, ifa->ifa_prefixlen,
+ 0 /* fuzzy_allowed */, &me, &address_bits_matched);
if (me) {
log_debug("found myself at %s (exact match)",
@@ -290,10 +292,11 @@ found:
return 1;
}
-int find_myself(struct booth_site **mep, int fuzzy_allowed)
+int find_myself(struct booth_config *conf, struct booth_site **mep,
+ int fuzzy_allowed)
{
- return _find_myself(AF_INET6, mep, fuzzy_allowed) ||
- _find_myself(AF_INET, mep, fuzzy_allowed);
+ return _find_myself(conf, AF_INET6, mep, fuzzy_allowed) ||
+ _find_myself(conf, AF_INET, mep, fuzzy_allowed);
}
diff --git a/src/transport.h b/src/transport.h
index e04d0ef..4f4d497 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -58,7 +58,19 @@ struct booth_transport {
};
extern const struct booth_transport booth_transport[TRANSPORT_ENTRIES];
-int find_myself(struct booth_site **me, int fuzzy_allowed);
+
+/**
+ * @internal
+ * Attempts to pick identity of self from config-tracked enumeration of sites
+ *
+ * @param[in,out] conf config object to refer to
+ * @param[out] mep when self-discovery successful, site pointer is stored here
+ * @param[in] fuzzy_allowed whether it's OK to approximate the match
+ *
+ * @return 0 on success or negative value (-1 or -errno) on error
+ */
+int find_myself(struct booth_config *conf, struct booth_site **me,
+ int fuzzy_allowed);
int read_client(struct client *req_cl);
int check_boothc_header(struct boothc_header *data, int len_incl_data);
--
2.25.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。