aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-06-02 14:08:27 -0400
committerpablo <pablo@1984.(none)>2009-06-02 14:08:27 -0400
commit03b64f518a893512d32f07a10b053e558beafcaf (patch)
tree1be8c5d011227102f89a5b94f62e58aae427d8bd /net
parent96bcf938dc9637e8bb8b2c5d7885d72af5cd10af (diff)
netfilter: ctnetlink: cleanup message-size calculation
This patch cleans up the message calculation to make it similar to rtnetlink, moreover, it removes unneeded verbose information. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net')
-rw-r--r--net/netfilter/nf_conntrack_netlink.c102
1 files changed, 40 insertions, 62 deletions
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 5c14867dd440..58fde0e47b05 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -403,76 +403,55 @@ nla_put_failure:
403} 403}
404 404
405#ifdef CONFIG_NF_CONNTRACK_EVENTS 405#ifdef CONFIG_NF_CONNTRACK_EVENTS
406/* 406static inline size_t
407 * The general structure of a ctnetlink event is 407ctnetlink_proto_size(const struct nf_conn *ct)
408 *
409 * CTA_TUPLE_ORIG
410 * <l3/l4-proto-attributes>
411 * CTA_TUPLE_REPLY
412 * <l3/l4-proto-attributes>
413 * CTA_ID
414 * ...
415 * CTA_PROTOINFO
416 * <l4-proto-attributes>
417 * CTA_TUPLE_MASTER
418 * <l3/l4-proto-attributes>
419 *
420 * Therefore the formular is
421 *
422 * size = sizeof(headers) + sizeof(generic_nlas) + 3 * sizeof(tuple_nlas)
423 * + sizeof(protoinfo_nlas)
424 */
425static struct sk_buff *
426ctnetlink_alloc_skb(const struct nf_conntrack_tuple *tuple, gfp_t gfp)
427{ 408{
428 struct nf_conntrack_l3proto *l3proto; 409 struct nf_conntrack_l3proto *l3proto;
429 struct nf_conntrack_l4proto *l4proto; 410 struct nf_conntrack_l4proto *l4proto;
430 int len; 411 size_t len = 0;
431 412
432#define NLA_TYPE_SIZE(type) nla_total_size(sizeof(type)) 413 rcu_read_lock();
433 414 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
434 /* proto independant part */ 415 len += l3proto->nla_size;
435 len = NLMSG_ALIGN(sizeof(struct nfgenmsg)) 416
436 + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */ 417 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
437 + 3 * nla_total_size(0) /* CTA_TUPLE_IP */ 418 len += l4proto->nla_size;
438 + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */ 419 rcu_read_unlock();
439 + 3 * NLA_TYPE_SIZE(u_int8_t) /* CTA_PROTO_NUM */ 420
440 + NLA_TYPE_SIZE(u_int32_t) /* CTA_ID */ 421 return len;
441 + NLA_TYPE_SIZE(u_int32_t) /* CTA_STATUS */ 422}
423
424static inline size_t
425ctnetlink_nlmsg_size(const struct nf_conn *ct)
426{
427 return NLMSG_ALIGN(sizeof(struct nfgenmsg))
428 + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */
429 + 3 * nla_total_size(0) /* CTA_TUPLE_IP */
430 + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */
431 + 3 * nla_total_size(sizeof(u_int8_t)) /* CTA_PROTO_NUM */
432 + nla_total_size(sizeof(u_int32_t)) /* CTA_ID */
433 + nla_total_size(sizeof(u_int32_t)) /* CTA_STATUS */
442#ifdef CONFIG_NF_CT_ACCT 434#ifdef CONFIG_NF_CT_ACCT
443 + 2 * nla_total_size(0) /* CTA_COUNTERS_ORIG|REPL */ 435 + 2 * nla_total_size(0) /* CTA_COUNTERS_ORIG|REPL */
444 + 2 * NLA_TYPE_SIZE(uint64_t) /* CTA_COUNTERS_PACKETS */ 436 + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_PACKETS */
445 + 2 * NLA_TYPE_SIZE(uint64_t) /* CTA_COUNTERS_BYTES */ 437 + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_BYTES */
446#endif 438#endif
447 + NLA_TYPE_SIZE(u_int32_t) /* CTA_TIMEOUT */ 439 + nla_total_size(sizeof(u_int32_t)) /* CTA_TIMEOUT */
448 + nla_total_size(0) /* CTA_PROTOINFO */ 440 + nla_total_size(0) /* CTA_PROTOINFO */
449 + nla_total_size(0) /* CTA_HELP */ 441 + nla_total_size(0) /* CTA_HELP */
450 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */ 442 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */
451#ifdef CONFIG_NF_CONNTRACK_SECMARK 443#ifdef CONFIG_NF_CONNTRACK_SECMARK
452 + NLA_TYPE_SIZE(u_int32_t) /* CTA_SECMARK */ 444 + nla_total_size(sizeof(u_int32_t)) /* CTA_SECMARK */
453#endif 445#endif
454#ifdef CONFIG_NF_NAT_NEEDED 446#ifdef CONFIG_NF_NAT_NEEDED
455 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */ 447 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
456 + 2 * NLA_TYPE_SIZE(u_int32_t) /* CTA_NAT_SEQ_CORRECTION_POS */ 448 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */
457 + 2 * NLA_TYPE_SIZE(u_int32_t) /* CTA_NAT_SEQ_CORRECTION_BEFORE */
458 + 2 * NLA_TYPE_SIZE(u_int32_t) /* CTA_NAT_SEQ_CORRECTION_AFTER */
459#endif 449#endif
460#ifdef CONFIG_NF_CONNTRACK_MARK 450#ifdef CONFIG_NF_CONNTRACK_MARK
461 + NLA_TYPE_SIZE(u_int32_t) /* CTA_MARK */ 451 + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */
462#endif 452#endif
463 ; 453 + ctnetlink_proto_size(ct)
464 454 ;
465#undef NLA_TYPE_SIZE
466
467 rcu_read_lock();
468 l3proto = __nf_ct_l3proto_find(tuple->src.l3num);
469 len += l3proto->nla_size;
470
471 l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum);
472 len += l4proto->nla_size;
473 rcu_read_unlock();
474
475 return nlmsg_new(len, gfp);
476} 455}
477 456
478static int ctnetlink_conntrack_event(struct notifier_block *this, 457static int ctnetlink_conntrack_event(struct notifier_block *this,
@@ -507,9 +486,8 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
507 if (!item->report && !nfnetlink_has_listeners(group)) 486 if (!item->report && !nfnetlink_has_listeners(group))
508 return NOTIFY_DONE; 487 return NOTIFY_DONE;
509 488
510 skb = ctnetlink_alloc_skb(nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL), 489 skb = nlmsg_new(ctnetlink_nlmsg_size(ct), GFP_ATOMIC);
511 GFP_ATOMIC); 490 if (skb == NULL)
512 if (!skb)
513 goto errout; 491 goto errout;
514 492
515 type |= NFNL_SUBSYS_CTNETLINK << 8; 493 type |= NFNL_SUBSYS_CTNETLINK << 8;