]>
git.proxmox.com Git - mirror_iproute2.git/blob - tipc/media.c
2 * media.c TIPC link functionality.
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: Richard Alpe <richard.alpe@ericsson.com>
17 #include <linux/tipc_netlink.h>
18 #include <linux/tipc.h>
19 #include <linux/genetlink.h>
20 #include <libmnl/libmnl.h>
26 static int media_list_cb(const struct nlmsghdr
*nlh
, void *data
)
28 struct genlmsghdr
*genl
= mnl_nlmsg_get_payload(nlh
);
29 struct nlattr
*info
[TIPC_NLA_MAX
+ 1] = {};
30 struct nlattr
*attrs
[TIPC_NLA_MEDIA_MAX
+ 1] = {};
32 mnl_attr_parse(nlh
, sizeof(*genl
), parse_attrs
, info
);
33 if (!info
[TIPC_NLA_MEDIA
])
36 mnl_attr_parse_nested(info
[TIPC_NLA_MEDIA
], parse_attrs
, attrs
);
37 if (!attrs
[TIPC_NLA_MEDIA_NAME
])
40 printf("%s\n", mnl_attr_get_str(attrs
[TIPC_NLA_MEDIA_NAME
]));
45 static int cmd_media_list(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
46 struct cmdl
*cmdl
, void *data
)
48 char buf
[MNL_SOCKET_BUFFER_SIZE
];
51 fprintf(stderr
, "Usage: %s media list\n", cmdl
->argv
[0]);
55 if (!(nlh
= msg_init(buf
, TIPC_NL_MEDIA_GET
))) {
56 fprintf(stderr
, "error, message initialisation failed\n");
60 return msg_dumpit(nlh
, media_list_cb
, NULL
);
63 static int media_get_cb(const struct nlmsghdr
*nlh
, void *data
)
66 struct genlmsghdr
*genl
= mnl_nlmsg_get_payload(nlh
);
67 struct nlattr
*info
[TIPC_NLA_MAX
+ 1] = {};
68 struct nlattr
*attrs
[TIPC_NLA_MEDIA_MAX
+ 1] = {};
69 struct nlattr
*props
[TIPC_NLA_PROP_MAX
+ 1] = {};
71 mnl_attr_parse(nlh
, sizeof(*genl
), parse_attrs
, info
);
72 if (!info
[TIPC_NLA_MEDIA
])
75 mnl_attr_parse_nested(info
[TIPC_NLA_MEDIA
], parse_attrs
, attrs
);
76 if (!attrs
[TIPC_NLA_MEDIA_PROP
])
79 mnl_attr_parse_nested(attrs
[TIPC_NLA_MEDIA_PROP
], parse_attrs
, props
);
83 printf("%u\n", mnl_attr_get_u32(props
[*prop
]));
88 static int cmd_media_get_prop(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
89 struct cmdl
*cmdl
, void *data
)
92 char buf
[MNL_SOCKET_BUFFER_SIZE
];
96 { "media", OPT_KEYVAL
, NULL
},
100 if (strcmp(cmd
->cmd
, "priority") == 0)
101 prop
= TIPC_NLA_PROP_PRIO
;
102 else if ((strcmp(cmd
->cmd
, "tolerance") == 0))
103 prop
= TIPC_NLA_PROP_TOL
;
104 else if ((strcmp(cmd
->cmd
, "window") == 0))
105 prop
= TIPC_NLA_PROP_WIN
;
106 else if ((strcmp(cmd
->cmd
, "mtu") == 0))
107 prop
= TIPC_NLA_PROP_MTU
;
116 if (parse_opts(opts
, cmdl
) < 0)
119 if (!(nlh
= msg_init(buf
, TIPC_NL_MEDIA_GET
))) {
120 fprintf(stderr
, "error, message initialisation failed\n");
124 if (!(opt
= get_opt(opts
, "media"))) {
125 fprintf(stderr
, "error, missing media\n");
129 if ((prop
== TIPC_NLA_PROP_MTU
) &&
130 (strcmp(opt
->val
, "udp"))) {
131 fprintf(stderr
, "error, not supported for media\n");
134 nest
= mnl_attr_nest_start(nlh
, TIPC_NLA_MEDIA
);
135 mnl_attr_put_strz(nlh
, TIPC_NLA_MEDIA_NAME
, opt
->val
);
136 mnl_attr_nest_end(nlh
, nest
);
138 return msg_doit(nlh
, media_get_cb
, &prop
);
141 static void cmd_media_get_help(struct cmdl
*cmdl
)
143 fprintf(stderr
, "Usage: %s media get PPROPERTY media MEDIA\n\n"
145 " tolerance - Get media tolerance\n"
146 " priority - Get media priority\n"
147 " window - Get media window\n"
148 " mtu - Get media mtu\n",
152 static int cmd_media_get(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
153 struct cmdl
*cmdl
, void *data
)
155 const struct cmd cmds
[] = {
156 { "priority", cmd_media_get_prop
, cmd_media_get_help
},
157 { "tolerance", cmd_media_get_prop
, cmd_media_get_help
},
158 { "window", cmd_media_get_prop
, cmd_media_get_help
},
159 { "mtu", cmd_media_get_prop
, cmd_media_get_help
},
163 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);
166 static void cmd_media_set_help(struct cmdl
*cmdl
)
168 fprintf(stderr
, "Usage: %s media set PPROPERTY media MEDIA\n\n"
170 " tolerance TOLERANCE - Set media tolerance\n"
171 " priority PRIORITY - Set media priority\n"
172 " window WINDOW - Set media window\n"
173 " mtu MTU - Set media mtu\n",
177 static int cmd_media_set_prop(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
178 struct cmdl
*cmdl
, void *data
)
182 char buf
[MNL_SOCKET_BUFFER_SIZE
];
183 struct nlattr
*props
;
184 struct nlattr
*attrs
;
186 struct opt opts
[] = {
187 { "media", OPT_KEYVAL
, NULL
},
191 if (strcmp(cmd
->cmd
, "priority") == 0)
192 prop
= TIPC_NLA_PROP_PRIO
;
193 else if ((strcmp(cmd
->cmd
, "tolerance") == 0))
194 prop
= TIPC_NLA_PROP_TOL
;
195 else if ((strcmp(cmd
->cmd
, "window") == 0))
196 prop
= TIPC_NLA_PROP_WIN
;
197 else if ((strcmp(cmd
->cmd
, "mtu") == 0))
198 prop
= TIPC_NLA_PROP_MTU
;
207 if (cmdl
->optind
>= cmdl
->argc
) {
208 fprintf(stderr
, "error, missing value\n");
211 val
= atoi(shift_cmdl(cmdl
));
213 if (parse_opts(opts
, cmdl
) < 0)
216 if (!(nlh
= msg_init(buf
, TIPC_NL_MEDIA_SET
))) {
217 fprintf(stderr
, "error, message initialisation failed\n");
220 attrs
= mnl_attr_nest_start(nlh
, TIPC_NLA_MEDIA
);
222 if (!(opt
= get_opt(opts
, "media"))) {
223 fprintf(stderr
, "error, missing media\n");
227 if ((prop
== TIPC_NLA_PROP_MTU
) &&
228 (strcmp(opt
->val
, "udp"))) {
229 fprintf(stderr
, "error, not supported for media\n");
232 mnl_attr_put_strz(nlh
, TIPC_NLA_MEDIA_NAME
, opt
->val
);
234 props
= mnl_attr_nest_start(nlh
, TIPC_NLA_MEDIA_PROP
);
235 mnl_attr_put_u32(nlh
, prop
, val
);
236 mnl_attr_nest_end(nlh
, props
);
238 mnl_attr_nest_end(nlh
, attrs
);
240 return msg_doit(nlh
, NULL
, NULL
);
243 static int cmd_media_set(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
244 struct cmdl
*cmdl
, void *data
)
246 const struct cmd cmds
[] = {
247 { "priority", cmd_media_set_prop
, cmd_media_set_help
},
248 { "tolerance", cmd_media_set_prop
, cmd_media_set_help
},
249 { "window", cmd_media_set_prop
, cmd_media_set_help
},
250 { "mtu", cmd_media_set_prop
, cmd_media_set_help
},
254 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);
257 void cmd_media_help(struct cmdl
*cmdl
)
260 "Usage: %s media COMMAND [ARGS] ...\n"
263 " list - List active media types\n"
264 " get - Get various media properties\n"
265 " set - Set various media properties\n",
269 int cmd_media(struct nlmsghdr
*nlh
, const struct cmd
*cmd
, struct cmdl
*cmdl
,
272 const struct cmd cmds
[] = {
273 { "get", cmd_media_get
, cmd_media_get_help
},
274 { "list", cmd_media_list
, NULL
},
275 { "set", cmd_media_set
, cmd_media_set_help
},
279 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);