netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
session.c File Reference
#include <assert.h>
#include <endian.h>
#include <errno.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <libipset/compat.h>
#include <libipset/debug.h>
#include <libipset/data.h>
#include <libipset/errcode.h>
#include <libipset/print.h>
#include <libipset/types.h>
#include <libipset/transport.h>
#include <libipset/mnl.h>
#include <libipset/utils.h>
#include <libipset/ui.h>
#include <libipset/session.h>
Include dependency graph for session.c:

Data Structures

struct  ipset_session
 
struct  ipset_attr_policy
 

Macros

#define IPSET_NEST_MAX   4
 
#define FAILURE(format, args...)   { ipset_err(session, format , ## args); return MNL_CB_ERROR; }
 
#define ATTR2DATA(session, nla, type, attrs)
 
#define FAMILY_TO_STR(f)
 
#define IPSET_PROTOCOL_MIN   IPSET_PROTOCOL
 
#define IPSET_PROTOCOL_MAX   IPSET_PROTOCOL
 
#define BUFFER_FULL(bufsize, nlmsg_len, nestlen, attrlen)
 
#define ADDATTR_PROTOCOL(nlh)   mnl_attr_put_u8(nlh, IPSET_ATTR_PROTOCOL, IPSET_PROTOCOL)
 
#define ADDATTR(session, nlh, data, type, family, attrs)   data2attr(session, nlh, data, type, family, attrs)
 
#define ADDATTR_SETNAME(session, nlh, data)
 
#define ADDATTR_IF(session, nlh, data, type, family, attrs)
 
#define ADDATTR_RAW(session, nlh, data, type, attrs)   rawdata2attr(session, nlh, data, type, NFPROTO_IPV4, attrs)
 
#define PRIVATE_MSG_BUFLEN   256
 

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_envopt_parse (struct ipset_session *session, int opt, const char *arg UNUSED)
 ipset_envopt_parse - parse/set environment option : session structure : environment option More...
 
bool ipset_envopt_test (struct ipset_session *session, enum ipset_envopt opt)
 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 __attribute__ ((format(printf, 3, 4)))
 ipset_session_report - fill the report buffer : session structure : report type : message format More...
 
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_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...
 
int ipset_session_outfn (struct ipset_session *session, ipset_outfn outfn)
 ipset_session_outfn - set session output printing function 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...
 

Macro Definition Documentation

#define ADDATTR (   session,
  nlh,
  data,
  type,
  family,
  attrs 
)    data2attr(session, nlh, data, type, family, attrs)
#define ADDATTR_IF (   session,
  nlh,
  data,
  type,
  family,
  attrs 
)
Value:
ipset_data_test(data, attrs[type].opt) ? \
data2attr(session, nlh, data, type, family, attrs) : 0
static int const struct sk_buff const struct xt_action_param enum ipset_adt adt struct ip_set_adt_opt * opt
Definition: ip_set_hash_gen.h:1153
struct expr
u8 family
Definition: ip_set.h:140
enum nf_conntrack_query query const void * data
Definition: libnetfilter_conntrack.h:570
const struct nlmsghdr * nlh
Definition: libnetfilter_conntrack.h:565
#define ADDATTR_PROTOCOL (   nlh)    mnl_attr_put_u8(nlh, IPSET_ATTR_PROTOCOL, IPSET_PROTOCOL)
#define ADDATTR_RAW (   session,
  nlh,
  data,
  type,
  attrs 
)    rawdata2attr(session, nlh, data, type, NFPROTO_IPV4, attrs)
#define ADDATTR_SETNAME (   session,
  nlh,
  data 
)
Value:
data2attr(session, nlh, data, IPSET_ATTR_SETNAME, NFPROTO_IPV4, \
cmd_attrs)
Definition: nfproto.h:11
Definition: linux_ip_set.h:58
enum nf_conntrack_query query const void * data
Definition: libnetfilter_conntrack.h:570
const struct nlmsghdr * nlh
Definition: libnetfilter_conntrack.h:565
#define ATTR2DATA (   session,
  nla,
  type,
  attrs 
)
Value:
if (attr2data(session, nla, type, attrs) < 0) \
return MNL_CB_ERROR
#define MNL_CB_ERROR
Definition: libmnl.h:170
struct expr
#define BUFFER_FULL (   bufsize,
  nlmsg_len,
  nestlen,
  attrlen 
)
Value:
(nlmsg_len + nestlen + MNL_ATTR_HDRLEN + MNL_ALIGN(alen) + \
MNL_ALIGN(sizeof(struct nlmsgerr)) > bufsize)
#define MNL_ATTR_HDRLEN
Definition: libmnl.h:82
Netlink error message.
Definition: netlink.h:98
#define MNL_ALIGN(len)
Definition: libmnl.h:40
int nlmsg_len(const struct nlmsghdr *)
length of message payload
Definition: msg.c:232
#define FAILURE (   format,
  args... 
)    { ipset_err(session, format , ## args); return MNL_CB_ERROR; }
#define FAMILY_TO_STR (   f)
Value:
((f) == NFPROTO_IPV4 ? "inet" : \
(f) == NFPROTO_IPV6 ? "inet6" : "any")
Definition: nfproto.h:11
Definition: nfproto.h:14
#define IPSET_NEST_MAX   4
#define IPSET_PROTOCOL_MAX   IPSET_PROTOCOL
#define IPSET_PROTOCOL_MIN   IPSET_PROTOCOL
#define PRIVATE_MSG_BUFLEN   256

Function Documentation

int __attribute__ ( (format(printf, 3, 4))  )

ipset_session_report - fill the report buffer : session structure : report type : message format

Fill the report buffer with an error or warning message. Depending on the report type, set the error or warning message pointer.

Returns -1.

References ipset_type::args, IPSET_ERROR, IPSET_ERRORBUFLEN, len, and NULL.

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  opt,
const char *arg  UNUSED 
)

ipset_envopt_parse - parse/set environment option : session structure : environment option

  • : option argument (unused)

Parse and set an environment option.

Returns 0 on success or a negative error code.

References ipset_session::envopts, IPSET_ENV_EXIST, IPSET_ENV_LIST_HEADER, IPSET_ENV_LIST_SETNAME, IPSET_ENV_QUIET, IPSET_ENV_RESOLVE, IPSET_ENV_SORTED, and opt.

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_outfn ( struct ipset_session session,
ipset_outfn  outfn 
)

ipset_session_outfn - set session output printing function

Set the session printing function.

References ipset_session::outfn.

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:

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: