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
300
301 err =
nlmsg_parse(nlh,
sizeof(
struct nfgenmsg), tb, CTA_MAX,
302 ct_policy);
303 if (err < 0)
304 goto errout;
305
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.
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
parse attributes of a netlink message
uint8_t nfnlmsg_family(struct nlmsghdr *nlh)
Get netfilter family from message.
uint16_t nlmsg_type
Message type (content type)