From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Eric Leblond <eric@inl.fr>
Cc: Harald Welte <laforge@netfilter.org>,
netfilter-devel@lists.netfilter.org,
Patrick McHardy <kaber@trash.net>,
Vincent Deffontaines <vincent@inl.fr>
Subject: Re: [Patch 1/2] libnfnetlink, iface conversion to string
Date: Thu, 25 Jan 2007 02:46:35 +0100 [thread overview]
Message-ID: <45B80BFB.2060203@netfilter.org> (raw)
In-Reply-To: <59155.90.13.189.211.1169586830.squirrel@mail.inl.fr>
Hi Eric,
Eric Leblond wrote:
>> On Fri, Jan 19, 2007 at 06:38:42PM +0100, Pablo Neira Ayuso wrote:
>>> Patrick McHardy wrote:
>>> Indeed. Eric, all this global stuff below must dissapear at all, from
>>> rtnl.c:
>
> I've done a big cleaning and I hope I will not annoy Patrick with my
> coding style problem this time.
>
> I've introduced two structures:
>
> struct rtnl_inst {
^^^^
please, rename this to _handle
> int rtnl_fd;
> int rtnl_seq;
> int rtnl_dump;
> struct sockaddr_nl rtnl_local;
> struct rtnl_handler *handlers;
> };
>
> struct nlif_inst {
^^^^
same thing here
> struct ifindex_map *ifindex_map[16];
> struct rtnl_inst *rtnl_inst;
> struct rtnl_handler *ifadd_handler;
> struct rtnl_handler *ifdel_handler;
> };
>
> which hide all previously defined global variables.
>
> The list of exported functions is the following:
>
> struct nlif_inst *nlif_table_init(void);
> void nlif_table_fini(struct nlif_inst *orig);
> int nlif_get_fd(struct nlif_inst *nlif_inst); /* to be used in select */
> int nlif_treat_msg(struct nlif_inst *nlif_inst);
I prefer keeping it homogeneous with libnfnetlink, I would rename the
functions above to:
struct nlif_handle *nlif_open(void);
void nlif_close(struct nlif_handle *h);
int nlif_fd(struct nlif_handle *h);
int nlif_catch(struct nlif_handle *h);
char *nlif_index2name(struct nlif_handle *h, unsigned int index);
BTW, could you spend some time on documenting the API in docbook format?
I know that this is not available in all netfilter libraries but I'd
appreciate it, we should start getting use to do these things ;)
> === include/libnfnetlink/libnfnetlink.h
> ==================================================================
> --- include/libnfnetlink/libnfnetlink.h (revision 5686)
> +++ include/libnfnetlink/libnfnetlink.h (local)
> @@ -176,6 +176,22 @@
>
> extern void nfnl_dump_packet(struct nlmsghdr *, int, char *);
>
> +struct nlif_inst {
> + struct ifindex_map *ifindex_map[16];
> + struct rtnl_inst *rtnl_inst;
> + struct rtnl_handler *ifadd_handler;
> + struct rtnl_handler *ifdel_handler;
> +};
move this definition to an internal header file and just put an empty
definition inside libnfnetlink.h like:
struct nlif_handle;
This is better for encapsulation, if we have to modify the layout later
for whatever reason, we will not break backward binary compatibility. We
just give a pointer to an object with private attributes that are only
accesible through the appropiate functions like the nlif_fd() getter.
> === src/iftable.c
> ==================================================================
> --- src/iftable.c (revision 5686)
> +++ src/iftable.c (local)
> @@ -19,6 +19,7 @@
>
> #include <linux/netdevice.h>
>
> +#include <libnfnetlink/libnfnetlink.h>
> #include "rtnl.h"
>
> #define iftb_log(x, ...)
> @@ -34,28 +35,6 @@
> char name[16];
> };
>
> -static struct ifindex_map *ifindex_map[16];
> -
> -/* iftable_dump - Dump the interface table to a given file stream
> - * @outfd: file stream to which table should be dumped
> - */
> -int iftable_dump(FILE *outfd)
> -{
> - int i;
> -
> - for (i = 0; i < 16; i++) {
> - struct ifindex_map *im;
> - for (im = ifindex_map[i]; im; im = im->next) {
> - fprintf(outfd, "%u %s", im->index, im->name);
> - if (!(im->flags & IFF_UP))
> - fputs(" DOWN", outfd);
> - fputc('\n', outfd);
> - }
> - }
> - fflush(outfd);
> - return 0;
> -}
We can introduce some kind of iterator, later:
int nlif_iterate(struct nlif_handle *h, int (*iterate)(void *data));
That's enough for now, we can revisit this later and clean it up a bit
more. Thanks.
--
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
next prev parent reply other threads:[~2007-01-25 1:46 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-27 22:17 [RFC] libnfnetlink and iface conversion to string Eric Leblond
2006-12-28 17:39 ` Pablo Neira Ayuso
2006-12-28 23:40 ` Eric Leblond
2007-01-02 8:46 ` [Patch 1/2] Resend : sending iface name from nfnetlink_queue Eric Leblond
2007-01-10 6:52 ` Patrick McHardy
2007-01-02 8:48 ` [Patch 2/2] getting iface name from libnetfilter_queue Eric Leblond
2007-01-07 14:26 ` [RFC] libnfnetlink and iface conversion to string Harald Welte
2007-01-08 22:41 ` Eric Leblond
2007-01-09 0:53 ` Pablo Neira Ayuso
2007-01-09 2:50 ` Eric Leblond
2007-01-09 11:51 ` Harald Welte
2007-01-18 23:24 ` [Patch 0/2] " Eric Leblond
2007-01-18 23:30 ` [Patch 1/2] libnfnetlink, " Eric Leblond
2007-01-19 15:22 ` Patrick McHardy
2007-01-19 17:38 ` Pablo Neira Ayuso
2007-01-19 22:46 ` Eric Leblond
2007-01-22 12:36 ` Harald Welte
2007-01-23 21:13 ` Eric Leblond
2007-01-24 16:50 ` Patrick McHardy
2007-01-25 1:46 ` Pablo Neira Ayuso [this message]
2007-01-25 12:11 ` Eric Leblond
2007-01-25 15:59 ` Harald Welte
2007-01-26 2:24 ` Pablo Neira Ayuso
2007-01-25 12:16 ` [Patch 2/2] libnetfilter_queue, " Eric Leblond
2007-01-26 2:26 ` Pablo Neira Ayuso
2007-01-29 10:36 ` Eric Leblond
2007-01-31 1:49 ` Pablo Neira Ayuso
2007-01-18 23:33 ` [Patch 2/2] libnetfilter_queue and " Eric Leblond
2007-01-19 15:25 ` Patrick McHardy
2007-01-19 16:17 ` Resend: " Eric Leblond
2007-01-23 21:17 ` Eric Leblond
2007-01-09 10:22 ` [RFC] libnfnetlink " Patrick McHardy
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=45B80BFB.2060203@netfilter.org \
--to=pablo@netfilter.org \
--cc=eric@inl.fr \
--cc=kaber@trash.net \
--cc=laforge@netfilter.org \
--cc=netfilter-devel@lists.netfilter.org \
--cc=vincent@inl.fr \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.