Gentoo Archives: gentoo-commits

From: Craig Andrews <candrews@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: net-misc/mptcpd/, net-misc/mptcpd/files/
Date: Fri, 01 Apr 2022 14:46:01
Message-Id: 1648824353.208e9cad2358fd2eb812fa8fb9b68f5b2aabe403.candrews@gentoo
1 commit: 208e9cad2358fd2eb812fa8fb9b68f5b2aabe403
2 Author: Craig Andrews <candrews <AT> gentoo <DOT> org>
3 AuthorDate: Fri Apr 1 14:42:59 2022 +0000
4 Commit: Craig Andrews <candrews <AT> gentoo <DOT> org>
5 CommitDate: Fri Apr 1 14:45:53 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=208e9cad
7
8 net-misc/mptcpd: Fix failing network-monitor
9
10 See: https://github.com/intel/mptcpd/commit/a200ef26e4daf0347dd8f1bd35d49dd66fba7a7e
11 Closes: https://bugs.gentoo.org/836601
12 Package-Manager: Portage-3.0.30, Repoman-3.0.3
13 Signed-off-by: Craig Andrews <candrews <AT> gentoo.org>
14
15 .../files/mptcpd-0.9-loopback-monitoring.patch | 197 +++++++++++++++++++++
16 net-misc/mptcpd/mptcpd-0.9.ebuild | 3 +
17 2 files changed, 200 insertions(+)
18
19 diff --git a/net-misc/mptcpd/files/mptcpd-0.9-loopback-monitoring.patch b/net-misc/mptcpd/files/mptcpd-0.9-loopback-monitoring.patch
20 new file mode 100644
21 index 000000000000..38061a754a4d
22 --- /dev/null
23 +++ b/net-misc/mptcpd/files/mptcpd-0.9-loopback-monitoring.patch
24 @@ -0,0 +1,197 @@
25 +From a200ef26e4daf0347dd8f1bd35d49dd66fba7a7e Mon Sep 17 00:00:00 2001
26 +From: Ossama Othman <ossama.othman@×××××.com>
27 +Date: Thu, 17 Feb 2022 16:39:59 -0800
28 +Subject: [PATCH] Allow loopback network interface monitoring. (#220)
29 +
30 +* network_monitor: Allow loopback monitoring.
31 +
32 +Add a new mptcpd_nm_monitor_loopback() function that allows the user
33 +to enable monitoring of loopback network interfaces. Monitoring of
34 +loopback network interfaces is meant primarily for testing purposes.
35 +Mptcpd will retain the previous behavior of only monitoring
36 +non-loopback network interfaces by default.
37 +
38 +* tests: Enable loopback interface monitoring.
39 +
40 +Enable loopback network interface monitoring to allow the
41 +test-network-monitor unit test to succeed in cases where non-loopback
42 +interfaces are unavailable, such as in a sandboxed environment.
43 +
44 +Fixes #208.
45 +
46 +Co-authored-by: Mat Martineau <mathew.j.martineau@×××××××××××.com>
47 +---
48 + include/mptcpd/network_monitor.h | 21 ++++++++++++++++++
49 + lib/network_monitor.c | 38 +++++++++++++++++++++-----------
50 + tests/test-network-monitor.c | 15 +++++++++----
51 + 3 files changed, 57 insertions(+), 17 deletions(-)
52 +
53 +diff --git a/include/mptcpd/network_monitor.h b/include/mptcpd/network_monitor.h
54 +index dc35e3d..ea1a95b 100644
55 +--- a/include/mptcpd/network_monitor.h
56 ++++ b/include/mptcpd/network_monitor.h
57 +@@ -213,6 +213,27 @@ MPTCPD_API bool mptcpd_nm_register_ops(struct mptcpd_nm *nm,
58 + struct mptcpd_nm_ops const *ops,
59 + void *user_data);
60 +
61 ++/**
62 ++ * @brief Enable monitoring of the loopback network interface.
63 ++ *
64 ++ * Mptcpd normally only monitors non-loopback network interfaces.
65 ++ * Call this function to enable monitoring of loopback network
66 ++ * interfaces.
67 ++ *
68 ++ * @note Mptcpd monitoring of loopback network interfaces is meant
69 ++ * primarily for testing purposes.
70 ++ *
71 ++ * @param[in,out] nm Pointer to the mptcpd network monitor
72 ++ * object.
73 ++ * @param[in] enable Enable or disable monitoring of loopback
74 ++ * network interfaces.
75 ++ *
76 ++ * @retval true Successfully enable or disabled.
77 ++ * @retval false Invalid @a nm argument.
78 ++ */
79 ++MPTCPD_API bool mptcpd_nm_monitor_loopback(struct mptcpd_nm *nm,
80 ++ bool enable);
81 ++
82 + #ifdef __cplusplus
83 + }
84 + #endif
85 +diff --git a/lib/network_monitor.c b/lib/network_monitor.c
86 +index 2ae275b..7a3927e 100644
87 +--- a/lib/network_monitor.c
88 ++++ b/lib/network_monitor.c
89 +@@ -4,7 +4,7 @@
90 + *
91 + * @brief mptcpd network device monitoring.
92 + *
93 +- * Copyright (c) 2017-2021, Intel Corporation
94 ++ * Copyright (c) 2017-2022, Intel Corporation
95 + */
96 +
97 + #ifdef HAVE_CONFIG_H
98 +@@ -78,6 +78,9 @@ struct mptcpd_nm
99 +
100 + /// Flags controlling address notification.
101 + uint32_t notify_flags;
102 ++
103 ++ /// Enable/disable loopback network interface monitoring.
104 ++ bool monitor_loopback;
105 + };
106 +
107 + // -------------------------------------------------------------------
108 +@@ -525,16 +528,15 @@ static void mptcpd_interface_callback(void *data, void *user_data)
109 + *
110 + * @return @c true if network interface is ready, and @c false other.
111 + */
112 +-static bool is_interface_ready(struct ifinfomsg const *ifi)
113 ++static bool is_interface_ready(struct mptcpd_nm const *nm,
114 ++ struct ifinfomsg const *ifi)
115 + {
116 +- /*
117 +- Only accept non-loopback network interfaces that are
118 +- up and running.
119 +- */
120 +- static unsigned int const iff_ready = IFF_UP | IFF_RUNNING;
121 ++ // Only accept network interfaces that are up and running.
122 ++ static unsigned int iff_ready = IFF_UP | IFF_RUNNING;
123 +
124 + return (ifi->ifi_flags & iff_ready) == iff_ready
125 +- && (ifi->ifi_flags & IFF_LOOPBACK) == 0;
126 ++ && ((ifi->ifi_flags & IFF_LOOPBACK) == 0
127 ++ || nm->monitor_loopback);
128 + }
129 +
130 + /**
131 +@@ -708,7 +710,7 @@ static void handle_link(uint16_t type,
132 +
133 + switch (type) {
134 + case RTM_NEWLINK:
135 +- if (is_interface_ready(ifi))
136 ++ if (is_interface_ready(nm, ifi))
137 + update_link(ifi, len, nm);
138 + else
139 + remove_link(ifi, nm); // Interface disabled.
140 +@@ -1301,7 +1303,7 @@ static void handle_rtm_getlink(int error,
141 + struct ifinfomsg const *const ifi = data;
142 + struct mptcpd_nm *const nm = user_data;
143 +
144 +- if (is_interface_ready(ifi)) {
145 ++ if (is_interface_ready(nm, ifi)) {
146 + (void) insert_link(ifi, len, nm);
147 + }
148 + }
149 +@@ -1442,9 +1444,10 @@ struct mptcpd_nm *mptcpd_nm_create(uint32_t flags)
150 + return NULL;
151 + }
152 +
153 +- nm->notify_flags = flags;
154 +- nm->interfaces = l_queue_new();
155 +- nm->ops = l_queue_new();
156 ++ nm->notify_flags = flags;
157 ++ nm->interfaces = l_queue_new();
158 ++ nm->ops = l_queue_new();
159 ++ nm->monitor_loopback = false;
160 +
161 + /**
162 + * Get network interface information.
163 +@@ -1555,6 +1558,15 @@ bool mptcpd_nm_register_ops(struct mptcpd_nm *nm,
164 + return registered;
165 + }
166 +
167 ++bool mptcpd_nm_monitor_loopback(struct mptcpd_nm *nm, bool enable)
168 ++{
169 ++ if (nm == NULL)
170 ++ return false;
171 ++
172 ++ nm->monitor_loopback = enable;
173 ++
174 ++ return true;
175 ++}
176 +
177 + /*
178 + Local Variables:
179 +diff --git a/tests/test-network-monitor.c b/tests/test-network-monitor.c
180 +index d7c6b87..d22f6be 100644
181 +--- a/tests/test-network-monitor.c
182 ++++ b/tests/test-network-monitor.c
183 +@@ -4,7 +4,7 @@
184 + *
185 + * @brief mptcpd network monitor test.
186 + *
187 +- * Copyright (c) 2018-2020, Intel Corporation
188 ++ * Copyright (c) 2018-2020, 2022, Intel Corporation
189 + */
190 +
191 + #define _DEFAULT_SOURCE // Enable IFF_... interface flags in <net/if.h>.
192 +@@ -115,12 +115,11 @@ static void check_interface(struct mptcpd_interface const *i, void *data)
193 + l_queue_foreach(i->addrs, dump_addr, NULL);
194 +
195 + /*
196 +- Only non-loopback interfaces that are up and running should
197 +- be monitored.
198 ++ Only network interfaces that are up and running should be
199 ++ monitored.
200 + */
201 + static unsigned int const ready = IFF_UP | IFF_RUNNING;
202 + assert(ready == (i->flags & ready));
203 +- assert(!(i->flags & IFF_LOOPBACK));
204 +
205 + if (data) {
206 + struct foreach_data *const fdata = data;
207 +@@ -249,6 +248,14 @@ int main(void)
208 + struct mptcpd_nm *const nm = mptcpd_nm_create(0);
209 + assert(nm);
210 +
211 ++ assert(!mptcpd_nm_monitor_loopback(NULL, true)); // Bad arg
212 ++
213 ++ /*
214 ++ Enable loopback network interface monitoring for this unit
215 ++ test in case non-loopback network interfaces are unavailable.
216 ++ */
217 ++ assert(mptcpd_nm_monitor_loopback(nm, true));
218 ++
219 + struct mptcpd_nm_ops const nm_events[] = {
220 + {
221 + .new_interface = handle_new_interface,
222
223 diff --git a/net-misc/mptcpd/mptcpd-0.9.ebuild b/net-misc/mptcpd/mptcpd-0.9.ebuild
224 index 8f307676ab46..a35610eb41ad 100644
225 --- a/net-misc/mptcpd/mptcpd-0.9.ebuild
226 +++ b/net-misc/mptcpd/mptcpd-0.9.ebuild
227 @@ -27,6 +27,9 @@ BDEPEND="
228 )
229 virtual/pkgconfig
230 "
231 +PATCHES=(
232 + "${FILESDIR}/${P}-loopback-monitoring.patch"
233 +)
234
235 if [[ ${PV} == 9999* ]]; then
236 inherit git-r3