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