static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_FW_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_FW_MAX, opt); if (handle) fprintf(f, "handle 0x%x ", handle); if (tb[TCA_FW_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "classid %s ", sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_FW_CLASSID]), b1)); } if (tb[TCA_FW_POLICE]) tc_print_police(f, tb[TCA_FW_POLICE]); if (tb[TCA_FW_INDEV]) { struct rtattr *idev = tb[TCA_FW_INDEV]; fprintf(f, "input dev %s ",(char *)RTA_DATA(idev)); } if (tb[TCA_FW_ACT]) { fprintf(f, "\n"); tc_print_action(f, tb[TCA_FW_ACT]); } return 0; }
static int basic_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_BASIC_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_BASIC_MAX, opt); if (handle) fprintf(f, "handle 0x%x ", handle); if (tb[TCA_BASIC_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1)); } if (tb[TCA_BASIC_EMATCHES]) print_ematch(f, tb[TCA_BASIC_EMATCHES]); if (tb[TCA_BASIC_POLICE]) { fprintf(f, "\n"); tc_print_police(f, tb[TCA_BASIC_POLICE]); } if (tb[TCA_BASIC_ACT]) { tc_print_action(f, tb[TCA_BASIC_ACT]); } return 0; }
static int cgroup_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_CGROUP_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt); if (handle) fprintf(f, "handle 0x%x ", handle); if (tb[TCA_CGROUP_EMATCHES]) print_ematch(f, tb[TCA_CGROUP_EMATCHES]); if (tb[TCA_CGROUP_POLICE]) { fprintf(f, "\n"); tc_print_police(f, tb[TCA_CGROUP_POLICE]); } if (tb[TCA_CGROUP_ACT]) tc_print_action(f, tb[TCA_CGROUP_ACT]); return 0; }
static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_FW_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_FW_MAX, opt); if (handle || tb[TCA_FW_MASK]) { __u32 mark = 0, mask = 0; if(handle) mark = handle; if(tb[TCA_FW_MASK] && (mask = *(__u32*)RTA_DATA(tb[TCA_FW_MASK])) != 0xFFFFFFFF) fprintf(f, "handle 0x%x/0x%x ", mark, mask); else fprintf(f, "handle 0x%x ", handle); } if (tb[TCA_FW_FMASK]) { __u32 mask = 0, shift = 0; mask = *(__u32*)RTA_DATA(tb[TCA_FW_FMASK]); if (tb[TCA_FW_FSHIFT] && (shift = *(__u32*)RTA_DATA(tb[TCA_FW_FSHIFT])) != 0x0) fprintf(f, "mask 0x%x/0x%x ", mask, shift); else fprintf(f, "mask 0x%x ", mask); } if (tb[TCA_FW_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "classid %s ", sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_FW_CLASSID]), b1)); } if (tb[TCA_FW_POLICE]) tc_print_police(f, tb[TCA_FW_POLICE]); if (tb[TCA_FW_INDEV]) { struct rtattr *idev = tb[TCA_FW_INDEV]; fprintf(f, "input dev %s ",(char *)RTA_DATA(idev)); } if (tb[TCA_FW_ACT]) { fprintf(f, "\n"); tc_print_action(f, tb[TCA_FW_ACT]); } return 0; }
int print_action(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct tcamsg *t = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[TCAA_MAX+1]; len -= NLMSG_LENGTH(sizeof(*t)); if (len < 0) { fprintf(stderr, "Wrong len %d\n", len); return -1; } parse_rtattr(tb, TCAA_MAX, TA_RTA(t), len); if (NULL == tb[TCA_ACT_TAB]) { if (n->nlmsg_type != RTM_GETACTION) fprintf(stderr, "print_action: NULL kind\n"); return -1; } if (n->nlmsg_type == RTM_DELACTION) { if (n->nlmsg_flags & NLM_F_ROOT) { fprintf(fp, "Flushed table "); tab_flush = 1; } else { fprintf(fp, "deleted action "); } } if (n->nlmsg_type == RTM_NEWACTION) fprintf(fp, "Added action "); tc_print_action(fp, tb[TCA_ACT_TAB]); return 0; }
static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_FLOW_MAX+1]; SPRINT_BUF(b1); unsigned int i; __u32 mask = ~0, val = 0; if (opt == NULL) return -EINVAL; parse_rtattr_nested(tb, TCA_FLOW_MAX, opt); fprintf(f, "handle 0x%x ", handle); if (tb[TCA_FLOW_MODE]) { __u32 mode = *(__u32 *)RTA_DATA(tb[TCA_FLOW_MODE]); switch (mode) { case FLOW_MODE_MAP: fprintf(f, "map "); break; case FLOW_MODE_HASH: fprintf(f, "hash "); break; } } if (tb[TCA_FLOW_KEYS]) { __u32 keymask = *(__u32 *)RTA_DATA(tb[TCA_FLOW_KEYS]); char *sep = ""; fprintf(f, "keys "); for (i = 0; i <= FLOW_KEY_MAX; i++) { if (keymask & (1 << i)) { fprintf(f, "%s%s", sep, flow_keys[i]); sep = ","; } } fprintf(f, " "); } if (tb[TCA_FLOW_MASK]) mask = *(__u32 *)RTA_DATA(tb[TCA_FLOW_MASK]); if (tb[TCA_FLOW_XOR]) val = *(__u32 *)RTA_DATA(tb[TCA_FLOW_XOR]); if (mask != ~0 || val != 0) { __u32 or = (mask & val) ^ val; __u32 xor = mask & val; if (mask != ~0) fprintf(f, "and 0x%.8x ", mask); if (xor != 0) fprintf(f, "xor 0x%.8x ", xor); if (or != 0) fprintf(f, "or 0x%.8x ", or); } if (tb[TCA_FLOW_RSHIFT]) fprintf(f, "rshift %u ", *(__u32 *)RTA_DATA(tb[TCA_FLOW_RSHIFT])); if (tb[TCA_FLOW_ADDEND]) fprintf(f, "addend 0x%x ", *(__u32 *)RTA_DATA(tb[TCA_FLOW_ADDEND])); if (tb[TCA_FLOW_DIVISOR]) fprintf(f, "divisor %u ", *(__u32 *)RTA_DATA(tb[TCA_FLOW_DIVISOR])); if (tb[TCA_FLOW_BASECLASS]) fprintf(f, "baseclass %s ", sprint_tc_classid(*(__u32 *)RTA_DATA(tb[TCA_FLOW_BASECLASS]), b1)); if (tb[TCA_FLOW_PERTURB]) fprintf(f, "perturb %usec ", *(__u32 *)RTA_DATA(tb[TCA_FLOW_PERTURB])); if (tb[TCA_FLOW_EMATCHES]) print_ematch(f, tb[TCA_FLOW_EMATCHES]); if (tb[TCA_FLOW_POLICE]) tc_print_police(f, tb[TCA_FLOW_POLICE]); if (tb[TCA_FLOW_ACT]) { fprintf(f, "\n"); tc_print_action(f, tb[TCA_FLOW_ACT]); } return 0; }