All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] libnfnetlink, libnetfilter_log, libnetfilter_queue  error handling
@ 2006-06-09 16:01 Gregor Maier
  2006-06-11 22:04 ` Pablo Neira Ayuso
  2006-06-12 12:34 ` Holger Eitzenberger
  0 siblings, 2 replies; 3+ messages in thread
From: Gregor Maier @ 2006-06-09 16:01 UTC (permalink / raw)
  To: netfilter-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,


I noticed that libnfnetlink, libnetfilter_* are currently missing decent
error handling and reporting mechanisms.

libnetfilter_log and libnetfilter_queue define a nflog_errno resp.
nfq_errno but those aren't really used. libnfnetlink uses fprintf for
error handling/reporting.



What do you think about the following suggestions:
* add a nfnl_errno variable
* add #defines for nfnl_errno values also add a nfnl_strerror and a
nfnl_perror function
* add #defines for nflog_errno and nfq_errno and nf{log|q}_strerror and
nf{log|q}_perror functions.

* make nflog_errno and nfq_errno a superset of the nfnl_errnos. E.g. by
defining that error values from 1...N are for nfnl and values above N
are for nfq_errno and nflog_errno.
* nflog_strerror (and nfq_strerror) check if nflog_errno (resp.
nfq_errno) is <= N. If so, they call nfnl_strerror otherwise they handle
the error themselves.

A user of the libnetfilter_{queue|log} only has to use the nfq_strerror
or nflog_strerror (resp. perror) functions without getting in touch with
the libnfnetlink errors. And by making nf{q|log}_errnos a superset of
nfnl_errnos, reporting netlink errors is straightforward.



How this could look like in code:

/**** libnfnetlink ****/
#define   ENFNL_NOERR    0
#define   ENFNL_FOO      1
#define   ENFNL_FOOBAR   2
....
#define   ENFNL_MAXERR   1024



static const char *const nfnl_errlist[] =
{
   "No error",                  /* 0 */
   "Error foo occured",         /* 1 = ENFNL_FOO */
 .....
};

const char *nfnl_strerror(int errnum) {
	static char buf[1024];

	if (errnum >= nfnl_nerr) {
		snprintf(buf, sizeof(buf), "No such nfnetlink error number %d", errnum);
	}
	else {
		strncpy(buf, nfnl_errlist[errnum], sizeof(buf)-1);
      	buf[sizeof(buf)-1] = '\0'; /* terminate if the error was too long */
	}
	return buf;
		
}



void nfnl_perror(const char *s);

static const int nfnl_nerr =  sizeof (nfnl_errlist) / sizeof
(nfnl_errlist[0]);


/*******************************/
/***** libnetfilter_queue *****/
#define   ENFQ_DUMMY    (ENFQ_MAXERR+1)
#define   ENFQ_BLUB     (ENFQ_MAXERR+2)

...
const char *nfq_strerror(int errnum) {
	static char buf[1024];

	if (errnum <= ENFNL_MAXERR) {
		snprintf(buf, sizeof(buf), "%s", nfnl_strerror(errnum));
	}
	else if (errnum >= ENFNL_MAXERR+1+nfq_nerr) {
		snprintf(buf, sizeof(buf), "No such netfilter_queue error number %d",
errnum);
	}
	else {
		strncpy(buf, nfq_errlist[errnum-ENFNL_MAXERR-1], sizeof(buf)-1);
      	buf[sizeof(buf)-1] = '\0'; /* terminate if the error was too long */
	}
	return buf;
		
}




/*******************************/
/***** libnetfilter_log *****/
#define   ENFLOG_FOO      (ENFNL_MAXERR+1)
#define   ENFLOG_BARFOO   (ENFNL_MAXERR+2)

...
const char *nflog_strerror(int errnum) {
	static char buf[1024];

	if (errnum <= ENFNL_MAXERR) {
		snprintf(buf, sizeof(buf), "%s", nfnl_strerror(errnum));
	}
	else if (errnum >= ENFNL_MAXERR+1+nflog_nerr) {
		snprintf(buf, sizeof(buf), "No such netfilter_log error number %d",
errnum);
	}
	else {
		strncpy(buf, nflog_errlist[errnum-ENFNL_MAXERR-1], sizeof(buf)-1);
      	buf[sizeof(buf)-1] = '\0'; /* terminate if the error was too long */
	}
	return buf;
		
}



Comments?

cu
Gregor

- --
Gregor Maier                                      Lehrstuhl Informatik 8
gregor@net.in.tum.de                              Tel: +49 89  289-18010
http://www.net.in.tum.de                                     TU Muenchen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEiZtEdGiwgbikMYMRAmiWAJ9vKqp5xdOLeI3dZzh8xsMEw+bxWgCgmC0t
lYaGuEyxlMa7Rvma4qhRdbA=
=ZmGE
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-12 12:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-09 16:01 [RFC] libnfnetlink, libnetfilter_log, libnetfilter_queue error handling Gregor Maier
2006-06-11 22:04 ` Pablo Neira Ayuso
2006-06-12 12:34 ` Holger Eitzenberger

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.