]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_dsmark.c
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 #define usage() return(-1)
25 static void explain(void)
27 fprintf(stderr
,"Usage: dsmark indices INDICES [ default_index "
28 "DEFAULT_INDEX ] [ set_tc_index ]\n");
32 static int dsmark_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
38 int dflt
,set_tc_index
;
40 ind
= set_tc_index
= 0;
43 if (!strcmp(*argv
,"indices")) {
45 ind
= strtoul(*argv
,&end
,0);
51 else if (!strcmp(*argv
,"default_index") || !strcmp(*argv
,
54 dflt
= strtoul(*argv
,&end
,0);
60 else if (!strcmp(*argv
,"set_tc_index")) {
74 tail
= (struct rtattr
*) (((void *) n
)+NLMSG_ALIGN(n
->nlmsg_len
));
75 addattr_l(n
,1024,TCA_OPTIONS
,NULL
,0);
76 addattr_l(n
,1024,TCA_DSMARK_INDICES
,&ind
,sizeof(ind
));
80 addattr_l(n
,1024,TCA_DSMARK_DEFAULT_INDEX
,&tmp
,sizeof(tmp
));
82 if (set_tc_index
) addattr_l(n
,1024,TCA_DSMARK_SET_TC_INDEX
,NULL
,0);
83 tail
->rta_len
= (((void *) n
)+n
->nlmsg_len
)-(void *) tail
;
88 static void explain_class(void)
90 fprintf(stderr
, "Usage: ... dsmark [ mask MASK ] [ value VALUE ]\n");
94 static int dsmark_parse_class_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
101 tail
= (struct rtattr
*) (((void *) n
)+NLMSG_ALIGN(n
->nlmsg_len
));
102 addattr_l(n
,1024,TCA_OPTIONS
,NULL
,0);
104 if (!strcmp(*argv
,"mask")) {
106 tmp
= strtoul(*argv
,&end
,0);
111 addattr_l(n
,1024,TCA_DSMARK_MASK
,&tmp
,1);
113 else if (!strcmp(*argv
,"value")) {
115 tmp
= strtoul(*argv
,&end
,0);
120 addattr_l(n
,1024,TCA_DSMARK_VALUE
,&tmp
,1);
129 tail
->rta_len
= (((void *) n
)+n
->nlmsg_len
)-(void *) tail
;
135 static int dsmark_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
137 struct rtattr
*tb
[TCA_DSMARK_MAX
+1];
140 memset(tb
, 0, sizeof(tb
));
141 parse_rtattr(tb
, TCA_DSMARK_MAX
, RTA_DATA(opt
), RTA_PAYLOAD(opt
));
142 if (tb
[TCA_DSMARK_MASK
]) {
143 if (!RTA_PAYLOAD(tb
[TCA_DSMARK_MASK
]))
144 fprintf(stderr
,"dsmark: empty mask\n");
145 else fprintf(f
,"mask 0x%02x ",
146 *(__u8
*) RTA_DATA(tb
[TCA_DSMARK_MASK
]));
148 if (tb
[TCA_DSMARK_VALUE
]) {
149 if (!RTA_PAYLOAD(tb
[TCA_DSMARK_VALUE
]))
150 fprintf(stderr
,"dsmark: empty value\n");
151 else fprintf(f
,"value 0x%02x ",
152 *(__u8
*) RTA_DATA(tb
[TCA_DSMARK_VALUE
]));
154 if (tb
[TCA_DSMARK_INDICES
]) {
155 if (RTA_PAYLOAD(tb
[TCA_DSMARK_INDICES
]) < sizeof(__u16
))
156 fprintf(stderr
,"dsmark: indices too short\n");
157 else fprintf(f
,"indices 0x%04x ",
158 *(__u16
*) RTA_DATA(tb
[TCA_DSMARK_INDICES
]));
160 if (tb
[TCA_DSMARK_DEFAULT_INDEX
]) {
161 if (RTA_PAYLOAD(tb
[TCA_DSMARK_DEFAULT_INDEX
]) < sizeof(__u16
))
162 fprintf(stderr
,"dsmark: default_index too short\n");
163 else fprintf(f
,"default_index 0x%04x ",
164 *(__u16
*) RTA_DATA(tb
[TCA_DSMARK_DEFAULT_INDEX
]));
166 if (tb
[TCA_DSMARK_SET_TC_INDEX
]) fprintf(f
,"set_tc_index ");
171 static int dsmark_print_xstats(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*xstats
)
177 struct qdisc_util dsmark_util
= {
184 dsmark_parse_class_opt
,