2 * iplink_ipoib.c IPoIB device support
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Or Gerlitz <ogerlitz@mellanox.com>
10 * copied iflink_vlan.c authored by Patrick McHardy <kaber@trash.net>
16 #include <linux/if_link.h>
20 #include "ip_common.h"
22 static void explain(void)
25 "Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}]"
28 "PKEY := 0x8001-0xffff\n"
33 static int mode_arg(void)
35 fprintf(stderr
, "Error: argument of \"mode\" must be \"datagram\""
36 "or \"connected\"\n");
40 static int ipoib_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
43 __u16 pkey
, mode
, umcast
;
46 if (matches(*argv
, "pkey") == 0) {
48 if (get_u16(&pkey
, *argv
, 0))
49 invarg("pkey is invalid", *argv
);
50 addattr_l(n
, 1024, IFLA_IPOIB_PKEY
, &pkey
, 2);
51 } else if (matches(*argv
, "mode") == 0) {
53 if (strcmp(*argv
, "datagram") == 0)
54 mode
= IPOIB_MODE_DATAGRAM
;
55 else if (strcmp(*argv
, "connected") == 0)
56 mode
= IPOIB_MODE_CONNECTED
;
59 addattr_l(n
, 1024, IFLA_IPOIB_MODE
, &mode
, 2);
60 } else if (matches(*argv
, "umcast") == 0) {
62 if (get_u16(&umcast
, *argv
, 0))
63 invarg("umcast is invalid", *argv
);
64 addattr_l(n
, 1024, IFLA_IPOIB_UMCAST
, &umcast
, 2);
65 } else if (matches(*argv
, "help") == 0) {
69 fprintf(stderr
, "ipoib: unknown option \"%s\"?\n", *argv
);
79 static void ipoib_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
86 if (!tb
[IFLA_IPOIB_PKEY
] ||
87 RTA_PAYLOAD(tb
[IFLA_IPOIB_PKEY
]) < sizeof(__u16
))
90 fprintf(f
, "pkey %#.4x ", rta_getattr_u16(tb
[IFLA_IPOIB_PKEY
]));
92 if (!tb
[IFLA_IPOIB_MODE
] ||
93 RTA_PAYLOAD(tb
[IFLA_IPOIB_MODE
]) < sizeof(__u16
))
96 mode
= rta_getattr_u16(tb
[IFLA_IPOIB_MODE
]);
97 fprintf(f
, "mode %s ",
98 mode
== IPOIB_MODE_DATAGRAM
? "datagram" :
99 mode
== IPOIB_MODE_CONNECTED
? "connected" :
102 if (!tb
[IFLA_IPOIB_UMCAST
] ||
103 RTA_PAYLOAD(tb
[IFLA_IPOIB_UMCAST
]) < sizeof(__u16
))
106 fprintf(f
, "umcast %.4x ", rta_getattr_u16(tb
[IFLA_IPOIB_UMCAST
]));
109 struct link_util ipoib_link_util
= {
111 .maxattr
= IFLA_IPOIB_MAX
,
112 .parse_opt
= ipoib_parse_opt
,
113 .print_opt
= ipoib_print_opt
,