1 /* SPDX-License-Identifier: GPL-2.0 */
3 * q_dsmark.c Differentiated Services field marking.
5 * Hacked 1998,1999 by Werner Almesberger, EPFL ICA
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
22 static void explain(void)
24 fprintf(stderr
,"Usage: dsmark indices INDICES [ default_index DEFAULT_INDEX ] [ set_tc_index ]\n");
28 static int dsmark_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
29 struct nlmsghdr
*n
, const char *dev
)
34 int dflt
, set_tc_index
;
36 ind
= set_tc_index
= 0;
39 if (!strcmp(*argv
, "indices")) {
41 ind
= strtoul(*argv
, &end
, 0);
46 } else if (!strcmp(*argv
,"default_index") || !strcmp(*argv
,
49 dflt
= strtoul(*argv
, &end
, 0);
54 } else if (!strcmp(*argv
,"set_tc_index")) {
67 tail
= addattr_nest(n
, 1024, TCA_OPTIONS
);
68 addattr_l(n
, 1024, TCA_DSMARK_INDICES
, &ind
, sizeof(ind
));
72 addattr_l(n
, 1024, TCA_DSMARK_DEFAULT_INDEX
, &tmp
, sizeof(tmp
));
75 addattr_l(n
, 1024, TCA_DSMARK_SET_TC_INDEX
, NULL
, 0);
76 addattr_nest_end(n
, tail
);
81 static void explain_class(void)
83 fprintf(stderr
, "Usage: ... dsmark [ mask MASK ] [ value VALUE ]\n");
87 static int dsmark_parse_class_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
88 struct nlmsghdr
*n
, const char *dev
)
94 tail
= addattr_nest(n
, 1024, TCA_OPTIONS
);
96 if (!strcmp(*argv
, "mask")) {
98 tmp
= strtoul(*argv
, &end
, 0);
103 addattr_l(n
, 1024, TCA_DSMARK_MASK
, &tmp
, 1);
104 } else if (!strcmp(*argv
,"value")) {
106 tmp
= strtoul(*argv
, &end
, 0);
111 addattr_l(n
, 1024, TCA_DSMARK_VALUE
, &tmp
, 1);
119 addattr_nest_end(n
, tail
);
125 static int dsmark_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
127 struct rtattr
*tb
[TCA_DSMARK_MAX
+1];
130 parse_rtattr(tb
, TCA_DSMARK_MAX
, RTA_DATA(opt
), RTA_PAYLOAD(opt
));
131 if (tb
[TCA_DSMARK_MASK
]) {
132 if (!RTA_PAYLOAD(tb
[TCA_DSMARK_MASK
]))
133 fprintf(stderr
, "dsmark: empty mask\n");
134 else fprintf(f
, "mask 0x%02x ",
135 rta_getattr_u8(tb
[TCA_DSMARK_MASK
]));
137 if (tb
[TCA_DSMARK_VALUE
]) {
138 if (!RTA_PAYLOAD(tb
[TCA_DSMARK_VALUE
]))
139 fprintf(stderr
, "dsmark: empty value\n");
140 else fprintf(f
, "value 0x%02x ",
141 rta_getattr_u8(tb
[TCA_DSMARK_VALUE
]));
143 if (tb
[TCA_DSMARK_INDICES
]) {
144 if (RTA_PAYLOAD(tb
[TCA_DSMARK_INDICES
]) < sizeof(__u16
))
145 fprintf(stderr
, "dsmark: indices too short\n");
146 else fprintf(f
, "indices 0x%04x ",
147 rta_getattr_u16(tb
[TCA_DSMARK_INDICES
]));
149 if (tb
[TCA_DSMARK_DEFAULT_INDEX
]) {
150 if (RTA_PAYLOAD(tb
[TCA_DSMARK_DEFAULT_INDEX
]) < sizeof(__u16
))
151 fprintf(stderr
, "dsmark: default_index too short\n");
152 else fprintf(f
, "default_index 0x%04x ",
153 rta_getattr_u16(tb
[TCA_DSMARK_DEFAULT_INDEX
]));
155 if (tb
[TCA_DSMARK_SET_TC_INDEX
]) fprintf(f
, "set_tc_index ");
160 struct qdisc_util dsmark_qdisc_util
= {
162 .parse_qopt
= dsmark_parse_opt
,
163 .print_qopt
= dsmark_print_opt
,
164 .parse_copt
= dsmark_parse_class_opt
,
165 .print_copt
= dsmark_print_opt
,