Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

WANG Cong and committed by
David S. Miller
a56e1953 ddafd34f

+40 -55
+40 -55
net/sched/act_api.c
··· 789 789 } 790 790 791 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 819 tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, 793 820 u32 portid, int event) 794 821 { ··· 848 821 if (event == RTM_GETACTION) 849 822 ret = act_get_notify(net, portid, n, &actions, event); 850 823 else { /* delete */ 851 - struct sk_buff *skb; 852 - 853 - skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 854 - if (!skb) { 855 - ret = -ENOBUFS; 824 + ret = tcf_del_notify(net, n, &actions, portid); 825 + if (ret) 856 826 goto err; 857 - } 858 - 859 - if (tca_get_fill(skb, &actions, portid, n->nlmsg_seq, 0, event, 860 - 0, 1) <= 0) { 861 - kfree_skb(skb); 862 - ret = -EINVAL; 863 - goto err; 864 - } 865 - 866 - /* now do the delete */ 867 - tcf_action_destroy(&actions, 0); 868 - ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC, 869 - n->nlmsg_flags & NLM_F_ECHO); 870 - if (ret > 0) 871 - return 0; 872 827 return ret; 873 828 } 874 829 err: ··· 858 849 return ret; 859 850 } 860 851 861 - static int tcf_add_notify(struct net *net, struct list_head *actions, 862 - u32 portid, u32 seq, int event, u16 flags) 852 + static int 853 + tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions, 854 + u32 portid) 863 855 { 864 - struct tcamsg *t; 865 - struct nlmsghdr *nlh; 866 856 struct sk_buff *skb; 867 - struct nlattr *nest; 868 - unsigned char *b; 869 857 int err = 0; 870 858 871 859 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 872 860 if (!skb) 873 861 return -ENOBUFS; 874 862 875 - b = skb_tail_pointer(skb); 863 + if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags, 864 + RTM_NEWACTION, 0, 0) <= 0) { 865 + kfree_skb(skb); 866 + return -EINVAL; 867 + } 876 868 877 - nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags); 878 - if (!nlh) 879 - goto out_kfree_skb; 880 - t = nlmsg_data(nlh); 881 - t->tca_family = AF_UNSPEC; 882 - t->tca__pad1 = 0; 883 - t->tca__pad2 = 0; 884 - 885 - nest = nla_nest_start(skb, TCA_ACT_TAB); 886 - if (nest == NULL) 887 - goto out_kfree_skb; 888 - 889 - if (tcf_action_dump(skb, actions, 0, 0) < 0) 890 - goto out_kfree_skb; 891 - 892 - nla_nest_end(skb, nest); 893 - 894 - nlh->nlmsg_len = skb_tail_pointer(skb) - b; 895 - NETLINK_CB(skb).dst_group = RTNLGRP_TC; 896 - 897 - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO); 869 + err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, 870 + n->nlmsg_flags & NLM_F_ECHO); 898 871 if (err > 0) 899 872 err = 0; 900 873 return err; 901 - 902 - out_kfree_skb: 903 - kfree_skb(skb); 904 - return -1; 905 874 } 906 - 907 875 908 876 static int 909 877 tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n, ··· 888 902 { 889 903 int ret = 0; 890 904 LIST_HEAD(actions); 891 - u32 seq = n->nlmsg_seq; 892 905 893 906 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions); 894 907 if (ret) ··· 896 911 /* dump then free all the actions after update; inserted policy 897 912 * stays intact 898 913 */ 899 - ret = tcf_add_notify(net, &actions, portid, seq, RTM_NEWACTION, n->nlmsg_flags); 914 + ret = tcf_add_notify(net, n, &actions, portid); 900 915 cleanup_a(&actions); 901 916 done: 902 917 return ret;