cregit-Linux how code gets into the kernel

Release 4.14 net/sched/cls_basic.c

Directory: net/sched
/*
 * net/sched/cls_basic.c        Basic Packet Classifier.
 *
 *              This program is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation; either version
 *              2 of the License, or (at your option) any later version.
 *
 * Authors:     Thomas Graf <tgraf@suug.ch>
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/rtnetlink.h>
#include <linux/skbuff.h>
#include <net/netlink.h>
#include <net/act_api.h>
#include <net/pkt_cls.h>


struct basic_head {
	
u32			hgenerator;
	
struct list_head	flist;
	
struct rcu_head		rcu;
};


struct basic_filter {
	
u32			handle;
	
struct tcf_exts		exts;
	
struct tcf_ematch_tree	ematches;
	
struct tcf_result	res;
	
struct tcf_proto	*tp;
	
struct list_head	link;
	union {
		
struct work_struct	work;
		
struct rcu_head		rcu;
	};
};


static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp, struct tcf_result *res) { int r; struct basic_head *head = rcu_dereference_bh(tp->root); struct basic_filter *f; list_for_each_entry_rcu(f, &head->flist, link) { if (!tcf_em_tree_match(skb, &f->ematches, NULL)) continue; *res = f->res; r = tcf_exts_exec(skb, &f->exts, res); if (r < 0) continue; return r; } return -1; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller9895.15%133.33%
John Fastabend43.88%133.33%
Eric Dumazet10.97%133.33%
Total103100.00%3100.00%


static void *basic_get(struct tcf_proto *tp, u32 handle) { struct basic_head *head = rtnl_dereference(tp->root); struct basic_filter *f; list_for_each_entry(f, &head->flist, link) { if (f->handle == handle) { return f; } } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller4679.31%125.00%
Américo Wang58.62%125.00%
Daniel Borkmann46.90%125.00%
John Fastabend35.17%125.00%
Total58100.00%4100.00%


static int basic_init(struct tcf_proto *tp) { struct basic_head *head; head = kzalloc(sizeof(*head), GFP_KERNEL); if (head == NULL) return -ENOBUFS; INIT_LIST_HEAD(&head->flist); rcu_assign_pointer(tp->root, head); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy4169.49%133.33%
David S. Miller1423.73%133.33%
John Fastabend46.78%133.33%
Total59100.00%3100.00%


static void __basic_delete_filter(struct basic_filter *f) { tcf_exts_destroy(&f->exts); tcf_em_tree_destroy(&f->ematches); tcf_exts_put_net(&f->exts); kfree(f); }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang40100.00%1100.00%
Total40100.00%1100.00%


static void basic_delete_filter_work(struct work_struct *work) { struct basic_filter *f = container_of(work, struct basic_filter, work); rtnl_lock(); __basic_delete_filter(f); rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller1437.84%125.00%
Américo Wang1232.43%250.00%
John Fastabend1129.73%125.00%
Total37100.00%4100.00%


static void basic_delete_filter(struct rcu_head *head) { struct basic_filter *f = container_of(head, struct basic_filter, rcu); INIT_WORK(&f->work, basic_delete_filter_work); tcf_queue_work(&f->work); }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang44100.00%1100.00%
Total44100.00%1100.00%


static void basic_destroy(struct tcf_proto *tp) { struct basic_head *head = rtnl_dereference(tp->root); struct basic_filter *f, *n; list_for_each_entry_safe(f, n, &head->flist, link) { list_del_rcu(&f->link); tcf_unbind_filter(tp, &f->res); if (tcf_exts_get_net(&f->exts)) call_rcu(&f->rcu, basic_delete_filter); else __basic_delete_filter(f); } kfree_rcu(head, rcu); }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller4648.94%116.67%
John Fastabend2728.72%233.33%
Américo Wang1718.09%233.33%
Patrick McHardy44.26%116.67%
Total94100.00%6100.00%


static int basic_delete(struct tcf_proto *tp, void *arg, bool *last) { struct basic_head *head = rtnl_dereference(tp->root); struct basic_filter *f = arg; list_del_rcu(&f->link); tcf_unbind_filter(tp, &f->res); tcf_exts_get_net(&f->exts); call_rcu(&f->rcu, basic_delete_filter); *last = list_empty(&head->flist); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang3742.05%342.86%
David S. Miller3236.36%114.29%
John Fastabend1618.18%228.57%
Jiri Pirko33.41%114.29%
Total88100.00%7100.00%

static const struct nla_policy basic_policy[TCA_BASIC_MAX + 1] = { [TCA_BASIC_CLASSID] = { .type = NLA_U32 }, [TCA_BASIC_EMATCHES] = { .type = NLA_NESTED }, };
static int basic_set_parms(struct net *net, struct tcf_proto *tp, struct basic_filter *f, unsigned long base, struct nlattr **tb, struct nlattr *est, bool ovr) { int err; err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr); if (err < 0) return err; err = tcf_em_tree_validate(tp, tb[TCA_BASIC_EMATCHES], &f->ematches); if (err < 0) return err; if (tb[TCA_BASIC_CLASSID]) { f->res.classid = nla_get_u32(tb[TCA_BASIC_CLASSID]); tcf_bind_filter(tp, &f->res, base); } f->tp = tp; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller10876.60%112.50%
Jiri Pirko128.51%225.00%
Benjamin LaHaise74.96%112.50%
John Fastabend64.26%112.50%
Cong Wang53.55%112.50%
Patrick McHardy32.13%225.00%
Total141100.00%8100.00%


static int basic_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, void **arg, bool ovr) { int err; struct basic_head *head = rtnl_dereference(tp->root); struct nlattr *tb[TCA_BASIC_MAX + 1]; struct basic_filter *fold = (struct basic_filter *) *arg; struct basic_filter *fnew; if (tca[TCA_OPTIONS] == NULL) return -EINVAL; err = nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], basic_policy, NULL); if (err < 0) return err; if (fold != NULL) { if (handle && fold->handle != handle) return -EINVAL; } fnew = kzalloc(sizeof(*fnew), GFP_KERNEL); if (!fnew) return -ENOBUFS; err = tcf_exts_init(&fnew->exts, TCA_BASIC_ACT, TCA_BASIC_POLICE); if (err < 0) goto errout; err = -EINVAL; if (handle) { fnew->handle = handle; } else if (fold) { fnew->handle = fold->handle; } else { unsigned int i = 0x80000000; do { if (++head->hgenerator == 0x7FFFFFFF) head->hgenerator = 1; } while (--i > 0 && basic_get(tp, head->hgenerator)); if (i <= 0) { pr_err("Insufficient number of handles\n"); goto errout; } fnew->handle = head->hgenerator; } err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr); if (err < 0) goto errout; *arg = fnew; if (fold) { list_replace_rcu(&fold->link, &fnew->link); tcf_unbind_filter(tp, &fold->res); tcf_exts_get_net(&fold->exts); call_rcu(&fold->rcu, basic_delete_filter); } else { list_add_rcu(&fnew->link, &head->flist); } return 0; errout: tcf_exts_destroy(&fnew->exts); kfree(fnew); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller24960.44%15.26%
John Fastabend8219.90%210.53%
Américo Wang409.71%526.32%
Patrick McHardy143.40%315.79%
Benjamin LaHaise71.70%15.26%
Cong Wang51.21%15.26%
Eric W. Biedermann51.21%15.26%
Jiri Pirko51.21%15.26%
Johannes Berg20.49%15.26%
Eric Dumazet10.24%15.26%
Kim Nordlund10.24%15.26%
Panagiotis Issaris10.24%15.26%
Total412100.00%19100.00%


static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg) { struct basic_head *head = rtnl_dereference(tp->root); struct basic_filter *f; list_for_each_entry(f, &head->flist, link) { if (arg->count < arg->skip) goto skip; if (arg->fn(tp, f, arg) < 0) { arg->stop = 1; break; } skip: arg->count++; } }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller8496.55%150.00%
John Fastabend33.45%150.00%
Total87100.00%2100.00%


static void basic_bind_class(void *fh, u32 classid, unsigned long cl) { struct basic_filter *f = fh; if (f && f->res.classid == classid) f->res.class = cl; }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang44100.00%1100.00%
Total44100.00%1100.00%


static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh, struct sk_buff *skb, struct tcmsg *t) { struct basic_filter *f = fh; struct nlattr *nest; if (f == NULL) return skb->len; t->tcm_handle = f->handle; nest = nla_nest_start(skb, TCA_OPTIONS); if (nest == NULL) goto nla_put_failure; if (f->res.classid && nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid)) goto nla_put_failure; if (tcf_exts_dump(skb, &f->exts) < 0 || tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0) goto nla_put_failure; nla_nest_end(skb, nest); if (tcf_exts_dump_stats(skb, &f->exts) < 0) goto nla_put_failure; return skb->len; nla_put_failure: nla_nest_cancel(skb, nest); return -1; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller11263.64%222.22%
Patrick McHardy2011.36%222.22%
Thomas Graf1810.23%111.11%
Stephen Hemminger179.66%111.11%
Américo Wang73.98%222.22%
Arnaldo Carvalho de Melo21.14%111.11%
Total176100.00%9100.00%

static struct tcf_proto_ops cls_basic_ops __read_mostly = { .kind = "basic", .classify = basic_classify, .init = basic_init, .destroy = basic_destroy, .get = basic_get, .change = basic_change, .delete = basic_delete, .walk = basic_walk, .dump = basic_dump, .bind_class = basic_bind_class, .owner = THIS_MODULE, };
static int __init init_basic(void) { return register_tcf_proto_ops(&cls_basic_ops); }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller16100.00%1100.00%
Total16100.00%1100.00%


static void __exit exit_basic(void) { unregister_tcf_proto_ops(&cls_basic_ops); }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller15100.00%1100.00%
Total15100.00%1100.00%

module_init(init_basic) module_exit(exit_basic) MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
David S. Miller96859.90%25.13%
Américo Wang25916.03%923.08%
John Fastabend16910.46%25.13%
Patrick McHardy1187.30%820.51%
Jiri Pirko201.24%410.26%
Thomas Graf181.11%12.56%
Stephen Hemminger171.05%12.56%
Benjamin LaHaise140.87%12.56%
Cong Wang100.62%12.56%
Eric W. Biedermann50.31%12.56%
Arnaldo Carvalho de Melo50.31%25.13%
Daniel Borkmann40.25%12.56%
Tejun Heo30.19%12.56%
Johannes Berg20.12%12.56%
Eric Dumazet20.12%25.13%
Panagiotis Issaris10.06%12.56%
Kim Nordlund10.06%12.56%
Total1616100.00%39100.00%
Directory: net/sched
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.