Skip to content

Commit ffa276f

Browse files
author
Ossama Othman
authored
Support ELL 0.68 l_netlink_message API. (#303)
* configure: Check for l_netlink_message_new_sized() ELL 0.68 introduced a non-backward compatible change to its API by introducing a new l_netlink_message API to simplify use of the l_netlink_send() function. Check for the existence of the new API in the mptcpd configure script. * network_monitor: Support ELL l_netlink_message API Support both the pre- and post- ELL 0.68 versions of l_netlink_send() function. * network_monitor: Refactor l_netlink_send() calls. Refactor #ifdef blocks containing calls to the pre- and post-0.68 ELL l_netlink_send() calls to a separate helper functions. This simplifies the code, and obviates the need to have an #ifdef block each time l_netlink_send() is called. Many thanks to Matthieu Baerts for making this suggestion. * configure: Bump copyright year.
1 parent a4e7b65 commit ffa276f

File tree

2 files changed

+77
-26
lines changed

2 files changed

+77
-26
lines changed

configure.ac

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- Autoconf -*-
33
# Process this file with autoconf to produce a configure script.
44
#
5-
# Copyright (c) 2017-2023, Intel Corporation
5+
# Copyright (c) 2017-2024, Intel Corporation
66

77
AC_PREREQ([2.69])
88
AC_INIT([mptcpd],
@@ -265,6 +265,12 @@ AC_CHECK_FUNC([l_hashmap_replace],
265265
[AC_DEFINE([HAVE_L_HASHMAP_REPLACE],
266266
[],
267267
[ELL has l_hashmap_replace()])])
268+
269+
dnl l_netlink_message_new_sized() was introduced in ELL v0.68.
270+
AC_CHECK_FUNC([l_netlink_message_new_sized],
271+
[AC_DEFINE([HAVE_L_NETLINK_MESSAGE_NEW_SIZED],
272+
[],
273+
[ELL has l_netlink_message_new_sized()])])
268274
LIBS=$mptcpd_save_libs
269275

270276
# ---------------------------------------------------------------

lib/network_monitor.c

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @brief mptcpd network device monitoring.
66
*
7-
* Copyright (c) 2017-2022, Intel Corporation
7+
* Copyright (c) 2017-2022, 2024, Intel Corporation
88
*/
99

1010
#ifdef HAVE_CONFIG_H
@@ -95,6 +95,51 @@ struct mptcpd_nm
9595
bool monitor_loopback;
9696
};
9797

98+
// -------------------------------------------------------------------
99+
// Helper Functions
100+
// -------------------------------------------------------------------
101+
102+
/**
103+
* @brief Wrap different versions of ELL @c l_netlink_send().
104+
*
105+
* ELL 0.68 changed the API for @c l_netlink_send(). This helper
106+
* function wraps the two different function calls so that mptcpd will
107+
* work with both pre- and post-0.68 @c l_netlink_send() APIs.
108+
*/
109+
static unsigned int netlink_send(struct l_netlink *netlink,
110+
uint16_t type,
111+
uint16_t flags,
112+
void const *data,
113+
uint32_t len,
114+
l_netlink_command_func_t function,
115+
void *user_data,
116+
l_netlink_destroy_func_t destroy)
117+
{
118+
#ifdef HAVE_L_NETLINK_MESSAGE_NEW_SIZED
119+
// ELL >= 0.68
120+
struct l_netlink_message *const message =
121+
l_netlink_message_new_sized(type, flags, len);
122+
123+
l_netlink_message_add_header(message, data, len);
124+
125+
return l_netlink_send(netlink,
126+
message,
127+
function,
128+
user_data,
129+
destroy);
130+
#else
131+
// ELL < 0.68
132+
return l_netlink_send(netlink,
133+
type,
134+
flags,
135+
data,
136+
len,
137+
function,
138+
user_data,
139+
destroy);
140+
#endif
141+
}
142+
98143
// -------------------------------------------------------------------
99144
// Network Address Information Handling
100145
// -------------------------------------------------------------------
@@ -1015,14 +1060,14 @@ static void check_default_route(struct nm_addr_info *ai)
10151060
*/
10161061
mptcpd_addr_get(ai);
10171062

1018-
if (l_netlink_send(ai->nm->rtnl,
1019-
RTM_GETROUTE,
1020-
0,
1021-
&store,
1022-
buf - (char *) &store,
1023-
handle_rtm_getroute,
1024-
ai,
1025-
NULL) == 0) {
1063+
if (netlink_send(ai->nm->rtnl,
1064+
RTM_GETROUTE,
1065+
0,
1066+
&store,
1067+
buf - (char *) &store,
1068+
handle_rtm_getroute,
1069+
ai,
1070+
NULL) == 0) {
10261071
l_debug("Route lookup failed");
10271072
mptcpd_addr_put(ai);
10281073
}
@@ -1388,14 +1433,14 @@ static void send_getaddr_command(void *user_data)
13881433

13891434
// Get IP addresses.
13901435
struct ifaddrmsg addr_msg = { .ifa_family = AF_UNSPEC };
1391-
if (l_netlink_send(nm->rtnl,
1392-
RTM_GETADDR,
1393-
NLM_F_DUMP,
1394-
&addr_msg,
1395-
sizeof(addr_msg),
1396-
handle_rtm_getaddr,
1397-
nm,
1398-
NULL) == 0) {
1436+
if (netlink_send(nm->rtnl,
1437+
RTM_GETADDR,
1438+
NLM_F_DUMP,
1439+
&addr_msg,
1440+
sizeof(addr_msg),
1441+
handle_rtm_getaddr,
1442+
nm,
1443+
NULL) == 0) {
13991444
l_error("Unable to obtain IP addresses.");
14001445

14011446
/*
@@ -1481,14 +1526,14 @@ struct mptcpd_nm *mptcpd_nm_create(uint32_t flags)
14811526
* resulted in an EBUSY error.
14821527
*/
14831528
struct ifinfomsg link_msg = { .ifi_family = AF_UNSPEC };
1484-
if (l_netlink_send(nm->rtnl,
1485-
RTM_GETLINK,
1486-
NLM_F_DUMP,
1487-
&link_msg,
1488-
sizeof(link_msg),
1489-
handle_rtm_getlink,
1490-
nm,
1491-
send_getaddr_command)
1529+
if (netlink_send(nm->rtnl,
1530+
RTM_GETLINK,
1531+
NLM_F_DUMP,
1532+
&link_msg,
1533+
sizeof(link_msg),
1534+
handle_rtm_getlink,
1535+
nm,
1536+
send_getaddr_command)
14921537
== 0) {
14931538
l_error("Unable to obtain network devices.");
14941539
mptcpd_nm_destroy(nm);

0 commit comments

Comments
 (0)