Skip to content

Commit d47a6b0

Browse files
jpirkodavem330
authored andcommitted
net: sched: introduce ingress/egress block index attributes for qdisc
Introduce two new attributes to be used for qdisc creation and dumping. One for ingress block, one for egress block. Introduce a set of ops that qdisc which supports block sharing would implement. Passing block indexes in qdisc change is not supported yet and it is checked and forbidded. In future, these attributes are to be reused for specifying block indexes for classes as well. As of this moment however, it is not supported so a check is in place to forbid it. Suggested-by: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Acked-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7960d1d commit d47a6b0

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

include/net/sch_generic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ struct Qdisc_ops {
204204
int (*dump)(struct Qdisc *, struct sk_buff *);
205205
int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
206206

207+
void (*ingress_block_set)(struct Qdisc *sch,
208+
u32 block_index);
209+
void (*egress_block_set)(struct Qdisc *sch,
210+
u32 block_index);
211+
u32 (*ingress_block_get)(struct Qdisc *sch);
212+
u32 (*egress_block_get)(struct Qdisc *sch);
213+
207214
struct module *owner;
208215
};
209216

include/uapi/linux/rtnetlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@ enum {
568568
TCA_DUMP_INVISIBLE,
569569
TCA_CHAIN,
570570
TCA_HW_OFFLOAD,
571+
TCA_INGRESS_BLOCK,
572+
TCA_EGRESS_BLOCK,
571573
__TCA_MAX
572574
};
573575

net/sched/sch_api.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
791791
unsigned char *b = skb_tail_pointer(skb);
792792
struct gnet_dump d;
793793
struct qdisc_size_table *stab;
794+
u32 block_index;
794795
__u32 qlen;
795796

796797
cond_resched();
@@ -807,6 +808,18 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
807808
tcm->tcm_info = refcount_read(&q->refcnt);
808809
if (nla_put_string(skb, TCA_KIND, q->ops->id))
809810
goto nla_put_failure;
811+
if (q->ops->ingress_block_get) {
812+
block_index = q->ops->ingress_block_get(q);
813+
if (block_index &&
814+
nla_put_u32(skb, TCA_INGRESS_BLOCK, block_index))
815+
goto nla_put_failure;
816+
}
817+
if (q->ops->egress_block_get) {
818+
block_index = q->ops->egress_block_get(q);
819+
if (block_index &&
820+
nla_put_u32(skb, TCA_EGRESS_BLOCK, block_index))
821+
goto nla_put_failure;
822+
}
810823
if (q->ops->dump && q->ops->dump(q, skb) < 0)
811824
goto nla_put_failure;
812825
if (nla_put_u8(skb, TCA_HW_OFFLOAD, !!(q->flags & TCQ_F_OFFLOADED)))
@@ -994,6 +1007,40 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
9941007
return err;
9951008
}
9961009

1010+
static int qdisc_block_indexes_set(struct Qdisc *sch, struct nlattr **tca,
1011+
struct netlink_ext_ack *extack)
1012+
{
1013+
u32 block_index;
1014+
1015+
if (tca[TCA_INGRESS_BLOCK]) {
1016+
block_index = nla_get_u32(tca[TCA_INGRESS_BLOCK]);
1017+
1018+
if (!block_index) {
1019+
NL_SET_ERR_MSG(extack, "Ingress block index cannot be 0");
1020+
return -EINVAL;
1021+
}
1022+
if (!sch->ops->ingress_block_set) {
1023+
NL_SET_ERR_MSG(extack, "Ingress block sharing is not supported");
1024+
return -EOPNOTSUPP;
1025+
}
1026+
sch->ops->ingress_block_set(sch, block_index);
1027+
}
1028+
if (tca[TCA_EGRESS_BLOCK]) {
1029+
block_index = nla_get_u32(tca[TCA_EGRESS_BLOCK]);
1030+
1031+
if (!block_index) {
1032+
NL_SET_ERR_MSG(extack, "Egress block index cannot be 0");
1033+
return -EINVAL;
1034+
}
1035+
if (!sch->ops->egress_block_set) {
1036+
NL_SET_ERR_MSG(extack, "Egress block sharing is not supported");
1037+
return -EOPNOTSUPP;
1038+
}
1039+
sch->ops->egress_block_set(sch, block_index);
1040+
}
1041+
return 0;
1042+
}
1043+
9971044
/* lockdep annotation is needed for ingress; egress gets it only for name */
9981045
static struct lock_class_key qdisc_tx_lock;
9991046
static struct lock_class_key qdisc_rx_lock;
@@ -1088,6 +1135,10 @@ static struct Qdisc *qdisc_create(struct net_device *dev,
10881135
netdev_info(dev, "Caught tx_queue_len zero misconfig\n");
10891136
}
10901137

1138+
err = qdisc_block_indexes_set(sch, tca, extack);
1139+
if (err)
1140+
goto err_out3;
1141+
10911142
if (ops->init) {
10921143
err = ops->init(sch, tca[TCA_OPTIONS], extack);
10931144
if (err != 0)
@@ -1169,6 +1220,10 @@ static int qdisc_change(struct Qdisc *sch, struct nlattr **tca,
11691220
NL_SET_ERR_MSG(extack, "Change operation not supported by specified qdisc");
11701221
return -EINVAL;
11711222
}
1223+
if (tca[TCA_INGRESS_BLOCK] || tca[TCA_EGRESS_BLOCK]) {
1224+
NL_SET_ERR_MSG(extack, "Change of blocks is not supported");
1225+
return -EOPNOTSUPP;
1226+
}
11721227
err = sch->ops->change(sch, tca[TCA_OPTIONS], extack);
11731228
if (err)
11741229
return err;
@@ -1894,6 +1949,11 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n,
18941949
}
18951950
}
18961951

1952+
if (tca[TCA_INGRESS_BLOCK] || tca[TCA_EGRESS_BLOCK]) {
1953+
NL_SET_ERR_MSG(extack, "Shared blocks are not supported for classes");
1954+
return -EOPNOTSUPP;
1955+
}
1956+
18971957
new_cl = cl;
18981958
err = -EOPNOTSUPP;
18991959
if (cops->change)

0 commit comments

Comments
 (0)