Blame include/libiptc/libiptc.h

Packit Service 3880ab
/* SPDX-License-Identifier: GPL-2.0 */
Packit Service 3880ab
#ifndef _LIBIPTC_H
Packit Service 3880ab
#define _LIBIPTC_H
Packit Service 3880ab
/* Library which manipulates filtering rules. */
Packit Service 3880ab
Packit Service 3880ab
#include <linux/types.h>
Packit Service 3880ab
#include <libiptc/ipt_kernel_headers.h>
Packit Service 3880ab
#ifdef __cplusplus
Packit Service 3880ab
#	include <climits>
Packit Service 3880ab
#else
Packit Service 3880ab
#	include <limits.h> /* INT_MAX in ip_tables.h */
Packit Service 3880ab
#endif
Packit Service 3880ab
#include <linux/netfilter_ipv4/ip_tables.h>
Packit Service 3880ab
#include <libiptc/xtcshared.h>
Packit Service 3880ab
Packit Service 3880ab
#ifdef __cplusplus
Packit Service 3880ab
extern "C" {
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
#define iptc_handle xtc_handle
Packit Service 3880ab
#define ipt_chainlabel xt_chainlabel
Packit Service 3880ab
Packit Service 3880ab
#define IPTC_LABEL_ACCEPT  "ACCEPT"
Packit Service 3880ab
#define IPTC_LABEL_DROP    "DROP"
Packit Service 3880ab
#define IPTC_LABEL_QUEUE   "QUEUE"
Packit Service 3880ab
#define IPTC_LABEL_RETURN  "RETURN"
Packit Service 3880ab
Packit Service 3880ab
/* Does this chain exist? */
Packit Service 3880ab
int iptc_is_chain(const char *chain, struct xtc_handle *const handle);
Packit Service 3880ab
Packit Service 3880ab
/* Take a snapshot of the rules.  Returns NULL on error. */
Packit Service 3880ab
struct xtc_handle *iptc_init(const char *tablename);
Packit Service 3880ab
Packit Service 3880ab
/* Cleanup after iptc_init(). */
Packit Service 3880ab
void iptc_free(struct xtc_handle *h);
Packit Service 3880ab
Packit Service 3880ab
/* Iterator functions to run through the chains.  Returns NULL at end. */
Packit Service 3880ab
const char *iptc_first_chain(struct xtc_handle *handle);
Packit Service 3880ab
const char *iptc_next_chain(struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Get first rule in the given chain: NULL for empty chain. */
Packit Service 3880ab
const struct ipt_entry *iptc_first_rule(const char *chain,
Packit Service 3880ab
					struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Returns NULL when rules run out. */
Packit Service 3880ab
const struct ipt_entry *iptc_next_rule(const struct ipt_entry *prev,
Packit Service 3880ab
				       struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Returns a pointer to the target name of this entry. */
Packit Service 3880ab
const char *iptc_get_target(const struct ipt_entry *e,
Packit Service 3880ab
			    struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Is this a built-in chain? */
Packit Service 3880ab
int iptc_builtin(const char *chain, struct xtc_handle *const handle);
Packit Service 3880ab
Packit Service 3880ab
/* Get the policy of a given built-in chain */
Packit Service 3880ab
const char *iptc_get_policy(const char *chain,
Packit Service 3880ab
			    struct xt_counters *counter,
Packit Service 3880ab
			    struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* These functions return TRUE for OK or 0 and set errno.  If errno ==
Packit Service 3880ab
   0, it means there was a version error (ie. upgrade libiptc). */
Packit Service 3880ab
/* Rule numbers start at 1 for the first rule. */
Packit Service 3880ab
Packit Service 3880ab
/* Insert the entry `e' in chain `chain' into position `rulenum'. */
Packit Service 3880ab
int iptc_insert_entry(const xt_chainlabel chain,
Packit Service 3880ab
		      const struct ipt_entry *e,
Packit Service 3880ab
		      unsigned int rulenum,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Atomically replace rule `rulenum' in `chain' with `e'. */
Packit Service 3880ab
int iptc_replace_entry(const xt_chainlabel chain,
Packit Service 3880ab
		       const struct ipt_entry *e,
Packit Service 3880ab
		       unsigned int rulenum,
Packit Service 3880ab
		       struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Append entry `e' to chain `chain'.  Equivalent to insert with
Packit Service 3880ab
   rulenum = length of chain. */
Packit Service 3880ab
int iptc_append_entry(const xt_chainlabel chain,
Packit Service 3880ab
		      const struct ipt_entry *e,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Check whether a mathching rule exists */
Packit Service 3880ab
int iptc_check_entry(const xt_chainlabel chain,
Packit Service 3880ab
		      const struct ipt_entry *origfw,
Packit Service 3880ab
		      unsigned char *matchmask,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Delete the first rule in `chain' which matches `e', subject to
Packit Service 3880ab
   matchmask (array of length == origfw) */
Packit Service 3880ab
int iptc_delete_entry(const xt_chainlabel chain,
Packit Service 3880ab
		      const struct ipt_entry *origfw,
Packit Service 3880ab
		      unsigned char *matchmask,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Delete the rule in position `rulenum' in `chain'. */
Packit Service 3880ab
int iptc_delete_num_entry(const xt_chainlabel chain,
Packit Service 3880ab
			  unsigned int rulenum,
Packit Service 3880ab
			  struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Check the packet `e' on chain `chain'.  Returns the verdict, or
Packit Service 3880ab
   NULL and sets errno. */
Packit Service 3880ab
const char *iptc_check_packet(const xt_chainlabel chain,
Packit Service 3880ab
			      struct ipt_entry *entry,
Packit Service 3880ab
			      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Flushes the entries in the given chain (ie. empties chain). */
Packit Service 3880ab
int iptc_flush_entries(const xt_chainlabel chain,
Packit Service 3880ab
		       struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Zeroes the counters in a chain. */
Packit Service 3880ab
int iptc_zero_entries(const xt_chainlabel chain,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Creates a new chain. */
Packit Service 3880ab
int iptc_create_chain(const xt_chainlabel chain,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Deletes a chain. */
Packit Service 3880ab
int iptc_delete_chain(const xt_chainlabel chain,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Renames a chain. */
Packit Service 3880ab
int iptc_rename_chain(const xt_chainlabel oldname,
Packit Service 3880ab
		      const xt_chainlabel newname,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Sets the policy on a built-in chain. */
Packit Service 3880ab
int iptc_set_policy(const xt_chainlabel chain,
Packit Service 3880ab
		    const xt_chainlabel policy,
Packit Service 3880ab
		    struct xt_counters *counters,
Packit Service 3880ab
		    struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Get the number of references to this chain */
Packit Service 3880ab
int iptc_get_references(unsigned int *ref,
Packit Service 3880ab
			const xt_chainlabel chain,
Packit Service 3880ab
			struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* read packet and byte counters for a specific rule */
Packit Service 3880ab
struct xt_counters *iptc_read_counter(const xt_chainlabel chain,
Packit Service 3880ab
				       unsigned int rulenum,
Packit Service 3880ab
				       struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* zero packet and byte counters for a specific rule */
Packit Service 3880ab
int iptc_zero_counter(const xt_chainlabel chain,
Packit Service 3880ab
		      unsigned int rulenum,
Packit Service 3880ab
		      struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* set packet and byte counters for a specific rule */
Packit Service 3880ab
int iptc_set_counter(const xt_chainlabel chain,
Packit Service 3880ab
		     unsigned int rulenum,
Packit Service 3880ab
		     struct xt_counters *counters,
Packit Service 3880ab
		     struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Makes the actual changes. */
Packit Service 3880ab
int iptc_commit(struct xtc_handle *handle);
Packit Service 3880ab
Packit Service 3880ab
/* Get raw socket. */
Packit Service 3880ab
int iptc_get_raw_socket(void);
Packit Service 3880ab
Packit Service 3880ab
/* Translates errno numbers into more human-readable form than strerror. */
Packit Service 3880ab
const char *iptc_strerror(int err);
Packit Service 3880ab
Packit Service 3880ab
extern void dump_entries(struct xtc_handle *const);
Packit Service 3880ab
Packit Service 3880ab
extern const struct xtc_ops iptc_ops;
Packit Service 3880ab
Packit Service 3880ab
#ifdef __cplusplus
Packit Service 3880ab
}
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
#endif /* _LIBIPTC_H */