2 * q_dsmark.c Differentiated Services field marking.
4 * 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
,
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")) {
68 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
69 addattr_l(n
, 1024, TCA_DSMARK_INDICES
, &ind
, sizeof(ind
));
73 addattr_l(n
, 1024, TCA_DSMARK_DEFAULT_INDEX
, &tmp
, sizeof(tmp
));
75 if (set_tc_index
) addattr_l(n
, 1024, TCA_DSMARK_SET_TC_INDEX
, NULL
, 0);
76 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) 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
,
95 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
97 if (!strcmp(*argv
, "mask")) {
99 tmp
= strtoul(*argv
, &end
, 0);
104 addattr_l(n
, 1024, TCA_DSMARK_MASK
, &tmp
, 1);
105 } else if (!strcmp(*argv
,"value")) {
107 tmp
= strtoul(*argv
, &end
, 0);
112 addattr_l(n
, 1024, TCA_DSMARK_VALUE
, &tmp
, 1);
120 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
126 static int dsmark_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
128 struct rtattr
*tb
[TCA_DSMARK_MAX
+1];
131 parse_rtattr(tb
, TCA_DSMARK_MAX
, RTA_DATA(opt
), RTA_PAYLOAD(opt
));
132 if (tb
[TCA_DSMARK_MASK
]) {
133 if (!RTA_PAYLOAD(tb
[TCA_DSMARK_MASK
]))
134 fprintf(stderr
, "dsmark: empty mask\n");
135 else fprintf(f
, "mask 0x%02x ",
136 rta_getattr_u8(tb
[TCA_DSMARK_MASK
]));
138 if (tb
[TCA_DSMARK_VALUE
]) {
139 if (!RTA_PAYLOAD(tb
[TCA_DSMARK_VALUE
]))
140 fprintf(stderr
, "dsmark: empty value\n");
141 else fprintf(f
, "value 0x%02x ",
142 rta_getattr_u8(tb
[TCA_DSMARK_VALUE
]));
144 if (tb
[TCA_DSMARK_INDICES
]) {
145 if (RTA_PAYLOAD(tb
[TCA_DSMARK_INDICES
]) < sizeof(__u16
))
146 fprintf(stderr
, "dsmark: indices too short\n");
147 else fprintf(f
, "indices 0x%04x ",
148 rta_getattr_u16(tb
[TCA_DSMARK_INDICES
]));
150 if (tb
[TCA_DSMARK_DEFAULT_INDEX
]) {
151 if (RTA_PAYLOAD(tb
[TCA_DSMARK_DEFAULT_INDEX
]) < sizeof(__u16
))
152 fprintf(stderr
, "dsmark: default_index too short\n");
153 else fprintf(f
, "default_index 0x%04x ",
154 rta_getattr_u16(tb
[TCA_DSMARK_DEFAULT_INDEX
]));
156 if (tb
[TCA_DSMARK_SET_TC_INDEX
]) fprintf(f
, "set_tc_index ");
161 struct qdisc_util dsmark_qdisc_util
= {
163 .parse_qopt
= dsmark_parse_opt
,
164 .print_qopt
= dsmark_print_opt
,
165 .parse_copt
= dsmark_parse_class_opt
,
166 .print_copt
= dsmark_print_opt
,