From: Cyril Hrubis <chrubis@suse.cz>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/3] tst_netdevice: Add helper functions for qdisc and filter management
Date: Fri, 28 Jul 2023 09:53:58 +0200 [thread overview]
Message-ID: <ZMN0FtFduNJgY1cc@yuki> (raw)
In-Reply-To: <20230727150013.31835-2-mdoucha@suse.cz>
Hi!
> --- a/lib/tst_netdevice.c
> +++ b/lib/tst_netdevice.c
> @@ -7,6 +7,7 @@
> #include <linux/veth.h>
> #include <sys/socket.h>
> #include <net/if.h>
> +#include <linux/pkt_sched.h>
> #include "lapi/rtnetlink.h"
>
> #define TST_NO_DEFAULT_MAIN
> @@ -518,3 +519,116 @@ int tst_netdev_remove_route_inet(const char *file, const int lineno,
> return modify_route_inet(file, lineno, RTM_DELROUTE, 0, ifname,
> srcaddr, srcprefix, dstaddr, dstprefix, gateway);
> }
> +
> +static int modify_qdisc(const char *file, const int lineno, const char *object,
> + unsigned int action, unsigned int nl_flags, const char *ifname,
> + unsigned int family, unsigned int parent, unsigned int handle,
> + unsigned int info, const char *qd_kind,
> + const struct tst_rtnl_attr_list *config)
> +{
> + struct tst_rtnl_context *ctx;
> + int ret;
> + struct tcmsg msg = {
> + .tcm_family = family,
> + .tcm_handle = handle,
> + .tcm_parent = parent,
> + .tcm_info = info
> + };
> +
> + if (!qd_kind) {
> + tst_brk_(file, lineno, TBROK,
> + "Queueing discipline name required");
> + return 0;
> + }
> +
> + if (ifname) {
> + msg.tcm_ifindex = tst_netdev_index_by_name(file, lineno,
> + ifname);
> +
> + if (msg.tcm_ifindex < 0) {
> + tst_brk_(file, lineno, TBROK, "Interface %s not found",
> + ifname);
> + return 0;
> + }
> + }
> +
> + ctx = create_request(file, lineno, action, nl_flags, &msg, sizeof(msg));
> +
> + if (!ctx)
> + return 0;
> +
> + if (!tst_rtnl_add_attr_string(file, lineno, ctx, TCA_KIND, qd_kind)) {
> + tst_rtnl_destroy_context(file, lineno, ctx);
> + return 0;
> + }
> +
> + if (config && !tst_rtnl_add_attr_list(file, lineno, ctx, config)) {
> + tst_rtnl_destroy_context(file, lineno, ctx);
> + return 0;
> + }
Here as well, shouldn't we tst_brk_() consistently if we fail to prepare
the context?
> + ret = tst_rtnl_send_validate(file, lineno, ctx);
> + tst_rtnl_destroy_context(file, lineno, ctx);
> +
> + if (!ret) {
> + tst_brk_(file, lineno, TBROK,
> + "Failed to modify %s: %s", object,
> + tst_strerrno(tst_rtnl_errno));
> + }
> +
> + return ret;
> +}
> +
> +int tst_netdev_add_qdisc(const char *file, const int lineno,
> + const char *ifname, unsigned int family, unsigned int parent,
> + unsigned int handle, const char *qd_kind,
> + const struct tst_rtnl_attr_list *config)
> +{
> + return modify_qdisc(file, lineno, "queueing discipline", RTM_NEWQDISC,
> + NLM_F_CREATE | NLM_F_EXCL, ifname, family, parent, handle, 0,
> + qd_kind, config);
> +}
> +
> +int tst_netdev_remove_qdisc(const char *file, const int lineno,
> + const char *ifname, unsigned int family, unsigned int parent,
> + unsigned int handle, const char *qd_kind)
> +{
> + return modify_qdisc(file, lineno, "queueing discipline", RTM_DELQDISC,
> + 0, ifname, family, parent, handle, 0, qd_kind, NULL);
> +}
> +
> +int tst_netdev_add_traffic_class(const char *file, const int lineno,
> + const char *ifname, unsigned int parent, unsigned int handle,
> + const char *qd_kind, const struct tst_rtnl_attr_list *config)
> +{
> + return modify_qdisc(file, lineno, "traffic class", RTM_NEWTCLASS,
> + NLM_F_CREATE | NLM_F_EXCL, ifname, AF_UNSPEC, parent, handle,
> + 0, qd_kind, config);
> +}
> +
> +int tst_netdev_remove_traffic_class(const char *file, const int lineno,
> + const char *ifname, unsigned int parent, unsigned int handle,
> + const char *qd_kind)
> +{
> + return modify_qdisc(file, lineno, "traffic class", RTM_DELTCLASS, 0,
> + ifname, AF_UNSPEC, parent, handle, 0, qd_kind, NULL);
> +}
> +
> +int tst_netdev_add_traffic_filter(const char *file, const int lineno,
> + const char *ifname, unsigned int parent, unsigned int handle,
> + unsigned int protocol, unsigned int priority, const char *f_kind,
> + const struct tst_rtnl_attr_list *config)
> +{
> + return modify_qdisc(file, lineno, "traffic filter", RTM_NEWTFILTER,
> + NLM_F_CREATE | NLM_F_EXCL, ifname, AF_UNSPEC, parent, handle,
> + TC_H_MAKE(priority << 16, htons(protocol)), f_kind, config);
> +}
> +
> +int tst_netdev_remove_traffic_filter(const char *file, const int lineno,
> + const char *ifname, unsigned int parent, unsigned int handle,
> + unsigned int protocol, unsigned int priority, const char *f_kind)
> +{
> + return modify_qdisc(file, lineno, "traffic filter", RTM_DELTFILTER,
> + 0, ifname, AF_UNSPEC, parent, handle,
> + TC_H_MAKE(priority << 16, htons(protocol)), f_kind, NULL);
> +}
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-07-28 7:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 15:00 [LTP] [PATCH 1/3] tst_netdevice: Add missing rtnetlink context allocation checks Martin Doucha
2023-07-27 15:00 ` [LTP] [PATCH 2/3] tst_netdevice: Add helper functions for qdisc and filter management Martin Doucha
2023-07-28 7:53 ` Cyril Hrubis [this message]
2023-07-28 8:21 ` Martin Doucha
2023-07-28 12:09 ` Petr Vorel
2023-07-27 15:00 ` [LTP] [PATCH 3/3] Add test for CVE 2023-1829 Martin Doucha
2023-07-28 8:36 ` Petr Vorel
2023-08-03 12:51 ` Cyril Hrubis
2023-08-04 9:23 ` Martin Doucha
2023-07-28 7:46 ` [LTP] [PATCH 1/3] tst_netdevice: Add missing rtnetlink context allocation checks Cyril Hrubis
2023-07-28 8:17 ` Martin Doucha
2023-07-28 8:45 ` Cyril Hrubis
2023-07-28 11:43 ` Petr Vorel
2023-08-04 13:28 ` [LTP] [PATCH v2 3/3] Add test for CVE 2023-1829 Martin Doucha
2023-08-04 13:38 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZMN0FtFduNJgY1cc@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=mdoucha@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox