^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* net/sched/sch_dsmark.c - Differentiated Services field marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/dsfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * classid class marking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * ------- ----- -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * n/a 0 n/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * x:0 1 use entry [0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * ... ... ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * x:y y>0 y+1 use entry [y]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * ... ... ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * x:indices-1 indices use entry [indices-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * ... ... ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * x:y y+1 use entry [y & (indices-1)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * ... ... ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * 0xffff 0x10000 use entry [indices-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define NO_DEFAULT_INDEX (1 << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct mask_value {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u8 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct dsmark_qdisc_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct Qdisc *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct tcf_proto __rcu *filter_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct tcf_block *block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct mask_value *mv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u16 indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u8 set_tc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 default_index; /* index range is 0...0xffff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define DSMARK_EMBEDDED_SZ 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct mask_value embedded[DSMARK_EMBEDDED_SZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return index <= p->indices && index > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* ------------------------- Class/flow operations ------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int dsmark_graft(struct Qdisc *sch, unsigned long arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct Qdisc *new, struct Qdisc **old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) pr_debug("%s(sch %p,[qdisc %p],new %p,old %p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) __func__, sch, p, new, old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (new == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) new = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) sch->handle, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (new == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) new = &noop_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *old = qdisc_replace(sch, new, &p->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static struct Qdisc *dsmark_leaf(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return p->q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static unsigned long dsmark_find(struct Qdisc *sch, u32 classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return TC_H_MIN(classid) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static unsigned long dsmark_bind_filter(struct Qdisc *sch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned long parent, u32 classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) pr_debug("%s(sch %p,[qdisc %p],classid %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) __func__, sch, qdisc_priv(sch), classid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return dsmark_find(sch, classid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void dsmark_unbind_filter(struct Qdisc *sch, unsigned long cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static const struct nla_policy dsmark_policy[TCA_DSMARK_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) [TCA_DSMARK_INDICES] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) [TCA_DSMARK_DEFAULT_INDEX] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) [TCA_DSMARK_SET_TC_INDEX] = { .type = NLA_FLAG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) [TCA_DSMARK_MASK] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) [TCA_DSMARK_VALUE] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct nlattr **tca, unsigned long *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct nlattr *opt = tca[TCA_OPTIONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct nlattr *tb[TCA_DSMARK_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) pr_debug("%s(sch %p,[qdisc %p],classid %x,parent %x), arg 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __func__, sch, p, classid, parent, *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!dsmark_valid_index(p, *arg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) err = nla_parse_nested_deprecated(tb, TCA_DSMARK_MAX, opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dsmark_policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (tb[TCA_DSMARK_VALUE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) p->mv[*arg - 1].value = nla_get_u8(tb[TCA_DSMARK_VALUE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (tb[TCA_DSMARK_MASK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) p->mv[*arg - 1].mask = nla_get_u8(tb[TCA_DSMARK_MASK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int dsmark_delete(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!dsmark_valid_index(p, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) p->mv[arg - 1].mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) p->mv[arg - 1].value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static void dsmark_walk(struct Qdisc *sch, struct qdisc_walker *walker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) pr_debug("%s(sch %p,[qdisc %p],walker %p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) __func__, sch, p, walker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (walker->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) for (i = 0; i < p->indices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (p->mv[i].mask == 0xff && !p->mv[i].value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto ignore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (walker->count >= walker->skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (walker->fn(sch, i + 1, walker) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) walker->stop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) walker->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static struct tcf_block *dsmark_tcf_block(struct Qdisc *sch, unsigned long cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return p->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* --------------------------- Qdisc operations ---------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned int len = qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pr_debug("%s(skb %p,sch %p,[qdisc %p])\n", __func__, skb, sch, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (p->set_tc_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int wlen = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) switch (skb_protocol(skb, true)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) wlen += sizeof(struct iphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!pskb_may_pull(skb, wlen) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) skb_try_make_writable(skb, wlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) skb->tc_index = ipv4_get_dsfield(ip_hdr(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) & ~INET_ECN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) wlen += sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!pskb_may_pull(skb, wlen) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) skb_try_make_writable(skb, wlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) skb->tc_index = ipv6_get_dsfield(ipv6_hdr(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) & ~INET_ECN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) skb->tc_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (TC_H_MAJ(skb->priority) == sch->handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) skb->tc_index = TC_H_MIN(skb->priority);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct tcf_result res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct tcf_proto *fl = rcu_dereference_bh(p->filter_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int result = tcf_classify(skb, fl, &res, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) pr_debug("result %d class 0x%04x\n", result, res.classid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #ifdef CONFIG_NET_CLS_ACT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case TC_ACT_QUEUED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) case TC_ACT_STOLEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) case TC_ACT_TRAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) __qdisc_drop(skb, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case TC_ACT_SHOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case TC_ACT_OK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) skb->tc_index = TC_H_MIN(res.classid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (p->default_index != NO_DEFAULT_INDEX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) skb->tc_index = p->default_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) err = qdisc_enqueue(skb, p->q, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (err != NET_XMIT_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (net_xmit_drop_count(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) qdisc_qstats_drop(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) sch->qstats.backlog += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) sch->q.qlen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return NET_XMIT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) qdisc_drop(skb, sch, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static struct sk_buff *dsmark_dequeue(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) skb = qdisc_dequeue_peeked(p->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) qdisc_bstats_update(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) qdisc_qstats_backlog_dec(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sch->q.qlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) index = skb->tc_index & (p->indices - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) pr_debug("index %d->%d\n", skb->tc_index, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) switch (skb_protocol(skb, true)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ipv4_change_dsfield(ip_hdr(skb), p->mv[index].mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) p->mv[index].value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ipv6_change_dsfield(ipv6_hdr(skb), p->mv[index].mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) p->mv[index].value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * Only complain if a change was actually attempted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * This way, we can send non-IP traffic through dsmark
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * and don't need yet another qdisc as a bypass.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (p->mv[index].mask != 0xff || p->mv[index].value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) pr_warn("%s: unsupported protocol %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) __func__, ntohs(skb_protocol(skb, true)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static struct sk_buff *dsmark_peek(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return p->q->ops->peek(p->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int dsmark_init(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct nlattr *tb[TCA_DSMARK_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) u32 default_index = NO_DEFAULT_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) u16 indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) pr_debug("%s(sch %p,[qdisc %p],opt %p)\n", __func__, sch, p, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) err = tcf_block_get(&p->block, &p->filter_list, sch, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) err = nla_parse_nested_deprecated(tb, TCA_DSMARK_MAX, opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) dsmark_policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (!tb[TCA_DSMARK_INDICES])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) indices = nla_get_u16(tb[TCA_DSMARK_INDICES]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (hweight32(indices) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (tb[TCA_DSMARK_DEFAULT_INDEX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) default_index = nla_get_u16(tb[TCA_DSMARK_DEFAULT_INDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (indices <= DSMARK_EMBEDDED_SZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) p->mv = p->embedded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) p->mv = kmalloc_array(indices, sizeof(*p->mv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!p->mv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) for (i = 0; i < indices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) p->mv[i].mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) p->mv[i].value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) p->indices = indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) p->default_index = default_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) p->set_tc_index = nla_get_flag(tb[TCA_DSMARK_SET_TC_INDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) p->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, sch->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (p->q == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) p->q = &noop_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) qdisc_hash_add(p->q, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) pr_debug("%s: qdisc %p\n", __func__, p->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static void dsmark_reset(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (p->q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) qdisc_reset(p->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) sch->qstats.backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) sch->q.qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static void dsmark_destroy(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) tcf_block_put(p->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) qdisc_put(p->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (p->mv != p->embedded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) kfree(p->mv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static int dsmark_dump_class(struct Qdisc *sch, unsigned long cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct sk_buff *skb, struct tcmsg *tcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct nlattr *opts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) pr_debug("%s(sch %p,[qdisc %p],class %ld\n", __func__, sch, p, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (!dsmark_valid_index(p, cl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) tcm->tcm_handle = TC_H_MAKE(TC_H_MAJ(sch->handle), cl - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) tcm->tcm_info = p->q->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (opts == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (nla_put_u8(skb, TCA_DSMARK_MASK, p->mv[cl - 1].mask) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) nla_put_u8(skb, TCA_DSMARK_VALUE, p->mv[cl - 1].value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return nla_nest_end(skb, opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) nla_nest_cancel(skb, opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static int dsmark_dump(struct Qdisc *sch, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct dsmark_qdisc_data *p = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct nlattr *opts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (opts == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (nla_put_u16(skb, TCA_DSMARK_INDICES, p->indices))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (p->default_index != NO_DEFAULT_INDEX &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) nla_put_u16(skb, TCA_DSMARK_DEFAULT_INDEX, p->default_index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (p->set_tc_index &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) nla_put_flag(skb, TCA_DSMARK_SET_TC_INDEX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return nla_nest_end(skb, opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) nla_nest_cancel(skb, opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static const struct Qdisc_class_ops dsmark_class_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) .graft = dsmark_graft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) .leaf = dsmark_leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) .find = dsmark_find,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) .change = dsmark_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) .delete = dsmark_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) .walk = dsmark_walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) .tcf_block = dsmark_tcf_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) .bind_tcf = dsmark_bind_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) .unbind_tcf = dsmark_unbind_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .dump = dsmark_dump_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static struct Qdisc_ops dsmark_qdisc_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) .next = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) .cl_ops = &dsmark_class_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) .id = "dsmark",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) .priv_size = sizeof(struct dsmark_qdisc_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) .enqueue = dsmark_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) .dequeue = dsmark_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) .peek = dsmark_peek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) .init = dsmark_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) .reset = dsmark_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) .destroy = dsmark_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) .change = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) .dump = dsmark_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int __init dsmark_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return register_qdisc(&dsmark_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static void __exit dsmark_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) unregister_qdisc(&dsmark_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) module_init(dsmark_module_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) module_exit(dsmark_module_exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) MODULE_LICENSE("GPL");