From: Pablo Neira Ayuso <pablo@netfilter.org>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] route_bench: Filter out all responses.
Date: Sun, 20 Feb 2011 23:28:15 +0100 [thread overview]
Message-ID: <4D61957F.5060905@netfilter.org> (raw)
In-Reply-To: <20110220.140450.48516784.davem@davemloft.net>
On 20/02/11 23:04, David Miller wrote:
>
> Install a socket filter to reduce the pure netlink overhead.
>
> Unfortunately the libmnl library does not provide a way to
> set socket options that are of level other than SOL_NETLINK.
>
> So we hack it by knowing some things about libmnl internals.
>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> ---
>
> The knowledge of libmnl internals is unfortunate, but there
> is currently no other way to do this.
>
> route_bench.c | 33 +++++++++++++++++++++++++--------
> 1 files changed, 25 insertions(+), 8 deletions(-)
>
> diff --git a/route_bench.c b/route_bench.c
> index c75ea45..6c6b525 100644
> --- a/route_bench.c
> +++ b/route_bench.c
> @@ -22,6 +22,17 @@
> #include <linux/if.h>
> #include <linux/if_link.h>
> #include <linux/rtnetlink.h>
> +#include <linux/filter.h>
> +
> +/* XXX Ugly knowledge of internals, but there is currently no way
> + * XXX provided by the libmnl library to set socket options that are
> + * XXX of level other than SOL_NETLINK. And we need to set one of
> + * XXX level SOL_SOCKET to install the socket filter.
> + */
> +struct mnl_socket {
> + int fd;
> + struct sockaddr_nl addr;
> +};
>
> static int usage(void)
> {
> @@ -139,8 +150,10 @@ static int do_bench(int count, in_addr_t src_addr, in_addr_t dst_addr,
> unsigned int mark, unsigned int iif)
> {
> char send_buf[MNL_SOCKET_BUFFER_SIZE];
> - char recv_buf[MNL_SOCKET_BUFFER_SIZE];
> unsigned int min, sec, frac, tmp;
> + struct sock_filter insns = { .code = BPF_RET | BPF_K,
> + .k = 0 };
> + struct sock_fprog filter = { .len = 1, .filter = &insns, };
> struct bench_state *s = &state;
> struct timeval start_time;
> struct timeval end_time;
> @@ -148,7 +161,7 @@ static int do_bench(int count, in_addr_t src_addr, in_addr_t dst_addr,
> struct nlmsghdr *nlh;
> unsigned int portid;
> struct rtmsg *rtm;
> - int i;
> + int i, err;
>
> init_bench_state(s);
>
> @@ -165,10 +178,15 @@ static int do_bench(int count, in_addr_t src_addr, in_addr_t dst_addr,
>
> portid = mnl_socket_get_portid(nl);
>
> + err = setsockopt(nl->fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter));
> + if (err) {
> + perror("setsockopt");
> + return -1;
> + }
> +
You can use:
extern int mnl_socket_get_fd(const struct mnl_socket *nl);
Thus, you can invoke setsockopt directly ;-).
next prev parent reply other threads:[~2011-02-20 22:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-20 22:04 [PATCH] route_bench: Filter out all responses David Miller
2011-02-20 22:28 ` Pablo Neira Ayuso [this message]
2011-02-20 22:32 ` David Miller
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=4D61957F.5060905@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.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