Skip to content

Commit 72e65e6

Browse files
committed
network: add support to configure IPoIB interfaces
1 parent b90d0f8 commit 72e65e6

File tree

10 files changed

+98
-1
lines changed

10 files changed

+98
-1
lines changed

man/systemd.network.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,15 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
32273227
</variablelist>
32283228
</refsect1>
32293229

3230+
<refsect1>
3231+
<title>[IPoIB] Section Options</title>
3232+
<para>The [IPoIB] section manages the IP over Infiniband and accepts the following keys:</para>
3233+
<variablelist class='network-directives'>
3234+
<xi:include href="systemd.netdev.xml" xpointer="ipoib_mode" />
3235+
<xi:include href="systemd.netdev.xml" xpointer="ipoib_umcast" />
3236+
</variablelist>
3237+
</refsect1>
3238+
32303239
<refsect1>
32313240
<title>[QDisc] Section Options</title>
32323241
<para>The [QDisc] section manages the traffic control queueing discipline (qdisc).</para>

src/network/netdev/ipoib.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/if_link.h>
55

66
#include "ipoib.h"
7+
#include "networkd-network.h"
78
#include "parse-util.h"
89
#include "string-table.h"
910

@@ -56,6 +57,48 @@ static int netdev_ipoib_fill_message_create(NetDev *netdev, Link *link, sd_netli
5657
return 0;
5758
}
5859

60+
int ipoib_set_netlink_message(Link *link, sd_netlink_message *m) {
61+
int r;
62+
63+
assert(link);
64+
assert(link->network);
65+
assert(m);
66+
67+
r = sd_netlink_message_set_flags(m, NLM_F_REQUEST | NLM_F_ACK);
68+
if (r < 0)
69+
return log_link_debug_errno(link, r, "Could not set netlink flags: %m");
70+
71+
r = sd_netlink_message_open_container(m, IFLA_LINKINFO);
72+
if (r < 0)
73+
return log_link_debug_errno(link, r, "Failed to open IFLA_LINKINFO container: %m");
74+
75+
r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, link->kind);
76+
if (r < 0)
77+
return log_link_debug_errno(link, r, "Could not open IFLA_INFO_DATA container: %m");
78+
79+
if (link->network->ipoib_mode >= 0) {
80+
r = sd_netlink_message_append_u16(m, IFLA_IPOIB_MODE, link->network->ipoib_mode);
81+
if (r < 0)
82+
return log_link_debug_errno(link, r, "Could not append IFLA_IPOIB_MODE attribute: %m");
83+
}
84+
85+
if (link->network->ipoib_umcast >= 0) {
86+
r = sd_netlink_message_append_u16(m, IFLA_IPOIB_UMCAST, link->network->ipoib_umcast);
87+
if (r < 0)
88+
return log_link_debug_errno(link, r, "Could not append IFLA_IPOIB_UMCAST attribute: %m");
89+
}
90+
91+
r = sd_netlink_message_close_container(m);
92+
if (r < 0)
93+
return log_link_debug_errno(link, r, "Failed to close IFLA_INFO_DATA container: %m");
94+
95+
r = sd_netlink_message_close_container(m);
96+
if (r < 0)
97+
return log_link_debug_errno(link, r, "Failed to close IFLA_LINKINFO container: %m");
98+
99+
return 0;
100+
}
101+
59102
static const char * const ipoib_mode_table[_IP_OVER_INFINIBAND_MODE_MAX] = {
60103
[IP_OVER_INFINIBAND_MODE_DATAGRAM] = "datagram",
61104
[IP_OVER_INFINIBAND_MODE_CONNECTED] = "connected",

src/network/netdev/ipoib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ typedef struct IPoIB {
2424
DEFINE_NETDEV_CAST(IPOIB, IPoIB);
2525
extern const NetDevVTable ipoib_vtable;
2626

27+
int ipoib_set_netlink_message(Link *link, sd_netlink_message *m);
28+
2729
CONFIG_PARSER_PROTOTYPE(config_parse_ipoib_pkey);
2830
CONFIG_PARSER_PROTOTYPE(config_parse_ipoib_mode);

src/network/networkd-link.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,10 @@ static int link_configure(Link *link) {
11011101
if (r < 0)
11021102
return r;
11031103

1104+
r = link_request_to_set_ipoib(link);
1105+
if (r < 0)
1106+
return r;
1107+
11041108
r = link_request_to_set_flags(link);
11051109
if (r < 0)
11061110
return r;

src/network/networkd-network-gperf.gperf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ CAN.PresumeACK, config_parse_can_control_mode,
382382
CAN.FDNonISO, config_parse_can_control_mode, CAN_CTRLMODE_FD_NON_ISO, 0
383383
CAN.ClassicDataLengthCode, config_parse_can_control_mode, CAN_CTRLMODE_CC_LEN8_DLC, 0
384384
CAN.Termination, config_parse_can_termination, 0, 0
385+
IPoIB.Mode, config_parse_ipoib_mode, 0, offsetof(Network, ipoib_mode)
386+
IPoIB.IgnoreUserspaceMulticastGroups, config_parse_tristate, 0, offsetof(Network, ipoib_umcast)
385387
QDisc.Parent, config_parse_qdisc_parent, _QDISC_KIND_INVALID, 0
386388
QDisc.Handle, config_parse_qdisc_handle, _QDISC_KIND_INVALID, 0
387389
BFIFO.Parent, config_parse_qdisc_parent, QDISC_KIND_BFIFO, 0

src/network/networkd-network.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
476476
.ipv6_accept_ra_start_dhcp6_client = IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES,
477477

478478
.can_termination = -1,
479+
480+
.ipoib_mode = _IP_OVER_INFINIBAND_MODE_INVALID,
481+
.ipoib_umcast = -1,
479482
};
480483

481484
r = config_parse_many(

src/network/networkd-network.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "condition.h"
1212
#include "conf-parser.h"
1313
#include "hashmap.h"
14+
#include "ipoib.h"
1415
#include "net-condition.h"
1516
#include "netdev.h"
1617
#include "networkd-bridge-vlan.h"
@@ -286,6 +287,10 @@ struct Network {
286287
uint16_t can_termination;
287288
bool can_termination_set;
288289

290+
/* IPoIB support */
291+
IPoIBMode ipoib_mode;
292+
int ipoib_umcast;
293+
289294
/* sysctl settings */
290295
AddressFamily ip_forward;
291296
int ipv4_accept_local;

src/network/networkd-setlink.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static const char *const set_link_operation_table[_SET_LINK_OPERATION_MAX] = {
2424
[SET_LINK_CAN] = "CAN interface configurations",
2525
[SET_LINK_FLAGS] = "link flags",
2626
[SET_LINK_GROUP] = "interface group",
27+
[SET_LINK_IPOIB] = "IPoIB configurations",
2728
[SET_LINK_MAC] = "MAC address",
2829
[SET_LINK_MASTER] = "master interface",
2930
[SET_LINK_MTU] = "MTU",
@@ -153,6 +154,10 @@ static int link_set_group_handler(sd_netlink *rtnl, sd_netlink_message *m, Link
153154
return set_link_handler_internal(rtnl, m, link, SET_LINK_GROUP, /* ignore = */ false, NULL);
154155
}
155156

157+
static int link_set_ipoib_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
158+
return set_link_handler_internal(rtnl, m, link, SET_LINK_IPOIB, /* ignore = */ true, NULL);
159+
}
160+
156161
static int link_set_mac_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
157162
return set_link_handler_internal(rtnl, m, link, SET_LINK_MAC, /* ignore = */ true, get_link_default_handler);
158163
}
@@ -236,7 +241,7 @@ static int link_configure(
236241
r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->master_ifindex);
237242
if (r < 0)
238243
return log_link_debug_errno(link, r, "Could not allocate RTM_NEWLINK message: %m");
239-
} else if (op == SET_LINK_CAN) {
244+
} else if (IN_SET(op, SET_LINK_CAN, SET_LINK_IPOIB)) {
240245
r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->ifindex);
241246
if (r < 0)
242247
return log_link_debug_errno(link, r, "Could not allocate RTM_NEWLINK message: %m");
@@ -468,6 +473,11 @@ static int link_configure(
468473
if (r < 0)
469474
return log_link_debug_errno(link, r, "Could not append IFLA_ADDRESS attribute: %m");
470475
break;
476+
case SET_LINK_IPOIB:
477+
r = ipoib_set_netlink_message(link, req);
478+
if (r < 0)
479+
return r;
480+
break;
471481
case SET_LINK_MASTER:
472482
r = sd_netlink_message_append_u32(req, IFLA_MASTER, PTR_TO_UINT32(userdata));
473483
if (r < 0)
@@ -800,6 +810,20 @@ int link_request_to_set_mac(Link *link, bool allow_retry) {
800810
NULL);
801811
}
802812

813+
int link_request_to_set_ipoib(Link *link) {
814+
assert(link);
815+
assert(link->network);
816+
817+
if (link->iftype != ARPHRD_INFINIBAND)
818+
return 0;
819+
820+
if (link->network->ipoib_mode < 0 &&
821+
link->network->ipoib_umcast < 0)
822+
return 0;
823+
824+
return link_request_set_link(link, SET_LINK_IPOIB, link_set_ipoib_handler, NULL);
825+
}
826+
803827
int link_request_to_set_master(Link *link) {
804828
assert(link);
805829
assert(link->network);

src/network/networkd-setlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef enum SetLinkOperation {
1414
SET_LINK_CAN, /* Setting CAN interface configs. */
1515
SET_LINK_FLAGS, /* Setting IFF_NOARP or friends. */
1616
SET_LINK_GROUP, /* Setting interface group. */
17+
SET_LINK_IPOIB, /* Setting IPoIB configs. */
1718
SET_LINK_MAC, /* Setting MAC address. */
1819
SET_LINK_MASTER, /* Setting IFLA_MASTER. */
1920
SET_LINK_MTU, /* Setting MTU. */
@@ -33,6 +34,7 @@ int link_request_to_set_can(Link *link);
3334
int link_request_to_set_flags(Link *link);
3435
int link_request_to_set_group(Link *link);
3536
int link_request_to_set_mac(Link *link, bool allow_retry);
37+
int link_request_to_set_ipoib(Link *link);
3638
int link_request_to_set_master(Link *link);
3739
int link_request_to_set_mtu(Link *link, uint32_t mtu);
3840

test/fuzz/fuzz-network-parser/directives.network

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ Loopback=
287287
OneShot=
288288
PresumeACK=
289289
ClassicDataLengthCode=
290+
[IPoIB]
291+
Mode=
292+
IgnoreUserspaceMulticastGroups=
290293
[Address]
291294
DuplicateAddressDetection=
292295
AutoJoin=

0 commit comments

Comments
 (0)