From: Chris Mi <chrism@mellanox.com>
To: David Ahern <dsahern@gmail.com>, netdev@vger.kernel.org
Cc: gerlitz.or@gmail.com, stephen@networkplumber.org,
marcelo.leitner@gmail.com
Subject: Re: [patch iproute2 v5 1/3] lib/libnetlink: Add a function rtnl_talk_msg
Date: Thu, 4 Jan 2018 15:27:49 +0800 [thread overview]
Message-ID: <82731477-58a3-bbb7-cfdc-d612df01882a@mellanox.com> (raw)
In-Reply-To: <81255ea8-2f27-891e-4fe9-6a97d4de0e64@gmail.com>
2018/1/3 12:08, David Ahern:
> On 1/2/18 7:55 PM, Chris Mi wrote:
>> diff --git a/lib/libnetlink.c b/lib/libnetlink.c
>> index 00e6ce0c..cc02a139 100644
>> --- a/lib/libnetlink.c
>> +++ b/lib/libnetlink.c
>> @@ -581,32 +581,34 @@ static void rtnl_talk_error(struct nlmsghdr *h, struct nlmsgerr *err,
>> strerror(-err->error));
>> }
>>
>> -static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
>> - struct nlmsghdr **answer,
>> - bool show_rtnl_err, nl_ext_ack_fn_t errfn)
>> +static int __rtnl_talk_msg(struct rtnl_handle *rtnl, struct msghdr *m,
>> + struct nlmsghdr **answer,
>> + bool show_rtnl_err, nl_ext_ack_fn_t errfn)
>> {
>> - int status;
>> - unsigned int seq;
>> - struct nlmsghdr *h;
>> + int iovlen = m->msg_iovlen;
>> + unsigned int seq = 0;
>> + int i, status;
>> + char *buf;
>> +
>> struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
>> - struct iovec iov = {
>> - .iov_base = n,
>> - .iov_len = n->nlmsg_len
>> - };
>> + struct iovec iov, *v;
>> + struct nlmsghdr *h;
>> struct msghdr msg = {
>> .msg_name = &nladdr,
>> .msg_namelen = sizeof(nladdr),
>> .msg_iov = &iov,
>> .msg_iovlen = 1,
>> };
>> - char *buf;
> Reverse xmas tree is the coding standard for net code. Please adhere to
> it. Only dependencies between variables are an acceptable exception.
OK, got it.
>
> Some of those (struct nlmsghdr *h and struct iovec *v) can be moved to
> the for loop which aligns with your intentions of grouping variables.
Done.
>
>>
>> - n->nlmsg_seq = seq = ++rtnl->seq;
>> -
>> - if (answer == NULL)
>> - n->nlmsg_flags |= NLM_F_ACK;
>> + for (i = 0; i < iovlen; i++) {
>> + v = &m->msg_iov[i];
>> + h = v->iov_base;
>> + h->nlmsg_seq = seq = ++rtnl->seq;
> doesn't seq need to track the recvmsg loop? I think for batching you
> want it to start at the first seq number and then in the recvmsg loop
> increment it.
Yes, it is a bug. Thanks for your test case.
>
> As it stands this file:
> $ cat tc.batch
> filter add dev eth2 ingress protocol ip pref 21 flower dst_ip
> 192.168.1.0/16 action drop
> filter add dev eth2 ingress protocol ip pref 22 flower dst_ip
> 192.168.2.0/16 action drop
> filter add dev eth2 ingress protocol ip pref 22 flower dst_ip
> 192.168.3.0/16 action drop
> filter add dev eth2 ingress protocol ip pref 24 flower dst_ip
> 192.168.4.0/16 action drop
> filter add dev eth2 ingress protocol ip pref 25 flower dst_ip
> 192.168.5.0/16 action drop
>
> does not give me an error message:
> $ tc -b tc.batch -bs 5
> <no output>
>
> Yet it failed to insert all filters:
> $ tc filter show dev eth2 ingress
> filter protocol ip pref 21 flower chain 0
> filter protocol ip pref 21 flower chain 0 handle 0x1
> eth_type ipv4
> dst_ip 192.168.1.0/16
> not_in_hw
> action order 1: gact action drop
> random type none pass val 0
> index 1 ref 1 bind 1
>
> filter protocol ip pref 22 flower chain 0
> filter protocol ip pref 22 flower chain 0 handle 0x1
> eth_type ipv4
> dst_ip 192.168.2.0/16
> not_in_hw
> action order 1: gact action drop
> random type none pass val 0
> index 2 ref 1 bind 1
>
> filter protocol ip pref 24 flower chain 0
> filter protocol ip pref 24 flower chain 0 handle 0x1
> eth_type ipv4
> dst_ip 192.168.4.0/16
> not_in_hw
> action order 1: gact action drop
> random type none pass val 0
> index 3 ref 1 bind 1
>
> filter protocol ip pref 25 flower chain 0
> filter protocol ip pref 25 flower chain 0 handle 0x1
> eth_type ipv4
> dst_ip 192.168.5.0/16
> not_in_hw
> action order 1: gact action drop
> random type none pass val 0
> index 4 ref 1 bind 1
>
After fixing it, the test result is:
# tc -b tc.batch -bs 5
RTNETLINK answers: File exists
We have an error talking to the kernel, -1
Command failed 1.txt:0-4
We can't tell exactly which command causes this error, so we give a
range which is less than the batch size.
next prev parent reply other threads:[~2018-01-04 7:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-03 2:55 [patch iproute2 v5 0/3] tc: Add -bs option to batch mode Chris Mi
2018-01-03 2:55 ` [patch iproute2 v5 1/3] lib/libnetlink: Add a function rtnl_talk_msg Chris Mi
2018-01-03 4:08 ` David Ahern
2018-01-04 7:27 ` Chris Mi [this message]
2018-01-03 2:55 ` [patch iproute2 v5 2/3] tc: Add -bs option to batch mode Chris Mi
2018-01-03 4:25 ` David Ahern
2018-01-04 7:32 ` Chris Mi
2018-01-03 2:55 ` [patch iproute2 v5 3/3] man: Add -bs option to tc manpage Chris Mi
2018-01-03 2:57 ` [patch iproute2 v5 0/3] tc: Add -bs option to batch mode David Ahern
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=82731477-58a3-bbb7-cfdc-d612df01882a@mellanox.com \
--to=chrism@mellanox.com \
--cc=dsahern@gmail.com \
--cc=gerlitz.or@gmail.com \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/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