|
4 | 4 | * |
5 | 5 | * @brief mptcpd network device monitoring. |
6 | 6 | * |
7 | | - * Copyright (c) 2017-2022, Intel Corporation |
| 7 | + * Copyright (c) 2017-2022, 2024, Intel Corporation |
8 | 8 | */ |
9 | 9 |
|
10 | 10 | #ifdef HAVE_CONFIG_H |
@@ -95,6 +95,51 @@ struct mptcpd_nm |
95 | 95 | bool monitor_loopback; |
96 | 96 | }; |
97 | 97 |
|
| 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 | + |
98 | 143 | // ------------------------------------------------------------------- |
99 | 144 | // Network Address Information Handling |
100 | 145 | // ------------------------------------------------------------------- |
@@ -1015,14 +1060,14 @@ static void check_default_route(struct nm_addr_info *ai) |
1015 | 1060 | */ |
1016 | 1061 | mptcpd_addr_get(ai); |
1017 | 1062 |
|
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) { |
1026 | 1071 | l_debug("Route lookup failed"); |
1027 | 1072 | mptcpd_addr_put(ai); |
1028 | 1073 | } |
@@ -1388,14 +1433,14 @@ static void send_getaddr_command(void *user_data) |
1388 | 1433 |
|
1389 | 1434 | // Get IP addresses. |
1390 | 1435 | 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) { |
1399 | 1444 | l_error("Unable to obtain IP addresses."); |
1400 | 1445 |
|
1401 | 1446 | /* |
@@ -1481,14 +1526,14 @@ struct mptcpd_nm *mptcpd_nm_create(uint32_t flags) |
1481 | 1526 | * resulted in an EBUSY error. |
1482 | 1527 | */ |
1483 | 1528 | 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) |
1492 | 1537 | == 0) { |
1493 | 1538 | l_error("Unable to obtain network devices."); |
1494 | 1539 | mptcpd_nm_destroy(nm); |
|
0 commit comments