Functions

Conntrack object handling

Functions

struct nf_conntrack * nfct_new (void)
void nfct_destroy (struct nf_conntrack *ct)
size_t nfct_sizeof (const struct nf_conntrack *ct)
size_t nfct_maxsize (void)
struct nf_conntrack * nfct_clone (const struct nf_conntrack *ct)
int nfct_setobjopt (struct nf_conntrack *ct, unsigned int option)
int nfct_getobjopt (const struct nf_conntrack *ct, unsigned int option)
void nfct_set_attr (struct nf_conntrack *ct, const enum nf_conntrack_attr type, const void *value)
void nfct_set_attr_u8 (struct nf_conntrack *ct, const enum nf_conntrack_attr type, u_int8_t value)
void nfct_set_attr_u16 (struct nf_conntrack *ct, const enum nf_conntrack_attr type, u_int16_t value)
void nfct_set_attr_u32 (struct nf_conntrack *ct, const enum nf_conntrack_attr type, u_int32_t value)
void nfct_set_attr_u64 (struct nf_conntrack *ct, const enum nf_conntrack_attr type, u_int64_t value)
const void * nfct_get_attr (const struct nf_conntrack *ct, const enum nf_conntrack_attr type)
u_int8_t nfct_get_attr_u8 (const struct nf_conntrack *ct, const enum nf_conntrack_attr type)
u_int16_t nfct_get_attr_u16 (const struct nf_conntrack *ct, const enum nf_conntrack_attr type)
u_int32_t nfct_get_attr_u32 (const struct nf_conntrack *ct, const enum nf_conntrack_attr type)
u_int64_t nfct_get_attr_u64 (const struct nf_conntrack *ct, const enum nf_conntrack_attr type)
int nfct_attr_is_set (const struct nf_conntrack *ct, const enum nf_conntrack_attr type)
int nfct_attr_is_set_array (const struct nf_conntrack *ct, const enum nf_conntrack_attr *type_array, int size)
int nfct_attr_unset (struct nf_conntrack *ct, const enum nf_conntrack_attr type)
void nfct_set_attr_grp (struct nf_conntrack *ct, const enum nf_conntrack_attr_grp type, const void *data)
int nfct_get_attr_grp (const struct nf_conntrack *ct, const enum nf_conntrack_attr_grp type, void *data)
int nfct_attr_grp_is_set (const struct nf_conntrack *ct, const enum nf_conntrack_attr_grp type)
int nfct_attr_grp_unset (struct nf_conntrack *ct, const enum nf_conntrack_attr_grp type)
int nfct_snprintf (char *buf, unsigned int size, const struct nf_conntrack *ct, unsigned int msg_type, unsigned int out_type, unsigned int flags)

Function Documentation

int nfct_attr_grp_is_set ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr_grp  type 
)

nfct_attr_grp_is_set - check if an attribute group is set

Parameters:
ct pointer to a valid conntrack object
type attribute group (see ATTR_GRP_*)

If the attribute group is set, this function returns 1, otherwise 0.

Definition at line 650 of file conntrack/api.c.

int nfct_attr_grp_unset ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr_grp  type 
)

nfct_attr_grp_unset - unset an attribute group

Parameters:
ct pointer to a valid conntrack object
type attribute group (see ATTR_GRP_*)

On error, it returns -1 and errno is appropriately set. On success, this function returns 0.

Definition at line 670 of file conntrack/api.c.

int nfct_attr_is_set ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_attr_is_set - check if a certain attribute is set

Parameters:
ct pointer to a valid conntrack object
type attribute type

On error, -1 is returned and errno is set appropiately, otherwise the value of the attribute is returned.

Definition at line 529 of file conntrack/api.c.

int nfct_attr_is_set_array ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr *  type_array,
int  size 
)

nfct_attr_is_set_array - check if an array of attribute types is set

Parameters:
ct pointer to a valid conntrack object
array attribute type array
size size of the array

On error, -1 is returned and errno is set appropiately, otherwise the value of the attribute is returned.

Definition at line 550 of file conntrack/api.c.

int nfct_attr_unset ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_attr_unset - unset a certain attribute

Parameters:
type attribute type
ct pointer to a valid conntrack object

On error, -1 is returned and errno is set appropiately, otherwise 0 is returned.

Definition at line 577 of file conntrack/api.c.

struct nf_conntrack* nfct_clone ( const struct nf_conntrack *  ct  )  [read]

nfct_clone - clone a conntrack object

Parameters:
ct pointer to a valid conntrack object

On error, NULL is returned and errno is appropiately set. Otherwise, a valid pointer to the clone conntrack is returned.

Definition at line 134 of file conntrack/api.c.

void nfct_destroy ( struct nf_conntrack *  ct  ) 

nf_conntrack_destroy - release a conntrack object

Parameters:
ct pointer to the conntrack object

Definition at line 89 of file conntrack/api.c.

const void* nfct_get_attr ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_get_attr - get a conntrack attribute

Parameters:
ct pointer to a valid conntrack
type attribute type

In case of success a valid pointer to the attribute requested is returned, on error NULL is returned and errno is set appropiately.

Definition at line 437 of file conntrack/api.c.

int nfct_get_attr_grp ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr_grp  type,
void *  data 
)

nfct_get_attr_grp - get an attribute group

Parameters:
ct pointer to a valid conntrack object
type attribute group (see ATTR_GRP_*)
data pointer to struct (see struct nfct_attr_grp_*)

On error, it returns -1 and errno is appropriately set. On success, the data pointer contains the attribute group.

Definition at line 624 of file conntrack/api.c.

u_int16_t nfct_get_attr_u16 ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_get_attr_u16 - get attribute of unsigned 16-bits long

Parameters:
ct pointer to a valid conntrack
type attribute type

Returns the value of the requested attribute, if the attribute is not set, 0 is returned. In order to check if the attribute is set or not, use nfct_attr_is_set.

Definition at line 482 of file conntrack/api.c.

u_int32_t nfct_get_attr_u32 ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_get_attr_u32 - get attribute of unsigned 32-bits long

Parameters:
ct pointer to a valid conntrack
type attribute type

Returns the value of the requested attribute, if the attribute is not set, 0 is returned. In order to check if the attribute is set or not, use nfct_attr_is_set.

Definition at line 498 of file conntrack/api.c.

u_int64_t nfct_get_attr_u64 ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_get_attr_u64 - get attribute of unsigned 32-bits long

Parameters:
ct pointer to a valid conntrack
type attribute type

Returns the value of the requested attribute, if the attribute is not set, 0 is returned. In order to check if the attribute is set or not, use nfct_attr_is_set.

Definition at line 514 of file conntrack/api.c.

u_int8_t nfct_get_attr_u8 ( const struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type 
)

nfct_get_attr_u8 - get attribute of unsigned 8-bits long

Parameters:
ct pointer to a valid conntrack
type attribute type

Returns the value of the requested attribute, if the attribute is not set, 0 is returned. In order to check if the attribute is set or not, use nfct_attr_is_set.

Definition at line 466 of file conntrack/api.c.

int nfct_getobjopt ( const struct nf_conntrack *  ct,
unsigned int  option 
)

nfct_getobjopt - get a certain option for a conntrack object

Parameters:
ct conntrack object
option option parameter

In case of error, -1 is returned and errno is appropiately set. On success, 0 is returned.

Definition at line 175 of file conntrack/api.c.

size_t nfct_maxsize ( void   ) 

nfct_maxsize - return the maximum size in bytes of a conntrack object

Use this function if you want to allocate a conntrack object in the stack instead of the heap. For example:

	char buf[nfct_maxsize()];
	struct nf_conntrack *ct = (struct nf_conntrack *) buf;
	memset(ct, 0, nfct_maxsize());

Note: As for now this function returns the same size that nfct_sizeof(ct) does although _this could change in the future_. Therefore, do not assume that nfct_sizeof(ct) == nfct_maxsize().

Definition at line 122 of file conntrack/api.c.

struct nf_conntrack* nfct_new ( void   )  [read]

nfct_conntrack_new - allocate a new conntrack

In case of success, this function returns a valid pointer to a memory blob, otherwise NULL is returned and errno is set appropiately.

Definition at line 72 of file conntrack/api.c.

void nfct_set_attr ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type,
const void *  value 
)

nfct_set_attr - set the value of a certain conntrack attribute

Parameters:
ct pointer to a valid conntrack
type attribute type
value pointer to the attribute value

Note that certain attributes are unsettable:

  • ATTR_USE
  • ATTR_ID
  • ATTR_*_COUNTER_*
  • ATTR_SECCTX The call of this function for such attributes do nothing.

Definition at line 361 of file conntrack/api.c.

void nfct_set_attr_grp ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr_grp  type,
const void *  data 
)

nfct_set_attr_grp - set a group of attributes

Parameters:
ct pointer to a valid conntrack object
type attribute group (see ATTR_GRP_*)
data pointer to struct (see struct nfct_attr_grp_*)

Note that calling this function for ATTR_GRP_COUNTER_* does nothing since counters are unsettable.

Definition at line 600 of file conntrack/api.c.

void nfct_set_attr_u16 ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type,
u_int16_t  value 
)

nfct_set_attr_u16 - set the value of a certain conntrack attribute

Parameters:
ct pointer to a valid conntrack
type attribute type
value unsigned 16 bits attribute value

Definition at line 396 of file conntrack/api.c.

void nfct_set_attr_u32 ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type,
u_int32_t  value 
)

nfct_set_attr_u32 - set the value of a certain conntrack attribute

Parameters:
ct pointer to a valid conntrack
type attribute type
value unsigned 32 bits attribute value

Definition at line 409 of file conntrack/api.c.

void nfct_set_attr_u64 ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type,
u_int64_t  value 
)

nfct_set_attr_u64 - set the value of a certain conntrack attribute

Parameters:
ct pointer to a valid conntrack
type attribute type
value unsigned 64 bits attribute value

Definition at line 422 of file conntrack/api.c.

void nfct_set_attr_u8 ( struct nf_conntrack *  ct,
const enum nf_conntrack_attr  type,
u_int8_t  value 
)

nfct_set_attr_u8 - set the value of a certain conntrack attribute

Parameters:
ct pointer to a valid conntrack
type attribute type
value unsigned 8 bits attribute value

Definition at line 383 of file conntrack/api.c.

int nfct_setobjopt ( struct nf_conntrack *  ct,
unsigned int  option 
)

nfct_setobjopt - set a certain option for a conntrack object

Parameters:
ct conntrack object
option option parameter

In case of error, -1 is returned and errno is appropiately set. On success, 0 is returned.

Definition at line 155 of file conntrack/api.c.

size_t nfct_sizeof ( const struct nf_conntrack *  ct  ) 

nf_sizeof - return the size in bytes of a certain conntrack object

Parameters:
ct pointer to the conntrack object

Definition at line 102 of file conntrack/api.c.

int nfct_snprintf ( char *  buf,
unsigned int  size,
const struct nf_conntrack *  ct,
unsigned int  msg_type,
unsigned int  out_type,
unsigned int  flags 
)

nfct_snprintf - print a conntrack object to a buffer

Parameters:
buf buffer used to build the printable conntrack
size size of the buffer
ct pointer to a valid conntrack object
message_type print message type (NFCT_T_UNKNOWN, NFCT_T_NEW,...)
output_type print type (NFCT_O_DEFAULT, NFCT_O_XML, ...)
flags extra flags for the output type (NFCT_OF_LAYER3)

If you are listening to events, probably you want to display the message type as well. In that case, set the message type parameter to any of the known existing types, ie. NFCT_T_NEW, NFCT_T_UPDATE, NFCT_T_DESTROY. If you pass NFCT_T_UNKNOWN, the message type will not be output.

Currently, the output available are:

  • NFCT_O_DEFAULT: default /proc-like output
  • NFCT_O_XML: XML output

The output flags are:

  • NFCT_OF_SHOW_LAYER3: include layer 3 information in the output, this is *only* required by NFCT_O_DEFAULT.
  • NFCT_OF_TIME: display time.

This function returns the size of the information that _would_ have been written to the buffer, even if there was no room for it. Thus, the behaviour is similar to snprintf.

Definition at line 979 of file conntrack/api.c.