libipq.h revision 803f33c0e9cb458cf7989f3826e9baba8da19e2f
1e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher/*
2e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * libipq.h
3e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher *
4e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * IPQ library for userspace.
5e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher *
6e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * This program is free software; you can redistribute it and/or modify
7e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * it under the terms of the GNU General Public License as published by
8e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * the Free Software Foundation; either version 2 of the License, or
9e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * (at your option) any later version.
10e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher *
11e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * This program is distributed in the hope that it will be useful,
12e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * but WITHOUT ANY WARRANTY; without even the implied warranty of
13e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher * GNU General Public License for more details.
15e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher *
16e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher */
17e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#ifndef _LIBIPQ_H
18e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#define _LIBIPQ_H
19e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
20e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <errno.h>
21e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <unistd.h>
22e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <fcntl.h>
23e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <sys/types.h>
24e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <sys/socket.h>
25e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <sys/uio.h>
26e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <asm/types.h>
27e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <linux/netlink.h>
28e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
29eede68159820640725c2f92dcc95cd97de1df743Rusty Russell#ifdef KERNEL_64_USERSPACE_32
30eede68159820640725c2f92dcc95cd97de1df743Rusty Russell#include "ip_queue_64.h"
31803f33c0e9cb458cf7989f3826e9baba8da19e2fRusty Russelltypedef u_int64_t ipq_id_t;
32eede68159820640725c2f92dcc95cd97de1df743Rusty Russell#else
33e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <linux/netfilter_ipv4/ip_queue.h>
34803f33c0e9cb458cf7989f3826e9baba8da19e2fRusty Russelltypedef u_int32_t ipq_id_t;
35eede68159820640725c2f92dcc95cd97de1df743Rusty Russell#endif
36e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
37e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#ifdef DEBUG_LIBIPQ
38e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#include <stdio.h>
39e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#define LDEBUG(x...) fprintf(stderr, ## x)
40e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#else
41e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#define LDEBUG(x...)
42e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#endif	/* DEBUG_LIBIPQ */
43e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
44e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher/* FIXME: glibc sucks */
45e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#ifndef MSG_TRUNC
46e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#define MSG_TRUNC 0x20
47e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#endif
48e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
49e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherstruct ipq_handle
50e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher{
51e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher	int fd;
52e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher	u_int8_t blocking;
53e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher	struct sockaddr_nl local;
54e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher	struct sockaddr_nl peer;
55e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher};
56e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
57e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherstruct ipq_handle *ipq_create_handle(u_int32_t flags);
58e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
59e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherint ipq_destroy_handle(struct ipq_handle *h);
60e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
61e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherssize_t ipq_read(const struct ipq_handle *h,
62e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher                unsigned char *buf, size_t len, int timeout);
63e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
64e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherint ipq_set_mode(const struct ipq_handle *h, u_int8_t mode, size_t len);
65e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
66e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucheripq_packet_msg_t *ipq_get_packet(const unsigned char *buf);
67e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
68e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherint ipq_message_type(const unsigned char *buf);
69e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
70e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherint ipq_get_msgerr(const unsigned char *buf);
71e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
72e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherint ipq_set_verdict(const struct ipq_handle *h,
73803f33c0e9cb458cf7989f3826e9baba8da19e2fRusty Russell                    ipq_id_t id,
74e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher                    unsigned int verdict,
75e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher                    size_t data_len,
76e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher                    unsigned char *buf);
77e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
78e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucherint ipq_ctl(const struct ipq_handle *h, int request, ...);
79e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
80e6869a8f59d779ff4d5a0984c86d80db7078496Marc Bouchervoid ipq_perror(const char *s);
81e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
82e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher#endif	/* _LIBIPQ_H */
83e6869a8f59d779ff4d5a0984c86d80db7078496Marc Boucher
84