From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [patch iproute2 v5 1/3] lib/libnetlink: Add a function rtnl_talk_msg Date: Tue, 2 Jan 2018 21:08:42 -0700 Message-ID: <81255ea8-2f27-891e-4fe9-6a97d4de0e64@gmail.com> References: <20180103025517.3767-1-chrism@mellanox.com> <20180103025517.3767-2-chrism@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: gerlitz.or@gmail.com, stephen@networkplumber.org, marcelo.leitner@gmail.com To: Chris Mi , netdev@vger.kernel.org Return-path: Received: from mail-pf0-f194.google.com ([209.85.192.194]:39620 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbeACEIo (ORCPT ); Tue, 2 Jan 2018 23:08:44 -0500 Received: by mail-pf0-f194.google.com with SMTP id l24so282477pfj.6 for ; Tue, 02 Jan 2018 20:08:44 -0800 (PST) In-Reply-To: <20180103025517.3767-2-chrism@mellanox.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: 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. 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. > > - 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. 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 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