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 print_explain(FILE *f
)
25 "Usage: ... ipoib [ pkey PKEY ]\n"
26 " [ mode {datagram | connected} ]\n"
29 "PKEY := 0x8001-0xffff\n"
33 static void explain(void)
35 print_explain(stderr
);
38 static int mode_arg(void)
40 fprintf(stderr
, "Error: argument of \"mode\" must be \"datagram\"or \"connected\"\n");
44 static int ipoib_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
47 __u16 pkey
, mode
, umcast
;
50 if (matches(*argv
, "pkey") == 0) {
52 if (get_u16(&pkey
, *argv
, 0))
53 invarg("pkey is invalid", *argv
);
54 addattr_l(n
, 1024, IFLA_IPOIB_PKEY
, &pkey
, 2);
55 } else if (matches(*argv
, "mode") == 0) {
57 if (strcmp(*argv
, "datagram") == 0)
58 mode
= IPOIB_MODE_DATAGRAM
;
59 else if (strcmp(*argv
, "connected") == 0)
60 mode
= IPOIB_MODE_CONNECTED
;
63 addattr_l(n
, 1024, IFLA_IPOIB_MODE
, &mode
, 2);
64 } else if (matches(*argv
, "umcast") == 0) {
66 if (get_u16(&umcast
, *argv
, 0))
67 invarg("umcast is invalid", *argv
);
68 addattr_l(n
, 1024, IFLA_IPOIB_UMCAST
, &umcast
, 2);
69 } else if (matches(*argv
, "help") == 0) {
73 fprintf(stderr
, "ipoib: unknown option \"%s\"?\n", *argv
);
83 static void ipoib_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
90 if (!tb
[IFLA_IPOIB_PKEY
] ||
91 RTA_PAYLOAD(tb
[IFLA_IPOIB_PKEY
]) < sizeof(__u16
))
94 fprintf(f
, "pkey %#.4x ", rta_getattr_u16(tb
[IFLA_IPOIB_PKEY
]));
96 if (!tb
[IFLA_IPOIB_MODE
] ||
97 RTA_PAYLOAD(tb
[IFLA_IPOIB_MODE
]) < sizeof(__u16
))
100 mode
= rta_getattr_u16(tb
[IFLA_IPOIB_MODE
]);
101 fprintf(f
, "mode %s ",
102 mode
== IPOIB_MODE_DATAGRAM
? "datagram" :
103 mode
== IPOIB_MODE_CONNECTED
? "connected" :
106 if (!tb
[IFLA_IPOIB_UMCAST
] ||
107 RTA_PAYLOAD(tb
[IFLA_IPOIB_UMCAST
]) < sizeof(__u16
))
110 fprintf(f
, "umcast %.4x ", rta_getattr_u16(tb
[IFLA_IPOIB_UMCAST
]));
113 static void ipoib_print_help(struct link_util
*lu
, int argc
, char **argv
,
119 struct link_util ipoib_link_util
= {
121 .maxattr
= IFLA_IPOIB_MAX
,
122 .parse_opt
= ipoib_parse_opt
,
123 .print_opt
= ipoib_print_opt
,
124 .print_help
= ipoib_print_help
,