cregit-Linux how code gets into the kernel

Release 4.8 net/sched/sch_dsmark.c

Directory: net/sched
/* net/sched/sch_dsmark.c - Differentiated Services field marker */

/* Written 1998-2000 by Werner Almesberger, EPFL ICA */


#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/skbuff.h>
#include <linux/rtnetlink.h>
#include <linux/bitops.h>
#include <net/pkt_sched.h>
#include <net/dsfield.h>
#include <net/inet_ecn.h>
#include <asm/byteorder.h>

/*
 * classid      class           marking
 * -------      -----           -------
 *   n/a          0             n/a
 *   x:0          1             use entry [0]
 *   ...         ...            ...
 *   x:y y>0     y+1            use entry [y]
 *   ...         ...            ...
 * x:indices-1  indices         use entry [indices-1]
 *   ...         ...            ...
 *   x:y         y+1            use entry [y & (indices-1)]
 *   ...         ...            ...
 * 0xffff       0x10000         use entry [indices-1]
 */



#define NO_DEFAULT_INDEX	(1 << 16)


struct mask_value {
	
u8			mask;
	
u8			value;
};


struct dsmark_qdisc_data {
	
struct Qdisc		*q;
	
struct tcf_proto __rcu	*filter_list;
	
struct mask_value	*mv;
	
u16			indices;
	
u8			set_tc_index;
	
u32			default_index;	/* index range is 0...0xffff */

#define DSMARK_EMBEDDED_SZ	16
	
struct mask_value	embedded[DSMARK_EMBEDDED_SZ];
};


static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index) { return index <= p->indices && index > 0; }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf26100.00%1100.00%
Total26100.00%1100.00%

/* ------------------------- Class/flow operations ------------------------- */
static int dsmark_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, struct Qdisc **old) { struct dsmark_qdisc_data *p = qdisc_priv(sch); pr_debug("%s(sch %p,[qdisc %p],new %p,old %p)\n", __func__, sch, p, new, old); if (new == NULL) { new = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, sch->handle); if (new == NULL) new = &noop_qdisc; } *old = qdisc_replace(sch, new, &p->q); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git6461.54%111.11%
thomas grafthomas graf1817.31%111.11%
patrick mchardypatrick mchardy76.73%333.33%
americo wangamerico wang65.77%111.11%
david s. millerdavid s. miller43.85%111.11%
yang yingliangyang yingliang32.88%111.11%
stephen hemmingerstephen hemminger21.92%111.11%
Total104100.00%9100.00%


static struct Qdisc *dsmark_leaf(struct Qdisc *sch, unsigned long arg) { struct dsmark_qdisc_data *p = qdisc_priv(sch); return p->q; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1856.25%133.33%
stephen hemmingerstephen hemminger928.12%133.33%
linus torvaldslinus torvalds515.62%133.33%
Total32100.00%3100.00%


static unsigned long dsmark_get(struct Qdisc *sch, u32 classid) { pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, qdisc_priv(sch), classid); return TC_H_MIN(classid) + 1; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git3179.49%125.00%
thomas grafthomas graf37.69%125.00%
yang yingliangyang yingliang37.69%125.00%
stephen hemmingerstephen hemminger25.13%125.00%
Total39100.00%4100.00%


static unsigned long dsmark_bind_filter(struct Qdisc *sch, unsigned long parent, u32 classid) { return dsmark_get(sch, classid); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git27100.00%1100.00%
Total27100.00%1100.00%


static void dsmark_put(struct Qdisc *sch, unsigned long cl) { }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git14100.00%1100.00%
Total14100.00%1100.00%

static const struct nla_policy dsmark_policy[TCA_DSMARK_MAX + 1] = { [TCA_DSMARK_INDICES] = { .type = NLA_U16 }, [TCA_DSMARK_DEFAULT_INDEX] = { .type = NLA_U16 }, [TCA_DSMARK_SET_TC_INDEX] = { .type = NLA_FLAG }, [TCA_DSMARK_MASK] = { .type = NLA_U8 }, [TCA_DSMARK_VALUE] = { .type = NLA_U8 }, };
static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent, struct nlattr **tca, unsigned long *arg) { struct dsmark_qdisc_data *p = qdisc_priv(sch); struct nlattr *opt = tca[TCA_OPTIONS]; struct nlattr *tb[TCA_DSMARK_MAX + 1]; int err = -EINVAL; pr_debug("%s(sch %p,[qdisc %p],classid %x,parent %x), arg 0x%lx\n", __func__, sch, p, classid, parent, *arg); if (!dsmark_valid_index(p, *arg)) { err = -ENOENT; goto errout; } if (!opt) goto errout; err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy); if (err < 0) goto errout; if (tb[TCA_DSMARK_VALUE]) p->mv[*arg - 1].value = nla_get_u8(tb[TCA_DSMARK_VALUE]); if (tb[TCA_DSMARK_MASK]) p->mv[*arg - 1].mask = nla_get_u8(tb[TCA_DSMARK_MASK]); err = 0; errout: return err; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git11759.69%112.50%
patrick mchardypatrick mchardy3316.84%337.50%
thomas grafthomas graf2814.29%112.50%
eric dumazeteric dumazet136.63%112.50%
yang yingliangyang yingliang31.53%112.50%
stephen hemmingerstephen hemminger21.02%112.50%
Total196100.00%8100.00%


static int dsmark_delete(struct Qdisc *sch, unsigned long arg) { struct dsmark_qdisc_data *p = qdisc_priv(sch); if (!dsmark_valid_index(p, arg)) return -EINVAL; p->mv[arg - 1].mask = 0xff; p->mv[arg - 1].value = 0; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5682.35%125.00%
eric dumazeteric dumazet68.82%125.00%
thomas grafthomas graf57.35%125.00%
stephen hemmingerstephen hemminger11.47%125.00%
Total68100.00%4100.00%


static void dsmark_walk(struct Qdisc *sch, struct qdisc_walker *walker) { struct dsmark_qdisc_data *p = qdisc_priv(sch); int i; pr_debug("%s(sch %p,[qdisc %p],walker %p)\n", __func__, sch, p, walker); if (walker->stop) return; for (i = 0; i < p->indices; i++) { if (p->mv[i].mask == 0xff && !p->mv[i].value) goto ignore; if (walker->count >= walker->skip) { if (walker->fn(sch, i + 1, walker) < 0) { walker->stop = 1; break; } } ignore: walker->count++; } }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git12188.32%120.00%
eric dumazeteric dumazet64.38%120.00%
thomas grafthomas graf53.65%120.00%
yang yingliangyang yingliang32.19%120.00%
stephen hemmingerstephen hemminger21.46%120.00%
Total137100.00%5100.00%


static inline struct tcf_proto __rcu **dsmark_find_tcf(struct Qdisc *sch, unsigned long cl) { struct dsmark_qdisc_data *p = qdisc_priv(sch); return &p->filter_list; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git2466.67%133.33%
stephen hemmingerstephen hemminger1130.56%133.33%
john fastabendjohn fastabend12.78%133.33%
Total36100.00%3100.00%

/* --------------------------- Qdisc operations ---------------------------- */
static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) { struct dsmark_qdisc_data *p = qdisc_priv(sch); int err; pr_debug("%s(skb %p,sch %p,[qdisc %p])\n", __func__, skb, sch, p); if (p->set_tc_index) { switch (tc_skb_protocol(skb)) { case htons(ETH_P_IP): if (skb_cow_head(skb, sizeof(struct iphdr))) goto drop; skb->tc_index = ipv4_get_dsfield(ip_hdr(skb)) & ~INET_ECN_MASK; break; case htons(ETH_P_IPV6): if (skb_cow_head(skb, sizeof(struct ipv6hdr))) goto drop; skb->tc_index = ipv6_get_dsfield(ipv6_hdr(skb)) & ~INET_ECN_MASK; break; default: skb->tc_index = 0; break; } } if (TC_H_MAJ(skb->priority) == sch->handle) skb->tc_index = TC_H_MIN(skb->priority); else { struct tcf_result res; struct tcf_proto *fl = rcu_dereference_bh(p->filter_list); int result = tc_classify(skb, fl, &res, false); pr_debug("result %d class 0x%04x\n", result, res.classid); switch (result) { #ifdef CONFIG_NET_CLS_ACT case TC_ACT_QUEUED: case TC_ACT_STOLEN: __qdisc_drop(skb, to_free); return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN; case TC_ACT_SHOT: goto drop; #endif case TC_ACT_OK: skb->tc_index = TC_H_MIN(res.classid); break; default: if (p->default_index != NO_DEFAULT_INDEX) skb->tc_index = p->default_index; break; } } err = qdisc_enqueue(skb, p->q, to_free); if (err != NET_XMIT_SUCCESS) { if (net_xmit_drop_count(err)) qdisc_qstats_drop(sch); return err; } qdisc_qstats_backlog_inc(sch, skb); sch->q.qlen++; return NET_XMIT_SUCCESS; drop: qdisc_drop(skb, sch, to_free); return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git19956.06%14.55%
stephen hemmingerstephen hemminger4612.96%29.09%
thomas grafthomas graf226.20%29.09%
patrick mchardypatrick mchardy185.07%29.09%
john fastabendjohn fastabend164.51%29.09%
eric dumazeteric dumazet164.51%29.09%
jarek poplawskijarek poplawski123.38%29.09%
arnaldo carvalho de meloarnaldo carvalho de melo82.25%313.64%
americo wangamerico wang71.97%14.55%
yang yingliangyang yingliang30.85%14.55%
jiri pirkojiri pirko30.85%14.55%
linus torvaldslinus torvalds20.56%14.55%
daniel borkmanndaniel borkmann20.56%14.55%
jussi kivilinnajussi kivilinna10.28%14.55%
Total355100.00%22100.00%


static struct sk_buff *dsmark_dequeue(struct Qdisc *sch) { struct dsmark_qdisc_data *p = qdisc_priv(sch); struct sk_buff *skb; u32 index; pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p); skb = qdisc_dequeue_peeked(p->q); if (skb == NULL) return NULL; qdisc_bstats_update(sch, skb); qdisc_qstats_backlog_dec(sch, skb); sch->q.qlen--; index = skb->tc_index & (p->indices - 1); pr_debug("index %d->%d\n", skb->tc_index, index); switch (tc_skb_protocol(skb)) { case htons(ETH_P_IP): ipv4_change_dsfield(ip_hdr(skb), p->mv[index].mask, p->mv[index].value); break; case htons(ETH_P_IPV6): ipv6_change_dsfield(ipv6_hdr(skb), p->mv[index].mask, p->mv[index].value); break; default: /* * Only complain if a change was actually attempted. * This way, we can send non-IP traffic through dsmark * and don't need yet another qdisc as a bypass. */ if (p->mv[index].mask != 0xff || p->mv[index].value) pr_warn("%s: unsupported protocol %d\n", __func__, ntohs(tc_skb_protocol(skb))); break; } return skb; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git16272.32%16.67%
eric dumazeteric dumazet2511.16%213.33%
arnaldo carvalho de meloarnaldo carvalho de melo83.57%320.00%
americo wangamerico wang73.12%16.67%
yang yingliangyang yingliang73.12%213.33%
jiri pirkojiri pirko62.68%16.67%
stephen hemmingerstephen hemminger41.79%213.33%
thomas grafthomas graf31.34%16.67%
al viroal viro10.45%16.67%
kyeong yookyeong yoo10.45%16.67%
Total224100.00%15100.00%


static struct sk_buff *dsmark_peek(struct Qdisc *sch) { struct dsmark_qdisc_data *p = qdisc_priv(sch); pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p); return p->q->ops->peek(p->q); }

Contributors

PersonTokensPropCommitsCommitProp
jarek poplawskijarek poplawski4593.75%150.00%
yang yingliangyang yingliang36.25%150.00%
Total48100.00%2100.00%


static int dsmark_init(struct Qdisc *sch, struct nlattr *opt) { struct dsmark_qdisc_data *p = qdisc_priv(sch); struct nlattr *tb[TCA_DSMARK_MAX + 1]; int err = -EINVAL; u32 default_index = NO_DEFAULT_INDEX; u16 indices; int i; pr_debug("%s(sch %p,[qdisc %p],opt %p)\n", __func__, sch, p, opt); if (!opt) goto errout; err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy); if (err < 0) goto errout; err = -EINVAL; indices = nla_get_u16(tb[TCA_DSMARK_INDICES]); if (hweight32(indices) != 1) goto errout; if (tb[TCA_DSMARK_DEFAULT_INDEX]) default_index = nla_get_u16(tb[TCA_DSMARK_DEFAULT_INDEX]); if (indices <= DSMARK_EMBEDDED_SZ) p->mv = p->embedded; else p->mv = kmalloc_array(indices, sizeof(*p->mv), GFP_KERNEL); if (!p->mv) { err = -ENOMEM; goto errout; } for (i = 0; i < indices; i++) { p->mv[i].mask = 0xff; p->mv[i].value = 0; } p->indices = indices; p->default_index = default_index; p->set_tc_index = nla_get_flag(tb[TCA_DSMARK_SET_TC_INDEX]); p->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, sch->handle); if (p->q == NULL) p->q = &noop_qdisc; pr_debug("%s: qdisc %p\n", __func__, p->q); err = 0; errout: return err; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git13142.95%17.69%
thomas grafthomas graf6922.62%17.69%
eric dumazeteric dumazet5718.69%17.69%
patrick mchardypatrick mchardy299.51%430.77%
david s. millerdavid s. miller72.30%215.38%
yang yingliangyang yingliang61.97%17.69%
stephen hemmingerstephen hemminger30.98%17.69%
jamal hadi salimjamal hadi salim20.66%17.69%
adrian bunkadrian bunk10.33%17.69%
Total305100.00%13100.00%


static void dsmark_reset(struct Qdisc *sch) { struct dsmark_qdisc_data *p = qdisc_priv(sch); pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p); qdisc_reset(p->q); sch->qstats.backlog = 0; sch->q.qlen = 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4276.36%125.00%
americo wangamerico wang814.55%125.00%
yang yingliangyang yingliang35.45%125.00%
stephen hemmingerstephen hemminger23.64%125.00%
Total55100.00%4100.00%


static void dsmark_destroy(struct Qdisc *sch) { struct dsmark_qdisc_data *p = qdisc_priv(sch); pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p); tcf_destroy_chain(&p->filter_list); qdisc_destroy(p->q); if (p->mv != p->embedded) kfree(p->mv); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4570.31%116.67%
eric dumazeteric dumazet1117.19%116.67%
patrick mchardypatrick mchardy34.69%233.33%
yang yingliangyang yingliang34.69%116.67%
stephen hemmingerstephen hemminger23.12%116.67%
Total64100.00%6100.00%


static int dsmark_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb, struct tcmsg *tcm) { struct dsmark_qdisc_data *p = qdisc_priv(sch); struct nlattr *opts = NULL; pr_debug("%s(sch %p,[qdisc %p],class %ld\n", __func__, sch, p, cl); if (!dsmark_valid_index(p, cl)) return -EINVAL; tcm->tcm_handle = TC_H_MAKE(TC_H_MAJ(sch->handle), cl - 1); tcm->tcm_info = p->q->handle; opts = nla_nest_start(skb, TCA_OPTIONS); if (opts == NULL) goto nla_put_failure; if (nla_put_u8(skb, TCA_DSMARK_MASK, p->mv[cl - 1].mask) || nla_put_u8(skb, TCA_DSMARK_VALUE, p->mv[cl - 1].value)) goto nla_put_failure; return nla_nest_end(skb, opts); nla_put_failure: nla_nest_cancel(skb, opts); return -EMSGSIZE; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git11564.97%111.11%
patrick mchardypatrick mchardy2413.56%222.22%
thomas grafthomas graf1810.17%222.22%
david s. millerdavid s. miller95.08%111.11%
eric dumazeteric dumazet63.39%111.11%
yang yingliangyang yingliang31.69%111.11%
stephen hemmingerstephen hemminger21.13%111.11%
Total177100.00%9100.00%


static int dsmark_dump(struct Qdisc *sch, struct sk_buff *skb) { struct dsmark_qdisc_data *p = qdisc_priv(sch); struct nlattr *opts = NULL; opts = nla_nest_start(skb, TCA_OPTIONS); if (opts == NULL) goto nla_put_failure; if (nla_put_u16(skb, TCA_DSMARK_INDICES, p->indices)) goto nla_put_failure; if (p->default_index != NO_DEFAULT_INDEX && nla_put_u16(skb, TCA_DSMARK_DEFAULT_INDEX, p->default_index)) goto nla_put_failure; if (p->set_tc_index && nla_put_flag(skb, TCA_DSMARK_SET_TC_INDEX)) goto nla_put_failure; return nla_nest_end(skb, opts); nla_put_failure: nla_nest_cancel(skb, opts); return -EMSGSIZE; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7458.73%114.29%
david s. millerdavid s. miller1915.08%114.29%
thomas grafthomas graf1612.70%228.57%
patrick mchardypatrick mchardy1411.11%114.29%
linus torvaldslinus torvalds21.59%114.29%
stephen hemmingerstephen hemminger10.79%114.29%
Total126100.00%7100.00%

static const struct Qdisc_class_ops dsmark_class_ops = { .graft = dsmark_graft, .leaf = dsmark_leaf, .get = dsmark_get, .put = dsmark_put, .change = dsmark_change, .delete = dsmark_delete, .walk = dsmark_walk, .tcf_chain = dsmark_find_tcf, .bind_tcf = dsmark_bind_filter, .unbind_tcf = dsmark_put, .dump = dsmark_dump_class, }; static struct Qdisc_ops dsmark_qdisc_ops __read_mostly = { .next = NULL, .cl_ops = &dsmark_class_ops, .id = "dsmark", .priv_size = sizeof(struct dsmark_qdisc_data), .enqueue = dsmark_enqueue, .dequeue = dsmark_dequeue, .peek = dsmark_peek, .init = dsmark_init, .reset = dsmark_reset, .destroy = dsmark_destroy, .change = NULL, .dump = dsmark_dump, .owner = THIS_MODULE, };
static int __init dsmark_module_init(void) { return register_qdisc(&dsmark_qdisc_ops); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1381.25%150.00%
al viroal viro318.75%150.00%
Total16100.00%2100.00%


static void __exit dsmark_module_exit(void) { unregister_qdisc(&dsmark_qdisc_ops); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1280.00%150.00%
al viroal viro320.00%150.00%
Total15100.00%2100.00%

module_init(dsmark_module_init) module_exit(dsmark_module_exit) MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git137257.48%23.39%
thomas grafthomas graf2189.13%711.86%
patrick mchardypatrick mchardy1968.21%1118.64%
eric dumazeteric dumazet1697.08%58.47%
stephen hemmingerstephen hemminger893.73%35.08%
dave jonesdave jones672.81%11.69%
jarek poplawskijarek poplawski622.60%35.08%
david s. millerdavid s. miller512.14%58.47%
yang yingliangyang yingliang401.68%23.39%
americo wangamerico wang281.17%23.39%
linus torvaldslinus torvalds261.09%46.78%
john fastabendjohn fastabend180.75%23.39%
arnaldo carvalho de meloarnaldo carvalho de melo160.67%35.08%
al viroal viro160.67%23.39%
jiri pirkojiri pirko90.38%11.69%
tejun heotejun heo30.13%11.69%
daniel borkmanndaniel borkmann20.08%11.69%
jamal hadi salimjamal hadi salim20.08%11.69%
jussi kivilinnajussi kivilinna10.04%11.69%
adrian bunkadrian bunk10.04%11.69%
kyeong yookyeong yoo10.04%11.69%
Total2387100.00%59100.00%
Directory: net/sched
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.