netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
session.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <libipset/linux_ip_set.h>
Include dependency graph for session.h:
This graph shows which files directly or indirectly include this file:

Macros

#define IPSET_ERRORBUFLEN   1024
 
#define IPSET_OUTBUFLEN   8192
 
#define ipset_err(session, fmt, args...)   ipset_session_report(session, IPSET_ERROR, fmt , ## args)
 
#define ipset_warn(session, fmt, args...)   ipset_session_report(session, IPSET_WARNING, fmt , ## args)
 
#define ipset_errptr(session, fmt, args...)
 
#define ipset_session_data_set(session, opt, value)   ipset_data_set(ipset_session_data(session), opt, value)
 
#define ipset_session_data_get(session, opt)   ipset_data_get(ipset_session_data(session), opt)
 

Typedefs

typedef int(* ipset_outfn )(const char *fmt,...) __attribute__((format(printf
 
typedef int(*) in ipset_session_outfn )(struct ipset_session *session, ipset_outfn outfn)
 

Enumerations

enum  ipset_err_type {
  IPSET_ERROR,
  IPSET_WARNING
}
 
enum  ipset_envopt {
  IPSET_ENV_BIT_SORTED = 0,
  IPSET_ENV_SORTED = (1 << IPSET_ENV_BIT_SORTED),
  IPSET_ENV_BIT_QUIET = 1,
  IPSET_ENV_QUIET = (1 << IPSET_ENV_BIT_QUIET),
  IPSET_ENV_BIT_RESOLVE = 2,
  IPSET_ENV_RESOLVE = (1 << IPSET_ENV_BIT_RESOLVE),
  IPSET_ENV_BIT_EXIST = 3,
  IPSET_ENV_EXIST = (1 << IPSET_ENV_BIT_EXIST),
  IPSET_ENV_BIT_LIST_SETNAME = 4,
  IPSET_ENV_LIST_SETNAME = (1 << IPSET_ENV_BIT_LIST_SETNAME),
  IPSET_ENV_BIT_LIST_HEADER = 5,
  IPSET_ENV_LIST_HEADER = (1 << IPSET_ENV_BIT_LIST_HEADER)
}
 
enum  ipset_output_mode {
  IPSET_LIST_NONE,
  IPSET_LIST_PLAIN,
  IPSET_LIST_SAVE,
  IPSET_LIST_XML
}
 

Functions

struct ipset_dataipset_session_data (const struct ipset_session *session)
 ipset_session_data - return pointer to the data : session structure More...
 
struct ipset_handleipset_session_handle (const struct ipset_session *session)
 ipset_session_handle - return pointer to the handle : session structure More...
 
const struct ipset_typeipset_saved_type (const struct ipset_session *session)
 ipset_saved_type - return pointer to the saved type : session structure More...
 
void ipset_session_lineno (struct ipset_session *session, uint32_t lineno)
 ipset_session_lineno - set session lineno : session structure More...
 
int ipset_session_report (struct ipset_session *session, enum ipset_err_type type, const char *fmt,...)
 
void ipset_session_report_reset (struct ipset_session *session)
 ipset_session_reset - reset the report buffer : session structure More...
 
const char * ipset_session_error (const struct ipset_session *session)
 ipset_session_error - return the report buffer as error : session structure More...
 
const char * ipset_session_warning (const struct ipset_session *session)
 ipset_session_warning - return the report buffer as warning : session structure More...
 
int ipset_envopt_parse (struct ipset_session *session, int env, const char *str)
 
bool ipset_envopt_test (struct ipset_session *session, enum ipset_envopt env)
 ipset_envopt_test - test environment option : session structure : environment option More...
 
int ipset_session_output (struct ipset_session *session, enum ipset_output_mode mode)
 ipset_session_output - set the session output mode : session structure : output mode More...
 
int ipset_commit (struct ipset_session *session)
 ipset_commit - commit buffered commands : session structure More...
 
int ipset_cmd (struct ipset_session *session, enum ipset_cmd cmd, uint32_t lineno)
 ipset_cmd - execute a command : session structure : command to execute : command line number in restore mode More...
 
struct ipset_sessionipset_session_init (ipset_outfn outfn)
 ipset_session_init - initialize an ipset session More...
 
int ipset_session_fini (struct ipset_session *session)
 ipset_session_fini - destroy an ipset session : session structure More...
 
void ipset_debug_msg (const char *dir, void *buffer, int len)
 

Macro Definition Documentation

#define ipset_err (   session,
  fmt,
  args... 
)    ipset_session_report(session, IPSET_ERROR, fmt , ## args)
#define IPSET_ERRORBUFLEN   1024

Referenced by __attribute__().

#define ipset_errptr (   session,
  fmt,
  args... 
)
Value:
({ \
ipset_session_report(session, IPSET_ERROR, fmt , ## args); \
})
#define NULL
Definition: linux_stddef.h:8
Definition: session.h:34
int ipset_session_report(struct ipset_session *session, enum ipset_err_type type, const char *fmt,...)

Referenced by ipset_type_check().

#define IPSET_OUTBUFLEN   8192
#define ipset_session_data_get (   session,
  opt 
)    ipset_data_get(ipset_session_data(session), opt)

Referenced by ipset_parse_elem().

#define ipset_warn (   session,
  fmt,
  args... 
)    ipset_session_report(session, IPSET_WARNING, fmt , ## args)

Referenced by ipset_parse_ignored().

Typedef Documentation

typedef int(* ipset_outfn)(const char *fmt,...) __attribute__((format(printf
typedef int(*) in ipset_session_outfn)(struct ipset_session *session, ipset_outfn outfn)

Enumeration Type Documentation

Enumerator
IPSET_ENV_BIT_SORTED 
IPSET_ENV_SORTED 
IPSET_ENV_BIT_QUIET 
IPSET_ENV_QUIET 
IPSET_ENV_BIT_RESOLVE 
IPSET_ENV_RESOLVE 
IPSET_ENV_BIT_EXIST 
IPSET_ENV_EXIST 
IPSET_ENV_BIT_LIST_SETNAME 
IPSET_ENV_LIST_SETNAME 
IPSET_ENV_BIT_LIST_HEADER 
IPSET_ENV_LIST_HEADER 
Enumerator
IPSET_ERROR 
IPSET_WARNING 
Enumerator
IPSET_LIST_NONE 
IPSET_LIST_PLAIN 
IPSET_LIST_SAVE 
IPSET_LIST_XML 

Function Documentation

int ipset_cmd ( struct ipset_session session,
enum ipset_cmd  cmd,
uint32_t  lineno 
)

ipset_cmd - execute a command : session structure : command to execute : command line number in restore mode

Execute - or prepare/buffer in restore mode - a command. It is the caller responsibility that the data field be filled out with all required parameters for a successful execution. The data field is cleared after this function call for the public commands.

Returns 0 on success or a negative error code.

References ipset_session::cmd, D, ipset_session::data, data, ipset_session::handle, IPSET_CMD_ADD, IPSET_CMD_DEL, IPSET_CMD_HEADER, IPSET_CMD_LIST, IPSET_CMD_PROTOCOL, IPSET_CMD_SAVE, IPSET_CMD_TYPE, ipset_commit(), ipset_data_get(), ipset_data_reset(), ipset_data_setname(), ipset_err, IPSET_LIST_NONE, IPSET_LIST_PLAIN, IPSET_LIST_SAVE, IPSET_LIST_XML, IPSET_MSG_MAX, IPSET_OPT_TYPE, ipset_session::lineno, lineno, ipset_session::mode, NULL, ipset_session::saved_setname, ipset_session::saved_type, and ipset_session::version_checked.

Here is the call graph for this function:

int ipset_commit ( struct ipset_session session)

ipset_commit - commit buffered commands : session structure

Commit buffered commands, if there are any.

Returns 0 on success or a negative error code.

References ipset_session::buffer, ipset_session::bufsize, ipset_session::cmd, D, ipset_session::handle, ipset_err, ipset_session::nested, ipset_session::nestid, nlh, nlmsghdr::nlmsg_len, NULL, ipset_session::printed_set, ipset_transport::query, ipset_session::report, ipset_session::saved_setname, and ipset_session::transport.

Referenced by ipset_cmd().

Here is the caller graph for this function:

int ipset_envopt_parse ( struct ipset_session session,
int  env,
const char *  str 
)

Referenced by parse_commandline().

Here is the caller graph for this function:

bool ipset_envopt_test ( struct ipset_session session,
enum ipset_envopt  opt 
)

ipset_envopt_test - test environment option : session structure : environment option

Test whether the environment option is set in the session.

Returns true or false.

References ipset_session::envopts, and opt.

Referenced by parse_commandline().

Here is the caller graph for this function:

const struct ipset_type* ipset_saved_type ( const struct ipset_session session)

ipset_saved_type - return pointer to the saved type : session structure

Returns the pointer to the saved type from the last ipset_cmd It is required to decode type-specific error codes in restore mode.

References ipset_session::saved_type.

Referenced by ipset_errcode().

Here is the caller graph for this function:

const char* ipset_session_error ( const struct ipset_session session)

ipset_session_error - return the report buffer as error : session structure

Return the pointer to the report buffer as an error report. If there is no error message in the buffer, NULL returned.

References ipset_session::errmsg.

int ipset_session_fini ( struct ipset_session session)

ipset_session_fini - destroy an ipset session : session structure

Destroy an ipset session: release the created structures.

Returns 0 on success or a negative error code.

References ipset_session::data, ipset_transport::fini, ipset_session::handle, ipset_cache_fini(), ipset_data_fini(), and ipset_session::transport.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

struct ipset_handle* ipset_session_handle ( const struct ipset_session session)

ipset_session_handle - return pointer to the handle : session structure

Returns the pointer to the transport handle structure of the session.

References ipset_session::handle.

struct ipset_session* ipset_session_init ( ipset_outfn  outfn)

ipset_session_init - initialize an ipset session

Initialize an ipset session by allocating a session structure and filling out with the initialization data.

Returns the created session sctructure on success or NULL.

References ipset_session::buffer, ipset_session::bufsize, ipset_session::data, ipset_cache_init(), ipset_data_init(), ipset_mnl_transport, NULL, ipset_session::outfn, and ipset_session::transport.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void ipset_session_lineno ( struct ipset_session session,
uint32_t  lineno 
)

ipset_session_lineno - set session lineno : session structure

Set session lineno to report parser errors correctly.

References ipset_session::lineno, and lineno.

Referenced by parse_commandline().

Here is the caller graph for this function:

int ipset_session_output ( struct ipset_session session,
enum ipset_output_mode  mode 
)

ipset_session_output - set the session output mode : session structure : output mode

Set the output mode for the session.

Returns 0 on success or a negative error code.

References ipset_session::mode.

Referenced by ipset_parse_output().

Here is the caller graph for this function:

int ipset_session_report ( struct ipset_session session,
enum ipset_err_type  type,
const char *  fmt,
  ... 
)
void ipset_session_report_reset ( struct ipset_session session)

ipset_session_reset - reset the report buffer : session structure

Reset the report buffer, the error and warning pointers.

References ipset_session::errmsg, NULL, ipset_session::report, and ipset_session::warnmsg.

Referenced by ipset_parse_mark(), ipset_parse_port(), and parse_commandline().

Here is the caller graph for this function:

const char* ipset_session_warning ( const struct ipset_session session)

ipset_session_warning - return the report buffer as warning : session structure

Return the pointer to the report buffer as a warning report. If there is no warning message in the buffer, NULL returned.

References ipset_session::warnmsg.

Referenced by parse_commandline().

Here is the caller graph for this function: