From 14c6542e9d79cc2ebc23c6a3fba691f63f55a26f Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org" Date: Sat, 6 Aug 2005 09:00:20 +0000 Subject: add support for callback-based parsing of messages, similar to kernel API --- include/libnfnetlink/libnfnetlink.h | 50 ++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'include/libnfnetlink') diff --git a/include/libnfnetlink/libnfnetlink.h b/include/libnfnetlink/libnfnetlink.h index 95ec004..d88c7fa 100644 --- a/include/libnfnetlink/libnfnetlink.h +++ b/include/libnfnetlink/libnfnetlink.h @@ -16,6 +16,12 @@ #define NFNL_BUFFSIZE 8192 +struct nfnl_callback { + int (*call)(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data); + void *data; + u_int16_t attr_count; +}; + struct nfnl_handle { int fd; struct sockaddr_nl local; @@ -24,34 +30,51 @@ struct nfnl_handle { u_int32_t seq; u_int32_t dump; struct nlmsghdr *last_nlhdr; + + u_int8_t cb_count; + struct nfnl_callback *cb; /* array of callbacks */ }; /* get a new library handle */ -extern int nfnl_open(struct nfnl_handle *, u_int8_t, unsigned int); +extern int nfnl_open(struct nfnl_handle *, u_int8_t, u_int8_t, unsigned int); extern int nfnl_close(struct nfnl_handle *); + +/* sending of data */ extern int nfnl_send(struct nfnl_handle *, struct nlmsghdr *); extern int nfnl_sendmsg(const struct nfnl_handle *, const struct msghdr *msg, unsigned int flags); extern int nfnl_sendiov(const struct nfnl_handle *nfnlh, const struct iovec *iov, unsigned int num, unsigned int flags); - extern void nfnl_fill_hdr(struct nfnl_handle *, struct nlmsghdr *, unsigned int, u_int8_t, u_int16_t, u_int16_t, u_int16_t); +extern int nfnl_talk(struct nfnl_handle *, struct nlmsghdr *, pid_t, + unsigned, struct nlmsghdr *, + int (*)(struct sockaddr_nl *, struct nlmsghdr *, void *), + void *); -extern struct nfattr *nfnl_parse_hdr(const struct nfnl_handle *nfnlh, - const struct nlmsghdr *nlh, - struct nfgenmsg **genmsg); - +/* simple challenge/response */ extern int nfnl_listen(struct nfnl_handle *, int (*)(struct sockaddr_nl *, struct nlmsghdr *, void *), void *); -extern int nfnl_talk(struct nfnl_handle *, struct nlmsghdr *, pid_t, - unsigned, struct nlmsghdr *, - int (*)(struct sockaddr_nl *, struct nlmsghdr *, void *), - void *); +/* receiving */ +extern int nfnl_callback_register(struct nfnl_handle *, + u_int8_t type, struct nfnl_callback *cb); +extern int nfnl_callback_unregister(struct nfnl_handle *, u_int8_t type); +extern int nfnl_handle_packet(struct nfnl_handle *, char *buf, int len); + +/* parsing */ +extern struct nfattr *nfnl_parse_hdr(const struct nfnl_handle *nfnlh, + const struct nlmsghdr *nlh, + struct nfgenmsg **genmsg); +extern struct nlmsghdr *nfnl_get_msg_first(struct nfnl_handle *h, + const unsigned char *buf, + size_t len); +extern struct nlmsghdr *nfnl_get_msg_next(struct nfnl_handle *h, + const unsigned char *buf, + size_t len); /* nfnl attribute handling functions */ extern int nfnl_addattr_l(struct nlmsghdr *, int, int, void *, int); @@ -74,12 +97,5 @@ extern void nfnl_build_nfa_iovec(struct iovec *iov, struct nfattr *nfa, extern unsigned int nfnl_rcvbufsiz(struct nfnl_handle *h, unsigned int size); -extern struct nlmsghdr *nfnl_get_msg_first(struct nfnl_handle *h, - const unsigned char *buf, - size_t len); -extern struct nlmsghdr *nfnl_get_msg_next(struct nfnl_handle *h, - const unsigned char *buf, - size_t len); - extern void nfnl_dump_packet(struct nlmsghdr *, int, char *); #endif /* __LIBNFNETLINK_H */ -- cgit v1.2.3