return 0;
}
-
static int get_police_result(int *action, int *result, char *arg)
{
char *p = strchr(arg, '/');
return 0;
}
-
-int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
+int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p,
+ int tca_id, struct nlmsghdr *n)
{
int argc = *argc_p;
char **argv = *argv_p;
if (!ok)
return -1;
- if (p.rate.rate && !buffer) {
+ if (p.rate.rate && avrate)
+ return -1;
+
+ /* Must at least do late binding, use TB or ewma policing */
+ if (!p.rate.rate && !avrate && !p.index) {
+ fprintf(stderr, "\"rate\" or \"avrate\" MUST be specified.\n");
+ return -1;
+ }
+
+ /* When the TB policer is used, burst is required */
+ if (p.rate.rate && !buffer && !avrate) {
fprintf(stderr, "\"burst\" requires \"rate\".\n");
return -1;
}
+
if (p.peakrate.rate) {
if (!p.rate.rate) {
fprintf(stderr, "\"peakrate\" requires \"rate\".\n");
if (p.rate.rate) {
p.rate.mpu = mpu;
p.rate.overhead = overhead;
- if (tc_calc_rtable(&p.rate, rtab, Rcell_log, mtu, linklayer) < 0) {
- fprintf(stderr, "TBF: failed to calculate rate table.\n");
+ if (tc_calc_rtable(&p.rate, rtab, Rcell_log, mtu,
+ linklayer) < 0) {
+ fprintf(stderr, "POLICE: failed to calculate rate table.\n");
return -1;
}
p.burst = tc_calc_xmittime(p.rate.rate, buffer);
if (p.peakrate.rate) {
p.peakrate.mpu = mpu;
p.peakrate.overhead = overhead;
- if (tc_calc_rtable(&p.peakrate, ptab, Pcell_log, mtu, linklayer) < 0) {
+ if (tc_calc_rtable(&p.peakrate, ptab, Pcell_log, mtu,
+ linklayer) < 0) {
fprintf(stderr, "POLICE: failed to calculate peak rate table.\n");
return -1;
}
return act_parse_police(NULL, argc_p, argv_p, tca_id, n);
}
-int
-print_police(struct action_util *a, FILE *f, struct rtattr *arg)
+int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
{
SPRINT_BUF(b1);
SPRINT_BUF(b2);
if (p->peakrate.rate)
fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1));
if (tb[TCA_POLICE_AVRATE])
- fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1));
- fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1)));
+ fprintf(f, "avrate %s ",
+ sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]),
+ b1));
+ fprintf(f, "action %s",
+ police_action_n2a(p->action, b1, sizeof(b1)));
if (tb[TCA_POLICE_RESULT]) {
- fprintf(f, "/%s ", police_action_n2a(*(int *)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1)));
+ fprintf(f, "/%s",
+ police_action_n2a(*(int *)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1)));
} else
fprintf(f, " ");
fprintf(f, "overhead %ub ", p->rate.overhead);
linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK);
if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
- fprintf(f, "\nref %d bind %d\n", p->refcnt, p->bindcnt);
+ fprintf(f, "\n\tref %d bind %d\n", p->refcnt, p->bindcnt);
return 0;
}
-int
-tc_print_police(FILE *f, struct rtattr *arg) {
+int tc_print_police(FILE *f, struct rtattr *arg)
+{
return print_police(&police_action_util, f, arg);
}