From: Eric Leblond <eric@inl.fr>
To: Harald Welte <laforge@netfilter.org>
Cc: Vincent Deffontaines <vincent@inl.fr>,
netfilter-devel@lists.netfilter.org,
Patrick McHardy <kaber@trash.net>,
Pablo Neira Ayuso <pablo@netfilter.org>
Subject: [Patch 1/2] libnfnetlink, iface conversion to string
Date: Fri, 19 Jan 2007 00:30:50 +0100 [thread overview]
Message-ID: <1169163050.8926.16.camel@localhost> (raw)
In-Reply-To: <1169162676.8926.14.camel@localhost>
[-- Attachment #1.1: Type: text/plain, Size: 92 bytes --]
Hi,
Here's the patch against libnfnetlink.
BR,
--
Eric Leblond <eric@inl.fr>
INL
[-- Attachment #1.2: libnfnetlink_iface_name.diff --]
[-- Type: text/x-patch, Size: 5687 bytes --]
Index: include/libnfnetlink/libnfnetlink.h
===================================================================
--- include/libnfnetlink/libnfnetlink.h (révision 6736)
+++ include/libnfnetlink/libnfnetlink.h (copie de travail)
@@ -176,6 +176,13 @@
extern void nfnl_dump_packet(struct nlmsghdr *, int, char *);
+int nlif_table_init(void);
+void nlif_table_fini(void);
+
+char *nlif_index_2name(unsigned int index);
+int nlif_treat_msg(int fd);
+
+
/* Pablo: What is the equivalence of be64_to_cpu in userspace?
*
* Harald: Good question. I don't think there's a standard way [yet?],
Index: src/rtnl.c
===================================================================
--- src/rtnl.c (révision 6736)
+++ src/rtnl.c (copie de travail)
@@ -116,7 +116,7 @@
struct sockaddr_nl nladdr;
memset(&nladdr, 0, sizeof(nladdr));
- memset(&req, 0, sizeof(req));
+ memset(&req, 0, sizeof(req));
nladdr.nl_family = AF_NETLINK;
req.nlh.nlmsg_len = sizeof(req);
@@ -127,11 +127,11 @@
req.g.rtgen_family = AF_INET;
return sendto(rtnl_fd, (void*)&req, sizeof(req), 0,
- (struct sockaddr*)&nladdr, sizeof(nladdr));
+ (struct sockaddr*)&nladdr, sizeof(nladdr));
}
/* rtnl_receive - receive netlink packets from rtnetlink socket */
-int rtnl_receive()
+int rtnl_receive(int rtnl_fd)
{
int status;
char buf[8192];
Index: src/iftable.c
===================================================================
--- src/iftable.c (révision 6736)
+++ src/iftable.c (copie de travail)
@@ -2,7 +2,7 @@
*
* (C) 2004 by Astaro AG, written by Harald Welte <hwelte@astaro.com>
*
- * This software is Free Software and licensed under GNU GPLv2.
+ * This software is Free Software and licensed under GNU GPLv2.
*
*/
@@ -23,8 +23,8 @@
#define iftb_log(x, ...)
-struct ifindex_map {
- struct ifindex_map *next;
+struct ifindex_map_t {
+ struct ifindex_map_t *next;
u_int32_t index;
u_int32_t type;
@@ -34,7 +34,7 @@
char name[16];
};
-static struct ifindex_map *ifindex_map[16];
+static struct ifindex_map_t *ifindex_map[16];
/* iftable_dump - Dump the interface table to a given file stream
* @outfd: file stream to which table should be dumped
@@ -44,7 +44,7 @@
int i;
for (i = 0; i < 16; i++) {
- struct ifindex_map *im;
+ struct ifindex_map_t *im;
for (im = ifindex_map[i]; im; im = im->next) {
fprintf(outfd, "%u %s", im->index, im->name);
if (!(im->flags & IFF_UP))
@@ -67,7 +67,7 @@
{
unsigned int hash;
struct ifinfomsg *ifi_msg = NLMSG_DATA(n);
- struct ifindex_map *im, **imp;
+ struct ifindex_map_t *im, **imp;
struct rtattr *cb[IFLA_MAX+1];
if (n->nlmsg_type != RTM_NEWLINK)
@@ -108,7 +108,7 @@
iftb_log(LOG_DEBUG, "creating new iftable (ifindex=%u)",
im->index);
}
-
+
im->type = ifi_msg->ifi_type;
im->flags = ifi_msg->ifi_flags;
if (cb[IFLA_ADDRESS]) {
@@ -129,14 +129,13 @@
* @n: netlink message header of a RTM_DELLINK nlmsg
* @arg: not used
*
- * Delete an entry from the interface table.
+ * Delete an entry from the interface table.
* Returns -1 on error, 0 if no matching entry was found or 1 on success.
*/
int iftable_del(struct nlmsghdr *n, void *arg)
{
struct ifinfomsg *ifi_msg = NLMSG_DATA(n);
struct rtattr *cb[IFLA_MAX+1];
- struct ifindex_map *im;
if (n->nlmsg_type != RTM_DELLINK) {
iftb_log(LOG_ERROR,
@@ -157,15 +156,15 @@
return 1;
}
-
-/* ifindex_2name - get the name for an ifindex
+
+/* nl_ifindex_2name - get the name for an ifindex
* @index: ifindex to be resolved
*
* Return value: character string containing name of interface
*/
-char *ifindex_2name(unsigned int index)
+char *nlif_index_2name(unsigned int index)
{
- struct ifindex_map *im;
+ struct ifindex_map_t *im;
if (index == 0)
return "*";
@@ -183,7 +182,7 @@
*/
int iftable_up(unsigned int index)
{
- struct ifindex_map *im;
+ struct ifindex_map_t *im;
for (im = ifindex_map[index&0xF]; im; im = im->next) {
if (im->index == index) {
@@ -208,6 +207,14 @@
if (fini)
goto cleanup;
+ memset(ifindex_map,0,sizeof(ifindex_map));
+
+ ret = rtnl_init();
+
+ if (ret == -1) {
+ goto cleanup_none;
+ }
+
if (rtnl_handler_register(&handlers[0]) < 0) {
ret = -1;
goto cleanup_none;
@@ -223,7 +230,7 @@
goto cleanup_1;
}
- return 0;
+ return ret;
#if 0
if (rtnl_wilddump_requet(rtnl_fd, AF_UNSPEC, RTM_GETLINK) < 0) {
@@ -243,19 +250,30 @@
return ret;
}
-/* iftable_init - Initialize interface table
+/** nl_iftable_init - Initialize interface table
+ *
+ * Initialize rtnl interface and interface table
+ *
+ * \return file descriptor to netlink socket
*/
-int iftable_init(void)
+int nlif_table_init(void)
{
iftb_log(LOG_DEBUG, "%s", __FUNCTION__);
return init_or_fini(0);
}
-/* iftable_fini - Destructor of interface table
+/* nl_iftable_fini - Destructor of interface table
*/
-void iftable_fini(void)
+void nlif_table_fini(void)
{
init_or_fini(1);
}
+/**
+ * \return 0 if OK
+ */
+int nlif_treat_msg(int fd)
+{
+ return rtnl_receive(fd);
+}
Index: src/Makefile.am
===================================================================
--- src/Makefile.am (révision 6736)
+++ src/Makefile.am (copie de travail)
@@ -8,4 +8,4 @@
libnfnetlink_la_LDFLAGS = -Wc,-nostartfiles \
-version-info $(LIBVERSION)
-libnfnetlink_la_SOURCES = libnfnetlink.c
+libnfnetlink_la_SOURCES = libnfnetlink.c iftable.c rtnl.c
[-- Attachment #2: Ceci est une partie de message numériquement signée --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-01-18 23:30 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 ` Eric Leblond [this message]
2007-01-19 15:22 ` [Patch 1/2] libnfnetlink, " 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
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=1169163050.8926.16.camel@localhost \
--to=eric@inl.fr \
--cc=kaber@trash.net \
--cc=laforge@netfilter.org \
--cc=netfilter-devel@lists.netfilter.org \
--cc=pablo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).