diff options
author | WANG Cong <xiyou.wangcong@gmail.com> | 2014-01-09 19:14:00 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-13 14:50:14 -0500 |
commit | a56e19538d02ade9ee6ae82da4a216d7a632e8d5 (patch) | |
tree | 8e32386ce0edace7b0544b0132b8c935fd260293 | |
parent | ddafd34f419546f1eb7c343178685f059c3cf127 (diff) |
net_sched: act: clean up notification functions
Refactor tcf_add_notify() and factor out tcf_del_notify().
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/sched/act_api.c | 95 |
1 files changed, 40 insertions, 55 deletions
diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 74ae3ff05747..178bf2eab117 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c | |||
@@ -789,6 +789,33 @@ noflush_out: | |||
789 | } | 789 | } |
790 | 790 | ||
791 | static int | 791 | static int |
792 | tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions, | ||
793 | u32 portid) | ||
794 | { | ||
795 | int ret; | ||
796 | struct sk_buff *skb; | ||
797 | |||
798 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); | ||
799 | if (!skb) | ||
800 | return -ENOBUFS; | ||
801 | |||
802 | if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION, | ||
803 | 0, 1) <= 0) { | ||
804 | kfree_skb(skb); | ||
805 | return -EINVAL; | ||
806 | } | ||
807 | |||
808 | /* now do the delete */ | ||
809 | tcf_action_destroy(actions, 0); | ||
810 | |||
811 | ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC, | ||
812 | n->nlmsg_flags & NLM_F_ECHO); | ||
813 | if (ret > 0) | ||
814 | return 0; | ||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | static int | ||
792 | tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, | 819 | tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, |
793 | u32 portid, int event) | 820 | u32 portid, int event) |
794 | { | 821 | { |
@@ -821,27 +848,9 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, | |||
821 | if (event == RTM_GETACTION) | 848 | if (event == RTM_GETACTION) |
822 | ret = act_get_notify(net, portid, n, &actions, event); | 849 | ret = act_get_notify(net, portid, n, &actions, event); |
823 | else { /* delete */ | 850 | else { /* delete */ |
824 | struct sk_buff *skb; | 851 | ret = tcf_del_notify(net, n, &actions, portid); |
825 | 852 | if (ret) | |
826 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); | ||
827 | if (!skb) { | ||
828 | ret = -ENOBUFS; | ||
829 | goto err; | ||
830 | } | ||
831 | |||
832 | if (tca_get_fill(skb, &actions, portid, n->nlmsg_seq, 0, event, | ||
833 | 0, 1) <= 0) { | ||
834 | kfree_skb(skb); | ||
835 | ret = -EINVAL; | ||
836 | goto err; | 853 | goto err; |
837 | } | ||
838 | |||
839 | /* now do the delete */ | ||
840 | tcf_action_destroy(&actions, 0); | ||
841 | ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC, | ||
842 | n->nlmsg_flags & NLM_F_ECHO); | ||
843 | if (ret > 0) | ||
844 | return 0; | ||
845 | return ret; | 854 | return ret; |
846 | } | 855 | } |
847 | err: | 856 | err: |
@@ -849,60 +858,36 @@ err: | |||
849 | return ret; | 858 | return ret; |
850 | } | 859 | } |
851 | 860 | ||
852 | static int tcf_add_notify(struct net *net, struct list_head *actions, | 861 | static int |
853 | u32 portid, u32 seq, int event, u16 flags) | 862 | tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions, |
863 | u32 portid) | ||
854 | { | 864 | { |
855 | struct tcamsg *t; | ||
856 | struct nlmsghdr *nlh; | ||
857 | struct sk_buff *skb; | 865 | struct sk_buff *skb; |
858 | struct nlattr *nest; | ||
859 | unsigned char *b; | ||
860 | int err = 0; | 866 | int err = 0; |
861 | 867 | ||
862 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); | 868 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); |
863 | if (!skb) | 869 | if (!skb) |
864 | return -ENOBUFS; | 870 | return -ENOBUFS; |
865 | 871 | ||
866 | b = skb_tail_pointer(skb); | 872 | if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags, |
867 | 873 | RTM_NEWACTION, 0, 0) <= 0) { | |
868 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags); | 874 | kfree_skb(skb); |
869 | if (!nlh) | 875 | return -EINVAL; |
870 | goto out_kfree_skb; | 876 | } |
871 | t = nlmsg_data(nlh); | ||
872 | t->tca_family = AF_UNSPEC; | ||
873 | t->tca__pad1 = 0; | ||
874 | t->tca__pad2 = 0; | ||
875 | |||
876 | nest = nla_nest_start(skb, TCA_ACT_TAB); | ||
877 | if (nest == NULL) | ||
878 | goto out_kfree_skb; | ||
879 | |||
880 | if (tcf_action_dump(skb, actions, 0, 0) < 0) | ||
881 | goto out_kfree_skb; | ||
882 | |||
883 | nla_nest_end(skb, nest); | ||
884 | |||
885 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | ||
886 | NETLINK_CB(skb).dst_group = RTNLGRP_TC; | ||
887 | 877 | ||
888 | err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO); | 878 | err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, |
879 | n->nlmsg_flags & NLM_F_ECHO); | ||
889 | if (err > 0) | 880 | if (err > 0) |
890 | err = 0; | 881 | err = 0; |
891 | return err; | 882 | return err; |
892 | |||
893 | out_kfree_skb: | ||
894 | kfree_skb(skb); | ||
895 | return -1; | ||
896 | } | 883 | } |
897 | 884 | ||
898 | |||
899 | static int | 885 | static int |
900 | tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n, | 886 | tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n, |
901 | u32 portid, int ovr) | 887 | u32 portid, int ovr) |
902 | { | 888 | { |
903 | int ret = 0; | 889 | int ret = 0; |
904 | LIST_HEAD(actions); | 890 | LIST_HEAD(actions); |
905 | u32 seq = n->nlmsg_seq; | ||
906 | 891 | ||
907 | ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions); | 892 | ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions); |
908 | if (ret) | 893 | if (ret) |
@@ -911,7 +896,7 @@ tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n, | |||
911 | /* dump then free all the actions after update; inserted policy | 896 | /* dump then free all the actions after update; inserted policy |
912 | * stays intact | 897 | * stays intact |
913 | */ | 898 | */ |
914 | ret = tcf_add_notify(net, &actions, portid, seq, RTM_NEWACTION, n->nlmsg_flags); | 899 | ret = tcf_add_notify(net, n, &actions, portid); |
915 | cleanup_a(&actions); | 900 | cleanup_a(&actions); |
916 | done: | 901 | done: |
917 | return ret; | 902 | return ret; |