libnl 1.1.4
Macros | Functions

Macros

#define NFNLMSG_CT_TYPE(type)   NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, (type))
 

Functions

int nfnlmsg_ct_group (struct nlmsghdr *nlh)
 
struct nfnl_ct * nfnlmsg_ct_parse (struct nlmsghdr *nlh)
 
int nfnl_ct_dump_request (struct nl_handle *h)
 

Cache Management

struct nl_cache * nfnl_ct_alloc_cache (struct nl_handle *handle)
 Build a conntrack cache holding all conntrack currently in the kernel.
 

Detailed Description

Macro Definition Documentation

◆ NFNLMSG_CT_TYPE

#define NFNLMSG_CT_TYPE (   type)    NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, (type))

Definition at line 439 of file ct.c.

Function Documentation

◆ nfnlmsg_ct_group()

int nfnlmsg_ct_group ( struct nlmsghdr nlh)

Definition at line 274 of file ct.c.

275{
276 switch (nfnlmsg_subtype(nlh)) {
277 case IPCTNL_MSG_CT_NEW:
279 return NFNLGRP_CONNTRACK_NEW;
280 else
281 return NFNLGRP_CONNTRACK_UPDATE;
282 case IPCTNL_MSG_CT_DELETE:
283 return NFNLGRP_CONNTRACK_DESTROY;
284 default:
285 return NFNLGRP_NONE;
286 }
287}
#define NLM_F_EXCL
Don't replace the config object if it already exists.
#define NLM_F_CREATE
Create config object if it doesn't already exist.
uint8_t nfnlmsg_subtype(struct nlmsghdr *nlh)
Get netfilter message type from message.
Definition: nfnl.c:141
uint16_t nlmsg_flags
Message flags.

◆ nfnlmsg_ct_parse()

struct nfnl_ct * nfnlmsg_ct_parse ( struct nlmsghdr nlh)

Definition at line 289 of file ct.c.

290{
291 struct nfnl_ct *ct;
292 struct nlattr *tb[CTA_MAX+1];
293 int err;
294
295 ct = nfnl_ct_alloc();
296 if (!ct)
297 return NULL;
298
299 ct->ce_msgtype = nlh->nlmsg_type;
300
301 err = nlmsg_parse(nlh, sizeof(struct nfgenmsg), tb, CTA_MAX,
302 ct_policy);
303 if (err < 0)
304 goto errout;
305
306 nfnl_ct_set_family(ct, nfnlmsg_family(nlh));
307
308 if (tb[CTA_TUPLE_ORIG]) {
309 err = ct_parse_tuple(ct, 0, tb[CTA_TUPLE_ORIG]);
310 if (err < 0)
311 goto errout;
312 }
313 if (tb[CTA_TUPLE_REPLY]) {
314 err = ct_parse_tuple(ct, 1, tb[CTA_TUPLE_REPLY]);
315 if (err < 0)
316 goto errout;
317 }
318
319 if (tb[CTA_PROTOINFO]) {
320 err = ct_parse_protoinfo(ct, tb[CTA_PROTOINFO]);
321 if (err < 0)
322 goto errout;
323 }
324
325 if (tb[CTA_STATUS])
326 nfnl_ct_set_status(ct, ntohl(nla_get_u32(tb[CTA_STATUS])));
327 if (tb[CTA_TIMEOUT])
328 nfnl_ct_set_timeout(ct, ntohl(nla_get_u32(tb[CTA_TIMEOUT])));
329 if (tb[CTA_MARK])
330 nfnl_ct_set_mark(ct, ntohl(nla_get_u32(tb[CTA_MARK])));
331 if (tb[CTA_USE])
332 nfnl_ct_set_use(ct, ntohl(nla_get_u32(tb[CTA_USE])));
333 if (tb[CTA_ID])
334 nfnl_ct_set_id(ct, ntohl(nla_get_u32(tb[CTA_ID])));
335
336 if (tb[CTA_COUNTERS_ORIG]) {
337 err = ct_parse_counters(ct, 0, tb[CTA_COUNTERS_ORIG]);
338 if (err < 0)
339 goto errout;
340 }
341
342 if (tb[CTA_COUNTERS_REPLY]) {
343 err = ct_parse_counters(ct, 1, tb[CTA_COUNTERS_REPLY]);
344 if (err < 0)
345 goto errout;
346 }
347
348 return ct;
349
350errout:
351 nfnl_ct_put(ct);
352 return NULL;
353}
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of u32 attribute.
Definition: attr.c:693
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
parse attributes of a netlink message
Definition: msg.c:319
uint8_t nfnlmsg_family(struct nlmsghdr *nlh)
Get netfilter family from message.
Definition: nfnl.c:150
uint16_t nlmsg_type
Message type (content type)

◆ nfnl_ct_dump_request()

int nfnl_ct_dump_request ( struct nl_handle *  h)

Definition at line 380 of file ct.c.

381{
382 return nfnl_send_simple(h, NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_GET,
383 NLM_F_DUMP, AF_UNSPEC, 0);
384}
#define NLM_F_DUMP
Dump all entries.
int nfnl_send_simple(struct nl_handle *handle, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Send trivial netfilter netlink message.
Definition: nfnl.c:108

◆ nfnl_ct_alloc_cache()

struct nl_cache * nfnl_ct_alloc_cache ( struct nl_handle *  handle)
Parameters
handlenetlink handle

Allocates a new cache, initializes it properly and updates it to contain all conntracks currently in the kernel.

Note
The caller is responsible for destroying and freeing the cache after using it.
Returns
The cache or NULL if an error has occured.

Definition at line 407 of file ct.c.

408{
409 struct nl_cache *cache;
410
411 cache = nl_cache_alloc(&nfnl_ct_ops);
412 if (!cache)
413 return NULL;
414
415 if (handle && nl_cache_refill(handle, cache) < 0) {
416 free(cache);
417 return NULL;
418 }
419
420 return cache;
421}
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:680

References nl_cache_alloc(), and nl_cache_refill().