]>
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
;
114 if (parse_opts(opts
, cmdl
) < 0)
117 if (!(nlh
= msg_init(buf
, TIPC_NL_MEDIA_GET
))) {
118 fprintf(stderr
, "error, message initialisation failed\n");
122 if (!(opt
= get_opt(opts
, "media"))) {
123 fprintf(stderr
, "error, missing media\n");
126 nest
= mnl_attr_nest_start(nlh
, TIPC_NLA_MEDIA
);
127 mnl_attr_put_strz(nlh
, TIPC_NLA_MEDIA_NAME
, opt
->val
);
128 mnl_attr_nest_end(nlh
, nest
);
130 return msg_doit(nlh
, media_get_cb
, &prop
);
133 static void cmd_media_get_help(struct cmdl
*cmdl
)
135 fprintf(stderr
, "Usage: %s media get PPROPERTY media MEDIA\n\n"
137 " tolerance - Get media tolerance\n"
138 " priority - Get media priority\n"
139 " window - Get media window\n",
143 static int cmd_media_get(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
144 struct cmdl
*cmdl
, void *data
)
146 const struct cmd cmds
[] = {
147 { "priority", cmd_media_get_prop
, cmd_media_get_help
},
148 { "tolerance", cmd_media_get_prop
, cmd_media_get_help
},
149 { "window", cmd_media_get_prop
, cmd_media_get_help
},
153 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);
156 static void cmd_media_set_help(struct cmdl
*cmdl
)
158 fprintf(stderr
, "Usage: %s media set PPROPERTY media MEDIA\n\n"
160 " tolerance TOLERANCE - Set media tolerance\n"
161 " priority PRIORITY - Set media priority\n"
162 " window WINDOW - Set media window\n",
166 static int cmd_media_set_prop(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
167 struct cmdl
*cmdl
, void *data
)
171 char buf
[MNL_SOCKET_BUFFER_SIZE
];
172 struct nlattr
*props
;
173 struct nlattr
*attrs
;
175 struct opt opts
[] = {
176 { "media", OPT_KEYVAL
, NULL
},
180 if (strcmp(cmd
->cmd
, "priority") == 0)
181 prop
= TIPC_NLA_PROP_PRIO
;
182 else if ((strcmp(cmd
->cmd
, "tolerance") == 0))
183 prop
= TIPC_NLA_PROP_TOL
;
184 else if ((strcmp(cmd
->cmd
, "window") == 0))
185 prop
= TIPC_NLA_PROP_WIN
;
194 if (cmdl
->optind
>= cmdl
->argc
) {
195 fprintf(stderr
, "error, missing value\n");
198 val
= atoi(shift_cmdl(cmdl
));
200 if (parse_opts(opts
, cmdl
) < 0)
203 if (!(nlh
= msg_init(buf
, TIPC_NL_MEDIA_SET
))) {
204 fprintf(stderr
, "error, message initialisation failed\n");
207 attrs
= mnl_attr_nest_start(nlh
, TIPC_NLA_MEDIA
);
209 if (!(opt
= get_opt(opts
, "media"))) {
210 fprintf(stderr
, "error, missing media\n");
213 mnl_attr_put_strz(nlh
, TIPC_NLA_MEDIA_NAME
, opt
->val
);
215 props
= mnl_attr_nest_start(nlh
, TIPC_NLA_MEDIA_PROP
);
216 mnl_attr_put_u32(nlh
, prop
, val
);
217 mnl_attr_nest_end(nlh
, props
);
219 mnl_attr_nest_end(nlh
, attrs
);
221 return msg_doit(nlh
, NULL
, NULL
);
224 static int cmd_media_set(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
225 struct cmdl
*cmdl
, void *data
)
227 const struct cmd cmds
[] = {
228 { "priority", cmd_media_set_prop
, cmd_media_set_help
},
229 { "tolerance", cmd_media_set_prop
, cmd_media_set_help
},
230 { "window", cmd_media_set_prop
, cmd_media_set_help
},
234 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);
237 void cmd_media_help(struct cmdl
*cmdl
)
240 "Usage: %s media COMMAND [ARGS] ...\n"
243 " list - List active media types\n"
244 " get - Get various media properties\n"
245 " set - Set various media properties\n",
249 int cmd_media(struct nlmsghdr
*nlh
, const struct cmd
*cmd
, struct cmdl
*cmdl
,
252 const struct cmd cmds
[] = {
253 { "get", cmd_media_get
, cmd_media_get_help
},
254 { "list", cmd_media_list
, NULL
},
255 { "set", cmd_media_set
, cmd_media_set_help
},
259 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);