diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-02 14:07:39 -0400 |
---|---|---|
committer | pablo <pablo@1984.(none)> | 2009-06-02 14:07:39 -0400 |
commit | 96bcf938dc9637e8bb8b2c5d7885d72af5cd10af (patch) | |
tree | 33aa7ee88e3fe8d255edcaa597f22bbd683fe7df | |
parent | f2f3e38c63c58a3d39bd710039af8bbd15ecaff6 (diff) |
netfilter: ctnetlink: use nlmsg_* helper function to build messages
Replaces the old macros to build Netlink messages with the
new nlmsg_*() helper functions.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | net/netfilter/nf_conntrack_netlink.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 3553f3941259..5c14867dd440 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c | |||
@@ -353,13 +353,14 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, | |||
353 | struct nlmsghdr *nlh; | 353 | struct nlmsghdr *nlh; |
354 | struct nfgenmsg *nfmsg; | 354 | struct nfgenmsg *nfmsg; |
355 | struct nlattr *nest_parms; | 355 | struct nlattr *nest_parms; |
356 | unsigned char *b = skb_tail_pointer(skb); | 356 | unsigned int flags = pid ? NLM_F_MULTI : 0; |
357 | 357 | ||
358 | event |= NFNL_SUBSYS_CTNETLINK << 8; | 358 | event |= NFNL_SUBSYS_CTNETLINK << 8; |
359 | nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg)); | 359 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*nfmsg), flags); |
360 | nfmsg = NLMSG_DATA(nlh); | 360 | if (nlh == NULL) |
361 | goto nlmsg_failure; | ||
361 | 362 | ||
362 | nlh->nlmsg_flags = pid ? NLM_F_MULTI : 0; | 363 | nfmsg = nlmsg_data(nlh); |
363 | nfmsg->nfgen_family = nf_ct_l3num(ct); | 364 | nfmsg->nfgen_family = nf_ct_l3num(ct); |
364 | nfmsg->version = NFNETLINK_V0; | 365 | nfmsg->version = NFNETLINK_V0; |
365 | nfmsg->res_id = 0; | 366 | nfmsg->res_id = 0; |
@@ -392,12 +393,12 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, | |||
392 | ctnetlink_dump_nat_seq_adj(skb, ct) < 0) | 393 | ctnetlink_dump_nat_seq_adj(skb, ct) < 0) |
393 | goto nla_put_failure; | 394 | goto nla_put_failure; |
394 | 395 | ||
395 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | 396 | nlmsg_end(skb, nlh); |
396 | return skb->len; | 397 | return skb->len; |
397 | 398 | ||
398 | nlmsg_failure: | 399 | nlmsg_failure: |
399 | nla_put_failure: | 400 | nla_put_failure: |
400 | nlmsg_trim(skb, b); | 401 | nlmsg_cancel(skb, nlh); |
401 | return -1; | 402 | return -1; |
402 | } | 403 | } |
403 | 404 | ||
@@ -431,7 +432,7 @@ ctnetlink_alloc_skb(const struct nf_conntrack_tuple *tuple, gfp_t gfp) | |||
431 | #define NLA_TYPE_SIZE(type) nla_total_size(sizeof(type)) | 432 | #define NLA_TYPE_SIZE(type) nla_total_size(sizeof(type)) |
432 | 433 | ||
433 | /* proto independant part */ | 434 | /* proto independant part */ |
434 | len = NLMSG_SPACE(sizeof(struct nfgenmsg)) | 435 | len = NLMSG_ALIGN(sizeof(struct nfgenmsg)) |
435 | + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */ | 436 | + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */ |
436 | + 3 * nla_total_size(0) /* CTA_TUPLE_IP */ | 437 | + 3 * nla_total_size(0) /* CTA_TUPLE_IP */ |
437 | + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */ | 438 | + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */ |
@@ -471,7 +472,7 @@ ctnetlink_alloc_skb(const struct nf_conntrack_tuple *tuple, gfp_t gfp) | |||
471 | len += l4proto->nla_size; | 472 | len += l4proto->nla_size; |
472 | rcu_read_unlock(); | 473 | rcu_read_unlock(); |
473 | 474 | ||
474 | return alloc_skb(len, gfp); | 475 | return nlmsg_new(len, gfp); |
475 | } | 476 | } |
476 | 477 | ||
477 | static int ctnetlink_conntrack_event(struct notifier_block *this, | 478 | static int ctnetlink_conntrack_event(struct notifier_block *this, |
@@ -484,7 +485,6 @@ static int ctnetlink_conntrack_event(struct notifier_block *this, | |||
484 | struct nf_conn *ct = item->ct; | 485 | struct nf_conn *ct = item->ct; |
485 | struct sk_buff *skb; | 486 | struct sk_buff *skb; |
486 | unsigned int type; | 487 | unsigned int type; |
487 | sk_buff_data_t b; | ||
488 | unsigned int flags = 0, group; | 488 | unsigned int flags = 0, group; |
489 | 489 | ||
490 | /* ignore our fake conntrack entry */ | 490 | /* ignore our fake conntrack entry */ |
@@ -512,13 +512,12 @@ static int ctnetlink_conntrack_event(struct notifier_block *this, | |||
512 | if (!skb) | 512 | if (!skb) |
513 | goto errout; | 513 | goto errout; |
514 | 514 | ||
515 | b = skb->tail; | ||
516 | |||
517 | type |= NFNL_SUBSYS_CTNETLINK << 8; | 515 | type |= NFNL_SUBSYS_CTNETLINK << 8; |
518 | nlh = NLMSG_PUT(skb, item->pid, 0, type, sizeof(struct nfgenmsg)); | 516 | nlh = nlmsg_put(skb, item->pid, 0, type, sizeof(*nfmsg), flags); |
519 | nfmsg = NLMSG_DATA(nlh); | 517 | if (nlh == NULL) |
518 | goto nlmsg_failure; | ||
520 | 519 | ||
521 | nlh->nlmsg_flags = flags; | 520 | nfmsg = nlmsg_data(nlh); |
522 | nfmsg->nfgen_family = nf_ct_l3num(ct); | 521 | nfmsg->nfgen_family = nf_ct_l3num(ct); |
523 | nfmsg->version = NFNETLINK_V0; | 522 | nfmsg->version = NFNETLINK_V0; |
524 | nfmsg->res_id = 0; | 523 | nfmsg->res_id = 0; |
@@ -582,12 +581,13 @@ static int ctnetlink_conntrack_event(struct notifier_block *this, | |||
582 | #endif | 581 | #endif |
583 | rcu_read_unlock(); | 582 | rcu_read_unlock(); |
584 | 583 | ||
585 | nlh->nlmsg_len = skb->tail - b; | 584 | nlmsg_end(skb, nlh); |
586 | nfnetlink_send(skb, item->pid, group, item->report); | 585 | nfnetlink_send(skb, item->pid, group, item->report); |
587 | return NOTIFY_DONE; | 586 | return NOTIFY_DONE; |
588 | 587 | ||
589 | nla_put_failure: | 588 | nla_put_failure: |
590 | rcu_read_unlock(); | 589 | rcu_read_unlock(); |
590 | nlmsg_cancel(skb, nlh); | ||
591 | nlmsg_failure: | 591 | nlmsg_failure: |
592 | kfree_skb(skb); | 592 | kfree_skb(skb); |
593 | errout: | 593 | errout: |
@@ -609,7 +609,7 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) | |||
609 | struct nf_conn *ct, *last; | 609 | struct nf_conn *ct, *last; |
610 | struct nf_conntrack_tuple_hash *h; | 610 | struct nf_conntrack_tuple_hash *h; |
611 | struct hlist_nulls_node *n; | 611 | struct hlist_nulls_node *n; |
612 | struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh); | 612 | struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh); |
613 | u_int8_t l3proto = nfmsg->nfgen_family; | 613 | u_int8_t l3proto = nfmsg->nfgen_family; |
614 | 614 | ||
615 | rcu_read_lock(); | 615 | rcu_read_lock(); |
@@ -789,7 +789,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, | |||
789 | struct nf_conntrack_tuple_hash *h; | 789 | struct nf_conntrack_tuple_hash *h; |
790 | struct nf_conntrack_tuple tuple; | 790 | struct nf_conntrack_tuple tuple; |
791 | struct nf_conn *ct; | 791 | struct nf_conn *ct; |
792 | struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); | 792 | struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
793 | u_int8_t u3 = nfmsg->nfgen_family; | 793 | u_int8_t u3 = nfmsg->nfgen_family; |
794 | int err = 0; | 794 | int err = 0; |
795 | 795 | ||
@@ -844,7 +844,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, | |||
844 | struct nf_conntrack_tuple tuple; | 844 | struct nf_conntrack_tuple tuple; |
845 | struct nf_conn *ct; | 845 | struct nf_conn *ct; |
846 | struct sk_buff *skb2 = NULL; | 846 | struct sk_buff *skb2 = NULL; |
847 | struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); | 847 | struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
848 | u_int8_t u3 = nfmsg->nfgen_family; | 848 | u_int8_t u3 = nfmsg->nfgen_family; |
849 | int err = 0; | 849 | int err = 0; |
850 | 850 | ||
@@ -869,8 +869,8 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, | |||
869 | ct = nf_ct_tuplehash_to_ctrack(h); | 869 | ct = nf_ct_tuplehash_to_ctrack(h); |
870 | 870 | ||
871 | err = -ENOMEM; | 871 | err = -ENOMEM; |
872 | skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); | 872 | skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
873 | if (!skb2) { | 873 | if (skb2 == NULL) { |
874 | nf_ct_put(ct); | 874 | nf_ct_put(ct); |
875 | return -ENOMEM; | 875 | return -ENOMEM; |
876 | } | 876 | } |
@@ -1322,7 +1322,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, | |||
1322 | { | 1322 | { |
1323 | struct nf_conntrack_tuple otuple, rtuple; | 1323 | struct nf_conntrack_tuple otuple, rtuple; |
1324 | struct nf_conntrack_tuple_hash *h = NULL; | 1324 | struct nf_conntrack_tuple_hash *h = NULL; |
1325 | struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); | 1325 | struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
1326 | u_int8_t u3 = nfmsg->nfgen_family; | 1326 | u_int8_t u3 = nfmsg->nfgen_family; |
1327 | int err = 0; | 1327 | int err = 0; |
1328 | 1328 | ||
@@ -1504,13 +1504,14 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq, | |||
1504 | { | 1504 | { |
1505 | struct nlmsghdr *nlh; | 1505 | struct nlmsghdr *nlh; |
1506 | struct nfgenmsg *nfmsg; | 1506 | struct nfgenmsg *nfmsg; |
1507 | unsigned char *b = skb_tail_pointer(skb); | 1507 | unsigned int flags = pid ? NLM_F_MULTI : 0; |
1508 | 1508 | ||
1509 | event |= NFNL_SUBSYS_CTNETLINK_EXP << 8; | 1509 | event |= NFNL_SUBSYS_CTNETLINK_EXP << 8; |
1510 | nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg)); | 1510 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*nfmsg), flags); |
1511 | nfmsg = NLMSG_DATA(nlh); | 1511 | if (nlh == NULL) |
1512 | goto nlmsg_failure; | ||
1512 | 1513 | ||
1513 | nlh->nlmsg_flags = pid ? NLM_F_MULTI : 0; | 1514 | nfmsg = nlmsg_data(nlh); |
1514 | nfmsg->nfgen_family = exp->tuple.src.l3num; | 1515 | nfmsg->nfgen_family = exp->tuple.src.l3num; |
1515 | nfmsg->version = NFNETLINK_V0; | 1516 | nfmsg->version = NFNETLINK_V0; |
1516 | nfmsg->res_id = 0; | 1517 | nfmsg->res_id = 0; |
@@ -1518,12 +1519,12 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq, | |||
1518 | if (ctnetlink_exp_dump_expect(skb, exp) < 0) | 1519 | if (ctnetlink_exp_dump_expect(skb, exp) < 0) |
1519 | goto nla_put_failure; | 1520 | goto nla_put_failure; |
1520 | 1521 | ||
1521 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | 1522 | nlmsg_end(skb, nlh); |
1522 | return skb->len; | 1523 | return skb->len; |
1523 | 1524 | ||
1524 | nlmsg_failure: | 1525 | nlmsg_failure: |
1525 | nla_put_failure: | 1526 | nla_put_failure: |
1526 | nlmsg_trim(skb, b); | 1527 | nlmsg_cancel(skb, nlh); |
1527 | return -1; | 1528 | return -1; |
1528 | } | 1529 | } |
1529 | 1530 | ||
@@ -1537,7 +1538,6 @@ static int ctnetlink_expect_event(struct notifier_block *this, | |||
1537 | struct nf_conntrack_expect *exp = item->exp; | 1538 | struct nf_conntrack_expect *exp = item->exp; |
1538 | struct sk_buff *skb; | 1539 | struct sk_buff *skb; |
1539 | unsigned int type; | 1540 | unsigned int type; |
1540 | sk_buff_data_t b; | ||
1541 | int flags = 0; | 1541 | int flags = 0; |
1542 | 1542 | ||
1543 | if (events & IPEXP_NEW) { | 1543 | if (events & IPEXP_NEW) { |
@@ -1550,17 +1550,16 @@ static int ctnetlink_expect_event(struct notifier_block *this, | |||
1550 | !nfnetlink_has_listeners(NFNLGRP_CONNTRACK_EXP_NEW)) | 1550 | !nfnetlink_has_listeners(NFNLGRP_CONNTRACK_EXP_NEW)) |
1551 | return NOTIFY_DONE; | 1551 | return NOTIFY_DONE; |
1552 | 1552 | ||
1553 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); | 1553 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
1554 | if (!skb) | 1554 | if (skb == NULL) |
1555 | goto errout; | 1555 | goto errout; |
1556 | 1556 | ||
1557 | b = skb->tail; | ||
1558 | |||
1559 | type |= NFNL_SUBSYS_CTNETLINK_EXP << 8; | 1557 | type |= NFNL_SUBSYS_CTNETLINK_EXP << 8; |
1560 | nlh = NLMSG_PUT(skb, item->pid, 0, type, sizeof(struct nfgenmsg)); | 1558 | nlh = nlmsg_put(skb, item->pid, 0, type, sizeof(*nfmsg), flags); |
1561 | nfmsg = NLMSG_DATA(nlh); | 1559 | if (nlh == NULL) |
1560 | goto nlmsg_failure; | ||
1562 | 1561 | ||
1563 | nlh->nlmsg_flags = flags; | 1562 | nfmsg = nlmsg_data(nlh); |
1564 | nfmsg->nfgen_family = exp->tuple.src.l3num; | 1563 | nfmsg->nfgen_family = exp->tuple.src.l3num; |
1565 | nfmsg->version = NFNETLINK_V0; | 1564 | nfmsg->version = NFNETLINK_V0; |
1566 | nfmsg->res_id = 0; | 1565 | nfmsg->res_id = 0; |
@@ -1570,12 +1569,13 @@ static int ctnetlink_expect_event(struct notifier_block *this, | |||
1570 | goto nla_put_failure; | 1569 | goto nla_put_failure; |
1571 | rcu_read_unlock(); | 1570 | rcu_read_unlock(); |
1572 | 1571 | ||
1573 | nlh->nlmsg_len = skb->tail - b; | 1572 | nlmsg_end(skb, nlh); |
1574 | nfnetlink_send(skb, item->pid, NFNLGRP_CONNTRACK_EXP_NEW, item->report); | 1573 | nfnetlink_send(skb, item->pid, NFNLGRP_CONNTRACK_EXP_NEW, item->report); |
1575 | return NOTIFY_DONE; | 1574 | return NOTIFY_DONE; |
1576 | 1575 | ||
1577 | nla_put_failure: | 1576 | nla_put_failure: |
1578 | rcu_read_unlock(); | 1577 | rcu_read_unlock(); |
1578 | nlmsg_cancel(skb, nlh); | ||
1579 | nlmsg_failure: | 1579 | nlmsg_failure: |
1580 | kfree_skb(skb); | 1580 | kfree_skb(skb); |
1581 | errout: | 1581 | errout: |
@@ -1595,7 +1595,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) | |||
1595 | { | 1595 | { |
1596 | struct net *net = &init_net; | 1596 | struct net *net = &init_net; |
1597 | struct nf_conntrack_expect *exp, *last; | 1597 | struct nf_conntrack_expect *exp, *last; |
1598 | struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh); | 1598 | struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh); |
1599 | struct hlist_node *n; | 1599 | struct hlist_node *n; |
1600 | u_int8_t l3proto = nfmsg->nfgen_family; | 1600 | u_int8_t l3proto = nfmsg->nfgen_family; |
1601 | 1601 | ||
@@ -1648,7 +1648,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, | |||
1648 | struct nf_conntrack_tuple tuple; | 1648 | struct nf_conntrack_tuple tuple; |
1649 | struct nf_conntrack_expect *exp; | 1649 | struct nf_conntrack_expect *exp; |
1650 | struct sk_buff *skb2; | 1650 | struct sk_buff *skb2; |
1651 | struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); | 1651 | struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
1652 | u_int8_t u3 = nfmsg->nfgen_family; | 1652 | u_int8_t u3 = nfmsg->nfgen_family; |
1653 | int err = 0; | 1653 | int err = 0; |
1654 | 1654 | ||
@@ -1679,8 +1679,8 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, | |||
1679 | } | 1679 | } |
1680 | 1680 | ||
1681 | err = -ENOMEM; | 1681 | err = -ENOMEM; |
1682 | skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); | 1682 | skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
1683 | if (!skb2) | 1683 | if (skb2 == NULL) |
1684 | goto out; | 1684 | goto out; |
1685 | 1685 | ||
1686 | rcu_read_lock(); | 1686 | rcu_read_lock(); |
@@ -1708,7 +1708,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, | |||
1708 | struct nf_conntrack_expect *exp; | 1708 | struct nf_conntrack_expect *exp; |
1709 | struct nf_conntrack_tuple tuple; | 1709 | struct nf_conntrack_tuple tuple; |
1710 | struct nf_conntrack_helper *h; | 1710 | struct nf_conntrack_helper *h; |
1711 | struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); | 1711 | struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
1712 | struct hlist_node *n, *next; | 1712 | struct hlist_node *n, *next; |
1713 | u_int8_t u3 = nfmsg->nfgen_family; | 1713 | u_int8_t u3 = nfmsg->nfgen_family; |
1714 | unsigned int i; | 1714 | unsigned int i; |
@@ -1849,7 +1849,7 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb, | |||
1849 | { | 1849 | { |
1850 | struct nf_conntrack_tuple tuple; | 1850 | struct nf_conntrack_tuple tuple; |
1851 | struct nf_conntrack_expect *exp; | 1851 | struct nf_conntrack_expect *exp; |
1852 | struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); | 1852 | struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
1853 | u_int8_t u3 = nfmsg->nfgen_family; | 1853 | u_int8_t u3 = nfmsg->nfgen_family; |
1854 | int err = 0; | 1854 | int err = 0; |
1855 | 1855 | ||